Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setSimulationOptions keyword argumente inputs #100

Open
AnHeuermann opened this issue Sep 7, 2023 · 12 comments
Open

setSimulationOptions keyword argumente inputs #100

AnHeuermann opened this issue Sep 7, 2023 · 12 comments

Comments

@AnHeuermann
Copy link
Member

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.

  1. setXXX("Name=value") string of keyword assignments
  2. 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).

@AnHeuermann
Copy link
Member Author

Oh and apparently there are more settings that can be set, e.g. solver. But how should a user know what values are valid?

@olivleno
Copy link

I'd like to set the result file path. This is not an annotation, but is there another way to set it?

@arun3688
Copy link
Contributor

@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

@olivleno
Copy link

olivleno commented May 24, 2024

Thanks for the hint. Now I realize that the simulate function exists twice:

  1. OMJulia.simulate
  2. 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.

@AnHeuermann
Copy link
Member Author

AnHeuermann commented May 24, 2024

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.

@olivleno
Copy link

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?

@arun3688
Copy link
Contributor

@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

@olivleno
Copy link

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

@olivleno
Copy link

sendExpression(omc, "simulate(Modelica.Electrical.Analog.Examples.CauerLowPassAnalog, simflags="-r="test.mat")")

This code sample doesn't work.

@olivleno
Copy link

olivleno commented May 24, 2024

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

@AnHeuermann
Copy link
Member Author

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.

@olivleno
Copy link

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 , if you like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants