quaternio
quaternio

Reputation: 97

Modelica Partial Test Model results initialisation error for a simple media

I am currently working on creating my own medium based on the TemplateMedium in the MSL media package.

The medium passes the medium test in MSL media utilities, but does not in a different model involving valves that I have created. In my model the medium density equation which depends on pressure and temperature was causing errors, so I decided to make a constant density medium.

Now this constant density medium does not even pass the original simple test. The medium initial pressure in a volume is equal to start_p + dp of pipe connected to it.

My guess is because the density and pressure being related was providing a way for the icnreased pressure from the dp to "escape" by changing the density and letting pressure be equal to p_start . I am now not sure how I can modify my medium to work.

The error message I get

The initialization problem is inconsistent due to the following equation: 
0 != -10000 = volume.p_start - volume.medium.p
package MyPackageSO

  package SimpleMedia "Simple media with constant density and linear enthalpy"
    extends Modelica.Media.Interfaces.PartialMedium(final mediumName = "Diesel", final substanceNames = {mediumName}, final singleState = false, final reducedX = true, final fixedX = true, Temperature(min = 273, max = 373, start = 298), p_default = 1e5, reference_p = 1e5, reference_T = 298, reference_X = {1}, AbsolutePressure(min = 1e-6, max = 3e8, start = 1e5),ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.pT);
      // Provide medium constants here
      constant SpecificHeatCapacity cp_const = 1350 "Constant specific heat capacity at constant pressure -- using approx value at 300K";
  
    redeclare model extends BaseProperties(final standardOrderComponents = true) "Base properties of medium"
      equation
        d = density(state);
        h = specificEnthalpy(state);
        u = h - p/d;
        MM = 0.025;
        R_s = 0;
        state.p = p;
        state.T = T;
    end BaseProperties;
  
    redeclare replaceable record ThermodynamicState "A selection of variables that uniquely defines the thermodynamic state"
      extends Modelica.Icons.Record;
      AbsolutePressure p "Absolute pressure of medium";
      Temperature T "Temperature of medium";
      annotation(
        Documentation(info = "<html>
    
    </html>"));
    end ThermodynamicState;
  
    redeclare function extends setState_pTX "Return thermodynamic state as function of p, T and composition X or Xi"
      extends Modelica.Icons.Function;
      algorithm
        state := ThermodynamicState(p = p, T = T);
      annotation(
        Inline = true);
    end setState_pTX;
    
    redeclare function extends setState_phX "Return thermodynamic state as function of p, h and composition X or Xi"
      extends Modelica.Icons.Function;
      algorithm
        state := ThermodynamicState(p = p, T = h / cp_const);
      annotation(
        Inline = true);
    end setState_phX;
      
    redeclare function extends pressure "Return the Pressure"
    algorithm
      p := state.p;
    end pressure;
    
    redeclare function extends temperature "Return temperature"
      input ThermodynamicState state "Thermodynamic state record";
      output Temperature T "Temperature";
    algorithm
      T := state.T;
    end temperature;
    
    redeclare function extends density "Return the density"
    algorithm
      d := 871;
    end density;
    
    redeclare function extends specificEnthalpy "Return specific enthalpy"
      extends Modelica.Icons.Function;
      input ThermodynamicState state "Thermodynamic state record";
      output SpecificEnthalpy h "Specific enthalpy";
      algorithm  
        h := cp_const * (state.T - reference_T);
      annotation(Documentation(info = "<html></html>"));
    end specificEnthalpy;      
    
        redeclare function extends specificInternalEnergy
      "Return specific internal energy"
      extends Modelica.Icons.Function;
    algorithm
      u := cp_const*(state.T - reference_T);
      annotation (Documentation(info="<html>
  <p>
  This function computes the specific internal energy of the fluid, but neglects the (small) influence of the pressure term p/d.
  </p>
  </html>"));
    end specificInternalEnergy;
    
    redeclare function extends dynamicViscosity "Return dynamic viscosity"
      algorithm
        eta := 0.014773467;
      annotation(
        Documentation(info = "<html>
    
    </html>"));
    end dynamicViscosity;
    
    redeclare function extends thermalConductivity "Return thermal conductivity"
      algorithm
        lambda := 0.1;
      annotation(
        Documentation(info = "<html>
    
    </html>"));
    end thermalConductivity;
    
    redeclare function extends specificHeatCapacityCp "Return specific heat capacity at constant pressure"
      algorithm
        cp := 1350;
      annotation(
        Documentation(info = "<html>
    
    </html>"));
    end specificHeatCapacityCp;
    
    redeclare function extends isentropicExponent "Return isentropic exponent"
        extends Modelica.Icons.Function;
    
      algorithm
        gamma := 1.16;
      annotation(
        Documentation(info = "<html>
    
    </html>"));
    end isentropicExponent;
    
    redeclare function extends velocityOfSound "Return velocity of sound"
        extends Modelica.Icons.Function;
      algorithm
        a := 1100;
      annotation(
        Documentation(info = "<html>
    
    </html>"));
    end velocityOfSound;
  
  end SimpleMedia;

  model TestOfMyMedium
    extends Modelica.Media.Examples.Utilities.PartialTestModel(redeclare package Medium = MyPackage.SimpleMedia, volume(p_start = 1e8), ambient(p_ambient = 1e8));
  end TestOfMyMedium;
end MyPackageSO;

Upvotes: 1

Views: 46

Answers (1)

quaternio
quaternio

Reputation: 97

Most components in the MSL Fluid assume that the media is compressible, the media presented in this question has constant density, causing the initialisation to not complete correctly.

Upvotes: 0

Related Questions