diff --git a/.gitignore b/.gitignore index 0924a2f..346a53f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ doc/usg.pdf *.pyc brent_test tasmet +tasmet_automoc.dir diff --git a/CMakeLists.txt b/CMakeLists.txt index 03bfc17..f3f595a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) #================================================== # Optimized code flags ******************************************* #================================================== @@ -129,7 +130,6 @@ include_directories( add_subdirectory(src) add_subdirectory(testing) -# add_executable(tasmet src/main.cpp src/main.moc) -add_executable(tasmet src/main.cpp) +add_executable(tasmet src/main.cpp src/gui/tasmet_resources.qrc) target_link_libraries(tasmet tasmet_gui tasmet_src messages PythonQt Qt5::Widgets openblas) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 36d37f1..3a3de20 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,7 @@ include_directories( . protobuf duct + ductbc # duct/cell # duct/connectors # duct/eq @@ -35,6 +36,9 @@ add_library(tasmet_src duct/geom.cpp duct/duct.cpp + ductbc/ductbc.cpp + ductbc/pressurebc.cpp + funcs/bessel.cpp funcs/cbessj.cpp funcs/rottfuncs.cpp @@ -65,3 +69,4 @@ add_library(tasmet_src add_subdirectory(gui) add_subdirectory(protobuf) +target_link_libraries(tasmet_src Qt5::Widgets) diff --git a/src/ductbc/ductbc.cpp b/src/ductbc/ductbc.cpp new file mode 100644 index 0000000..f94a06c --- /dev/null +++ b/src/ductbc/ductbc.cpp @@ -0,0 +1,33 @@ +// ductbc.cpp +// +// last-edit-by: J.A. de Jong +// +// Description: +// +////////////////////////////////////////////////////////////////////// +#include "ductbc.h" +#include "ductbc.pb.h" +#include "tasmet_tracer.h" +#include "tasmet_assert.h" +#include "pressurebc.h" + +Segment* DuctBc::newDuctBc(const us id, + const TaSystem& sys, + const pb::DuctBc& dbc) { + + TRACE(15,"newDuctBc"); + + switch (dbc.type()) { + case pb::PressureBc: { + return new PressureBc(id,sys,dbc); + break; + } + default: + tasmet_assert(false,"Not implemented DuctBc"); + break; + } + return nullptr; + +} + +////////////////////////////////////////////////////////////////////// diff --git a/src/ductbc/ductbc.h b/src/ductbc/ductbc.h new file mode 100644 index 0000000..e89fab0 --- /dev/null +++ b/src/ductbc/ductbc.h @@ -0,0 +1,27 @@ +// ductbc.h +// +// Author: J.A. de Jong +// +// Description: +// Prototype for duct boundary conditions +////////////////////////////////////////////////////////////////////// +#pragma once +#ifndef DUCTBC_H +#define DUCTBC_H +#include "segment.h" + +namespace pb{ + class DuctBc; +} + +class DuctBc { + +public: + static Segment* newDuctBc(const us id, + const TaSystem& sys, + const pb::DuctBc&); +}; + + +#endif // DUCTBC_H +////////////////////////////////////////////////////////////////////// diff --git a/src/ductbc/pressurebc.cpp b/src/ductbc/pressurebc.cpp new file mode 100644 index 0000000..46536cd --- /dev/null +++ b/src/ductbc/pressurebc.cpp @@ -0,0 +1,63 @@ +// pressurebc.cpp +// +// last-edit-by: J.A. de Jong +// +// Description: +// +////////////////////////////////////////////////////////////////////// + +#include "pressurebc.h" +#include "ductbc.pb.h" +#include "tasmet_tracer.h" + +PressureBc::PressureBc(const us id, + const TaSystem& sys, + const pb::DuctBc& dbc): + Segment(id,dbc.name()) +{ + TRACE(15,"PressureBc(id,sys,dbc)"); + + + + +} +PressureBc::PressureBc(const PressureBc& o): + Segment(o) { + + TRACE(15,"PressureBc(o)"); + +} +PressureBc::~PressureBc() { + +} +PressureBc* PressureBc::copy() const { + return new PressureBc(*this); +} +vd PressureBc::initialSolution(const TaSystem& sys) const { + return vd(); +} + +void PressureBc::residual(const TaSystem&, + arma::subview_col&& residual + ) const { + + TRACE(15,"PressureBc::residual()"); + + +} + +us PressureBc::getNEqs(const TaSystem&) const { + TRACE(15,"PressureBc::getNEqs()"); + + +} +void PressureBc::show(const TaSystem&,us verbosity_level) const { + TRACE(15,"PressureBc::show()"); +} +void PressureBc::jac(const TaSystem&,Jacobian&, + us dof_start,us eq_start) const { + + TRACE(15,"PressureBc::jac()"); + +} +////////////////////////////////////////////////////////////////////// diff --git a/src/ductbc/pressurebc.h b/src/ductbc/pressurebc.h new file mode 100644 index 0000000..bd3ea36 --- /dev/null +++ b/src/ductbc/pressurebc.h @@ -0,0 +1,56 @@ +// pressurebc.h +// +// Author: J.A. de Jong +// +// Description: +// Pressure boundary condition on a side of the duct +////////////////////////////////////////////////////////////////////// +#pragma once +#ifndef PRESSUREBC_H +#define PRESSUREBC_H +#include "segment.h" + +class TaSystem; +namespace pb{ + class DuctBc; +} +class Variable; + +class PressureBc: public Segment { + Variable *_p,*_T,*_Ts; +protected: + PressureBc(const PressureBc&); +public: + PressureBc(const us id, + const TaSystem& sys, + const pb::DuctBc&); + ~PressureBc(); + PressureBc* copy() const; + + vd initialSolution(const TaSystem&) const; + + virtual void residual(const TaSystem&, + arma::subview_col&& residual + ) const; + + // Return the total number of equations in this segment + virtual us getNEqs(const TaSystem&) const; + + // Return the current mass in this segment + virtual d getMass(const TaSystem&) const { return 0;}; + + virtual void show(const TaSystem&,us verbosity_level) const; + + // Reset amplitude data in higher harmonics + // virtual void resetHarmonics() = 0; + + // Fill Jacobian with values from the equations in this + // segment/connector. + virtual void jac(const TaSystem&,Jacobian&,us dof_start,us eq_start) const; + + +}; + + +#endif // PRESSUREBC_H +////////////////////////////////////////////////////////////////////// diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index d833a74..a484a45 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -5,6 +5,8 @@ add_library(tasmet_gui mainwindow.cpp add_duct_dialog.cpp + add_ductbc_dialog.cpp + about_dialog.cpp ) target_link_libraries(tasmet_gui qcustomplot) diff --git a/src/gui/about_dialog.cpp b/src/gui/about_dialog.cpp new file mode 100644 index 0000000..5ca4b83 --- /dev/null +++ b/src/gui/about_dialog.cpp @@ -0,0 +1,18 @@ +// about_dialog.cpp +// +// last-edit-by: J.A. de Jong +// +// Description: +// +////////////////////////////////////////////////////////////////////// +#include "about_dialog.h" +#include "ui_about_dialog.h" + +AboutDialog::AboutDialog(QWidget* parent): + QDialog(parent), + _dialog(new Ui::about_dialog) +{ + _dialog->setupUi(this); + +} +////////////////////////////////////////////////////////////////////// diff --git a/src/gui/about_dialog.h b/src/gui/about_dialog.h new file mode 100644 index 0000000..9d0f35c --- /dev/null +++ b/src/gui/about_dialog.h @@ -0,0 +1,22 @@ +// about_dialog.h +// +// Author: J.A. de Jong +// +// Description: +// +////////////////////////////////////////////////////////////////////// +#pragma once +#ifndef ABOUT_DIALOG_H +#define ABOUT_DIALOG_H +#include +namespace Ui{ + class about_dialog; +} +class AboutDialog:public QDialog{ + Ui::about_dialog* _dialog; +public: + AboutDialog(QWidget* parent); +}; + +#endif // ABOUT_DIALOG_H +////////////////////////////////////////////////////////////////////// diff --git a/src/gui/about_dialog.ui b/src/gui/about_dialog.ui new file mode 100644 index 0000000..eb0e6f0 --- /dev/null +++ b/src/gui/about_dialog.ui @@ -0,0 +1,142 @@ + + + about_dialog + + + + 0 + 0 + 318 + 582 + + + + + 0 + 0 + + + + About TaSMET + + + + + + + DejaVu Sans Mono + 14 + 75 + true + + + + TaSMET + + + Qt::AlignCenter + + + + + + + Thermoacoustic System + + + Qt::AlignCenter + + + + + + + Modeling Environment Twente + + + Qt::AlignCenter + + + + + + + + 300 + 433 + + + + + 300 + 433 + + + + background-color: rgb(255, 255, 255) + + + QFrame::Box + + + + + + :/images/tasmet.png + + + true + + + + + + + Copyright (c) 2017 Anne de Jong + + + Qt::AlignCenter + + + + + + + All rights reserved + + + Qt::AlignCenter + + + + + + + OK + + + + + + + + + + + pushButton + clicked() + about_dialog + accept() + + + 158 + 562 + + + 158 + 290 + + + + + diff --git a/src/gui/add_duct_dialog.cpp b/src/gui/add_duct_dialog.cpp index 67c1f4c..dc13aae 100644 --- a/src/gui/add_duct_dialog.cpp +++ b/src/gui/add_duct_dialog.cpp @@ -129,11 +129,7 @@ void AddDuctDialog::accept(){ } catch(TaSMETError& e) { - QMessageBox msg(QMessageBox::Warning, - "Input parsing error", - e.what()); - - msg.exec(); + e.show_user("Input parsing error"); // Do not finally accept until we do not have any errors return; @@ -220,19 +216,19 @@ void AddDuctDialog::changed(){ switch (pshow) { case CSArea: _plot->yAxis->setLabel("S [m^2]"); - y = geom->S; + y = duct->S; break; case Porosity: _plot->yAxis->setLabel("phi [-]"); - y = geom->phi; + y = duct->phi; break; case HydraulicRadius: _plot->yAxis->setLabel("rh [m]"); - y = geom->rh; + y = duct->rh; break; case SolidTemperatureFunction: _plot->yAxis->setLabel("Ts [K]"); - y = geom->rh; + y = duct->rh; break; default: tasmet_assert(false,"Unhandled PreviewShow case"); diff --git a/src/gui/add_duct_dialog.ui b/src/gui/add_duct_dialog.ui index 6a1df7d..8eda641 100644 --- a/src/gui/add_duct_dialog.ui +++ b/src/gui/add_duct_dialog.ui @@ -6,8 +6,8 @@ 0 0 - 841 - 654 + 848 + 667 @@ -19,231 +19,13 @@ + + + 391 + 16777215 + + - - - - Geometry - - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Length (L): - - - - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - [-] - - - - - - - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Cross-sectional area function: - - - - - - - [m] - - - - - - - Cross sectional shape - - - - - - - Porosity function: - - - - - - - [m^2] - - - - - - - Solid type - - - - - - - - - - Hydraulic radius: - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - [m] - - - - - - - - - - - - Preview options - - - - - - - - - Show: - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - - Model - - - - - - Drag model - - - - - - - Heat transfer model - - - - - - - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Solid temperature function - - - - - - - - - - [K] - - - - - - - Solid temperature model - - - - - - - - - @@ -314,26 +96,245 @@ + + + + Geometry + + + + + + + + Cross sectional shape + + + + + + + [m^2] + + + + + + + [m] + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Solid type + + + + + + + + + + Porosity function: + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Length (L): + + + + + + + Hydraulic radius: + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + [m] + + + + + + + [-] + + + + + + + Cross-sectional area function: + + + + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + Model + + + + + + Drag model + + + + + + + Heat transfer model + + + + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Solid temperature function + + + + + + + + + + [K] + + + + + + + Solid temperature model + + + + + + + + + - - - - - - - - 0 - 0 - - - - Preview - - - + + + + + + + 0 + 0 + + + + Preview options + + + + + + Show: + + + + + + + + + + + + + + 0 + 0 + + + + Preview + + + + + + + + + + verticalLayoutWidget + groupBox_4 + diff --git a/src/gui/add_ductbc_dialog.cpp b/src/gui/add_ductbc_dialog.cpp new file mode 100644 index 0000000..c996339 --- /dev/null +++ b/src/gui/add_ductbc_dialog.cpp @@ -0,0 +1,104 @@ +// add_ductbc_dialog.cpp +// +// last-edit-by: J.A. de Jong +// +// Description: +// +////////////////////////////////////////////////////////////////////// + +#include "add_ductbc_dialog.h" +#include "ui_add_ductbc_dialog.h" +#include "tasmet_tracer.h" +#include "tasmet_assert.h" + +AddDuctBcDialog::AddDuctBcDialog(const std::string& name,QWidget* parent): + QDialog(parent), + _dialog(new Ui::add_ductbc_dialog), + _ductbc(pb::DuctBc::default_instance()) +{ + TRACE(15,"AddDuctDialog"); + _dialog->setupUi(this); + + _ductbc.set_name(name); + + QString title = "Add/edit duct boundary condition segment '"; + title += QString::fromStdString(name); + title +="'"; + this->setWindowTitle(title); + + for(int ductbctype = pb::DuctBcType_MIN; + ductbctype<=pb::DuctBcType_MAX; + ductbctype++){ + _dialog->type->addItem(QString::fromStdString(DuctBcType_Name((pb::DuctBcType) ductbctype))); + } + _dialog->type->setCurrentIndex(0); + + for(int ductside = pb::DuctSide_MIN; + ductside<=pb::DuctSide_MAX; + ductside++){ + _dialog->side->addItem(QString::fromStdString(DuctSide_Name((pb::DuctSide) ductside))); + } + _dialog->side->setCurrentIndex(0); + + _dialog->pressure->setText("p0 + 1.0*sin(2*pi*freq*t)"); + _dialog->temperature->setText("T0"); + + _init = false; + changed(); + +} +void AddDuctBcDialog::changed() { + if(_init) return; + pb::DuctBcType type = (pb::DuctBcType) _dialog->type->currentIndex(); + bool isentropic = _dialog->isentropic->isChecked(); + VARTRACE(15,type); + switch (type) { + case pb::PressureBc: + _dialog->isentropic->setEnabled(true); + _dialog->temperature->setEnabled(!isentropic); + _dialog->pressure->setEnabled(true); + break; + case pb::AdiabaticWall: + _dialog->isentropic->setEnabled(false); + _dialog->temperature->setEnabled(false); + _dialog->pressure->setEnabled(false); + break; + case pb::IsoTWall: + _dialog->isentropic->setEnabled(false); + _dialog->temperature->setEnabled(true); + _dialog->pressure->setEnabled(false); + break; + default: + tasmet_assert(false,"Not implemented"); + break; + } + _ductbc.set_type(type); + _ductbc.set_side((pb::DuctSide) _dialog->side->currentIndex()); + _ductbc.set_duct_id(_dialog->duct_id->value()); + _ductbc.set_pressure(_dialog->pressure->text().toStdString()); + _ductbc.set_temperature(_dialog->temperature->text().toStdString()); + _ductbc.set_isentropic(isentropic); + +} +void AddDuctBcDialog::set(const pb::DuctBc& ductbc) { + + _dialog->type->setCurrentIndex((int) ductbc.type()); + _dialog->side->setCurrentIndex((int) ductbc.side()); + _dialog->duct_id->setValue(ductbc.duct_id()); + _dialog->pressure->setText(QString::fromStdString(ductbc.pressure())); + _dialog->temperature->setText(QString::fromStdString(ductbc.temperature())); + _dialog->isentropic->setChecked(ductbc.isentropic()); + _ductbc = ductbc; +} + +AddDuctBcDialog::~AddDuctBcDialog(){ + delete _dialog; + +} +void AddDuctBcDialog::reject() { + QDialog::reject(); +} +void AddDuctBcDialog::accept() { + QDialog::accept(); +} +////////////////////////////////////////////////////////////////////// diff --git a/src/gui/add_ductbc_dialog.h b/src/gui/add_ductbc_dialog.h new file mode 100644 index 0000000..8fe96e0 --- /dev/null +++ b/src/gui/add_ductbc_dialog.h @@ -0,0 +1,40 @@ +// add_ductbc_dialog.h +// +// Author: J.A. de Jong +// +// Description: +// +////////////////////////////////////////////////////////////////////// +#pragma once +#ifndef ADD_DUCTBC_DIALOG_H +#define ADD_DUCTBC_DIALOG_H +#include "ductbc.pb.h" +#include +namespace Ui{ + class add_ductbc_dialog; +} +class AddDuctBcDialog: public QDialog { + Q_OBJECT + Ui::add_ductbc_dialog* _dialog; + pb::DuctBc _ductbc; + bool _init = true; +public: + AddDuctBcDialog(const std::string& name,QWidget* parent = nullptr); + ~AddDuctBcDialog(); + + void set(const pb::DuctBc&); + const pb::DuctBc& get() const {return _ductbc; } + +private: + void changed(); + +private slots: + void on_type_currentIndexChanged(int) {changed();} + void on_isentropic_stateChanged(int) {changed();} + void accept(); + void reject(); + +}; + +#endif // ADD_DUCTBC_DIALOG_H +////////////////////////////////////////////////////////////////////// diff --git a/src/gui/add_ductbc_dialog.ui b/src/gui/add_ductbc_dialog.ui new file mode 100644 index 0000000..4fe4372 --- /dev/null +++ b/src/gui/add_ductbc_dialog.ui @@ -0,0 +1,151 @@ + + + add_ductbc_dialog + + + + 0 + 0 + 412 + 300 + + + + Dialog + + + + + + + + Prescribed pressure + + + + + + + Type + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Side + + + + + + + [K] + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Duct ID + + + + + + + Isentropic pressure-temperature coupling + + + + + + + + + + [Pa] + + + + + + + Prescribed temperature + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + add_ductbc_dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + add_ductbc_dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/gui/images/document-new.png b/src/gui/images/document-new.png new file mode 100644 index 0000000..61db97a Binary files /dev/null and b/src/gui/images/document-new.png differ diff --git a/src/gui/images/document-open.png b/src/gui/images/document-open.png new file mode 100644 index 0000000..3432ed2 Binary files /dev/null and b/src/gui/images/document-open.png differ diff --git a/src/gui/images/document-save-as.png b/src/gui/images/document-save-as.png new file mode 100644 index 0000000..ed2453d Binary files /dev/null and b/src/gui/images/document-save-as.png differ diff --git a/src/gui/images/document-save.png b/src/gui/images/document-save.png new file mode 100644 index 0000000..cc380a0 Binary files /dev/null and b/src/gui/images/document-save.png differ diff --git a/src/gui/images/tasmet.png b/src/gui/images/tasmet.png new file mode 100755 index 0000000..a4b2f1d Binary files /dev/null and b/src/gui/images/tasmet.png differ diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 06c5bc5..b34f0a5 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -16,99 +16,456 @@ #include #include "gas.h" #include "tasmet_tracer.h" +#include "tasmet_assert.h" #include "add_duct_dialog.h" +#include "add_ductbc_dialog.h" +#include "tasystem.h" +#include "tasmet_exception.h" +#include +#include +#include +#include "about_dialog.h" +#include -const QString default_name = "Unnamed segment"; +using google::protobuf::TextFormat; + +const QString default_system_name = QString("Unsaved TaSMET Model") + + constants::system_fileext; +const QString default_segment_name = "Unnamed segment"; +const QString start_file_location = QStandardPaths:: + writableLocation(QStandardPaths::DocumentsLocation); +const QString filetype = QString("TaSMET Model files (*") + constants::system_fileext + ")"; +const QString window_title_part = "TaSMET Model Builder - "; +namespace { + pb::System loadSystem(const string& filepath) { + + TRACE(15,"loadSystem()"); + VARTRACE(15,filepath); + std::ifstream myfile(filepath); + + if(!myfile.good()) { + string error = "Read error on "; + error += filepath; + throw TaSMETError(error); + + } + + pb::System sys; + + std::stringstream strStream; + strStream << myfile.rdbuf(); //read the file + string data = strStream.str();//str holds the content of the file + VARTRACE(15,data); + + if(!TextFormat::ParseFromString(data,&sys)) { + string error = "Invalid TaSMET Model file: "; + error += filepath; + throw TaSMETError(error); + } + + return sys; + + + } + + // // Returns true when the two systems are equal + bool compareSys(const pb::System& s1,const pb::System& s2) { + return (s1.SerializeAsString()==s2.SerializeAsString()); + } + + int saveFileFirstQuestion(QWidget* parent) { + + return QMessageBox::question(parent, + "Model has unsaved changes", + "Would you like to save the changes?", + QMessageBox::Yes | + QMessageBox::No | + QMessageBox::Cancel); + + } +} TaSMETMainWindow::TaSMETMainWindow(): - window(new Ui::MainWindow()) + _window(new Ui::MainWindow()), + _system(pb::System::default_instance()) { - window->setupUi(this); + if(!_window) throw TaSMETBadAlloc(); + _window->setupUi(this); // Restore settings QSettings settings(company,appname); restoreGeometry(settings.value("geometry").toByteArray()); restoreState(settings.value("windowState").toByteArray()); - for(const SystemType& t: SystemType_vec){ - window->systemtype->addItem(SystemTypeToString(t)); + _window->systemtype->addItem(SystemTypeToString(t)); } for(int gastype = pb::GasType_MIN;gastype<=pb::GasType_MAX;gastype++){ - window->gastype->addItem(QString::fromStdString(GasType_Name((pb::GasType) gastype))); + _window->gastype->addItem(QString::fromStdString(GasType_Name((pb::GasType) gastype))); } for(const SegmentType& t: SegmentType_vec){ - window->segmenttype->addItem(SegmentTypeToString(t)); + _window->segmenttype->addItem(SegmentTypeToString(t)); } - window->T0->setText(QString::number(constants::default_T0)); - window->T0->setValidator(new QDoubleValidator(constants::min_T0, + // TODO: change from omg to freq + _window->freq->setValidator(new QDoubleValidator(constants::min_omg, + constants::max_omg, + constants::field_decimals)); + + + _window->T0->setText(QString::number(constants::default_T0)); + _window->T0->setValidator(new QDoubleValidator(constants::min_T0, constants::max_T0, constants::field_decimals)); - window->p0->setText(QString::number(constants::default_p0)); - window->p0->setValidator(new QDoubleValidator(constants::min_p0, + _window->p0->setText(QString::number(constants::default_p0)); + _window->p0->setValidator(new QDoubleValidator(constants::min_p0, constants::max_p0, constants::field_decimals)); - window->name->setText(default_name); + _window->segmentname->setText(default_system_name); + + _window->segmentid->setMaximum(constants::max_segs); + + _window->nf->setMaximum(constants::max_Nf); + + _init = false; + + changed(); + +} + +TaSMETMainWindow::~TaSMETMainWindow(){ + delete _window; +} + +void TaSMETMainWindow::newModel() { + TRACE(15,"newModel"); + _system = pb::System::default_instance(); + _filepath = ""; + set(_system); +} +void TaSMETMainWindow::loadModel() { + TRACE(15,"loadModel"); + if(isDirty()) { + int answer = saveFileFirstQuestion(this); + if(answer == QMessageBox::Yes) saveModel(); + else if(answer == QMessageBox::Cancel) return; + } + + QString title = tr("Open existing TaSMET model file"); + + QString filepath = QFileDialog::getOpenFileName(this, + title, + start_file_location, + filetype); + string filepath_s = filepath.toStdString(); + if(filepath.size()!=0) { + try { + TRACE(15,"Setting loaded system"); + _filepath = filepath_s; + set(loadSystem(filepath_s)); + } + catch(TaSMETError &e) { + _filepath = ""; + e.show_user("Error opening model file"); + } + } +} +void TaSMETMainWindow::saveModel(string* filepath) { + + TRACE(15,"saveModel"); + + if(isDirty() || filepath!=nullptr) { + + // The user pressed save, but the model has never + // been saved. Hence we 'save as' + if(_filepath.size()==0 && filepath == nullptr) { + return saveAsModel(); + } + else if(filepath == nullptr) { + filepath = &_filepath; + } + + std::ofstream sfile(*filepath); + if(!sfile.good()){ + + QMessageBox::warning(this, + "File error", + "Could not open file for saving"); + return; + } + string data; + if(TextFormat::PrintToString(_system,&data)) { + // Can maybe assign to itself. Which is no problem + // according to C++ docs + TRACE(15,"Saving file succeeded"); + VARTRACE(15,data); + sfile << data; + // Close file here, such that in can be opened to compare + // whether the file is still dirty + sfile.close(); + _filepath = *filepath; + changed(); + } + else { + QMessageBox::warning(this, + "File error", + "Could not save model to file"); + + } + + } } -TaSMETMainWindow::~TaSMETMainWindow(){ - delete window; +void TaSMETMainWindow::saveAsModel() { + TRACE(15,"saveModel"); + + QString suggested_file; + + if(_filepath.size()==0) { + suggested_file = QDir(start_file_location).filePath(default_system_name); + } + else { + suggested_file.fromStdString(_filepath); + } + + + VARTRACE(15,filetype.toStdString()); + QString title = tr("Save model file"); + QString fileName = QFileDialog::getSaveFileName(this, + title, + suggested_file, + filetype); + + if(fileName.size()!=0) { + string fn = fileName.toStdString(); + + saveModel(&fn); + } + +} +void TaSMETMainWindow::changed() { + TRACE(15,"changed()"); + if(_init) return; + TRACE(15,"changed() continued"); + + _system.set_nf(_window->nf->value()); + _system.set_freq(_window->freq->text().toDouble()); + + _system.set_gastype((pb::GasType) _window->gastype->currentIndex()); + _system.set_t0(_window->T0->text().toDouble()); + _system.set_p0(_window->p0->text().toDouble()); + + _system.set_systemtype((pb::SystemType) _window->systemtype->currentIndex()); + + QString windowtitle = window_title_part; + if(isDirty()) windowtitle+= '*'; + if(_filepath.size()!=0) { + windowtitle += QString::fromStdString(_filepath); + } + else { + windowtitle += default_system_name; + } + + setWindowTitle(windowtitle); + _window->segoverview->setPlainText(QString::fromStdString(_system.DebugString())); + + // Update stuff based on the segments + int value = _window->segmentid->value(); + on_segmentid_valueChanged(value); + +} +void TaSMETMainWindow::set(const pb::System& sys) { + TRACE(15,"set()"); + _init = true; + + _window->nf->setValue(sys.nf()); + _window->freq->setText(QString::number(sys.freq())); + _window->p0->setText(QString::number(sys.p0())); + _window->T0->setText(QString::number(sys.t0())); + _window->systemtype->setCurrentIndex((int) sys.systemtype()); + _window->gastype->setCurrentIndex((int) sys.gastype()); + + _system = sys; + _init = false; + + changed(); + } void TaSMETMainWindow::closeEvent(QCloseEvent *event) { + if(isDirty()) { + + int answer = saveFileFirstQuestion(this); + if(answer == QMessageBox::Yes){ + saveModel(); + // If we are still dirty after a save (user probably + // cancelled the save action, return to the GUI + if(isDirty()) { + TRACE(15,"still dirty"); + event->ignore(); + return; + } + } + else if(answer == QMessageBox::Cancel) { + TRACE(15,"CloseEvent cancelled"); + event->ignore(); + return; + } + } + // Save window configuration to settings QSettings settings(company,appname); settings.setValue("geometry", saveGeometry()); settings.setValue("windowState", saveState()); - // Forward close event to parent - QMainWindow::closeEvent(event); + event->accept(); } -void TaSMETMainWindow::on_addsegment_clicked() { - - us id = window->segmentid_add->value(); - string name = window->name->text().toStdString(); - VARTRACE(15,name); - bool edit = false; - - AddDuctDialog dialog(name,this); - - auto& ductmap = *_system.mutable_ducts(); - if(ductmap.find(id) != ductmap.end()) { - dialog.set(ductmap[id]); +// Different segments all have different type. Therefore this part of +// the code is templatized. In this function, the dialog is +// created. If the segment already existed, the `set' function is +// called, with the found segment in the list. Finally the exitcode of +// the dialog is returned +template +int add_edit_segment(QWidget* parent, + const string& name, + google::protobuf::Map & segmap, + const us id) { + + dialogtype dialog(name,parent); + + if(segmap.find(id) != segmap.end()) { + dialog.set(segmap[id]); } int exitcode = dialog.exec(); if(exitcode == QDialog::Accepted) { - VARTRACE(15,dialog.get().name()); - ductmap[id] = dialog.get(); - window->segmentid_add->setValue(id+1); + segmap[id] = dialog.get(); + + } + return exitcode; +} + +void TaSMETMainWindow::on_addsegment_clicked() { + TRACE(15,"on_addsegment_clicked"); + us id = _window->segmentid->value(); + string name = _window->segmentname->text().toStdString(); + VARTRACE(15,name); + + SegmentType segtype = (SegmentType) _window->segmenttype->currentIndex(); + + int exitcode=QDialog::Rejected; + + switch (segtype) { + case Duct: { + exitcode = add_edit_segment + (this, + name, + *_system.mutable_ducts(), + id); + break; + } + case DuctBc: { + exitcode = add_edit_segment + (this, + name, + *_system.mutable_ductbcs(), + id); + break; + } + + default: + tasmet_assert(false,"Not implemented"); } - + if(exitcode == QDialog::Accepted) { + _window->segmentid->setValue(id+1); + changed(); + } + } -void TaSMETMainWindow::on_segmentid_add_valueChanged(int id) { +void TaSMETMainWindow::on_removesegment_clicked() { + TRACE(15,"on_remove"); + QString question = "Are you you wish to delete segment "; + int segid = _window->segmentid->value(); + + question+= QString::number(segid); + question+= "?"; + int answ = QMessageBox::question(this, + "Deleting segment", + question, + QMessageBox::Yes | QMessageBox::No); + if(answ == QMessageBox::Yes) { + _system.mutable_ducts()->erase(segid); + _system.mutable_ductbcs()->erase(segid); + changed(); + } +} + +void TaSMETMainWindow::on_segmentid_valueChanged(int id) { auto& ductmap = *_system.mutable_ducts(); + auto& ductbcmap = *_system.mutable_ductbcs(); + + bool is_segment = false; + if(ductmap.find(id) != ductmap.end()) { - window->name->setText(QString::fromStdString(ductmap[id].name())); - } + _window->segmentname->setText(QString::fromStdString(ductmap[id].name())); + is_segment = true; + } + if(ductbcmap.find(id) != ductbcmap.end()) { + _window->segmentname->setText(QString::fromStdString(ductbcmap[id].name())); + is_segment = true; + } + + _window->removesegment->setEnabled(is_segment); + } void TaSMETMainWindow::on_name_textEdited() { auto& ductmap = *_system.mutable_ducts(); - int id = window->segmentid_add->value(); - + auto& ductbcmap = *_system.mutable_ductbcs(); + + int id = _window->segmentid->value(); + if(ductmap.find(id) != ductmap.end()) { - ductmap[id].set_name(window->name->text().toStdString()); - + ductmap[id].set_name(_window->segmentname->text().toStdString()); + } + if(ductbcmap.find(id) != ductbcmap.end()) { + ductbcmap[id].set_name(_window->segmentname->text().toStdString()); + } + +} + +void TaSMETMainWindow::on_actionSolve_triggered() { + TRACE(15,"actionSolve()"); + TaSystem sys(_system); + +} +bool TaSMETMainWindow::isDirty() const { + TRACE(15,"isDirty()"); + if(_filepath.size()==0) return true; + + try { + pb::System filesys = loadSystem(_filepath); + bool dirty = !compareSys(filesys,_system); + VARTRACE(15,dirty); + return dirty; + } + catch(TaSMETError& e) { + TRACE(15,"Files could not be compared"); + return true; } } + +void TaSMETMainWindow::on_actionAbout_triggered(){ + + AboutDialog(this).exec(); +} + ////////////////////////////////////////////////////////////////////// diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 44ca38f..ce987ae 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -11,23 +11,66 @@ #include "tasmet_config.h" #include #include "protobuf/system.pb.h" +#include "tasmet_types.h" namespace Ui{ class MainWindow; } class TaSMETMainWindow: public QMainWindow { + // For Qt Q_OBJECT - Ui::MainWindow *window; + + Ui::MainWindow *_window; + + // In-memory system pb::System _system; + + // Where the file is stored + string _filepath = ""; + + bool _init = true; + public: TaSMETMainWindow(); ~TaSMETMainWindow(); +private: + void newModel(); + void loadModel(); + void saveModel(string* filepath=nullptr); + void saveAsModel(); + + // When the user interacts, we call this function to update the + // internal state and set the widget status accordingly + void changed(); + void set(const pb::System&); + + // Check whether the filepath contents agree with the system in + // memory + bool isDirty() const; + private slots: void closeEvent(QCloseEvent *event); void on_addsegment_clicked(); - void on_segmentid_add_valueChanged(int i); + void on_removesegment_clicked(); + void on_segmentid_valueChanged(int i); void on_name_textEdited(); + + // Couple slots to functions + void on_actionNew_triggered() { newModel();} + void on_actionOpen_triggered() { loadModel();} + void on_actionSave_triggered() { saveModel();} + void on_actionSaveAs_triggered() { saveAsModel();} + void on_actionExit_triggered() { closeEvent(NULL);} + void on_actionAbout_triggered(); // Show about dialog + void on_actionSolve_triggered(); // Solve the system + + void on_nf_valueChanged(int) {changed();} + void on_freq_textEdited() {changed();} + void on_gastype_currentIndexChanged(int) {changed();} + void on_T0_textEdited() {changed();} + void on_p0_textEdited() {changed();} + void on_systemtype_currentIndexChanged(int) {changed();} }; diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 22507d0..0e49e9e 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -6,13 +6,17 @@ 0 0 - 1124 - 835 + 683 + 488 MainWindow + + + :/images/tasmet.png:/images/tasmet.png + @@ -56,51 +60,10 @@ - - + + - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - [Hz] - - - - - - - Number of harmonics: - - - - - - - 100 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - - - Reference temperature + System type: @@ -111,57 +74,23 @@ - - + + - 1 + Reference temperature + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - [-] - - - - - - - Fundamental frequency: - - - - - - - - - - System type: - - - - - - - [K] - - - - - - - Reference pressure - - - @@ -172,6 +101,47 @@ + + + + 100 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Reference pressure + + + + + + + Number of harmonics: + + + + + + + [Hz] + + + + + + + Fundamental frequency: + + + + + + @@ -179,6 +149,33 @@ + + + + [K] + + + + + + + + + + + + + + + + + [-] + + + + + + @@ -210,19 +207,12 @@ - + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - Add/edit segment... - - - @@ -231,42 +221,26 @@ - + - - - - - - - - - Remove segment - - - - - - - - Segment ID - - - - - - - + Remove segment... + + + + Add/edit segment... + + + @@ -299,6 +273,12 @@ + + + 0 + 0 + + Type your info here... @@ -310,29 +290,16 @@ - Segment overview + System overview - + - false + true - - - - - - - - - Output - - - - - - false + + true @@ -345,49 +312,6 @@ - - - - Solve - - - - - - Solve... - - - - - - - Reinitialize solution - - - - - - - Postprocess... - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - @@ -395,45 +319,109 @@ 0 0 - 1124 - 21 + 683 + 18 - Fi&le + &File + + + + + Help + + + + + + Solver + + + + + + + + :/images/document-new.png:/images/document-new.png + &New + + New TaSMET Model + + + Ctrl+N + + + + :/images/document-open.png:/images/document-open.png + - &Open + &Open... + + + Ctrl+O + + + :/images/document-save.png:/images/document-save.png + &Save + + Ctrl+S + + + + + + :/images/document-save-as.png:/images/document-save-as.png + + + Save &as... + &Exit + + Ctrl+Q + + + + + &About + + + + + Solve... + - + + + diff --git a/src/gui/solver.ui b/src/gui/solver.ui index 5a21f63..6f3db4b 100644 --- a/src/gui/solver.ui +++ b/src/gui/solver.ui @@ -6,140 +6,183 @@ 0 0 - 711 - 494 + 730 + 362 - Dialog + TaSMET Solver - - - - 10 - 40 - 651 - 341 - - - - - + + + + + + + + 0 + 0 + + + + Solver Settings + + + + + + Maximum iterations: + + + + + + + Solver type + + + + + + + + + + + 0 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Solution tolerance: + + + + + + + Residual tolerance: + + + + + + + + 0 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + 0 + + + + Solve! + + + + + + Solve + + + + + + + Stop + + + + + + + Single iteration + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + 0 + + + + Progress + + - - - Solver Settings - - - - - - Maximum iterations: - - - - - - - Solver type - - - - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Solution tolerance: - - - - - - - Residual tolerance: - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - + - - - Solve! - - - - - - Solve - - - - - - - Stop - - - - - - - Single iteration - - - - - + - - - - - Progress - - - - - - - - - - - - - - solversettings - groupBox - groupBox_2 - solversettings + + + + + + QCustomPlot + QWidget +
qcustomplot.h
+ 1 +
+
diff --git a/src/gui/tasmet_resources.qrc b/src/gui/tasmet_resources.qrc new file mode 100644 index 0000000..a884ef4 --- /dev/null +++ b/src/gui/tasmet_resources.qrc @@ -0,0 +1,9 @@ + + + images/tasmet.png + images/document-new.png + images/document-open.png + images/document-save.png + images/document-save-as.png + + diff --git a/src/main.cpp b/src/main.cpp index 504857c..3f2691f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -83,7 +83,6 @@ int main(int argc, char *argv[]) { TaSMETMainWindow win; - win.setWindowTitle("TaSMET UI"); win.show(); return app.exec(); diff --git a/src/protobuf/ductbc.proto b/src/protobuf/ductbc.proto new file mode 100644 index 0000000..34d9f3c --- /dev/null +++ b/src/protobuf/ductbc.proto @@ -0,0 +1,22 @@ +syntax = "proto2"; +package pb; + +enum DuctBcType { + PressureBc = 0; + AdiabaticWall = 1; + IsoTWall = 2; +} +enum DuctSide { + left = 0; + right = 1; +} +message DuctBc { + required DuctBcType type = 1; + required DuctSide side = 2; + required uint32 duct_id = 3; + optional string pressure = 4; + optional string temperature = 5; + optional bool isentropic = 6; + required string name = 7; + +} diff --git a/src/protobuf/system.proto b/src/protobuf/system.proto index a4f49a8..444de6d 100644 --- a/src/protobuf/system.proto +++ b/src/protobuf/system.proto @@ -2,19 +2,20 @@ syntax = "proto2"; package pb; import "duct.proto"; +import "ductbc.proto"; import "gas.proto"; enum SystemType { TaSystem = 0; } message System { - required SystemType systemtype = 1; - required uint32 Nf = 2; - required double freq = 3; - required GasType gastype = 4; - required double p0 = 5; - required double T0 = 6; + required SystemType systemtype = 1 [default=TaSystem]; + required uint32 Nf = 2 [default=0]; + required double freq = 3 [default = 100]; + required GasType gastype = 4 [default = air]; + required double p0 = 5 [default = 101325]; + required double T0 = 6 [default = 293.15]; map ducts = 7; - repeated double solution = 8; - + map ductbcs = 8; + repeated double solution = 9; } diff --git a/src/sys/globalconf.cpp b/src/sys/globalconf.cpp index 7adad26..0c32e6c 100644 --- a/src/sys/globalconf.cpp +++ b/src/sys/globalconf.cpp @@ -16,7 +16,7 @@ GlobalConf::GlobalConf(us Nf,d freq): TRACE(10,"GlobalConf constructor done"); - if(Nf>=constants::maxNf) + if(Nf>=constants::max_Nf) throw TaSMETError("Too large number of frequencies given"); @@ -60,7 +60,7 @@ void GlobalConf::setomg(d omg){ _DDTfd=zeros(Ns(),Ns()); // Sanity checks - if(omgconstants::maxomg) + if(omgconstants::max_omg) throw TaSMETError("Illegal frequency given"); this->_omg=omg; diff --git a/src/sys/tasystem.cpp b/src/sys/tasystem.cpp index 4160674..db6902d 100644 --- a/src/sys/tasystem.cpp +++ b/src/sys/tasystem.cpp @@ -9,10 +9,12 @@ #include "tasystem.h" #include "triplets.h" #include "jacobian.h" +#include "tasmet_utils.h" #include "tasmet_assert.h" #include "tasmet_exception.h" #include "tasmet_constants.h" #include "duct.h" +#include "ductbc.h" TaSystem::TaSystem(const pb::System& sys): GlobalConf(sys.nf(),sys.freq()) @@ -29,13 +31,33 @@ TaSystem::TaSystem(const pb::System& sys): // Create all ducts for(const auto& d : sys.ducts()) { + // d.first: id + // d.second: duct description try { _segs[d.first] = new Duct(d.first,d.second); if(!_segs[d.first]) throw TaSMETBadAlloc(); } catch(TaSMETError e) { - // Cleanup the already successfully created Ducts + // Cleanup the already successfully created Ducts and rethrow cleanup(); + throw e; + } + } + // Create all ducts + for(const auto& d : sys.ductbcs()) { + // d.first: id + // d.second: duct description + try { + _segs[d.first] = DuctBc::newDuctBc(d.first, + *this, + d.second); + + if(!_segs[d.first]) throw TaSMETBadAlloc(); + } + catch(TaSMETError e) { + // Cleanup the already successfully created Ducts and rethrow + cleanup(); + throw e; } } @@ -311,11 +333,7 @@ TaSystem::~TaSystem() { cleanup(); } void TaSystem::cleanup() { - - for(auto& seg: _segs){ - delete seg.second; - } - + purge(_segs); } ////////////////////////////////////////////////////////////////////// diff --git a/src/tasmet_config.h b/src/tasmet_config.h index 1d69eb2..8663996 100644 --- a/src/tasmet_config.h +++ b/src/tasmet_config.h @@ -18,7 +18,7 @@ const QString company = "None"; // DECLARE_ENUM(SYSTEM_TYPE,DrivenSystem,EngineSystem) DECLARE_ENUM(SystemType,Driven) -DECLARE_ENUM(SegmentType,Duct) +DECLARE_ENUM(SegmentType,Duct,DuctBc) DECLARE_ENUM(SolverType,NewtonRaphson) diff --git a/src/tasmet_constants.h b/src/tasmet_constants.h index ecfeb60..64c114e 100644 --- a/src/tasmet_constants.h +++ b/src/tasmet_constants.h @@ -61,11 +61,11 @@ namespace constants { const us max_ngp=3000; // Maximum number of gridpoints const us default_ngp = 100; - const us maxNf=100; // Maximum number of frequencies - const d minomg=1e-3; // Minimal oscillation frequency - const d maxomg=1e5; + const us max_Nf=20; // Maximum number of frequencies + const d min_omg=1e-3; // Minimal oscillation frequency + const d max_omg=1e5; - const int maxsegs=30; // Maximum number of segments in a TaSystem + const int max_segs=30; // Maximum number of segments in a TaSystem const int maxndofs=600000; // Maximum number of DOFS @@ -105,6 +105,8 @@ namespace constants { const int nvars_reserve=7; const int neqs_reserve=7; + const char* const system_fileext = ".tasmet"; + } // namespace constants #endif // TASMET_CONSTANTS_H diff --git a/src/tasmet_exception.cpp b/src/tasmet_exception.cpp index f77ba4c..ee9dec5 100644 --- a/src/tasmet_exception.cpp +++ b/src/tasmet_exception.cpp @@ -7,6 +7,7 @@ ////////////////////////////////////////////////////////////////////// #include "tasmet_exception.h" +#include const char* TaSMETError::what() const throw() { return _msg.c_str(); @@ -19,7 +20,17 @@ const char* TaSMETBadAlloc::what() const throw() { return "Error: memory allocation failed. " "Please make sure enough memory is available and restart the application"; } +void TaSMETError::show_user(const std::string& window_title, + QMessageBox::Icon icon) { + QString msg = what(); + QMessageBox msgbx(icon, + QString::fromStdString(window_title), + msg); + + msgbx.exec(); + +} ////////////////////////////////////////////////////////////////////// diff --git a/src/tasmet_exception.h b/src/tasmet_exception.h index 5d5e9ae..b58303c 100644 --- a/src/tasmet_exception.h +++ b/src/tasmet_exception.h @@ -12,6 +12,7 @@ #include #include #include // stringstream +#include class TaSMETError : public std::runtime_error { std::string _msg; @@ -28,6 +29,8 @@ public: } void setContext(const std::string& ctx); virtual const char* what() const throw (); + virtual void show_user(const std::string& window_title, + QMessageBox::Icon = QMessageBox::Warning); }; class TaSMETBadAlloc: public std::bad_alloc { diff --git a/src/tasmet_utils.h b/src/tasmet_utils.h index 8db2a96..82f5821 100644 --- a/src/tasmet_utils.h +++ b/src/tasmet_utils.h @@ -1,4 +1,4 @@ -// utils.h +// tasmet_utils.h // // Author: J.A. de Jong // @@ -6,21 +6,12 @@ // Some generic utils. ////////////////////////////////////////////////////////////////////// #pragma once -#ifndef UTILS_H -#define UTILS_H -#include -#include -#include "tracer.h" -#include "vtypes.h" -#include -#include -#include - +#ifndef TASMET_UTILS_H +#define TASMET_UTILS_H // Purge a vector of components template void purge(std::vector& vec){ - TRACE(10,"purge(vector)"); for (T& it: vec){ delete it; it=nullptr; @@ -31,32 +22,12 @@ void purge(std::vector& vec){ // Purge a vector of components template void purge(std::map& map){ - TRACE(10,"purge(map)"); for (auto& it: map){ delete it.second; it.second=nullptr; } map.clear(); } - -template -const T& min(const T& x,const T& y) { - return x<=y? x : y; -} - -template -const T& max(const T& x,const T& y) { - return x<=y? y : x; -} - -template -SegType* copySeg(const SegType& t,const Sys& sys) { - SegType* newt=new SegType(t); - if(!newt){ - WARN("Copying " << typeid(t).name() << "failed!"); - } - return newt; -} // copySeg template void makeNormal(T& c) { for(auto& val: c) @@ -64,8 +35,5 @@ void makeNormal(T& c) { val=0; } -} // namespace utils - - +#endif // TASMET_UTILS_H ////////////////////////////////////////////////////////////////////// -