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
#define PRESSUREBC_H
#include "segment.h"
#include "ductbc.pb.h"
class TaSystem;
namespace pb{
class DuctBc;
}
class Variable;
class PressureBc: public Segment {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,6 @@
//////////////////////////////////////////////////////////////////////
#include "message_tools.h"
#include <fstream>
#include <google/protobuf/text_format.h>
#include "tasmet_types.h"
#include "tasmet_io.h"
#include "tasmet_exception.h"
@ -77,9 +76,14 @@ bool compareMessage(const T& s1,const T& s2) {
return (s1.SerializeAsString()==s2.SerializeAsString());
}
template <>
// Explicit instantiation for pb::Model
template
bool compareMessage<pb::Model>(const pb::Model& s1,const pb::Model& s2);
template <>
template
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
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
const auto& sol = sys.solution();
us size = sol.size(), i=0;
if(size>0) {
_solution = vd(size);
for(auto& val: sol) {
_solution(i) = val;
i++;
}
}
// const auto& sol = sys.solution();
// us size = sol.size(), i=0;
// if(size>0) {
// _solution = vd(size);
// for(auto& val: sol) {
// _solution(i) = val;
// i++;
// }
// }
}
TaSystem::TaSystem(const TaSystem& o):

View File

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

View File

@ -5,11 +5,11 @@
// Description:
// 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_exception.h"
#include "sys/tasystem.h"
#include "protobuf/model.pb.h"
// For using python from within Qt
#include <PythonQt.h>
@ -39,11 +39,11 @@ int main(int argc, char *argv[]) {
return -1;
}
pb::System sys;
pb::Model model;
string filename = argv[1];
try {
sys = loadSystem(filename);
model = loadMessage<pb::Model>(filename);
}
catch(TaSMETError &e) {
cerr << e.what() << endl;
@ -51,12 +51,12 @@ int main(int argc, char *argv[]) {
}
cout << "Loaded model: " << endl;
cout << sys.DebugString();
cout << model.system().DebugString();
TaSystem* system;
try {
system = new TaSystem(sys);
system = new TaSystem(model.system());
}
catch(TaSMETError &e) {
cerr << "Model initialization error: " << endl;