https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SimpleFluidProperties.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
11#include "NewtonInversion.h"
12
14
17{
19 params.addParam<Real>("molar_mass", 1.8E-2, "Constant molar mass of the fluid (kg/mol)");
20 params.addParam<Real>(
21 "thermal_expansion", 2.14E-4, "Constant coefficient of thermal expansion (1/K)");
22 params.addParam<Real>(
23 "cv", 4186.0, "Constant specific heat capacity at constant volume (J/kg/K)");
24 params.addParam<Real>(
25 "cp", 4194.0, "Constant specific heat capacity at constant pressure (J/kg/K)");
26 params.addRangeCheckedParam<Real>(
27 "bulk_modulus", 2.0E9, "bulk_modulus>0", "Constant bulk modulus (Pa)");
28 params.addParam<Real>("thermal_conductivity", 0.6, "Constant thermal conductivity (W/m/K)");
29 params.addParam<Real>("specific_entropy", 300.0, "Constant specific entropy (J/kg/K)");
30 params.addParam<Real>("viscosity", 1.0E-3, "Constant dynamic viscosity (Pa.s)");
31 params.addParam<Real>("density0", 1000.0, "Density at zero pressure and zero temperature");
32 params.addParam<Real>("porepressure_coefficient",
33 1.0,
34 "The enthalpy is internal_energy + P / density * "
35 "porepressure_coefficient. Physically this should be 1.0, "
36 "but analytic solutions are simplified when it is zero");
37 params.addClassDescription("Fluid properties for a simple fluid with a constant bulk density");
38 return params;
39}
40
42 : SinglePhaseFluidProperties(parameters),
43 _molar_mass(getParam<Real>("molar_mass")),
44 _thermal_expansion(getParam<Real>("thermal_expansion")),
45 _cv(getParam<Real>("cv")),
46 _cp(getParam<Real>("cp")),
47 _bulk_modulus(getParam<Real>("bulk_modulus")),
48 _thermal_conductivity(getParam<Real>("thermal_conductivity")),
49 _specific_entropy(getParam<Real>("specific_entropy")),
50 _viscosity(getParam<Real>("viscosity")),
51 _density0(getParam<Real>("density0")),
52 _pp_coeff(getParam<Real>("porepressure_coefficient"))
53{
54}
55
57
58std::string
60{
61 return "simple_fluid";
62}
63
64Real
69
70Real
71SimpleFluidProperties::beta_from_p_T(Real /*pressure*/, Real /*temperature*/) const
72{
73 return _thermal_expansion;
74}
75
76void
78 Real pressure, Real temperature, Real & beta, Real & dbeta_dp, Real & dbeta_dT) const
79{
80 beta = beta_from_p_T(pressure, temperature);
81 dbeta_dp = 0.0;
82 dbeta_dT = 0.0;
83}
84
85Real
86SimpleFluidProperties::cp_from_p_T(Real /*pressure*/, Real /*temperature*/) const
87{
88 return _cp;
89}
90
91void
93 Real pressure, Real temperature, Real & cp, Real & dcp_dp, Real & dcp_dT) const
94{
95 cp = cp_from_p_T(pressure, temperature);
96 dcp_dp = 0.0;
97 dcp_dT = 0.0;
98}
99
100Real
101SimpleFluidProperties::cp_from_v_e(Real /*v*/, Real /*e*/) const
102{
103 return _cp;
104}
105
106void
107SimpleFluidProperties::cp_from_v_e(Real v, Real e, Real & cp, Real & dcp_dv, Real & dcp_de) const
108{
109 cp = cp_from_v_e(v, e);
110 dcp_dv = 0.0;
111 dcp_de = 0.0;
112}
113
114Real
115SimpleFluidProperties::cv_from_p_T(Real /*pressure*/, Real /*temperature*/) const
116{
117 return _cv;
118}
119
120void
122 Real pressure, Real temperature, Real & cv, Real & dcv_dp, Real & dcv_dT) const
123{
124 cv = cv_from_p_T(pressure, temperature);
125 dcv_dp = 0.0;
126 dcv_dT = 0.0;
127}
128
129Real
130SimpleFluidProperties::cv_from_v_e(Real /*v*/, Real /*e*/) const
131{
132 return _cv;
133}
134
135void
136SimpleFluidProperties::cv_from_v_e(Real v, Real e, Real & cv, Real & dcv_dv, Real & dcv_de) const
137{
138 cv = cv_from_v_e(v, e);
139 dcv_dv = 0.0;
140 dcv_de = 0.0;
141}
142
143Real
144SimpleFluidProperties::c_from_p_T(Real pressure, Real temperature) const
145{
146 return std::sqrt(_bulk_modulus / rho_from_p_T(pressure, temperature));
147}
148
149void
151 Real pressure, Real temperature, Real & c, Real & dc_dp, Real & dc_dT) const
152{
153 c = c_from_p_T(pressure, temperature);
154 dc_dp =
155 -std::exp(_thermal_expansion * temperature - pressure / _bulk_modulus) / 2 / _density0 /
156 std::sqrt(_bulk_modulus *
157 std::exp(_thermal_expansion * temperature - pressure / _bulk_modulus) / _density0);
158 dc_dT =
160 std::exp(_thermal_expansion * temperature - pressure / _bulk_modulus) / 2 / _density0 /
161 std::sqrt(_bulk_modulus *
162 std::exp(_thermal_expansion * temperature - pressure / _bulk_modulus) / _density0);
163}
164
165Real
167{
168 return std::sqrt(_bulk_modulus * v);
169}
170
171void
172SimpleFluidProperties::c_from_v_e(Real v, Real /*e*/, Real & c, Real & dc_dv, Real & dc_de) const
173{
174 c = std::sqrt(_bulk_modulus * v);
175
176 dc_dv = 0.5 * std::sqrt(_bulk_modulus / v);
177 dc_de = 0.0;
178}
179
180Real
181SimpleFluidProperties::k_from_p_T(Real /*pressure*/, Real /*temperature*/) const
182{
184}
185
186void
188 Real /*pressure*/, Real /*temperature*/, Real & k, Real & dk_dp, Real & dk_dT) const
189{
191 dk_dp = 0;
192 dk_dT = 0;
193}
194
195Real
196SimpleFluidProperties::k_from_v_e(Real /*v*/, Real /*e*/) const
197{
199}
200
201void
203 Real /*v*/, Real /*e*/, Real & k, Real & dk_dv, Real & dk_de) const
204{
206 dk_dv = 0;
207 dk_de = 0;
208}
209
210Real
211SimpleFluidProperties::s_from_p_T(Real /*pressure*/, Real /*temperature*/) const
212{
213 return _specific_entropy;
214}
215
216void
218 Real /*p*/, Real /*T*/, Real & s, Real & ds_dp, Real & ds_dT) const
219{
221 ds_dp = 0;
222 ds_dT = 0;
223}
224
225Real
226SimpleFluidProperties::s_from_h_p(Real /*enthalpy*/, Real /*pressure*/) const
227{
228 return _specific_entropy;
229}
230
231Real
232SimpleFluidProperties::s_from_v_e(Real /*v*/, Real /*e*/) const
233{
234 return _specific_entropy;
235}
236
237void
239 Real /*v*/, Real /*e*/, Real & s, Real & ds_dv, Real & ds_de) const
240{
242 ds_dv = 0;
243 ds_de = 0;
244}
245
246Real
247SimpleFluidProperties::rho_from_p_T(Real pressure, Real temperature) const
248{
249 return _density0 * std::exp(pressure / _bulk_modulus - _thermal_expansion * temperature);
250}
251
252void
254 Real pressure, Real temperature, Real & rho, Real & drho_dp, Real & drho_dT) const
255{
256 rho = this->rho_from_p_T(pressure, temperature);
257 drho_dp = rho / _bulk_modulus;
258 drho_dT = -_thermal_expansion * rho;
259}
260
261void
263 const ADReal & temperature,
264 ADReal & rho,
265 ADReal & drho_dp,
266 ADReal & drho_dT) const
267{
268 rho = SinglePhaseFluidProperties::rho_from_p_T(pressure, temperature);
269 drho_dp = rho / _bulk_modulus;
270 drho_dT = -_thermal_expansion * rho;
271}
272
273Real
274SimpleFluidProperties::T_from_v_e(Real /*v*/, Real e) const
275{
276 // NOTE: while e = _cv * T, h is not equal to _cp * T
277 return e / _cv;
278}
279
280Real
282{
283 return (std::log(1. / _density0 / v) - h / v / _bulk_modulus) / -_thermal_expansion /
285}
286
287void
288SimpleFluidProperties::T_from_v_h(Real v, Real h, Real & T, Real & dT_dv, Real & dT_dh) const
289{
290 T = T_from_v_h(v, h);
291 dT_dv =
292 (1 / -_thermal_expansion) *
293 ((-1. / v + h / v / v / _bulk_modulus) * (1 + _cv / v / _thermal_expansion / _bulk_modulus) -
294 (std::log(1. / _density0 / v) - h / v / _bulk_modulus) *
296 Utility::pow<2>(1 + _cv / v / _thermal_expansion / _bulk_modulus);
297 dT_dh = (-1 / v / _bulk_modulus) / -_thermal_expansion /
299}
300
301void
302SimpleFluidProperties::T_from_v_e(Real v, Real e, Real & T, Real & dT_dv, Real & dT_de) const
303{
304 T = T_from_v_e(v, e);
305 dT_dv = 0.0;
306 dT_de = 1.0 / _cv;
307}
308
309void
311 const ADReal & v, const ADReal & e, ADReal & T, ADReal & dT_dv, ADReal & dT_de) const
312{
313 T = SinglePhaseFluidProperties::T_from_v_e(v, e);
314 dT_dv = 0.0;
315 dT_de = 1.0 / _cv;
316}
317
318Real
320{
321 mooseAssert(rho > 0, "Density should be positive");
322 return (std::log(rho / _density0) - p / _bulk_modulus) / -_thermal_expansion;
323}
324
325void
326SimpleFluidProperties::T_from_p_rho(Real p, Real rho, Real & T, Real & dT_dp, Real & dT_drho) const
327{
328 T = T_from_p_rho(p, rho);
329 dT_dp = 1 / (_thermal_expansion * _bulk_modulus);
330 dT_drho = 1 / (-_thermal_expansion * rho);
331}
332
333Real
335{
336 // Likely a better guess than user-selected
337 Real T_initial = h / _cp;
338
339 // exponential dependence in rho and linear dependence in e makes it challenging
340 auto lambda = [&](Real p, Real current_T, Real & new_rho, Real & dh_dp, Real & dh_dT)
341 { h_from_p_T(p, current_T, new_rho, dh_dp, dh_dT); };
343 p, h, T_initial, _tolerance, lambda, name() + "::T_from_p_h", _max_newton_its)
344 .first;
345}
346
347Real
349{
350 Real temperature = T_from_v_e(v, e);
351 return _bulk_modulus * (_thermal_expansion * temperature + std::log(1 / (v * _density0)));
352}
353
354void
355SimpleFluidProperties::p_from_v_e(Real v, Real e, Real & p, Real & dp_dv, Real & dp_de) const
356{
357 p = p_from_v_e(v, e);
358 dp_dv = -_bulk_modulus / v;
360}
361
362void
364 const ADReal & v, const ADReal & e, ADReal & p, ADReal & dp_dv, ADReal & dp_de) const
365{
366 p = SinglePhaseFluidProperties::p_from_v_e(v, e);
367 dp_dv = -_bulk_modulus / v;
369}
370
371Real
373{
374 Real T = T_from_v_h(v, h);
375 return _bulk_modulus * (_thermal_expansion * T + std::log(1 / (v * _density0)));
376}
377
378void
379SimpleFluidProperties::p_from_v_h(Real v, Real h, Real & p, Real & dp_dv, Real & dp_dh) const
380{
381 Real T, dT_dv, dT_dh;
382 T_from_v_h(v, h, T, dT_dv, dT_dh);
383 p = _bulk_modulus * (_thermal_expansion * T + std::log(1 / (v * _density0)));
384 dp_dv = _bulk_modulus * (_thermal_expansion * dT_dv - 1. / v);
385 dp_dh = _bulk_modulus * (_thermal_expansion * dT_dh);
386}
387
388Real
389SimpleFluidProperties::e_from_p_T(Real /*pressure*/, Real temperature) const
390{
391 return _cv * temperature;
392}
393
394void
396 Real pressure, Real temperature, Real & e, Real & de_dp, Real & de_dT) const
397{
398 e = this->e_from_p_T(pressure, temperature);
399 de_dp = 0.0;
400 de_dT = _cv;
401}
402
403Real
405{
406 Real T = T_from_p_rho(p, rho);
407 return e_from_p_T(p, T);
408}
409
410void
411SimpleFluidProperties::e_from_p_rho(Real p, Real rho, Real & e, Real & de_dp, Real & de_drho) const
412{
413 // get temperature and derivatives
414 Real T, dT_dp, dT_drho;
415 T_from_p_rho(p, rho, T, dT_dp, dT_drho);
416
417 // get energy and derivatives
418 Real de_dT;
419 e_from_p_T(p, T, e, de_dp, de_dT);
420 de_dp = de_dT * dT_dp + de_dp;
421 de_drho = de_dT * dT_drho + de_dp * dT_dp;
422}
423
424Real
426{
427 Real T = T_from_v_h(v, h);
428 Real p = p_from_v_h(v, h);
429 return e_from_p_T(p, T);
430}
431
432void
433SimpleFluidProperties::e_from_v_h(Real v, Real h, Real & e, Real & de_dv, Real & de_dh) const
434{
435 Real T, dT_dv, dT_dh;
436 Real p, dp_dv, dp_dh;
437 T_from_v_h(v, h, T, dT_dv, dT_dh);
438 p_from_v_h(v, h, p, dp_dv, dp_dh);
439
440 Real de_dp, de_dT;
441 e_from_p_T(p, T, e, de_dp, de_dT);
442 de_dv = de_dp * dp_dv + de_dT * dT_dv;
443 de_dh = de_dp * dp_dh + de_dT * dT_dh;
444}
445
446Real
447SimpleFluidProperties::mu_from_p_T(Real /*pressure*/, Real /*temperature*/) const
448{
449 return _viscosity;
450}
451
452void
454 Real pressure, Real temperature, Real & mu, Real & dmu_dp, Real & dmu_dT) const
455{
456 mu = this->mu_from_p_T(pressure, temperature);
457 dmu_dp = 0.0;
458 dmu_dT = 0.0;
459}
460
461Real
462SimpleFluidProperties::mu_from_v_e(Real /*v*/, Real /*e*/) const
463{
464 return _viscosity;
465}
466
467void
468SimpleFluidProperties::mu_from_v_e(Real v, Real e, Real & mu, Real & dmu_dv, Real & dmu_de) const
469{
470 mu = this->mu_from_v_e(v, e);
471 dmu_dv = 0.0;
472 dmu_de = 0.0;
473}
474
475Real
476SimpleFluidProperties::h_from_p_T(Real pressure, Real temperature) const
477{
478 return e_from_p_T(pressure, temperature) +
479 _pp_coeff * pressure / rho_from_p_T(pressure, temperature);
480}
481
482void
484 Real pressure, Real temperature, Real & h, Real & dh_dp, Real & dh_dT) const
485{
486 h = this->h_from_p_T(pressure, temperature);
487
488 Real density, ddensity_dp, ddensity_dT;
489 rho_from_p_T(pressure, temperature, density, ddensity_dp, ddensity_dT);
490
491 dh_dp = _pp_coeff / density - _pp_coeff * pressure * ddensity_dp / density / density;
492 dh_dT = _cv - _pp_coeff * pressure * ddensity_dT / density / density;
493}
DualNumber< Real, DNDerivativeType, true > ADReal
const double mu
const Real p
const double rho
const double T
const double v
registerMooseObject("FluidPropertiesApp", SimpleFluidProperties)
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)
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
const std::string & name() const
Fluid properties of a simple, idealised fluid density=density0 * exp(P / bulk_modulus - thermal_expan...
const Real _specific_entropy
specific entropy
virtual Real cv_from_p_T(Real pressure, Real temperature) const override
virtual Real cv_from_v_e(Real v, Real e) const override
virtual Real mu_from_p_T(Real pressure, Real temperature) const override
virtual Real s_from_h_p(Real h, Real p) const override
virtual Real beta_from_p_T(Real pressure, Real temperature) const override
virtual Real k_from_v_e(Real v, Real e) const override
virtual Real e_from_p_rho(Real pressure, Real rho) const override
virtual Real h_from_p_T(Real p, Real T) const override
static InputParameters validParams()
const Real _thermal_conductivity
thermal conductivity
virtual Real s_from_v_e(Real v, Real e) const override
virtual Real T_from_v_h(Real v, Real h) const
virtual Real cp_from_v_e(Real v, Real e) const override
virtual Real e_from_v_h(Real v, Real h) const override
virtual Real rho_from_p_T(Real pressure, Real temperature) const override
const Real _thermal_expansion
thermal expansion coefficient
virtual Real T_from_p_rho(Real p, Real rho) const
virtual std::string fluidName() const override
Fluid name.
const Real _molar_mass
molar mass
virtual Real p_from_v_e(Real v, Real e) const override
const Real _viscosity
viscosity
virtual Real molarMass() const override
Molar mass [kg/mol].
virtual Real T_from_v_e(Real v, Real e) const override
virtual Real k_from_p_T(Real pressure, Real temperature) const override
virtual Real T_from_p_h(Real p, Real h) const override
virtual Real c_from_p_T(Real pressure, Real temperature) const override
const Real _density0
density at zero pressure and temperature
SimpleFluidProperties(const InputParameters &parameters)
virtual Real c_from_v_e(Real v, Real e) const override
const Real _cv
specific heat at constant volume
const Real _cp
specific heat at constant pressure
virtual Real s_from_p_T(Real pressure, Real temperature) const override
virtual Real p_from_v_h(Real v, Real h) const
virtual Real e_from_p_T(Real pressure, Real temperature) const override
virtual Real cp_from_p_T(Real pressure, Real temperature) const override
const Real _pp_coeff
Porepressure coefficient: enthalpy = internal_energy + porepressure / density * _pp_coeff.
virtual Real mu_from_v_e(Real v, Real e) const override
const Real _bulk_modulus
bulk modulus
Common class for single phase fluid properties.
static InputParameters validParams()
const Real _tolerance
Newton's method may be used to convert between variable sets.
const unsigned int _max_newton_its
Maximum number of iterations for the variable conversion newton solves.
e e e e s T T T T T rho v v T e h
std::pair< T, T > NewtonSolve(const T &x, const T &y, const Real z_initial_guess, const Real tolerance, const Functor &y_from_x_z, const std::string &caller_name, const unsigned int max_its=100, const bool verbose=false)
NewtonSolve does a 1D Newton Solve to solve the equation y = f(x, z) for variable z.