Skip to content

Commit 4d935ff

Browse files
authored
update startTime provided by user in FMU (#12948)
1 parent d406121 commit 4d935ff

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

OMCompiler/SimulationRuntime/fmi/export/openmodelica/fmu2_model_interface.c.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,10 @@ fmi2Status fmi2SetupExperiment(fmi2Component c, fmi2Boolean toleranceDefined, fm
843843
comp->startTime = startTime;
844844
comp->stopTimeDefined = stopTimeDefined;
845845
comp->stopTime = stopTime;
846+
/* fix issue https://github.com/OpenModelica/OpenModelica/issues/12561
847+
update the startTime values provided by users (e.g) OMSimulator test.fmu --startTime=2.5
848+
*/
849+
comp->fmuData->localData[0]->timeValue = startTime;
846850
return fmi2OK;
847851
}
848852

testsuite/omsimulator/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ recompileFMU.mos \
2424
reset_omc.mos \
2525
reset.mos \
2626
resetWithLoops.mos \
27+
setStartTime.mos \
2728
testDirectionalDerivatives.mos \
2829
testLoopsOverFMUs.mos \
2930
testSynchronousFMU_01.mos \
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// keywords: fmu export import
2+
// status: correct
3+
// teardown_command: rm -rf setstartTime.fmu setstartTime.log setstartTime_systemCall.log/
4+
5+
loadModel(Modelica); getErrorString();
6+
7+
loadString("
8+
model setstartTime
9+
import Modelica.Blocks.Sources;
10+
import Modelica.Blocks.Types;
11+
parameter Real x_0 = 5;
12+
Real x(start=x_0, fixed=true);
13+
Real t;
14+
Real u;
15+
Sources.CombiTimeTable scheme(
16+
smoothness=Types.Smoothness.ConstantSegments,
17+
extrapolation = Types.Extrapolation.HoldLastPoint,
18+
table=[0,0; 1.0,1; 2.0,2; 1003,3; 1004,4; 1005,5; 1006,6; 1007,7; 1008,8; 1009,9]);
19+
equation
20+
t = time;
21+
u = scheme.y[1];
22+
der(x) = -x;
23+
end setstartTime;
24+
"); getErrorString();
25+
26+
buildModelFMU(setstartTime, version="2.0", fmuType="me_cs", platforms={"static"}); getErrorString();
27+
28+
system(getInstallationDirectoryPath() + "/bin/OMSimulator setstartTime.fmu --startTime=2.5 --stopTime=5 -r=start_time_res.mat", "setstartTime_systemCall.log");
29+
readFile("setstartTime_systemCall.log");
30+
31+
val(t, 2.5, "start_time_res.mat");
32+
val(u, 2.5, "start_time_res.mat");
33+
34+
// Result:
35+
// true
36+
// ""
37+
// true
38+
// ""
39+
// "setstartTime.fmu"
40+
// ""
41+
// 0
42+
// "info: maximum step size for 'model.root': 0.002000
43+
// info: Result file: start_time_res.mat (bufferSize=1)
44+
// info: Parameter model.root.setstartTime.scheme.fileName will not be stored in the result file, because the signal type is not supported
45+
// info: Parameter model.root.setstartTime.scheme.tableName will not be stored in the result file, because the signal type is not supported
46+
// info: Final Statistics for 'model.root':
47+
// NumSteps = 1252 NumRhsEvals = 1255 NumLinSolvSetups = 65
48+
// NumNonlinSolvIters = 1254 NumNonlinSolvConvFails = 0 NumErrTestFails = 0
49+
// "
50+
// 2.5
51+
// 2.0
52+
// endResult

0 commit comments

Comments
 (0)