Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Custom components requiring special environment variables

Custom components requiring special environment variables

Dear all,

I have created a DLL (on Windows) allowing me to integrate and use a Python object into OpenModelica.

Currently I have verified that:

1. The DLL and the connection to Python unit test is ok;
2. The compilation of a Modelica test using the external library within OpenModelica also completes successfully;
3. The simulation of the model fails because Python needs a number of environment variable to be added to the path;
4. The manual simulation of the built model completes successfully when the appropriate environment variables are set.

I would like to be able to instruct OpenModelica to create a certain environment before executing the to call to the model, because I don't want to change the system's environment. Basically I would like to do something similar to what I do in python with

Code:


import sys
sys.path.append([PathDir1, PathDir2, ... PathDirN])

before the call to

Code:


SHCControls.TSModel.Test.exe -port=49324 -logFormat=xmltcp -override=startTime=0,stopTime=1,stepSize=0.002,tolerance=1e-6,solver=dassl,outputFormat=mat,variableFilter=.* -r=SHCControls.TSModel.Test_res.mat -w -lv=LOG_STATS

Does somebody know if this is possible and, in case, how to do it?

Thank you!

Edited by: Alanturing - Jul-27-20 14:06:49

Re: Custom components requiring special environment variables

You can use these functions in a .mos script:
https://build.openmodelica.org/Document … ntVar.html
https://build.openmodelica.org/Document … ntVar.html

Code:


// -- script.mos
// save PATH
savedPath := getEnvironmentVar("PATH"); getErrorString();
// set PATH, note that the path separator is ";" in Windows and ":" in Linux
setEnvironmentVar("PATH", savedPath + "some;other:paths:here"); getErrorString();
// simulate
simulate(SHCControls.TSModel.Test); getErrorString();
// set back the PATH
setEnvironmentVar("PATH", savedPath); getErrorString();
// -- end script.mos

Then you just do omc script.mos
Of course, you would need to load you library via loadModel(Lib); or loadFile("Lib/package.mo"); before simulating the model.

See other scripting command here:
https://build.openmodelica.org/Document … pting.html




Edited by: adrpo - Jul-27-20 15:25:19

Re: Custom components requiring special environment variables

Thank you Adrian,

always fast and effective.

I wonder: is it possible to "program" the button "->" in the IDE so that it executes the instructions you suggested?

Then, sorry for the stupid question: how can I load the .mat file with the simulation results back in the IDE when I run your script from the command prompt?

Sincerely,

Re: Custom components requiring special environment variables

Currently is not possible but it seems to be an easy addition to OMEdit.
Well, it is possible but you need to manually write or paste stuff in the OpenModelica CLI in OMEdit.
Would be nice to have "Pre simulation script" and "Post simulation script" in which advanced users can write anything they want.

Also, it seems calling
> OMEdit Result.mat
will not open the result file in the plotting perspective.

I'll open some tickets about these and we'll implement them.

Re: Custom components requiring special environment variables

Very nice to hear.

Thank you very much Adrian for your availability.

All the best.

 

Re: Custom components requiring special environment variables

OMEdit Result.mat will not open the result file in the plotting perspective. But File -> Open result file (or whatever it was called)... should work. Of course, you can't script that.

Re: Custom components requiring special environment variables

Thank you, very useful!

There are 0 guests and 0 other users also viewing this topic
You are here: