Updated all GUI stuff to new protobuf config of model containing a system, solver and solution

This commit is contained in:
Anne de Jong 2017-01-05 16:25:16 +01:00
parent c4ffca4640
commit e255b9e2c9
16 changed files with 650 additions and 635 deletions

View File

@ -9,11 +9,8 @@
#ifndef PRESSUREBC_H #ifndef PRESSUREBC_H
#define PRESSUREBC_H #define PRESSUREBC_H
#include "segment.h" #include "segment.h"
#include "ductbc.pb.h"
class TaSystem; class TaSystem;
namespace pb{
class DuctBc;
}
class Variable; class Variable;
class PressureBc: public Segment { class PressureBc: public Segment {

View File

@ -54,8 +54,8 @@ namespace {
TaSMETMainWindow::TaSMETMainWindow(): TaSMETMainWindow::TaSMETMainWindow():
_window(new Ui::MainWindow()), _window(new Ui::MainWindow()),
_model(pb::Model::default_instance()) _model(pb::Model::default_instance()),
_system(*_model.mutable_sytem()) _system(*_model.mutable_system())
{ {
if(!_window) throw TaSMETBadAlloc(); if(!_window) throw TaSMETBadAlloc();
@ -224,7 +224,7 @@ void TaSMETMainWindow::changed() {
windowtitle += QString::fromStdString(_filepath); windowtitle += QString::fromStdString(_filepath);
} }
else { else {
windowtitle += default_system_name; windowtitle += default_model_name;
} }
setWindowTitle(windowtitle); setWindowTitle(windowtitle);
@ -254,10 +254,11 @@ void TaSMETMainWindow::changed() {
} }
void TaSMETMainWindow::set(const pb::System& sys) { void TaSMETMainWindow::set(const pb::Model& model) {
TRACE(15,"set()"); TRACE(15,"set()");
_init = true; _init = true;
const pb::System& sys = model.system();
_window->nf->setValue(sys.nf()); _window->nf->setValue(sys.nf());
_window->freq->setText(QString::number(sys.freq())); _window->freq->setText(QString::number(sys.freq()));
_window->p0->setText(QString::number(sys.p0())); _window->p0->setText(QString::number(sys.p0()));
@ -265,7 +266,8 @@ void TaSMETMainWindow::set(const pb::System& sys) {
_window->systemtype->setCurrentIndex((int) sys.systemtype()); _window->systemtype->setCurrentIndex((int) sys.systemtype());
_window->gastype->setCurrentIndex((int) sys.gastype()); _window->gastype->setCurrentIndex((int) sys.gastype());
_system = sys; _model = model;
_system = *_model.mutable_system();
_init = false; _init = false;
changed(); changed();
@ -406,7 +408,7 @@ void TaSMETMainWindow::on_actionSolve_triggered() {
SolverDialog *d; SolverDialog *d;
try { try {
d = new SolverDialog(this,_system); d = new SolverDialog(this,_system,*_model.mutable_sparams());
} }
catch(TaSMETError &e) { catch(TaSMETError &e) {
e.show_user("Solver failed to initialize"); e.show_user("Solver failed to initialize");
@ -425,8 +427,8 @@ bool TaSMETMainWindow::isDirty() const {
if(_filepath.size()==0) return true; if(_filepath.size()==0) return true;
try { try {
pb::System filesys = loadSystem(_filepath); pb::Model filemodel = loadMessage<pb::Model>(_filepath);
bool dirty = !compareSys(filesys,_system); bool dirty = !compareMessage<pb::Model>(filemodel,_model);
VARTRACE(15,dirty); VARTRACE(15,dirty);
return dirty; return dirty;
} }

View File

@ -9,6 +9,8 @@
#include "solver_dialog.h" #include "solver_dialog.h"
#include "ui_solver_dialog.h" #include "ui_solver_dialog.h"
#include "system.pb.h" #include "system.pb.h"
#include "solver.pb.h"
#include "tasmet_exception.h" #include "tasmet_exception.h"
#include "tasmet_constants.h" #include "tasmet_constants.h"
#include "tasmet_tracer.h" #include "tasmet_tracer.h"
@ -20,9 +22,11 @@
#include <qcustomplot.h> #include <qcustomplot.h>
SolverDialog::SolverDialog(QWidget* parent, SolverDialog::SolverDialog(QWidget* parent,
pb::System& sys): pb::System& sys,
pb::SolverParams& sparams):
QDialog(parent), QDialog(parent),
_sys(sys), _sys(sys),
_sparams(sparams),
_dialog(new Ui::solver_dialog()) _dialog(new Ui::solver_dialog())
{ {
@ -85,7 +89,7 @@ SolverDialog::SolverDialog(QWidget* parent,
_plot->legend->setVisible(true); _plot->legend->setVisible(true);
_plot->replot(); _plot->replot();
set(_sys.solverparams()); set(_sparams);
setEnabled(true); setEnabled(true);
@ -113,9 +117,9 @@ void SolverDialog::set(const pb::SolverParams& sol) {
void SolverDialog::changed() { void SolverDialog::changed() {
TRACE(15,"changed"); TRACE(15,"changed");
if(_init) return; if(_init) return;
_sys.mutable_solverparams()->set_funtol(_dialog->funtol->text().toDouble()); _sparams.set_funtol(_dialog->funtol->text().toDouble());
_sys.mutable_solverparams()->set_reltol(_dialog->reltol->text().toDouble()); _sparams.set_reltol(_dialog->reltol->text().toDouble());
_sys.mutable_solverparams()->set_solvertype((pb::SolverType) _dialog->solvertype->currentIndex()); _sparams.set_solvertype((pb::SolverType) _dialog->solvertype->currentIndex());
} }
void SolverDialog::solver_progress(const SolverProgress& progress){ void SolverDialog::solver_progress(const SolverProgress& progress){
@ -123,8 +127,8 @@ void SolverDialog::solver_progress(const SolverProgress& progress){
// VARTRACE(15,progress.fun_err); // VARTRACE(15,progress.fun_err);
// VARTRACE(15,progress.iteration); // VARTRACE(15,progress.iteration);
d funtol = _sys.solverparams().funtol(); d funtol = _sparams.funtol();
d reltol = _sys.solverparams().reltol(); d reltol = _sparams.reltol();
_funer->addData(progress.iteration,progress.fun_err); _funer->addData(progress.iteration,progress.fun_err);
_reler->addData(progress.iteration,progress.rel_err); _reler->addData(progress.iteration,progress.rel_err);
@ -160,7 +164,7 @@ void SolverDialog::on_solve_clicked() {
qRegisterMetaType<SolverProgress>(); qRegisterMetaType<SolverProgress>();
_solver_worker = new SolverWorker(_sys); _solver_worker = new SolverWorker(_sys,_sparams);
QThread* thread = new QThread; QThread* thread = new QThread;
_solver_worker->moveToThread(thread); _solver_worker->moveToThread(thread);

View File

@ -15,10 +15,12 @@
namespace pb { namespace pb {
class System; class System;
class SolverParams;
} }
namespace Ui { namespace Ui {
class solver_dialog; class solver_dialog;
} }
class QCustomPlot; class QCustomPlot;
class QCPGraph; class QCPGraph;
class SolverWorker; class SolverWorker;
@ -28,6 +30,7 @@ class SolverDialog: public QDialog {
Q_OBJECT Q_OBJECT
pb::System& _sys; // Reference to system pb::System& _sys; // Reference to system
pb::SolverParams& _sparams;
Ui::solver_dialog* _dialog; Ui::solver_dialog* _dialog;
@ -41,11 +44,11 @@ class SolverDialog: public QDialog {
public: public:
SolverDialog(QWidget* parent, SolverDialog(QWidget* parent,
pb::System& sys); pb::System& sys,
pb::SolverParams& sparams);
~SolverDialog(); ~SolverDialog();
void set(const pb::SolverParams&);
public slots: public slots:
void solver_progress(const SolverProgress&); void solver_progress(const SolverProgress&);
private slots: private slots:
@ -64,6 +67,7 @@ private:
// Called whenever the user changes input values // Called whenever the user changes input values
void changed(); void changed();
void setEnabled(bool); void setEnabled(bool);
void set(const pb::SolverParams&);
}; };

View File

@ -9,13 +9,17 @@
#include "solver_worker.h" #include "solver_worker.h"
#include <functional> #include <functional>
#include "tasmet_tracer.h" #include "tasmet_tracer.h"
#include "system.pb.h" #include "system.pb.h"
#include "solver.pb.h"
#include <QThread> #include <QThread>
#include <qcustomplot.h>
SolverWorker::SolverWorker(pb::System& sys):
SolverWorker::SolverWorker(const pb::System& sys,const pb::SolverParams& sparams):
_run(false), _run(false),
_reltol(sys.solverparams().reltol()), _reltol(sparams.reltol()),
_funtol(sys.solverparams().funtol()) _funtol(sparams.funtol())
{ {
} }

View File

@ -16,6 +16,7 @@
#include <QObject> #include <QObject>
namespace pb{ namespace pb{
class System; class System;
class SolverParams;
} }
Q_DECLARE_METATYPE(SolverProgress); Q_DECLARE_METATYPE(SolverProgress);
@ -28,8 +29,7 @@ class SolverWorker: public QObject {
bool _converged = false; bool _converged = false;
d _funtol,_reltol; d _funtol,_reltol;
public: public:
SolverWorker(const pb::System& sys,const pb::SolverParams& sparams);
SolverWorker(pb::System& sys);
~SolverWorker(); ~SolverWorker();
void solver_stop(); void solver_stop();

View File

@ -7,7 +7,6 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "message_tools.h" #include "message_tools.h"
#include <fstream> #include <fstream>
#include <google/protobuf/text_format.h>
#include "tasmet_types.h" #include "tasmet_types.h"
#include "tasmet_io.h" #include "tasmet_io.h"
#include "tasmet_exception.h" #include "tasmet_exception.h"
@ -77,9 +76,14 @@ bool compareMessage(const T& s1,const T& s2) {
return (s1.SerializeAsString()==s2.SerializeAsString()); return (s1.SerializeAsString()==s2.SerializeAsString());
} }
template <> // Explicit instantiation for pb::Model
template
bool compareMessage<pb::Model>(const pb::Model& s1,const pb::Model& s2); bool compareMessage<pb::Model>(const pb::Model& s1,const pb::Model& s2);
template <>
template
pb::Model loadMessage(const string& filepath); pb::Model loadMessage(const string& filepath);
template
void saveMessage<pb::Model>(const string& filepath,const pb::Model& model);
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////

View File

@ -21,7 +21,7 @@ void saveMessage(const string& filepath,const T& sys);
// Returns true when the two systems are equal // Returns true when the two systems are equal
template<typename T> template<typename T>
bool compareSys(const T& s1,const T& s2); bool compareMessage(const T& s1,const T& s2);

View File

@ -62,15 +62,15 @@ TaSystem::TaSystem(const pb::System& sys):
} }
// Copy solution vector, if valid // Copy solution vector, if valid
const auto& sol = sys.solution(); // const auto& sol = sys.solution();
us size = sol.size(), i=0; // us size = sol.size(), i=0;
if(size>0) { // if(size>0) {
_solution = vd(size); // _solution = vd(size);
for(auto& val: sol) { // for(auto& val: sol) {
_solution(i) = val; // _solution(i) = val;
i++; // i++;
} // }
} // }
} }
TaSystem::TaSystem(const TaSystem& o): TaSystem::TaSystem(const TaSystem& o):

View File

@ -105,7 +105,7 @@ namespace constants {
const int nvars_reserve=7; const int nvars_reserve=7;
const int neqs_reserve=7; const int neqs_reserve=7;
const char* const system_fileext = ".tasmet"; const char* const model_fileext = ".tasmet";
} // namespace constants } // namespace constants

View File

@ -5,11 +5,11 @@
// Description: // Description:
// Program which can be used to solve a TaSMET Model from the CLI // Program which can be used to solve a TaSMET Model from the CLI
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "protobuf/system_tools.h" // loadSystem, saveSystem #include "protobuf/message_tools.h" // loadSystem, saveSystem
#include "tasmet_io.h" #include "tasmet_io.h"
#include "tasmet_exception.h" #include "tasmet_exception.h"
#include "sys/tasystem.h" #include "sys/tasystem.h"
#include "protobuf/model.pb.h"
// For using python from within Qt // For using python from within Qt
#include <PythonQt.h> #include <PythonQt.h>
@ -39,11 +39,11 @@ int main(int argc, char *argv[]) {
return -1; return -1;
} }
pb::System sys; pb::Model model;
string filename = argv[1]; string filename = argv[1];
try { try {
sys = loadSystem(filename); model = loadMessage<pb::Model>(filename);
} }
catch(TaSMETError &e) { catch(TaSMETError &e) {
cerr << e.what() << endl; cerr << e.what() << endl;
@ -51,12 +51,12 @@ int main(int argc, char *argv[]) {
} }
cout << "Loaded model: " << endl; cout << "Loaded model: " << endl;
cout << sys.DebugString(); cout << model.system().DebugString();
TaSystem* system; TaSystem* system;
try { try {
system = new TaSystem(sys); system = new TaSystem(model.system());
} }
catch(TaSMETError &e) { catch(TaSMETError &e) {
cerr << "Model initialization error: " << endl; cerr << "Model initialization error: " << endl;