Skip to content

Commit

Permalink
[OMSI] Added test for algebraic loops
Browse files Browse the repository at this point in the history
Added models with linear and non-linear loops to test default OMSIBase solver
for algebraic loops.
  • Loading branch information
AnHeuermann authored and lochel committed Jun 17, 2019
1 parent 4ce17f7 commit 96fa58a
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 5 deletions.
4 changes: 3 additions & 1 deletion testsuite/openmodelica/omsi/omsic/Makefile
Expand Up @@ -11,7 +11,9 @@ endif
TESTFILES = \
buildSimpleOMSU.mos \
simulateSimpleOMSU.mos \
problem2.mos
problem2.mos \
simpleLoop.mos \
simpleNonLinLoop.mos

# test that currently fail. Move up when fixed.

Expand Down
6 changes: 3 additions & 3 deletions testsuite/openmodelica/omsi/omsic/problem2.mos
Expand Up @@ -32,7 +32,7 @@ simulate(problem2); getErrorString();
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();
system(getInstallationDirectoryPath() + "/bin/OMSimulator problem2.fmu --intervals=500 --tolerance=1e-6 --resultFile=\"problem2_OMS_res.mat\" --suppressPath=true --tempDir=\"problem2-tmp\"", "problem2_systemCall.log"); getErrorString();
readFile("problem2_systemCall.log");

// Compare results
Expand Down Expand Up @@ -63,8 +63,8 @@ compareSimulationResults("problem2_OMS_res.mat",
// "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
// NumSteps = 48 NumRhsEvals = 66 NumLinSolvSetups = 14
// NumNonlinSolvIters = 65 NumNonlinSolvConvFails = 0 NumErrTestFails = 3
// "
// {"Files Equal!"}
// endResult
68 changes: 68 additions & 0 deletions testsuite/openmodelica/omsi/omsic/simpleLoop.mos
@@ -0,0 +1,68 @@
// name: simpleLoop
// keywords: omsi omsic fmu fmi
// status: correct
// teardown_command: rm -rf simpleLoop.fmutmp simpleLoop.fmu simpleLoop_systemCall.log simpleLoop-tmp simpleLoop*res.mat simpleLoop_result_diff.log
//
// Tests simulating OMSIC OMSU/FMU with OMSimulator and check results
// Simple model containing linear loop.
//

loadString("
model simpleLoop
Real x;
Real y;
Real z;
Real s(start=1, fixed=true);
parameter Real a=1, b=-1, c = 7;
equation
time = a*x+b*y+c*z;
2*time = 2*a*x+y-3*z;
7 = 23*a-3/8*b+z;
der(s) = x+y+z;
end simpleLoop;
"); getErrorString();

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

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

// Simulate with OMSimulator
system(getInstallationDirectoryPath() + "/bin/OMSimulator simpleLoop.fmu --intervals=500 --tolerance=1e-6 --resultFile=\"simpleLoop_OMS_res.mat\" --suppressPath=true --tempDir=\"simpleLoop-tmp\"", "simpleLoop_systemCall.log"); getErrorString();
readFile("simpleLoop_systemCall.log");

// Compare results
compareSimulationResults("simpleLoop_OMS_res.mat",
"simpleLoop_res.mat",
"simpleLoop_result_diff.log",
vars = {"x","y","z","s","der(s)","a","b","c"}
);


// Result:
// true
// ""
// record SimulationResult
// resultFile = "simpleLoop_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'simpleLoop', 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
// ""
// "simpleLoop.fmu"
// ""
// 0
// ""
// "info: maximum step size for 'model.root': 0.100000
// info: Result file: simpleLoop_OMS_res.mat (bufferSize=1)
// info: Final Statistics for 'model.root':
// NumSteps = 120 NumRhsEvals = 258 NumLinSolvSetups = 96
// NumNonlinSolvIters = 256 NumNonlinSolvConvFails = 0 NumErrTestFails = 49
// "
// {"Files Equal!"}
// endResult
64 changes: 64 additions & 0 deletions testsuite/openmodelica/omsi/omsic/simpleNonLinLoop.mos
@@ -0,0 +1,64 @@
// name: simpleNonLinLoop
// keywords: omsi omsic fmu fmi
// status: correct
// teardown_command: rm -rf simpleNonLinLoop.fmutmp simpleNonLinLoop.fmu simpleNonLinLoop_systemCall.log simpleNonLinLoop-tmp simpleNonLinLoop*res.mat simpleNonLinLoop_result_diff.log
//
// Tests simulating OMSIC OMSU/FMU with OMSimulator and check results
// Simple model containing non-linear loop.
//

loadString("
model simpleNonLinLoop
Real a(start=1), b(start=1), c(start=1);
Real s(start=1, fixed=true);
equation
a + b + c=0;
2*a - 3*b + 2*c=9;
a*a + b*b + c*c=5;
der(s) = time*(a*b*c);
end simpleNonLinLoop;
"); getErrorString();

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

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

// Simulate with OMSimulator
system(getInstallationDirectoryPath() + "/bin/OMSimulator simpleNonLinLoop.fmu --intervals=500 --tolerance=1e-6 --resultFile=\"simpleNonLinLoop_OMS_res.mat\" --suppressPath=true --tempDir=\"simpleNonLinLoop-tmp\"", "simpleNonLinLoop_systemCall.log"); getErrorString();
readFile("simpleNonLinLoop_systemCall.log");

// Compare results
compareSimulationResults("simpleNonLinLoop_OMS_res.mat",
"simpleNonLinLoop_res.mat",
"simpleNonLinLoop_result_diff.log",
vars = {"der(s)","s","a","b","c"}
);

// Result:
// true
// ""
// record SimulationResult
// resultFile = "simpleNonLinLoop_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'simpleNonLinLoop', 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
// ""
// "simpleNonLinLoop.fmu"
// ""
// 0
// ""
// "info: maximum step size for 'model.root': 0.100000
// info: Result file: simpleNonLinLoop_OMS_res.mat (bufferSize=1)
// info: Final Statistics for 'model.root':
// NumSteps = 702 NumRhsEvals = 2001 NumLinSolvSetups = 1025
// NumNonlinSolvIters = 1963 NumNonlinSolvConvFails = 0 NumErrTestFails = 541
// "
// {"Files Equal!"}
// endResult
2 changes: 1 addition & 1 deletion testsuite/openmodelica/omsi/omsic/simulateSimpleOMSU.mos
@@ -1,7 +1,7 @@
// name: simulateSimpleOMSU
// keywords: omsi omsic fmu fmi
// status: correct
// teardown_command: rm -rf helloWorldOMSU.fmutmp helloWorldOMSU.fmu helloWorldOMSU_systemCall.log helloWorldOMSU-tmp
// teardown_command: rm -rf helloWorldOMSU.fmutmp helloWorldOMSU.fmu helloWorldOMSU_systemCall.log helloWorldOMSU-tmp helloWorldOMSU_res.mat
//
// Tests simulating OMSIC OMSU/FMU with OMSimulator
//
Expand Down

0 comments on commit 96fa58a

Please sign in to comment.