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 obtain a variability=tunable parameter when exporting FMU?

How to obtain a variability=tunable parameter when exporting FMU?

I want to export a model in OpenModelica to FMU including a 'tunable' input parameter to the parameter. For this, I call

>> translateModelFMU(model)

And in the model I have a set of parameters such as

parameter input Real param;

The resulting FMU modelDescription.xml lists the variable as
 
<ScalarVariable
    name="param"
    valueReference="37"
    variability="fixed"
    causality="input" >
    <Real start="0.0"/>
  </ScalarVariable>

i.e., as a fixed input parameter. I would like to change the Modelica code to obtain a tunable parameter in the resulting FMU.

In Dymola, adding the annotation (Evaluate=false) to the definition of the parameter will do the trick. However, this solution seems to be specific to Dymola. I tried to add the annotation in OM but seems to have no effect regarding the resulting FMU. What would be the way to achieve this in OpenModelica?

Re: How to obtain a variability=tunable parameter when exporting FMU?

tunableParameter.mo

using OM 1.18.1
tunable parameter works
see example, one parameter is the value k of the gain-block, another defined as 'parameter Real k1 = 1'

I remember there were issues with older versions, there you had to disable the translation flag 'Evaluate all parameters' (think since 1.18 disabled by default)

not sure about 'parameter input Real xyz' - never used that

hope this helps

Edited by: glang - Mar-29-22 14:00:04

Re: How to obtain a variability=tunable parameter when exporting FMU?

Hey @glang

Thanks for the input!
However I downgraded OM to 1.18.1 and used the model you sent me, with unsuccessful results. The compiled FMU still shows:

Code:


  <!-- Index of variable = "4" -->
  <ScalarVariable
    name="gain.k"
    valueReference="3"
    description="Gain value multiplied with input signal"
    variability="fixed"
    causality="parameter"
    >
    <Real start="1.0" unit="1"/>
  </ScalarVariable>
  <!-- Index of variable = "5" -->
  <ScalarVariable
    name="k1"
    valueReference="4"
    description="gain 1"
    variability="fixed"
    causality="parameter"
    >
    <Real start="1.0"/>
  </ScalarVariable>

in the modelDescription.xml file.
In Simulation Setup, at the Translation Flags tab, the 'Evaluate all parameters' checkbox is disabled.

Best,

Re: How to obtain a variability=tunable parameter when exporting FMU?

Hello,
my xml looks similar,
but when I run the fmu (in the co-simulation tool of my choice) I can change the values of k and k1, and the results of y and y1 are correct.

I think you are right - variability of k and k1 should be set to "tunable";
maybe someone with better knowledge of the FMI standard can comment on this please?
strange that it works with variability = "fixed"

Have you tested your fmu?

attached my fmu (co-simulation and model exchange), which you can also run in OM (don't forget to change the name from 'tunableParameter_me_FMU' to e.g. 'tunableParameter_me_FMU_1' when inserting into a model, otherwise you'll get an error)

tunableParameter.fmu

Edited by: glang - Mar-30-22 05:27:52

Re: How to obtain a variability=tunable parameter when exporting FMU?

---deleted

Edited by: glang - Mar-30-22 05:50:06

Re: How to obtain a variability=tunable parameter when exporting FMU?

after checking the FMI standard:

causality = parameter:
A data value that is provided by the importer or user to change the behavior of the FMU.
It is constant during the simulation (except for tunable parameters)

so sorry if I didn't get your initial question right...my proposed solution doesn't provide a tunable parameter, just one you can set at the beginning of the simulation.

maybe just use a normal input instead of a tunable parameter.

PS: after manually editing the ModelDescription.xml:
  <ScalarVariable
    name="k1"
    valueReference="4"
    description="gain 1"
    variability="fixed"
    causality="parameter"
    >
to:
  <ScalarVariable
    name="k1"
    valueReference="4"
    description="gain 1"
    variability="tunable"
    causality="parameter"
    >
and zipping to tunableParameter.fmu the fmu it seems to work.
just a work around, think there is something missing in OM to define tunable parameters; but just my guess; maybe there is a better way to define tunable parameters inside the model?

Edited by: glang - Mar-30-22 07:08:27

Re: How to obtain a variability=tunable parameter when exporting FMU?

Thanks @glang for the response,

Unfortunately, this workaround will not work for my purpose (parameter estimation through optimization using the FMU). I guess it also needs to be declared somehow within the FMU binaries.

For the record, I also posed the question in the OM github at the Q&A section: https://github.com/OpenModelica/OpenMod … sions/8781

and I was referred to the following ongoing discussion in the Modelica Specification github https://github.com/modelica/ModelicaSpe … ssues/3140

Seems that there is some work to be done to get there!

Best,

Re: How to obtain a variability=tunable parameter when exporting FMU?

Hello w1ldw0lf,
just wanted to mention, that with the modified fmu
  <ScalarVariable
    name="k1"
    valueReference="6"
    description="gain 1"
    variability="tunable"
    causality="parameter"
    >

it is possible, to change k1 whilst the simulation is running, and the output is as expected (see attached csv files from an actual simulation, using a slider to control k1)
(I'm working with AVL Model.CONNECT, not sure about other tools...)

I've added another output 'k1_check' which just outputs the value of k1 during runtime


1648649650_tunableParameter.fmu

FMU-1-in.csv

FMU-1-res.csv

sorry if I'm bothering you, but as I'm also very much interested in using OM fmu's (and was struggling a bit too) I'm quite interested in this topic being resolved
cheers, GL


Edited by: glang - Mar-30-22 14:28:36

Re: How to obtain a variability=tunable parameter when exporting FMU?

Thanks @glang again for the quick response, no bother at all! All knowledge is always very welcome

So, to be clear, when compiled the FMU had fixed parameters? And then the XML was manually changed to set these as tunable?

From my side, I am using CasADi to convert the FMU into an optimization problem.
I am already in contact with the CasADi developers to tackle this issue, so it may take some days to get deep into it. Good to know that at least is not coming from the FMU side. That is clearly shown from your results. Highly appreciated!

Best,

Edited by: w1ldw0lf - Mar-30-22 14:56:01

Re: How to obtain a variability=tunable parameter when exporting FMU?

you're welcome.
not sure if the fmu is 100% okay, just recognized that with a certain tool tuning (changing) the parameter during runtime worked (after manually editing the xml)
so yes, after exporting the fmu k1 was 'fixed', and I changed it to 'tunable'
then zipped the directory to an fmu, which I've tested
quite sure that there has something to be improved on the OM side.
Best
GL

Edited by: glang - Mar-30-22 15:01:37
There are 0 guests and 0 other users also viewing this topic
You are here: