...
 
/*
* Copyright © 2007-2019 Dynare Team
* Copyright © 2007-2020 Dynare Team
*
* This file is part of Dynare.
*
......@@ -105,33 +105,33 @@ enum Tags
};
enum BlockType
enum class BlockType
{
SIMULTANS, //!< Simultaneous time separable block
PROLOGUE, //!< Prologue block (one equation at the beginning, later merged)
EPILOGUE, //!< Epilogue block (one equation at the beginning, later merged)
SIMULTAN //!< Simultaneous time unseparable block
simultans, //!< Simultaneous time separable block
prologue, //!< Prologue block (one equation at the beginning, later merged)
epilogue, //!< Epilogue block (one equation at the beginning, later merged)
simultan //!< Simultaneous time unseparable block
};
enum EquationType
enum class EquationType
{
E_UNKNOWN, //!< Unknown equation type
E_EVALUATE, //!< Simple evaluation, normalized variable on left-hand side
E_EVALUATE_S, //!< Simple evaluation, normalize using the first order derivative
E_SOLVE //!< No simple evaluation of the equation, it has to be solved
unknown, //!< Unknown equation type
evaluate, //!< Simple evaluation, normalized variable on left-hand side
evaluate_s, //!< Simple evaluation, normalize using the first order derivative
solve //!< No simple evaluation of the equation, it has to be solved
};
enum BlockSimulationType
enum class BlockSimulationType
{
UNKNOWN, //!< Unknown simulation type
EVALUATE_FORWARD, //!< Simple evaluation, normalized variable on left-hand side, forward
EVALUATE_BACKWARD, //!< Simple evaluation, normalized variable on left-hand side, backward
SOLVE_FORWARD_SIMPLE, //!< Block of one equation, newton solver needed, forward
SOLVE_BACKWARD_SIMPLE, //!< Block of one equation, newton solver needed, backward
SOLVE_TWO_BOUNDARIES_SIMPLE, //!< Block of one equation, newton solver needed, forward & ackward
SOLVE_FORWARD_COMPLETE, //!< Block of several equations, newton solver needed, forward
SOLVE_BACKWARD_COMPLETE, //!< Block of several equations, newton solver needed, backward
SOLVE_TWO_BOUNDARIES_COMPLETE //!< Block of several equations, newton solver needed, forward and backwar
unknown, //!< Unknown simulation type
evaluateForward, //!< Simple evaluation, normalized variable on left-hand side, forward
evaluateBackward, //!< Simple evaluation, normalized variable on left-hand side, backward
solveForwardSimple, //!< Block of one equation, newton solver needed, forward
solveBackwardSimple, //!< Block of one equation, newton solver needed, backward
solveTwoBoundariesSimple, //!< Block of one equation, newton solver needed, forward & ackward
solveForwardComplete, //!< Block of several equations, newton solver needed, forward
solveBackwardComplete, //!< Block of several equations, newton solver needed, backward
solveTwoBoundariesComplete //!< Block of several equations, newton solver needed, forward and backwar
};
//! Enumeration of possible symbol types
......@@ -1428,7 +1428,7 @@ private:
unsigned int nb_col_det_exo_jacob, nb_col_exo_jacob, nb_col_other_endo_jacob;
public:
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}
{
}
......@@ -1577,8 +1577,10 @@ public:
CompileCode.write(reinterpret_cast<char *>(&variable[i]), sizeof(variable[0]));
CompileCode.write(reinterpret_cast<char *>(&equation[i]), sizeof(equation[0]));
}
if (type == SOLVE_TWO_BOUNDARIES_SIMPLE || type == SOLVE_TWO_BOUNDARIES_COMPLETE
|| type == SOLVE_BACKWARD_COMPLETE || type == SOLVE_FORWARD_COMPLETE)
if (type == static_cast<uint8_t>(BlockSimulationType::solveTwoBoundariesSimple)
|| 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 *>(&endo_nbr), sizeof(endo_nbr));
......@@ -1617,8 +1619,10 @@ public:
memcpy(&bc.Equation, code, sizeof(bc.Equation)); code += sizeof(bc.Equation);
Block_Contain_.push_back(bc);
}
if (type == SOLVE_TWO_BOUNDARIES_SIMPLE || type == SOLVE_TWO_BOUNDARIES_COMPLETE
|| type == SOLVE_BACKWARD_COMPLETE || type == SOLVE_FORWARD_COMPLETE)
if (type == static_cast<uint8_t>(BlockSimulationType::solveTwoBoundariesSimple)
|| 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(&endo_nbr, code, sizeof(endo_nbr)); code += sizeof(endo_nbr);
......
This diff is collapsed.
......@@ -619,7 +619,7 @@ public:
bool
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
expr_t
......
......@@ -136,19 +136,19 @@ ExprNode::collectVariables(SymbolType type, set<int> &result) const
void
ExprNode::collectEndogenous(set<pair<int, int>> &result) const
{
set<pair<int, int>> symb_ids;
collectDynamicVariables(SymbolType::endogenous, symb_ids);
for (const auto &symb_id : symb_ids)
result.emplace(datatree.symbol_table.getTypeSpecificID(symb_id.first), symb_id.second);
set<pair<int, int>> symb_ids_and_lags;
collectDynamicVariables(SymbolType::endogenous, symb_ids_and_lags);
for (const auto &[symb_id, lag] : symb_ids_and_lags)
result.emplace(datatree.symbol_table.getTypeSpecificID(symb_id), lag);
}
void
ExprNode::collectExogenous(set<pair<int, int>> &result) const
{
set<pair<int, int>> symb_ids;
collectDynamicVariables(SymbolType::exogenous, symb_ids);
for (const auto &symb_id : symb_ids)
result.emplace(datatree.symbol_table.getTypeSpecificID(symb_id.first), symb_id.second);
set<pair<int, int>> symb_ids_and_lags;
collectDynamicVariables(SymbolType::exogenous, symb_ids_and_lags);
for (const auto &[symb_id, lag] : symb_ids_and_lags)
result.emplace(datatree.symbol_table.getTypeSpecificID(symb_id), lag);
}
void
......
This diff is collapsed.
......@@ -282,11 +282,9 @@ protected:
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
bool computeNaturalNormalization();
//! Try to normalized each unnormalized equation (matched endogenous variable only on the LHS)
multimap<int, int> computeNormalizedEquations() const;
//! Evaluate the jacobian and suppress all the elements below the cutoff
//! Evaluate the jacobian (w.r.t. endogenous) and suppress all the elements below the cutoff
/*! 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);
//! Select and reorder the non linear equations of the model
/*! Returns a tuple (blocks, equation_lag_lead, variable_lag_lead, n_static,
......@@ -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);
//! Search the equations and variables belonging to the prologue and the epilogue of the model
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
equation_type_and_normalized_equation_t equationTypeDetermination(const map<tuple<int, int, int>, expr_t> &first_order_endo_derivatives, int mfs) const;
//! Determine the type of each equation of model and try to normalize the unnormalized equation
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
/*! Returns a tuple (blocks, equation_lag_lead, variable_lag_lead, n_static,
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);
//! 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
/*! 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;
......@@ -310,7 +308,7 @@ protected:
//! Print an abstract of the block structure of the model
void printBlockDecomposition(const vector<pair<int, int>> &blocks) const;
//! Determine for each block if it is linear or not
vector<bool> BlockLinear() const;
void determineLinearBlocks();
//! Remove equations specified by exclude_eqs
vector<int> includeExcludeEquations(set<pair<string, string>> &eqs, bool exclude_eqs,
vector<BinaryOpNode *> &equations, vector<int> &equations_lineno,
......@@ -437,61 +435,64 @@ public:
}
inline static string
c_Equation_Type(int type)
c_Equation_Type(EquationType type)
{
vector<string> c_Equation_Type =
switch (type)
{
"E_UNKNOWN ",
"E_EVALUATE ",
"E_EVALUATE_S",
"E_SOLVE "
};
return c_Equation_Type[type];
};
case EquationType::evaluate:
return "EVALUATE ";
case EquationType::evaluate_s:
return "EVALUATE_S";
case EquationType::solve:
return "SOLVE ";
default:
return "UNKNOWN ";
}
}
inline static string
BlockType0(BlockType type)
{
switch (type)
{
case SIMULTANS:
case BlockType::simultans:
return "SIMULTANEOUS TIME SEPARABLE ";
case PROLOGUE:
case BlockType::prologue:
return "PROLOGUE ";
case EPILOGUE:
case BlockType::epilogue:
return "EPILOGUE ";
case SIMULTAN:
case BlockType::simultan:
return "SIMULTANEOUS TIME UNSEPARABLE";
default:
return "UNKNOWN ";
}
};
}
inline static string
BlockSim(int type)
BlockSim(BlockSimulationType type)
{
switch (type)
{
case EVALUATE_FORWARD:
case BlockSimulationType::evaluateForward:
return "EVALUATE FORWARD ";
case EVALUATE_BACKWARD:
case BlockSimulationType::evaluateBackward:
return "EVALUATE BACKWARD ";
case SOLVE_FORWARD_SIMPLE:
case BlockSimulationType::solveForwardSimple:
return "SOLVE FORWARD SIMPLE ";
case SOLVE_BACKWARD_SIMPLE:
case BlockSimulationType::solveBackwardSimple:
return "SOLVE BACKWARD SIMPLE ";
case SOLVE_TWO_BOUNDARIES_SIMPLE:
case BlockSimulationType::solveTwoBoundariesSimple:
return "SOLVE TWO BOUNDARIES SIMPLE ";
case SOLVE_FORWARD_COMPLETE:
case BlockSimulationType::solveForwardComplete:
return "SOLVE FORWARD COMPLETE ";
case SOLVE_BACKWARD_COMPLETE:
case BlockSimulationType::solveBackwardComplete:
return "SOLVE BACKWARD COMPLETE ";
case SOLVE_TWO_BOUNDARIES_COMPLETE:
case BlockSimulationType::solveTwoBoundariesComplete:
return "SOLVE TWO BOUNDARIES COMPLETE";
default:
return "UNKNOWN ";
}
};
}
};
#endif
This diff is collapsed.
/*
* Copyright © 2003-2019 Dynare Team
* Copyright © 2003-2020 Dynare Team
*
* This file is part of Dynare.
*
......@@ -256,7 +256,7 @@ public:
bool
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
expr_t
......