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

Issue with external function in OpenModelica

Issue with external function in OpenModelica

Hi,

I tried to use an external function in OpenModelica but my simple model does not translate.
When I try to translate model MotorExtFunc1D from the package below I get the following error message:

Translation    10:01:04        0:0-0:0    Internal error Inverse Algorithm needs to be solved for in   extinterface1d1.torque := $_start(extinterface1d1.torque);
  extinterface1d1.torque := ExtFuncTest.ExtFunc1D(extinterface1d1.interfaceName,time,extinterface1d1.w);
. This is not implemented yet.


Strange enough does the model RotationExtFunc1D translate without problems.
Any hints?

Alexander

Here the package (attaching it didn't work):
package ExtFuncTest
  model SimpleDCMotor
    Modelica.Electrical.Analog.Basic.Resistor resistor1 annotation(Placement(visible = true, transformation(origin = {-20.4842,54.0037}, extent = {{-12,-12},{12,12}}, rotation = 0)));
    Modelica.Electrical.Analog.Basic.Inductor inductor1 annotation(Placement(visible = true, transformation(origin = {18.622,52.8864}, extent = {{-12,-12},{12,12}}, rotation = 0)));
    Modelica.Electrical.Analog.Basic.Ground ground1 annotation(Placement(visible = true, transformation(origin = {3.72439,-18.2495}, extent = {{-12,-12},{12,12}}, rotation = 0)));
    Modelica.Electrical.Analog.Basic.EMF emf annotation(Placement(visible = true, transformation(origin = {49.5345,17.5047}, extent = {{-12,-12},{12,12}}, rotation = 0)));
    //  annotation(Icon(graphics = {Rectangle(rotation = 0, lineColor = {0,0,255}, fillColor = {170,170,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.HorizontalCylinder, lineThickness = 0.25, extent = {{71.5084,19.3669},{1.11732,-5.95903}}),Rectangle(rotation = 0, lineColor = {0,0,255}, fillColor = {85,0,0}, pattern = LinePattern.Solid, fillPattern = FillPattern.Solid, lineThickness = 0.25, extent = {{1.8622,44.3203},{-87.8957,-48.0447}}),Polygon(points = {{-59.9628,-47.6723},{-69.6462,-58.1006},{-12.2905,-58.1006},{-24.2086,-47.6723},{-59.9628,-47.6723}}, rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,0}, pattern = LinePattern.Solid, fillPattern = FillPattern.Solid, lineThickness = 0.25)}), Diagram());
    annotation(Diagram(), Icon(graphics = {Rectangle(rotation = 0, lineColor = {0,0,255}, fillColor = {170,170,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.HorizontalCylinder, lineThickness = 0.25, extent = {{77.1429,23.6735},{-8.97959,-8.16327}}),Rectangle(rotation = 0, lineColor = {0,0,0}, fillColor = {85,85,0}, pattern = LinePattern.Solid, fillPattern = FillPattern.HorizontalCylinder, lineThickness = 0.25, extent = {{-8.57143,44.898},{-89.3878,-28.9796}}),Polygon(points = {{-71.4286,-28.5714},{-80.4082,-48.1633},{-17.1429,-48.1633},{-25.7143,-28.5714},{-71.4286,-28.5714}}, rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,0}, pattern = LinePattern.Solid, fillPattern = FillPattern.Solid, lineThickness = 0.25)}));
    Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b annotation(Placement(visible = true, transformation(origin = {88.2682,7.44879}, extent = {{-12,-12},{12,12}}, rotation = 0), iconTransformation(origin = {88.2682,7.44879}, extent = {{-12,-12},{12,12}}, rotation = 0)));
    Modelica.Electrical.Analog.Sources.ConstantVoltage constantvoltage1(V = 1) annotation(Placement(visible = true, transformation(origin = {-50.2793,16.3873}, extent = {{-12,12},{12,-12}}, rotation = -90)));
  equation
    connect(flange_b,emf.flange) annotation(Line(points = {{98.6965,32.0298},{61.4525,32.0298},{61.4525,17.5047},{61.5345,17.5047}}));
    connect(constantvoltage1.p,resistor1.p) annotation(Line(points = {{-50.2793,28.3873},{-33.1471,28.3873},{-33.1471,54.0037},{-32.4842,54.0037}}));
    connect(constantvoltage1.n,ground1.p) annotation(Line(points = {{-50.2793,4.38734},{4.09683,4.38734},{4.09683,-6.24953},{3.72439,-6.24953}}));
    connect(emf.n,ground1.p) annotation(Line(points = {{49.5345,5.50466},{49.5345,-5.95903},{3.72439,-5.95903},{3.72439,-6.24953}}));
    connect(inductor1.n,emf.p) annotation(Line(points = {{30.622,52.8864},{49.9069,52.8864},{49.9069,29.5047},{49.5345,29.5047}}));
    connect(resistor1.n,inductor1.p) annotation(Line(points = {{-8.48417,54.0037},{6.70391,54.0037},{6.70391,52.8864},{6.62197,52.8864}}));
  end SimpleDCMotor;
  function ExtFunc1D
    input String name "Interface name";
    input Real timeIn "Current time";
    input Real w "Angular velocity";
    output Real t "Torque/moment vector";

    external "C" calc_tlm_force(name,timeIn,w,t)     annotation(Include = "#include<tlmforce.h>", Library = "tlmmodelica");
  end ExtFunc1D;
  model MotorExtFunc1D
    ExtFuncTest.SimpleDCMotor simpledcmotor1 annotation(Placement(visible = true, transformation(origin = {-73.8318,10.2804}, extent = {{-12,-12},{12,12}}, rotation = 0)));
    ExtFuncTest.ExtInterface1D extinterface1d1 annotation(Placement(visible = true, transformation(origin = {17.0561,8.64486}, extent = {{-12,-12},{12,12}}, rotation = 0)));
  equation
    connect(simpledcmotor1.flange_b,extinterface1d1.flange_b) annotation(Line(points = {{-63.2396,11.1742},{8.17757,11.1742},{8.17757,8.4126},{7.84317,8.4126}}));
  end MotorExtFunc1D;
  model RotationExtFunc1D
    Modelica.Mechanics.Rotational.Sources.ConstantSpeed constantspeed1 annotation(Placement(visible = true, transformation(origin = {-57.9439,2.80374}, extent = {{-12,-12},{12,12}}, rotation = 0)));
    ExtFuncTest.ExtInterface1D extinterface1d1 annotation(Placement(visible = true, transformation(origin = {27.1028,3.73832}, extent = {{-12,-12},{12,12}}, rotation = 0)));
  equation
    connect(constantspeed1.flange,extinterface1d1.flange_b) annotation(Line(points = {{-45.9439,2.80374},{17.757,2.80374},{17.757,3.50606},{17.8899,3.50606}}));
  end RotationExtFunc1D;
  model ExtInterface1D
    annotation(Diagram(), Icon(graphics = {Rectangle(rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.HorizontalCylinder, lineThickness = 0.25, extent = {{-29.5484,42.5806},{96.9032,-45.8065}}),Text(rotation = 0, lineColor = {0,0,0}, fillColor = {0,0,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.None, lineThickness = 0.25, extent = {{-6.32258,18.0645},{74.9677,-20.6452}}, textString = "ExtFunc", fontSize = 28),Line(points = {{-63.2258,-2.58065},{-28.3871,-2.58065}}, rotation = 0, color = {0,0,255}, pattern = LinePattern.Solid, thickness = 5)}));
    Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b annotation(Placement(visible = true, transformation(origin = {-76.7742,-1.93548}, extent = {{-12,-12},{12,12}}, rotation = 0), iconTransformation(origin = {-76.7742,-1.93548}, extent = {{-12,-12},{12,12}}, rotation = 0)));
    parameter String interfaceName = "tlm";
    Real w(start = 0.0);
    Real torque(start = 0.0);
  equation
    w = der(flange_b.phi);
    flange_b.tau = -torque;
  algorithm
    torque:=ExtFunc1D(interfaceName, time, w);
  end ExtInterface1D;
end ExtFuncTest;

There are 0 guests and 0 other users also viewing this topic
You are here: