...
 
/* /*
* Copyright © 2007-2019 Dynare Team * Copyright © 2007-2020 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -105,33 +105,33 @@ enum Tags ...@@ -105,33 +105,33 @@ enum Tags
}; };
enum BlockType enum class BlockType
{ {
SIMULTANS, //!< Simultaneous time separable block simultans, //!< Simultaneous time separable block
PROLOGUE, //!< Prologue block (one equation at the beginning, later merged) prologue, //!< Prologue block (one equation at the beginning, later merged)
EPILOGUE, //!< Epilogue block (one equation at the beginning, later merged) epilogue, //!< Epilogue block (one equation at the beginning, later merged)
SIMULTAN //!< Simultaneous time unseparable block simultan //!< Simultaneous time unseparable block
}; };
enum EquationType enum class EquationType
{ {
E_UNKNOWN, //!< Unknown equation type unknown, //!< Unknown equation type
E_EVALUATE, //!< Simple evaluation, normalized variable on left-hand side evaluate, //!< Simple evaluation, normalized variable on left-hand side
E_EVALUATE_S, //!< Simple evaluation, normalize using the first order derivative evaluate_s, //!< Simple evaluation, normalize using the first order derivative
E_SOLVE //!< No simple evaluation of the equation, it has to be solved solve //!< No simple evaluation of the equation, it has to be solved
}; };
enum BlockSimulationType enum class BlockSimulationType
{ {
UNKNOWN, //!< Unknown simulation type unknown, //!< Unknown simulation type
EVALUATE_FORWARD, //!< Simple evaluation, normalized variable on left-hand side, forward evaluateForward, //!< Simple evaluation, normalized variable on left-hand side, forward
EVALUATE_BACKWARD, //!< Simple evaluation, normalized variable on left-hand side, backward evaluateBackward, //!< Simple evaluation, normalized variable on left-hand side, backward
SOLVE_FORWARD_SIMPLE, //!< Block of one equation, newton solver needed, forward solveForwardSimple, //!< Block of one equation, newton solver needed, forward
SOLVE_BACKWARD_SIMPLE, //!< Block of one equation, newton solver needed, backward solveBackwardSimple, //!< Block of one equation, newton solver needed, backward
SOLVE_TWO_BOUNDARIES_SIMPLE, //!< Block of one equation, newton solver needed, forward & ackward solveTwoBoundariesSimple, //!< Block of one equation, newton solver needed, forward & ackward
SOLVE_FORWARD_COMPLETE, //!< Block of several equations, newton solver needed, forward solveForwardComplete, //!< Block of several equations, newton solver needed, forward
SOLVE_BACKWARD_COMPLETE, //!< Block of several equations, newton solver needed, backward solveBackwardComplete, //!< Block of several equations, newton solver needed, backward
SOLVE_TWO_BOUNDARIES_COMPLETE //!< Block of several equations, newton solver needed, forward and backwar solveTwoBoundariesComplete //!< Block of several equations, newton solver needed, forward and backwar
}; };
//! Enumeration of possible symbol types //! Enumeration of possible symbol types
...@@ -1428,7 +1428,7 @@ private: ...@@ -1428,7 +1428,7 @@ private:
unsigned int nb_col_det_exo_jacob, nb_col_exo_jacob, nb_col_other_endo_jacob; unsigned int nb_col_det_exo_jacob, nb_col_exo_jacob, nb_col_other_endo_jacob;
public: public:
inline inline
FBEGINBLOCK_() : size{0}, type{UNKNOWN}, FBEGINBLOCK_() : size{0}, type{static_cast<uint8_t>(BlockSimulationType::unknown)},
is_linear{false}, endo_nbr{0}, Max_Lag{0}, Max_Lead{0}, u_count_int{0}, nb_col_jacob{0} is_linear{false}, endo_nbr{0}, Max_Lag{0}, Max_Lead{0}, u_count_int{0}, nb_col_jacob{0}
{ {
} }
...@@ -1577,8 +1577,10 @@ public: ...@@ -1577,8 +1577,10 @@ public:
CompileCode.write(reinterpret_cast<char *>(&variable[i]), sizeof(variable[0])); CompileCode.write(reinterpret_cast<char *>(&variable[i]), sizeof(variable[0]));
CompileCode.write(reinterpret_cast<char *>(&equation[i]), sizeof(equation[0])); CompileCode.write(reinterpret_cast<char *>(&equation[i]), sizeof(equation[0]));
} }
if (type == SOLVE_TWO_BOUNDARIES_SIMPLE || type == SOLVE_TWO_BOUNDARIES_COMPLETE if (type == static_cast<uint8_t>(BlockSimulationType::solveTwoBoundariesSimple)
|| type == SOLVE_BACKWARD_COMPLETE || type == SOLVE_FORWARD_COMPLETE) || type == static_cast<uint8_t>(BlockSimulationType::solveTwoBoundariesComplete)
|| type == static_cast<uint8_t>(BlockSimulationType::solveBackwardComplete)
|| type == static_cast<uint8_t>(BlockSimulationType::solveForwardComplete))
{ {
CompileCode.write(reinterpret_cast<char *>(&is_linear), sizeof(is_linear)); CompileCode.write(reinterpret_cast<char *>(&is_linear), sizeof(is_linear));
CompileCode.write(reinterpret_cast<char *>(&endo_nbr), sizeof(endo_nbr)); CompileCode.write(reinterpret_cast<char *>(&endo_nbr), sizeof(endo_nbr));
...@@ -1617,8 +1619,10 @@ public: ...@@ -1617,8 +1619,10 @@ public:
memcpy(&bc.Equation, code, sizeof(bc.Equation)); code += sizeof(bc.Equation); memcpy(&bc.Equation, code, sizeof(bc.Equation)); code += sizeof(bc.Equation);
Block_Contain_.push_back(bc); Block_Contain_.push_back(bc);
} }
if (type == SOLVE_TWO_BOUNDARIES_SIMPLE || type == SOLVE_TWO_BOUNDARIES_COMPLETE if (type == static_cast<uint8_t>(BlockSimulationType::solveTwoBoundariesSimple)
|| type == SOLVE_BACKWARD_COMPLETE || type == SOLVE_FORWARD_COMPLETE) || type == static_cast<uint8_t>(BlockSimulationType::solveTwoBoundariesComplete)
|| type == static_cast<uint8_t>(BlockSimulationType::solveBackwardComplete)
|| type == static_cast<uint8_t>(BlockSimulationType::solveForwardComplete))
{ {
memcpy(&is_linear, code, sizeof(is_linear)); code += sizeof(is_linear); memcpy(&is_linear, code, sizeof(is_linear)); code += sizeof(is_linear);
memcpy(&endo_nbr, code, sizeof(endo_nbr)); code += sizeof(endo_nbr); memcpy(&endo_nbr, code, sizeof(endo_nbr)); code += sizeof(endo_nbr);
......
This diff is collapsed.
...@@ -619,7 +619,7 @@ public: ...@@ -619,7 +619,7 @@ public:
bool bool
isBlockEquationRenormalized(int block_number, int equation_number) const override isBlockEquationRenormalized(int block_number, int equation_number) const override
{ {
return equation_type_and_normalized_equation[equation_reordered[get<1>(block_type_firstequation_size_mfs[block_number])+equation_number]].first == E_EVALUATE_S; return equation_type_and_normalized_equation[equation_reordered[get<1>(block_type_firstequation_size_mfs[block_number])+equation_number]].first == EquationType::evaluate_s;
}; };
//! Return the expr_t of the equation equation_number belonging to the block block_number //! Return the expr_t of the equation equation_number belonging to the block block_number
expr_t expr_t
......
...@@ -136,19 +136,19 @@ ExprNode::collectVariables(SymbolType type, set<int> &result) const ...@@ -136,19 +136,19 @@ ExprNode::collectVariables(SymbolType type, set<int> &result) const
void void
ExprNode::collectEndogenous(set<pair<int, int>> &result) const ExprNode::collectEndogenous(set<pair<int, int>> &result) const
{ {
set<pair<int, int>> symb_ids; set<pair<int, int>> symb_ids_and_lags;
collectDynamicVariables(SymbolType::endogenous, symb_ids); collectDynamicVariables(SymbolType::endogenous, symb_ids_and_lags);
for (const auto &symb_id : symb_ids) for (const auto &[symb_id, lag] : symb_ids_and_lags)
result.emplace(datatree.symbol_table.getTypeSpecificID(symb_id.first), symb_id.second); result.emplace(datatree.symbol_table.getTypeSpecificID(symb_id), lag);
} }
void void
ExprNode::collectExogenous(set<pair<int, int>> &result) const ExprNode::collectExogenous(set<pair<int, int>> &result) const
{ {
set<pair<int, int>> symb_ids; set<pair<int, int>> symb_ids_and_lags;
collectDynamicVariables(SymbolType::exogenous, symb_ids); collectDynamicVariables(SymbolType::exogenous, symb_ids_and_lags);
for (const auto &symb_id : symb_ids) for (const auto &[symb_id, lag] : symb_ids_and_lags)
result.emplace(datatree.symbol_table.getTypeSpecificID(symb_id.first), symb_id.second); result.emplace(datatree.symbol_table.getTypeSpecificID(symb_id), lag);
} }
void void
......
This diff is collapsed.
...@@ -282,11 +282,9 @@ protected: ...@@ -282,11 +282,9 @@ protected:
void computeNonSingularNormalization(jacob_map_t &contemporaneous_jacobian, double cutoff, jacob_map_t &static_jacobian); void computeNonSingularNormalization(jacob_map_t &contemporaneous_jacobian, double cutoff, jacob_map_t &static_jacobian);
//! Try to find a natural normalization if all equations are matched to an endogenous variable on the LHS //! Try to find a natural normalization if all equations are matched to an endogenous variable on the LHS
bool computeNaturalNormalization(); bool computeNaturalNormalization();
//! Try to normalized each unnormalized equation (matched endogenous variable only on the LHS) //! Evaluate the jacobian (w.r.t. endogenous) and suppress all the elements below the cutoff
multimap<int, int> computeNormalizedEquations() const;
//! Evaluate the jacobian and suppress all the elements below the cutoff
/*! Returns a pair (contemporaneous_jacobian, static_jacobian). Also fills /*! Returns a pair (contemporaneous_jacobian, static_jacobian). Also fills
dynamic_jacobian. */ dynamic_jacobian. External functions are evaluated to 1. */
pair<jacob_map_t, jacob_map_t> evaluateAndReduceJacobian(const eval_context_t &eval_context, double cutoff, bool verbose); pair<jacob_map_t, jacob_map_t> evaluateAndReduceJacobian(const eval_context_t &eval_context, double cutoff, bool verbose);
//! Select and reorder the non linear equations of the model //! Select and reorder the non linear equations of the model
/*! Returns a tuple (blocks, equation_lag_lead, variable_lag_lead, n_static, /*! Returns a tuple (blocks, equation_lag_lead, variable_lag_lead, n_static,
...@@ -294,14 +292,14 @@ protected: ...@@ -294,14 +292,14 @@ protected:
tuple<vector<pair<int, int>>, lag_lead_vector_t, lag_lead_vector_t, vector<unsigned int>, vector<unsigned int>, vector<unsigned int>, vector<unsigned int>> select_non_linear_equations_and_variables(const vector<bool> &is_equation_linear); tuple<vector<pair<int, int>>, lag_lead_vector_t, lag_lead_vector_t, vector<unsigned int>, vector<unsigned int>, vector<unsigned int>, vector<unsigned int>> select_non_linear_equations_and_variables(const vector<bool> &is_equation_linear);
//! Search the equations and variables belonging to the prologue and the epilogue of the model //! Search the equations and variables belonging to the prologue and the epilogue of the model
void computePrologueAndEpilogue(const jacob_map_t &static_jacobian); void computePrologueAndEpilogue(const jacob_map_t &static_jacobian);
//! Determine the type of each equation of model and try to normalized the unnormalized equation using computeNormalizedEquations //! Determine the type of each equation of model and try to normalize the unnormalized equation
equation_type_and_normalized_equation_t equationTypeDetermination(const map<tuple<int, int, int>, expr_t> &first_order_endo_derivatives, int mfs) const; void equationTypeDetermination(const map<tuple<int, int, int>, expr_t> &first_order_endo_derivatives, int mfs);
//! Compute the block decomposition and for a non-recusive block find the minimum feedback set //! Compute the block decomposition and for a non-recusive block find the minimum feedback set
/*! Returns a tuple (blocks, equation_lag_lead, variable_lag_lead, n_static, /*! Returns a tuple (blocks, equation_lag_lead, variable_lag_lead, n_static,
n_forward, n_backward, n_mixed) */ n_forward, n_backward, n_mixed) */
tuple<vector<pair<int, int>>, lag_lead_vector_t, lag_lead_vector_t, vector<unsigned int>, vector<unsigned int>, vector<unsigned int>, vector<unsigned int>> computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob_map_t &static_jacobian, const equation_type_and_normalized_equation_t &Equation_Type, bool verbose_, bool select_feedback_variable); tuple<vector<pair<int, int>>, lag_lead_vector_t, lag_lead_vector_t, vector<unsigned int>, vector<unsigned int>, vector<unsigned int>, vector<unsigned int>> computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob_map_t &static_jacobian, const equation_type_and_normalized_equation_t &Equation_Type, bool verbose_, bool select_feedback_variable);
//! Reduce the number of block merging the same type equation in the prologue and the epilogue and determine the type of each block //! Reduce the number of block merging the same type equation in the prologue and the epilogue and determine the type of each block
block_type_firstequation_size_mfs_t reduceBlocksAndTypeDetermination(const vector<pair<int, int>> &blocks, const equation_type_and_normalized_equation_t &Equation_Type, const vector<unsigned int> &n_static, const vector<unsigned int> &n_forward, const vector<unsigned int> &n_backward, const vector<unsigned int> &n_mixed, bool linear_decomposition); void reduceBlocksAndTypeDetermination(const vector<pair<int, int>> &blocks, const equation_type_and_normalized_equation_t &Equation_Type, const vector<unsigned int> &n_static, const vector<unsigned int> &n_forward, const vector<unsigned int> &n_backward, const vector<unsigned int> &n_mixed, bool linear_decomposition);
//! Determine the maximum number of lead and lag for the endogenous variable in a bloc //! Determine the maximum number of lead and lag for the endogenous variable in a bloc
/*! Returns a pair { equation_lead,lag, variable_lead_lag } */ /*! Returns a pair { equation_lead,lag, variable_lead_lag } */
pair<lag_lead_vector_t, lag_lead_vector_t> getVariableLeadLagByBlock(const vector<int> &components_set, int nb_blck_sim) const; pair<lag_lead_vector_t, lag_lead_vector_t> getVariableLeadLagByBlock(const vector<int> &components_set, int nb_blck_sim) const;
...@@ -310,7 +308,7 @@ protected: ...@@ -310,7 +308,7 @@ protected:
//! Print an abstract of the block structure of the model //! Print an abstract of the block structure of the model
void printBlockDecomposition(const vector<pair<int, int>> &blocks) const; void printBlockDecomposition(const vector<pair<int, int>> &blocks) const;
//! Determine for each block if it is linear or not //! Determine for each block if it is linear or not
vector<bool> BlockLinear() const; void determineLinearBlocks();
//! Remove equations specified by exclude_eqs //! Remove equations specified by exclude_eqs
vector<int> includeExcludeEquations(set<pair<string, string>> &eqs, bool exclude_eqs, vector<int> includeExcludeEquations(set<pair<string, string>> &eqs, bool exclude_eqs,
vector<BinaryOpNode *> &equations, vector<int> &equations_lineno, vector<BinaryOpNode *> &equations, vector<int> &equations_lineno,
...@@ -437,61 +435,64 @@ public: ...@@ -437,61 +435,64 @@ public:
} }
inline static string inline static string
c_Equation_Type(int type) c_Equation_Type(EquationType type)
{ {
vector<string> c_Equation_Type = switch (type)
{ {
"E_UNKNOWN ", case EquationType::evaluate:
"E_EVALUATE ", return "EVALUATE ";
"E_EVALUATE_S", case EquationType::evaluate_s:
"E_SOLVE " return "EVALUATE_S";
}; case EquationType::solve:
return c_Equation_Type[type]; return "SOLVE ";
}; default:
return "UNKNOWN ";
}
}
inline static string inline static string
BlockType0(BlockType type) BlockType0(BlockType type)
{ {
switch (type) switch (type)
{ {
case SIMULTANS: case BlockType::simultans:
return "SIMULTANEOUS TIME SEPARABLE "; return "SIMULTANEOUS TIME SEPARABLE ";
case PROLOGUE: case BlockType::prologue:
return "PROLOGUE "; return "PROLOGUE ";
case EPILOGUE: case BlockType::epilogue:
return "EPILOGUE "; return "EPILOGUE ";
case SIMULTAN: case BlockType::simultan:
return "SIMULTANEOUS TIME UNSEPARABLE"; return "SIMULTANEOUS TIME UNSEPARABLE";
default: default:
return "UNKNOWN "; return "UNKNOWN ";
} }
}; }
inline static string inline static string
BlockSim(int type) BlockSim(BlockSimulationType type)
{ {
switch (type) switch (type)
{ {
case EVALUATE_FORWARD: case BlockSimulationType::evaluateForward:
return "EVALUATE FORWARD "; return "EVALUATE FORWARD ";
case EVALUATE_BACKWARD: case BlockSimulationType::evaluateBackward:
return "EVALUATE BACKWARD "; return "EVALUATE BACKWARD ";
case SOLVE_FORWARD_SIMPLE: case BlockSimulationType::solveForwardSimple:
return "SOLVE FORWARD SIMPLE "; return "SOLVE FORWARD SIMPLE ";
case SOLVE_BACKWARD_SIMPLE: case BlockSimulationType::solveBackwardSimple:
return "SOLVE BACKWARD SIMPLE "; return "SOLVE BACKWARD SIMPLE ";
case SOLVE_TWO_BOUNDARIES_SIMPLE: case BlockSimulationType::solveTwoBoundariesSimple:
return "SOLVE TWO BOUNDARIES SIMPLE "; return "SOLVE TWO BOUNDARIES SIMPLE ";
case SOLVE_FORWARD_COMPLETE: case BlockSimulationType::solveForwardComplete:
return "SOLVE FORWARD COMPLETE "; return "SOLVE FORWARD COMPLETE ";
case SOLVE_BACKWARD_COMPLETE: case BlockSimulationType::solveBackwardComplete:
return "SOLVE BACKWARD COMPLETE "; return "SOLVE BACKWARD COMPLETE ";
case SOLVE_TWO_BOUNDARIES_COMPLETE: case BlockSimulationType::solveTwoBoundariesComplete:
return "SOLVE TWO BOUNDARIES COMPLETE"; return "SOLVE TWO BOUNDARIES COMPLETE";
default: default:
return "UNKNOWN "; return "UNKNOWN ";
} }
}; }
}; };
#endif #endif
This diff is collapsed.
/* /*
* Copyright © 2003-2019 Dynare Team * Copyright © 2003-2020 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -256,7 +256,7 @@ public: ...@@ -256,7 +256,7 @@ public:
bool bool
isBlockEquationRenormalized(int block_number, int equation_number) const override isBlockEquationRenormalized(int block_number, int equation_number) const override
{ {
return (equation_type_and_normalized_equation[equation_reordered[get<1>(block_type_firstequation_size_mfs[block_number])+equation_number]].first == E_EVALUATE_S); return (equation_type_and_normalized_equation[equation_reordered[get<1>(block_type_firstequation_size_mfs[block_number])+equation_number]].first == EquationType::evaluate_s);
}; };
//! Return the expr_t of the equation equation_number belonging to the block block_number //! Return the expr_t of the equation equation_number belonging to the block block_number
expr_t expr_t
......