Line data Source code
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 :
10 : #pragma once
11 :
12 : #include "FluidProperties.h"
13 : #include "SinglePhaseFluidProperties.h"
14 :
15 : #define propfunc(want, prop1, prop2, prop3) \
16 : virtual Real want##_from_##prop1##_##prop2##_##prop3(Real, Real, Real) const \
17 : { \
18 : mooseError(name(), ": ", __PRETTY_FUNCTION__, " not implemented."); \
19 : } \
20 : \
21 : virtual void want##_from_##prop1##_##prop2##_##prop3(Real prop1, \
22 : Real prop2, \
23 : Real prop3, \
24 : Real & val, \
25 : Real & d##want##d1, \
26 : Real & d##want##d2, \
27 : Real & d##want##d3) const \
28 : { \
29 : if (_allow_imperfect_jacobians) \
30 : mooseWarning(name(), ": ", __PRETTY_FUNCTION__, " derivatives not implemented."); \
31 : else \
32 : mooseError(name(), ": ", __PRETTY_FUNCTION__, " derivatives not implemented."); \
33 : \
34 : d##want##d1 = 0.0; \
35 : d##want##d2 = 0.0; \
36 : d##want##d3 = 0.0; \
37 : val = want##_from_##prop1##_##prop2##_##prop3(prop1, prop2, prop3); \
38 : } \
39 : \
40 : ADReal want##_from_##prop1##_##prop2##_##prop3( \
41 : const ADReal & p1, const ADReal & p2, const ADReal & p3) const \
42 : { \
43 : const Real raw1 = p1.value(); \
44 : const Real raw2 = p2.value(); \
45 : const Real raw3 = p3.value(); \
46 : Real x = 0.0; \
47 : Real dxd1 = 0.0; \
48 : Real dxd2 = 0.0; \
49 : Real dxd3 = 0.0; \
50 : want##_from_##prop1##_##prop2##_##prop3(raw1, raw2, raw3, x, dxd1, dxd2, dxd3); \
51 : \
52 : ADReal result = x; \
53 : result.derivatives() = \
54 : p1.derivatives() * dxd1 + p2.derivatives() * dxd2 + p3.derivatives() * dxd3; \
55 : \
56 : return result; \
57 : }
58 :
59 : /**
60 : * Common class for multiple component fluid
61 : * properties using a pressure and
62 : * temperature formulation
63 : */
64 : class MultiComponentFluidProperties : public FluidProperties
65 : {
66 : public:
67 : static InputParameters validParams();
68 :
69 : MultiComponentFluidProperties(const InputParameters & parameters);
70 : virtual ~MultiComponentFluidProperties();
71 :
72 : #pragma GCC diagnostic push
73 : #pragma GCC diagnostic ignored "-Woverloaded-virtual"
74 : // clang-format off
75 :
76 : /**
77 : * @brief Compute a fluid property given for the state defined by three given properties.
78 : *
79 : * For all functions, the first three arguments are the given properties that define the fluid
80 : * state. For the three-argument variants, the desired property is the return value.
81 : * The seven-argument variants also provide partial derivatives x/da, dx/db and dx/dc where x
82 : * is the desired property being computed, a is the first given property, b is the second given property etc.
83 : * The desired property, dx/da, dx/db and dx/dc are stored into the 4rd, 5th, 6th and 7th arguments respectively.
84 : *
85 : * Properties/parameters used in these function are listed below with their units:
86 : *
87 : * @begincode
88 : * p pressure [Pa]
89 : * T temperature [K]
90 : * X solute mass fraction [-]
91 : * e specific internal energy [J/kg]
92 : * rho density [kg/m^3]
93 : * h specific enthalpy [J/kg]
94 : * mu viscosity [Pa*s]
95 : * k thermal conductivity [W/(m*K)]
96 : * c speed of sound [m/s]
97 : * cp constant-pressure specific heat [J/K]
98 : * cv constant-volume specific heat [J/K]
99 : * @endcode
100 : *
101 : * As an example:
102 : *
103 : * @begincode
104 : * // calculate desnity given pressure, temperature and solute mass fraction:
105 : * auto density = your_fluid_properties_object.rho_from_p_T_X(p, T, X);
106 : *
107 : * // or use the derivative variant:
108 : * Real rho = 0; // density will be stored into here
109 : * Real drho_dp = 0; // derivative will be stored into here
110 : * Real drho_dT = 0; // derivative will be stored into here
111 : * Real drho_dX = 0; // derivative will be stored into here
112 : * your_fluid_properties_object.rho_from_p_T_X(p, T, X, rho, drho_dp, drho_dT, drho_dX);
113 : * @endcode
114 : *
115 : * Automatic differentiation (AD) support is provided through prop_from_p_T_X(ADReal p, ADReal T, ADReal X) versions
116 : * of the functions where p, T and X must be ADReal/DualNumber's calculated using all AD-supporting values.
117 : */
118 : ///@{
119 0 : propfunc(rho, p, T, X)
120 0 : propfunc(mu, p, T, X)
121 0 : propfunc(h, p, T, X)
122 0 : propfunc(cp, p, T, X)
123 0 : propfunc(e, p, T, X)
124 0 : propfunc(k, p, T, X)
125 : ///@}
126 :
127 : // clang-format on
128 :
129 : #undef propfunc
130 : #pragma GCC diagnostic pop
131 :
132 : /**
133 : * Fluid name
134 : * @return string representing fluid name
135 : */
136 : virtual std::string fluidName() const;
137 :
138 : /**
139 : * Density and viscosity
140 : * @param pressure fluid pressure (Pa)
141 : * @param temperature fluid temperature (K)
142 : * @param xmass mass fraction (-)
143 : * @param[out] rho density (kg/m^3)
144 : */
145 : virtual void
146 : rho_mu_from_p_T_X(Real pressure, Real temperature, Real xmass, Real & rho, Real & mu) const;
147 :
148 : virtual void rho_mu_from_p_T_X(
149 : ADReal pressure, ADReal temperature, ADReal xmass, ADReal & rho, ADReal & mu) const;
150 :
151 : /**
152 : * Density and viscosity and their derivatives wrt pressure, temperature
153 : * and mass fraction
154 : * @param pressure fluid pressure (Pa)
155 : * @param temperature fluid temperature (K)
156 : * @param xmass mass fraction (-)
157 : * @param[out] rho density (kg/m^3)
158 : * @param[out] drho_dp derivative of density wrt pressure
159 : * @param[out] drho_dT derivative of density wrt temperature
160 : * @param[out] drho_dx derivative of density wrt mass fraction
161 : * @param[out] mu viscosity (Pa.s)
162 : * @param[out] dmu_dp derivative of viscosity wrt pressure
163 : * @param[out] dmu_dT derivative of viscosity wrt temperature
164 : * @param[out] dmu_dx derivative of viscosity wrt mass fraction
165 : */
166 : virtual void rho_mu_from_p_T_X(Real pressure,
167 : Real temperature,
168 : Real xmass,
169 : Real & rho,
170 : Real & drho_dp,
171 : Real & drho_dT,
172 : Real & drho_dx,
173 : Real & mu,
174 : Real & dmu_dp,
175 : Real & dmu_dT,
176 : Real & dmu_dx) const;
177 :
178 : /**
179 : * Get UserObject for specified component
180 : * @param component fluid component
181 : * @return reference to
182 : * SinglePhaseFluidPropertiesPT UserObject
183 : * for component
184 : */
185 : virtual const SinglePhaseFluidProperties & getComponent(unsigned int component) const;
186 : };
|