OMJulia.jl
OMJulia.jl copied to clipboard
setSimulationOptions keyword argumente inputs
The input name or setSimulationOptions is difficult to use and error prone.
Two setting possibilities are accepted using setXXXs(),where "XXX" can be any of above functions.
- setXXX("Name=value") string of keyword assignments
- setXXX(["Name1=value1","Name2=value2","Name3=value3"]) array of string of keyword assignments
There are only four simulation options one can set.
Make them keyword arguments of setSimulationOptions:
function setSimulationOptions(omc; startTime, stopTime, interval, tolerance)
and give them default values (e.g. nothing).
Oh and apparently there are more settings that can be set, e.g. solver. But how should a user know what values are valid?
I'd like to set the result file path. This is not an annotation, but is there another way to set it?
@olivleno you can use the simulate API to specify the result file path for example
simulate(omc, resultfile="xxxxx.mat") see the documentation https://openmodelica.github.io/OMJulia.jl/dev/modelicaSystem/#Advanced-Simulation
Thanks for the hint. Now I realize that the simulate function exists twice:
- OMJulia.simulate
- OMJulia.API.simulate
What is the rational behind this? Is there a recommendation which variant to use for what?
I want to load an entire library and simulate one-by-one the contained test cases.
The ModelicaSystem seems to be designed to work one model to be simulated.
The API seems to allow to load a package once and then simulate models without having to load it first.
Is there a recommendation which variant to use for what?
It depends on where you are coming from. OMJulia.simulate is like the OMPython version. If you are used to it ModelicaSystem is probably the easy way to go. It's not super flexible but brings everything most users should need.
If you are used to the OpenModelica Scripting API I would recommend to use the OMJulia.API. It is very similar, but the arguments are Julia types instead of everything is in string like with the sendExpression.
sendExpression(omc, "loadFile(\"/some/path/to/BouncingBall.mo\")")
It's a bit more flexible, but you need to know how to use the Scripting API functions. Check https://openmodelica.github.io/OMJulia.jl/dev/quickstart/#omjulia-api for the quick start.
If it's more flexible then I'd like to stick with the OMJulia.API. Unfortunately I did not find a way to set the result file path. Neither in the OMJulia.API nor the generell scripting API did I find a corresponding function or argument. Did I miss it?
@olivleno It depends on which one you want to use if you want to use API, then you have to use the commands directly like
julia> using OMJulia
julia> omc = OMJulia.OMCSession()
julia> sendExpression(omc, "loadModel(Modelica)")
julia> sendExpression(omc, "simulate(Modelica.Electrical.Analog.Examples.CauerLowPassAnalog, simflags="-r=\"test.mat\")")
julia> OMJulia.quit(omc)
If you are using ModelicaSystem then you can specify result file like this
julia> using OMJulia
julia> omc = OMJulia.OMCSession()
julia> ModelicaSystem(omc, "C:/Examples/BouncingBall.mo", "BouncingBall")
julia> simulate(omc, resultfile= "C:/Examples/BouncingBall.mat") // specify the result file here
Thanks for the hint to simflags -r. I tried to apply it to OMJulia.API with
OMJulia.API.simulate(omc,model_name;
outputFormat = "csv",
simflags = "-r=\"ref.csv\"")
which results in
ERROR: ParseError:
└ ── premature end of input
sendExpression(omc, "simulate(Modelica.Electrical.Analog.Examples.CauerLowPassAnalog, simflags="-r="test.mat")")
This code sample doesn't work.
It should be:
sendExpression(omc, "simulate(Modelica.Electrical.Analog.Examples.CauerLowPassAnalog, simflags= \"-r test.mat\" )")
or
result = OMJulia.API.simulate(omc,model_name;
outputFormat = "csv",
simflags = "-r ref.csv")
But the resultfile name is now: ref.csv though by default fileNamePrefix=className.
I'd expect: Modelica.Electrical.Analog.Examples.CauerLowPassAnalog_ref.csv
But the resultfile name is now: ref.csv though by default fileNamePrefix=className. I'd expect: Modelica.Electrical.Analog.Examples.CauerLowPassAnalog_ref.csv
That is what you specified with -r. To change only the output format skip the simflags keyword argument:
julia> OMJulia.API.simulate(omc, "BouncingBall", outputFormat="csv")
Dict{String, Any} with 10 entries:
"timeCompile" => 0.308608
"simulationOptions" => "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-6, method = '', fileName…
"messages" => "LOG_SUCCESS | info | The initialization finished successfully without homotopy method.\n…
"timeFrontend" => 0.00238572
"timeTotal" => 0.337119
"timeTemplates" => 0.0104497
"timeSimulation" => 0.00682997
"resultFile" => "/path/to/BouncingBall_res.csv"
⋮ => ⋮
I hope this is the same on Windows.
Sure. I was seeking for a simple way to setup a batch script to run simulations creating result files named <className_ref.csv.
I was hoping that this could be done by changing the default: _res to _ref in the same way as it is possible to change .mat to .csv.
Unfortunately there is no such named attribute. simflag does overwrite the entire name string.
My workaround is to keep the default name and to use a system command to move and rename the created files afterwards.
To me it would be cool to have the following attributes and defaults in the simulationOptions:
- resultDir = pwd()
- resultName = "_res"
- resultPrefix = className
- resultFormat = ".mat"
or instead of
you may say