Is it possible to build a "conditional" FMU using Modelica?

I have an application in which I use Dymola as a development environment, but will export models in the form of FMU that will be used in another application. The systems that I simulate have interchangeable components, which makes them very suitable for modeling in Modelica. But I'm not sure that I can use this opportunity when I want to export models in the form of FMU.

Consider the simple package below. The goal of the package is to identify two very simple models and allow the user to choose between possible models when executing the model. Although this is easy to do in the Modelica IDE, I need a similar feature in FMU.

A partial model defines a model where y = p0 + p1 * x. Two advanced models simply assign different values ​​to the parameters p0 and p1. Finally, TestModel adds a parameter called modelIndex, which is used in conditional expressions that define two possible types of model. Inside Dymola, this works great, as the user can easily set the value of the modelIndex parameter. I am trying to figure out if this can be done through FMU by making modelIndex input to FMU. But compilation failed if I set the annotation Evaluate = false for the modelIndex variable. Indicated error: "The current version of the Modelica translator can only process conditional components with a fixed condition .... All variables used in the conditional declaration condition must be declared as constants or parameters."

If someone can help give guidance on how to create a conditional FMU, he would greatly appreciate it. This simple example is used only to demonstrate the problem. The true system that is being modeled has 4-5 main components, each of which has 5 + possible models, which gives a large set of possible permutations. Just batch exporting all configurations is probably not possible.

Thank! Justin

package ConfigurableModel 
  "Package to test whether or not models can be configured by external inputs"
  partial model partialModel 
    "Partial model used to control selectable options in Dymola"

    Modelica.Blocks.Interfaces.RealInput x(start = 1) "input value";
    Modelica.Blocks.Interfaces.RealOutput y "output value";

    parameter Real p0 = 0;
    parameter Real p1 = 0;

  equation 
    y = p0 + p1*x;
      annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
      coordinateSystem(preserveAspectRatio=false)));
  end partialModel;

  model linearModel_NoOffset "Linear model with no offset"
    extends partialModel(p0 = 0, p1 = 1);
  end linearModel_NoOffset;

  model linearModel_Offset "Linear model with offset"
    extends partialModel(p0=1, p1=1);
  end linearModel_Offset;

  model TestModel "Model to test configurability"
    // parameter Integer modelIndex = 2 "1 = linear_NoOffset, 2 = linear_Offset" annotation(Evaluate=false);

    parameter Integer modelIndex = 2 "1 = linear_NoOffset, 2 = linear_Offset";

    // Conditional instances, only one model is created based upon value of modelIndex
    linearModel_NoOffset linear_NoOffset if modelIndex == 1;
    linearModel_Offset linear_Offset if modelIndex == 2;

    // Input and output blocks
    Modelica.Blocks.Sources.Constant xMaster(k=1) annotation (Placement(transformation(extent={{-100,-10},{-80,10}})));
    Modelica.Blocks.Interfaces.RealOutput yMaster annotation (Placement(transformation(extent={{100,-10},{120,10}})));

  equation 
    // Note that only the connections for the components that exist will be used

    // Connect input to each model instance
    connect(xMaster.y, linear_NoOffset.x);
    connect(xMaster.y, linear_Offset.x);

    // Connect output to each model instance
    connect(yMaster, linear_NoOffset.y);
    connect(yMaster, linear_Offset.y);

      annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
      coordinateSystem(preserveAspectRatio=false)));
  end TestModel;
    annotation (uses(Modelica(version="3.2.1")));
end ConfigurableModel;
+4
source share
2 answers

, FMI. - Modelica, , Modelica C-, FMU ( C-Code ). FMU (, ). , modeldescription.xml FMU, FMU. FMU . , Modelica, Modelica . , (RealInput RealOutput) , , , linear_NoOffset, linear_Offset ( "if modelIndex == xy" ) , , modelIndex, . , . .

+2

, Elmqvist (2014), . , - Dymola, , .

+2

Source: https://habr.com/ru/post/1670032/


All Articles