Commit d2696ca2 authored by Sébastien Villemot's avatar Sébastien Villemot

Preprocessor: factorize code common between StaticModel and DynamicModel, and put it in ModelTree

parent 06f7d23e
...@@ -45,9 +45,7 @@ DynamicModel::DynamicModel(SymbolTable &symbol_table_arg, ...@@ -45,9 +45,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),
global_temporary_terms(true), global_temporary_terms(true)
cutoff(1e-15),
mfs(0)
{ {
} }
...@@ -83,16 +81,6 @@ DynamicModel::compileChainRuleDerivative(ofstream &code_file, unsigned int &inst ...@@ -83,16 +81,6 @@ DynamicModel::compileChainRuleDerivative(ofstream &code_file, unsigned int &inst
} }
} }
void
DynamicModel::initializeVariablesAndEquations()
{
for (int j = 0; j < equation_number(); j++)
{
equation_reordered.push_back(j);
variable_reordered.push_back(j);
}
}
void void
DynamicModel::computeTemporaryTermsOrdered() DynamicModel::computeTemporaryTermsOrdered()
{ {
...@@ -3978,9 +3966,3 @@ DynamicModel::fillEvalContext(eval_context_t &eval_context) const ...@@ -3978,9 +3966,3 @@ DynamicModel::fillEvalContext(eval_context_t &eval_context) const
it != trendVars.end(); it++) it != trendVars.end(); it++)
eval_context[*it] = 2; //not <= 0 bc of log, not 1 bc of powers eval_context[*it] = 2; //not <= 0 bc of log, not 1 bc of powers
} }
void
DynamicModel::set_cutoff_to_zero()
{
cutoff = 0;
}
...@@ -194,9 +194,6 @@ private: ...@@ -194,9 +194,6 @@ private:
//! Indicate if the temporary terms are computed for the overall model (true) or not (false). Default value true //! Indicate if the temporary terms are computed for the overall model (true) or not (false). Default value true
bool global_temporary_terms; bool global_temporary_terms;
//! vector of block reordered variables and equations
vector<int> equation_reordered, variable_reordered, inv_equation_reordered, inv_variable_reordered;
//! Vector describing equations: BlockSimulationType, if BlockSimulationType == EVALUATE_s then a expr_t on the new normalized equation //! Vector describing equations: BlockSimulationType, if BlockSimulationType == EVALUATE_s then a expr_t on the new normalized equation
equation_type_and_normalized_equation_t equation_type_and_normalized_equation; equation_type_and_normalized_equation_t equation_type_and_normalized_equation;
...@@ -244,17 +241,7 @@ public: ...@@ -244,17 +241,7 @@ public:
//! Adds a variable node //! Adds a variable node
/*! This implementation allows for non-zero lag */ /*! This implementation allows for non-zero lag */
virtual VariableNode *AddVariable(int symb_id, int lag = 0); virtual VariableNode *AddVariable(int symb_id, int lag = 0);
//! Absolute value under which a number is considered to be zero
double cutoff;
//! Compute the minimum feedback set in the dynamic model:
/*! 0 : all endogenous variables are considered as feedback variables
1 : the variables belonging to non normalized equation are considered as feedback variables
2 : the variables belonging to a non linear equation are considered as feedback variables
3 : the variables belonging to a non normalizable non linear equation are considered as feedback variables
default value = 0 */
int mfs;
//! the file containing the model and the derivatives code
ofstream code_file;
//! Execute computations (variable sorting + derivation) //! Execute computations (variable sorting + derivation)
/*! /*!
\param jacobianExo whether derivatives w.r. to exo and exo_det should be in the Jacobian (derivatives w.r. to endo are always computed) \param jacobianExo whether derivatives w.r. to exo and exo_det should be in the Jacobian (derivatives w.r. to endo are always computed)
...@@ -292,9 +279,6 @@ public: ...@@ -292,9 +279,6 @@ public:
//! Writes LaTeX file with the equations of the dynamic model //! Writes LaTeX file with the equations of the dynamic model
void writeLatexFile(const string &basename) const; void writeLatexFile(const string &basename) const;
//! Initialize equation_reordered & variable_reordered
void initializeVariablesAndEquations();
virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException); virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException);
virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException); virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException);
virtual void addAllParamDerivId(set<int> &deriv_id_set); virtual void addAllParamDerivId(set<int> &deriv_id_set);
...@@ -338,8 +322,6 @@ public: ...@@ -338,8 +322,6 @@ public:
//! Fills eval context with values of model local variables and auxiliary variables //! Fills eval context with values of model local variables and auxiliary variables
void fillEvalContext(eval_context_t &eval_context) const; void fillEvalContext(eval_context_t &eval_context) const;
void set_cutoff_to_zero();
//! Return the number of blocks //! Return the number of blocks
virtual unsigned int virtual unsigned int
getNbBlocks() const getNbBlocks() const
......
...@@ -957,7 +957,10 @@ ModelTree::BlockLinear(const blocks_derivatives_t &blocks_derivatives, const vec ...@@ -957,7 +957,10 @@ ModelTree::BlockLinear(const blocks_derivatives_t &blocks_derivatives, const vec
ModelTree::ModelTree(SymbolTable &symbol_table_arg, ModelTree::ModelTree(SymbolTable &symbol_table_arg,
NumericalConstants &num_constants_arg, NumericalConstants &num_constants_arg,
ExternalFunctionsTable &external_functions_table_arg) : ExternalFunctionsTable &external_functions_table_arg) :
DataTree(symbol_table_arg, num_constants_arg, external_functions_table_arg) DataTree(symbol_table_arg, num_constants_arg, external_functions_table_arg),
cutoff(1e-15),
mfs(0)
{ {
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
NNZDerivatives[i] = 0; NNZDerivatives[i] = 0;
...@@ -1405,3 +1408,19 @@ ModelTree::addNonstationaryVariables(vector<int> nonstationary_vars, expr_t defl ...@@ -1405,3 +1408,19 @@ ModelTree::addNonstationaryVariables(vector<int> nonstationary_vars, expr_t defl
nonstationary_vars.pop_back(); nonstationary_vars.pop_back();
} }
} }
void
ModelTree::initializeVariablesAndEquations()
{
for (int j = 0; j < equation_number(); j++)
{
equation_reordered.push_back(j);
variable_reordered.push_back(j);
}
}
void
ModelTree::set_cutoff_to_zero()
{
cutoff = 0;
}
...@@ -99,6 +99,12 @@ protected: ...@@ -99,6 +99,12 @@ protected:
//! Nonstationary variables and their deflators //! Nonstationary variables and their deflators
trend_symbols_map_t nonstationary_symbols_map; trend_symbols_map_t nonstationary_symbols_map;
//! vector of block reordered variables and equations
vector<int> equation_reordered, variable_reordered, inv_equation_reordered, inv_variable_reordered;
//! the file containing the model and the derivatives code
ofstream code_file;
//! Computes 1st derivatives //! Computes 1st derivatives
/*! \param vars the derivation IDs w.r. to which compute the derivatives */ /*! \param vars the derivation IDs w.r. to which compute the derivatives */
void computeJacobian(const set<int> &vars); void computeJacobian(const set<int> &vars);
...@@ -230,8 +236,19 @@ protected: ...@@ -230,8 +236,19 @@ protected:
virtual int getBlockInitialDetExogenousID(int block_number, int variable_number) const = 0; virtual int getBlockInitialDetExogenousID(int block_number, int variable_number) const = 0;
//! Return the position of the other endogenous variable_number in the block number belonging to the block block_number //! Return the position of the other endogenous variable_number in the block number belonging to the block block_number
virtual int getBlockInitialOtherEndogenousID(int block_number, int variable_number) const = 0; virtual int getBlockInitialOtherEndogenousID(int block_number, int variable_number) const = 0;
//! Initialize equation_reordered & variable_reordered
void initializeVariablesAndEquations();
public: public:
ModelTree(SymbolTable &symbol_table_arg, NumericalConstants &num_constants_arg, ExternalFunctionsTable &external_functions_table_arg); ModelTree(SymbolTable &symbol_table_arg, NumericalConstants &num_constants_arg, ExternalFunctionsTable &external_functions_table_arg);
//! Absolute value under which a number is considered to be zero
double cutoff;
//! Compute the minimum feedback set
/*! 0 : all endogenous variables are considered as feedback variables
1 : the variables belonging to non normalized equation are considered as feedback variables
2 : the variables belonging to a non linear equation are considered as feedback variables
3 : the variables belonging to a non normalizable non linear equation are considered as feedback variables
default value = 0 */
int mfs;
//! Declare a node as an equation of the model //! Declare a node as an equation of the model
void addEquation(expr_t eq); void addEquation(expr_t eq);
//! Adds tags to equation number i //! Adds tags to equation number i
...@@ -244,7 +261,8 @@ public: ...@@ -244,7 +261,8 @@ public:
void addTrendVariables(vector<int> trend_vars, expr_t growth_factor) throw (TrendException); void addTrendVariables(vector<int> trend_vars, expr_t growth_factor) throw (TrendException);
//! Adds a nonstationary variable with its deflator //! Adds a nonstationary variable with its deflator
void addNonstationaryVariables(vector<int> nonstationary_vars, expr_t deflator) throw (TrendException); void addNonstationaryVariables(vector<int> nonstationary_vars, expr_t deflator) throw (TrendException);
void set_cutoff_to_zero();
inline static std::string inline static std::string
c_Equation_Type(int type) c_Equation_Type(int type)
{ {
......
...@@ -39,9 +39,7 @@ StaticModel::StaticModel(SymbolTable &symbol_table_arg, ...@@ -39,9 +39,7 @@ StaticModel::StaticModel(SymbolTable &symbol_table_arg,
NumericalConstants &num_constants_arg, NumericalConstants &num_constants_arg,
ExternalFunctionsTable &external_functions_table_arg) : ExternalFunctionsTable &external_functions_table_arg) :
ModelTree(symbol_table_arg, num_constants_arg, external_functions_table_arg), ModelTree(symbol_table_arg, num_constants_arg, external_functions_table_arg),
global_temporary_terms(true), global_temporary_terms(true)
cutoff(1e-15),
mfs(0)
{ {
} }
...@@ -71,16 +69,6 @@ StaticModel::compileChainRuleDerivative(ofstream &code_file, unsigned int &instr ...@@ -71,16 +69,6 @@ StaticModel::compileChainRuleDerivative(ofstream &code_file, unsigned int &instr
} }
} }
void
StaticModel::initializeVariablesAndEquations()
{
for (int j = 0; j < equation_number(); j++)
{
equation_reordered.push_back(j);
variable_reordered.push_back(j);
}
}
void void
StaticModel::computeTemporaryTermsOrdered() StaticModel::computeTemporaryTermsOrdered()
{ {
...@@ -1611,9 +1599,3 @@ StaticModel::writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) ...@@ -1611,9 +1599,3 @@ StaticModel::writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type)
output << ";" << endl; output << ";" << endl;
} }
} }
void
StaticModel::set_cutoff_to_zero()
{
cutoff = 0;
}
...@@ -123,9 +123,6 @@ protected: ...@@ -123,9 +123,6 @@ protected:
//! Indicate if the temporary terms are computed for the overall model (true) or not (false). Default value true //! Indicate if the temporary terms are computed for the overall model (true) or not (false). Default value true
bool global_temporary_terms; bool global_temporary_terms;
//! vector of block reordered variables and equations
vector<int> equation_reordered, variable_reordered, inv_equation_reordered, inv_variable_reordered;
//! Vector describing equations: BlockSimulationType, if BlockSimulationType == EVALUATE_s then a expr_t on the new normalized equation //! Vector describing equations: BlockSimulationType, if BlockSimulationType == EVALUATE_s then a expr_t on the new normalized equation
equation_type_and_normalized_equation_t equation_type_and_normalized_equation; equation_type_and_normalized_equation_t equation_type_and_normalized_equation;
...@@ -169,16 +166,6 @@ public: ...@@ -169,16 +166,6 @@ public:
//! Writes information on block decomposition when relevant //! Writes information on block decomposition when relevant
void writeOutput(ostream &output, bool block) const; void writeOutput(ostream &output, bool block) const;
//! Absolute value under which a number is considered to be zero
double cutoff;
//! Compute the minimum feedback set in the static model:
/*! 0 : all endogenous variables are considered as feedback variables
1 : the variables belonging to a non linear equation are considered as feedback variables
2 : the variables belonging to a non normalizable non linear equation are considered as feedback variables
default value = 0 */
int mfs;
//! the file containing the model and the derivatives code
ofstream code_file;
//! Execute computations (variable sorting + derivation) //! Execute computations (variable sorting + derivation)
/*! /*!
\param jacobianExo whether derivatives w.r. to exo and exo_det should be in the Jacobian (derivatives w.r. to endo are always computed) \param jacobianExo whether derivatives w.r. to exo and exo_det should be in the Jacobian (derivatives w.r. to endo are always computed)
...@@ -203,13 +190,8 @@ public: ...@@ -203,13 +190,8 @@ public:
//! Writes initializations in oo_.steady_state or steady state file for the auxiliary variables //! Writes initializations in oo_.steady_state or steady state file for the auxiliary variables
void writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) const; void writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) const;
//! Initialize equation_reordered & variable_reordered
void initializeVariablesAndEquations();
virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException); virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException);
void set_cutoff_to_zero();
//! Return the number of blocks //! Return the number of blocks
virtual unsigned int virtual unsigned int
getNbBlocks() const getNbBlocks() const
......
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