Commit 21eb0e86 authored by Henning Francke's avatar Henning Francke
Browse files

Fixed variable nX_gas in 2Phase packages

made BrineProp3Salts4Gas as BrineProp work
reorganized UnitTests
parent e103807b
......@@ -24,6 +24,7 @@ package Brine3salts3gas "Two-phase aqueous solution of NaCl, KCl, CaCl2, N2, CO2
gasNames = {"carbondioxide","nitrogen","methane"},
MM_gas = {M_CO2,M_N2,M_CH4},
nM_gas = {nM_CO2,nM_N2,nM_CH4}); //iGas not final, because reassigned in Brine5salts3gas
//order of gases must be consistentwith Brine3Gas TODO: pass order or copy enthalpy/density/cp here
redeclare function extends setState_pTX "to avoid check error"
end setState_pTX;
......@@ -52,23 +53,24 @@ package Brine3salts3gas "Two-phase aqueous solution of NaCl, KCl, CaCl2, N2, CO2
end solubilities_pTX;
redeclare function extends density_liq_pTX
// extends density_Duan2008_pTX(MM_vec=cat(1,MM_salt, {M_H2O}));
//TODO should take MM_vec;
// PowerPlant.Media.Brine.Salt_Data_Duan.density_Duan2008_pTX;
protected
constant Integer[:] liqIndex=cat(1,1:nX_salt,{nX});
Real X_[:] = cat(1, X[1:nX_salt], {1-sum(X[1:nX_salt])}); //recalculate water mass fraction when gases are omitted (which they are in the density function)
algorithm
d := density_Duan2008_pTX(p,T,X_,MM[liqIndex],
saltConstants);
// print("density_liquid_pTX: "+String(p*1e-5)+" bar,"+String(T)+" K->"+String(d)+"kg/m^3");
end density_liq_pTX;
/*function extends density_Duan2008_pTX(nX_salt_=nX_salt, ignoreLimitSalt_p_=ignoreLimitSalt_p_global)
"just to set the flags"
end density_Duan2008_pTX;*/
redeclare replaceable function extends density_gas_pTX
algorithm
d := BrineGas3Gas.density_pTX(p,T,X,MM);
// print("density_liquid_pTX: "+String(p*1e-5)+" bar,"+String(T)+" K->"+String(d)+"kg/m^3");
end density_gas_pTX;
redeclare function extends specificEnthalpy_liq_pTX
// Partial_Units.Molality molalities = massFractionsToMoleFractions(X, MM_vec);
// SI.SpecificEnthalpy h_H2O := Modelica.Media.Water.WaterIF97_pT.specificEnthalpy_pT(p, T) "H2O";
......@@ -81,13 +83,10 @@ protected
// print(String(p*1e-5)+" bar,"+String(T)+" K->"+String(h)+" J/kg (Brine_Duan_Multi_TwoPhase_ngas_3.specificEnthalpy_liq_pTX)");
end specificEnthalpy_liq_pTX;
redeclare function extends specificEnthalpy_gas_pTX
redeclare replaceable function extends specificEnthalpy_gas_pTX
algorithm
h :=BrineGas3Gas.specificEnthalpy_pTX(
p,
T,
X);
h :=BrineGas3Gas.specificEnthalpy_pTX(p,T,X); //,MM
end specificEnthalpy_gas_pTX;
redeclare function extends dynamicViscosity_liq
......
......@@ -3,6 +3,7 @@ setState_pTX
setState_phX
solubilities_pTX
density_liq_pTX
density_gas_pTX
specificEnthalpy_liq_pTX
specificEnthalpy_gas_pTX
dynamicViscosity_liq
......
within BrineProp.Examples.Gas;
model Brine3Gas
model UnitTestBrine3Gas
package Medium = BrineProp.BrineGas3Gas (ignoreNoCompositionInBrineGas=true);
//package Medium = Modelica.Media.Air.SimpleAir;
//package Medium = PartialBrineGas;
......@@ -58,9 +58,14 @@ equation
// props.Xi={0.8};
props.Xi={0.0892134,0.0051995,0.137699,0,0,0.000639217,7.0356e-6,1.5464e-5};
*/
// assert(abs(props.GVF-0.0497710432105261)<1e6,"GVF differs!");
assert(abs(props.h-2777119.5)<1e6,"h differs!");
assert(abs(props.d-0.007391231)<1e6,"d differs!");
algorithm
// print("rho="+String(d)+" kg/m^3, TDS = " + String(TDS) + " g/l -> "+ String(f*265/TDS));
// print("sum(X_l)="+String(sum(props.state.X_l)-1)+"");
// print("sum(X_sat)="+String(sum(X_sat)));
end Brine3Gas;
end UnitTestBrine3Gas;
Brine3Gas_Minimal
Brine3Gas
Brine4Gas_Minimal
UnitTestBrine3Gas
within BrineProp.Examples.UnitTests;
model H2solubility_Chabab
package Medium = BrineProp.Brine3salts3gas (ignoreNoCompositionInBrineGas=true);
package Medium = BrineProp.Brine3salts4gas (ignoreNoCompositionInBrineGas=true);
//package Medium = Modelica.Media.Air.SimpleAir;
//package Medium = PartialBrineGas;
// Medium.BaseProperties props;
equation
assert(abs(GasData.solubility_H2_pT_Chabab2020_y(1e7, 323.15) -
0.001272328226268451) < 1e-8, "Nope");
assert(abs(GasData.solubility_H2_pTb_Chabab2020_y(
1e7,
323.15,
1) - 0.0009584062226925354) < 1e-8, "Nope");
assert(abs(GasData.solubility_H2_pTb_Chabab2020_molality(
1e7,
323.15,
1) - 0.05325070081453114) < 1e-8, "Nope");
assert(abs(Medium.solubility_H2_pTX_Chabab2020_molality(102e5, 323.15,{0.0552160106873965,0,0,0,0,0,0}, 100e5, Modelica.Media.Water.WaterIF97_pT.saturationPressure(323.15))-0.05325070081453114)<1e-8, "Nope");
assert(abs(GasData.solubility_H2_pT_Chabab2020_y(1e7, 323.15) - 0.001272328226268451)< 1e-8, "Nope");
assert(abs(GasData.solubility_H2_pTb_Chabab2020_y(1e7,323.15,1) - 0.000958406222692535) < 1e-8, "Nope");
assert(abs(GasData.solubility_H2_pTb_Chabab2020_molality(1e7,323.15,1) - 0.0532507008145311) < 1e-8, "Nope");
assert(abs(0.00396636796628623-Medium.solubility_H2_pTX_Chabab2020_molality(50e5, 323.15,{0.0839077010751,0.00253365118988,0.122786737978,0.00016883,0.00073459,0.000065652,0.00001,0.789792838},Medium.MM_vec,15e5))<1e-8, "Nope");
assert(abs(6.31433733266665E-06-Medium.solubility_H2_pTX_Chabab2020(50e5, 323.15,{0.0839077010751,0.00253365118988,0.122786737978,0.00016883,0.00073459,0.000065652,0.00001,0.789792838},Medium.MM_vec, 15e5,false))<1e-8, "Nope");
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
coordinateSystem(preserveAspectRatio=false)));
end H2solubility_Chabab;
......@@ -24,7 +24,7 @@ equation
props.Xi = Xi;
assert(abs(props.GVF-0.0497710432105261)<1e6,"GVF differs!");
assert(abs(props.h-288702.455)<1e6,"GVF differs!");
assert(abs(props.h-288702.455)<1e6,"h differs!");
annotation (experiment(StopTime=1, __Dymola_NumberOfIntervals=1),
__Dymola_experimentSetupOutput);
end UnitTestsTwoPhase4Gas;
......@@ -23,7 +23,7 @@ partial package PartialBrineGas "Medium template for gas mixture of nX_gas gases
// (h,x,d,d_g,d_l) = specificEnthalpy_pTX(p,T,X) unfortunately, this is not invertable;
h = specificEnthalpy_pTX(p,T,X);
// d=density_pTX(p,T,X);
(d,R) = density_pTX(p,T,X);
(d,R) = density_pTX(p,T,X, MM_vec);
state=ThermodynamicState(p=p,T=T,X=X);
end BaseProperties;
......@@ -47,9 +47,20 @@ constant String gasNames[:]={""};
input SI.Pressure p;
input SI.Temp_K T;
input MassFraction X[nX] "Mass fractions";
input SI.MolarMass MM[:]=fill(0,nX) "molar masses of components";
output SI.Density d;
output SpecificHeatCapacity R_gas;
//algorithm
algorithm
if debugmode then
print("Running density_pTX("+String(p/1e5)+" bar,"+String(T-273.15)+" degC, X="+Modelica.Math.Matrices.toString(transpose([X]))+")");
end if;
if not min(X)>0 and not ignoreNoCompositionInBrineGas then
print("No gas composition, assuming water vapour.(BrineProp.BrineGas_3Gas.density_pTX)");
end if;
R_gas :=Modelica.Constants.R*sum(cat(1,X[1:end-1],{(if min(X)>0 then X[end] else 1)})./ MM);
d :=p/(T*R_gas);
end density_pTX;
......
......@@ -126,6 +126,52 @@ partial package PartialBrineMultiSaltMultiGasTwoPhase "Template medium for aqueo
</html>"));
end ThermodynamicState;
redeclare function extends density "return density of ideal gas"
algorithm
d := state.d;
end density;
redeclare function density_pTX "wrapper to extract d from state"
//necessary for declaration of inverse function p(T,d)
input SI.Pressure p;
input SI.Temp_K T;
input MassFraction X[:] "mass fraction m_NaCl/m_Sol";
input FixedPhase phase=0
"2 for two-phase, 1 for one-phase, 0 if not known";
input Real[nX_gas+1] n_g_norm_start=fill(0.5,nX_gas+1)
"start value, all gas in gas phase, all water liquid";
output SI.Density d;
algorithm
if debugmode then
print("Running density_pTX("+String(p/1e5)+","+String(T-273.15)+"degC, X="+Modelica.Math.Matrices.toString(transpose([X]))+")");
end if;
d:=density(setState_pTX(p,T,X,phase,n_g_norm_start));
annotation(LateInline=true,inverse(p=pressure_dTX(d,T,X,phase,n_g_norm_start)));
end density_pTX;
replaceable function density_liq_pTX "Density of the liquid phase"
input SI.Pressure p "TODO: Rename to density_liq_pTX";
input SI.Temp_K T;
input MassFraction X[nX] "mass fraction m_NaCl/m_Sol";
input SI.MolarMass MM[:] "=MM_vec =fill(0,nX) molar masses of components";
output SI.Density d;
end density_liq_pTX;
replaceable function density_gas_pTX "Density of the gas phase"
input SI.Pressure p;
input SI.Temp_K T;
input MassFraction X[:] "nX_gas mass fraction";
input SI.MolarMass MM[:] "=MM_vec =fill(0,nX) molar masses of components";
output SI.Density d;
end density_gas_pTX;
redeclare function extends saturationTemperature "saturation temperature"
algorithm
T := 373.15;
end saturationTemperature;
redeclare function extends dewEnthalpy
"dew curve specific enthalpy of water"
algorithm
......@@ -138,11 +184,6 @@ partial package PartialBrineMultiSaltMultiGasTwoPhase "Template medium for aqueo
hl := 2000;
end bubbleEnthalpy;
redeclare function extends saturationTemperature "saturation temperature"
algorithm
T := 373.15;
end saturationTemperature;
replaceable partial function solutionEnthalpy
input SI.Temp_K T;
output SI.SpecificEnthalpy Delta_h_solution;
......@@ -172,14 +213,6 @@ protected
Types.Pressure_bar p_bar=SI.Conversions.to_bar(p);
end fugacity_pTX;
replaceable function density_liq_pTX "Density of the liquid phase"
input SI.Pressure p "TODO: Rename to density_liq_pTX";
input SI.Temp_K T;
input MassFraction X[nX] "mass fraction m_NaCl/m_Sol";
input SI.MolarMass MM[:] "=MM_vec =fill(0,nX) molar masses of components";
output SI.Density d;
end density_liq_pTX;
redeclare function vapourQuality
"Returns vapour quality, needs to be defined to overload function defined in PartialMixtureTwoPhaseMedium"
input ThermodynamicState state "Thermodynamic state record";
......@@ -188,56 +221,6 @@ protected
x := state.x;
end vapourQuality;
redeclare function specificEnthalpy_pTX "wrapper to extract h from state"
//necessary for declaration of inverse function T(p,h)
input SI.Pressure p;
input SI.Temp_K T;
input MassFraction X[:] "mass fraction m_NaCl/m_Sol";
input FixedPhase phase=0
"2 for two-phase, 1 for one-phase, 0 if not known";
input Real[nX_gas+1] n_g_norm_start=fill(0.5,nX_gas+1)
"start value, all gas in gas phase, all water liquid";
input Boolean ignoreTlimit=false;
output SI.SpecificEnthalpy h;
algorithm
if debugmode then
print("Running specificEnthalpy_pTX("+String(p/1e5)+" bar,"+String(T-273.15)+" C, ignoreTlimit="+String(ignoreTlimit)+", X="+Modelica.Math.Matrices.toString(transpose([X]))+")");
end if;
h:=specificEnthalpy(setState_pTX(
p,
T,
X,
phase,
n_g_norm_start,
ignoreTlimit));
//print(String(p)+","+String(T)+" K->"+String(h)+" J/kg & (PartialBrine_Multi_TwoPhase_ngas.specificEnthalpy_pTX)");
//,p=pressure_ThX(T,h,X);
annotation(LateInline=true,inverse(T=temperature_phX(p,h,X,phase,n_g_norm_start,ignoreTlimit)));
end specificEnthalpy_pTX;
redeclare function density_pTX "wrapper to extract d from state"
//necessary for declaration of inverse function p(T,d)
input SI.Pressure p;
input SI.Temp_K T;
input MassFraction X[:] "mass fraction m_NaCl/m_Sol";
input FixedPhase phase=0
"2 for two-phase, 1 for one-phase, 0 if not known";
input Real[nX_gas+1] n_g_norm_start=fill(0.5,nX_gas+1)
"start value, all gas in gas phase, all water liquid";
output SI.Density d;
algorithm
if debugmode then
print("Running density_pTX("+String(p/1e5)+","+String(T-273.15)+"degC, X="+Modelica.Math.Matrices.toString(transpose([X]))+")");
end if;
d:=density(setState_pTX(p,T,X,phase,n_g_norm_start));
annotation(LateInline=true,inverse(p=pressure_dTX(d,T,X,phase,n_g_norm_start)));
end density_pTX;
redeclare function temperature_phX
"iterative inversion of specificEnthalpy_pTX by regula falsi"
extends Modelica.Icons.Function;
......@@ -400,6 +383,36 @@ protected
end pressure_dTX;
redeclare function specificEnthalpy_pTX "wrapper to extract h from state"
//necessary for declaration of inverse function T(p,h)
input SI.Pressure p;
input SI.Temp_K T;
input MassFraction X[:] "mass fraction m_NaCl/m_Sol";
input FixedPhase phase=0
"2 for two-phase, 1 for one-phase, 0 if not known";
input Real[nX_gas+1] n_g_norm_start=fill(0.5,nX_gas+1)
"start value, all gas in gas phase, all water liquid";
input Boolean ignoreTlimit=false;
output SI.SpecificEnthalpy h;
algorithm
if debugmode then
print("Running specificEnthalpy_pTX("+String(p/1e5)+" bar,"+String(T-273.15)+" C, ignoreTlimit="+String(ignoreTlimit)+", X="+Modelica.Math.Matrices.toString(transpose([X]))+")");
end if;
h:=specificEnthalpy(setState_pTX(
p,
T,
X,
phase,
n_g_norm_start,
ignoreTlimit));
//print(String(p)+","+String(T)+" K->"+String(h)+" J/kg & (PartialBrine_Multi_TwoPhase_ngas.specificEnthalpy_pTX)");
//,p=pressure_ThX(T,h,X);
annotation(LateInline=true,inverse(T=temperature_phX(p,h,X,phase,n_g_norm_start,ignoreTlimit)));
end specificEnthalpy_pTX;
replaceable function specificEnthalpy_liq_pTX
"Specific enthalpy of liquid phase"
input SI.Pressure p;
......@@ -414,8 +427,8 @@ protected
"Specific enthalpy of gas in gas phase"
input SI.Pressure p;
input SI.Temp_K T;
// input SI.MolarMass MM[:]=fill(0,nX) "molar masses of components";
input MassFraction X[:] "mass fraction m_NaCl/m_Sol";
// input SI.MolarMass MM[:]=fill(0,nX) "molar masses of components";
output SI.SpecificEnthalpy h;
end specificEnthalpy_gas_pTX;
......@@ -429,7 +442,6 @@ protected
output SI.Pressure[nX_gas] p_sat;
end saturationPressures;
redeclare replaceable partial function extends setState_pTX
"finds the VLE iteratively by varying the normalized quantity of gas in the gasphase, calculates the densities"
input Real[nX_gas + 1] n_g_norm_start= fill(0.1,nX_gas+1)
......@@ -672,11 +684,8 @@ protected
d_g :=if x > 0 then p/(T2*R_gas) else -1;*/
// d_g:= if x>0 then p/(Modelica.Constants.R*T2)*(n_g*cat(1,MM_gas,{M_H2O}))/sum(n_g) else -1;
if x > 0 then
d_g :=BrineGas3Gas.density_pTX(
p,
T,
X_g);
h_g := specificEnthalpy_gas_pTX(p,T,X_g);
d_g := density_gas_pTX(p,T,X_g,MM_gas); //BrineGas3Gas.density_pTX(
h_g := specificEnthalpy_gas_pTX(p,T,X_g); //,MM_gas
else
d_g := -1;
h_g := -1;
......@@ -846,11 +855,6 @@ protected
h := state.h;
end specificEnthalpy;
redeclare function extends density "return density of ideal gas"
algorithm
d := state.d;
end density;
annotation (Documentation(info="<html>
<ul>
<li><b>PartialBrine_ngas_Newton</b> is based on <code>PartialMixtureTwoPhaseMedium</code>, an extension to the <code>Modelica.Media</code> library. This extension was necessary because <code>Modelica.Media</code> supports mixtures and two-phase media, but not both combined.</li>
......
......@@ -14,18 +14,20 @@ MM_gas
nM_gas
BaseProperties
ThermodynamicState
density
density_pTX
density_liq_pTX
density_gas_pTX
saturationTemperature
dewEnthalpy
bubbleEnthalpy
saturationTemperature
solutionEnthalpy
solubilities_pTX
fugacity_pTX
density_liq_pTX
vapourQuality
specificEnthalpy_pTX
density_pTX
temperature_phX
pressure_dTX
specificEnthalpy_pTX
specificEnthalpy_liq_pTX
specificEnthalpy_gas_pTX
saturationPressures
......@@ -37,4 +39,3 @@ specificHeatCapacityCp_liq
specificHeatCapacityCp_gas
isobaricExpansionCoefficient_liq
specificEnthalpy
density
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment