modelica-3rdparty / ExternalMedia

The ExternalMedia library provides a framework for interfacing external codes computing fluid properties to Modelica.Media-compatible component models.
53 stars 36 forks source link

Failed to differentiate the equation ExternalMedia.Media.CoolPropMedium.setState_ph_ #13

Closed slamer59 closed 1 year ago

slamer59 commented 6 years ago

Hello, I have a simple model using ExternalMedia which I'm not able to debug.

It maybe a pure modelica issue but I have no idea how to solve it.

It might be a duplicate of https://github.com/modelica/ModelicaStandardLibrary/issues/1575 and https://github.com/ibell/coolprop/issues/61

model CO2InternalCycleSimple1
  //   package Medium = Modelica.Media.IdealGases.SingleGases.CO2 "Medium model";
  //   package Medium = Modelica.Media.R134a "Medium model";
  //  package Medium = ExternalMedia.Examples.CO2CoolProp "Medium model";
  package Medium = Media.CO2 "Medium model";
  parameter Modelica.SIunits.AbsolutePressure p_sink=6000000;

  inner Modelica.Fluid.System system(
    p_ambient=p_sink,
    T_ambient=873.15,
    m_flow_start=1e-5,
    p_start=p_sink,
    T_start=573.15)
    annotation (Placement(visible=true, transformation(extent={{56,-6},{76,14}}, rotation=0)));
  Modelica.Fluid.Machines.SweptVolume cylinder1(
    redeclare package Medium = Medium,
    T_start=system.T_start,
    p_start=system.p_start,
    use_HeatTransfer=true,
    use_portsData=false,
    use_T_start=true,
    nPorts=1,
    pistonCrossArea=Modelica.Constants.pi,
    clearance=1e-4)
              annotation (smoothOrder=20, Placement(visible=true, transformation(extent={{-34,64},{-6,36}},
          rotation=0)));

  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor heatCapacitor1(C=500*25, T(start=773.15))
    annotation (Placement(visible=true, transformation(extent={{-54,50},{-34,70}}, rotation=0)));

  Modelica.Fluid.Sources.Boundary_ph  sink(
    p=p_sink,
    redeclare package Medium = Medium,
    nPorts=1)
    annotation (Placement(visible=true, transformation(extent={{98,-58},{78,-38}}, rotation=0)));
  Modelica.Mechanics.Translational.Components.Fixed
                                 fixed2(s0=1) annotation (Placement(
        transformation(extent={{-26,-10},{-6,10}})));
    annotation (Placement(transformation(extent={{-58,-74},{-38,-54}})));
initial equation 

equation 
  connect(heatCapacitor1.port, cylinder1.heatPort)
    annotation (Line(points={{-44,50},{-34,50}}, color={191,0,0}));
  // Ajout
  connect(sink.ports[1], cylinder1.ports[1])
    annotation (Line(points={{78,-48},{32,-48},{32,64},{-20,64}}, color={0,127,255}));
  connect(fixed2.flange, cylinder1.flange)
    annotation (Line(points={{-16,0},{-18,0},{-18,36},{-20,36}}, color={0,127,0}));
  annotation (
    smoothOrder=20,
    Diagram(coordinateSystem(extent={{-100,-100},{100,100}}, preserveAspectRatio=false)),
    Icon(coordinateSystem(extent={{-100,-100},{100,100}})),
    experiment(
      Interval=0.0001,
      Tolerance=1e-05,
      __Dymola_Algorithm="Radau"));
end CO2InternalCycleSimple1;

CO2 media is defined as:

package CO2 "Model for CO2"
  extends ExternalMedia.Media.CoolPropMedium(
    mediumName="CarbonDioxide",
    substanceNames={"CO2"},
    ThermoStates=Modelica.Media.Interfaces.Choices.IndependentVariables.ph,
    SpecificEnthalpy(start=1e5),
    AbsolutePressure(start=1e5));
  annotation (Documentation(info="<html>
http://www.coolprop.org/coolprop/Tabular.html
</html>"));
end CO2;
jowr commented 3 years ago

Maybe you could tell us what the problem is? Do you get an error message? Does it crash?

If the title of this post is the error message, you can tell from it that you are using incompatible state variables. I seem to remember that the Modelica.Fluid.Machines.SweptVolume model is built around a mass and energy balance that uses density and internal energy as state variables. However, you explicitly selected pressure and enthalpy which forces the Modelica compiler to try and rearrange equations leading to the missing derivative problem...

casella commented 2 years ago

@slamer59 what about @jowr's comments? Are you still interested in this issue?

Thanks

casella commented 1 year ago

Didn't get any feedback. @slamer59 please reopen if you are still interested.