https://mooseframework.inl.gov
PorousFlowMultiComponentFluid.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 
15 
16 template <bool is_ad>
19 {
21  params.addRequiredParam<UserObjectName>("fp", "The name of the user object for fluid properties");
22  params.addCoupledVar("x", 0, "The mass fraction variable");
23  params.addClassDescription(
24  "This Material calculates fluid properties for a multicomponent fluid");
25  return params;
26 }
27 
28 template <bool is_ad>
30  const InputParameters & parameters)
31  : PorousFlowFluidPropertiesBaseTempl<is_ad>(parameters),
32  _ddensity_dX(_compute_rho_mu
33  ? (_nodal_material ? &this->template declarePropertyDerivative<Real>(
34  "PorousFlow_fluid_phase_density_nodal" + _phase,
35  _mass_fraction_variable_name)
36  : &this->template declarePropertyDerivative<Real>(
37  "PorousFlow_fluid_phase_density_qp" + _phase,
38  _mass_fraction_variable_name))
39  : nullptr),
40  _dviscosity_dX(
41  _compute_rho_mu
42  ? (_nodal_material
43  ? &this->template declarePropertyDerivative<Real>(
44  "PorousFlow_viscosity_nodal" + _phase, _mass_fraction_variable_name)
45  : &this->template declarePropertyDerivative<Real>(
46  "PorousFlow_viscosity_qp" + _phase, _mass_fraction_variable_name))
47  : nullptr),
48  _dinternal_energy_dX(_compute_internal_energy
49  ? (_nodal_material
50  ? &this->template declarePropertyDerivative<Real>(
51  "PorousFlow_fluid_phase_internal_energy_nodal" + _phase,
52  _mass_fraction_variable_name)
53  : &this->template declarePropertyDerivative<Real>(
54  "PorousFlow_fluid_phase_internal_energy_qp" + _phase,
55  _mass_fraction_variable_name))
56  : nullptr),
57  _denthalpy_dX(_compute_enthalpy
58  ? (_nodal_material ? &this->template declarePropertyDerivative<Real>(
59  "PorousFlow_fluid_phase_enthalpy_nodal" + _phase,
60  _mass_fraction_variable_name)
61  : &this->template declarePropertyDerivative<Real>(
62  "PorousFlow_fluid_phase_enthalpy_qp" + _phase,
63  _mass_fraction_variable_name))
64  : nullptr),
65  _fp(this->template getUserObject<MultiComponentFluidProperties>("fp")),
66  _is_X_nodal(isCoupled("x") ? getFieldVar("x", 0)->isNodal() : false),
67  _X(_nodal_material && _is_X_nodal ? this->template coupledGenericDofValue<is_ad>("x")
68  : this->template coupledGenericValue<is_ad>("x"))
69 {
70 }
71 
72 template <bool is_ad>
73 void
75 {
76  if (_compute_rho_mu)
77  (*_density)[_qp] = _fp.rho_from_p_T_X(
78  _porepressure[_qp][_phase_num] * _pressure_to_Pascals, _temperature[_qp] + _t_c2k, _X[_qp]);
79 
80  if (_compute_internal_energy)
81  (*_internal_energy)[_qp] = _fp.e_from_p_T_X(
82  _porepressure[_qp][_phase_num] * _pressure_to_Pascals, _temperature[_qp] + _t_c2k, _X[_qp]);
83 
84  if (_compute_enthalpy)
85  (*_enthalpy)[_qp] = _fp.h_from_p_T_X(
86  _porepressure[_qp][_phase_num] * _pressure_to_Pascals, _temperature[_qp] + _t_c2k, _X[_qp]);
87 }
88 
89 template <bool is_ad>
90 void
92 {
93  const GenericReal<is_ad> Tk = _temperature[_qp] + _t_c2k;
94 
95  if (_compute_rho_mu)
96  {
97  if (is_ad)
98  {
99  (*_density)[_qp] =
100  _fp.rho_from_p_T_X(_porepressure[_qp][_phase_num] * _pressure_to_Pascals, Tk, _X[_qp]);
101  (*_viscosity)[_qp] =
102  _fp.mu_from_p_T_X(_porepressure[_qp][_phase_num] * _pressure_to_Pascals, Tk, _X[_qp]) /
103  _pressure_to_Pascals / _time_to_seconds;
104  }
105  else
106  {
107  // Density and derivatives wrt pressure and temperature
108  Real rho, drho_dp, drho_dT, drho_dx;
109  _fp.rho_from_p_T_X(MetaPhysicL::raw_value(_porepressure[_qp][_phase_num]) *
110  _pressure_to_Pascals,
112  MetaPhysicL::raw_value(_X[_qp]),
113  rho,
114  drho_dp,
115  drho_dT,
116  drho_dx);
117  (*_density)[_qp] = rho;
118  (*_ddensity_dp)[_qp] = drho_dp * _pressure_to_Pascals;
119  (*_ddensity_dT)[_qp] = drho_dT;
120  (*_ddensity_dX)[_qp] = drho_dx;
121 
122  // Viscosity and derivatives wrt pressure and temperature
123  Real mu, dmu_dp, dmu_dT, dmu_dx;
124  _fp.mu_from_p_T_X(MetaPhysicL::raw_value(_porepressure[_qp][_phase_num]) *
125  _pressure_to_Pascals,
127  MetaPhysicL::raw_value(_X[_qp]),
128  mu,
129  dmu_dp,
130  dmu_dT,
131  dmu_dx);
132  (*_viscosity)[_qp] = mu / _pressure_to_Pascals / _time_to_seconds;
133  (*_dviscosity_dp)[_qp] = dmu_dp / _time_to_seconds;
134  (*_dviscosity_dT)[_qp] = dmu_dT / _pressure_to_Pascals / _time_to_seconds;
135  (*_dviscosity_dX)[_qp] = dmu_dx / _pressure_to_Pascals / _time_to_seconds;
136  }
137  }
138 
139  // Internal energy and derivatives wrt pressure and temperature
140  if (_compute_internal_energy)
141  {
142  if (is_ad)
143  (*_internal_energy)[_qp] =
144  _fp.e_from_p_T_X(_porepressure[_qp][_phase_num] * _pressure_to_Pascals, Tk, _X[_qp]);
145  else
146  {
147  Real e, de_dp, de_dT, de_dx;
148  _fp.e_from_p_T_X(MetaPhysicL::raw_value(_porepressure[_qp][_phase_num]) *
149  _pressure_to_Pascals,
151  MetaPhysicL::raw_value(_X[_qp]),
152  e,
153  de_dp,
154  de_dT,
155  de_dx);
156  (*_internal_energy)[_qp] = e;
157  (*_dinternal_energy_dp)[_qp] = de_dp * _pressure_to_Pascals;
158  (*_dinternal_energy_dT)[_qp] = de_dT;
159  (*_dinternal_energy_dX)[_qp] = de_dx;
160  }
161  }
162 
163  // Enthalpy and derivatives wrt pressure and temperature
164  if (_compute_enthalpy)
165  {
166  if (is_ad)
167  (*_enthalpy)[_qp] =
168  _fp.h_from_p_T_X(_porepressure[_qp][_phase_num] * _pressure_to_Pascals, Tk, _X[_qp]);
169  else
170  {
171  Real h, dh_dp, dh_dT, dh_dx;
172  _fp.h_from_p_T_X(MetaPhysicL::raw_value(_porepressure[_qp][_phase_num]) *
173  _pressure_to_Pascals,
175  MetaPhysicL::raw_value(_X[_qp]),
176  h,
177  dh_dp,
178  dh_dT,
179  dh_dx);
180  (*_enthalpy)[_qp] = h;
181  (*_denthalpy_dp)[_qp] = dh_dp * _pressure_to_Pascals;
182  (*_denthalpy_dT)[_qp] = dh_dT;
183  (*_denthalpy_dX)[_qp] = dh_dx;
184  }
185  }
186 }
187 
Moose::GenericType< Real, is_ad > GenericReal
auto raw_value(const Eigen::Map< T > &in)
Base class for fluid properties materials.
PorousFlowMultiComponentFluidTempl(const InputParameters &parameters)
void addRequiredParam(const std::string &name, const std::string &doc_string)
static const std::string mu
Definition: NS.h:123
registerMooseObject("PorousFlowApp", PorousFlowMultiComponentFluid)
void addCoupledVar(const std::string &name, const std::string &doc_string)
Common class for multiple component fluid properties using a pressure and temperature formulation...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
General multicomponent fluid material.
void addClassDescription(const std::string &doc_string)