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 use OpenModelica from command line.

How to use OpenModelica from command line.

I would like to use OpenModelica in batch mode.
I want to compile and simulate Modelica model from command line in Command Pompt.

If someone knows how to compile and simulate Modelica model from command line, please let me know.Thank you!

Re: How to use OpenModelica from command line.

myscript.mos:

Code:

loadModel(Modelica);

loadFile("mymodel.mo");
simulate(MyModel);

From the shell:

Code:

omc myscript.mos

In Windows (probably):

Code:

%OPENMODELICAHOME%\bin\omc myscript.mos

Re: How to use OpenModelica from command line.

Hi.

I can simulate from command line following your message.

Thank you!

Re: How to use OpenModelica from command line.

Hello,

Thanks a lot for your description. I could also simulate my model from cmd. I have a small question. How can I change the simulation options like the starting time and ending time (basically time step) without openning OMEdIt.

Best,
Pouya

Re: How to use OpenModelica from command line.

simulate

simulates a modelica model by generating c code, build it and run the simulation executable. The only required argument is the className, while all others have some default values. simulate(className, [startTime], [stopTime], [numberOfIntervals], [tolerance], [method], [fileNamePrefix], [options], [outputFormat], [variableFilter], [cflags], [simflags]) Example command: simulate(A);

Code:


function simulate
  input TypeName className "the class that should simulated";
  input Real startTime = "<default>" "the start time of the simulation. <default> = 0.0";
  input Real stopTime = 1.0 "the stop time of the simulation. <default> = 1.0";
  input Real numberOfIntervals = 500 "number of intervals in the result file. <default> = 500";
  input Real tolerance = 1e-6 "tolerance used by the integration method. <default> = 1e-6";
  input String method = "<default>" "integration method used for simulation. <default> = dassl";
  input String fileNamePrefix = "<default>" "fileNamePrefix. <default> = \"\"";
  input String options = "<default>" "options. <default> = \"\"";
  input String outputFormat = "mat" "Format for the result file. <default> = \"mat\"";
  input String variableFilter = ".*" "Filter for variables that should store in result file. <default> = \".*\"";
  input String cflags = "<default>" "cflags. <default> = \"\"";
  input String simflags = "<default>" "simflags. <default> = \"\"";
  output String simulationResults;
end simulate;

see OpenModelicaUsersGuide/scripting_api

Edited by: lochel - Oct-23-15 09:18:44

Re: How to use OpenModelica from command line.

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 current/smile

Best,
Pouya

Edited by: PJS - Nov-24-15 14:07:53

Re: How to use OpenModelica from command line.

Hi JPS,
If you would like to check errors during model flattening you should just run

Code:

omc test.mo Modelica

this allows test.mo to use|link any module defined in Modelica libraries.

If there are other dependencies you can just append other files

Code:

omc test.mo Modelica test_library.mo

again the main file is the first one i.e. test.mo

This way all the dependencies are fixed: any error that comes from the compilation now regards only your errors (too many equations/variables,etc...).

Edited by: DarioMangoni - Dec-20-17 15:32:15

Re: How to use OpenModelica from command line.

Hi,
I am following your steps and trying to simulate but failed. I am getting the following messages:
messages = "Simulation execuation failed for model: mymodel
Access is denied.
"

Also, I tried on another computer and there the message is,
messages = "Failed to build model: mymodel"

Could you please help me how to fix the issue.

Thanks

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