6
$\begingroup$

I have two FMU developed with different simulation tools. I would like to connect them through some variables and run a co-simulation with an open source tool as OpenModelica. This co-simulation has to be rather tight as both FMU have discontinuities.

Is that possible?. Could you provide a simple sample?

$\endgroup$
3
  • $\begingroup$ What is an FMU? $\endgroup$ Commented Jun 21, 2013 at 9:28
  • 1
    $\begingroup$ Functional Mock-up Interface is a standard to interface simulations made in different tools (Symulink, Dymola, AMESim, ...) in the same co-simulation. $\endgroup$
    – Koldo
    Commented Jun 21, 2013 at 9:32
  • 1
    $\begingroup$ I've added a tag for FMI with an explanation (still pending review). $\endgroup$ Commented Jun 21, 2013 at 9:35

1 Answer 1

7
$\begingroup$

Model Exchange vs. Co-Simulation

This depends on how you export your FMUs: You can either use FMI for model-exchange or FMI for co-simulation.

In the model-exchange scenario, the FMU contains only the model and no solver. Therefore the solver of the importing simulator is used.

In the co-simulation scenario, the FMU contains both the model and a solver. Here the importing simulator acts as the master of the co-simulation.

In both cases you will need a simulator that supports the import of the respective FMU type. OpenModelica has support for import of model-exchange FMUs since version 1.8.0. Hence, if you have two FMUs that you have exported using FMI for model-exchange, you can import them both into OpenModelica and simulate them using the OpenModelica solver. Note that strictly speaking, this isn't a real co-simulation since only one solver is involved.

If you want to use a separate solver for each FMU (i.e. perform a real co-simulation) then you should only export one of the models as an FMU using FMI for co-simulation. Import that FMU into the simulator of the other model. Note that OpenModelica 1.8.0 doesn't support FMI for co-simulation.

Model Exchange Example

Here's a working example (tested in Dymola, I don't have OpenModelica installed here right now):

File TestFMU1.mo:

model TestFMU1
  parameter Real p = 1.0;

  connector TestOutputConnector
    output Real value;
  end TestOutputConnector;
  TestOutputConnector c;

equation 
  c.value = p;

end TestFMU1;

File TestFMU2.mo:

model TestFMU2
  Real result;

  connector TestInputConnector
    input Real value;
  end TestInputConnector;
  TestInputConnector c;

equation 
  result = c.value;

end TestFMU2;

Export both of these as FMUs. Then import them and combine them as follows:

model TestConnection
  TestFMU1_fmu OutputFMU;
  TestFMU2_fmu InputFMU;
equation 
  connect(OutputFMU.c_value, InputFMU.c_value);
end TestConnection;

OpenModelica

It seems that OpenModelica currently does not support simulating two FMUs simultaneously. This is a known bug.

$\endgroup$
5
  • $\begingroup$ The problem is how to link two models in Modelica language. As both FMU have the same number of equations and unknowns, adding an additional equation to put, lets say, Force_FMU_1 = Force_FMU_2, would add an additional equation so it would be overdetermined. $\endgroup$
    – Koldo
    Commented Jun 21, 2013 at 10:28
  • $\begingroup$ FMI only supports directed in- and outputs. Undirected ports, like the standard ports in Modelica, are currently not supported. In addition, OpenModelica cannot "see" the equations used to build your FMUs. Hence there is no problem connecting the outputs of one FMU with the inputs of the other. $\endgroup$ Commented Jun 21, 2013 at 11:23
  • $\begingroup$ Thank you Florian. Could you put a simple sample?. For example, this do not run because it is overdetermined: model Master FMU_Model1_me_FMU model1; // Loaded from FMU_Model1_me_FMU.mo FMU_Model2_me_FMU model2; // Loaded from FMU_Model2_me_FMU.mo equation model1.out = model2.in; end Master; $\endgroup$
    – Koldo
    Commented Jun 22, 2013 at 6:26
  • $\begingroup$ @Koldo: See my update. $\endgroup$ Commented Jun 24, 2013 at 15:13
  • $\begingroup$ Excellent!. Thank you Florian. That is what I wanted!. Unfortunately it does not work in OpenModelica. The generated .exe for TestConnection gets crashed. I will report them. $\endgroup$
    – Koldo
    Commented Jun 25, 2013 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.