Skip to content

Commit

Permalink
- added testcase for fmi parameters changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Willi Braun committed Aug 3, 2015
1 parent 4db7025 commit 722fdf9
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 0 deletions.
1 change: 1 addition & 0 deletions openmodelica/fmi/ModelExchange/1.0/Makefile
Expand Up @@ -13,6 +13,7 @@ Modelica_Mechanics_MultiBody_Examples_Elementary_DoublePendulum.mos \
Pendulum.mos \
SampleExample.mos \
testAssert.mos \
testChangeParam.mos \
TanksConnectedPI.mos \
CoupledClutches.mos \
BooleanNetwork1.mos \
Expand Down
84 changes: 84 additions & 0 deletions openmodelica/fmi/ModelExchange/1.0/testChangeParam.mos
@@ -0,0 +1,84 @@
// name: testChangeParam
// keywords: FMI 2.0 export
// status: correct
// teardown_command: rm -rf binaries sources modelDescription.xml modelDescription.tmp.xml test_ChangeParam* output.log
//


loadString("
model test_ChangeParam
parameter Real a = 2.0;
parameter Integer i = 1;
parameter Boolean b = true;
parameter String s = \"foo\";
Real x(start=1);
input Real u;
output Real y;
equation
der(x) = x*a+u;
y = if b then der(x)-x-i else der(x)+x+i;
when time>1 then
terminate(\"Simulation done by \" + s);
end when;
annotation(experiment(StopTime=2));
end test_ChangeParam;
");
getErrorString();
loadModel(Modelica);


translateModelFMU(test_ChangeParam, version="2.0");
getErrorString();
importFMU("test_ChangeParam.fmu");

loadFile("test_ChangeParam_me_FMU.mo");
getErrorString();

simulate(test_ChangeParam_me_FMU);
val(x, 1);
val(a, 1);
val(y, 1);
getErrorString();

system("./test_ChangeParam_me_FMU -override a=-2,i=-10,b=false,s=\"bar\"");
echo(false);
readSimulationResult("test_ChangeParam_me_FMU_res.mat", {x,a,y});
echo(true);
val(x, 1);
val(a, 1);
val(y, 1);
getErrorString();


// Result:
// true
// ""
// true
// "SimCode: The model test_ChangeParam has been translated to FMU"
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
// "
// "test_ChangeParam_me_FMU.mo"
// true
// ""
// record SimulationResult
// resultFile = "test_ChangeParam_me_FMU_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 2.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'test_ChangeParam_me_FMU', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = "[<interactive>:14:7-14:43:writable]
// stdout | info | Simulation call terminate() at time 1.000000
// | | | | Message : Simulation done by foo
// "
// end SimulationResult;
// 7.389089930122212
// 2.0
// 6.389089930122212
// ""
// [<interactive>:14:7-14:43:writable]
// stdout | info | Simulation call terminate() at time 1.000000
// | | | | Message : Simulation done by bar
// 0
// true
// 0.135336321156737
// 2.0
// -10.13533632115674
// ""
// endResult
1 change: 1 addition & 0 deletions openmodelica/fmi/ModelExchange/2.0/Makefile
Expand Up @@ -7,6 +7,7 @@ HelloFMIWorld.mos \
HelloFMIWorldEvent.mos \
IntegerNetwork1.mos \
testAssert.mos \
testChangeParam.mos \
testBug2764.mos \
testBug3034.mos \
testBug3049.mos \
Expand Down
84 changes: 84 additions & 0 deletions openmodelica/fmi/ModelExchange/2.0/testChangeParam.mos
@@ -0,0 +1,84 @@
// name: testChangeParam
// keywords: FMI 2.0 export
// status: correct
// teardown_command: rm -rf binaries sources modelDescription.xml modelDescription.tmp.xml test_ChangeParam* output.log
//


loadString("
model test_ChangeParam
parameter Real a = 2.0;
parameter Integer i = 1;
parameter Boolean b = true;
parameter String s = \"foo\";
Real x(start=1);
input Real u;
output Real y;
equation
der(x) = x*a+u;
y = if b then der(x)-x-i else der(x)+x+i;
when time>1 then
terminate(\"Simulation done by \" + s);
end when;
annotation(experiment(StopTime=2));
end test_ChangeParam;
");
getErrorString();
loadModel(Modelica);


translateModelFMU(test_ChangeParam, version="2.0");
getErrorString();
importFMU("test_ChangeParam.fmu");

loadFile("test_ChangeParam_me_FMU.mo");
getErrorString();

simulate(test_ChangeParam_me_FMU);
val(x, 1);
val(a, 1);
val(y, 1);
getErrorString();

system("./test_ChangeParam_me_FMU -override a=-2,i=-10,b=false,s=\"bar\"");
echo(false);
readSimulationResult("test_ChangeParam_me_FMU_res.mat", {x,a,y});
echo(true);
val(x, 1);
val(a, 1);
val(y, 1);
getErrorString();


// Result:
// true
// ""
// true
// "SimCode: The model test_ChangeParam has been translated to FMU"
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
// "
// "test_ChangeParam_me_FMU.mo"
// true
// ""
// record SimulationResult
// resultFile = "test_ChangeParam_me_FMU_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 2.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'test_ChangeParam_me_FMU', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = "[<interactive>:14:7-14:43:writable]
// stdout | info | Simulation call terminate() at time 1.000000
// | | | | Message : Simulation done by foo
// "
// end SimulationResult;
// 7.389089930122212
// 2.0
// 6.389089930122212
// ""
// [<interactive>:14:7-14:43:writable]
// stdout | info | Simulation call terminate() at time 1.000000
// | | | | Message : Simulation done by bar
// 0
// true
// 0.135336321156737
// 2.0
// -10.13533632115674
// ""
// endResult

0 comments on commit 722fdf9

Please sign in to comment.