Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Exporting FMU of underdetermined Models for coupled Simulation

Exporting FMU of underdetermined Models for coupled Simulation

Hello,

following the example of the Lund University (https://portal.research.lu.se/portal/fi … i_tech.pdf , page 12, 4.3.  Simulation of coupled models), i wanted to couple to FMUs. One is a simple RL-Circuit with an adjustable source (signalvoltage), the other one is a PID-Controller which sets the voltage according to the demanded current.

In Python, i want to import the FMUs and run the models with following lines:

Code:



from  pyfmi  import  load_fmu
from  pyfmi.master  import  Master

controller   = load_fmu("controller.fmu")
RL = load_fmu("RL_Tester.fmu")

connections = [( RL ,"currentSensor1.i",controller ,"feedback1.u2"),
               (controller ,"PID.y",RL ,"signalVoltage1.v")]

models = [RL , controller]

master_simulator = Master(models , connections)

res = master_simulator.simulate(final_time =1)

The connections between my Currentsensor and the PID-Controller are set in Python.

So each model individually is underdetermined, which means i create an Error when I try to build a FMU of the Models.

How can I build the FMUs which i need for this type of CO-Simulation?

The Code for Both Modelica models is attached, i only used the modelica standard libraries.

Best regards and thanks in advance!

Henrik

 Spoiler Show Spoiler Hide Spoiler
 

Code:


model RL_TesterMaster
  Modelica.Electrical.Analog.Basic.Resistor resistor1(R = 0.01) annotation(
    Placement(visible = true, transformation(origin = {-26, 46}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Inductor inductor1(L = 0.0001) annotation(
    Placement(visible = true, transformation(origin = {8, 46}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Ground ground1 annotation(
    Placement(visible = true, transformation(origin = {-66, -14}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Sources.SignalVoltage signalVoltage1 annotation(
    Placement(visible = true, transformation(origin = {-66, 30}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
 
  Modelica.Electrical.Analog.Sensors.CurrentSensor currentSensor1 annotation(
    Placement(visible = true, transformation(origin = {42, 46}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));

equation
  connect(inductor1.n, currentSensor1.p) annotation(
    Line(points = {{18, 46}, {32, 46}}, color = {0, 0, 255}));
  connect(currentSensor1.n, signalVoltage1.n) annotation(
    Line(points = {{52, 46}, {58, 46}, {58, 20}, {-66, 20}}, color = {0, 0, 255}));
  connect(resistor1.n, inductor1.p) annotation(
    Line(points = {{-16, 46}, {-2, 46}}, color = {0, 0, 255}));
  connect(signalVoltage1.p, resistor1.p) annotation(
    Line(points = {{-66, 40}, {-65.5, 40}, {-65.5, 46}, {-36, 46}}, color = {0, 0, 255}));
  connect(signalVoltage1.n, ground1.p) annotation(
    Line(points = {{-66, 20}, {-66, -4}}, color = {0, 0, 255}));
  annotation(
    uses(Modelica(version = "3.2.3")));
end RL_TesterMaster;

Code:


model controllerMaster
  Modelica.Blocks.Math.Feedback feedback1 annotation(
    Placement(visible = true, transformation(origin = {32, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
  Modelica.Blocks.Sources.RealExpression realExpression1(y = 100)  annotation(
    Placement(visible = true, transformation(origin = {82, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));

Modelica.Blocks.Continuous.PID PID(Td = 0.0001, Ti = 0.001, k = 0.1)  annotation(
    Placement(visible = true, transformation(origin = {38, -36}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(feedback1.u1, realExpression1.y) annotation(
    Line(points = {{40, 0}, {72, 0}}, color = {0, 0, 127}));
connect(PID.u, feedback1.y) annotation(
    Line(points = {{26, -36}, {-7, -36}, {-7, 0}, {23, 0}}, color = {0, 0, 127}));
end controllerMaster;

Edited by: Mota - Dec-17-19 10:14:12

Re: Exporting FMU of underdetermined Models for coupled Simulation

IMHO you could use some Real I/O for each I/O you want to connect, so the FMU has a "port" to outside.

For example:

Code:


  model RL
    ...
    output Real i_out;
   ...

   equation
    i_out = currentSensor1.i
   end RL;

  model controller
    ...
    input Real u2_in
   ...

   equation
   feedback1.u2 = u2_in
   end controller;

so you can connect the ports in python.

Code:

 connections = [( RL ,"i_out",controller ,"u2_in") 

i think it will solve your underdetrmined problem.

Cheers

Edited by: Arinomo23 - Dec-18-19 06:52:40
There are 0 guests and 0 other users also viewing this topic
You are here: