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
  • Index
  • » Users
  • » dimitri.tratkanov
  • » Profile

Posts

Posts

Jul-07-15 10:04:34
FMU Co-simulation : Inputs/Outputs of FMU Block

Finally, I have download OpenModelica 1.9.1 (r22929) (RML version) and it’s works !

Jul-07-15 08:52:28
FMU Co-simulation : Inputs/Outputs of FMU Block

This is the code of OpenModelica 1.9.2 (r25117). In this case I haven't any error but still the function fmiSetReal do not change the input values.

Code:

model e_battery_cs_st_FMU

  constant String fmuLocation = "file://C:/Users/DIMITR~1.TRA/AppData/Local/Temp/OpenModelica/OMEdit/resources";
  constant String fmuWorkingDir = "C:/Users/DIMITR~1.TRA/AppData/Local/Temp/OpenModelica/OMEdit";
  parameter Integer logLevel = 3 "log level used during the loading of FMU" annotation(Dialog(tab = "FMI", group = "Enable logging"));
  parameter Boolean debugLogging = false "enables the FMU simulation logging" annotation(Dialog(tab = "FMI", group = "Enable logging"));
  constant String mimeType = "";
  constant Real timeout = 0.0;
  constant Boolean visible = false;
  constant Boolean interactive = false;
  parameter Real startTime = 0.0 "start time used to initialize the slave" annotation(Dialog(tab = "FMI", group = "Step time"));
  parameter Real stopTime = 1.0 "stop time used to initialize the slave" annotation(Dialog(tab = "FMI", group = "Step time"));
  parameter Real numberOfSteps = 500 annotation(Dialog(tab = "FMI", group = "Step time"));
  parameter Real communicationStepSize = (stopTime - startTime) / numberOfSteps "step size used by fmiDoStep" annotation(Dialog(tab = "FMI", group = "Step time"));
  constant Boolean stopTimeDefined = true;
  parameter Real n_cellule(start = 2.0, fixed = false) "number of parallel cells";
  parameter Real m_cellule(start = 3.0, fixed = false) "number of series cells";
  parameter Real nbr_warburg(start = 4.0, fixed = false) "number of Warburg cells";
  parameter Real k_1(start = 0.9, fixed = false) "parameter k1 of model";
  parameter Real k_2(start = 0.8, fixed = false) "parameter k2 of model";
  Modelica.Blocks.Interfaces.RealInput I_req(start = 5.0, fixed = false) "Request of current" annotation(Placement(transformation(extent = {{-120, 60}, {-100, 80}})));
  Modelica.Blocks.Interfaces.RealOutput soc(start = 0.0, fixed = false) "State Of Charge" annotation(Placement(transformation(extent = {{100, 60}, {120, 80}})));
  Modelica.Blocks.Interfaces.RealOutput voltage(start = 0.0, fixed = false) "Number of I reference node" annotation(Placement(transformation(extent = {{100, 35}, {120, 55}})));
  parameter Real E(start = 3.2, fixed = false) "E";
protected
  FMI1CoSimulation fmi1cs = FMI1CoSimulation(logLevel, fmuWorkingDir, "e_battery", debugLogging, fmuLocation, mimeType, timeout, visible, interactive, startTime, stopTimeDefined, stopTime);
  parameter Real flowInitialized(fixed = false);
  Real flowStep;
  Real fmi_input_I_req;
initial equation
  flowInitialized = fmi1Functions.fmi1InitializeSlave(fmi1cs, 1);
equation
  {soc, voltage} = fmi1Functions.fmi1GetReal(fmi1cs, {6.0, 7.0}, flowInitialized);
  {fmi_input_I_req} = fmi1Functions.fmi1SetReal(fmi1cs, {5.0}, {I_req});
  flowStep = fmi1Functions.fmi1DoStep(fmi1cs, time, communicationStepSize, true, flowInitialized);
protected
  class FMI1CoSimulation
    extends ExternalObject;

    function constructor
      input Integer fmiLogLevel;
      input String workingDirectory;
      input String instanceName;
      input Boolean debugLogging;
      input String fmuLocation;
      input String mimeType;
      input Real timeOut;
      input Boolean visible;
      input Boolean interactive;
      input Real tStart;
      input Boolean stopTimeDefined;
      input Real tStop;
      output FMI1CoSimulation fmi1cs;
   
      external "C" fmi1cs = FMI1CoSimulationConstructor_OMC(fmiLogLevel, workingDirectory, instanceName, debugLogging, fmuLocation, mimeType, timeOut, visible, interactive, tStart, stopTimeDefined, tStop) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"});
    end constructor;

    function destructor
      input FMI1CoSimulation fmi1cs;
   
      external "C" FMI1CoSimulationDestructor_OMC(fmi1cs) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"});
    end destructor;
  end FMI1CoSimulation;

  package fmi1Functions
    function fmi1InitializeSlave
      input FMI1CoSimulation fmi1cs;
      input Real preInitialized;
      output Real postInitialized = preInitialized;
   
      external "C" fmi1InitializeSlave_OMC(fmi1cs) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"});
    end fmi1InitializeSlave;

    function fmi1DoStep
      input FMI1CoSimulation fmi1cs;
      input Real currentCommunicationPoint;
      input Real communicationStepSize;
      input Boolean newStep;
      input Real preInitialized;
      output Real postInitialized = preInitialized;
   
      external "C" fmi1DoStep_OMC(fmi1cs, currentCommunicationPoint, communicationStepSize, newStep) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"});
    end fmi1DoStep;

    function fmi1GetReal
      input FMI1CoSimulation fmi1cs;
      input Real realValuesReferences[:];
      input Real inFlowStatesInput;
      output Real realValues[size(realValuesReferences, 1)];
   
      external "C" fmi1GetReal_OMC(fmi1cs, size(realValuesReferences, 1), realValuesReferences, inFlowStatesInput, realValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"});
    end fmi1GetReal;

    function fmi1SetReal
      input FMI1CoSimulation fmi1cs;
      input Real realValuesReferences[:];
      input Real realValues[size(realValuesReferences, 1)];
      output Real out_Values[size(realValuesReferences, 1)];
   
      external "C" fmi1SetReal_OMC(fmi1cs, size(realValuesReferences, 1), realValuesReferences, realValues, out_Values, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"});
    end fmi1SetReal;

    function fmi1GetInteger
      input FMI1CoSimulation fmi1cs;
      input Real integerValuesReferences[:];
      input Real inFlowStatesInput;
      output Integer integerValues[size(integerValuesReferences, 1)];
   
      external "C" fmi1GetInteger_OMC(fmi1cs, size(integerValuesReferences, 1), integerValuesReferences, inFlowStatesInput, integerValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"});
    end fmi1GetInteger;

    function fmi1SetInteger
      input FMI1CoSimulation fmi1cs;
      input Real integerValuesReferences[:];
      input Integer integerValues[size(integerValuesReferences, 1)];
      output Real out_Values[size(integerValuesReferences, 1)];
   
      external "C" fmi1SetInteger_OMC(fmi1cs, size(integerValuesReferences, 1), integerValuesReferences, integerValues, out_Values, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"});
    end fmi1SetInteger;

    function fmi1GetBoolean
      input FMI1CoSimulation fmi1cs;
      input Real booleanValuesReferences[:];
      input Real inFlowStatesInput;
      output Boolean booleanValues[size(booleanValuesReferences, 1)];
   
      external "C" fmi1GetBoolean_OMC(fmi1cs, size(booleanValuesReferences, 1), booleanValuesReferences, inFlowStatesInput, booleanValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"});
    end fmi1GetBoolean;

    function fmi1SetBoolean
      input FMI1CoSimulation fmi1cs;
      input Real booleanValuesReferences[:];
      input Boolean booleanValues[size(booleanValuesReferences, 1)];
      output Boolean out_Values[size(booleanValuesReferences, 1)];
   
      external "C" fmi1SetBoolean_OMC(fmi1cs, size(booleanValuesReferences, 1), booleanValuesReferences, booleanValues, out_Values, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"});
    end fmi1SetBoolean;

    function fmi1GetString
      input FMI1CoSimulation fmi1cs;
      input Real stringValuesReferences[:];
      input Real inFlowStatesInput;
      output String stringValues[size(stringValuesReferences, 1)];
   
      external "C" fmi1GetString_OMC(fmi1cs, size(stringValuesReferences, 1), stringValuesReferences, inFlowStatesInput, stringValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"});
    end fmi1GetString;

    function fmi1SetString
      input FMI1CoSimulation fmi1cs;
      input Real stringValuesReferences[:];
      input String stringValues[size(stringValuesReferences, 1)];
      output String out_Values[size(stringValuesReferences, 1)];
   
      external "C" fmi1SetString_OMC(fmi1cs, size(stringValuesReferences, 1), stringValuesReferences, stringValues, out_Values, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"});
    end fmi1SetString;
  end fmi1Functions;
  annotation(experiment(StartTime = 0.0, StopTime = 1.0, Tolerance = 0.0001));
  annotation(Icon(graphics = {Rectangle(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, fillColor = {240, 240, 240}, fillPattern = FillPattern.Solid, lineThickness = 0.5), Text(extent = {{-100, 40}, {100, 0}}, lineColor = {0, 0, 0}, textString = "%name"), Text(extent = {{-100, -50}, {100, -90}}, lineColor = {0, 0, 0}, textString = "V1.0")}));
end e_battery_cs_st_FMU;

Jul-06-15 15:23:47
FMU Co-simulation : Inputs/Outputs of FMU Block

For this example I used OpenModelica 1.9.1 Beta2 (r19512)
And with the latest version I had the same error.

Jul-06-15 14:36:33
FMU Co-simulation : Inputs/Outputs of FMU Block

model e_battery_cs_st_FMU
  constant String fmuLocation = "C:/Users/dimitri.tratkanov/Documents/FMU_SDK_MODIF/fmusdk_mna_ver22.06/fmu10/fmu/cs/e_battery.fmu";
  constant String fmuWorkingDir = "C:/Users/DIMITR~1.TRA/AppData/Local/Temp/OpenModelica/OMEdit";
  parameter Integer logLevel = 3 "log level used during the loading of FMU" annotation(Dialog(tab = "FMI", group = "Enable logging"));
  parameter Boolean debugLogging = false "enables the FMU simulation logging" annotation(Dialog(tab = "FMI", group = "Enable logging"));
  constant String mimeType = "";
  constant Real timeout = 0.0;
  constant Boolean visible = false;
  constant Boolean interactive = false;
  parameter Real StartTime = 0.0 "start time used to initialize the slave" annotation(Dialog(tab = "FMI", group = "Step time"));
  parameter Real StopTime = 1.0 "stop time used to initialize the slave" annotation(Dialog(tab = "FMI", group = "Step time"));
  parameter Real communicationStepSize = (StopTime - StartTime) / 500 "step size used by fmiDoStep" annotation(Dialog(tab = "FMI", group = "Step time"));
  constant Boolean stopTimeDefined = false;
  FMI1CoSimulation fmi1cs = FMI1CoSimulation(logLevel, fmuWorkingDir, "e_battery", debugLogging, fmuLocation, mimeType, timeout, visible, interactive, StartTime, stopTimeDefined, StopTime);
  parameter Real n_cellule(start = 2.0) "number of parallel cells";
  parameter Real m_cellule(start = 3.0) "number of series cells";
  parameter Real nbr_warburg(start = 4.0) "number of Warburg cells";
  parameter Real k_1(start = 0.9) "parameter k1 of model";
  parameter Real k_2(start = 0.8) "parameter k2 of model";
  Modelica.Blocks.Interfaces.RealInput I_req(start = 5.0) "Request of current" annotation(Placement(transformation(extent = {{-120,60},{-100,80}})));
  Modelica.Blocks.Interfaces.RealOutput soc(start = 0.0) "State Of Charge" annotation(Placement(transformation(extent = {{100,60},{120,80}})));
  Modelica.Blocks.Interfaces.RealOutput voltage(start = 0.0) "Number of I reference node" annotation(Placement(transformation(extent = {{100,35},{120,55}})));
  parameter Real E(start = 3.2) "E";
  Real flowControl;
  class FMI1CoSimulation
    extends ExternalObject;
    function constructor
      input Integer fmiLogLevel;
      input String workingDirectory;
      input String instanceName;
      input Boolean debugLogging;
      input String fmuLocation;
      input String mimeType;
      input Real timeOut;
      input Boolean visible;
      input Boolean interactive;
      input Real tStart;
      input Boolean stopTimeDefined;
      input Real tStop;
      output FMI1CoSimulation fmi1cs;

      external "C" fmi1cs = FMI1CoSimulationConstructor_OMC(fmiLogLevel,workingDirectory,instanceName,debugLogging,fmuLocation,mimeType,timeOut,visible,interactive,tStart,stopTimeDefined,tStop)       annotation(Library = {"OpenModelicaFMIRuntimeC","fmilib","shlwapi"});
    end constructor;
    function destructor
      input FMI1CoSimulation fmi1cs;

      external "C" FMI1CoSimulationDestructor_OMC(fmi1cs)       annotation(Library = {"OpenModelicaFMIRuntimeC","fmilib","shlwapi"});
    end destructor;
  end FMI1CoSimulation;
  package fmi1Functions
    function fmi1DoStep
      input FMI1CoSimulation fmi1cs;
      input Real currentCommunicationPoint;
      input Real communicationStepSize;
      input Boolean newStep;
      output Real outFlowControl;

      external "C" outFlowControl = fmi1DoStep_OMC(fmi1cs,currentCommunicationPoint,communicationStepSize,newStep)       annotation(Library = {"OpenModelicaFMIRuntimeC","fmilib","shlwapi"});
    end fmi1DoStep;
    function fmi1GetReal
      input FMI1CoSimulation fmi1cs;
      input Real realValuesReferences[:];
      input Real inFlowStatesInput;
      output Real realValues[size(realValuesReferences, 1)];

      external "C" fmi1GetReal_OMC(fmi1cs,size(realValuesReferences, 1),realValuesReferences,inFlowStatesInput,realValues,2)       annotation(Library = {"OpenModelicaFMIRuntimeC","fmilib","shlwapi"});
    end fmi1GetReal;
    function fmi1SetReal
      input FMI1CoSimulation fmi1cs;
      input Real realValuesReferences[:];
      input Real realValues[size(realValuesReferences, 1)];
      output Real out_Values[size(realValuesReferences, 1)];

      external "C" fmi1SetReal_OMC(fmi1cs,size(realValuesReferences, 1),realValuesReferences,realValues,out_Values,2)       annotation(Library = {"OpenModelicaFMIRuntimeC","fmilib","shlwapi"});
    end fmi1SetReal;
    function fmi1GetInteger
      input FMI1CoSimulation fmi1cs;
      input Real integerValuesReferences[:];
      input Real inFlowStatesInput;
      output Integer integerValues[size(integerValuesReferences, 1)];

      external "C" fmi1GetInteger_OMC(fmi1cs,size(integerValuesReferences, 1),integerValuesReferences,inFlowStatesInput,integerValues,2)       annotation(Library = {"OpenModelicaFMIRuntimeC","fmilib","shlwapi"});
    end fmi1GetInteger;
    function fmi1SetInteger
      input FMI1CoSimulation fmi1cs;
      input Real integerValuesReferences[:];
      input Integer integerValues[size(integerValuesReferences, 1)];
      output Real out_Values[size(integerValuesReferences, 1)];

      external "C" fmi1SetInteger_OMC(fmi1cs,size(integerValuesReferences, 1),integerValuesReferences,integerValues,out_Values,2)       annotation(Library = {"OpenModelicaFMIRuntimeC","fmilib","shlwapi"});
    end fmi1SetInteger;
    function fmi1GetBoolean
      input FMI1CoSimulation fmi1cs;
      input Real booleanValuesReferences[:];
      input Real inFlowStatesInput;
      output Boolean booleanValues[size(booleanValuesReferences, 1)];

      external "C" fmi1GetBoolean_OMC(fmi1cs,size(booleanValuesReferences, 1),booleanValuesReferences,inFlowStatesInput,booleanValues,2)       annotation(Library = {"OpenModelicaFMIRuntimeC","fmilib","shlwapi"});
    end fmi1GetBoolean;
    function fmi1SetBoolean
      input FMI1CoSimulation fmi1cs;
      input Real booleanValuesReferences[:];
      input Boolean booleanValues[size(booleanValuesReferences, 1)];
      output Real out_Values[size(booleanValuesReferences, 1)];

      external "C" fmi1SetBoolean_OMC(fmi1cs,size(booleanValuesReferences, 1),booleanValuesReferences,booleanValues,out_Values,2)       annotation(Library = {"OpenModelicaFMIRuntimeC","fmilib","shlwapi"});
    end fmi1SetBoolean;
    function fmi1GetString
      input FMI1CoSimulation fmi1cs;
      input Real stringValuesReferences[:];
      input Real inFlowStatesInput;
      output String stringValues[size(stringValuesReferences, 1)];

      external "C" fmi1GetString_OMC(fmi1cs,size(stringValuesReferences, 1),stringValuesReferences,inFlowStatesInput,stringValues,2)       annotation(Library = {"OpenModelicaFMIRuntimeC","fmilib","shlwapi"});
    end fmi1GetString;
    function fmi1SetString
      input FMI1CoSimulation fmi1cs;
      input Real stringValuesReferences[:];
      input String stringValues[size(stringValuesReferences, 1)];
      output Real out_Values[size(stringValuesReferences, 1)];

      external "C" fmi1SetString_OMC(fmi1cs,size(stringValuesReferences, 1),stringValuesReferences,stringValues,out_Values,2)       annotation(Library = {"OpenModelicaFMIRuntimeC","fmilib","shlwapi"});
    end fmi1SetString;
  end fmi1Functions;
  package fmiStatus
    constant Integer fmiOK = 0;
    constant Integer fmiWarning = 1;
    constant Integer fmiDiscard = 2;
    constant Integer fmiError = 3;
    constant Integer fmiFatal = 4;
    constant Integer fmiPending = 5;
  end fmiStatus;
equation
  {I_req} = fmi1Functions.fmi1SetReal(fmi1cs, {5.0}, {I_req});
  flowControl = fmi1Functions.fmi1DoStep(fmi1cs, time, communicationStepSize, true);
  {voltage} = fmi1Functions.fmi1GetReal(fmi1cs, {6.0}, flowControl);
  {soc} = fmi1Functions.fmi1GetReal(fmi1cs, {7.0}, flowControl);
end e_battery_cs_st_FMU;

Jul-06-15 14:28:49
FMU Co-simulation : Inputs/Outputs of FMU Block

Hello,
I have a problem with fmu co-simulation. The problem that there isn’t any call of fmiSetReal function from OpenModelica so that all of the input variables remain constant during simulation.
As I read from OpenModelica forum that (https://www.openmodelica.org/forum/defa … bles#p4313 ) currently OpenModelica doesn’t fully supports fmu co-simulation import.
However in this forum, Addel gives some solutions for fixing OpenModelica : he says that I can add SetReal function in the code. (https://www.openmodelica.org/forum/defa … bles#p4317 ).
I done this but I get another error : [:0:0-0:0] Error: Too many equations, over-determined system. The model has 4 equation(s) and 3 variable(s).
I would like to know if I need to add something special in order to fmiSetReal function will be called by OpenModelica or do you have another solutions for fmiSetReal function

Best regards,
Dimitri

Hello,

I have the problem with data exchange between fmu model and OpenModelica block. The FMU model I have built and imported from fmu sdk (https://www.qtronic.de/en/fmusdk.html)
The problem there isn’t any call of fmiSetReal function from OpenModelica so that all input variables remain constant during simulation. I also verified if others functions (example doStep, fmiGetReal etc) is called by OpenModelica and it is fine. All others function is called well by OpenModelica.
I would like to know if I need to add something special in order to fmiSetReal function will be called by OpenModelica.

Best regards,
Dimitri

  • Index
  • » Users
  • » dimitri.tratkanov
  • » Profile
You are here: