Package ptolemy.cg.kernel.generic.program.procedural.fmima

Generate code for the Functional Mockup Unit Master Algorithm (FMIMA).

Two master algorithms are available:

  • FMI 2.0 CoSimulation MA
  • FMI Hybrid MA

This code generator use the algorithm defined in
David Broman, Christopher Brooks, Lev Greenberg, Edward A. Lee, Michael Masin, Stavros Tripakis and Michael Wetter, "Determinate Composition of FMUs for Co-Simulation," EECS Department University of California, Berkeley Technical Report No. UCB/EECS-2013-153 August 18, 2013. Which is a version of a EMSOFT '13 paper.

The only difference among FMI 2.0 CoSimulation MA and FMI Hybrid MA is the representation of time. In the FMI Hybrid MA, time is represented as an integer, where all the FMUs must agree on the same time precision.

The Hybrid FMUs are located in $PTII/ptolemy/actor/lib/fmi/fmus/Hybrid*

Resources

Overview

The ptolemy.cg has a lot of classes, but the FMIMA work consists of only a few classes.

The easist way to work with the code is to look for the fmima directories and then the .java files

      bash-3.2$ cd $PTII/ptolemy/cg
      bash-3.2$ find . -name fmima
      ./adapter/generic/program/procedural/fmima
      ./kernel/generic/program/procedural/fmima
      bash-3.2$ find ./adapter/generic/program/procedural/fmima -name "*.java"
      ./adapter/generic/program/procedural/fmima/adapters/ptolemy/actor/Director.java
      ./adapter/generic/program/procedural/fmima/adapters/ptolemy/actor/lib/fmi/FMUImport.java
      ./adapter/generic/program/procedural/fmima/adapters/ptolemy/actor/TypedCompositeActor.java
      ./adapter/generic/program/procedural/fmima/test/junit/JUnitTclTest.java
      bash-3.2$ find ./kernel/generic/program/procedural/fmima -name "*.java"
      ./kernel/generic/program/procedural/fmima/FMIMACodeGenerator.java
      ./kernel/generic/program/procedural/fmima/FMIMACodeGeneratorAdapter.java
      ./kernel/generic/program/procedural/fmima/test/junit/JUnitTclTest.java
      bash-3.2$ 
    

Invocation of the FMI MA code generators

The main entry point is $PTII/ptolemy/cg/kernel/generic/program/procedural/fmima/FMIMACodeGenerator.java. When the code generator is invoked, that class is instantiated.

Run $PTII/bin/ptcg -help to see other command line arguments.

Below is the command to run a sample model:

Invoking FMI 2.0 CoSimulation MA

      $PTII/bin/ptcg -language fmima $PTII/ptolemy/cg/kernel/generic/program/procedural/fmima/test/auto/emsoft2013.xml
    

Invoking FMI Hybrid MA

      $PTII/bin/ptcg -language fmima -dialect hybrid $PTII/ptolemy/cg/kernel/generic/program/procedural/fmima/test/auto/Test4.xml
    

In Test4.c you can find the MA, while in results.cv there is the output of the simulation. The output show all the interface signals of all the FMUs and therefore it is a little bit hard to read at a first glance. However the name of the signals are self-explanatory and you can easily understand the signal traces.

How it works

In a nut shell, the code iterates through the model, finding actors and attributes. An adapter class is searched for that will handle each actor and attribute. If an adapter is not found, then an adapter for the parent class of the actor or attribute is searched for.

What to modify

$PTII/ptolemy/cg/kernel/generic/program/procedural/fmima/FMIMACodeGenerator.java
Copies the C files in $PTII/ptolemy/actor/lib/fmi/ma/includes/ and shared/
$PTII/ptolemy/cg/adapter/generic/program/procedural/fmima/adapters/ptolemy/actor/TypedCompositeActor.c
The template file that includes the body of the Master Algorithm.

Since:
Ptolemy II 10.0