Modelica.Media.Examples.TwoPhaseWater

extension of the StandardWater package

Information


Example: TwoPhaseWater

The TwoPhaseWater package demonstrates how to extend the parsimonius BaseProperties with a minimal set of properties from the standard water package with most properties that are needed in two-phase situations. The model also demonstrates how to compute additional  properties for the medium model. In this scenario, that builds a new medium model with many more properties than the default, the standard BaseProperties is used as a basis. For additional properties, a user has to:
  1. Declare a new variable of the wanted type, e.g., "DynamicViscosity eta".
  2. Compute that variable by calling the function form the package, e.g., eta = dynamicViscosity(state). Note that the instance of ThermodynamicState is used as an input to the function. This instance "state" is declared in PartialMedium and thus available in every medium model. A user does not have to know what actual variables are required to compute the dynamic viscosity, because the state instance is guaranteed to contain what is needed. 
  3. Attention: Many properties are not well defined in the two phase region and the functions might return undesired values if called there. It is the user's responsibility  to take care of such ituations. The example uses one of several possible models to compute an averaged viscosity for two-phase flows.
In two phase models, properties are often needed on the phase boundary just outside the two phase dome, right on the border.. To compute the thermodynamic state there, two auxiliary functions are provided: setDewState(sat) and setBubbleState(sat). They take an instance of SaturationProperties as input. By default they are in one-phase, but with the optional phase argument set to 2, the output is forced to be just inside the phase boundary. This is only needed when derivatives like cv are computed with are different on both sides of the boundaries. The ususal steps to compute properties on the phase boundary are:
  1. Declare an instance of ThermodynamicState, e.g., "ThermodynamicState  dew".
  2. Compute the state, using an instance of SaturationProperties, e.g., dew = setDewState(sat)
  3. Compute properties on the phase boundary to your full desire, e.g., "cp_d = specificHeatCapacityCp(dew)".

The sample model TestTwoPhaseStates test the extended properties

The same procedure can be used to compute properties at other state points, e.g., when an isentropic reference state is computed.

Extends from Modelica.Media.Water.StandardWater (Water using the IF97 standard, explicit in p and h. Recommended for most applications).

Package Content

NameDescription
Modelica.Media.Examples.TwoPhaseWater.BaseProperties BaseProperties Make StandardWater.BaseProperties non replaceable in order that inheritance is possible in model ExtendedProperties
Modelica.Media.Examples.TwoPhaseWater.ExtendedProperties ExtendedProperties plenty of two-phase properties
Modelica.Media.Examples.TwoPhaseWater.TestTwoPhaseStates TestTwoPhaseStates Test the above model
Inherited
Modelica.Media.Water.WaterIF97_base.ThermodynamicState ThermodynamicState thermodynamic state
ph_explicittrue if explicit in pressure and specific enthalpy
dT_explicittrue if explicit in density and temperature
pT_explicittrue if explicit in pressure and temperature
Modelica.Media.Water.WaterIF97_base.density_ph density_ph Computes density as a function of pressure and specific enthalpy
Modelica.Media.Water.WaterIF97_base.temperature_ph temperature_ph Computes temperature as a function of pressure and specific enthalpy
Modelica.Media.Water.WaterIF97_base.temperature_ps temperature_ps Compute temperature from pressure and specific enthalpy
Modelica.Media.Water.WaterIF97_base.density_ps density_ps Computes density as a function of pressure and specific enthalpy
Modelica.Media.Water.WaterIF97_base.pressure_dT pressure_dT Computes pressure as a function of density and temperature
Modelica.Media.Water.WaterIF97_base.specificEnthalpy_dT specificEnthalpy_dT Computes specific enthalpy as a function of density and temperature
Modelica.Media.Water.WaterIF97_base.specificEnthalpy_pT specificEnthalpy_pT Computes specific enthalpy as a function of pressure and temperature
Modelica.Media.Water.WaterIF97_base.specificEnthalpy_ps specificEnthalpy_ps Computes specific enthalpy as a function of pressure and temperature
Modelica.Media.Water.WaterIF97_base.density_pT density_pT Computes density as a function of pressure and temperature
Modelica.Media.Water.WaterIF97_base.setDewState setDewState set the thermodynamic state on the dew line
Modelica.Media.Water.WaterIF97_base.setBubbleState setBubbleState set the thermodynamic state on the bubble line
Modelica.Media.Water.WaterIF97_base.dynamicViscosity dynamicViscosity Dynamic viscosity of water
Modelica.Media.Water.WaterIF97_base.thermalConductivity thermalConductivity Thermal conductivity of water
Modelica.Media.Water.WaterIF97_base.surfaceTension surfaceTension Surface tension in two phase region of water
Modelica.Media.Water.WaterIF97_base.pressure pressure return pressure of ideal gas
Modelica.Media.Water.WaterIF97_base.temperature temperature return temperature of ideal gas
Modelica.Media.Water.WaterIF97_base.density density return density of ideal gas
Modelica.Media.Water.WaterIF97_base.specificEnthalpy specificEnthalpy Return specific enthalpy
Modelica.Media.Water.WaterIF97_base.specificInternalEnergy specificInternalEnergy Return specific internal energy
Modelica.Media.Water.WaterIF97_base.specificGibbsEnergy specificGibbsEnergy Return specific Gibbs energy
Modelica.Media.Water.WaterIF97_base.specificHelmholtzEnergy specificHelmholtzEnergy Return specific Helmholtz energy
Modelica.Media.Water.WaterIF97_base.specificEntropy specificEntropy specific entropy of water
Modelica.Media.Water.WaterIF97_base.specificHeatCapacityCp specificHeatCapacityCp specific heat capacity at constant pressure of water
Modelica.Media.Water.WaterIF97_base.specificHeatCapacityCv specificHeatCapacityCv specific heat capacity at constant volume of water
Modelica.Media.Water.WaterIF97_base.isentropicExponent isentropicExponent Return isentropic exponent
Modelica.Media.Water.WaterIF97_base.isothermalCompressibility isothermalCompressibility Isothermal compressibility of water
Modelica.Media.Water.WaterIF97_base.isobaricExpansionCoefficient isobaricExpansionCoefficient isobaric expansion coefficient of water
Modelica.Media.Water.WaterIF97_base.velocityOfSound velocityOfSound Return velocity of sound as a function of the thermodynamic state record
Modelica.Media.Water.WaterIF97_base.isentropicEnthalpy isentropicEnthalpy compute h(p,s)
Modelica.Media.Water.WaterIF97_base.density_derh_p density_derh_p density derivative by specific enthalpy
Modelica.Media.Water.WaterIF97_base.density_derp_h density_derp_h density derivative by pressure
Modelica.Media.Water.WaterIF97_base.bubbleEnthalpy bubbleEnthalpy boiling curve specific enthalpy of water
Modelica.Media.Water.WaterIF97_base.dewEnthalpy dewEnthalpy dew curve specific enthalpy of water
Modelica.Media.Water.WaterIF97_base.bubbleEntropy bubbleEntropy boiling curve specific entropy of water
Modelica.Media.Water.WaterIF97_base.dewEntropy dewEntropy dew curve specific entropy of water
Modelica.Media.Water.WaterIF97_base.bubbleDensity bubbleDensity boiling curve specific density of water
Modelica.Media.Water.WaterIF97_base.dewDensity dewDensity dew curve specific density of water
Modelica.Media.Water.WaterIF97_base.saturationTemperature saturationTemperature saturation temperature of water
Modelica.Media.Water.WaterIF97_base.saturationTemperature_derp saturationTemperature_derp derivative of saturation temperature w.r.t. pressure
Modelica.Media.Water.WaterIF97_base.saturationPressure saturationPressure saturation pressure of water
Modelica.Media.Water.WaterIF97_base.dBubbleDensity_dPressure dBubbleDensity_dPressure bubble point density derivative
Modelica.Media.Water.WaterIF97_base.dDewDensity_dPressure dDewDensity_dPressure dew point density derivative
Modelica.Media.Water.WaterIF97_base.dBubbleEnthalpy_dPressure dBubbleEnthalpy_dPressure bubble point specific enthalpy derivative
Modelica.Media.Water.WaterIF97_base.dDewEnthalpy_dPressure dDewEnthalpy_dPressure dew point specific enthalpy derivative
Modelica.Media.Water.WaterIF97_base.setState_dTX setState_dTX Return thermodynamic state of water as function of d and T
Modelica.Media.Water.WaterIF97_base.setState_phX setState_phX Return thermodynamic state of water as function of p and h
Modelica.Media.Water.WaterIF97_base.setState_psX setState_psX Return thermodynamic state of water as function of p and s
Modelica.Media.Water.WaterIF97_base.setState_pTX setState_pTX Return thermodynamic state of water as function of p and T
Modelica.Media.Water.WaterIF97_base.setSmoothState setSmoothState Return thermodynamic state so that it smoothly approximates: if x > 0 then state_a else state_b
smoothModeltrue if the (derived) model should not generate state events
onePhasetrue if the (derived) model should never be called with two-phase inputs
Modelica.Media.Interfaces.PartialTwoPhaseMedium.FluidLimits FluidLimits validity limits for fluid model
Modelica.Media.Interfaces.PartialTwoPhaseMedium.FluidConstants FluidConstants extended fluid constants
fluidConstantsconstant data for the fluid
Modelica.Media.Interfaces.PartialTwoPhaseMedium.SaturationProperties SaturationProperties Saturation properties of two phase medium
FixedPhase phase of the fluid: 1 for 1-phase, 2 for two-phase, 0 for not known, e.g., interactive use
Modelica.Media.Interfaces.PartialTwoPhaseMedium.setSat_T setSat_T Return saturation property record from temperature
Modelica.Media.Interfaces.PartialTwoPhaseMedium.setSat_p setSat_p Return saturation property record from pressure
Modelica.Media.Interfaces.PartialTwoPhaseMedium.saturationPressure_sat saturationPressure_sat Return saturation temperature
Modelica.Media.Interfaces.PartialTwoPhaseMedium.saturationTemperature_sat saturationTemperature_sat Return saturation temperature
Modelica.Media.Interfaces.PartialTwoPhaseMedium.saturationTemperature_derp_sat saturationTemperature_derp_sat Return derivative of saturation temperature w.r.t. pressure
Modelica.Media.Interfaces.PartialTwoPhaseMedium.molarMass molarMass Return the molar mass of the medium
Modelica.Media.Interfaces.PartialTwoPhaseMedium.specificEnthalpy_pTX specificEnthalpy_pTX Return specific enthalpy from pressure, temperature and mass fraction
Modelica.Media.Interfaces.PartialTwoPhaseMedium.temperature_phX temperature_phX Return temperature from p, h, and X or Xi
Modelica.Media.Interfaces.PartialTwoPhaseMedium.density_phX density_phX Return density from p, h, and X or Xi
Modelica.Media.Interfaces.PartialTwoPhaseMedium.temperature_psX temperature_psX Return temperature from p, s, and X or Xi
Modelica.Media.Interfaces.PartialTwoPhaseMedium.density_psX density_psX Return density from p, s, and X or Xi
Modelica.Media.Interfaces.PartialTwoPhaseMedium.specificEnthalpy_psX specificEnthalpy_psX Return specific enthalpy from p, s, and X or Xi
Modelica.Media.Interfaces.PartialTwoPhaseMedium.setState_pT setState_pT Return thermodynamic state from p and T
Modelica.Media.Interfaces.PartialTwoPhaseMedium.setState_ph setState_ph Return thermodynamic state from p and h
Modelica.Media.Interfaces.PartialTwoPhaseMedium.setState_ps setState_ps Return thermodynamic state from p and s
Modelica.Media.Interfaces.PartialTwoPhaseMedium.setState_dT setState_dT Return thermodynamic state from d and T
Modelica.Media.Interfaces.PartialTwoPhaseMedium.setState_px setState_px Return thermodynamic state from pressure and vapour quality
Modelica.Media.Interfaces.PartialTwoPhaseMedium.setState_Tx setState_Tx Return thermodynamic state from temperature and vapour quality
Modelica.Media.Interfaces.PartialTwoPhaseMedium.vapourQuality vapourQuality Return vapour quality
ThermoStatesEnumeration type for independent variables
mediumName="unusablePartialMedium"Name of the medium
substanceNames={mediumName}Names of the mixture substances. Set substanceNames={mediumName} if only one substance.
extraPropertiesNames=fill("", 0)Names of the additional (extra) transported properties. Set extraPropertiesNames=fill("",0) if unused
singleState= true, if u and d are not a function of pressure
reducedX=true= true if medium contains the equation sum(X) = 1.0; set reducedX=true if only one substance (see docu for details)
fixedX=false= true if medium contains the equation X = reference_X
reference_p=101325Reference pressure of Medium: default 1 atmosphere
reference_T=298.15Reference temperature of Medium: default 25 deg Celsius
reference_X=fill(1/nX, nX)Default mass fractions of medium
p_default=101325Default value for pressure of medium (for initialization)
T_default=Modelica.SIunits.Conversions.from_degC(20)Default value for temperature of medium (for initialization)
h_default=specificEnthalpy_pTX(p_default, T_default, X_default)Default value for specific enthalpy of medium (for initialization)
X_default=reference_XDefault value for mass fractions of medium (for initialization)
nS=size(substanceNames, 1)Number of substances
nX=nSNumber of mass fractions
nXi=if fixedX then 0 else if reducedX then nS - 1 else nSNumber of structurally independent mass fractions (see docu for details)
nC=size(extraPropertiesNames, 1)Number of extra (outside of standard mass-balance) transported properties
C_nominal=1.0e-6*ones(nC)Default for the nominal values for the extra properties
Modelica.Media.Interfaces.PartialMedium.prandtlNumber prandtlNumber Return the Prandtl number
Modelica.Media.Interfaces.PartialMedium.heatCapacity_cp heatCapacity_cp alias for deprecated name
Modelica.Media.Interfaces.PartialMedium.heatCapacity_cv heatCapacity_cv alias for deprecated name
Modelica.Media.Interfaces.PartialMedium.beta beta alias for isobaricExpansionCoefficient for user convenience
Modelica.Media.Interfaces.PartialMedium.kappa kappa alias of isothermalCompressibility for user convenience
Modelica.Media.Interfaces.PartialMedium.density_derp_T density_derp_T Return density derivative w.r.t. pressure at const temperature
Modelica.Media.Interfaces.PartialMedium.density_derT_p density_derT_p Return density derivative w.r.t. temperature at constant pressure
Modelica.Media.Interfaces.PartialMedium.density_derX density_derX Return density derivative w.r.t. mass fraction
Modelica.Media.Interfaces.PartialMedium.specificEntropy_pTX specificEntropy_pTX Return specific enthalpy from p, T, and X or Xi
Modelica.Media.Interfaces.PartialMedium.density_pTX density_pTX Return density from p, T, and X or Xi
AbsolutePressure Type for absolute pressure with medium specific attributes
Density Type for density with medium specific attributes
DynamicViscosity Type for dynamic viscosity with medium specific attributes
EnthalpyFlowRate Type for enthalpy flow rate with medium specific attributes
MassFlowRate Type for mass flow rate with medium specific attributes
MassFraction Type for mass fraction with medium specific attributes
MoleFraction Type for mole fraction with medium specific attributes
MolarMass Type for molar mass with medium specific attributes
MolarVolume Type for molar volume with medium specific attributes
IsentropicExponent Type for isentropic exponent with medium specific attributes
SpecificEnergy Type for specific energy with medium specific attributes
SpecificInternalEnergy Type for specific internal energy with medium specific attributes
SpecificEnthalpy Type for specific enthalpy with medium specific attributes
SpecificEntropy Type for specific entropy with medium specific attributes
SpecificHeatCapacity Type for specific heat capacity with medium specific attributes
SurfaceTension Type for surface tension with medium specific attributes
Temperature Type for temperature with medium specific attributes
ThermalConductivity Type for thermal conductivity with medium specific attributes
PrandtlNumber Type for Prandtl number with medium specific attributes
VelocityOfSound Type for velocity of sound with medium specific attributes
ExtraProperty Type for unspecified, mass-specific property transported by flow
CumulativeExtraProperty Type for conserved integral of unspecified, mass specific property
ExtraPropertyFlowRate Type for flow rate of unspecified, mass-specific property
IsobaricExpansionCoefficient Type for isobaric expansion coefficient with medium specific attributes
DipoleMoment Type for dipole moment with medium specific attributes
DerDensityByPressure Type for partial derivative of density with resect to pressure with medium specific attributes
DerDensityByEnthalpy Type for partial derivative of density with resect to enthalpy with medium specific attributes
DerEnthalpyByPressure Type for partial derivative of enthalpy with resect to pressure with medium specific attributes
DerDensityByTemperature Type for partial derivative of density with resect to temperature with medium specific attributes
Modelica.Media.Interfaces.PartialMedium.Choices Choices Types, constants to define menu choices


Modelica.Media.Examples.TwoPhaseWater.BaseProperties Modelica.Media.Examples.TwoPhaseWater.BaseProperties

Make StandardWater.BaseProperties non replaceable in order that inheritance is possible in model ExtendedProperties

Information

Extends from (Base properties of water).

Parameters

TypeNameDefaultDescription
Initialization
Integerphase.start12 for two-phase, 1 for one-phase, 0 if not known
Advanced
BooleanpreferredMediumStatesfalse= true if StateSelect.prefer shall be used for the independent property variables of the medium

Modelica definition

redeclare model extends BaseProperties 
  "Make StandardWater.BaseProperties non replaceable in order that inheritance is possible in model ExtendedProperties"
end BaseProperties;

Modelica.Media.Examples.TwoPhaseWater.ExtendedProperties Modelica.Media.Examples.TwoPhaseWater.ExtendedProperties

plenty of two-phase properties

Information

Extends from BaseProperties (Make StandardWater.BaseProperties non replaceable in order that inheritance is possible in model ExtendedProperties).

Parameters

TypeNameDefaultDescription
Initialization
Integerphase.start12 for two-phase, 1 for one-phase, 0 if not known
Advanced
BooleanpreferredMediumStatesfalse= true if StateSelect.prefer shall be used for the independent property variables of the medium

Modelica definition

model ExtendedProperties "plenty of two-phase properties"
  extends BaseProperties;
  ThermodynamicState dew "dew line Properties";
  ThermodynamicState bubble "bubble line Properties";
  ThermodynamicState bubble2 "bubble line Properties, on the 2-phase side";
  DynamicViscosity eta "viscosity (McAdams mixture rules if in 2-phase)";
  DynamicViscosity eta_d "dew line viscosity";
  DynamicViscosity eta_b "bubble line viscosity";
  ThermalConductivity lambda_d "dew line thermal conductivity";
  ThermalConductivity lambda_b "bubble line thermal conductivity";
  SpecificHeatCapacity cp_d "dew line Specific heat capacity";
  SpecificHeatCapacity cp_b "bubble line Specific heat capacity";
  Real ddhp;
  Real ddhp_d;
  Real ddhp_b "derivatives";
  Real ddph;
  Real ddph_d;
  Real ddph_b "derivatives";
  Real ddhp_b2;
  Real ddph_b2 "derivatives";
  // no derivatives yet, ... sat should be temporary
  MassFraction x "steam mass fraction";
  Real dTp;
  Real dTp2;
  SpecificEntropy s_b;
  SpecificEntropy s_d;
equation 
  eta = if phase == 1 then dynamicViscosity(state) else 1/(x/eta_d + (1 - x)
    /eta_b);
  dew =  setDewState(sat);
  bubble =  setBubbleState(sat);
  bubble2 =  setBubbleState(sat,2);
  x = (h - bubble.h)/max(dew.h - bubble.h,1e-6);
  eta_d = dynamicViscosity(dew);
  eta_b = dynamicViscosity(bubble);
  lambda_d = thermalConductivity(dew);
  lambda_b = thermalConductivity(bubble);
  cp_d = specificHeatCapacityCp(dew);
  cp_b = specificHeatCapacityCp(bubble);
  s_d = specificEntropy(dew);
  s_b = specificEntropy(bubble);
  ddph = density_derp_h(state);
  ddph_d = density_derp_h(dew);
  ddph_b = density_derp_h(bubble);
  ddhp = density_derh_p(state);
  ddhp_d = density_derh_p(dew);
  ddhp_b = density_derh_p(bubble);
  ddhp_b2 = density_derh_p(bubble2);
  ddph_b2 = density_derp_h(bubble2);
  dTp = saturationTemperature_derp(p);
  dTp2 = (1/dew.d - 1/bubble.d)/max(s_d - s_b,1e-6);
end ExtendedProperties;

Modelica.Media.Examples.TwoPhaseWater.TestTwoPhaseStates Modelica.Media.Examples.TwoPhaseWater.TestTwoPhaseStates

Test the above model

Information


For details see the documentation of the example package TwoPhaseWater

Extends from Modelica.Icons.Example (Icon for runnable examples).

Parameters

TypeNameDefaultDescription
Realdh80000.080 kJ/second
Realdp1.0e610 bars per second

Modelica definition

model TestTwoPhaseStates "Test the above model"
  extends Modelica.Icons.Example;
  ExtendedProperties medium(p(start = 700.0),
   h(start = 8.0e5));
  parameter Real dh = 80000.0 "80 kJ/second";
  parameter Real dp = 1.0e6 "10 bars per second";
equation 
  der(medium.p) = dp;
  der(medium.h) = dh;
end TestTwoPhaseStates;

Automatically generated Fri Nov 12 16:31:26 2010.