Block decomposition: in the dynamic file, y and T are now vectors as in non-block mode
parent
91d5be3b8c
commit
79763911b2
|
@ -227,7 +227,7 @@ void
|
||||||
DynamicModel::writeDynamicPerBlockMFiles(const string &basename) const
|
DynamicModel::writeDynamicPerBlockMFiles(const string &basename) const
|
||||||
{
|
{
|
||||||
temporary_terms_t temporary_terms; // Temp terms written so far
|
temporary_terms_t temporary_terms; // Temp terms written so far
|
||||||
constexpr ExprNodeOutputType local_output_type = ExprNodeOutputType::matlabDynamicBlockModel;
|
constexpr ExprNodeOutputType local_output_type = ExprNodeOutputType::matlabDynamicModel;
|
||||||
|
|
||||||
for (int blk = 0; blk < static_cast<int>(blocks.size()); blk++)
|
for (int blk = 0; blk < static_cast<int>(blocks.size()); blk++)
|
||||||
{
|
{
|
||||||
|
@ -1294,10 +1294,10 @@ DynamicModel::writeDynamicBlockMFile(const string &basename) const
|
||||||
<< "function [residual, dr] = dynamic(options_, M_, oo_, y, x, params, steady_state, it_, dr)" << endl;
|
<< "function [residual, dr] = dynamic(options_, M_, oo_, y, x, params, steady_state, it_, dr)" << endl;
|
||||||
|
|
||||||
if (blocks_temporary_terms_idxs.size() > 0)
|
if (blocks_temporary_terms_idxs.size() > 0)
|
||||||
mDynamicModelFile << " T=NaN(" << blocks_temporary_terms_idxs.size()
|
mDynamicModelFile << " T=NaN(" << blocks_temporary_terms_idxs.size() << ");" << endl;
|
||||||
<< ",options_.periods+M_.maximum_lag+M_.maximum_lead);" << endl;
|
|
||||||
|
|
||||||
mDynamicModelFile << " ys=y(it_,:);" << endl;
|
mDynamicModelFile << " ys=y;" << endl
|
||||||
|
<< " ll_index=M_.lead_lag_incidence(M_.maximum_endo_lag+1, :);" << endl;
|
||||||
|
|
||||||
for (int blk = 0; blk < static_cast<int>(blocks.size()); blk++)
|
for (int blk = 0; blk < static_cast<int>(blocks.size()); blk++)
|
||||||
{
|
{
|
||||||
|
@ -1323,7 +1323,9 @@ DynamicModel::writeDynamicBlockMFile(const string &basename) const
|
||||||
case BlockSimulationType::evaluateForward:
|
case BlockSimulationType::evaluateForward:
|
||||||
case BlockSimulationType::evaluateBackward:
|
case BlockSimulationType::evaluateBackward:
|
||||||
mDynamicModelFile << " [y, T, dr(" << blk + 1 << ").g1, dr(" << blk + 1 << ").g1_x, dr(" << blk + 1 << ").g1_xd, dr(" << blk + 1 << ").g1_o]=" << basename << ".block.dynamic_" << blk + 1 << "(y, x, params, steady_state, T, it_, true);" << endl
|
mDynamicModelFile << " [y, T, dr(" << blk + 1 << ").g1, dr(" << blk + 1 << ").g1_x, dr(" << blk + 1 << ").g1_xd, dr(" << blk + 1 << ").g1_o]=" << basename << ".block.dynamic_" << blk + 1 << "(y, x, params, steady_state, T, it_, true);" << endl
|
||||||
<< " residual(y_index_eq)=ys(y_index)-y(it_, y_index);" << endl;
|
<< " r=NaN(M_.endo_nbr,1);" << endl
|
||||||
|
<< " r(nonzeros(ll_index))=ys(find(ll_index))-y(find(ll_index));" << endl
|
||||||
|
<< " residual(y_index_eq)=r(y_index);" << endl;
|
||||||
break;
|
break;
|
||||||
case BlockSimulationType::solveForwardSimple:
|
case BlockSimulationType::solveForwardSimple:
|
||||||
case BlockSimulationType::solveBackwardSimple:
|
case BlockSimulationType::solveBackwardSimple:
|
||||||
|
@ -5496,7 +5498,7 @@ DynamicModel::isChecksumMatching(const string &basename, bool block) const
|
||||||
// Write equation tags
|
// Write equation tags
|
||||||
equation_tags.writeCheckSumInfo(buffer);
|
equation_tags.writeCheckSumInfo(buffer);
|
||||||
|
|
||||||
ExprNodeOutputType buffer_type = block ? ExprNodeOutputType::matlabDynamicBlockModel : ExprNodeOutputType::CDynamicModel;
|
ExprNodeOutputType buffer_type = ExprNodeOutputType::CDynamicModel;
|
||||||
|
|
||||||
deriv_node_temp_terms_t tef_terms;
|
deriv_node_temp_terms_t tef_terms;
|
||||||
temporary_terms_t temp_term_union;
|
temporary_terms_t temp_term_union;
|
||||||
|
|
|
@ -100,10 +100,8 @@ ExprNode::checkIfTemporaryTermThenWrite(ostream &output, ExprNodeOutputType outp
|
||||||
// It is the responsibility of the caller to ensure that all temporary terms have their index
|
// It is the responsibility of the caller to ensure that all temporary terms have their index
|
||||||
assert(it2 != temporary_terms_idxs.end());
|
assert(it2 != temporary_terms_idxs.end());
|
||||||
output << "T" << LEFT_ARRAY_SUBSCRIPT(output_type)
|
output << "T" << LEFT_ARRAY_SUBSCRIPT(output_type)
|
||||||
<< it2->second + ARRAY_SUBSCRIPT_OFFSET(output_type);
|
<< it2->second + ARRAY_SUBSCRIPT_OFFSET(output_type)
|
||||||
if (output_type == ExprNodeOutputType::matlabDynamicBlockModel)
|
<< RIGHT_ARRAY_SUBSCRIPT(output_type);
|
||||||
output << ",it_";
|
|
||||||
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1006,15 +1004,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
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;
|
||||||
case ExprNodeOutputType::matlabDynamicBlockModel:
|
|
||||||
i = tsid + ARRAY_SUBSCRIPT_OFFSET(output_type);
|
|
||||||
if (lag > 0)
|
|
||||||
output << "y" << LEFT_ARRAY_SUBSCRIPT(output_type) << "it_+" << lag << ", " << i << RIGHT_ARRAY_SUBSCRIPT(output_type);
|
|
||||||
else if (lag < 0)
|
|
||||||
output << "y" << LEFT_ARRAY_SUBSCRIPT(output_type) << "it_" << lag << ", " << i << RIGHT_ARRAY_SUBSCRIPT(output_type);
|
|
||||||
else
|
|
||||||
output << "y" << LEFT_ARRAY_SUBSCRIPT(output_type) << "it_, " << i << RIGHT_ARRAY_SUBSCRIPT(output_type);
|
|
||||||
break;
|
|
||||||
case ExprNodeOutputType::matlabOutsideModel:
|
case ExprNodeOutputType::matlabOutsideModel:
|
||||||
output << "oo_.steady_state(" << tsid + 1 << ")";
|
output << "oo_.steady_state(" << tsid + 1 << ")";
|
||||||
break;
|
break;
|
||||||
|
@ -1053,7 +1042,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
{
|
{
|
||||||
case ExprNodeOutputType::juliaDynamicModel:
|
case ExprNodeOutputType::juliaDynamicModel:
|
||||||
case ExprNodeOutputType::matlabDynamicModel:
|
case ExprNodeOutputType::matlabDynamicModel:
|
||||||
case ExprNodeOutputType::matlabDynamicBlockModel:
|
|
||||||
if (lag > 0)
|
if (lag > 0)
|
||||||
output << "x" << LEFT_ARRAY_SUBSCRIPT(output_type) << "it_+" << lag << ", " << i
|
output << "x" << LEFT_ARRAY_SUBSCRIPT(output_type) << "it_+" << lag << ", " << i
|
||||||
<< RIGHT_ARRAY_SUBSCRIPT(output_type);
|
<< RIGHT_ARRAY_SUBSCRIPT(output_type);
|
||||||
|
@ -1112,7 +1100,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
{
|
{
|
||||||
case ExprNodeOutputType::juliaDynamicModel:
|
case ExprNodeOutputType::juliaDynamicModel:
|
||||||
case ExprNodeOutputType::matlabDynamicModel:
|
case ExprNodeOutputType::matlabDynamicModel:
|
||||||
case ExprNodeOutputType::matlabDynamicBlockModel:
|
|
||||||
if (lag > 0)
|
if (lag > 0)
|
||||||
output << "x" << LEFT_ARRAY_SUBSCRIPT(output_type) << "it_+" << lag << ", " << i
|
output << "x" << LEFT_ARRAY_SUBSCRIPT(output_type) << "it_+" << lag << ", " << i
|
||||||
<< RIGHT_ARRAY_SUBSCRIPT(output_type);
|
<< RIGHT_ARRAY_SUBSCRIPT(output_type);
|
||||||
|
@ -2735,7 +2722,6 @@ UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
switch (output_type)
|
switch (output_type)
|
||||||
{
|
{
|
||||||
case ExprNodeOutputType::matlabDynamicModel:
|
case ExprNodeOutputType::matlabDynamicModel:
|
||||||
case ExprNodeOutputType::matlabDynamicBlockModel:
|
|
||||||
new_output_type = ExprNodeOutputType::matlabDynamicSteadyStateOperator;
|
new_output_type = ExprNodeOutputType::matlabDynamicSteadyStateOperator;
|
||||||
break;
|
break;
|
||||||
case ExprNodeOutputType::latexDynamicModel:
|
case ExprNodeOutputType::latexDynamicModel:
|
||||||
|
|
|
@ -83,7 +83,6 @@ enum class ExprNodeOutputType
|
||||||
{
|
{
|
||||||
matlabStaticModel, //!< Matlab code, static model
|
matlabStaticModel, //!< Matlab code, static model
|
||||||
matlabDynamicModel, //!< Matlab code, dynamic model
|
matlabDynamicModel, //!< Matlab code, dynamic model
|
||||||
matlabDynamicBlockModel, //!< Matlab code, dynamic block-decomposed model
|
|
||||||
CDynamicModel, //!< C code, dynamic model
|
CDynamicModel, //!< C code, dynamic model
|
||||||
CStaticModel, //!< C code, static model
|
CStaticModel, //!< C code, static model
|
||||||
juliaStaticModel, //!< Julia code, static model
|
juliaStaticModel, //!< Julia code, static model
|
||||||
|
@ -107,7 +106,6 @@ isMatlabOutput(ExprNodeOutputType output_type)
|
||||||
return output_type == ExprNodeOutputType::matlabStaticModel
|
return output_type == ExprNodeOutputType::matlabStaticModel
|
||||||
|| output_type == ExprNodeOutputType::matlabDynamicModel
|
|| output_type == ExprNodeOutputType::matlabDynamicModel
|
||||||
|| output_type == ExprNodeOutputType::matlabOutsideModel
|
|| output_type == ExprNodeOutputType::matlabOutsideModel
|
||||||
|| output_type == ExprNodeOutputType::matlabDynamicBlockModel
|
|
||||||
|| output_type == ExprNodeOutputType::matlabDynamicSteadyStateOperator
|
|| output_type == ExprNodeOutputType::matlabDynamicSteadyStateOperator
|
||||||
|| output_type == ExprNodeOutputType::steadyStateFile
|
|| output_type == ExprNodeOutputType::steadyStateFile
|
||||||
|| output_type == ExprNodeOutputType::matlabDseries
|
|| output_type == ExprNodeOutputType::matlabDseries
|
||||||
|
|
|
@ -339,7 +339,7 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_t &eval_context) const
|
||||||
catch (ExprNode::EvalException &e)
|
catch (ExprNode::EvalException &e)
|
||||||
{
|
{
|
||||||
cerr << "ERROR: evaluation of Jacobian failed for equation " << eq+1 << " (line " << equations_lineno[eq] << ") and variable " << symbol_table.getName(symb) << "(" << lag << ") [" << symb << "] !" << endl;
|
cerr << "ERROR: evaluation of Jacobian failed for equation " << eq+1 << " (line " << equations_lineno[eq] << ") and variable " << symbol_table.getName(symb) << "(" << lag << ") [" << symb << "] !" << endl;
|
||||||
d1->writeOutput(cerr, ExprNodeOutputType::matlabDynamicBlockModel, {}, {});
|
d1->writeOutput(cerr, ExprNodeOutputType::matlabDynamicModel, {}, {});
|
||||||
cerr << endl;
|
cerr << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue