Skip to content

Commit d0a57cd

Browse files
committed
- fix booleanclock handling, use subpartidx for clockinit
1 parent 4ec62d0 commit d0a57cd

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

Compiler/FrontEnd/DAEUtil.mo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6042,6 +6042,18 @@ algorithm
60426042
end match;
60436043
end getAssertConditionCrefs;
60446044

6045+
public function isBooleanClock
6046+
input DAE.ClockKind clkKind;
6047+
output Boolean isBooleanClk;
6048+
algorithm
6049+
isBooleanClk := match(clkKind)
6050+
case(DAE.BOOLEAN_CLOCK(_))
6051+
then true;
6052+
else
6053+
then false;
6054+
end match;
6055+
end isBooleanClock;
6056+
60456057
public function getSubscriptIndex "author: marcusw
60466058
Get the index of the given subscript as Integer. If the subscript is not a constant integer, the function returns -1."
60476059
input DAE.Subscript iSubscript;

Compiler/Template/CodegenCpp.tpl

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9810,17 +9810,20 @@ case SIMCODE(modelInfo = MODELINFO(__), modelStructure = fmims) then
98109810
'ModelicaMessage("Using default Clock(1.0)!");'
98119811
let subClocks = (subPartitions |> subPartition =>
98129812
match subPartition
9813-
case SUBPARTITION(subClock=SUBCLOCK(factor=RATIONAL(nom=fnom, denom=fres), shift=RATIONAL(nom=snom, denom=sres))) then
9813+
case SUBPARTITION(idx=idx, subClock=SUBCLOCK(factor=RATIONAL(nom=fnom, denom=fres), shift=RATIONAL(nom=snom, denom=sres))) then
9814+
let startTime =if isBooleanClock(baseClock) then <<-1>> else <<_simTime + _clockShift[<%idx%>-1] * _clockInterval[<%idx%>-1]>>
9815+
let startCondition = if isBooleanClock(baseClock) then <<false>> else <<true>>
9816+
98149817
<<
98159818
<%preExp%>
9816-
_clockInterval[<%i%>] = <%interval%> * <%fnom%>.0 / <%fres%>.0;
9817-
_clockShift[<%i%>] = <%snom%>.0 / <%sres%>.0;
9818-
_clockTime[<%i%>] = _simTime + _clockShift[<%i%>] * _clockInterval[<%i%>];
9819-
if( _clockShift[<%i%>]>0)
9820-
_clockCondition[<%i%>] = false;
9819+
_clockInterval[<%idx%>-1] = <%interval%> * <%fnom%>.0 / <%fres%>.0;
9820+
_clockShift[<%idx%>-1] = <%snom%>.0 / <%sres%>.0;
9821+
_clockTime[<%idx%>-1] = <%startTime%>;
9822+
if( _clockShift[<%idx%>-1]>0)
9823+
_clockCondition[<%idx%>-1] = false;
98219824
else
9822-
_clockCondition[<%i%>] =true;
9823-
_clockStart[<%i%>] = true;
9825+
_clockCondition[<%idx%>-1] = <%startCondition%>;
9826+
_clockStart[<%idx%>-1] = true;
98249827

98259828
<%i%> ++;
98269829
>>
@@ -12473,7 +12476,8 @@ template handleSystemEvents(list<ZeroCrossing> zeroCrossings, SimCode simCode ,T
1247312476
//if there is a single clock event, update all clock conditions
1247412477
if (clock_event_detected){
1247512478
for(int i =0;i< _dimClock;i++){
12476-
if(_simTime +1e-9 > _clockTime[i]){
12479+
//check if a deterministic clockTime is reached, boolean clocks have clockTime -1
12480+
if(_simTime +1e-9 > _clockTime[i] and _clockTime[i]!= -1){
1247712481
_clockCondition[i]=true;
1247812482
}
1247912483
}
@@ -12806,9 +12810,11 @@ template clockedPartFunctions(Integer i, list<SimEqSystem> previousAssignments,
1280612810
case SUBCLOCK(factor=RATIONAL(nom=fnom, denom=fres), shift=RATIONAL(nom=snom, denom=sres))
1280712811
then
1280812812
<<
12813+
//compute new clock tick
1280912814
_clockInterval[<%idx%>] = <%intvl%> * <%fnom%>.0 / <%fres%>.0;
1281012815
_clockTime[<%idx%>] = _simTime +_clockInterval[<%idx%>] ;
1281112816
>>
12817+
let newClockTime = if isBooleanClock(baseClock) then <<_clockTime[<%idx%>] = -1;>> else clockvals
1281212818

1281312819
let funcs = listAppend(previousAssignments,equations) |> eq =>
1281412820
equation_function_create_single_func(eq, context/*BUFC*/, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, "evaluate", "", stateDerVectorName, useFlatArrayNotation, enableMeasureTime, false, false, 'const int clockIndex = <%i%>;<%\n%>')
@@ -12824,22 +12830,26 @@ template clockedPartFunctions(Integer i, list<SimEqSystem> previousAssignments,
1282412830
createEvaluateWithSplit(i0, context, eqs, funcName, className, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace)
1282512831
; separator="\n")
1282612832
let idx = intAdd(i, -1)
12833+
12834+
1282712835
<<
1282812836
<%funcs%>
1282912837

1283012838
void <%className%>::<%funcName%>(const UPDATETYPE command)
1283112839
{
1283212840

12833-
<%varDecls%>
12841+
<%varDecls%>
1283412842
<%preExp%>
12843+
12844+
// do we still need _clockStart?
1283512845
if (_simTime > _clockTime[<%idx%>]) {
1283612846
_clockStart[<%idx%>] = false;
1283712847
}
12848+
1283812849
//evaluate clock partition equations
1283912850
<%funcCalls%>
1284012851

12841-
//compute new clock tick
12842-
<%clockvals%>
12852+
<%newClockTime%>
1284312853

1284412854
//assign the previous-vars since the step is completed
1284512855
<%funcCallsPrev%>

Compiler/Template/SimCodeTV.mo

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3419,6 +3419,11 @@ package DAEUtil
34193419
output Boolean b;
34203420
end statementsContainTryBlock;
34213421

3422+
function isBooleanClock
3423+
input DAE.ClockKind clkKind;
3424+
output Boolean isBooleanClk;
3425+
end isBooleanClock;
3426+
34223427
end DAEUtil;
34233428

34243429
package Types

0 commit comments

Comments
 (0)