- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Assigning parameter value through a file
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.
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.
- sjoelund.se
- 1700 Posts
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);
- sjoelund.se
- 1700 Posts
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.
- sjoelund.se
- 1700 Posts
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/
- adrpo
- 885 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Assigning parameter value through a file