Drop ModelTree::getEquationTags(), and replace it by calls to better interfaces
parent
bdb5d37dec
commit
e2c72a1b75
|
@ -4790,3 +4790,22 @@ DynamicModel::checkNoRemainingPacTargetNonstationary() const
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DynamicModel::checkIsLinear() const
|
||||||
|
{
|
||||||
|
if (!nonzero_hessian_eqs.empty())
|
||||||
|
{
|
||||||
|
cerr << "ERROR: If the model is declared linear the second derivatives must be equal to zero." << endl
|
||||||
|
<< " The following equations have non-zero second derivatives:" << endl;
|
||||||
|
for (auto it : nonzero_hessian_eqs)
|
||||||
|
{
|
||||||
|
cerr << " * Eq # " << it+1;
|
||||||
|
if (optional<string> eqname { equation_tags.getTagValueByEqnAndKey(it, "name") };
|
||||||
|
eqname)
|
||||||
|
cerr << " [" << *eqname << "]";
|
||||||
|
cerr << endl;
|
||||||
|
}
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2003-2022 Dynare Team
|
* Copyright © 2003-2023 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -372,12 +372,13 @@ public:
|
||||||
{
|
{
|
||||||
return computed_derivs_order >= 2;
|
return computed_derivs_order >= 2;
|
||||||
}
|
}
|
||||||
//! Returns equations that have non-zero second derivatives
|
|
||||||
set<int>
|
/* Check whether the model is linear, by verifying that the hessian is zero,
|
||||||
getNonZeroHessianEquations() const
|
and error out otherwise.
|
||||||
{
|
Must be called after computingPass().
|
||||||
return nonzero_hessian_eqs;
|
FIXME: this check always passes if derivsOrder = 1, i.e. for a perfect
|
||||||
}
|
foresight model, because the Hessian is not computed in that case. */
|
||||||
|
void checkIsLinear() const;
|
||||||
|
|
||||||
//! Fill the trend component model table with information available from the transformed model
|
//! Fill the trend component model table with information available from the transformed model
|
||||||
void fillTrendComponentModelTable() const;
|
void fillTrendComponentModelTable() const;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2006-2022 Dynare Team
|
* Copyright © 2006-2023 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -738,30 +738,11 @@ ModFile::computingPass(bool no_tmp_terms, OutputType output, int params_derivs_o
|
||||||
else // No computing task requested, compute derivatives up to 2nd order by default
|
else // No computing task requested, compute derivatives up to 2nd order by default
|
||||||
dynamic_model.computingPass(2, 0, global_eval_context, no_tmp_terms, block, use_dll);
|
dynamic_model.computingPass(2, 0, global_eval_context, no_tmp_terms, block, use_dll);
|
||||||
|
|
||||||
/* Check that the model is linear.
|
|
||||||
FIXME: this check always passes if derivsOrder = 1, i.e. for a perfect
|
|
||||||
foresight model, because the Hessian is not computed in that case. */
|
|
||||||
if (linear)
|
if (linear)
|
||||||
{
|
if (mod_file_struct.ramsey_model_present)
|
||||||
set<int> eqs = mod_file_struct.ramsey_model_present ?
|
orig_ramsey_dynamic_model.checkIsLinear();
|
||||||
orig_ramsey_dynamic_model.getNonZeroHessianEquations() :
|
else
|
||||||
dynamic_model.getNonZeroHessianEquations();
|
dynamic_model.checkIsLinear();
|
||||||
|
|
||||||
if (!eqs.empty())
|
|
||||||
{
|
|
||||||
cerr << "ERROR: If the model is declared linear the second derivatives must be equal to zero." << endl
|
|
||||||
<< " The following equations have non-zero second derivatives:" << endl;
|
|
||||||
for (const auto &it : eqs)
|
|
||||||
{
|
|
||||||
cerr << " * Eq # " << it+1;
|
|
||||||
auto tags = dynamic_model.getEquationTags(it);
|
|
||||||
if (auto it2 = tags.find("name"); it2 != tags.end())
|
|
||||||
cerr << " [" << it2->second << "]";
|
|
||||||
cerr << endl;
|
|
||||||
}
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Those matrices can only be filled here, because we use derivatives
|
// Those matrices can only be filled here, because we use derivatives
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2003-2022 Dynare Team
|
* Copyright © 2003-2023 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -1418,8 +1418,7 @@ void
|
||||||
ModelTree::findConstantEquationsWithoutMcpTag(map<VariableNode *, NumConstNode *> &subst_table) const
|
ModelTree::findConstantEquationsWithoutMcpTag(map<VariableNode *, NumConstNode *> &subst_table) const
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < equations.size(); i++)
|
for (size_t i = 0; i < equations.size(); i++)
|
||||||
if (auto tags = getEquationTags(i);
|
if (!equation_tags.exists(i, "mcp"))
|
||||||
tags.find("mcp") == tags.end())
|
|
||||||
equations[i]->findConstantEquations(subst_table);
|
equations[i]->findConstantEquations(subst_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1587,7 +1586,7 @@ ModelTree::writeJsonModelEquations(ostream &output, bool residuals) const
|
||||||
if (equations_lineno[eq])
|
if (equations_lineno[eq])
|
||||||
output << R"(, "line": )" << *equations_lineno[eq];
|
output << R"(, "line": )" << *equations_lineno[eq];
|
||||||
|
|
||||||
if (auto eqtags = getEquationTags(eq);
|
if (auto eqtags = equation_tags.getTagsByEqn(eq);
|
||||||
!eqtags.empty())
|
!eqtags.empty())
|
||||||
{
|
{
|
||||||
output << R"(, "tags": {)";
|
output << R"(, "tags": {)";
|
||||||
|
|
|
@ -659,13 +659,6 @@ public:
|
||||||
// Waits until the MEX compilation queue is empty
|
// Waits until the MEX compilation queue is empty
|
||||||
static void waitForMEXCompilationWorkers();
|
static void waitForMEXCompilationWorkers();
|
||||||
|
|
||||||
//! Returns all the equation tags associated to an equation
|
|
||||||
map<string, string>
|
|
||||||
getEquationTags(int eq) const
|
|
||||||
{
|
|
||||||
return equation_tags.getTagsByEqn(eq);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Returns the vector of non-zero derivative counts
|
//! Returns the vector of non-zero derivative counts
|
||||||
const vector<int> &
|
const vector<int> &
|
||||||
getNNZDerivatives() const
|
getNNZDerivatives() const
|
||||||
|
|
Loading…
Reference in New Issue