https://mooseframework.inl.gov
Loading...
Searching...
No Matches
NASA7IdealGasFluidProperties.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
13
16{
18
20 params.addRequiredParam<MooseEnum>("species", species, "Gas species");
21
22 // The temperature inversions start at the upper end of the temperature range of the data, and
23 // none of them needs a pressure guess
24 params.suppressParameter<Real>("T_initial_guess");
25 params.suppressParameter<Real>("p_initial_guess");
26
27 params.addClassDescription("Ideal gas with temperature-dependent heat capacity, enthalpy, and "
28 "entropy from NASA 7-coefficient polynomials");
29
30 return params;
31}
32
34 : SinglePhaseFluidProperties(parameters),
35 _data(NASA7::speciesData(getParam<MooseEnum>("species"))),
36 _R_specific(_R / _data.molar_mass),
37 _lennard_jones(GasTransportUtils::lennardJonesParameters(_data.name)),
38 _is_steam(_data.name == "H2O"),
39 _is_helium(_data.name == "He")
40{
41}
42
43std::string
48
49Real
54
55Real
57{
58 // The internal energy is convex in temperature over nearly all of the range of the data, so
59 // Newton's method started above the solution approaches it from above (see T_from_energy)
60 return _data.T_max;
61}
62
68
69template <typename CppType>
70void
72{
73 const auto T_raw = MetaPhysicL::raw_value(T);
74 if (std::isnan(T_raw) || T_raw <= 0)
75 flagInvalidSolution("Non-positive or not-a-number temperature");
76 else if (T_raw < _data.T_min || T_raw > _data.T_max)
77 flagSolutionWarning(
78 "Temperature outside the range of the NASA-7 data; the polynomials are extrapolated");
79}
80
81template <typename CppType>
82void
84{
86 // Range of validity of the IAPWS 2008 viscosity and IAPWS 2011 thermal conductivity
87 // formulations: from the triple point to 1173.15 K
88 const auto T_raw = MetaPhysicL::raw_value(T);
89 if (_is_steam && (T_raw < 273.16 || T_raw > 1173.15))
90 flagSolutionWarning("Temperature outside the range of validity of the IAPWS transport "
91 "formulations for steam");
92 // Range of validity of the helium correlations of Petersen (1970)
93 if (_is_helium && (T_raw < 273.15 || T_raw > 1800))
94 flagSolutionWarning("Temperature outside the range of validity of the transport correlations "
95 "for helium");
96}
97
98template <typename CppType>
99CppType
101{
103 return _R_specific * T * (NASA7::hOverRT(_data, T) - 1);
104}
105
106template <typename CppType>
107CppType
109{
111 return _R_specific * T * NASA7::hOverRT(_data, T);
112}
113
114template <typename CppType>
115CppType
117{
120}
121
122template <typename CppType>
123CppType
125{
127 return _R_specific * (NASA7::cpOverR(_data, T) - 1);
128}
129
130template <typename CppType>
131CppType
133{
135 const auto cp_R = NASA7::cpOverR(_data, T);
136 return cp_R / (cp_R - 1);
137}
138
139template <typename CppType>
140CppType
142{
144 if (_is_steam)
146 // The reduced temperature of helium exceeds the range of the collision integral fits above
147 // about 1000 K, and the Chapman-Enskog viscosity is then up to 8% low at 1500 K
148 if (_is_helium)
151}
152
153template <typename CppType>
154CppType
156{
158 // The modified Eucken correlation overestimates the conductivity of polar gases, that of steam
159 // by 20% to 40%
160 if (_is_steam)
162 if (_is_helium)
168}
169
170template <typename CppType>
171CppType
172NASA7IdealGasFluidProperties::rho_from_p_T_template(const CppType & p, const CppType & T) const
173{
174 return p / (_R_specific * T);
175}
176
177template <typename CppType>
178CppType
179NASA7IdealGasFluidProperties::v_from_p_T_template(const CppType & p, const CppType & T) const
180{
181 return _R_specific * T / p;
182}
183
184template <typename CppType>
185CppType
186NASA7IdealGasFluidProperties::e_from_p_T_template(const CppType & /*p*/, const CppType & T) const
187{
188 return e_from_T(T);
189}
190
191template <typename CppType>
192CppType
193NASA7IdealGasFluidProperties::h_from_p_T_template(const CppType & /*p*/, const CppType & T) const
194{
195 return h_from_T(T);
196}
197
198template <typename CppType>
199CppType
200NASA7IdealGasFluidProperties::s_from_p_T_template(const CppType & p, const CppType & T) const
201{
202 using std::log;
205}
206
207template <typename CppType>
208CppType
209NASA7IdealGasFluidProperties::cp_from_p_T_template(const CppType & /*p*/, const CppType & T) const
210{
211 return cp_from_T(T);
212}
213
214template <typename CppType>
215CppType
216NASA7IdealGasFluidProperties::cv_from_p_T_template(const CppType & /*p*/, const CppType & T) const
217{
218 return cv_from_T(T);
219}
220
221template <typename CppType>
222CppType
223NASA7IdealGasFluidProperties::c_from_p_T_template(const CppType & /*p*/, const CppType & T) const
224{
225 using std::sqrt;
226 return sqrt(gamma_from_T(T) * _R_specific * T);
227}
228
229template <typename CppType>
230CppType
231NASA7IdealGasFluidProperties::gamma_from_p_T_template(const CppType & /*p*/,
232 const CppType & T) const
233{
234 return gamma_from_T(T);
235}
236
237template <typename CppType>
238CppType
239NASA7IdealGasFluidProperties::mu_from_p_T_template(const CppType & /*p*/, const CppType & T) const
240{
241 return mu_from_T(T);
242}
243
244template <typename CppType>
245CppType
246NASA7IdealGasFluidProperties::k_from_p_T_template(const CppType & /*p*/, const CppType & T) const
247{
248 return k_from_T(T);
249}
250
251template <typename CppType>
252CppType
253NASA7IdealGasFluidProperties::p_from_T_v_template(const CppType & T, const CppType & v) const
254{
255 return _R_specific * T / v;
256}
257
258template <typename CppType>
259CppType
260NASA7IdealGasFluidProperties::e_from_T_v_template(const CppType & T, const CppType & /*v*/) const
261{
262 return e_from_T(T);
263}
264
265template <typename CppType>
266CppType
267NASA7IdealGasFluidProperties::h_from_T_v_template(const CppType & T, const CppType & /*v*/) const
268{
269 return h_from_T(T);
270}
271
272template <typename CppType>
273CppType
274NASA7IdealGasFluidProperties::s_from_T_v_template(const CppType & T, const CppType & v) const
275{
276 return s_from_p_T_template(p_from_T_v_template(T, v), T);
277}
278
279template <typename CppType>
280CppType
281NASA7IdealGasFluidProperties::cv_from_T_v_template(const CppType & T, const CppType & /*v*/) const
282{
283 return cv_from_T(T);
284}
285
286template <typename CppType>
287CppType
288NASA7IdealGasFluidProperties::e_from_p_rho_template(const CppType & p, const CppType & rho) const
289{
290 return e_from_T(p / (rho * _R_specific));
291}
292
293template <typename CppType>
294CppType
295NASA7IdealGasFluidProperties::T_from_energy(const CppType & y, const Real k) const
296{
297 // Start at the upper end of the temperature range of the data. y(T) is convex over nearly all of
298 // that range, because the heat capacity increases with temperature, so Newton's method started
299 // above the solution approaches it from above. Started below it, the first step can overshoot
300 // far beyond the range, where the extrapolated polynomials eventually give dy/dT <= 0 and a
301 // second, spurious solution. For the built-in species, this start finds the solution up to at
302 // least 1.7 T_max.
303 const Real T0 = _data.T_max;
304
305 // The energies include the enthalpy of formation, so they can be close to zero, where the
306 // convergence test of NewtonSolve, which is relative to the target value, would demand accuracy
307 // below roundoff. Solve y(T) + shift = y + shift instead, with the shift (dy/dT) T - y(T) at T0.
308 // Both sides are then close to (dy/dT) T, and the convergence test bounds the relative error in
309 // temperature.
310 const Real shift = _R_specific * T0 * (NASA7::cpOverR(_data, T0) - NASA7::hOverRT(_data, T0));
311
312 const auto shifted_y = [this, k, shift](const CppType & /*y*/,
313 const CppType & T,
314 CppType & y_T,
315 CppType & dy_T_dy,
316 CppType & dy_T_dT)
317 {
318 y_T = _R_specific * T * (NASA7::hOverRT(_data, T) - k) + shift;
319 dy_T_dy = 0;
320 dy_T_dT = _R_specific * (NASA7::cpOverR(_data, T) - k);
321 };
322
323 const CppType target = y + shift;
325 target,
326 T0,
328 shifted_y,
329 name() + "::T_from_energy",
332 .first;
333}
334
335template <typename CppType>
336CppType
337NASA7IdealGasFluidProperties::T_from_v_e_template(const CppType & /*v*/, const CppType & e) const
338{
339 const auto T = T_from_energy(e, 1);
341 return T;
342}
343
344template <typename CppType>
345CppType
346NASA7IdealGasFluidProperties::p_from_v_e_template(const CppType & v, const CppType & e) const
347{
348 const auto T = T_from_energy(e, 1);
350 return _R_specific * T / v;
351}
352
353template <typename CppType>
354CppType
355NASA7IdealGasFluidProperties::c_from_v_e_template(const CppType & /*v*/, const CppType & e) const
356{
357 using std::sqrt;
358 const auto T = T_from_energy(e, 1);
359 return sqrt(gamma_from_T(T) * _R_specific * T);
360}
361
362template <typename CppType>
363CppType
364NASA7IdealGasFluidProperties::cp_from_v_e_template(const CppType & /*v*/, const CppType & e) const
365{
366 return cp_from_T(T_from_energy(e, 1));
367}
368
369template <typename CppType>
370CppType
371NASA7IdealGasFluidProperties::cv_from_v_e_template(const CppType & /*v*/, const CppType & e) const
372{
373 return cv_from_T(T_from_energy(e, 1));
374}
375
376template <typename CppType>
377CppType
378NASA7IdealGasFluidProperties::gamma_from_v_e_template(const CppType & /*v*/,
379 const CppType & e) const
380{
381 return gamma_from_T(T_from_energy(e, 1));
382}
383
384template <typename CppType>
385CppType
386NASA7IdealGasFluidProperties::s_from_v_e_template(const CppType & v, const CppType & e) const
387{
388 return s_from_T_v_template(T_from_energy(e, 1), v);
389}
390
391template <typename CppType>
392CppType
393NASA7IdealGasFluidProperties::g_from_v_e_template(const CppType & v, const CppType & e) const
394{
395 using std::log;
396 const auto T = T_from_energy(e, 1);
398 const auto p = _R_specific * T / v;
399 // g = h - T s
400 return _R_specific * T *
402}
403
404template <typename CppType>
405CppType
406NASA7IdealGasFluidProperties::mu_from_v_e_template(const CppType & /*v*/, const CppType & e) const
407{
408 return mu_from_T(T_from_energy(e, 1));
409}
410
411template <typename CppType>
412CppType
413NASA7IdealGasFluidProperties::k_from_v_e_template(const CppType & /*v*/, const CppType & e) const
414{
415 return k_from_T(T_from_energy(e, 1));
416}
417
418template <typename CppType>
419CppType
420NASA7IdealGasFluidProperties::T_from_p_h_template(const CppType & /*p*/, const CppType & h) const
421{
422 const auto T = T_from_energy(h, 0);
424 return T;
425}
426
427template <typename CppType>
428CppType
429NASA7IdealGasFluidProperties::s_from_h_p_template(const CppType & h, const CppType & p) const
430{
431 return s_from_p_T_template(p, T_from_energy(h, 0));
432}
433
434template <typename CppType>
435CppType
436NASA7IdealGasFluidProperties::p_from_h_s_template(const CppType & h, const CppType & s) const
437{
438 using std::exp;
439 const auto T = T_from_energy(h, 0);
441 // Inverse of s = R_s (s0/R - ln(p / p_ref))
443}
444
445template <typename CppType>
446CppType
447NASA7IdealGasFluidProperties::e_from_v_h_template(const CppType & /*v*/, const CppType & h) const
448{
449 const auto T = T_from_energy(h, 0);
451 return h - _R_specific * T;
452}
453
454template <typename CppType>
455CppType
456NASA7IdealGasFluidProperties::T_from_p_s(const CppType & p, const CppType & s) const
457{
458 using std::exp, std::log;
459
460 // Solve s0(T)/R = s/R_s + ln(p/p_ref) for x = ln(T). The standard entropy s0/R increases with x,
461 // with slope cp/R, and is convex in x over nearly all of the range of the data, because the heat
462 // capacity increases with temperature, so Newton's method started at the upper end of the range
463 // approaches the solution from above. In T instead of ln(T), the first step from the upper end
464 // would overshoot to negative temperatures for solutions near the lower end.
465 const CppType target = s / _R_specific + log(p / NASA7::reference_pressure);
466 const auto s0_from_x = [this](const CppType & /*target*/,
467 const CppType & x,
468 CppType & s0_x,
469 CppType & ds0_x_dtarget,
470 CppType & ds0_x_dx)
471 {
472 const CppType T = exp(x);
473 s0_x = NASA7::sOverR(_data, T);
474 ds0_x_dtarget = 0;
475 ds0_x_dx = NASA7::cpOverR(_data, T);
476 };
477
478 return exp(FluidPropertiesUtils::NewtonSolve(target,
479 target,
480 std::log(_data.T_max),
482 s0_from_x,
483 name() + "::T_from_p_s",
486 .first);
487}
488
489template <typename CppType>
490CppType
491NASA7IdealGasFluidProperties::rho_from_p_s_template(const CppType & p, const CppType & s) const
492{
493 const auto T = T_from_p_s(p, s);
495 return p / (_R_specific * T);
496}
497
502#define definePropertyFromTemplate(want, prop1, prop2) \
503 template <typename CppType> \
504 void NASA7IdealGasFluidProperties::want##_from_##prop1##_##prop2##_template( \
505 const CppType & prop1, \
506 const CppType & prop2, \
507 CppType & val, \
508 CppType & d##want##d1, \
509 CppType & d##want##d2) const \
510 { \
511 const auto value = [this](const auto & x, const auto & y) \
512 { return this->want##_from_##prop1##_##prop2##_template(x, y); }; \
513 xyDerivatives(prop1, prop2, val, d##want##d1, d##want##d2, value); \
514 } \
515 \
516 Real NASA7IdealGasFluidProperties::want##_from_##prop1##_##prop2(Real prop1, Real prop2) const \
517 { \
518 return want##_from_##prop1##_##prop2##_template(prop1, prop2); \
519 } \
520 \
521 ADReal NASA7IdealGasFluidProperties::want##_from_##prop1##_##prop2(const ADReal & prop1, \
522 const ADReal & prop2) const \
523 { \
524 return want##_from_##prop1##_##prop2##_template(prop1, prop2); \
525 } \
526 \
527 void NASA7IdealGasFluidProperties::want##_from_##prop1##_##prop2( \
528 Real prop1, Real prop2, Real & val, Real & d##want##d1, Real & d##want##d2) const \
529 { \
530 want##_from_##prop1##_##prop2##_template(prop1, prop2, val, d##want##d1, d##want##d2); \
531 } \
532 \
533 void NASA7IdealGasFluidProperties::want##_from_##prop1##_##prop2(const ADReal & prop1, \
534 const ADReal & prop2, \
535 ADReal & val, \
536 ADReal & d##want##d1, \
537 ADReal & d##want##d2) const \
538 { \
539 want##_from_##prop1##_##prop2##_template(prop1, prop2, val, d##want##d1, d##want##d2); \
540 }
541
542// clang-format off
543definePropertyFromTemplate(rho, p, T)
544definePropertyFromTemplate(v, p, T)
545definePropertyFromTemplate(e, p, T)
546definePropertyFromTemplate(h, p, T)
547definePropertyFromTemplate(s, p, T)
548definePropertyFromTemplate(cp, p, T)
549definePropertyFromTemplate(cv, p, T)
550definePropertyFromTemplate(c, p, T)
551definePropertyFromTemplate(gamma, p, T)
552definePropertyFromTemplate(mu, p, T)
553definePropertyFromTemplate(k, p, T)
554definePropertyFromTemplate(p, T, v)
555definePropertyFromTemplate(e, T, v)
556definePropertyFromTemplate(h, T, v)
557definePropertyFromTemplate(s, T, v)
558definePropertyFromTemplate(cv, T, v)
559definePropertyFromTemplate(e, p, rho)
560definePropertyFromTemplate(T, v, e)
561definePropertyFromTemplate(p, v, e)
562definePropertyFromTemplate(c, v, e)
563definePropertyFromTemplate(cp, v, e)
564definePropertyFromTemplate(cv, v, e)
565definePropertyFromTemplate(gamma, v, e)
566definePropertyFromTemplate(s, v, e)
567definePropertyFromTemplate(g, v, e)
568definePropertyFromTemplate(mu, v, e)
569definePropertyFromTemplate(k, v, e)
570definePropertyFromTemplate(T, p, h)
571definePropertyFromTemplate(s, h, p)
572definePropertyFromTemplate(p, h, s)
573definePropertyFromTemplate(e, v, h)
574definePropertyFromTemplate(rho, p, s)
575// clang-format on
576
577#undef definePropertyFromTemplate
const std::vector< double > y
const std::vector< double > x
const double mu
const Real p
const double rho
const double T
const double v
registerMooseObject("FluidPropertiesApp", NASA7IdealGasFluidProperties)
const std::string name
Definition Setup.h:21
void suppressParameter(const std::string &name)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
const std::string & name() const
Ideal gas whose heat capacity, enthalpy, and entropy depend on temperature through NASA 7-coefficient...
const NASA7::SpeciesData _data
NASA 7-coefficient data of the species.
NASA7IdealGasFluidProperties(const InputParameters &parameters)
const bool _is_helium
Whether the species is helium, whose viscosity and thermal conductivity come from Petersen.
CppType T_from_energy(const CppType &y, const Real k) const
Temperature at which R_s T (h/(RT) - k) equals y, by Newton's method: k = 1 for the specific internal...
const bool _is_steam
Whether the species is steam, whose viscosity and thermal conductivity come from IAPWS.
std::string fluidName() const override
Fluid name.
CppType gamma_from_T(const CppType &T) const
CppType mu_from_T(const CppType &T) const
CppType T_from_p_s(const CppType &p, const CppType &s) const
Temperature at which the specific entropy at pressure p equals s, by Newton's method on the logarithm...
void checkTemperature(const CppType &T) const
Flags a temperature outside the range of the data as a solution warning, because the polynomials are ...
CppType cp_from_T(const CppType &T) const
CppType k_from_T(const CppType &T) const
Real molarMass() const override
Molar mass [kg/mol].
CppType e_from_T(const CppType &T) const
Properties that depend on temperature only.
CppType h_from_T(const CppType &T) const
CppType cv_from_T(const CppType &T) const
void checkTransportTemperature(const CppType &T) const
Checks the temperature as checkTemperature does and, for steam, also flags a temperature outside the ...
const GasTransportUtils::LennardJonesParameters _lennard_jones
Lennard-Jones parameters of the species.
virtual const GasTransportUtils::LennardJonesParameters * lennardJonesParameters() const override
Lennard-Jones parameters of the gas, from which a mixture computes binary diffusion coefficients,...
const Real _R_specific
Specific gas constant [J/(kg K)].
virtual Real newtonStartTemperature() const override
The upper end of the temperature range of the NASA 7-coefficient data [K].
Common class for single phase fluid properties.
const bool _verbose_newton
Whether to output information about newton solves to console.
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
auto exp(const T &)
auto log(const T &)
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
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.
Transport properties of dilute gases: Lennard-Jones parameters of the NASA 7-coefficient species,...
CppType heliumConductivityZeroPressure(const CppType &T)
Thermal conductivity of helium in the limit of zero pressure [W/(m K)], from the correlation of Peter...
CppType modifiedEuckenConductivity(const CppType &mu, const CppType &cp_over_R, const Real R_specific)
Thermal conductivity of a dilute gas from the modified Eucken correlation [W/(m K)],...
CppType steamViscosityZeroDensity(const CppType &T)
Viscosity of steam in the limit of zero density [Pa s], from the IAPWS 2008 formulation,...
CppType steamConductivityZeroDensity(const CppType &T)
Thermal conductivity of steam in the limit of zero density [W/(m K)], from the IAPWS 2011 formulation...
CppType viscosity(const CppType &T, const Real molar_mass, const LennardJonesParameters &lj)
Chapman-Enskog viscosity of a dilute gas [Pa s].
CppType heliumViscosity(const CppType &T)
Viscosity of helium [Pa s], from the correlation of Petersen (1970), as in HeliumFluidProperties.
auto raw_value(const Eigen::Map< T > &in)
Standard-state thermodynamic properties of ideal-gas species from NASA 7-coefficient polynomials.
CppType hOverRT(const SpeciesData &data, const CppType &T)
Standard-state molar enthalpy divided by the gas constant and temperature, h/(RT)
CppType cpOverR(const SpeciesData &data, const CppType &T)
Standard-state molar isobaric heat capacity divided by the gas constant, cp/R.
CppType sOverR(const SpeciesData &data, const CppType &T)
Standard-state molar entropy divided by the gas constant, s/R, at the reference pressure of the data ...
constexpr Real reference_pressure
Pressure at which the standard-state entropy of the built-in species applies [Pa].
std::string speciesNames()
Names of the built-in species, separated by spaces.
Parameters of the Lennard-Jones (12-6) potential of a species.
Real T_max
Upper end of the temperature range of the fit [K].
std::string name
Species name, e.g. "H2O".
Real molar_mass
Molar mass [kg/mol].