Opened 12 years ago

Closed 11 years ago

#2075 closed defect (duplicate)

FMU for co-simulation import warnings

Reported by: schteppe@… Owned by: Adeel Asghar
Priority: high Milestone: 1.9.1
Component: FMI Version: trunk
Keywords: fmi, fmu, co-simulation, cosimulation, import Cc:

Description

When I try importing my own FMU (for co-simulation), I get the following warning from the automatically generated FMI .mo-code.

Translation	14:02:50		0:0-0:0	System is over-determined in Equations 1:   if not initializationDone then
    pendulum_cs_st_FMU.fmiFunctions.fmi1InstantiateSlave(fmi, "pendulum", "/home/steffe/fmus/pendulum.fmu", "", 0.0, false, false, false);
    pendulum_cs_st_FMU.fmiFunctions.fmi1InitializeSlave(fmi, 0.0, false, 1.0);
    initializationDone := true;
  end if;
;
2:   initializationDone := true;
;

As I understood it, this is not my FMU implementations' fault, the error sits somewhere in the generated code. This is the full auto-generated FMI .mo code before I started editing it:

model pendulum_cs_st_FMU
  constant String fmuFile = "/home/steffe/fmus/pendulum.fmu";
  constant String fmuWorkingDir = "/tmp/OpenModelica/OMEdit";
  constant Integer fmiLogLevel = 3;
  constant Boolean debugLogging = false;
  constant String mimeType = "";
  constant Real timeout = 0.0;
  constant Boolean visible = false;
  constant Boolean interactive = false;
  constant Real communicationStepSize = 0.005;
  fmi1ImportInstance fmi = fmi1ImportInstance(context, fmuWorkingDir);
  fmi1ImportContext context = fmi1ImportContext(fmiLogLevel);
  Real z(start = 1.0, fixed = true);
  constant Boolean stopTimeDefined = false;
  Real flowControl;
  Boolean initializationDone(start = false);
initial algorithm
  if not initializationDone then 
    fmiFunctions.fmi1InstantiateSlave(fmi, "pendulum", fmuFile, mimeType, timeout, visible, interactive, debugLogging);
    fmiFunctions.fmi1InitializeSlave(fmi, 0.0, stopTimeDefined, 1.0);
    initializationDone:=true;
  else

  end if;
algorithm
  initializationDone:=true;
equation
  flowControl = fmiFunctions.fmi1DoStep(fmi, time, communicationStepSize, true);
  {z} = fmiFunctions.fmi1GetReal(fmi, {0.0}, flowControl);
algorithm
  when terminal() then
      fmiFunctions.fmi1TerminateSlave(fmi);  
  end when;
  annotation(experiment(StartTime = 0.0, StopTime = 1.0, Tolerance = 0.000001));
  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,20},{100,-20}}, lineColor = {0,0,0}, textString = "%name"),Text(extent = {{-100,80},{100,-80}}, lineColor = {0,0,0}, textString = "V1.0")}));
protected
  class fmi1ImportContext
    extends ExternalObject;
    function constructor
      input Integer fmiLogLevel;
      output fmi1ImportContext context;

      external "C" context = fmi1ImportContext_OMC(fmiLogLevel)       annotation(Library = {"omcruntime","fmilib"});
    end constructor;
    function destructor
      input fmi1ImportContext context;

      external "C" fmi1ImportFreeContext_OMC(context)       annotation(Library = {"omcruntime","fmilib"}); 
    end destructor;
  end fmi1ImportContext;
  class fmi1ImportInstance
    extends ExternalObject;
    function constructor
      input fmi1ImportContext context;
      input String tempPath;
      output fmi1ImportInstance fmi;

      external "C" fmi = fmi1ImportInstance_OMC(context,tempPath)       annotation(Library = {"omcruntime","fmilib"});
    end constructor;
    function destructor
      input fmi1ImportInstance fmi;

      external "C" fmi1ImportFreeInstance_OMC(fmi)       annotation(Library = {"omcruntime","fmilib"}); 
    end destructor;
  end fmi1ImportInstance;
  package fmiFunctions
    function fmi1InstantiateSlave
      input fmi1ImportInstance fmi;
      input String instanceName;
      input String fmuLocation;
      input String mimeType;
      input Real timeout;
      input Boolean visible;
      input Boolean interactive;
      input Boolean debugLogging;

      external "C" fmi1InstantiateSlave_OMC(fmi,instanceName,fmuLocation,mimeType,timeout,visible,interactive,debugLogging)       annotation(Library = {"omcruntime","fmilib"}); 
    end fmi1InstantiateSlave;
    function fmi1InitializeSlave
      input fmi1ImportInstance fmi;
      input Real tStart;
      input Boolean stopTimeDefined;
      input Real tStop;

      external "C" fmi1InitializeSlave_OMC(fmi,tStart,stopTimeDefined,tStop)       annotation(Library = {"omcruntime","fmilib"}); 
    end fmi1InitializeSlave;
    function fmi1DoStep
      input fmi1ImportInstance fmi;
      input Real currentCommunicationPoint;
      input Real communicationStepSize;
      input Boolean newStep;
      output Real outFlowControl;

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

      external "C" fmi1GetReal_OMC(fmi,size(realValuesReferences, 1),realValuesReferences,inFlowStatesInput,realValues)       annotation(Library = {"omcruntime","fmilib"}); 
    end fmi1GetReal;
    function fmi1SetReal
      input fmi1ImportInstance fmi;
      input Real realValuesReferences[:];
      input Real realValues[size(realValuesReferences, 1)];
      output Real outFlowParams;

      external "C" outFlowParams = fmi1SetReal_OMC(fmi,size(realValuesReferences, 1),realValuesReferences,realValues)       annotation(Library = {"omcruntime","fmilib"});
    end fmi1SetReal;
    function fmi1GetInteger
      input fmi1ImportInstance fmi;
      input Real integerValuesReferences[:];
      input Real inFlowStatesInput;
      output Integer integerValues[size(integerValuesReferences, 1)];

      external "C" fmi1GetInteger_OMC(fmi,size(integerValuesReferences, 1),integerValuesReferences,inFlowStatesInput,integerValues)       annotation(Library = {"omcruntime","fmilib"}); 
    end fmi1GetInteger;
    function fmi1SetInteger
      input fmi1ImportInstance fmi;
      input Real integerValuesReferences[:];
      input Integer integerValues[size(integerValuesReferences, 1)];
      output Real outFlowParams;

      external "C" outFlowParams = fmi1SetInteger_OMC(fmi,size(integerValuesReferences, 1),integerValuesReferences,integerValues)       annotation(Library = {"omcruntime","fmilib"});
    end fmi1SetInteger;
    function fmi1GetBoolean
      input fmi1ImportInstance fmi;
      input Real booleanValuesReferences[:];
      input Real inFlowStatesInput;
      output Boolean booleanValues[size(booleanValuesReferences, 1)];

      external "C" fmi1GetBoolean_OMC(fmi,size(booleanValuesReferences, 1),booleanValuesReferences,inFlowStatesInput,booleanValues)       annotation(Library = {"omcruntime","fmilib"}); 
    end fmi1GetBoolean;
    function fmi1SetBoolean
      input fmi1ImportInstance fmi;
      input Real booleanValuesReferences[:];
      input Boolean booleanValues[size(booleanValuesReferences, 1)];
      output Real outFlowParams;

      external "C" outFlowParams = fmi1SetBoolean_OMC(fmi,size(booleanValuesReferences, 1),booleanValuesReferences,booleanValues)       annotation(Library = {"omcruntime","fmilib"});
    end fmi1SetBoolean;
    function fmi1GetString
      input fmi1ImportInstance fmi;
      input Real stringValuesReferences[:];
      input Real inFlowStatesInput;
      output String stringValues[size(stringValuesReferences, 1)];

      external "C" fmi1GetString_OMC(fmi,size(stringValuesReferences, 1),stringValuesReferences,inFlowStatesInput,stringValues)       annotation(Library = {"omcruntime","fmilib"}); 
    end fmi1GetString;
    function fmi1SetString
      input fmi1ImportInstance fmi;
      input Real stringValuesReferences[:];
      input String stringValues[size(stringValuesReferences, 1)];
      output Real outFlowParams;

      external "C" outFlowParams = fmi1SetString_OMC(fmi,size(stringValuesReferences, 1),stringValuesReferences,stringValues)       annotation(Library = {"omcruntime","fmilib"});
    end fmi1SetString;
    function fmi1TerminateSlave
      input fmi1ImportInstance fmi;
      output Integer status;

      external "C" status = fmi1TerminateSlave_OMC(fmi)       annotation(Library = {"omcruntime","fmilib"});
    end fmi1TerminateSlave;
  end fmiFunctions;
  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;
end pendulum_cs_st_FMU;

Now, removing the variable initializationDone and all that has to do with it, things work out better. No warnings or errors. I instantiate and initialize the FMU in a new initial algorithm block instead. (I also had to remove the "fixed" flag from one of my FMU output variables but this is probably because of an error in my modelDescription.xml. Ignore this.).

This is the code after I "fixed" it:

model pendulum_cs_st_FMU
  constant String fmuFile = "/home/steffe/fmus/pendulum.fmu";
  constant String fmuWorkingDir = "/tmp/OpenModelica/OMEdit";
  constant Integer fmiLogLevel = 3;
  constant Boolean debugLogging = false;
  constant String mimeType = "";
  constant Real timeout = 0.0;
  constant Boolean visible = false;
  constant Boolean interactive = false;
  constant Real communicationStepSize = 0.005;
  fmi1ImportInstance fmi = fmi1ImportInstance(context, fmuWorkingDir);
  fmi1ImportContext context = fmi1ImportContext(fmiLogLevel);
  Real z(start = 1.0);
  constant Boolean stopTimeDefined = false;
  Real flowControl;
initial algorithm
  fmiFunctions.fmi1InstantiateSlave(fmi, "pendulum", fmuFile, mimeType, timeout, visible, interactive, debugLogging);
  fmiFunctions.fmi1InitializeSlave(fmi, 0.0, stopTimeDefined, 1.0);
equation
  flowControl = fmiFunctions.fmi1DoStep(fmi, time, communicationStepSize, true);
  {z} = fmiFunctions.fmi1GetReal(fmi, {0.0}, flowControl);
algorithm
  when terminal() then
      fmiFunctions.fmi1TerminateSlave(fmi);  
  end when;
  annotation(experiment(StartTime = 0.0, StopTime = 1.0, Tolerance = 0.000001));
  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,20},{100,-20}}, lineColor = {0,0,0}, textString = "%name"),Text(extent = {{-100,80},{100,-80}}, lineColor = {0,0,0}, textString = "V1.0")}));
protected
  class fmi1ImportContext
    extends ExternalObject;
    function constructor
      input Integer fmiLogLevel;
      output fmi1ImportContext context;

      external "C" context = fmi1ImportContext_OMC(fmiLogLevel)       annotation(Library = {"omcruntime","fmilib"});
    end constructor;
    function destructor
      input fmi1ImportContext context;

      external "C" fmi1ImportFreeContext_OMC(context)       annotation(Library = {"omcruntime","fmilib"}); 
    end destructor;
  end fmi1ImportContext;
  class fmi1ImportInstance
    extends ExternalObject;
    function constructor
      input fmi1ImportContext context;
      input String tempPath;
      output fmi1ImportInstance fmi;

      external "C" fmi = fmi1ImportInstance_OMC(context,tempPath)       annotation(Library = {"omcruntime","fmilib"});
    end constructor;
    function destructor
      input fmi1ImportInstance fmi;

      external "C" fmi1ImportFreeInstance_OMC(fmi)       annotation(Library = {"omcruntime","fmilib"}); 
    end destructor;
  end fmi1ImportInstance;
  package fmiFunctions
    function fmi1InstantiateSlave
      input fmi1ImportInstance fmi;
      input String instanceName;
      input String fmuLocation;
      input String mimeType;
      input Real timeout;
      input Boolean visible;
      input Boolean interactive;
      input Boolean debugLogging;

      external "C" fmi1InstantiateSlave_OMC(fmi,instanceName,fmuLocation,mimeType,timeout,visible,interactive,debugLogging)       annotation(Library = {"omcruntime","fmilib"}); 
    end fmi1InstantiateSlave;
    function fmi1InitializeSlave
      input fmi1ImportInstance fmi;
      input Real tStart;
      input Boolean stopTimeDefined;
      input Real tStop;

      external "C" fmi1InitializeSlave_OMC(fmi,tStart,stopTimeDefined,tStop)       annotation(Library = {"omcruntime","fmilib"}); 
    end fmi1InitializeSlave;
    function fmi1DoStep
      input fmi1ImportInstance fmi;
      input Real currentCommunicationPoint;
      input Real communicationStepSize;
      input Boolean newStep;
      output Real outFlowControl;

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

      external "C" fmi1GetReal_OMC(fmi,size(realValuesReferences, 1),realValuesReferences,inFlowStatesInput,realValues)       annotation(Library = {"omcruntime","fmilib"}); 
    end fmi1GetReal;
    function fmi1SetReal
      input fmi1ImportInstance fmi;
      input Real realValuesReferences[:];
      input Real realValues[size(realValuesReferences, 1)];
      output Real outFlowParams;

      external "C" outFlowParams = fmi1SetReal_OMC(fmi,size(realValuesReferences, 1),realValuesReferences,realValues)       annotation(Library = {"omcruntime","fmilib"});
    end fmi1SetReal;
    function fmi1GetInteger
      input fmi1ImportInstance fmi;
      input Real integerValuesReferences[:];
      input Real inFlowStatesInput;
      output Integer integerValues[size(integerValuesReferences, 1)];

      external "C" fmi1GetInteger_OMC(fmi,size(integerValuesReferences, 1),integerValuesReferences,inFlowStatesInput,integerValues)       annotation(Library = {"omcruntime","fmilib"}); 
    end fmi1GetInteger;
    function fmi1SetInteger
      input fmi1ImportInstance fmi;
      input Real integerValuesReferences[:];
      input Integer integerValues[size(integerValuesReferences, 1)];
      output Real outFlowParams;

      external "C" outFlowParams = fmi1SetInteger_OMC(fmi,size(integerValuesReferences, 1),integerValuesReferences,integerValues)       annotation(Library = {"omcruntime","fmilib"});
    end fmi1SetInteger;
    function fmi1GetBoolean
      input fmi1ImportInstance fmi;
      input Real booleanValuesReferences[:];
      input Real inFlowStatesInput;
      output Boolean booleanValues[size(booleanValuesReferences, 1)];

      external "C" fmi1GetBoolean_OMC(fmi,size(booleanValuesReferences, 1),booleanValuesReferences,inFlowStatesInput,booleanValues)       annotation(Library = {"omcruntime","fmilib"}); 
    end fmi1GetBoolean;
    function fmi1SetBoolean
      input fmi1ImportInstance fmi;
      input Real booleanValuesReferences[:];
      input Boolean booleanValues[size(booleanValuesReferences, 1)];
      output Real outFlowParams;

      external "C" outFlowParams = fmi1SetBoolean_OMC(fmi,size(booleanValuesReferences, 1),booleanValuesReferences,booleanValues)       annotation(Library = {"omcruntime","fmilib"});
    end fmi1SetBoolean;
    function fmi1GetString
      input fmi1ImportInstance fmi;
      input Real stringValuesReferences[:];
      input Real inFlowStatesInput;
      output String stringValues[size(stringValuesReferences, 1)];

      external "C" fmi1GetString_OMC(fmi,size(stringValuesReferences, 1),stringValuesReferences,inFlowStatesInput,stringValues)       annotation(Library = {"omcruntime","fmilib"}); 
    end fmi1GetString;
    function fmi1SetString
      input fmi1ImportInstance fmi;
      input Real stringValuesReferences[:];
      input String stringValues[size(stringValuesReferences, 1)];
      output Real outFlowParams;

      external "C" outFlowParams = fmi1SetString_OMC(fmi,size(stringValuesReferences, 1),stringValuesReferences,stringValues)       annotation(Library = {"omcruntime","fmilib"});
    end fmi1SetString;
    function fmi1TerminateSlave
      input fmi1ImportInstance fmi;
      output Integer status;

      external "C" status = fmi1TerminateSlave_OMC(fmi)       annotation(Library = {"omcruntime","fmilib"});
    end fmi1TerminateSlave;
  end fmiFunctions;
  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;
end pendulum_cs_st_FMU;

The problem with this code is that it doesn't produce any results when simulating. No plots appear, no plot variables are available etc, and there are no errors. I turn on FMU debugging before simulating but it does not produce any messages, the debug box does not even appear.

I'm using the nightly builds on Ubuntu 12.10.

Stefan

Change History (4)

comment:1 by schteppe@…, 12 years ago

Ok, I solved the latter problems: I now get my plots.
The autogenerated Modelica code inconsistency still remain though.

Stefan

comment:2 by schteppe@…, 12 years ago

Another quite important thing: The generated Modelica code does not have mechanisms for setting the values from OpenModelica context at all (fmiSetX is never even used)...

comment:3 by Martin Sjölund, 11 years ago

Milestone: 1.9.01.9.1

Postponed until 1.9.1

comment:4 by Adeel Asghar, 11 years ago

Resolution: duplicate
Status: newclosed

This ticket is based on old code generation. Refer to #2626.

Note: See TracTickets for help on using tickets.