https://mooseframework.inl.gov
Loading...
Searching...
No Matches
StiffenedGasTwoPhaseFluidProperties.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
12
14
17{
19 params += NaNInterface::validParams();
20
21 params.addParam<Real>("gamma_liquid", 2.35, "Liquid heat capacity ratio");
22 params.addParam<Real>("cv_liquid", 1816.0, "Liquid isochoric specific heat capacity");
23 params.addParam<Real>("q_liquid", -1.167e6, "Liquid reference specific internal energy");
24 params.addParam<Real>("p_inf_liquid", 1.0e9, "Liquid stiffness pressure");
25 params.addParam<Real>("q_prime_liquid", 0, "Liquid reference specific entropy");
26 params.addParam<Real>("k_liquid", 0.5, "Liquid thermal conductivity");
27 params.addParam<Real>("mu_liquid", 281.8e-6, "Liquid dynamic viscosity");
28 params.addParam<Real>("M_liquid", 0.01801488, "Liquid molar mass");
29
30 params.addParam<Real>("gamma_vapor", 1.43, "Vapor heat capacity ratio");
31 params.addParam<Real>("cv_vapor", 1040.0, "Vapor isochoric specific heat capacity");
32 params.addParam<Real>("q_vapor", 2.03e6, "Vapor reference specific internal energy");
33 params.addParam<Real>("p_inf_vapor", 0.0, "Vapor stiffness pressure");
34 params.addParam<Real>("q_prime_vapor", -2.3e4, "Vapor reference specific entropy");
35 params.addParam<Real>("k_vapor", 0.026, "Vapor thermal conductivity");
36 params.addParam<Real>("mu_vapor", 134.4e-7, "Vapor dynamic viscosity");
37 params.addParam<Real>("M_vapor", 0.01801488, "Vapor molar mass");
38
39 params.addParam<Real>("T_c", 647.096, "Critical temperature [K]");
40 params.addParam<Real>("p_c", 22.09e6, "Critical pressure [Pa]");
41 params.addParam<Real>("rho_c", 322.0, "Critical density [kg/m^3]");
42 params.addParam<Real>("e_c", 2702979.84310559, "Critical specific internal energy [J/kg]");
43 params.addParam<Real>("T_triple", 273.16, "Triple-point temperature [K]");
44 params.addParam<Real>("L_fusion", 0.334, "Latent heat of fusion [J/kg]");
45
46 params.addParam<Real>(
47 "sigma_A", 0.2358, "'A' constant used in surface tension correlation [N/m]");
48 params.addParam<Real>("sigma_B", 1.256, "'B' constant used in surface tension correlation");
49 params.addParam<Real>("sigma_C", 0.625, "'C' constant used in surface tension correlation");
50
51 // Default values correspond to water, from the freezing point to critical point, with 1 K
52 // increments
53 params.addParam<Real>("T_sat_min", 274.0, "Minimum temperature value in saturation curve [K]");
54 params.addParam<Real>("T_sat_max", 647.0, "Maximum temperature value in saturation curve [K]");
55 params.addParam<Real>(
56 "p_sat_guess", 611.0, "Initial guess for saturation pressure Newton solve [Pa]");
57 params.addParam<unsigned int>(
58 "n_sat_samples", 374, "Number of samples to take in saturation curve");
59
60 params.addClassDescription("Two-phase stiffened gas fluid properties");
61
62 return params;
63}
64
66 const InputParameters & parameters)
67 : TwoPhaseFluidProperties(parameters),
68 NaNInterface(this),
69
70 _gamma_liquid(getParam<Real>("gamma_liquid")),
71 _cv_liquid(getParam<Real>("cv_liquid")),
72 _cp_liquid(_gamma_liquid * _cv_liquid),
73 _q_liquid(getParam<Real>("q_liquid")),
74 _p_inf_liquid(getParam<Real>("p_inf_liquid")),
75 _q_prime_liquid(getParam<Real>("q_prime_liquid")),
76
77 _gamma_vapor(getParam<Real>("gamma_vapor")),
78 _cv_vapor(getParam<Real>("cv_vapor")),
79 _cp_vapor(_gamma_vapor * _cv_vapor),
80 _q_vapor(getParam<Real>("q_vapor")),
81 _p_inf_vapor(getParam<Real>("p_inf_vapor")),
82 _q_prime_vapor(getParam<Real>("q_prime_vapor")),
83
84 _T_c(getParam<Real>("T_c")),
85 _p_c(getParam<Real>("p_c")),
86 _T_triple(getParam<Real>("T_triple")),
87 _L_fusion(getParam<Real>("L_fusion")),
88
89 _sigma_A(getParam<Real>("sigma_A")),
90 _sigma_B(getParam<Real>("sigma_B")),
91 _sigma_C(getParam<Real>("sigma_C")),
92
93 _T_sat_min(getParam<Real>("T_sat_min")),
94 _T_sat_max(getParam<Real>("T_sat_max")),
95 _p_sat_guess(getParam<Real>("p_sat_guess")),
96 _n_sat_samples(getParam<unsigned int>("n_sat_samples")),
97 _dT_sat((_T_sat_max - _T_sat_min) / (_n_sat_samples - 1)),
98
99 _A((_cp_liquid - _cp_vapor + _q_prime_vapor - _q_prime_liquid) / (_cp_vapor - _cv_vapor)),
100 _B((_q_liquid - _q_vapor) / (_cp_vapor - _cv_vapor)),
101 _C((_cp_vapor - _cp_liquid) / (_cp_vapor - _cv_vapor)),
102 _D((_cp_liquid - _cv_liquid) / (_cp_vapor - _cv_vapor)),
103
104 _newton_tol(1.0e-8),
105 _newton_max_iter(200)
106{
107 if (_tid == 0)
108 {
109 std::string class_name = "StiffenedGasFluidProperties";
110 InputParameters params = _app.getFactory().getValidParams(class_name);
111 params.set<MooseEnum>("emit_on_nan") = getParam<MooseEnum>("emit_on_nan");
112 params.set<bool>("allow_nonphysical_states") = false;
113 params.set<Real>("gamma") = _gamma_liquid;
114 params.set<Real>("cv") = _cv_liquid;
115 params.set<Real>("q") = _q_liquid;
116 params.set<Real>("p_inf") = _p_inf_liquid;
117 params.set<Real>("q_prime") = _q_prime_liquid;
118 params.set<Real>("k") = getParam<Real>("k_liquid");
119 params.set<Real>("mu") = getParam<Real>("mu_liquid");
120 params.set<Real>("M") = getParam<Real>("M_liquid");
121 _fe_problem.addUserObject(class_name, _liquid_name, params);
122 }
124
125 if (_tid == 0)
126 {
127 std::string class_name = "StiffenedGasFluidProperties";
128 InputParameters params = _app.getFactory().getValidParams(class_name);
129 params.set<MooseEnum>("emit_on_nan") = getParam<MooseEnum>("emit_on_nan");
130 params.set<bool>("allow_nonphysical_states") = false;
131 params.set<Real>("gamma") = _gamma_vapor;
132 params.set<Real>("cv") = _cv_vapor;
133 params.set<Real>("q") = _q_vapor;
134 params.set<Real>("p_inf") = _p_inf_vapor;
135 params.set<Real>("q_prime") = _q_prime_vapor;
136 params.set<Real>("k") = getParam<Real>("k_vapor");
137 params.set<Real>("mu") = getParam<Real>("mu_vapor");
138 params.set<Real>("M") = getParam<Real>("M_vapor");
139 params.set<Real>("T_c") = getParam<Real>("T_c");
140 params.set<Real>("rho_c") = getParam<Real>("rho_c");
141 params.set<Real>("e_c") = getParam<Real>("e_c");
142 _fe_problem.addUserObject(class_name, _vapor_name, params);
143 }
145
146 // calculate the saturation curve p(T) and store the data in two vectors for re-use
147 {
148 _T_vec.resize(_n_sat_samples);
150
151 // loop over sample temperatures, starting with the minimum
152 Real T = _T_sat_min;
153 for (unsigned int i = 0; i < _n_sat_samples; i++)
154 {
155 _T_vec[i] = T;
157
158 // increment sample temperature
159 T += _dT_sat;
160 }
161 }
162
165}
166
167Real
172
173Real
178
179Real
184
185Real
187{
188 return _ipol_temp.sample(pressure);
189}
190
191Real
193{
194 return _ipol_pressure.sample(temperature);
195}
196
197Real
199{
200 Real p_sat = _p_sat_guess;
201 Real f_norm = 1.0e5;
202 unsigned int iter = 1;
203 while (std::fabs(f_norm / p_sat) > _newton_tol)
204 {
205 // check for maximum iteration
206 if (iter > _newton_max_iter)
207 mooseError("StiffenedGasTwoPhaseFluidProperties::compute_p_sat: ",
208 "Newton solve did not converge after ",
210 " iterations.");
211
212 // evaluate nonlinear residual and its derivative w.r.t. p_sat
213 Real f = std::log(p_sat + _p_inf_vapor) - _A - _B / T - _C * std::log(T) -
214 _D * std::log(p_sat + _p_inf_liquid);
215 Real f_prime = 1.0 / (p_sat + _p_inf_vapor) - _D / (p_sat + _p_inf_liquid);
216
217 // take Newton step
218 f_norm = f / f_prime;
219 p_sat -= f_norm;
220
221 iter++;
222 }
223 return p_sat;
224}
225
226Real
228{
229 return _ipol_temp.sampleDerivative(pressure);
230}
231
232Real
234{
235 const Real aux = 1.0 - T / _T_c;
236 return _sigma_A * std::pow(aux, _sigma_B) * (1.0 - _sigma_C * aux);
237}
238
239Real
241{
242 const Real aux = 1.0 - T / _T_c;
243 const Real daux_dT = -1.0 / _T_c;
244 const Real dsigma_daux =
245 _sigma_A * (_sigma_B * std::pow(aux, _sigma_B - 1.0) * (1.0 - _sigma_C * aux) -
246 _sigma_C * std::pow(aux, _sigma_B));
247 return dsigma_daux * daux_dT;
248}
Real f(Real x)
Test function for Brents method.
const double T
registerMooseObject("FluidPropertiesApp", StiffenedGasTwoPhaseFluidProperties)
void ErrorVector unsigned int
T & getUserObject(const std::string &name, unsigned int tid=0) const
virtual std::vector< std::shared_ptr< UserObject > > addUserObject(const std::string &user_object_name, const std::string &name, InputParameters &parameters)
InputParameters getValidParams(const std::string &name) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
void setData(const std::vector< Real > &X, const std::vector< Real > &Y)
T sampleDerivative(const T &x) const
T sample(const T &x) const
Factory & getFactory()
void mooseError(Args &&... args) const
Interface class for producing errors, warnings, or just quiet NaNs.
static InputParameters validParams()
Common class for single phase fluid properties.
Two-phase stiffened gas fluid properties.
const Real & _T_triple
Triple-point temperature.
const unsigned int & _n_sat_samples
Number of samples to take in saturation curve.
virtual Real L_fusion() const override
Returns the latent heat of fusion.
const Real & _T_sat_min
Minimum temperature value in saturation curve.
StiffenedGasTwoPhaseFluidProperties(const InputParameters &parameters)
const Real & _sigma_C
'C' constant used in surface tension correlation
virtual Real dT_sat_dp(Real pressure) const override
Computes dT/dp along the saturation line.
virtual Real sigma_from_T(Real T) const override
Computes surface tension sigma of saturated liquid in contact with saturated vapor.
const unsigned int _newton_max_iter
Newton max number of iterations.
const Real & _sigma_A
'A' constant used in surface tension correlation
virtual Real dsigma_dT_from_T(Real T) const override
Computes dsigma/dT along the saturation line.
const Real & _sigma_B
'B' constant used in surface tension correlation
const Real & _p_sat_guess
Initial guess for saturation pressure Newton solve.
const Real _dT_sat
Temperature increments on saturation curve.
Real compute_p_sat(const Real &T) const
Computes saturation pressure value using Newton solve.
virtual Real T_sat(Real pressure) const override
Computes the saturation temperature at a pressure.
virtual Real p_critical() const override
Returns the critical pressure.
virtual Real p_sat(Real temperature) const override
Computes the saturation pressure at a temperature.
virtual Real T_triple() const override
Returns the triple-point temperature.
Base class for fluid properties used with two-phase flow.
const UserObjectName _liquid_name
The name of the user object that provides liquid phase fluid properties.
const UserObjectName _vapor_name
The name of the user object that provides vapor phase fluid properties.
static InputParameters validParams()
const SinglePhaseFluidProperties * _fp_liquid
The user object that provides liquid phase fluid properties.
const SinglePhaseFluidProperties * _fp_vapor
The user object that provides vapor phase fluid properties.
FEProblemBase & _fe_problem