https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PorousFlowFluidStateBaseMaterial.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
13template <bool is_ad>
16{
18 MooseEnum unit_choice("Kelvin=0 Celsius=1", "Kelvin");
19 params.addParam<MooseEnum>(
20 "temperature_unit", unit_choice, "The unit of the temperature variable");
21 params.addRequiredParam<UserObjectName>("capillary_pressure",
22 "Name of the UserObject defining the capillary pressure");
23 params.addPrivateParam<std::string>("pf_material_type", "fluid_state");
24 params.addClassDescription("Base class for fluid state calculations using persistent primary "
25 "variables and a vapor-liquid flash");
26 return params;
27}
28
29template <bool is_ad>
31 const InputParameters & parameters)
32 : PorousFlowVariableBaseTempl<is_ad>(parameters),
33 _T_c2k(this->template getParam<MooseEnum>("temperature_unit") == 0 ? 0.0 : 273.15),
34 _is_initqp(false),
35 _pc(this->template getUserObject<PorousFlowCapillaryPressure>("capillary_pressure")),
36 _sfx(_nodal_material ? "_nodal" : "_qp"),
37 _mass_frac(this->template declareGenericProperty<std::vector<std::vector<Real>>, is_ad>(
38 "PorousFlow_mass_frac" + _sfx)),
39 _grad_mass_frac_qp(
40 _nodal_material
41 ? nullptr
42 : &this->template declareGenericProperty<std::vector<std::vector<RealGradient>>, is_ad>(
43 "PorousFlow_grad_mass_frac" + _sfx)),
44 _dmass_frac_dvar(
45 is_ad ? nullptr
46 : &this->template declareProperty<std::vector<std::vector<std::vector<Real>>>>(
47 "dPorousFlow_mass_frac" + _sfx + "_dvar")),
48 _fluid_density(this->template declareGenericProperty<std::vector<Real>, is_ad>(
49 "PorousFlow_fluid_phase_density" + _sfx)),
50 _dfluid_density_dvar(is_ad ? nullptr
51 : &this->template declareProperty<std::vector<std::vector<Real>>>(
52 "dPorousFlow_fluid_phase_density" + _sfx + "_dvar")),
53 _fluid_viscosity(this->template declareGenericProperty<std::vector<Real>, is_ad>(
54 "PorousFlow_viscosity" + _sfx)),
55 _dfluid_viscosity_dvar(is_ad ? nullptr
56 : &this->template declareProperty<std::vector<std::vector<Real>>>(
57 "dPorousFlow_viscosity" + _sfx + "_dvar")),
58 _fluid_enthalpy(this->template declareGenericProperty<std::vector<Real>, is_ad>(
59 "PorousFlow_fluid_phase_enthalpy" + _sfx)),
60 _dfluid_enthalpy_dvar(is_ad ? nullptr
61 : &this->template declareProperty<std::vector<std::vector<Real>>>(
62 "dPorousFlow_fluid_phase_enthalpy" + _sfx + "_dvar")),
63 _fluid_internal_energy(this->template declareGenericProperty<std::vector<Real>, is_ad>(
64 "PorousFlow_fluid_phase_internal_energy" + _sfx)),
65 _dfluid_internal_energy_dvar(
66 is_ad ? nullptr
67 : &this->template declareProperty<std::vector<std::vector<Real>>>(
68 "dPorousFlow_fluid_phase_internal_energy" + _sfx + "_dvar"))
69{
70 // Set the size of the FluidStateProperties vector
72}
73
74template <>
80
81template <>
87
88template <bool is_ad>
89void
91{
93
94 // The gradients of saturation, porepressure and mass fraction at the qps are built from the
95 // derivatives of the fluid state properties (computed using AD), and they can enter the residual.
96 // MOOSE turns AD derivatives off when it computes the residual alone, which would leave these
97 // derivatives stale, so we must turn them back on for the rest of this residual evaluation.
98 // The flag is shared by all threads, so it is set here (before the threaded loops), rather than
99 // around each flash; MOOSE turns derivatives on again once the residual has been computed
100 if (!is_ad && !_nodal_material)
101 ADReal::do_derivatives = true;
102}
103
104template <bool is_ad>
105void
107{
108 _is_initqp = true;
109 // Set the size of pressure and saturation vectors
111
112 // Set the size of all other vectors
113 setMaterialVectorSize();
114
115 thermophysicalProperties();
116
117 // Set the initial values of the properties at the nodes.
118 // Note: not required for qp materials as no old values at the qps are requested
119 // unless the material is AD (for the FV case there are no nodal materials)
120 if (_nodal_material || is_ad)
121 for (unsigned int ph = 0; ph < _num_phases; ++ph)
122 {
123 _saturation[_qp][ph] = genericValue(_fsp[ph].saturation);
124 _porepressure[_qp][ph] = genericValue(_fsp[ph].pressure);
125 _fluid_density[_qp][ph] = genericValue(_fsp[ph].density);
126 _fluid_viscosity[_qp][ph] = genericValue(_fsp[ph].viscosity);
127 _fluid_enthalpy[_qp][ph] = genericValue(_fsp[ph].enthalpy);
128 _fluid_internal_energy[_qp][ph] = genericValue(_fsp[ph].internal_energy);
129
130 for (unsigned int comp = 0; comp < _num_components; ++comp)
131 _mass_frac[_qp][ph][comp] = genericValue(_fsp[ph].mass_fraction[comp]);
132 }
133}
134
135template <bool is_ad>
136void
138{
139 _is_initqp = false;
140 // Size pressure and saturation and prepare the derivative vectors
142
143 // Set the size of all other vectors
144 setMaterialVectorSize();
145
146 // Calculate all required thermophysical properties
147 thermophysicalProperties();
148
149 for (unsigned int ph = 0; ph < _num_phases; ++ph)
150 {
151 _saturation[_qp][ph] = genericValue(_fsp[ph].saturation);
152 _porepressure[_qp][ph] = genericValue(_fsp[ph].pressure);
153 _fluid_density[_qp][ph] = genericValue(_fsp[ph].density);
154 _fluid_viscosity[_qp][ph] = genericValue(_fsp[ph].viscosity);
155 _fluid_enthalpy[_qp][ph] = genericValue(_fsp[ph].enthalpy);
156 _fluid_internal_energy[_qp][ph] = genericValue(_fsp[ph].internal_energy);
157
158 for (unsigned int comp = 0; comp < _num_components; ++comp)
159 _mass_frac[_qp][ph][comp] = genericValue(_fsp[ph].mass_fraction[comp]);
160 }
161}
162
163template <bool is_ad>
164void
166{
167 _fluid_density[_qp].resize(_num_phases, 0.0);
168 _fluid_viscosity[_qp].resize(_num_phases, 0.0);
169 _fluid_enthalpy[_qp].resize(_num_phases, 0.0);
170 _fluid_internal_energy[_qp].resize(_num_phases, 0.0);
171 _mass_frac[_qp].resize(_num_phases);
172
173 for (unsigned int ph = 0; ph < _num_phases; ++ph)
174 _mass_frac[_qp][ph].resize(_num_components);
175
176 // Derivatives and gradients are not required in initQpStatefulProperties
177 if (!_is_initqp)
178 {
179 // The gradient of the mass fractions are needed for qp materials and AD materials
180 if (!_nodal_material || is_ad)
181 {
182 (*_grad_mass_frac_qp)[_qp].resize(_num_phases);
183
184 for (unsigned int ph = 0; ph < _num_phases; ++ph)
185 (*_grad_mass_frac_qp)[_qp][ph].assign(_num_components, RealGradient());
186 }
187
188 // No derivatives are required for AD materials
189 if (!is_ad)
190 {
191 (*_dfluid_density_dvar)[_qp].resize(_num_phases);
192 (*_dfluid_viscosity_dvar)[_qp].resize(_num_phases);
193 (*_dfluid_enthalpy_dvar)[_qp].resize(_num_phases);
194 (*_dfluid_internal_energy_dvar)[_qp].resize(_num_phases);
195 (*_dmass_frac_dvar)[_qp].resize(_num_phases);
196
197 for (unsigned int ph = 0; ph < _num_phases; ++ph)
198 {
199 (*_dfluid_density_dvar)[_qp][ph].assign(_num_pf_vars, 0.0);
200 (*_dfluid_viscosity_dvar)[_qp][ph].assign(_num_pf_vars, 0.0);
201 (*_dfluid_enthalpy_dvar)[_qp][ph].assign(_num_pf_vars, 0.0);
202 (*_dfluid_internal_energy_dvar)[_qp][ph].assign(_num_pf_vars, 0.0);
203 (*_dmass_frac_dvar)[_qp][ph].resize(_num_components);
204
205 for (unsigned int comp = 0; comp < _num_components; ++comp)
206 (*_dmass_frac_dvar)[_qp][ph][comp].assign(_num_pf_vars, 0.0);
207 }
208 }
209 }
210}
211
DualNumber< Real, DNDerivativeType, true > ADReal
Moose::GenericType< Real, is_ad > GenericReal
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addPrivateParam(const std::string &name, const T &value)
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)
Base class for capillary pressure for multiphase flow in porous media.
Fluid state base class using a persistent set of primary variables for multiphase,...
PorousFlowFluidStateBaseMaterialTempl(const InputParameters &parameters)
GenericReal< is_ad > genericValue(const ADReal &value)
Templated method that takes an ADReal value, and returns the raw value when is_ad = false,...
virtual void setMaterialVectorSize() const
Size material property vectors and initialise with zeros.
std::vector< FluidStateProperties > _fsp
FluidStateProperties data for each fluid component in each fluid phase.
Base class for thermophysical variable materials, which assemble materials for primary variables such...
virtual void computeQpProperties() override
const unsigned int _num_phases
Number of phases.
static InputParameters validParams()
virtual void initQpStatefulProperties() override
const unsigned int _num_components
Number of components.
auto raw_value(const Eigen::Map< T > &in)
AD data structure to pass calculated thermophysical properties.