Skip to content

Commit

Permalink
update discreteSystems in fmu's during event update (OpenModelica#12390)
Browse files Browse the repository at this point in the history
  • Loading branch information
arun3688 committed May 7, 2024
1 parent 70d7a04 commit 9bc1350
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Expand Up @@ -333,6 +333,10 @@ fmi2Status internalEventUpdate(fmi2Component c, fmi2EventInfo* eventInfo)
* since the iteration seem not starting.
*/
storePreValues(comp->fmuData);
/* fix issue https://github.com/OpenModelica/OpenModelica/issues/12350
* we need to update discreteSystem during event update
*/
updateDiscreteSystem(comp->fmuData, threadData);
updateRelationsPre(comp->fmuData);

nextSampleEventDefined = getNextSampleTimeFMU(comp->fmuData, &nextSampleEvent);
Expand Down
1 change: 1 addition & 0 deletions testsuite/omsimulator/Makefile
Expand Up @@ -28,6 +28,7 @@ testDirectionalDerivatives.mos \
testLoopsOverFMUs.mos \
testSynchronousFMU_01.mos \
testSynchronousFMU_02.mos \
whenTest.mos \

FAILINGTESTFILES = \
test03.mos \
Expand Down
43 changes: 43 additions & 0 deletions testsuite/omsimulator/whenTest.mos
@@ -0,0 +1,43 @@
// keywords: fmu export import
// status: correct
// teardown_command: rm -rf WhenTest.fmu WhenTest.log WhenTest_res.mat WhenTest_info.json WhenTest_systemCall.log/

loadString("
model WhenTest
Real s(start=0, fixed=true);
Integer stop(start=0, fixed=true);
equation
der(s) = if stop > 0 then 0 else 2;
// Variant A
stop = if s >= 1 then 1 else 0;
when pre(stop) > 0 then
reinit(s, 1);
end when;
annotation(
experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-06, Interval = 0.002));
end WhenTest;
"); getErrorString();

buildModelFMU(WhenTest, version="2.0", fmuType="me", platforms={"static"}); getErrorString();

system(getInstallationDirectoryPath() + "/bin/OMSimulator WhenTest.fmu -r=WhenTest_res.mat", "WhenTest_systemCall.log");
readFile("WhenTest_systemCall.log");

val(der(s), 1.0, "WhenTest_res.mat");
val(stop, 1.0, "WhenTest_res.mat");

// Result:
// true
// ""
// "WhenTest.fmu"
// ""
// 0
// "info: maximum step size for 'model.root': 0.002000
// info: Result file: WhenTest_res.mat (bufferSize=1)
// info: Final Statistics for 'model.root':
// NumSteps = 250 NumRhsEvals = 251 NumLinSolvSetups = 14
// NumNonlinSolvIters = 250 NumNonlinSolvConvFails = 0 NumErrTestFails = 0
// "
// 0.0
// 1.0
// endResult

0 comments on commit 9bc1350

Please sign in to comment.