0

我正在编写一个程序,该程序从功能模型单元生成一个完整的 Modelica 模型。当我在 Dymola 中模拟模型时它工作得很好,但在 OpenModelica 中我得到了这个错误:

internal error reinit called with wrong args

触发事件后,我调用reinit(states, fmiGetContinuousStates(...));where以模型的新状态返回。fmiGetContinuousStates有人知道是什么导致了这个问题吗?

编辑:这是我的程序生成的模型。我现在有一个错误Error: type in operand to change must be simple type in component <NO COMPONENT>.

within ;
package BouncingBall 
 model BouncingBall_fmu
public
  constant String fmuInstanceName = "BouncingBall";
  constant String dll_path = "C:\\P418-FMIModelicaImport\\trunk\\fmu_path\\win32\\BouncingBall\\Resources\\Library\\binaries\\win32\\BouncingBall.dll";
  constant String GUID = "{7d4fc270-b710-45bd-abb1-b1aefef341ea}";
  parameter Boolean fmuLogger = true;
  parameter Real e = 0.700000 "coefficient of restitution";
  parameter Real g = 9.810000 "gravity acceleration";
  parameter Real h_start = 1.000000;
  Real h(start = h_start) "height of ball";
  Real der_h_ "der(height of ball)";
  parameter Real v_start = 0.000000;
  Real v(start = v_start) "velocity of ball";
  Real der_v_ "der(velocity of ball)";
  parameter Boolean flying_start = true;
  Boolean flying(start = flying_start) "true, the ball is flying";
  parameter Boolean impact_start = false;
  Boolean impact(start = impact_start);
  parameter Real v_new_start = 0.000000;
  Real v_new(start = v_new_start);
protected
  parameter Integer fmuNumberOfContinuousStates = 2;
  Real states[fmuNumberOfContinuousStates](each fixed=false)
    "The continuous states";
  parameter Integer fmuNumberOfEventIndicators = 4;
  Real eventIndicators[fmuNumberOfEventIndicators](each fixed = false)
    "Event indicators";
  Boolean domain_change[fmuNumberOfEventIndicators](each start = false)
    "Checks zero-crossing";
  fmiFunctions.FMU fmu = fmiFunctions.FMU(fmuInstanceName, fmuLogger, dll_path, GUID);
  parameter Real initNextTime(fixed = false);
  parameter Real startTime =  0.000000;

  Boolean newStates(start = false);
  Real tNext(start = initNextTime);
  Boolean stepEvent;
  Real states_set;
  Real states_and_inputs_set = states_set;
  Real der_states[fmuNumberOfContinuousStates];
  Real tempStates[fmuNumberOfContinuousStates](each start = 0);
   package fmiFunctions
     class FMU
      extends ExternalObject;
      function constructor "Initialize fmu model"
       extends Modelica.Icons.Function;
       input String instanceName;
       input Boolean loggingOn;
       input String dll_path;
       input String GUID;
       output FMU fmu;
      external"C" fmu = fmiInstantiateModel_wrapper(instanceName, loggingOn, dll_path, GUID)
       annotation (Include="#include <BouncingBall_wrappers.c>");
      end constructor;

      function destructor "Release storage of fmu model"
       extends Modelica.Icons.Function;
       input FMU fmu;
      external"C" fmiFreeModelInstance_wrapper(fmu);
       annotation (Include="#include <BouncingBall_wrappers.c>");
      end destructor;
     end FMU;

     function fmiSetTime
      input FMU fmu;
      input Real t;
     external"C" fmiSetTime_wrapper(fmu, t)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiSetTime;

     function fmiSetReal
      input FMU fmu;
      input Integer vr[:];
      input Real values[:];
      input Real inDummy;
      output Real outDummy = inDummy;
     external"C" fmiSetReal_wrapper(fmu, vr, size(vr,1), values)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiSetReal;

     function fmiInitialize
      input FMU fmu;
      output Real t;
     external"C" t = fmiInitialize_wrapper(fmu)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiInitialize;

     function fmiGetContinuousStates
      input FMU fmu;
      input Integer n;
      output Real x[n];
     external"C" fmiGetContinuousStates_wrapper(fmu, x, n)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiGetContinuousStates;

     function fmiGetNominalContinuousStates
      input FMU fmu;
      input Integer n;
      output Real x_nom[n];
     external"C" fmiGetNominalContinuousStates_wrapper(fmu, x_nom, n)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiGetNominalContinuousStates;

     function fmiGetReal
      input FMU fmu;
      input Integer vr[:];
      output Real values;
     external"C" fmiGetReal_wrapper(fmu, vr, size(vr,1), values)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiGetReal;

     function fmiGetInteger
      input FMU fmu;
      input Integer vr[:];
      output Integer values;
     external"C" fmiGetInteger_wrapper(fmu, vr, size(vr,1), values);
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiGetInteger;

     function fmiSetInteger
      input FMU fmu;
      input Integer vr[:];
      input Integer values[:];
     external"C" fmiSetInteger_wrapper(fmu, vr, size(vr,1), values);
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiSetInteger;

     function fmiGetString
      input FMU fmu;
      input Integer vr[:];
      output String values;
     external"C" fmiGetString_wrapper(fmu, vr, size(vr,1), values);
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiGetString;

     function fmiSetString
      input FMU fmu;
      input Integer vr[:];
      input Integer values[:];
     external"C" fmiSetString_wrapper(fmu, vr, size(vr,1), values);
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiSetString;

     function fmiGetDerivatives
      input FMU fmu;
      input Integer n;
      output Real derivatives[n];
     external"C" fmiGetDerivatives_wrapper(fmu, derivatives, n)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiGetDerivatives;

     function fmiSetContinuousStates
      input FMU fmu;
      input Real states[:];
      input Real inDummy;
      output Real outDummy = inDummy;
     external"C" fmiSetContinuousStates_wrapper(fmu, states, size(states,1))
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiSetContinuousStates;

     function fmiCompletedIntegratorStep
      input FMU fmu;
      input Real states_and_inputs_set;
      output Integer status;
     external"C" status = fmiCompletedIntegratorStep_wrapper(fmu)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiCompletedIntegratorStep;

     function fmiEventUpdate
      input FMU fmu;
      output Real nextTime;
      output Boolean newStates;
     external"C" newStates = fmiEventUpdate_wrapper(fmu, nextTime)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiEventUpdate;

     function fmiGetEventIndicators
      input FMU fmu;
      input Integer n;
      output Real eventIndicators[n];
     external"C" fmiGetEventIndicators_wrapper(fmu, eventIndicators, n)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiGetEventIndicators;

     function fmiGetBoolean
      input FMU fmu;
      input Integer vr[:];
      output Boolean values;
     external"C" fmiGetBoolean_wrapper(fmu, vr, size(vr,1), values)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiGetBoolean;

     function fmiSetBoolean
      input FMU fmu;
      input Integer vr[:];
      input Boolean values[:];
     external"C" fmiSetBoolean_wrapper(fmu, vr, size(vr,1), values)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiSetBoolean;

     function fmiSetDebugLogging
      input FMU fmu;
      input Boolean loggingOn;
     external"C" fmiSetDebugLogging_wrapper(fmu, loggingOn)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiSetDebugLogging;

     function fmiTerminate
      input FMU fmu;
     external"C" fmiTerminate_wrapper(fmu)
       annotation (Include="#include <BouncingBall_wrappers.c>");
     end fmiTerminate;
   end fmiFunctions;
 algorithm
  fmiFunctions.fmiSetTime(fmu, time);
  states_set := fmiFunctions.fmiSetContinuousStates(fmu, states, 1);
  der_states := fmiFunctions.fmiGetDerivatives(fmu, size(states,1));
  h := fmiFunctions.fmiGetReal(fmu, {33554432});
  der_h_ := fmiFunctions.fmiGetReal(fmu, {587202560});
  v := fmiFunctions.fmiGetReal(fmu, {33554433});
  der_v_ := fmiFunctions.fmiGetReal(fmu, {587202561});
  v_new := fmiFunctions.fmiGetReal(fmu, {637534210});
  flying :=fmiFunctions.fmiGetBoolean(fmu, {637534208});
  impact :=fmiFunctions.fmiGetBoolean(fmu, {637534209});
  eventIndicators := fmiFunctions.fmiGetEventIndicators(fmu, size(eventIndicators, 1));
  for i in 1:size(eventIndicators, 1) loop
   domain_change[i] := eventIndicators[i] > 0;
  end for;
  stepEvent := fmiFunctions.fmiCompletedIntegratorStep(fmu, states_and_inputs_set) > 0.5;

 equation
  der(states) = der_states;

  when cat(1, change(domain_change), {time >= pre(tNext) and pre(tNext) > 0, initial(), stepEvent}) then
   (tNext, newStates) = fmiFunctions.fmiEventUpdate(fmu);
  end when;

  when cat(1, change(domain_change), {time >= pre(tNext) and pre(tNext) > 0, initial(), stepEvent}) then
   if newStates then
     tempStates = fmiFunctions.fmiGetContinuousStates(fmu, fmuNumberOfContinuousStates);
   else
     tempStates = pre(tempStates);
   end if;
  end when;

  when cat(1, change(domain_change) and {newStates for i in 1:size(domain_change, 1)}, {time >= pre(tNext) and pre(tNext) > 0 and newStates, stepEvent and newStates}) then
    reinit(states, tempStates);
  end when;

 initial algorithm
  fmiFunctions.fmiSetReal(fmu, {16777216}, {e}, 1);
  fmiFunctions.fmiSetReal(fmu, {16777217}, {g}, 1);
  fmiFunctions.fmiSetReal(fmu, {33554432}, {h_start}, 1);
  fmiFunctions.fmiSetReal(fmu, {33554433}, {v_start}, 1);
  fmiFunctions.fmiSetBoolean(fmu, {637534208}, {flying_start});
  fmiFunctions.fmiSetBoolean(fmu, {637534209}, {impact_start});
  fmiFunctions.fmiSetReal(fmu, {637534210}, {v_new_start}, 1);
  fmiFunctions.fmiSetTime(fmu, startTime);
  initNextTime := fmiFunctions.fmiInitialize(fmu);
  states := fmiFunctions.fmiGetContinuousStates(fmu, size(states,1));
 end BouncingBall_fmu;


annotation (uses(Modelica(version="3.2")));
end BouncingBall;
4

0 回答 0