Fix block decomposition with temporary terms array

issue#70
Sébastien Villemot 2018-05-28 11:56:34 +02:00
parent 38ed0f2ffc
commit 8657d4dc98
4 changed files with 32 additions and 29 deletions

View File

@ -419,7 +419,8 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
it != v_temporary_terms[block][i].end(); it++)
{
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;
}
}
@ -464,9 +465,9 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
(*it)->writeExternalFunctionOutput(output, local_output_type, tt2, temporary_terms_idxs, tef_terms);
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 << " = ";
(*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
tt2.insert(*it);
output << ";" << endl;
@ -481,7 +482,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
lhs = eq_node->get_arg1();
rhs = eq_node->get_arg2();
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)
{
case EVALUATE_BACKWARD:
@ -494,7 +495,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
{
output << tmp_output.str();
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)
{
@ -502,15 +503,15 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
output << " = ";
if (isBlockEquationRenormalized(block, i))
{
rhs->writeOutput(output, local_output_type, local_temporary_terms);
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
output << "\n ";
tmp_output.str("");
eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i);
lhs = eq_node->get_arg1();
rhs = eq_node->get_arg2();
lhs->writeOutput(output, local_output_type, local_temporary_terms);
lhs->writeOutput(output, local_output_type, local_temporary_terms, {});
output << " = ";
rhs->writeOutput(output, local_output_type, local_temporary_terms);
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
}
}
else
@ -547,7 +548,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
end:
output << tmp_output.str();
output << ") - (";
rhs->writeOutput(output, local_output_type, local_temporary_terms);
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
output << ");\n";
#ifdef CONDITION
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;
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))
<< "(" << lag
<< ") " << varr+1 << ", " << var+1
@ -607,7 +608,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
}
expr_t id = it->second;
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))
<< "(" << lag
<< ") " << var+1
@ -630,7 +631,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
}
expr_t id = it->second;
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))
<< "(" << lag
<< ") " << var+1
@ -654,7 +655,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
expr_t id = it->second;
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))
<< "(" << lag
<< ") " << var+1
@ -687,7 +688,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
if (lag == 0)
{
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))
<< "(" << lag
<< ") " << varr+1
@ -743,7 +744,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
tmp_output << " g1(" << eq+1-block_recursive << "+Per_J_, "
<< var+1-block_recursive << "+y_size*(it_" << lag-1 << ")) = ";
output << " " << tmp_output.str();
id->writeOutput(output, local_output_type, local_temporary_terms);
id->writeOutput(output, local_output_type, local_temporary_terms, {});
output << ";";
output << " %2 variable=" << symbol_table.getName(symbol_table.getID(eEndogenous, varr))
<< "(" << lag << ") " << varr+1
@ -1838,7 +1839,8 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
OK = false;
else
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)
mDynamicModelFile << " global " << tmp_output.str() << ";\n";
@ -1849,7 +1851,8 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
it != temporary_terms.end(); it++)
{
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";
}
if (tmp_output.str().length() > 0)

View File

@ -113,7 +113,7 @@ ExprNode::checkIfTemporaryTermThenWrite(ostream &output, ExprNodeOutputType outp
if (output_type == oMatlabDynamicModelSparse)
output << "T" << idx << "(it_)";
else
if (IS_C(output_type))
if (output_type == oMatlabStaticModelSparse || IS_C(output_type))
output << "T" << idx;
else
{

View File

@ -280,7 +280,7 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_t &eval_context, jacob_m
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;
Id->writeOutput(cerr, oMatlabDynamicModelSparse, temporary_terms);
Id->writeOutput(cerr, oMatlabDynamicModelSparse, temporary_terms, {});
cerr << endl;
exit(EXIT_FAILURE);
}

View File

@ -288,12 +288,12 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
it != v_temporary_terms[block][i].end(); it++)
{
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;
(*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 << " = ";
(*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
tt2.insert(*it);
output << ";" << endl;
@ -308,7 +308,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
lhs = eq_node->get_arg1();
rhs = eq_node->get_arg2();
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)
{
case EVALUATE_BACKWARD:
@ -321,7 +321,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
{
output << tmp_output.str();
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)
{
@ -329,15 +329,15 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
output << " = ";
if (isBlockEquationRenormalized(block, i))
{
rhs->writeOutput(output, local_output_type, local_temporary_terms);
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
output << "\n ";
tmp_output.str("");
eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i);
lhs = eq_node->get_arg1();
rhs = eq_node->get_arg2();
lhs->writeOutput(output, local_output_type, local_temporary_terms);
lhs->writeOutput(output, local_output_type, local_temporary_terms, {});
output << " = ";
rhs->writeOutput(output, local_output_type, local_temporary_terms);
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
}
}
else
@ -362,7 +362,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
end:
output << tmp_output.str();
output << ") - (";
rhs->writeOutput(output, local_output_type, local_temporary_terms);
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
output << ");\n";
}
}
@ -384,7 +384,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
unsigned int varr = getBlockVariableID(block, var);
expr_t id = it->second.second;
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))
<< "(" << 0
<< ") " << varr+1