Search code examples
modelicadymolafmi

FMU-Export in Dymola: Is it possible to make a Modelica enumeration type variable "tunable" when exported as FMU / FMI


I have implemented three similar publications in one Modelica model, using an enumeration type variable to select the publication. The goal is to switch between calculation methods (i.e. between publications) by changing the value of the enumeration type variable online.
The calculation consists of three steps, each of which has its own enumeration variable. This allows for mixed calculation methods, e.g. by setting step 1 to calculate according to publication 1 and steps 2 and 3 according to publication 2.

Each step reads something like this

model Calculation_step

  type pubSelect = enumeration(
      Publication_1,
      Publication_2,
      Publication_3);
  // ####### Publication Selection #######
  parameter pubSelect selection = pubSelect.Publication_2;
  // ##### End Publication Selection #####

  Modelica.Blocks.Interfaces.RealInput incoming;
  Modelica.Blocks.Interfaces.RealOutput outgoing;

  parameter Real factor = 5;

equation 
  if selection == pubSelect.Publication_1 then
    outgoing = factor * sin(incoming);
  elseif selection == pubSelect.Publication_2 then
    outgoing = factor * sin(incoming)^2;
  elseif selection == pubSelect.Publication_3 then
    outgoing = factor * sin(incoming)^3;
  else
    outgoing = 99999;
  end if;

  annotation (uses(Publicationica(version="3.2.1"), Modelica(version="3.2.1")));
end Calculation_step;

The model will not be calculated in Dymola. Instead, a functional mock-up unit (FMU) is created using Dymola. This creates an XML file describing the model. In order to enable online changes, a variable has to have the attribute variability="tunable" set in this XML.

However, the variable selection is not tunable, as shown in the following excerpt of the XML:

-<ModelVariables>

<!-- Index for next variable = 1 -->


-<ScalarVariable name="selection" variability="constant" valueReference="100663296">

<Enumeration start="2" declaredType="Calculation_step"/>

</ScalarVariable>

Using the same code for the declaration of the variable factor yields a tunable FMU variable:

<!-- Index for next variable = 4 -->


-<ScalarVariable name="factor" variability="tunable" valueReference="16777216" causality="parameter">

<Real start="5"/>

</ScalarVariable>

tl;dr: Is it possible to make a Modelica enumeration type variable "tunable" when exported as FMU / FMI?

Dymola Version 2015 FD01 (32-bit), 2014-11-04


Solution

  • I tried to add a start value to the selection parameter, and with annotation (Evaluate=false) it became tunable.

    parameter pubSelect selection(start=pubSelect.Publication_2) annotation (Evaluate=false);
    

    It will give you a warning about an unassigned parameter tho, I have not really tried if it really works(change the value at events/communication points), please let me know the result if you have a chance to give it a try. Thanks~