In the driver file, provide mapping between model local variables and indices in the temporary terms vector

The structures are M_.model_local_variables_{dynamic,static}_tt_idxs.

Ref. dynare#1722
issue#70
Sébastien Villemot 2020-06-05 17:11:29 +02:00
parent 90b9b6a1e4
commit b402e35683
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
4 changed files with 18 additions and 2 deletions

View File

@ -2575,6 +2575,14 @@ DynamicModel::writeDriverOutput(ostream &output, const string &basename, bool bl
for (size_t i = 0; i < temporary_terms_derivatives.size(); i++)
output << temporary_terms_derivatives[i].size() + (i == 0 ? temporary_terms_mlv.size() : 0) << "; ";
output << "];" << endl;
/* Write mapping between model local variables and indices in the temporary
terms vector (dynare#1722) */
output << modstruct << "model_local_variables_dynamic_tt_idxs = {" << endl;
for (auto [mlv, value] : temporary_terms_mlv)
output << " '" << symbol_table.getName(mlv->symb_id) << "', "
<< temporary_terms_idxs.at(mlv)+1 << ';' << endl;
output << "};" << endl;
}
// Write equation tags

View File

@ -70,7 +70,7 @@ ModelTree::copyHelper(const ModelTree &m)
// Temporary terms
for (const auto &it : m.temporary_terms_mlv)
temporary_terms_mlv[f(it.first)] = f(it.second);
temporary_terms_mlv[dynamic_cast<VariableNode *>(f(it.first))] = f(it.second);
for (const auto &it : m.temporary_terms_derivatives)
temporary_terms_derivatives.push_back(convert_temporary_terms_t(it));
for (const auto &it : m.temporary_terms_idxs)

View File

@ -123,7 +123,7 @@ protected:
//! Used model local variables, that will be treated as temporary terms
/*! See the comments in ModelTree::computeTemporaryTerms() */
map<expr_t, expr_t, ExprNodeLess> temporary_terms_mlv;
map<VariableNode *, expr_t, ExprNodeLess> temporary_terms_mlv;
//! Temporary terms for residuals and derivatives
/*! Index 0 is temp. terms of residuals, index 1 for first derivatives, ... */

View File

@ -1728,6 +1728,14 @@ StaticModel::writeDriverOutput(ostream &output, bool block) const
output << temporary_terms_derivative.size() << "; ";
output << "];" << endl;
/* Write mapping between model local variables and indices in the temporary
terms vector (dynare#1722) */
output << "M_.model_local_variables_static_tt_idxs = {" << endl;
for (auto [mlv, value] : temporary_terms_mlv)
output << " '" << symbol_table.getName(mlv->symb_id) << "', "
<< temporary_terms_idxs.at(mlv)+1 << ';' << endl;
output << "};" << endl;
if (!block)
return;