14#include "metaphysicl/dualnumberarray.h"
21#define propfuncAD(want, prop1, prop2) \
22 virtual ADReal want##_from_##prop1##_##prop2(const ADReal & p1, const ADReal & p2) const \
25 Real raw1 = p1.value(); \
26 Real raw2 = p2.value(); \
29 want##_from_##prop1##_##prop2(raw1, raw2, x, dxd1, dxd2); \
32 result.derivatives() = p1.derivatives() * dxd1 + p2.derivatives() * dxd2; \
36 virtual void want##_from_##prop1##_##prop2(const ADReal & prop1, \
37 const ADReal & prop2, \
39 ADReal & d##want##d1, \
40 ADReal & d##want##d2) const \
42 unimplementedDerivativeMethod(__PRETTY_FUNCTION__); \
43 Real dummy, tmp1, tmp2; \
44 val = want##_from_##prop1##_##prop2(prop1, prop2); \
45 want##_from_##prop1##_##prop2(prop1.value(), prop2.value(), dummy, tmp1, tmp2); \
54#define propfunc(want, prop1, prop2) \
55 virtual Real want##_from_##prop1##_##prop2(Real, Real) const \
58 "The fluid properties class '", \
60 "' has not implemented the method below. If your application requires this method, you " \
61 "must either implement it or use a different fluid properties class.\n\n", \
62 __PRETTY_FUNCTION__); \
65 virtual void want##_from_##prop1##_##prop2( \
66 Real prop1, Real prop2, Real & val, Real & d##want##d1, Real & d##want##d2) const \
68 unimplementedDerivativeMethod(__PRETTY_FUNCTION__); \
71 val = want##_from_##prop1##_##prop2(prop1, prop2); \
74 propfuncAD(want, prop1, prop2)
81#define propfuncWithDefault(want, prop1, prop2) \
82 virtual Real want##_from_##prop1##_##prop2(Real, Real) const; \
83 virtual void want##_from_##prop1##_##prop2( \
84 Real prop1, Real prop2, Real & val, Real & d##want##d1, Real & d##want##d2) const; \
86 propfuncAD(want, prop1, prop2)
91#define propfuncWithDefinitionOverride(want, prop1, prop2) \
92 Real want##_from_##prop1##_##prop2(Real, Real) const override; \
93 void want##_from_##prop1##_##prop2( \
94 Real prop1, Real prop2, Real & val, Real & d##want##d1, Real & d##want##d2) const override; \
95 ADReal want##_from_##prop1##_##prop2(const ADReal &, const ADReal &) const override; \
96 void want##_from_##prop1##_##prop2(const ADReal & prop1, \
97 const ADReal & prop2, \
99 ADReal & d##want##d1, \
100 ADReal & d##want##d2) const override; \
101 template <typename CppType> \
102 CppType want##_from_##prop1##_##prop2##_template(const CppType & prop1, const CppType & prop2) \
104 template <typename CppType> \
105 void want##_from_##prop1##_##prop2##_template(const CppType & prop1, \
106 const CppType & prop2, \
108 CppType & d##want##d1, \
109 CppType & d##want##d2) const
122#pragma GCC diagnostic push
123#pragma GCC diagnostic ignored "-Woverloaded-virtual"
224#undef propfuncWithDefault
301 virtual void vaporPressure(Real
T, Real & psat, Real & dpsat_dT)
const;
323 template <
typename CppType>
324 void v_e_from_p_T(
const CppType &
p,
const CppType &
T, CppType &
v, CppType & e)
const;
325 template <
typename CppType>
333 CppType & de_dT)
const;
351 Real & dmu_dT)
const;
374 template <
typename CppType>
381 bool & conversion_succeeded)
const;
394 template <
typename T>
401 bool & conversion_succeeded)
const;
413 template <
typename T>
420 bool & conversion_succeeded)
const;
428 template <
typename T,
typename Functor>
436 template <
typename T>
456 const std::string message =
457 "The fluid properties class '" +
type() +
458 "' has not implemented the method below, which computes derivatives of fluid properties "
459 "with regards to the flow variables. If your application requires this "
460 "method, you must either implement it or use a different fluid properties "
462 property_function_name;
465 mooseDoOnce(
mooseWarning(message +
"\nThe unimplemented derivatives for this fluid property "
466 "are currently neglected, set to 0."));
468 mooseError(message +
"\n\nYou can avoid this error by neglecting the "
469 "unimplemented derivatives of fluid properties by setting the "
470 "'allow_imperfect_jacobians' parameter");
474#pragma GCC diagnostic pop
480 return {
T{0, 0},
T{1, 0}};
484inline std::pair<Real, Real>
487 return {Real{0}, Real{1}};
490template <
typename T,
typename Functor>
493 const T x,
const T &
y,
T & z,
T & dz_dx,
T & dz_dy,
const Functor & z_from_x_y)
498 CompoundType x_c(
x, zero);
499 auto & x_cd = x_c.derivatives();
501 CompoundType y_c(
y, zero);
502 auto & y_cd = y_c.derivatives();
505 const auto z_c = z_from_x_y(x_c, y_c);
507 dz_dx = z_c.derivatives()[0];
508 dz_dy = z_c.derivatives()[1];
511template <
typename CppType>
519 bool & conversion_succeeded)
const
521 auto v_lambda = [&](
const CppType & pressure,
522 const CppType & temperature,
525 CppType & dv_dT) { v_from_p_T(pressure, temperature, new_v, dv_dp, dv_dT); };
526 auto e_lambda = [&](
const CppType & pressure,
527 const CppType & temperature,
530 CppType & de_dT) { e_from_p_T(pressure, temperature, new_e, de_dp, de_dT); };
546 conversion_succeeded =
true;
550 conversion_succeeded =
false;
553 if (!conversion_succeeded)
554 mooseDoOnce(
mooseWarning(
"Conversion from (v, e)=(",
v,
", ", e,
") to (p, T) failed"));
565 bool & conversion_succeeded)
const
567 auto v_lambda = [&](
const T & pressure,
const T & temperature,
T & new_v,
T & dv_dp,
T & dv_dT)
568 { v_from_p_T(pressure, temperature, new_v, dv_dp, dv_dT); };
569 auto h_lambda = [&](
const T & pressure,
const T & temperature,
T & new_h,
T & dh_dp,
T & dh_dT)
570 { h_from_p_T(pressure, temperature, new_h, dh_dp, dh_dT); };
586 conversion_succeeded =
true;
590 conversion_succeeded =
false;
593 if (!conversion_succeeded)
594 mooseDoOnce(
mooseWarning(
"Conversion from (v, h)=(",
v,
", ",
h,
") to (p, T) failed"));
605 bool & conversion_succeeded)
const
607 auto h_lambda = [&](
const T & pressure,
const T & temperature,
T & new_h,
T & dh_dp,
T & dh_dT)
608 { h_from_p_T(pressure, temperature, new_h, dh_dp, dh_dT); };
609 auto s_lambda = [&](
const T & pressure,
const T & temperature,
T & new_s,
T & ds_dp,
T & ds_dT)
610 { s_from_p_T(pressure, temperature, new_s, ds_dp, ds_dT); };
626 conversion_succeeded =
true;
630 conversion_succeeded =
false;
633 if (!conversion_succeeded)
634 mooseDoOnce(
mooseWarning(
"Conversion from (h, s)=(",
h,
", ", s,
") to (p, T) failed"));
637template <
typename CppType>
644 const CppType
rho = rho_from_p_T(
p,
T);
649 e = e_from_p_T(
p,
T);
653 e = e_from_p_rho(
p,
rho);
657template <
typename CppType>
666 CppType & de_dT)
const
668 CppType
rho, drho_dp, drho_dT;
669 rho_from_p_T(
p,
T,
rho, drho_dp, drho_dT);
672 const CppType dv_drho = -1.0 / (
rho *
rho);
673 dv_dp = dv_drho * drho_dp;
674 dv_dT = dv_drho * drho_dT;
676 CppType de_dp_partial, de_drho;
677 e_from_p_rho(
p,
rho, e, de_dp_partial, de_drho);
678 de_dp = de_dp_partial + de_drho * drho_dp;
679 de_dT = de_drho * drho_dT;
DualNumber< Real, DNDerivativeType, true > ADReal
const std::vector< double > y
const std::vector< double > x
const bool _allow_imperfect_jacobians
Flag to set unimplemented Jacobian entries to zero.
const InputParameters & parameters() const
const std::string & type() const
void mooseError(Args &&... args) const
void mooseWarning(Args &&... args) const
Common class for single phase fluid properties.
virtual std::vector< Real > henryCoefficients() const
Henry's law coefficients for dissolution in water.
const Real _T_initial_guess
Initial guess for temperature (or temperature used to compute the initial guess)
void p_T_from_h_s(const T &h, const T &s, Real p0, Real T0, T &pressure, T &temperature, bool &conversion_succeeded) const
Determines (p,T) from (h,s) using Newton Solve in 2D Useful for conversion between different sets of ...
propfunc(p, v, e) propfunc(T
Compute a fluid property given for the state defined by two given properties.
virtual Real criticalInternalEnergy() const
Critical specific internal energy.
const bool _verbose_newton
Whether to output information about newton solves to console.
void p_T_from_v_e(const CppType &v, const CppType &e, Real p0, Real T0, CppType &p, CppType &T, bool &conversion_succeeded) const
Determines (p,T) from (v,e) using Newton Solve in 2D Useful for conversion between different sets of ...
static std::pair< T, T > makeZeroAndOne(const T &)
Given a type example, this method returns zero and unity representations of that type (first and seco...
const Real _p_initial_guess
Initial guess for pressure (or pressure used to compute the initial guess)
virtual void v_e_spndl_from_T(Real T, Real &v, Real &e) const
Specific internal energy from temperature and specific volume.
virtual Real vaporPressure(Real T) const
Vapor pressure.
static InputParameters validParams()
e e e e s T T T T T rho T
const Real _tolerance
Newton's method may be used to convert between variable sets.
virtual void rho_e_from_p_T(Real p, Real T, Real &rho, Real &drho_dp, Real &drho_dT, Real &e, Real &de_dp, Real &de_dT) const
virtual ~SinglePhaseFluidProperties()
virtual Real triplePointPressure() const
Triple point pressure.
virtual Real e_spndl_from_v(Real v) const
Specific internal energy from temperature and specific volume.
virtual Real criticalDensity() const
Critical density.
virtual Real criticalPressure() const
Critical pressure.
const unsigned int _max_newton_its
Maximum number of iterations for the variable conversion newton solves.
void p_T_from_v_h(const T &v, const T &h, Real p0, Real T0, T &pressure, T &temperature, bool &conversion_succeeded) const
Determines (p,T) from (v,h) using Newton Solve in 2D Useful for conversion between different sets of ...
virtual Real molarMass() const
Molar mass [kg/mol].
void unimplementedDerivativeMethod(const std::string &property_function_name) const
void v_e_from_p_T(const CppType &p, const CppType &T, CppType &v, CppType &e) const
e e e e s T T T propfuncWithDefault(cp, p, T) propfuncWithDefault(cv
e e e e s T T T T T rho v v T e h
virtual Real criticalTemperature() const
Critical temperature.
virtual Real triplePointTemperature() const
Triple point temperature.
virtual Real vaporTemperature(Real p) const
Vapor temperature.
static void xyDerivatives(const T x, const T &y, T &z, T &dz_dx, T &dz_dy, const Functor &z_from_x_y)
Computes the dependent variable z and its derivatives with respect to the independent variables x and...
e e e e s T T T T T rho v v T e p T T virtual T std::string fluidName() const
Fluid name.
virtual void rho_mu_from_p_T(Real p, Real T, Real &rho, Real &mu) const
Combined methods.
void NewtonSolve2D(const T &f, const T &g, const Real x0, const Real y0, T &x_final, T &y_final, const Real f_tol, const Real g_tol, const Functor1 &f_from_x_y, const Functor2 &g_from_x_y, const std::string &caller_name="", const unsigned int max_its=100, bool debug=false)
NewtonSolve2D does a 2D Newton Solve to solve for the x and y such that: f = f_from_x_y(x,...