Commit b0f252c2 authored by sebastien's avatar sebastien
Browse files

Some restructurings in the preprocessor:

* StaticModel: dropped creation of C file in USE_DLL mode
* StaticModel: added computation of derivatives for block MFS mode
* DynamicModel: catch error codes of mkdir()
* ModelTree: moved "mode" member variable to DynamicModel
* ModFile::writeOutput(): moved manipulations relative to dynamic model file to DynamicModel


git-svn-id: https://www.dynare.org/svn/dynare/trunk@2818 ac1d8469-bf42-47a9-8791-bf33cf982152
parent c8966e24
...@@ -81,7 +81,7 @@ void ModelInfoStatement::writeOutput(ostream &output, const string &basename) co ...@@ -81,7 +81,7 @@ void ModelInfoStatement::writeOutput(ostream &output, const string &basename) co
} }
SimulStatement::SimulStatement(const OptionsList &options_list_arg, ModelTreeMode mode_arg) : SimulStatement::SimulStatement(const OptionsList &options_list_arg, DynamicModel::mode_t mode_arg) :
options_list(options_list_arg), mode(mode_arg) options_list(options_list_arg), mode(mode_arg)
{ {
} }
...@@ -96,7 +96,7 @@ void ...@@ -96,7 +96,7 @@ void
SimulStatement::writeOutput(ostream &output, const string &basename) const SimulStatement::writeOutput(ostream &output, const string &basename) const
{ {
options_list.writeOutput(output); options_list.writeOutput(output);
if (mode == eStandardMode || mode == eDLLMode) if (mode == DynamicModel::eStandardMode || mode == DynamicModel::eDLLMode)
output << "simul(oo_.dr);\n"; output << "simul(oo_.dr);\n";
else else
{ {
...@@ -108,7 +108,7 @@ SimulStatement::writeOutput(ostream &output, const string &basename) const ...@@ -108,7 +108,7 @@ SimulStatement::writeOutput(ostream &output, const string &basename) const
<< " read_data_;" << endl << " read_data_;" << endl
<< " end" << endl << " end" << endl
<< "end" << endl; << "end" << endl;
if (mode == eSparseDLLMode) if (mode == DynamicModel::eSparseDLLMode)
output << "oo_.endo_simul=simulate;" << endl; output << "oo_.endo_simul=simulate;" << endl;
else else
output << basename << "_dynamic;" << endl; output << basename << "_dynamic;" << endl;
...@@ -118,7 +118,7 @@ SimulStatement::writeOutput(ostream &output, const string &basename) const ...@@ -118,7 +118,7 @@ SimulStatement::writeOutput(ostream &output, const string &basename) const
StochSimulStatement::StochSimulStatement(const SymbolList &symbol_list_arg, StochSimulStatement::StochSimulStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg, const OptionsList &options_list_arg,
ModelTreeMode mode_arg) : DynamicModel::mode_t mode_arg) :
symbol_list(symbol_list_arg), symbol_list(symbol_list_arg),
options_list(options_list_arg), options_list(options_list_arg),
mode(mode_arg) mode(mode_arg)
...@@ -149,7 +149,7 @@ StochSimulStatement::writeOutput(ostream &output, const string &basename) const ...@@ -149,7 +149,7 @@ StochSimulStatement::writeOutput(ostream &output, const string &basename) const
{ {
options_list.writeOutput(output); options_list.writeOutput(output);
symbol_list.writeOutput("var_list_", output); symbol_list.writeOutput("var_list_", output);
if (mode == eStandardMode || mode == eDLLMode) if (mode == DynamicModel::eStandardMode || mode == DynamicModel::eDLLMode)
output << "info = stoch_simul(var_list_);" << endl; output << "info = stoch_simul(var_list_);" << endl;
else else
output << "info = stoch_simul_sparse(var_list_);" << endl; output << "info = stoch_simul_sparse(var_list_);" << endl;
......
...@@ -52,9 +52,9 @@ class SimulStatement : public Statement ...@@ -52,9 +52,9 @@ class SimulStatement : public Statement
{ {
private: private:
const OptionsList options_list; const OptionsList options_list;
const ModelTreeMode mode; const DynamicModel::mode_t mode;
public: public:
SimulStatement(const OptionsList &options_list_arg, ModelTreeMode mode_arg); SimulStatement(const OptionsList &options_list_arg, DynamicModel::mode_t mode_arg);
virtual void checkPass(ModFileStructure &mod_file_struct); virtual void checkPass(ModFileStructure &mod_file_struct);
virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeOutput(ostream &output, const string &basename) const;
}; };
...@@ -74,11 +74,11 @@ class StochSimulStatement : public Statement ...@@ -74,11 +74,11 @@ class StochSimulStatement : public Statement
private: private:
const SymbolList symbol_list; const SymbolList symbol_list;
const OptionsList options_list; const OptionsList options_list;
const ModelTreeMode mode; const DynamicModel::mode_t mode;
public: public:
StochSimulStatement(const SymbolList &symbol_list_arg, StochSimulStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg, const OptionsList &options_list_arg,
ModelTreeMode mode_arg); DynamicModel::mode_t mode_arg);
virtual void checkPass(ModFileStructure &mod_file_struct); virtual void checkPass(ModFileStructure &mod_file_struct);
virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeOutput(ostream &output, const string &basename) const;
}; };
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include <cstdio>
#include <cerrno>
#include "DynamicModel.hh" #include "DynamicModel.hh"
...@@ -41,6 +43,7 @@ DynamicModel::DynamicModel(SymbolTable &symbol_table_arg, ...@@ -41,6 +43,7 @@ DynamicModel::DynamicModel(SymbolTable &symbol_table_arg,
max_exo_lag(0), max_exo_lead(0), max_exo_lag(0), max_exo_lead(0),
max_exo_det_lag(0), max_exo_det_lead(0), max_exo_det_lag(0), max_exo_det_lead(0),
dynJacobianColsNbr(0), dynJacobianColsNbr(0),
mode(eStandardMode),
cutoff(1e-15), cutoff(1e-15),
markowitz(0.7), markowitz(0.7),
block_triangular(symbol_table_arg, num_constants_arg) block_triangular(symbol_table_arg, num_constants_arg)
...@@ -2119,8 +2122,22 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput) const ...@@ -2119,8 +2122,22 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput) const
} }
void void
DynamicModel::writeOutput(ostream &output) const DynamicModel::writeOutput(ostream &output, const string &basename) const
{ {
output << "options_.model_mode = " << mode << ";" << endl;
// Erase possible remnants of previous runs
if (mode != eStandardMode)
output << "delete('" << basename << "_dynamic.m');" << endl;
if (mode != eDLLMode)
output << "erase_compiled_function('" + basename + "_dynamic');" << endl;
// Special setup for DLL or Sparse modes
if (mode == eDLLMode)
output << "mex -O LDFLAGS='-pthread -shared -Wl,--no-undefined' " << basename << "_dynamic.c" << endl;
if (mode == eSparseMode || mode == eSparseDLLMode)
output << "addpath " << basename << ";" << endl;
/* Writing initialisation for M_.lead_lag_incidence matrix /* Writing initialisation for M_.lead_lag_incidence matrix
M_.lead_lag_incidence is a matrix with as many columns as there are M_.lead_lag_incidence is a matrix with as many columns as there are
endogenous variables and as many rows as there are periods in the endogenous variables and as many rows as there are periods in the
...@@ -2352,6 +2369,13 @@ DynamicModel::writeOutput(ostream &output) const ...@@ -2352,6 +2369,13 @@ DynamicModel::writeOutput(ostream &output) const
<< "M_.NNZDerivatives(3) = " << NNZDerivatives[2] << ";" << endl; << "M_.NNZDerivatives(3) = " << NNZDerivatives[2] << ";" << endl;
} }
void
DynamicModel::writeOutputPostComputing(ostream &output, const string &basename) const
{
if (mode == eSparseMode || mode == eSparseDLLMode)
output << "rmpath " << basename << ";" << endl;
}
void void
DynamicModel::evaluateJacobian(const eval_context_type &eval_context, jacob_map *j_m) DynamicModel::evaluateJacobian(const eval_context_type &eval_context, jacob_map *j_m)
{ {
...@@ -2576,12 +2600,13 @@ DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivative ...@@ -2576,12 +2600,13 @@ DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivative
} }
else else
if (!no_tmp_terms) if (!no_tmp_terms)
computeTemporaryTerms(); computeTemporaryTerms(mode == eStandardMode);
} }
void void
DynamicModel::writeDynamicFile(const string &basename) const DynamicModel::writeDynamicFile(const string &basename) const
{ {
int r;
switch (mode) switch (mode)
{ {
case eStandardMode: case eStandardMode:
...@@ -2589,10 +2614,15 @@ DynamicModel::writeDynamicFile(const string &basename) const ...@@ -2589,10 +2614,15 @@ DynamicModel::writeDynamicFile(const string &basename) const
break; break;
case eSparseMode: case eSparseMode:
#ifdef _WIN32 #ifdef _WIN32
mkdir(basename.c_str()); r = mkdir(basename.c_str());
#else #else
mkdir(basename.c_str(), 0777); r = mkdir(basename.c_str(), 0777);
#endif #endif
if (r < 0 && errno != EEXIST)
{
perror("ERROR");
exit(EXIT_FAILURE);
}
writeSparseDynamicMFile(basename + "_dynamic", basename, mode); writeSparseDynamicMFile(basename + "_dynamic", basename, mode);
block_triangular.Free_Block(block_triangular.ModelBlock); block_triangular.Free_Block(block_triangular.ModelBlock);
block_triangular.incidencematrix.Free_IM(); block_triangular.incidencematrix.Free_IM();
...@@ -2604,10 +2634,15 @@ DynamicModel::writeDynamicFile(const string &basename) const ...@@ -2604,10 +2634,15 @@ DynamicModel::writeDynamicFile(const string &basename) const
case eSparseDLLMode: case eSparseDLLMode:
// create a directory to store all the files // create a directory to store all the files
#ifdef _WIN32 #ifdef _WIN32
mkdir(basename.c_str()); r = mkdir(basename.c_str());
#else #else
mkdir(basename.c_str(), 0777); r = mkdir(basename.c_str(), 0777);
#endif #endif
if (r < 0 && errno != EEXIST)
{
perror("ERROR");
exit(EXIT_FAILURE);
}
writeModelEquationsCodeOrdered(basename + "_dynamic", block_triangular.ModelBlock, basename, map_idx); writeModelEquationsCodeOrdered(basename + "_dynamic", block_triangular.ModelBlock, basename, map_idx);
block_triangular.Free_Block(block_triangular.ModelBlock); block_triangular.Free_Block(block_triangular.ModelBlock);
block_triangular.incidencematrix.Free_IM(); block_triangular.incidencematrix.Free_IM();
...@@ -2619,8 +2654,6 @@ DynamicModel::writeDynamicFile(const string &basename) const ...@@ -2619,8 +2654,6 @@ DynamicModel::writeDynamicFile(const string &basename) const
void void
DynamicModel::toStatic(StaticModel &static_model) const DynamicModel::toStatic(StaticModel &static_model) const
{ {
static_model.mode = mode;
// Convert model local variables (need to be done first) // Convert model local variables (need to be done first)
for (map<int, NodeID>::const_iterator it = local_variables_table.begin(); for (map<int, NodeID>::const_iterator it = local_variables_table.begin();
it != local_variables_table.end(); it++) it != local_variables_table.end(); it++)
...@@ -2871,3 +2904,25 @@ DynamicModel::writeLatexFile(const string &basename) const ...@@ -2871,3 +2904,25 @@ DynamicModel::writeLatexFile(const string &basename) const
{ {
writeLatexModelFile(basename + "_dynamic.tex", oLatexDynamicModel); writeLatexModelFile(basename + "_dynamic.tex", oLatexDynamicModel);
} }
void
DynamicModel::jacobianHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const
{
output << LEFT_ARRAY_SUBSCRIPT(output_type);
if (IS_MATLAB(output_type))
output << eq_nb + 1 << ", " << col_nb + 1;
else
output << eq_nb + col_nb * equations.size();
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
}
void
DynamicModel::hessianHelper(ostream &output, int row_nb, int col_nb, ExprNodeOutputType output_type) const
{
output << LEFT_ARRAY_SUBSCRIPT(output_type);
if (IS_MATLAB(output_type))
output << row_nb + 1 << ", " << col_nb + 1;
else
output << row_nb + col_nb * NNZDerivatives[1];
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
}
...@@ -30,6 +30,15 @@ using namespace std; ...@@ -30,6 +30,15 @@ using namespace std;
//! Stores a dynamic model //! Stores a dynamic model
class DynamicModel : public ModelTree class DynamicModel : public ModelTree
{ {
public:
//! The modes in which DynamicModel can work
enum mode_t
{
eStandardMode, //!< Standard mode (dynamic file in Matlab)
eSparseMode, //!< Sparse mode (dynamic file in Matlab with block decomposition)
eDLLMode, //!< DLL mode (dynamic file in C)
eSparseDLLMode //!< Sparse DLL mode (dynamic file in C with block decomposition plus a binary file)
};
private: private:
typedef map<pair<int, int>, int> deriv_id_table_t; typedef map<pair<int, int>, int> deriv_id_table_t;
//! Maps a pair (symbol_id, lag) to a deriv ID //! Maps a pair (symbol_id, lag) to a deriv ID
...@@ -114,8 +123,18 @@ private: ...@@ -114,8 +123,18 @@ private:
//! Collect only the first derivatives //! Collect only the first derivatives
map<pair<int, pair<int, int> >, NodeID> collect_first_order_derivatives_endogenous(); map<pair<int, pair<int, int> >, NodeID> collect_first_order_derivatives_endogenous();
//! Helper for writing the Jacobian elements in MATLAB and C
/*! Writes either (i+1,j+1) or [i+j*no_eq] */
void jacobianHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const;
//! Helper for writing the sparse Hessian elements in MATLAB and C
/*! Writes either (i+1,j+1) or [i+j*NNZDerivatives[1]] */
void hessianHelper(ostream &output, int row_nb, int col_nb, ExprNodeOutputType output_type) const;
public: public:
DynamicModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants); DynamicModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants);
//! Mode in which the ModelTree is supposed to work (Matlab, DLL or SparseDLL)
mode_t mode;
//! Adds a variable node //! Adds a variable node
/*! This implementation allows for non-zero lag */ /*! This implementation allows for non-zero lag */
virtual NodeID AddVariable(const string &name, int lag = 0); virtual NodeID AddVariable(const string &name, int lag = 0);
...@@ -137,7 +156,9 @@ public: ...@@ -137,7 +156,9 @@ public:
void computingPass(bool jacobianExo, bool hessian, bool thirdDerivatives, bool paramsDerivatives, void computingPass(bool jacobianExo, bool hessian, bool thirdDerivatives, bool paramsDerivatives,
const eval_context_type &eval_context, bool no_tmp_terms); const eval_context_type &eval_context, bool no_tmp_terms);
//! Writes model initialization and lead/lag incidence matrix to output //! Writes model initialization and lead/lag incidence matrix to output
void writeOutput(ostream &output) const; void writeOutput(ostream &output, const string &basename) const;
//! Write statements to be added to the main M-file, after computational tasks
void writeOutputPostComputing(ostream &output, const string &basename) const;
//! Complete set to block decompose the model //! Complete set to block decompose the model
BlockTriangular block_triangular; BlockTriangular block_triangular;
//! Adds informations for simulation in a binary file //! Adds informations for simulation in a binary file
......
...@@ -329,7 +329,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type, ...@@ -329,7 +329,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
break; break;
case oMatlabStaticModel: case oMatlabStaticModel:
case oMatlabStaticModelSparse: case oMatlabStaticModelSparse:
case oCStaticModel:
i = tsid + ARRAY_SUBSCRIPT_OFFSET(output_type); i = tsid + ARRAY_SUBSCRIPT_OFFSET(output_type);
output << "y" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << RIGHT_ARRAY_SUBSCRIPT(output_type); output << "y" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << RIGHT_ARRAY_SUBSCRIPT(output_type);
break; break;
...@@ -373,7 +372,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type, ...@@ -373,7 +372,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
break; break;
case oMatlabStaticModel: case oMatlabStaticModel:
case oMatlabStaticModelSparse: case oMatlabStaticModelSparse:
case oCStaticModel:
output << "x" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << RIGHT_ARRAY_SUBSCRIPT(output_type); output << "x" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << RIGHT_ARRAY_SUBSCRIPT(output_type);
break; break;
case oMatlabOutsideModel: case oMatlabOutsideModel:
...@@ -408,7 +406,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type, ...@@ -408,7 +406,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
break; break;
case oMatlabStaticModel: case oMatlabStaticModel:
case oMatlabStaticModelSparse: case oMatlabStaticModelSparse:
case oCStaticModel:
output << "x" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << RIGHT_ARRAY_SUBSCRIPT(output_type); output << "x" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << RIGHT_ARRAY_SUBSCRIPT(output_type);
break; break;
case oMatlabOutsideModel: case oMatlabOutsideModel:
......
...@@ -55,7 +55,6 @@ enum ExprNodeOutputType ...@@ -55,7 +55,6 @@ enum ExprNodeOutputType
oMatlabDynamicModel, //!< Matlab code, dynamic model declarations oMatlabDynamicModel, //!< Matlab code, dynamic model declarations
oMatlabStaticModelSparse, //!< Matlab code, static block decomposed mode declaration oMatlabStaticModelSparse, //!< Matlab code, static block decomposed mode declaration
oMatlabDynamicModelSparse,//!< Matlab code, dynamic block decomposed mode declaration oMatlabDynamicModelSparse,//!< Matlab code, dynamic block decomposed mode declaration
oCStaticModel, //!< C code, static model declarations
oCDynamicModel, //!< C code, dynamic model declarations oCDynamicModel, //!< C code, dynamic model declarations
oMatlabOutsideModel, //!< Matlab code, outside model block (for example in initval) oMatlabOutsideModel, //!< Matlab code, outside model block (for example in initval)
oLatexStaticModel, //!< LaTeX code, static model declarations oLatexStaticModel, //!< LaTeX code, static model declarations
...@@ -68,8 +67,7 @@ enum ExprNodeOutputType ...@@ -68,8 +67,7 @@ enum ExprNodeOutputType
|| (output_type) == oMatlabStaticModelSparse \ || (output_type) == oMatlabStaticModelSparse \
|| (output_type) == oMatlabDynamicModelSparse) || (output_type) == oMatlabDynamicModelSparse)
#define IS_C(output_type) ((output_type) == oCStaticModel \ #define IS_C(output_type) ((output_type) == oCDynamicModel)
|| (output_type) == oCDynamicModel)
#define IS_LATEX(output_type) ((output_type) == oLatexStaticModel \ #define IS_LATEX(output_type) ((output_type) == oLatexStaticModel \
|| (output_type) == oLatexDynamicModel) || (output_type) == oLatexDynamicModel)
......
...@@ -216,29 +216,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const ...@@ -216,29 +216,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
<< "delete " << basename << ".log;" << endl << "delete " << basename << ".log;" << endl
<< "warning warning_old_state" << endl << "warning warning_old_state" << endl
<< "logname_ = '" << basename << ".log';" << endl << "logname_ = '" << basename << ".log';" << endl
<< "diary " << basename << ".log" << endl << "diary " << basename << ".log" << endl;
<< "options_.model_mode = " << dynamic_model.mode << ";" << endl;
if (dynamic_model.mode == eSparseMode || dynamic_model.mode == eSparseDLLMode)
mOutputFile << "addpath " << basename << ";" << endl
<< "delete('" << basename << "_dynamic.m');" << endl;
if (dynamic_model.equation_number() > 0)
{
if (dynamic_model.mode == eDLLMode)
mOutputFile << "if exist('" << basename << "_static.c')" << endl
<< " clear " << basename << "_static" << endl
<< " mex -O " << basename << "_static.c" << endl
<< "end" << endl
<< "if exist('" << basename << "_dynamic.c')" << endl
<< " clear " << basename << "_dynamic" << endl
<< " mex -O LDFLAGS='-pthread -shared -Wl,--no-undefined' " << basename << "_dynamic.c" << endl
<< "end" << endl;
else
mOutputFile << "erase_compiled_function('" + basename + "_static');" << endl
<< "erase_compiled_function('" + basename + "_dynamic');" << endl;
}
cout << "Processing outputs ..."; cout << "Processing outputs ...";
...@@ -249,10 +227,8 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const ...@@ -249,10 +227,8 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
if (dynamic_model.equation_number() > 0) if (dynamic_model.equation_number() > 0)
{ {
dynamic_model.writeOutput(mOutputFile); dynamic_model.writeOutput(mOutputFile, basename);
static_model.writeStaticFile(basename); static_model.writeOutput(mOutputFile);
dynamic_model.writeDynamicFile(basename);
dynamic_model.writeParamsDerivativesFile(basename);
} }
// Print statements // Print statements
...@@ -260,14 +236,22 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const ...@@ -260,14 +236,22 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
it != statements.end(); it++) it != statements.end(); it++)
(*it)->writeOutput(mOutputFile, basename); (*it)->writeOutput(mOutputFile, basename);
mOutputFile << "save('" << basename << "_results.mat', 'oo_', 'M_', 'options_');" << endl if (dynamic_model.equation_number() > 0)
<< "diary off" << endl; dynamic_model.writeOutputPostComputing(mOutputFile, basename);
if (dynamic_model.mode == eSparseMode || dynamic_model.mode == eSparseDLLMode) mOutputFile << "save('" << basename << "_results.mat', 'oo_', 'M_', 'options_');" << endl
mOutputFile << "rmpath " << basename << ";" << endl; << "diary off" << endl
<< endl << "disp(['Total computing time : ' dynsec2hms(toc) ]);" << endl;
mOutputFile << endl << "disp(['Total computing time : ' dynsec2hms(toc) ]);" << endl;
mOutputFile.close(); mOutputFile.close();
// Create static and dynamic files
if (dynamic_model.equation_number() > 0)
{
static_model.writeStaticFile(basename);
dynamic_model.writeDynamicFile(basename);
dynamic_model.writeParamsDerivativesFile(basename);
}
cout << "done" << endl; cout << "done" << endl;
} }
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
ModelTree::ModelTree(SymbolTable &symbol_table_arg, ModelTree::ModelTree(SymbolTable &symbol_table_arg,
NumericalConstants &num_constants_arg) : NumericalConstants &num_constants_arg) :
DataTree(symbol_table_arg, num_constants_arg), DataTree(symbol_table_arg, num_constants_arg)
mode(eStandardMode)
{ {
for(int i=0; i < 3; i++) for(int i=0; i < 3; i++)
NNZDerivatives[i] = 0; NNZDerivatives[i] = 0;
...@@ -133,13 +132,11 @@ ModelTree::computeThirdDerivatives(const set<int> &vars) ...@@ -133,13 +132,11 @@ ModelTree::computeThirdDerivatives(const set<int> &vars)
} }
void void
ModelTree::computeTemporaryTerms() ModelTree::computeTemporaryTerms(bool is_matlab)
{ {
map<NodeID, int> reference_count; map<NodeID, int> reference_count;
temporary_terms.clear(); temporary_terms.clear();
bool is_matlab = (mode != eDLLMode);
for (vector<BinaryOpNode *>::iterator it = equations.begin(); for (vector<BinaryOpNode *>::iterator it = equations.begin();
it != equations.end(); it++) it != equations.end(); it++)
(*it)->computeTemporaryTerms(reference_count, temporary_terms, is_matlab); (*it)->computeTemporaryTerms(reference_count, temporary_terms, is_matlab);
...@@ -280,25 +277,3 @@ ModelTree::addEquation(NodeID eq) ...@@ -280,25 +277,3 @@ ModelTree::addEquation(NodeID eq)
equations.push_back(beq); equations.push_back(beq);
} }
void
ModelTree::jacobianHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const
{
output << LEFT_ARRAY_SUBSCRIPT(output_type);
if (IS_MATLAB(output_type))
output << eq_nb + 1 << ", " << col_nb + 1;
else
output << eq_nb + col_nb * equations.size();
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
}
void
ModelTree::hessianHelper(ostream &output, int row_nb, int col_nb, ExprNodeOutputType output_type) const
{
output << LEFT_ARRAY_SUBSCRIPT(output_type);
if (IS_MATLAB(output_type))
output << row_nb + 1 << ", " << col_nb + 1;
else
output << row_nb + col_nb * NNZDerivatives[1];
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
}
...@@ -29,15 +29,6 @@ using namespace std; ...@@ -29,15 +29,6 @@ using namespace std;
#include "DataTree.hh" #include "DataTree.hh"
//! The three in which ModelTree can work
enum ModelTreeMode
{
eStandardMode, //!< Standard mode (static and dynamic files in Matlab)
eSparseMode, //!< Sparse mode (static file in Matlab, dynamic file in Matlab with block decomposition)
eDLLMode, //!< DLL mode (static and dynamic files in C)
eSparseDLLMode //!< Sparse DLL mode (static file in Matlab, dynamic file in C with block decomposition plus a binary file)
};
//! Shared code for static and dynamic models //! Shared code for static and dynamic models
class ModelTree : public DataTree class ModelTree : public DataTree
{ {
...@@ -90,7 +81,7 @@ protected: ...@@ -90,7 +81,7 @@ protected:
//! Write derivative of an equation w.r. to a variable //! Write derivative of an equation w.r. to a variable
void writeDerivative(ostream &output, int eq, int symb_id, int lag, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const; void writeDerivative(ostream &output, int eq, int symb_id, int lag, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
//! Computes temporary terms (for all equations and derivatives) //! Computes temporary terms (for all equations and derivatives)
void computeTemporaryTerms(); void computeTemporaryTerms(bool is_matlab);
//! Writes temporary terms //! Writes temporary terms
void writeTemporaryTerms(const temporary_terms_type &tt, ostream &output, ExprNodeOutputType output_type) const; void writeTemporaryTerms(const temporary_terms_type &tt, ostream &output, ExprNodeOutputType output_type) const;
//! Writes model local variables