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

Assigning parameter value through a file

Assigning parameter value through a file

I've been reading through Peter Fritzson's Introduction to Modeling and Simulation of Technical and Physical Systems with Modelica.

On page 38 of this text, in section 2.1.3 Constants, the following is stated:

"Parameter constants can be declared without a declaration equation since their value can be defined, for example, by reading from a file, before simulation starts."

I know that another .mo file can instantiate parameter values when an object is instantiated.  Is that what Peter is referring to here?  Or is there some other means by which files can be used to assign parameter values?

If you had to state the difference between parameters and constants in Modelica, how would you word it?

As always, thank you for your time.  current/smile

Re: Assigning parameter value through a file

The difference between parameters and constants is that you can declare initial equations for parameters but not constants. Some Modelica tools (OpenModelica included) also allow you to compile a model and tune (certain) parameters before a simulation run. I prefer using constants.

Re: Assigning parameter value through a file

So there is no file i/o in the traditional programming sense in Modelica?

Re: Assigning parameter value through a file

You can define parameter input by reading a file during initalization:

Code:

parameter Real p = readFromInputFile("abc.txt", 13);

Re: Assigning parameter value through a file

I have seen nothing of the sort and I've been reading OpenModelica/Dymola/System Modeler/Modelica documents and the book I mentioned.  Argh.

Thank you again, sjoelund.se!  You are immensely helpful.

Re: Assigning parameter value through a file

Well, you do have to write such an input method yourself. You could probably see https://build.openmodelica.org/Document … ables.html for some ideas on how you could get a value from a file. Though as far as I know that is more used for reading data of a continuous signal.

Re: Assigning parameter value through a file

There is also an example function in the Modelica Standard Library on how to read from file.
See  for example:
https://build.openmodelica.org/Document … meter.html

Cheers,
Adrian Pop/

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