Skip to content

Commit eb90919

Browse files
authored
Fix handling of REAL_CLOCK (#8390)
- Do not put Clock constructor arguments inside previous call, but still generate local var if necessary. - No need to update constant interval.
1 parent ed824a9 commit eb90919

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

OMCompiler/Compiler/BackEnd/SynchronousFeatures.mo

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,9 +2302,8 @@ algorithm
23022302
then (DAE.REAL_CLOCK(e), eqs, vars, cnt);
23032303

23042304
case DAE.RATIONAL_CLOCK(e, i) equation
2305-
// AHeu: Surpressing substClockExp to get rid of previous in intervalCounter
2306-
//(e, eqs, vars, cnt) = substClockExp(e, inNewEqs, inNewVars, inCnt, inShared);
2307-
then (DAE.RATIONAL_CLOCK(e, i), inNewEqs, inNewVars, inCnt);
2305+
(e, eqs, vars, cnt) = substClockExp(e, inNewEqs, inNewVars, inCnt, inShared);
2306+
then (DAE.RATIONAL_CLOCK(e, i), eqs, vars, cnt);
23082307

23092308
else (inClk, inNewEqs, inNewVars, inCnt);
23102309
end match;
@@ -2362,10 +2361,6 @@ algorithm
23622361
outCnt := inCnt;
23632362
else
23642363
({outExp}, outNewEqs, outNewVars, outCnt) := substExp({inExp}, inNewEqs, inNewVars, inCnt);
2365-
outExp := match outExp
2366-
case DAE.CREF(_, ty) then Expression.makePureBuiltinCall("previous", {outExp}, ty);
2367-
else outExp;
2368-
end match;
23692364
end if;
23702365
end substClockExp;
23712366

OMCompiler/Compiler/Template/CodegenC.tpl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ template baseClockInit(ClockKind baseClock, Integer baseClockIdx, list<SubPartit
357357
else
358358
'0'
359359
let interval = match baseClock
360+
case REAL_CLOCK() then
361+
if isConst(interval) then
362+
daeExp(interval, contextOther, &preExp, &varDecls, &auxFunction)
363+
else
364+
'-1 /* Interval set in _updateSynchronous */'
360365
case INFERRED_CLOCK() then
361366
'1'
362367
else
@@ -471,11 +476,16 @@ template updatePartition(Integer i, DAE.ClockKind baseClock, Text &varDecls, Tex
471476
data->simulationInfo->baseClocks[base_idx].interval = DIVISION((modelica_real)data->simulationInfo->baseClocks[base_idx].intervalCounter, (modelica_real)data->simulationInfo->baseClocks[base_idx].resolution, "intervalCounter/resolution");
472477
>>
473478
case REAL_CLOCK() then
474-
let interval = daeExp(getClockInterval(baseClock), contextOther, &preExp, &varDecls, &auxFunction)
475-
<<
476-
<%preExp%>
477-
data->simulationInfo->baseClocks[base_idx].interval = <%interval%>;
478-
>>
479+
if isConst(interval) then
480+
<<
481+
/* Nothing to do */
482+
>>
483+
else
484+
let interval_ = daeExp(interval, contextOther, &preExp, &varDecls, &auxFunction)
485+
<<
486+
<%preExp%>
487+
data->simulationInfo->baseClocks[base_idx].interval = <%interval_%>;
488+
>>
479489
case INFERRED_CLOCK()
480490
case SOLVER_CLOCK()
481491
case EVENT_CLOCK() then

0 commit comments

Comments
 (0)