From 4e98ed5dd656288fdcb3d654b7ba102b2333b0bc Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 9 May 2019 17:55:05 +0200 Subject: [PATCH] [OMSI] Adition test and cleaner tests. Belonging to [master]: - OpenModelica/OpenModelica#171 - OpenModelica/OMCompiler#3084 --- testsuite/openmodelica/omsi/omsic/Makefile | 3 +- .../omsi/omsic/buildSimpleOMSU.mos | 1 + .../openmodelica/omsi/omsic/problem2.mos | 70 +++++++++++++++++++ .../omsi/omsic/simulateSimpleOMSU.mos | 69 +++++------------- 4 files changed, 90 insertions(+), 53 deletions(-) create mode 100644 testsuite/openmodelica/omsi/omsic/problem2.mos diff --git a/testsuite/openmodelica/omsi/omsic/Makefile b/testsuite/openmodelica/omsi/omsic/Makefile index 5da430dce97..50db3206e2b 100644 --- a/testsuite/openmodelica/omsi/omsic/Makefile +++ b/testsuite/openmodelica/omsi/omsic/Makefile @@ -10,7 +10,8 @@ endif TESTFILES = \ buildSimpleOMSU.mos \ -simulateSimpleOMSU.mos +simulateSimpleOMSU.mos \ +problem2.mos # test that currently fail. Move up when fixed. diff --git a/testsuite/openmodelica/omsi/omsic/buildSimpleOMSU.mos b/testsuite/openmodelica/omsi/omsic/buildSimpleOMSU.mos index 1d19a092059..56d4f73724c 100644 --- a/testsuite/openmodelica/omsi/omsic/buildSimpleOMSU.mos +++ b/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 // diff --git a/testsuite/openmodelica/omsi/omsic/problem2.mos b/testsuite/openmodelica/omsi/omsic/problem2.mos new file mode 100644 index 00000000000..a1b5de8448b --- /dev/null +++ b/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 diff --git a/testsuite/openmodelica/omsi/omsic/simulateSimpleOMSU.mos b/testsuite/openmodelica/omsi/omsic/simulateSimpleOMSU.mos index d0b9793a0a7..56533c6d3cd 100644 --- a/testsuite/openmodelica/omsi/omsic/simulateSimpleOMSU.mos +++ b/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: @@ -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