From e4745e040accacf3a02221102565755fa2363f38 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Wed, 27 Jul 2016 15:01:54 -0400 Subject: [PATCH] preprocessor: Return equation numbers/tags in error message when linear model contains nonzero hessian entries. #419 --- DynamicModel.cc | 18 ++++++++++++++++++ DynamicModel.hh | 3 +++ ModFile.cc | 12 +++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index 6d68eb42..20f8eb2c 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -1731,6 +1731,24 @@ DynamicModel::reform(const string name1) const return (name); } +void +DynamicModel::getNonZeroHessianEquations(map<int, string> &eqs) const +{ + for (second_derivatives_t::const_iterator it = second_derivatives.begin(); + it != second_derivatives.end(); it++) + if (eqs.find(it->first.first) == eqs.end()) + { + eqs[it->first.first] = ""; + for (size_t i = 0; i < equation_tags.size(); i++) + if (equation_tags[i].first == it->first.first) + if (equation_tags[i].second.first == "name") + { + eqs[it->first.first] = equation_tags[i].second.second; + break; + } + } +} + void DynamicModel::Write_Inf_To_Bin_File_Block(const string &dynamic_basename, const string &bin_basename, const int &num, int &u_count_int, bool &file_open, bool is_two_boundaries) const diff --git a/DynamicModel.hh b/DynamicModel.hh index 9c0e670f..6b99423c 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -220,6 +220,9 @@ public: //! Return true if the hessian is equal to zero inline bool checkHessianZero() const; + //! Return equations that have non-zero second derivatives + void getNonZeroHessianEquations(map<int, string> &eqs) const; + //! Adds informations for simulation in a binary file void Write_Inf_To_Bin_File_Block(const string &dynamic_basename, const string &bin_basename, const int &num, int &u_count_int, bool &file_open, bool is_two_boundaries) const; diff --git a/ModFile.cc b/ModFile.cc index 414a5130..e828fa45 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -536,7 +536,17 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output, bool compute_xr if (linear && !dynamic_model.checkHessianZero()) { - cerr << "ERROR: If the model is declared linear the second derivatives must be equal to zero." << endl; + map<int, string> eqs; + dynamic_model.getNonZeroHessianEquations(eqs); + cerr << "ERROR: If the model is declared linear the second derivatives must be equal to zero." << endl + << " The following equations had non-zero second derivatives:" << endl; + for (map<int, string >::const_iterator it = eqs.begin(); it != eqs.end(); it++) + { + cerr << " * Eq # " << it->first+1; + if (!it->second.empty()) + cerr << " [" << it->second << "]"; + cerr << endl; + } exit(EXIT_FAILURE); } } -- GitLab