Skip to content

Commit 8a87f91

Browse files
committed
fix event iteration for algloops
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18337 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 2cb3f6e commit 8a87f91

File tree

1 file changed

+14
-32
lines changed

1 file changed

+14
-32
lines changed

Compiler/Template/CodegenCpp.tpl

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4200,46 +4200,27 @@ template equation_(SimEqSystem eq, Context context, Text &varDecls, SimCode simC
42004200
then
42014201
<<
42024202

4203-
bool* conditions0<%index%> = new bool[_dimZeroFunc];
4204-
bool* conditions1<%index%> = new bool[_dimZeroFunc];
4205-
bool restart<%index%>=true;
4206-
unsigned int iterations<%index%> = 0;
4203+
4204+
42074205
try
42084206
{
42094207
_algLoopSolver<%index%>->initialize();
42104208
_algLoop<%index%>->evaluate();
4211-
4212-
unsigned int iterations = 0;
4213-
if( _callType == IContinuous::DISCRETE )
4209+
for(int i=0;i<_dimZeroFunc;i++)
42144210
{
4215-
while(restart<%index%> && !(iterations<%index%>++>500))
4216-
{
4217-
4218-
getConditions(conditions0<%index%>);
4219-
_algLoopSolver<%index%>->solve();
4220-
4221-
for(int i=0;i<_dimZeroFunc;i++)
4222-
{
4223-
getCondition(i);
4224-
}
4225-
4226-
getConditions(conditions1<%index%>);
4227-
restart<%index%> = !std::equal (conditions1<%index%>, conditions1<%index%>+_dimZeroFunc,conditions0<%index%>);
4228-
}
4211+
getCondition(i);
42294212
}
4230-
else
4231-
_algLoopSolver<%index%>->solve();
4213+
IContinuous::UPDATETYPE calltype = _callType;
4214+
_callType = IContinuous::CONTINUOUS;
4215+
_algLoopSolver<%index%>->solve();
4216+
_callType = calltype;
42324217
}
42334218
catch(std::exception &ex)
42344219
{
4235-
delete[] conditions0<%index%>;
4236-
delete[] conditions1<%index%>;
4220+
42374221
throw std::invalid_argument("Nonlinear solver stopped at time " + boost::lexical_cast<string>(_simTime) + " with error: " + ex.what());
42384222
}
4239-
delete[] conditions0<%index%>;
4240-
delete[] conditions1<%index%>;
4241-
if(restart<%index%> && iterations<%index%> > 0)
4242-
throw std::invalid_argument("Nonlinear solver stopped at time " + boost::lexical_cast<string>(_simTime) );
4223+
42434224
>>
42444225
else
42454226
<<
@@ -4252,21 +4233,22 @@ template equation_(SimEqSystem eq, Context context, Text &varDecls, SimCode simC
42524233
{
42534234
42544235
_algLoop<%index%>->evaluate();
4255-
4236+
42564237
42574238
if( _callType == IContinuous::DISCRETE )
42584239
{
42594240
while(restart<%index%> && !(iterations<%index%>++>500))
42604241
{
42614242
42624243
getConditions(conditions0<%index%>);
4244+
_callType = IContinuous::CONTINUOUS;
42634245
_algLoopSolver<%index%>->solve();
4264-
4246+
_callType = IContinuous::DISCRETE;
42654247
for(int i=0;i<_dimZeroFunc;i++)
42664248
{
42674249
getCondition(i);
42684250
}
4269-
4251+
42704252
getConditions(conditions1<%index%>);
42714253
restart<%index%> = !std::equal (conditions1<%index%>, conditions1<%index%>+_dimZeroFunc,conditions0<%index%>);
42724254
}

0 commit comments

Comments
 (0)