Commit 5546658b authored by Sébastien Villemot's avatar Sébastien Villemot

Preprocessor: with 'steady_state_model' command, write auxiliary equations in the steady state file

parent d68e984f
...@@ -24,9 +24,9 @@ ...@@ -24,9 +24,9 @@
#include "ModFile.hh" #include "ModFile.hh"
ModFile::ModFile() : expressions_tree(symbol_table, num_constants, external_functions_table), ModFile::ModFile() : expressions_tree(symbol_table, num_constants, external_functions_table),
steady_state_model(symbol_table, num_constants, external_functions_table),
dynamic_model(symbol_table, num_constants, external_functions_table), dynamic_model(symbol_table, num_constants, external_functions_table),
static_model(symbol_table, num_constants, external_functions_table), static_model(symbol_table, num_constants, external_functions_table),
steady_state_model(symbol_table, num_constants, external_functions_table, static_model),
linear(false), block(false), byte_code(false), linear(false), block(false), byte_code(false),
use_dll(false), no_static(false) use_dll(false), no_static(false)
{ {
...@@ -402,14 +402,14 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all ...@@ -402,14 +402,14 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all
InitValStatement *ivs = dynamic_cast<InitValStatement *>(*it); InitValStatement *ivs = dynamic_cast<InitValStatement *>(*it);
if (ivs != NULL) if (ivs != NULL)
{ {
static_model.writeAuxVarInitval(mOutputFile); static_model.writeAuxVarInitval(mOutputFile, oMatlabOutsideModel);
ivs->writeOutputPostInit(mOutputFile); ivs->writeOutputPostInit(mOutputFile);
} }
// Special treatment for load params and steady state statement: insert initial values for the auxiliary variables // Special treatment for load params and steady state statement: insert initial values for the auxiliary variables
LoadParamsAndSteadyStateStatement *lpass = dynamic_cast<LoadParamsAndSteadyStateStatement *>(*it); LoadParamsAndSteadyStateStatement *lpass = dynamic_cast<LoadParamsAndSteadyStateStatement *>(*it);
if (lpass && !no_static) if (lpass && !no_static)
static_model.writeAuxVarInitval(mOutputFile); static_model.writeAuxVarInitval(mOutputFile, oMatlabOutsideModel);
} }
// Remove path for block option with M-files // Remove path for block option with M-files
......
...@@ -48,12 +48,12 @@ public: ...@@ -48,12 +48,12 @@ public:
NumericalConstants num_constants; NumericalConstants num_constants;
//! Expressions outside model block //! Expressions outside model block
DataTree expressions_tree; DataTree expressions_tree;
//! Static model, as declared in the "steady_state_model" block if present
SteadyStateModel steady_state_model;
//! Dynamic model, as declared in the "model" block //! Dynamic model, as declared in the "model" block
DynamicModel dynamic_model; DynamicModel dynamic_model;
//! Static model, as derived from the "model" block when leads and lags have been removed //! Static model, as derived from the "model" block when leads and lags have been removed
StaticModel static_model; StaticModel static_model;
//! Static model, as declared in the "steady_state_model" block if present
SteadyStateModel steady_state_model;
//! Option linear //! Option linear
bool linear; bool linear;
......
...@@ -1362,11 +1362,11 @@ StaticModel::hessianHelper(ostream &output, int row_nb, int col_nb, ExprNodeOutp ...@@ -1362,11 +1362,11 @@ StaticModel::hessianHelper(ostream &output, int row_nb, int col_nb, ExprNodeOutp
} }
void void
StaticModel::writeAuxVarInitval(ostream &output) const StaticModel::writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) const
{ {
for (int i = 0; i < (int) aux_equations.size(); i++) for (int i = 0; i < (int) aux_equations.size(); i++)
{ {
dynamic_cast<ExprNode *>(aux_equations[i])->writeOutput(output); dynamic_cast<ExprNode *>(aux_equations[i])->writeOutput(output, output_type);
output << ";" << endl; output << ";" << endl;
} }
} }
...@@ -187,8 +187,8 @@ public: ...@@ -187,8 +187,8 @@ public:
//! Writes LaTeX file with the equations of the static model //! Writes LaTeX file with the equations of the static model
void writeLatexFile(const string &basename) const; void writeLatexFile(const string &basename) const;
//! Writes initializations in oo_.steady_state for the auxiliary variables //! Writes initializations in oo_.steady_state or steady state file for the auxiliary variables
void writeAuxVarInitval(ostream &output) const; void writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) const;
//! Initialize equation_reordered & variable_reordered //! Initialize equation_reordered & variable_reordered
void initializeVariablesAndEquations(); void initializeVariablesAndEquations();
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
#include "SteadyStateModel.hh" #include "SteadyStateModel.hh"
SteadyStateModel::SteadyStateModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants, ExternalFunctionsTable &external_functions_table_arg) : SteadyStateModel::SteadyStateModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants, ExternalFunctionsTable &external_functions_table_arg, const StaticModel &static_model_arg) :
DataTree(symbol_table_arg, num_constants, external_functions_table) DataTree(symbol_table_arg, num_constants, external_functions_table), static_model(static_model_arg)
{ {
} }
...@@ -81,6 +81,8 @@ SteadyStateModel::writeSteadyStateFile(const string &basename) const ...@@ -81,6 +81,8 @@ SteadyStateModel::writeSteadyStateFile(const string &basename) const
it->second->writeOutput(output, oSteadyStateFile); it->second->writeOutput(output, oSteadyStateFile);
output << ";" << endl; output << ";" << endl;
} }
output << " % Auxiliary equations" << endl;
static_model.writeAuxVarInitval(output, oSteadyStateFile);
output << " check_=0;" << endl output << " check_=0;" << endl
<< "end" << endl; << "end" << endl;
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define _STEADY_STATE_MODEL_HH #define _STEADY_STATE_MODEL_HH
#include "DataTree.hh" #include "DataTree.hh"
#include "StaticModel.hh"
class SteadyStateModel : public DataTree class SteadyStateModel : public DataTree
{ {
...@@ -29,6 +30,9 @@ private: ...@@ -29,6 +30,9 @@ private:
map<int, NodeID> def_table; map<int, NodeID> def_table;
vector<int> recursive_order; vector<int> recursive_order;
//! Reference to static model (for writing auxiliary equations)
const StaticModel &static_model;
public: public:
class AlreadyDefinedException class AlreadyDefinedException
{ {
...@@ -43,7 +47,7 @@ public: ...@@ -43,7 +47,7 @@ public:
UndefinedVariableException(const string &varname_arg) : varname(varname_arg) {} UndefinedVariableException(const string &varname_arg) : varname(varname_arg) {}
}; };
SteadyStateModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants, ExternalFunctionsTable &external_functions_table_arg); SteadyStateModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants, ExternalFunctionsTable &external_functions_table_arg, const StaticModel &static_model_arg);
//! Add an expression of the form "var = expr;" //! Add an expression of the form "var = expr;"
void addDefinition(int symb_id, NodeID expr) throw (UndefinedVariableException, AlreadyDefinedException); void addDefinition(int symb_id, NodeID expr) throw (UndefinedVariableException, AlreadyDefinedException);
//! Write the steady state file //! Write the steady state file
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment