- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Custom components requiring special...
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!
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
- adrpo
- 885 Posts
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.
- adrpo
- 885 Posts
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.
- sjoelund.se
- 1700 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Custom components requiring special...