Skip to content

Commit

Permalink
[OMSI] Adition test and cleaner tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnHeuermann authored and JKRT committed May 13, 2019
1 parent da4ae4f commit 4e98ed5
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 53 deletions.
3 changes: 2 additions & 1 deletion testsuite/openmodelica/omsi/omsic/Makefile
Expand Up @@ -10,7 +10,8 @@ endif

TESTFILES = \
buildSimpleOMSU.mos \
simulateSimpleOMSU.mos
simulateSimpleOMSU.mos \
problem2.mos

# test that currently fail. Move up when fixed.

Expand Down
1 change: 1 addition & 0 deletions testsuite/openmodelica/omsi/omsic/buildSimpleOMSU.mos
@@ -1,6 +1,7 @@
// name: buildSimpleOMSU
// keywords: omsi omsic fmu fmi
// status: correct
// teardown_command: rm -rf helloWorldOMSU.fmutmp helloWorldOMSU.fmu
//
// Tests generating OMSIC OMSU/FMU
//
Expand Down
70 changes: 70 additions & 0 deletions testsuite/openmodelica/omsi/omsic/problem2.mos
@@ -0,0 +1,70 @@
// name: problem2
// keywords: omsi omsic fmu fmi
// status: correct
// teardown_command: rm -rf problem2.fmutmp problem2.fmu problem2_systemCall.log problem2_result_diff.log problem2*res.mat problem2-tmp
//
// Tests simulating OMSIC OMSU/FMU with OMSimulator and check results
//
//


loadString("
model problem2
Real u1(start=1), u2(start=1), u3(start=1);
Real v1(start=-0.1, fixed=true);
Real w1(start=0.1, fixed=true);
Real p1 = 0.5;
parameter Integer p2 = 7;
equation
u1 + 5*u2 + u3 = 0.5;
-u1 + u2 - u3 = 10*v1;
u1 + 3*u2 - u3 = -0.1;

der(v1) = v1*p1*p2;
der(w1) = sin(w1*p1);
end problem2;
"); getErrorString();

// Simulate model for reference results
simulate(problem2); getErrorString();

// Build omsic FMU
setCommandLineOptions("--simCodeTarget=omsic --removeSimpleEquations=none"); getErrorString();
buildModelFMU(problem2); getErrorString();

system(getInstallationDirectoryPath() + "/bin/OMSimulator problem2.fmu --intervals=500 --resultFile=\"problem2_OMS_res.mat\" --suppressPath=true --tempDir=\"problem2-tmp\"", "problem2_systemCall.log"); getErrorString();
readFile("problem2_systemCall.log");

// Compare results
compareSimulationResults("problem2_OMS_res.mat",
"problem2_res.mat",
"problem2_result_diff.log",
vars = {"der(w1)", "der(v1)","u1","u2","u3","v1","w1","p1","p2"}
);


// Result:
// true
// ""
// record SimulationResult
// resultFile = "problem2_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'problem2', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = "LOG_SUCCESS | info | The initialization finished successfully without homotopy method.
// LOG_SUCCESS | info | The simulation finished successfully.
// "
// end SimulationResult;
// ""
// true
// ""
// "problem2.fmu"
// ""
// 0
// ""
// "info: maximum step size for 'model.root': 0.100000
// info: Result file: problem2_OMS_res.mat (bufferSize=1)
// info: Final Statistics for 'model.root':
// NumSteps = 30 NumRhsEvals = 37 NumLinSolvSetups = 8
// NumNonlinSolvIters = 36 NumNonlinSolvConvFails = 0 NumErrTestFails = 1
// "
// {"Files Equal!"}
// endResult
69 changes: 17 additions & 52 deletions testsuite/openmodelica/omsi/omsic/simulateSimpleOMSU.mos
@@ -1,49 +1,25 @@
// name: buildSimpleOMSU
// name: simulateSimpleOMSU
// keywords: omsi omsic fmu fmi
// status: correct
// teardown_command: rm -rf helloWorldOMSU.fmutmp helloWorldOMSU.fmu helloWorldOMSU_systemCall.log helloWorldOMSU-tmp
//
// Tests simulating OMSIC OMSU/FMU with OMSimulator
//
//


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

// Build omsic FMU
setCommandLineOptions("--simCodeTarget=omsic"); getErrorString();

buildModelFMU(helloWorldOMSU); getErrorString();

setCommandLineOptions("--simCodeTarget=C"); getErrorString();

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

oms_newModel(\"helloWorldOMSU\")
oms_addSystem(\"helloWorldOMSU.root\", oms_system_sc)
oms_addSubModel(\"helloWorldOMSU.root.system1\", \"helloWorldOMSU.fmu\")

oms_setResultFile(\"helloWorldOMSU\", \"\")
oms_setStopTime(\"helloWorldOMSU\", 0.1)
oms_setFixedStepSize(\"helloWorldOMSU.root\", 1e-4)
oms_setTolerance(\"helloWorldOMSU.root\", 1e-6)

oms_instantiate(\"helloWorldOMSU\")

oms_initialize(\"helloWorldOMSU\")

oms_simulate(\"helloWorldOMSU\")

oms_terminate(\"helloWorldOMSU\")
oms_delete(\"helloWorldOMSU\")
"); getErrorString();
// Simulate with OMSimulator
system(getInstallationDirectoryPath() + "/bin/OMSimulator helloWorldOMSU.fmu --intervals=500 --resultFile=\"helloWorldOMSU_res.mat\" --suppressPath=true --tempDir=\"helloWorldOMSU-tmp\"", "helloWorldOMSU_systemCall.log"); getErrorString();
readFile("helloWorldOMSU_systemCall.log");

system(getInstallationDirectoryPath() + "/bin/OMSimulator --ignoreInitialUnknowns=true helloWorldOMSU_me.lua");

simulate(helloWorldOMSU, stopTime=1); getErrorString();
val(x, {0.0,1.0});
val(der(x), {0.0,1.0});
val(x, {0.0,1.0}, "helloWorldOMSU_res.mat");
val(der(x), {0.0,1.0}, "helloWorldOMSU_res.mat");


// Result:
Expand All @@ -55,25 +31,14 @@ val(der(x), {0.0,1.0});
// "helloWorldOMSU.fmu"
// "Warning: The initial conditions are not fully specified. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->OMCFlags, in OMNotebook call setCommandLineOptions("-d=initialization").
// "
// true
// ""
// true
// ""
// info: maximum step size for 'helloWorldOMSU.root': 0.100000
// info: No result file will be created
// info: Final Statistics for 'helloWorldOMSU.root':
// NumSteps = 16 NumRhsEvals = 24 NumLinSolvSetups = 9
// NumNonlinSolvIters = 23 NumNonlinSolvConvFails = 0 NumErrTestFails = 1
// 0
// record SimulationResult
// resultFile = "helloWorldOMSU_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'helloWorldOMSU', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = "LOG_SUCCESS | info | The initialization finished successfully without homotopy method.
// LOG_SUCCESS | info | The simulation finished successfully.
// "
// end SimulationResult;
// "Warning: The initial conditions are not fully specified. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->OMCFlags, in OMNotebook call setCommandLineOptions("-d=initialization").
// ""
// "info: maximum step size for 'model.root': 0.100000
// info: Result file: helloWorldOMSU_res.mat (bufferSize=1)
// info: Final Statistics for 'model.root':
// NumSteps = 26 NumRhsEvals = 32 NumLinSolvSetups = 8
// NumNonlinSolvIters = 31 NumNonlinSolvConvFails = 0 NumErrTestFails = 1
// "
// {1.0,7.389089930122215}
// {2.0,14.77817986024443}
// {1.0,7.394290445175167}
// {2.0,14.78858089035033}
// endResult

0 comments on commit 4e98ed5

Please sign in to comment.