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

how to utilize the exe file that is compiled when i simulate a model?

how to utilize the exe file that is compiled when i simulate a model?

i want to know whether i can get my model files directly packaged into exe format, which does not depend on OMEdit and can generate the simulation results? Thank you !!

Re: how to utilize the exe file that is compiled when i simulate a model?

Yes, OpenModelica generates executables which do not depend on OMEdit. It is only on Windows that they are dependent on some odd files (the MinGW runtime), but you can add the dll's to the system PATH.

Re: how to utilize the exe file that is compiled when i simulate a model?

Is  there some guide about this?thank you !

Re: how to utilize the exe file that is compiled when i simulate a model?

Hi,

No, there is no guide.

However, is an Model.exe so you run it and the result will be a Model.mat file with the same name as your model.
The Model.mat file then can be opened with OMPlot or other programs.
Is also possible to generate Model.csv instead of Model.mat.

By default the .exe is generated in your temporary directory, which in Windows 7 is:
C:\Users\_YOUR_USERNAME_\AppData\Local\Temp\OpenModelica\OMEdit

You need the Model.exe, the Model_init.xml files.
By default Model.exe should not depend on any other .dlls or anything else so is self sufficient.

You run Model.exe from the command line to get Model.mat.
If you want Model.csv, edit Model_init.xml and change outputFormat   = "csv" or outputFormat   = "plt" (PtPlot format)
Run Model.exe -? for a list of command line parameters.
You can edit Model_init.xml to change the start values of the parameter before re-running Model.exe.
You can also use the script from here:
C:\OpenModelica1.8.1\share\omc\scripts\replace-startValue.bat variableName variableStartValue Model_init.xml > NewModel_init.xml

Hope this helps a bit.

Cheers,
Adrian Pop/

Re: how to utilize the exe file that is compiled when i simulate a model?

Thank you so much!
but i cannot understand "You run Model.exe from the command line to get Model.mat."  when i just double-click to open the exe file,then a window flash and then disappear.and how i  can run Model.exe from the command line?  thank  you ! i am a beginner so  what i know is so little.

Re: how to utilize the exe file that is compiled when i simulate a model?

Hi,

Double click on it works also. But is a console application so it doesn't display anything.
It just runs and creates Model.mat.

To run from command line (replace _YOUR_USERNAME_ with your Windows user name):
Start->cmd.exe
> c:
> cd \Users\_YOUR_USERNAME_\AppData\Local\Temp\OpenModelica\OMEdit
> Model.exe
> Model.exe -?
Like that you run from the command line.

Cheers,
Adrian Pop/

Re: how to utilize the exe file that is compiled when i simulate a model?

Thank  you  so much!!!  you help me so much!

Re: how to utilize the exe file that is compiled when i simulate a model?

i would also like to ask a question,could the exe file can directly display the result ,for example the curve of the variable,it can pop out in the screen? I am a Chinese college students doing the graduateproject , I am very grateful for your help!

Re: how to utilize the exe file that is compiled when i simulate a model?

Hi,

No.
The Model.exe  will not display/plot the results and will never do that.
You can use OMPlot from the OpenModelica installation for that.
These are the command line options for OMPlot:

Code:


Usage: OMPlot [OPTION] [--filename=NAME] [variable names]
OPTIONS
    --title=TITLE              Sets the TITLE of the plot window
    --filename=NAME            Sets the NAME of the file to plot
    --legend=[true|false]      Display a variable legend in the window
    --grid=[true|false]        Enable a grid in the window
    --logx=[true|false]        Use log scale for the x-axis
    --logy=[true|false]        Use log scale for the y-axis
    --xlabel=LABEL             Use LABEL as the label of the x-axis
    --ylabel=LABEL             Use LABEL as the label of the y-axis
    --plot                     Create a normal plot
    --plotAll                  Create a normal plot containing every variable in the result-file
    --plotParametric           Create a parametric plot (plot variables as functions of each other)
    --xrange=LEFT:RIGHT        Sets the initial range of the x-axis to LEFT:RIGHT
    --yrange=LEFT:RIGHT        Sets the initial range of the y-axis to LEFT:RIGHT
    --new-window=[true|false]  Create a MDI dialog in the plot-window

So, in the command line you can do something like this to plot all the variables:

Code:

> %OPENMODELICAHOME%\bin\OMPlot --filename=Model_res.mat --plotAll

or like this to plot only one (change VARIABLE_NAME to the name of your variable):

Code:

> %OPENMODELICAHOME%\bin\OMPlot --filename=Model_res.mat VARIABLE_NAME1 VARIABLE_NAME2

You can ship OMPlot.exe (take also all the .dlls from OpenModelicaX.Y.Z/bin) with your Model.exe if you don't want the user to install OpenModelica.

You should learn more about .bat files if you want to automate this.
You can create a .bat that runs your model, then plots the variables automatically.

Cheers,
Adrian Pop/

Re: how to utilize the exe file that is compiled when i simulate a model?

hi, when i script like "> %OPENMODELICAHOME%\bin\OMPlot --filename=helloworld_res.mat --plotAll" it  says helloworld_res.mat is not existent. is there some requirement for the path of the .mat file?
"

Re: how to utilize the exe file that is compiled when i simulate a model?

Write full absolute path of the file or put the file where OMPlot is located.

Adeel.

Re: how to utilize the exe file that is compiled when i simulate a model?

adrpo wrote:


Hi,

No, there is no guide.

However, is an Model.exe so you run it and the result will be a Model.mat file with the same name as your model.


Cheers,
Adrian Pop/

Hi, Adrian. Could you help me? When I tried to open Model.exe which is created by OpenModelica, I saw a message "there is no the libsundials_kinsol.dll". And nothing happen after that. What shoul I do to fix the error?
P.S. Sorry for double message, I didn't see where I could delete my message.

Edited by: Ascold - Sep-28-15 14:22:42

Re: how to utilize the exe file that is compiled when i simulate a model?

You need some dlls from C:\OpenModelica....\bin\ in order to be able to run your model.
Copy all dlls but the Qt ones to the folder you have Model.exe in.

Cheers,
Adrian Pop/


Re: how to utilize the exe file that is compiled when i simulate a model?

adrpo wrote:


You need some dlls from C:\OpenModelica....\bin\ in order to be able to run your model.
Copy all dlls but the Qt ones to the folder you have Model.exe in.

Cheers,
Adrian Pop/



Big thanks, Adrian!
You are really help me!

Edited by: Ascold - Oct-02-15 11:59:49

Re: how to utilize the exe file that is compiled when i simulate a model?

Hello everyone,

I have a model named "test.mo" and I am trying to simulate this model with omc command from cmd window. When I use the omc command I receive an error which says "Failed to build model: test". But I simulate the model with OMEdit without any problem. There is nothing wrong with the model and I do not understand why when I try to simulate it with omc command it says model cannot be built. I would be extremely grateful if you could help me out.

Best,
Pouya

Edited by: PJS - Nov-25-15 09:47:42

Re: how to utilize the exe file that is compiled when i simulate a model?

Are you using the Modelica standard library, but did not load it in your command-line omc?

Re: how to utilize the exe file that is compiled when i simulate a model?

Thanks for your attention,

I have loaded the library that I am using. This is my .mos file:

loadModel(Modelica);
loadFile("TResLib.mo");
loadFile("test.mo");   
simulate(test, outputFormat="csv");

and it gives :
True
True
True

which meanse that it has loaded the library but then it cannot build the model !!!!

I will appreciate your help.

Best,
Pouya


Edited by: PJS - Nov-25-15 11:03:37

Re: how to utilize the exe file that is compiled when i simulate a model?

Hi Everyone,

I have another question regarding compiling a model from cmd using OMC command. It seems like it takes more time to compile and simulate the model using OMC. I just wanted to ask if anyone knows the parameters affecting the time that it takes to compile the model. I increased the number of the elements in my model and it takes approximately the same time to be compiled. So, I was wondering what parameters of the model affect the time consumption for simulation.


Thanks for your attention,
Pouya

Re: how to utilize the exe file that is compiled when i simulate a model?

Loading MSL probably takes most of the time for smaller models (especially on Windows as OMC is not multi-threaded on Windows). There is also some overhead in launching the make and gcc processes on Windows, and linking the run-time, which makes small simulation have a somewhat large cost in time.

Re: how to utilize the exe file that is compiled when i simulate a model?

Dear all,

I am in trouble with the execution of the .exe created by OMedit.
I followed the steps described in this post (I copied the code.exe, the code_init.xml, the code_res.mat, the .dll requested in the same folder of the executable).

When I try to execute the executable, the follow error is displayed:
The application was unable to start correctly (0xc000007b).

Can someone help me?
Am I missing some flags or something when I try to execute? Is the executable compiled correctly?

Re: how to utilize the exe file that is compiled when i simulate a model?

In regard to pierluigiRossi, I also have problems when trying to run the executable generated by OMEdit. When I try to run it at command line, there is no response at all.

With the executable generated directly by omc.exe, I have no problems.

Edited by: brunoleos - Sep-27-16 16:17:20

Re: how to utilize the exe file that is compiled when i simulate a model?

Dear all,

Is there any way to get the executable file for ubuntu? I need to connect my model with Ua expert and then to connect with OpenModelica OPC UA server.

For windows we could use as--> xxx.exe -embeddedServer=opc-ua -rt=1

Is there anything similar for Ubuntu?

Thanking you in Anticipation.

Kind regards,
Maria

Re: how to utilize the exe file that is compiled when i simulate a model?

It is exactly the same for Ubuntu.

Adeel.

Re: how to utilize the exe file that is compiled when i simulate a model?

while running the exe through python the terminal window with the stdout msg pops up and consumes a lot of the time. is it possible to stop the terminal from appearing using some flags.
Request your kind help pls

Re: how to utilize the exe file that is compiled when i simulate a model?

I need to build my model in a specific path, so I am trying to use setTempDirectoryPath().
However, when I write the command setTempDirectoryPath("path/to/file") in omshell, it closes the omshell window.

Any reason for that or how to solve it


How to change some parameters in my model in the .xml file before running the executable?

Re: how to utilize the exe file that is compiled when i simulate a model?

I need to build my model in a specific path, so I am trying to use setTempDirectoryPath().
However, when I write the command setTempDirectoryPath("path/to/file") in omshell, it closes the omshell window.

Any reason for that or how to solve it


How to change some parameters in my model in the .xml file before running the executable?

Re: how to utilize the exe file that is compiled when i simulate a model?

Just creste a script.mos file containing:

Code:


// go to where you want
cd("path/to/directory/you/want"); getErrorString();
// create a new directory there
mkdir("someTempDirecoryName"); getErrorString();
// change to that directory
cd("someTempDirecoryName"); getErrorString();
// build your model
// load some libs first
loadModel(Modelica); getErrorString();
// load some model file
loadFile("path/to/Model.mo"); getErrorString();
// build model
buildModdl(Model); getErrorString();
// simulate model with some parameter change
system("./Model -override x=4"); getErrorString();

Then run omc from command line on it (Windows)

Code:


%OPENMODELICAHOME%\bin\omc script.mos

Or load and run the script jn OMShell.

See more here:
https://openmodelica.org/forum/default- … eter-sweep
https://build.openmodelica.org/Document … pting.html

OMShell dying on your command seems like a bug. I will check it out.

Re: how to utilize the exe file that is compiled when i simulate a model?

Thank you very much for your reply!
I have implemented my code based on your guide (line-by-line) in omshell, and I have the following concerns please:

1- The code worked in the default directory i.e. "C:\Users\user_name\AppData\Local\Temp\OpenModelica" and the system() command returned “0”. However, when I change the path directory to be through the One-Drive(i.e. "C:/path1/One-Drive/path2/model"), the code works except the system() command and it returns “1”. Do you know why?

2- I want to put the system() command within a time-loop (iterations), in which the results of system() command will effect the next iteration. So, generating a results file such as .mat and reading form it (at each iteration) will consume a lot of time. Is there any way to show the results of system() command directly into the workspace of omshell rather than reading them from the generated results file (.mat)? I used val(variable, time) but it didnt return anything.

3- I have created a script.mos as you described. Then I open command window (in the same location of the script) and typed the below command to run the script but it gave the below error, how to solve it? Alternateviely, what is the command to run the script from the omshell, is it %OPENMODELICAHOME%\bin\omc script.mos?

PS C:\Users\user_name\AppData\Local\Temp\OpenModelica> %OPENMODELICAHOME%\bin\omc script.mos
%OPENMODELICAHOME%\bin\omc : The module '%OPENMODELICAHOME%' could not be loaded. For more information, run
'Import-Module %OPENMODELICAHOME%'.
At line:1 char:1
+ %OPENMODELICAHOME%\bin\omc run_twovariableaddition.mos
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (%OPENMODELICAHOME%\bin\omc:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoLoadModule

Edited by: Amro - Dec-28-21 17:06:42

Re: how to utilize the exe file that is compiled when i simulate a model?

1. can I see the entire script? you could try to log the system command and display the error

Code:


system(system("./Model -override x=4", "log.txt"); getErrorString();
readFile("log.txt");  getErrorString();

2. it doesn't really work like you want, there is no workspace as Matlab has.
Do you know how to code in something like python or Julia, it might be easier to handle what you want.
I guess you want some variables at certain times and use those values in the next iteration.

3. Are you running those commands in cmd.exe or some other shell like powershell?
If yes, then you need to run it like this:

Code:


& "$env:OPENMODELICAHOME\bin\omc.exe" script.mos

Re: how to utilize the exe file that is compiled when i simulate a model?

There are alternatives to speed it up quite a bit if you only need for example just a few variables from a simulation run, you could skip the generation of the mat file entirely with -noemit: https://openmodelica.org/doc/OpenModeli … lag-noemit and using -output var1,var2,var3: https://openmodelica.org/doc/OpenModeli … lag-output
Then you would just read these variable values and use them for the next simulation.

Alternatively you could use FMI, generate an FMU from your model and use any FMI tool to run the FMU until a certain time, then read the values, then restart the FMU with the new values. No mat file is generated. I would suggest to use OMSimulator python interface for this: https://www.openmodelica.org/doc/OMSimu … ython.html
OMSimulator can run composite FMUs but you don't need that, one FMU should be enough, just load that and run it using stepUntil. I will try to make a python script example for this.

Re: how to utilize the exe file that is compiled when i simulate a model?

o

Edited by: Amro - Dec-28-21 21:11:51

Re: how to utilize the exe file that is compiled when i simulate a model?

.

Edited by: Amro - Dec-29-21 18:57:02

Re: how to utilize the exe file that is compiled when i simulate a model?

adrpo wrote:


3. Are you running those commands in cmd.exe or some other shell like powershell?
If yes, then you need to run it like this:
& "$env:OPENMODELICAHOME\bin\omc.exe" script.mos

Yes, from powershell

my script is "run_twovariableaddition.mos":

Code:


cd("C:/Users/amroa/AppData/Local/Temp/OpenModelica");
mkdir("Output"); getErrorString();
cd("Output"); getErrorString();
loadModel(Modelica); getErrorString();
loadFile("C:/Users/amroa/AppData/Local/Temp/OpenModelica/twovariableaddition.mo")
readFile("C:/Users/amroa/AppData/Local/Temp/OpenModelica/twovariableaddition.mo")
buildModel(twovariableaddition);
system("C:/Users/amroa/AppData/Local/Temp/OpenModelica/Output/twovariableaddition -override extpar1="+String(6)+",extpar2="+String(6)+" -r=twovariableaddition" + "_res.csv")

and I am running it from powershell as below and gave me an error:

Code:


PS C:\Users\amroa\AppData\Local\Temp\OpenModelica> & "$env:OPENMODELICAHOME\bin\omc.exe" run_twovariableaddition.mos
Error processing file: run_twovariableaddition.mos
[C:/Users/amroa/AppData/Local/Temp/OpenModelica/run_twovariableaddition.mos:1:52-1:52:writable] Error: Missing token: ASSIGN

# Error encountered! Exiting...
# Please check the error message and the flags.

Execution failed!

Edited by: Amro - Dec-28-21 21:19:56

Re: how to utilize the exe file that is compiled when i simulate a model?

adrpo wrote:


There are alternatives to speed it up quite a bit if you only need for example just a few variables from a simulation run, you could skip the generation of the mat file entirely with -noemit: https://openmodelica.org/doc/OpenModeli … lag-noemit and using -output var1,var2,var3: https://openmodelica.org/doc/OpenModeli … lag-output
Then you would just read these variable values and use them for the next simulation.

Yes, I only need some variables from the simulation. Can you give me an example here, because I dont know where to add the two extensions -noemit and -output var1,var2,var3

Edited by: Amro - Dec-28-21 21:25:34

Re: how to utilize the exe file that is compiled when i simulate a model?

Note that you cannot do

Code:

system("./Model ")

and then get the results in the environment, however, if you run

Code:

simulate(Model)

you can then use

Code:

val(var, 0)

.

I will make an example with -output.

Edited by: adrpo - Dec-29-21 11:30:18

Re: how to utilize the exe file that is compiled when i simulate a model?

For this one:

Code:


system("C:/Users/amroa/AppData/Local/Temp/OpenModelica/Output/twovariableaddition -override extpar1="+String(6)+",extpar2="+String(6)+" -r=twovariableaddition" + "_res.csv")

I think you're missing a semicolon at the end:

Code:


system("C:/Users/amroa/AppData/Local/Temp/OpenModelica/Output/twovariableaddition -override extpar1="+String(6)+",extpar2="+String(6)+" -r=twovariableaddition" + "_res.csv");

I suggest to also add

Code:

getErrorString();

after each command so you can see if there are any errors.

Amro wrote:


adrpo wrote:


3. Are you running those commands in cmd.exe or some other shell like powershell?
If yes, then you need to run it like this:
& "$env:OPENMODELICAHOME\bin\omc.exe" script.mos

Yes, from powershell

my script is "run_twovariableaddition.mos":

Code:


cd("C:/Users/amroa/AppData/Local/Temp/OpenModelica");
mkdir("Output"); getErrorString();
cd("Output"); getErrorString();
loadModel(Modelica); getErrorString();
loadFile("C:/Users/amroa/AppData/Local/Temp/OpenModelica/twovariableaddition.mo")
readFile("C:/Users/amroa/AppData/Local/Temp/OpenModelica/twovariableaddition.mo")
buildModel(twovariableaddition);
system("C:/Users/amroa/AppData/Local/Temp/OpenModelica/Output/twovariableaddition -override extpar1="+String(6)+",extpar2="+String(6)+" -r=twovariableaddition" + "_res.csv")

and I am running it from powershell as below and gave me an error:

Code:


PS C:\Users\amroa\AppData\Local\Temp\OpenModelica> & "$env:OPENMODELICAHOME\bin\omc.exe" run_twovariableaddition.mos
Error processing file: run_twovariableaddition.mos
[C:/Users/amroa/AppData/Local/Temp/OpenModelica/run_twovariableaddition.mos:1:52-1:52:writable] Error: Missing token: ASSIGN

# Error encountered! Exiting...
# Please check the error message and the flags.

Execution failed!

Re: how to utilize the exe file that is compiled when i simulate a model?

Note that you should also be able to use

Code:

val(var, time, "result_filename.mat|csv")

in case you use

Code:

system 

and not

Code:

simulate

https://build.openmodelica.org/Documentation/OpenModelica.Scripting.val.html
So hopefully this might work fine (but I'm a bit unsure if we implemented it for csv files):

Code:

val(s,0,"twovariableaddition_res.csv");

Edited by: adrpo - Dec-29-21 11:44:02

Re: how to utilize the exe file that is compiled when i simulate a model?

adrpo Thank you very much! Based on your great explanations, I have these below concerns please:
1- Is it possible to write system(\"./Model -override var1=6 -output s\") to put the output s in the environment? Since I care about the execution speed then using simulate() is not proper in my case. Alternatively, using system() to generate the "result_filename.mat|csv" and then using val(s,0,"twovariableaddition_res.csv") is also a consuming time. Do you think there would be a better alternative, such as using FMI?


My code worked in the default directory i.e. "C:\Users\user_name\AppData\Local\Temp\OpenModelica" and the system() command returned “0”. However, when I change the path directory to be through the One-Drive(i.e. "C:/path1/One- Drive/path2/model"), the code works except the system() command and it returns “1”.

2- Do you know why? is it because of the space?


There are alternatives to speed it up quite a bit if you only need for example just a few variables from a simulation run, you could skip the generation of the mat file entirely with -noemit: https://openmodelica.org/doc/OpenModeli … lag-noemit and using -output var1,var2,var3: https://openmodelica.org/doc/OpenModeli … lag-output
Then you would just read these variable values and use them for the next simulation.

3- Yes, I only need some variables from the simulation. Can you give me an example here, because I dont know where to add the two extensions -noemit and -output var1,var2,var3. Is it with simulate() or with system()?


Alternatively you could use FMI, generate an FMU from your model and use any FMI tool to run the FMU until a certain time, then read the values, then restart the FMU with the new values. No mat file is generated. I would suggest to use OMSimulator python interface for this: https://www.openmodelica.org/doc/OMSimu … ython.html
OMSimulator can run composite FMUs but you don't need that, one FMU should be enough, just load that and run it using stepUntil. I will try to make a python script example for this.

4- Yes, could you pleas give an example here?

Edited by: Amro - Jan-05-22 15:47:54

Re: how to utilize the exe file that is compiled when i simulate a model?

See here for an example using -output:
https://github.com/OpenModelica/OpenMod … ssues/8384

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