preprocessor: Return equation numbers/tags in error message when linear model contains nonzero hessian entries. #419

issue#70
Houtan Bastani 2016-07-27 15:01:54 -04:00
parent 98c08fd74b
commit e4745e040a
3 changed files with 32 additions and 1 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);
}
}