Skip to content

Commit

Permalink
added workaround in cpp tempate: try to solve algloop discrete if it …
Browse files Browse the repository at this point in the history
…not solvable

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18366 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Dec 2, 2013
1 parent 96c81ed commit 01c098b
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions Compiler/Template/CodegenCpp.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4236,6 +4236,10 @@ template equation_(SimEqSystem eq, Context context, Text &varDecls, SimCode simC
bool* conditions0<%index%> = new bool[_dimZeroFunc];
bool* conditions1<%index%> = new bool[_dimZeroFunc];
unsigned int iterations<%index%> = 0;
unsigned int dim<%index%> = _algLoop<%index%>->getDimReal();
double* algloop<%index%>Vars = new double[dim<%index%>];
_algLoop<%index%>->getReal(algloop<%index%>Vars );

try
{
Expand Down Expand Up @@ -4274,8 +4278,23 @@ template equation_(SimEqSystem eq, Context context, Text &varDecls, SimCode simC
delete[] conditions0<%index%>;
delete[] conditions1<%index%>;
if(restart<%index%>&& iterations<%index%> > 0)
throw std::invalid_argument("Nonlinear solver stopped at time " + boost::lexical_cast<string>(_simTime) );

{
try
{ //workaround: try to solve algoop discrete (evaluate all zero crossing conditions) since we do not have the information which zercrossing contains a algloop var
IContinuous::UPDATETYPE calltype = _callType;
_callType = IContinuous::DISCRETE;
_algLoop<%index%>->setReal(algloop<%index%>Vars );
_algLoopSolver<%index%>->solve(command);
_callType = calltype;
}
catch(std::exception &ex)
{
delete[] algloop<%index%>Vars;
throw std::invalid_argument("Nonlinear solver stopped at time " + boost::lexical_cast<string>(_simTime) + " with error: " + ex.what());
}

}
delete[] algloop<%index%>Vars;
>>
end match

Expand Down

0 comments on commit 01c098b

Please sign in to comment.