Cannot return Result in OMJulia

@arun3688 arun3688
@AnHeuermann AnHeuermann
I am using OpenModelica and I am trying to read the output (i.e., s here). I tried several ways but could not succeed. Any idea to solve that?

using OMJulia
omc= OMJulia.OMCSession()
sendExpression(omc,"model a Real s; equation s=sin(10*time); end a;")
1-element Array{Symbol,1}:
L = sendExpression(omc,"readSimulationResult(a_res.mat)")  # does not return anything
L = sendExpression(omc,"readSimulationResult(a_res)")  # does not return anything
L = sendExpression(omc,"readSimulationResult(s)")  # does not return anything

@Amro, You have to use getErrorString() API after every sendExpression() to see the error messages, And also the readSimulationResult() API requires two argument as input, first result file and second names of the variables as a list, So you should use something like below

sendExpression(omc, “readSimulationResult(“a_res.mat”,{s})”)
sendExpression(omc, “getErrorString()”)

Here are the list of API you can use and see their default and expected arguments. OpenModelica.Scripting

The error message tells you that Julia cannot handle the string


Try escaping the quote signs " in the string:

julia> OMJulia.sendExpression(omc, "readSimulationResult(\"a_res.mat\",{s})")
1-element Vector{Vector{Float64}}:
 [0.0, 0.01999866669333308, 0.03998933418663416, 0.0599640064794446, 0.0799146939691727, 0.09983341664682815, 0.1197122072889194, 0.1395431146442365, 0.159318206614246, 0.1790295734258242  …  -0.4033931121687696, -0.4216117517033922, -0.4396617521587485, -0.4575358937753213, -0.4752270271347798, -0.4927280760196602, -0.5100320402437544, -0.527131998452086, -0.5440211108893698, -0.5440211108893698]

Alternatives to OpenModelica and readSimulationResult() would be to generate a CSV result file and use CSV.jl to read the data:

sendExpression(omc,"simulate(a, outputFormat=\"csv\")")

I don’t know of a Julia package that can handle the mat file OpenModelica generates, at least MAT.jl is not working for them (no mat v4 support).

1 Like

Thank you. Yes, now it works. I have tried the MAT.jl but it didnot work due to the not support of mat 4 generated by OpenModelica.

The usual way to achieve this in Modelica is by having k be of “parameter” variability. K can then be overridden/set for new simulations without having to recompile.

1 Like

Scripting API — OpenModelica User's Guide v1.18.0-38-ga767f054d8 documentation is the corresponding code for OpenModelica mos-scripts. You can adapt it for Julia (easier on Linux since you need to set PATH variables on Windows if you call the executable within Julia).

1 Like

Thank you very much. Can you send me the link for the documentation of setting the PATH variables on Windows if you call the executable within Julia

There is no documentation as far as I know, and the Windows version of OpenModelica doesn’t run on my Windows work computer. Only the WSL version works… Maybe adding $OPENMODELICAHOME/bin is enough. I’m not sure.

1 Like

Excuse me, I have to add $OPENMODELICAHOME/bin into the environment variables in windows or where specifically?

You could do it inside of the Julia process or only setting it when calling the simulation executable. Note that you will need to expand OPENMODELICAHOME and it’s probably not set in the global environment unless you have an older installation. You can use Scripting API — OpenModelica User's Guide v1.19.0-dev-491-g8713a817d7e documentation to query it

1 Like

Thank you very much for explanations. I will read this part of documentation to become familiar with the issue here.

Thank you for your explanations. I have read the documentation, but honestly I didn’t get it well.

Is it correct to add it in windows as below? or how can I do it withing julia?

Could you please guide me here or give me example or link?

Could you please guide me here or give me example or link?

it returns

“C:/Program Files/OpenModelica1.18.0-64bit”