Fix block decomposition with temporary terms array
parent
38ed0f2ffc
commit
8657d4dc98
|
@ -419,7 +419,8 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
|
||||||
it != v_temporary_terms[block][i].end(); it++)
|
it != v_temporary_terms[block][i].end(); it++)
|
||||||
{
|
{
|
||||||
output << " ";
|
output << " ";
|
||||||
(*it)->writeOutput(output, oMatlabDynamicModel, local_temporary_terms);
|
// In the following, "Static" is used to avoid getting the "(it_)" subscripting
|
||||||
|
(*it)->writeOutput(output, oMatlabStaticModelSparse, local_temporary_terms, {});
|
||||||
output << " = T_zeros;" << endl;
|
output << " = T_zeros;" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -464,9 +465,9 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
|
||||||
(*it)->writeExternalFunctionOutput(output, local_output_type, tt2, temporary_terms_idxs, tef_terms);
|
(*it)->writeExternalFunctionOutput(output, local_output_type, tt2, temporary_terms_idxs, tef_terms);
|
||||||
|
|
||||||
output << " " << sps;
|
output << " " << sps;
|
||||||
(*it)->writeOutput(output, local_output_type, local_temporary_terms, temporary_terms_idxs, tef_terms);
|
(*it)->writeOutput(output, local_output_type, local_temporary_terms, {}, tef_terms);
|
||||||
output << " = ";
|
output << " = ";
|
||||||
(*it)->writeOutput(output, local_output_type, tt2, temporary_terms_idxs, tef_terms);
|
(*it)->writeOutput(output, local_output_type, tt2, {}, tef_terms);
|
||||||
// Insert current node into tt2
|
// Insert current node into tt2
|
||||||
tt2.insert(*it);
|
tt2.insert(*it);
|
||||||
output << ";" << endl;
|
output << ";" << endl;
|
||||||
|
@ -481,7 +482,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
|
||||||
lhs = eq_node->get_arg1();
|
lhs = eq_node->get_arg1();
|
||||||
rhs = eq_node->get_arg2();
|
rhs = eq_node->get_arg2();
|
||||||
tmp_output.str("");
|
tmp_output.str("");
|
||||||
lhs->writeOutput(tmp_output, local_output_type, local_temporary_terms);
|
lhs->writeOutput(tmp_output, local_output_type, local_temporary_terms, {});
|
||||||
switch (simulation_type)
|
switch (simulation_type)
|
||||||
{
|
{
|
||||||
case EVALUATE_BACKWARD:
|
case EVALUATE_BACKWARD:
|
||||||
|
@ -494,7 +495,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
|
||||||
{
|
{
|
||||||
output << tmp_output.str();
|
output << tmp_output.str();
|
||||||
output << " = ";
|
output << " = ";
|
||||||
rhs->writeOutput(output, local_output_type, local_temporary_terms);
|
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
}
|
}
|
||||||
else if (equ_type == E_EVALUATE_S)
|
else if (equ_type == E_EVALUATE_S)
|
||||||
{
|
{
|
||||||
|
@ -502,15 +503,15 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
|
||||||
output << " = ";
|
output << " = ";
|
||||||
if (isBlockEquationRenormalized(block, i))
|
if (isBlockEquationRenormalized(block, i))
|
||||||
{
|
{
|
||||||
rhs->writeOutput(output, local_output_type, local_temporary_terms);
|
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
output << "\n ";
|
output << "\n ";
|
||||||
tmp_output.str("");
|
tmp_output.str("");
|
||||||
eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i);
|
eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i);
|
||||||
lhs = eq_node->get_arg1();
|
lhs = eq_node->get_arg1();
|
||||||
rhs = eq_node->get_arg2();
|
rhs = eq_node->get_arg2();
|
||||||
lhs->writeOutput(output, local_output_type, local_temporary_terms);
|
lhs->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
output << " = ";
|
output << " = ";
|
||||||
rhs->writeOutput(output, local_output_type, local_temporary_terms);
|
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -547,7 +548,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
|
||||||
end:
|
end:
|
||||||
output << tmp_output.str();
|
output << tmp_output.str();
|
||||||
output << ") - (";
|
output << ") - (";
|
||||||
rhs->writeOutput(output, local_output_type, local_temporary_terms);
|
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
output << ");\n";
|
output << ");\n";
|
||||||
#ifdef CONDITION
|
#ifdef CONDITION
|
||||||
if (simulation_type == SOLVE_TWO_BOUNDARIES_COMPLETE || simulation_type == SOLVE_TWO_BOUNDARIES_SIMPLE)
|
if (simulation_type == SOLVE_TWO_BOUNDARIES_COMPLETE || simulation_type == SOLVE_TWO_BOUNDARIES_SIMPLE)
|
||||||
|
@ -584,7 +585,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
|
||||||
expr_t id = it->second;
|
expr_t id = it->second;
|
||||||
|
|
||||||
output << " g1(" << eq+1 << ", " << count_col << ") = ";
|
output << " g1(" << eq+1 << ", " << count_col << ") = ";
|
||||||
id->writeOutput(output, local_output_type, local_temporary_terms);
|
id->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
output << "; % variable=" << symbol_table.getName(symbol_table.getID(eEndogenous, varr))
|
output << "; % variable=" << symbol_table.getName(symbol_table.getID(eEndogenous, varr))
|
||||||
<< "(" << lag
|
<< "(" << lag
|
||||||
<< ") " << varr+1 << ", " << var+1
|
<< ") " << varr+1 << ", " << var+1
|
||||||
|
@ -607,7 +608,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
|
||||||
}
|
}
|
||||||
expr_t id = it->second;
|
expr_t id = it->second;
|
||||||
output << " g1_x(" << eqr+1 << ", " << count_col << ") = ";
|
output << " g1_x(" << eqr+1 << ", " << count_col << ") = ";
|
||||||
id->writeOutput(output, local_output_type, local_temporary_terms);
|
id->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
output << "; % variable=" << symbol_table.getName(symbol_table.getID(eExogenous, var))
|
output << "; % variable=" << symbol_table.getName(symbol_table.getID(eExogenous, var))
|
||||||
<< "(" << lag
|
<< "(" << lag
|
||||||
<< ") " << var+1
|
<< ") " << var+1
|
||||||
|
@ -630,7 +631,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
|
||||||
}
|
}
|
||||||
expr_t id = it->second;
|
expr_t id = it->second;
|
||||||
output << " g1_xd(" << eqr+1 << ", " << count_col << ") = ";
|
output << " g1_xd(" << eqr+1 << ", " << count_col << ") = ";
|
||||||
id->writeOutput(output, local_output_type, local_temporary_terms);
|
id->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
output << "; % variable=" << symbol_table.getName(symbol_table.getID(eExogenous, var))
|
output << "; % variable=" << symbol_table.getName(symbol_table.getID(eExogenous, var))
|
||||||
<< "(" << lag
|
<< "(" << lag
|
||||||
<< ") " << var+1
|
<< ") " << var+1
|
||||||
|
@ -654,7 +655,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
|
||||||
expr_t id = it->second;
|
expr_t id = it->second;
|
||||||
|
|
||||||
output << " g1_o(" << eqr+1 << ", " << /*var+1+(lag+block_max_lag)*block_size*/ count_col << ") = ";
|
output << " g1_o(" << eqr+1 << ", " << /*var+1+(lag+block_max_lag)*block_size*/ count_col << ") = ";
|
||||||
id->writeOutput(output, local_output_type, local_temporary_terms);
|
id->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
output << "; % variable=" << symbol_table.getName(symbol_table.getID(eEndogenous, var))
|
output << "; % variable=" << symbol_table.getName(symbol_table.getID(eEndogenous, var))
|
||||||
<< "(" << lag
|
<< "(" << lag
|
||||||
<< ") " << var+1
|
<< ") " << var+1
|
||||||
|
@ -687,7 +688,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
|
||||||
if (lag == 0)
|
if (lag == 0)
|
||||||
{
|
{
|
||||||
output << " g1(" << eq+1 << ", " << var+1-block_recursive << ") = ";
|
output << " g1(" << eq+1 << ", " << var+1-block_recursive << ") = ";
|
||||||
id->writeOutput(output, local_output_type, local_temporary_terms);
|
id->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
output << "; % variable=" << symbol_table.getName(symbol_table.getID(eEndogenous, varr))
|
output << "; % variable=" << symbol_table.getName(symbol_table.getID(eEndogenous, varr))
|
||||||
<< "(" << lag
|
<< "(" << lag
|
||||||
<< ") " << varr+1
|
<< ") " << varr+1
|
||||||
|
@ -743,7 +744,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
|
||||||
tmp_output << " g1(" << eq+1-block_recursive << "+Per_J_, "
|
tmp_output << " g1(" << eq+1-block_recursive << "+Per_J_, "
|
||||||
<< var+1-block_recursive << "+y_size*(it_" << lag-1 << ")) = ";
|
<< var+1-block_recursive << "+y_size*(it_" << lag-1 << ")) = ";
|
||||||
output << " " << tmp_output.str();
|
output << " " << tmp_output.str();
|
||||||
id->writeOutput(output, local_output_type, local_temporary_terms);
|
id->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
output << ";";
|
output << ";";
|
||||||
output << " %2 variable=" << symbol_table.getName(symbol_table.getID(eEndogenous, varr))
|
output << " %2 variable=" << symbol_table.getName(symbol_table.getID(eEndogenous, varr))
|
||||||
<< "(" << lag << ") " << varr+1
|
<< "(" << lag << ") " << varr+1
|
||||||
|
@ -1838,7 +1839,8 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
|
||||||
OK = false;
|
OK = false;
|
||||||
else
|
else
|
||||||
tmp_output << " ";
|
tmp_output << " ";
|
||||||
(*it)->writeOutput(tmp_output, oMatlabStaticModelSparse, temporary_terms);
|
// In the following, "Static" is used to avoid getting the "(it_)" subscripting
|
||||||
|
(*it)->writeOutput(tmp_output, oMatlabStaticModelSparse, temporary_terms, {});
|
||||||
}
|
}
|
||||||
if (tmp_output.str().length() > 0)
|
if (tmp_output.str().length() > 0)
|
||||||
mDynamicModelFile << " global " << tmp_output.str() << ";\n";
|
mDynamicModelFile << " global " << tmp_output.str() << ";\n";
|
||||||
|
@ -1849,7 +1851,8 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
|
||||||
it != temporary_terms.end(); it++)
|
it != temporary_terms.end(); it++)
|
||||||
{
|
{
|
||||||
tmp_output << " ";
|
tmp_output << " ";
|
||||||
(*it)->writeOutput(tmp_output, oMatlabDynamicModel, temporary_terms);
|
// In the following, "Static" is used to avoid getting the "(it_)" subscripting
|
||||||
|
(*it)->writeOutput(tmp_output, oMatlabStaticModelSparse, temporary_terms, {});
|
||||||
tmp_output << "=T_init;\n";
|
tmp_output << "=T_init;\n";
|
||||||
}
|
}
|
||||||
if (tmp_output.str().length() > 0)
|
if (tmp_output.str().length() > 0)
|
||||||
|
|
|
@ -113,7 +113,7 @@ ExprNode::checkIfTemporaryTermThenWrite(ostream &output, ExprNodeOutputType outp
|
||||||
if (output_type == oMatlabDynamicModelSparse)
|
if (output_type == oMatlabDynamicModelSparse)
|
||||||
output << "T" << idx << "(it_)";
|
output << "T" << idx << "(it_)";
|
||||||
else
|
else
|
||||||
if (IS_C(output_type))
|
if (output_type == oMatlabStaticModelSparse || IS_C(output_type))
|
||||||
output << "T" << idx;
|
output << "T" << idx;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -280,7 +280,7 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_t &eval_context, jacob_m
|
||||||
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;
|
||||||
Id->writeOutput(cerr, oMatlabDynamicModelSparse, temporary_terms);
|
Id->writeOutput(cerr, oMatlabDynamicModelSparse, temporary_terms, {});
|
||||||
cerr << endl;
|
cerr << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,12 +288,12 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
|
||||||
it != v_temporary_terms[block][i].end(); it++)
|
it != v_temporary_terms[block][i].end(); it++)
|
||||||
{
|
{
|
||||||
if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL)
|
if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL)
|
||||||
(*it)->writeExternalFunctionOutput(output, local_output_type, tt2, temporary_terms_idxs, tef_terms);
|
(*it)->writeExternalFunctionOutput(output, local_output_type, tt2, {}, tef_terms);
|
||||||
|
|
||||||
output << " " << sps;
|
output << " " << sps;
|
||||||
(*it)->writeOutput(output, local_output_type, local_temporary_terms, temporary_terms_idxs, tef_terms);
|
(*it)->writeOutput(output, local_output_type, local_temporary_terms, {}, tef_terms);
|
||||||
output << " = ";
|
output << " = ";
|
||||||
(*it)->writeOutput(output, local_output_type, tt2, temporary_terms_idxs, tef_terms);
|
(*it)->writeOutput(output, local_output_type, tt2, {}, tef_terms);
|
||||||
// Insert current node into tt2
|
// Insert current node into tt2
|
||||||
tt2.insert(*it);
|
tt2.insert(*it);
|
||||||
output << ";" << endl;
|
output << ";" << endl;
|
||||||
|
@ -308,7 +308,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
|
||||||
lhs = eq_node->get_arg1();
|
lhs = eq_node->get_arg1();
|
||||||
rhs = eq_node->get_arg2();
|
rhs = eq_node->get_arg2();
|
||||||
tmp_output.str("");
|
tmp_output.str("");
|
||||||
lhs->writeOutput(tmp_output, local_output_type, local_temporary_terms);
|
lhs->writeOutput(tmp_output, local_output_type, local_temporary_terms, {});
|
||||||
switch (simulation_type)
|
switch (simulation_type)
|
||||||
{
|
{
|
||||||
case EVALUATE_BACKWARD:
|
case EVALUATE_BACKWARD:
|
||||||
|
@ -321,7 +321,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
|
||||||
{
|
{
|
||||||
output << tmp_output.str();
|
output << tmp_output.str();
|
||||||
output << " = ";
|
output << " = ";
|
||||||
rhs->writeOutput(output, local_output_type, local_temporary_terms);
|
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
}
|
}
|
||||||
else if (equ_type == E_EVALUATE_S)
|
else if (equ_type == E_EVALUATE_S)
|
||||||
{
|
{
|
||||||
|
@ -329,15 +329,15 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
|
||||||
output << " = ";
|
output << " = ";
|
||||||
if (isBlockEquationRenormalized(block, i))
|
if (isBlockEquationRenormalized(block, i))
|
||||||
{
|
{
|
||||||
rhs->writeOutput(output, local_output_type, local_temporary_terms);
|
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
output << "\n ";
|
output << "\n ";
|
||||||
tmp_output.str("");
|
tmp_output.str("");
|
||||||
eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i);
|
eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i);
|
||||||
lhs = eq_node->get_arg1();
|
lhs = eq_node->get_arg1();
|
||||||
rhs = eq_node->get_arg2();
|
rhs = eq_node->get_arg2();
|
||||||
lhs->writeOutput(output, local_output_type, local_temporary_terms);
|
lhs->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
output << " = ";
|
output << " = ";
|
||||||
rhs->writeOutput(output, local_output_type, local_temporary_terms);
|
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -362,7 +362,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
|
||||||
end:
|
end:
|
||||||
output << tmp_output.str();
|
output << tmp_output.str();
|
||||||
output << ") - (";
|
output << ") - (";
|
||||||
rhs->writeOutput(output, local_output_type, local_temporary_terms);
|
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
output << ");\n";
|
output << ");\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -384,7 +384,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
|
||||||
unsigned int varr = getBlockVariableID(block, var);
|
unsigned int varr = getBlockVariableID(block, var);
|
||||||
expr_t id = it->second.second;
|
expr_t id = it->second.second;
|
||||||
output << " g1(" << eq+1-block_recursive << ", " << var+1-block_recursive << ") = ";
|
output << " g1(" << eq+1-block_recursive << ", " << var+1-block_recursive << ") = ";
|
||||||
id->writeOutput(output, local_output_type, local_temporary_terms);
|
id->writeOutput(output, local_output_type, local_temporary_terms, {});
|
||||||
output << "; % variable=" << symbol_table.getName(symbol_table.getID(eEndogenous, varr))
|
output << "; % variable=" << symbol_table.getName(symbol_table.getID(eEndogenous, varr))
|
||||||
<< "(" << 0
|
<< "(" << 0
|
||||||
<< ") " << varr+1
|
<< ") " << varr+1
|
||||||
|
|
Loading…
Reference in New Issue