Skip to content

Commit

Permalink
Add test case for fmi2Reset
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel committed Jun 25, 2019
1 parent 6b0461b commit 0d156da
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions testsuite/omsimulator/Makefile
Expand Up @@ -6,6 +6,7 @@ DualMassOscillator_me.mos \
initialization.mos \
initialization2.mos \
outputState.mos \
reset.mos \

FAILINGTESTFILES = \

Expand Down
89 changes: 89 additions & 0 deletions testsuite/omsimulator/reset.mos
@@ -0,0 +1,89 @@
// keywords: fmu export import
// status: correct
// teardown_command: rm -rf reset.lua reset.fmu reset.log reset_systemCall.log temp-reset/

loadString("
model reset
parameter Real a = -1;
parameter Real x_start = 1;
Real x(start=x_start, fixed=true);
equation
der(x) = a*x;
end reset;"); getErrorString();

buildModelFMU(reset, version="2.0", fmuType="cs", platforms={"static"}); getErrorString();

writeFile("reset.lua", "
oms_setCommandLineOption(\"--suppressPath=true\")
oms_setTempDirectory(\"./temp-reset/\")

oms_newModel(\"test\")
oms_addSystem(\"test.root\", oms_system_wc)
oms_addSubModel(\"test.root.A\", \"reset.fmu\")
oms_setResultFile(\"test\", \"\")

oms_instantiate(\"test\")
oms_initialize(\"test\")

print(\"info: Initialization\")
print(\"info: A.x_start: \" .. oms_getReal(\"test.root.A.x_start\"))
print(\"info: A.x: \" .. oms_getReal(\"test.root.A.x\"))

oms_simulate(\"test\")
print(\"info: Simulation\")
print(\"info: A.x_start: \" .. oms_getReal(\"test.root.A.x_start\"))
print(\"info: A.x: \" .. oms_getReal(\"test.root.A.x\"))

for i=1,2 do
oms_reset(\"test\")
oms_setReal(\"test.root.A.x_start\", 1.5)
oms_initialize(\"test\")

print(\"info: Initialization\")
print(\"info: A.x_start: \" .. oms_getReal(\"test.root.A.x_start\"))
print(\"info: A.x: \" .. oms_getReal(\"test.root.A.x\"))

oms_simulate(\"test\")
print(\"info: Simulation\")
print(\"info: A.x_start: \" .. oms_getReal(\"test.root.A.x_start\"))
print(\"info: A.x: \" .. oms_getReal(\"test.root.A.x\"))
end

oms_terminate(\"test\")
oms_delete(\"test\")
"); getErrorString();

system(getInstallationDirectoryPath() + "/bin/OMSimulator reset.lua", "reset_systemCall.log");
readFile("reset_systemCall.log");

// Result:
// true
// ""
// "reset.fmu"
// ""
// true
// ""
// 0
// "info: No result file will be created
// info: Initialization
// info: A.x_start: 1.0
// info: A.x: 1.0
// info: Simulation
// info: A.x_start: 1.0
// info: A.x: 0.3486784401
// info: No result file will be created
// info: Initialization
// info: A.x_start: 1.5
// info: A.x: 1.5
// info: Simulation
// info: A.x_start: 1.5
// info: A.x: 0.52301766015
// info: No result file will be created
// info: Initialization
// info: A.x_start: 1.5
// info: A.x: 1.5
// info: Simulation
// info: A.x_start: 1.5
// info: A.x: 0.52301766015
// "
// endResult

0 comments on commit 0d156da

Please sign in to comment.