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
  • » tgb
  • » Profile

Posts

Posts

In CompilerFrontEnd/Static.mo there is a function called evalExternalObjectInput that evaluates the inputs to externalObject constructors at compile time.

The function documentation states:

"External Object requires us to construct before initialization for good results. So try to evaluate the inputs."


The problem I'm having is that it is evaluating parametric inputs to an externalObject and the final c code ends up with a numeric literal instead of a reference to the parameter.  So the only way I can change the parameter value is by recompiling.

For typical cases the compile time is about 25 seconds but the simulation time less than 5 seconds.  I need to run 100s of cases with different parameters so it is running far slower than it could if I could reuse the executable.

I've recompiled OMC with the six calls to evalExternalObjectInput in Static.mo removed and it worked fine.  The parameter references were written into the c code and I could change them without needing to recompile for each simulation.

So my questions are:

1.  Why is this evaluation needed?

2.  If it is needed shouldn't it be restricted to inputs of "constant" variability only? (so "parameter" variability inputs are not evaluated).


Thanks

Tom


Dec-04-13 03:49:48
Incorrect fluid property calculations when using multiple media.
Category: Developer

In the package below (sorry, could not get attachments to work) there are 2 test cases, Working and Not_Working.

They each have 2 fluid streams, 1 using air and 1 using water.  In the Not_Working case the h_outflow from the water_inlet is incorrect.  Instead it is coming out at the same value as air_inlet.

In the Working case the only difference is that water_inlet is an instance of a class that extends from MassFlowSource_T and gives this type a different name -> MassFlowSource_T_ALT.

If you look in OMC_Fluid_Bug_No_Working_functions.c you can see that there is only a single function:

omc_Modelica_Fluid_Sources_MassFlowSource__T_Medium_specificEnthalpy__pTX

which uses the equation _h = (1005.45 * (-298.15 + _T)); (this is correct for air)

If you look in OMC_Fluid_Bug_Working_functions.c you can see the above function and the additional function:

omc_OMC__Fluid__Bug_MassFlowSource__T__ALT_Medium_specificEnthalpy__pTX

which uses the equation   _h = (4184.0 * (-273.15 + _T)); (this is correct for water.



This was ran with r18381 but I get similar results with r17628.



Is this a known bug?  Is there any fix planned?


Thanks

Tom


######################################################################

within ;
package OMC_Fluid_Bug
  "Demonstrate incorrect OMC behaviour with multiple fluid components"
  model Not_Working "Gives wrong outlet enthalpy for the water_inlet"

    inner Modelica.Fluid.System system
      annotation (Placement(transformation(extent={{-80,60},{-60,80}})));
    Modelica.Fluid.Sources.MassFlowSource_T air_inlet(
      nPorts=1,
      redeclare package Medium = Modelica.Media.Air.SimpleAir,
      m_flow=1) annotation (Placement(transformation(extent={{-80,0},{-60,20}})));
    Modelica.Fluid.Fittings.SimpleGenericOrifice air_orifice(
      diameter=0.01,
      use_zeta=false,
      m_flow_nominal=1,
      redeclare package Medium = Modelica.Media.Air.SimpleAir,
      zeta=1,
      dp_nominal=100000)
      annotation (Placement(transformation(extent={{-40,0},{-20,20}})));
    Modelica.Fluid.Sources.Boundary_pT air_sink(nPorts=1, redeclare package
        Medium = Modelica.Media.Air.SimpleAir) annotation (Placement(
          transformation(
          extent={{-10,-10},{10,10}},
          rotation=180,
          origin={10,10})));
    Modelica.Fluid.Sources.MassFlowSource_T water_inlet(
      nPorts=1,
      redeclare package Medium =
          Modelica.Media.Water.ConstantPropertyLiquidWater,
      m_flow=1)
      annotation (Placement(transformation(extent={{-80,-40},{-60,-20}})));

    Modelica.Fluid.Fittings.SimpleGenericOrifice water_orifice(
      diameter=0.01,
      use_zeta=false,
      m_flow_nominal=1,
      redeclare package Medium =
          Modelica.Media.Water.ConstantPropertyLiquidWater,
      zeta=1,
      dp_nominal=100000)
      annotation (Placement(transformation(extent={{-40,-40},{-20,-20}})));

    Modelica.Fluid.Sources.Boundary_pT water_sink(nPorts=1, redeclare package
        Medium = Modelica.Media.Water.ConstantPropertyLiquidWater) annotation (
        Placement(transformation(
          extent={{-10,-10},{10,10}},
          rotation=180,
          origin={10,-30})));
  equation
    connect(air_orifice.port_a, air_inlet.ports[1]) annotation (Line(
        points={{-40,10},{-60,10}},
        color={0,127,255},
        smooth=Smooth.None));
    connect(air_orifice.port_b, air_sink.ports[1]) annotation (Line(
        points={{-20,10},{0,10}},
        color={0,127,255},
        smooth=Smooth.None));
    connect(water_orifice.port_a, water_inlet.ports[1]) annotation (Line(
        points={{-40,-30},{-60,-30}},
        color={0,127,255},
        smooth=Smooth.None));
    connect(water_orifice.port_b, water_sink.ports[1]) annotation (Line(
        points={{-20,-30},{0,-30}},
        color={0,127,255},
        smooth=Smooth.None));
    annotation (Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,
              -100},{100,100}}), graphics));
  end Not_Working;
  annotation (uses(Modelica(version="3.2.1")));
  model MassFlowSource_T_ALT
    "Identical to MassFlowSource_T but with a different name"
    extends Modelica.Fluid.Sources.MassFlowSource_T;
    annotation (Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,
              -100},{100,100}}), graphics={Text(
            extent={{-100,-100},{100,-20}},
            lineColor={0,255,0},
            textString="ALT")}));
  end MassFlowSource_T_ALT;

  model Working "Gives correct outlet enthalpy for the water_inlet"

    inner Modelica.Fluid.System system
      annotation (Placement(transformation(extent={{-80,60},{-60,80}})));
    Modelica.Fluid.Sources.MassFlowSource_T air_inlet(
      nPorts=1,
      redeclare package Medium = Modelica.Media.Air.SimpleAir,
      m_flow=1) annotation (Placement(transformation(extent={{-80,0},{-60,20}})));
    Modelica.Fluid.Fittings.SimpleGenericOrifice air_orifice(
      diameter=0.01,
      use_zeta=false,
      m_flow_nominal=1,
      redeclare package Medium = Modelica.Media.Air.SimpleAir,
      zeta=1,
      dp_nominal=100000)
      annotation (Placement(transformation(extent={{-40,0},{-20,20}})));
    Modelica.Fluid.Sources.Boundary_pT air_sink(nPorts=1, redeclare package
        Medium = Modelica.Media.Air.SimpleAir) annotation (Placement(
          transformation(
          extent={{-10,-10},{10,10}},
          rotation=180,
          origin={10,10})));
    MassFlowSource_T_ALT                    water_inlet(
      nPorts=1,
      redeclare package Medium =
          Modelica.Media.Water.ConstantPropertyLiquidWater,
      m_flow=1)
      annotation (Placement(transformation(extent={{-80,-40},{-60,-20}})));

    Modelica.Fluid.Fittings.SimpleGenericOrifice water_orifice(
      diameter=0.01,
      use_zeta=false,
      m_flow_nominal=1,
      redeclare package Medium =
          Modelica.Media.Water.ConstantPropertyLiquidWater,
      zeta=1,
      dp_nominal=100000)
      annotation (Placement(transformation(extent={{-40,-40},{-20,-20}})));

    Modelica.Fluid.Sources.Boundary_pT water_sink(nPorts=1, redeclare package
        Medium = Modelica.Media.Water.ConstantPropertyLiquidWater) annotation (
        Placement(transformation(
          extent={{-10,-10},{10,10}},
          rotation=180,
          origin={10,-30})));
  equation
    connect(air_orifice.port_a, air_inlet.ports[1]) annotation (Line(
        points={{-40,10},{-60,10}},
        color={0,127,255},
        smooth=Smooth.None));
    connect(air_orifice.port_b, air_sink.ports[1]) annotation (Line(
        points={{-20,10},{0,10}},
        color={0,127,255},
        smooth=Smooth.None));
    connect(water_orifice.port_a, water_inlet.ports[1]) annotation (Line(
        points={{-40,-30},{-60,-30}},
        color={0,127,255},
        smooth=Smooth.None));
    connect(water_orifice.port_b, water_sink.ports[1]) annotation (Line(
        points={{-20,-30},{0,-30}},
        color={0,127,255},
        smooth=Smooth.None));
    annotation (Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,
              -100},{100,100}}), graphics));
  end Working;
end OMC_Fluid_Bug;

Thanks, that worked.

Tom

Is it possible to add other libraries in OMEdit as well as the msl?  Maybe I'm missing something but I just can't see where to do it.

Tom

  • Index
  • » Users
  • » tgb
  • » Profile
You are here: