0

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

Jay_At_Play
  • 136
  • 10
  • You could try to make "input pubSelect" instead of "parameter pubSelect". – Adrian Pop Apr 18 '15 at 20:43
  • I tried your suggestion, but that yields `variability="discrete" causality="input"`. Thank you none the less:) – Jay_At_Play Apr 20 '15 at 09:24
  • But causality input is OK. It means is tunable. Or isn't so? – Adrian Pop Apr 20 '15 at 13:26
  • @AdrianPop I guess that might work, I'll have to try it sometime. I guess the success depends on whether or not the required input variable can be made `tunable`. Unfortunately, I don't have the time right now, but will definitely update this thread if I continue my research! – Jay_At_Play Apr 24 '15 at 12:16

1 Answers1

1

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~

Hang Yu
  • 476
  • 2
  • 14
  • Sorry, I think the annotation(Evaluate=false) alone will do the job. – Hang Yu May 01 '15 at 14:51
  • Using `selection(start=pubSelect.Publication_2) annotation(Evaluate=false)` yields `variability="tunable" causality="parameter"` in the XML file. The original code `selection = pubSelect.Publication_2 annotation(Evaluate=false)` gives the exact same result in the XML file. So the annotation alone does the job on my computer as well, as suggested in your comment. Thanks a lot for your help! – Jay_At_Play May 22 '15 at 12:37