Opened 10 years ago

Closed 10 years ago

#2768 closed defect (fixed)

checkModel error with function handles

Reported by: e1026754@… Owned by: Martin Sjölund
Priority: high Milestone: 1.9.1
Component: Frontend Version: trunk
Keywords: checkModel Cc:

Description

When executing checkModel() on the following model it returns the following error message even though simulation of the model works fine. I am running the nightly build from Aug 3rd 2014.

Error message:

"[C:/OpenModelica1.9.1Nightly/lib/omlibrary/Modelica 3.2.1/Math/Nonlinear.mo:405:3-423:28:writable] Warning: Forcing full instantiation of partial class partialScalarFunction during checkModel.

[<interactive>:19:5-19:134:writable] Error: Type mismatch for positional argument 1 in Modelica.Math.Nonlinear.solveOneNonlinearEquation(f=function MetalHydrideStorage.M.equilibriumLoadingAdsorptionDummy(.MetalHydrideStorage.M.State(#(s.T), #(s.p), #(s.omega)))). The argument has type:
  .MetalHydrideStorage.M.equilibriumLoadingAdsorptionDummy<function>(#Real u) => #Real
expected type: .Modelica.Math.Nonlinear.Interfaces.partialScalarFunction<function>(Real u) => Real
Error: Error occurred while flattening model MetalHydrideStorage.M
"

Code:

model M
  import SI = Modelica.SIunits;

  record State
    SI.Temperature T;
    SI.AbsolutePressure p;
    Real omega;
  end State;

  function equilibriumPressureAdsorption
    input State s;
    output SI.Pressure p_eq;
  protected
    Real p1, p2;
    constant Real alpha = 0.5;
    constant Real a1 = -4.884, a2 = -2374.7, a3 = 3.4129 * 10 ^ (-3), a4 = 48.816, a5 = -50.404, a6 = 22.711, a7 = -7.9717, a8 = 1.233;
    constant Real b1 = -452.34, b2 = 15.522, b3 = 4.0954, b4 = -1.3222 * 10 ^ (-2), b5 = 1.4406 * 10 ^ (-5);
    Real omega = s.omega * 100;
  algorithm
    p1 := exp(a1 + a2 / s.T + a3 * s.T + a4 * omega ^ alpha + a5 * omega + a6 * omega ^ 2 + a7 * omega ^ 3 + a8 * omega ^ 4);
    p2 := exp(b1 + b2 * omega + b3 * s.T + b4 * s.T ^ 2 + b5 * s.T ^ 3);
    p_eq := p1 + p2;
  end equilibriumPressureAdsorption;

  function equilibriumLoadingAdsorption "Uses modelica's root finding algorithm to calculate the equilibrium loading based on the equilibrium pressure function"
    input State s;
    output Real omega_eq;
  algorithm
    omega_eq := Modelica.Math.Nonlinear.solveOneNonlinearEquation(function equilibriumLoadingAdsorptionDummy(s = s), 0, 0.02, 1e-006);
  end equilibriumLoadingAdsorption;

  function equilibriumLoadingAdsorptionDummy
    extends Modelica.Math.Nonlinear.Interfaces.partialScalarFunction;
    input State s;
  algorithm
    y := equilibriumPressureAdsorption(State(T = s.T, p = s.p, omega = u)) - s.p;
  end equilibriumLoadingAdsorptionDummy;

  Real r = equilibriumLoadingAdsorption(State(time * 100 + 273.15, 50, 0.01));
  Real b = equilibriumPressureAdsorption(State(time * 100 + 273.15, 50, 0.01));
  annotation(uses(Modelica(version = "3.2.1")));

end M;

Change History (2)

comment:1 by Martin Sjölund, 10 years ago

Component: UnknownFrontend
Owner: changed from somebody to Martin Sjölund
Status: newaccepted

comment:2 by Martin Sjölund, 10 years ago

Resolution: fixed
Status: acceptedclosed

Fixed in r21743.

Note: See TracTickets for help on using tickets.