From 3695bf46952108e2c5e1b6123b19146b19b5844e Mon Sep 17 00:00:00 2001 From: Houtan Bastani 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 --- preprocessor/DynamicModel.cc | 18 ++++++++++++++++++ preprocessor/DynamicModel.hh | 3 +++ preprocessor/ModFile.cc | 12 +++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index 6d68eb425..20f8eb2cb 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -1731,6 +1731,24 @@ DynamicModel::reform(const string name1) const return (name); } +void +DynamicModel::getNonZeroHessianEquations(map &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/preprocessor/DynamicModel.hh b/preprocessor/DynamicModel.hh index 9c0e670ff..6b99423c7 100644 --- a/preprocessor/DynamicModel.hh +++ b/preprocessor/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 &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/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index 414a51308..e828fa45e 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/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 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::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); } }