Skip to content

Commit 30bf246

Browse files
authored
Add assert check for event sub-clocks (#8650)
1 parent 0b2db45 commit 30bf246

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

OMCompiler/SimulationRuntime/c/simulation/solver/synchronous.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ void initSynchronous(DATA* data, threadData_t *threadData, modelica_real startTi
6262
assertStreamPrint(threadData, data->simulationInfo->baseClocks[i].subClocks[j].solverMethod != NULL, "Continuous clocked systems aren't supported yet.");
6363
assertStreamPrint(threadData, floorRat(data->simulationInfo->baseClocks[i].subClocks[j].shift) >= 0, "Shift of sub-clock is negative. Sub-clocks aren't allowed to fire before base-clock.");
6464
}
65+
if (data->simulationInfo->baseClocks[i].isEventClock) { /*event clock*/
66+
for(j=0; j<data->simulationInfo->baseClocks[i].nSubClocks; j++) {
67+
assertStreamPrint(threadData, data->simulationInfo->baseClocks[i].subClocks[j].factor.den == 1, "Factor of sub-clock of event-clock is not an integer, this is not allowed.");
68+
}
69+
}
6570
}
6671

6772
for(i=0; i<data->modelData->nBaseClocks; i++)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
within ;
2+
model EventSubClock "See Modelica 3.5 spec, section 16.5.2 Sub-clock conversion operators"
3+
Clock c = Clock(time > 0.5);
4+
Clock c1 = superSample(c, 2);
5+
Integer n(start=1, fixed=true);
6+
equation
7+
when c1 then
8+
n = previous(n) + 1;
9+
end when;
10+
end EventSubClock;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// name: EventSubClock
2+
// keywords: synchronous clocked equations
3+
// status: correct
4+
// cflags: -d=-newInst --std=3.3
5+
6+
loadFile("EventSubClock.mo");getErrorString();
7+
simulate(EventSubClock);getErrorString();
8+
// Result:
9+
// true
10+
// ""
11+
// record SimulationResult
12+
// resultFile = "",
13+
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'EventSubClock', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
14+
// messages = "Simulation execution failed for model: EventSubClock
15+
// assert | debug | Factor of sub-clock of event-clock is not an integer, this is not allowed.
16+
// assert | info | simulation terminated by an assertion at initialization
17+
// "
18+
// end SimulationResult;
19+
// ""
20+
// endResult

testsuite/simulation/modelica/synchronous/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Bug3503.mos \
66
EventClock.mos \
77
EventClock_cpp.mos \
88
EventClockAndClassic.mos \
9+
EventSubClock.mos \
910
MutuallyDependentClocks.mos \
1011
SamplingWithClocks.mos \
1112
subSample.mos \

0 commit comments

Comments
 (0)