https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PorousFlowHeatVolumetricExpansion.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
12#include "MooseVariable.h"
13
14#include "libmesh/quadrature.h"
15
18
19template <bool is_ad>
22{
24 params.set<MultiMooseEnum>("vector_tags") = "time";
25 params.set<MultiMooseEnum>("matrix_tags") = "system time";
26 params.addParam<bool>("strain_at_nearest_qp",
27 false,
28 "When calculating nodal porosity that depends on strain, use the strain at "
29 "the nearest quadpoint. This adds a small extra computational burden, and "
30 "is not necessary for simulations involving only linear lagrange elements. "
31 " If you set this to true, you will also want to set the same parameter to "
32 "true for related Kernels and Materials");
33 params.addRequiredParam<UserObjectName>(
34 "PorousFlowDictator", "The UserObject that holds the list of PorousFlow variable names.");
35 params.set<bool>("use_displaced_mesh") = false;
36 params.suppressParameter<bool>("use_displaced_mesh");
37 params.addClassDescription("Energy-density*rate_of_solid_volumetric_expansion. The "
38 "energy-density is lumped to the nodes");
39 return params;
40}
41
42template <bool is_ad>
44 const InputParameters & parameters)
45 : PorousFlowLumpedKernelBaseTempl<is_ad>(parameters),
46 _dictator(this->template getUserObject<PorousFlowDictator>("PorousFlowDictator")),
47 _var_is_porflow_var(_dictator.isPorousFlowVariable(_var.number())),
48 _num_phases(_dictator.numPhases()),
49 _fluid_present(_num_phases > 0),
50 _strain_at_nearest_qp(this->template getParam<bool>("strain_at_nearest_qp")),
51 _porosity(this->template getGenericMaterialProperty<Real, is_ad>("PorousFlow_porosity_nodal")),
52 _dporosity_dvar(is_ad ? nullptr
53 : &this->template getMaterialProperty<std::vector<Real>>(
54 "dPorousFlow_porosity_nodal_dvar")),
55 _dporosity_dgradvar(is_ad ? nullptr
56 : &this->template getMaterialProperty<std::vector<RealGradient>>(
57 "dPorousFlow_porosity_nodal_dgradvar")),
58 _nearest_qp(_strain_at_nearest_qp ? &this->template getMaterialProperty<unsigned int>(
59 "PorousFlow_nearestqp_nodal")
60 : nullptr),
61 _rock_energy_nodal(this->template getGenericMaterialProperty<Real, is_ad>(
62 "PorousFlow_matrix_internal_energy_nodal")),
63 _drock_energy_nodal_dvar(is_ad ? nullptr
64 : &this->template getMaterialProperty<std::vector<Real>>(
65 "dPorousFlow_matrix_internal_energy_nodal_dvar")),
66 _fluid_density(_fluid_present
67 ? &this->template getGenericMaterialProperty<std::vector<Real>, is_ad>(
68 "PorousFlow_fluid_phase_density_nodal")
69 : nullptr),
70 _dfluid_density_dvar(_fluid_present && !is_ad
71 ? &this->template getMaterialProperty<std::vector<std::vector<Real>>>(
72 "dPorousFlow_fluid_phase_density_nodal_dvar")
73 : nullptr),
74 _fluid_saturation_nodal(
75 _fluid_present ? &this->template getGenericMaterialProperty<std::vector<Real>, is_ad>(
76 "PorousFlow_saturation_nodal")
77 : nullptr),
78 _dfluid_saturation_nodal_dvar(
79 _fluid_present && !is_ad
80 ? &this->template getMaterialProperty<std::vector<std::vector<Real>>>(
81 "dPorousFlow_saturation_nodal_dvar")
82 : nullptr),
83 _energy_nodal(_fluid_present
84 ? &this->template getGenericMaterialProperty<std::vector<Real>, is_ad>(
85 "PorousFlow_fluid_phase_internal_energy_nodal")
86 : nullptr),
87 _denergy_nodal_dvar(_fluid_present && !is_ad
88 ? &this->template getMaterialProperty<std::vector<std::vector<Real>>>(
89 "dPorousFlow_fluid_phase_internal_energy_nodal_dvar")
90 : nullptr),
91 _strain_rate_qp(this->template getGenericMaterialProperty<Real, is_ad>(
92 "PorousFlow_volumetric_strain_rate_qp")),
93 _dstrain_rate_qp_dvar(is_ad ? nullptr
94 : &this->template getMaterialProperty<std::vector<RealGradient>>(
95 "dPorousFlow_volumetric_strain_rate_qp_dvar"))
96{
97}
98
99template <bool is_ad>
102{
103 GenericReal<is_ad> energy = (1.0 - _porosity[_i]) * _rock_energy_nodal[_i];
104 for (unsigned ph = 0; ph < _num_phases; ++ph)
105 energy += (*_fluid_density)[_i][ph] * (*_fluid_saturation_nodal)[_i][ph] *
106 (*_energy_nodal)[_i][ph] * _porosity[_i];
107
108 return _test[_i][_qp] * energy * _strain_rate_qp[_qp];
109}
110
111template <bool is_ad>
112Real
114{
115 return computedEnergyQpJac(_var.number()) + computedVolQpJac(_var.number());
116}
117
118template <bool is_ad>
119Real
121{
122 return computedEnergyQpJac(jvar) + computedVolQpJac(jvar);
123}
124
125template <bool is_ad>
126Real
128{
129 if constexpr (!is_ad)
130 {
131 if (_dictator.notPorousFlowVariable(jvar))
132 return 0.0;
133
134 Real energy = (1.0 - _porosity[_i]) * _rock_energy_nodal[_i];
135 for (unsigned ph = 0; ph < _num_phases; ++ph)
136 energy += (*_fluid_density)[_i][ph] * (*_fluid_saturation_nodal)[_i][ph] *
137 (*_energy_nodal)[_i][ph] * _porosity[_i];
138
139 const unsigned int pvar = _dictator.porousFlowVariableNum(jvar);
140 Real dvol = (*_dstrain_rate_qp_dvar)[_qp][pvar] * _grad_phi[_j][_qp];
141
142 return _test[_i][_qp] * energy * dvol;
143 }
144 else
145 {
146 libmesh_ignore(jvar);
147 return 0.0;
148 }
149}
150
151template <bool is_ad>
152Real
154{
155 if constexpr (!is_ad)
156 {
157 if (_dictator.notPorousFlowVariable(jvar))
158 return 0.0;
159
160 const unsigned int pvar = _dictator.porousFlowVariableNum(jvar);
161 const unsigned nearest_qp = (_strain_at_nearest_qp ? (*_nearest_qp)[_i] : _i);
162
163 Real denergy = -(*_dporosity_dgradvar)[_i][pvar] * _grad_phi[_j][_i] * _rock_energy_nodal[_i];
164 for (unsigned ph = 0; ph < _num_phases; ++ph)
165 denergy += (*_fluid_density)[_i][ph] * (*_fluid_saturation_nodal)[_i][ph] *
166 (*_energy_nodal)[_i][ph] * (*_dporosity_dgradvar)[_i][pvar] *
167 _grad_phi[_j][nearest_qp];
168
169 if (_i != _j)
170 return _test[_i][_qp] * denergy * _strain_rate_qp[_qp];
171
172 denergy += (*_drock_energy_nodal_dvar)[_i][pvar] * (1.0 - _porosity[_i]);
173 denergy -= _rock_energy_nodal[_i] * (*_dporosity_dvar)[_i][pvar];
174 for (unsigned ph = 0; ph < _num_phases; ++ph)
175 {
176 denergy += (*_dfluid_density_dvar)[_i][ph][pvar] * (*_fluid_saturation_nodal)[_i][ph] *
177 (*_energy_nodal)[_i][ph] * _porosity[_i];
178 denergy += (*_fluid_density)[_i][ph] * (*_dfluid_saturation_nodal_dvar)[_i][ph][pvar] *
179 (*_energy_nodal)[_i][ph] * _porosity[_i];
180 denergy += (*_fluid_density)[_i][ph] * (*_fluid_saturation_nodal)[_i][ph] *
181 (*_denergy_nodal_dvar)[_i][ph][pvar] * _porosity[_i];
182 denergy += (*_fluid_density)[_i][ph] * (*_fluid_saturation_nodal)[_i][ph] *
183 (*_energy_nodal)[_i][ph] * (*_dporosity_dvar)[_i][pvar];
184 }
185
186 return _test[_i][_qp] * denergy * _strain_rate_qp[_qp];
187 }
188 else
189 {
190 libmesh_ignore(jvar);
191 return 0.0;
192 }
193}
194
Moose::GenericType< Real, is_ad > GenericReal
registerMooseObject("PorousFlowApp", PorousFlowHeatVolumetricExpansion)
void ErrorVector unsigned int
static InputParameters validParams()
void suppressParameter(const std::string &name)
void addRequiredParam(const std::string &name, const std::string &doc_string)
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)
T & set(const std::string &name, bool quiet_mode=false)
This holds maps between the nonlinear variables used in a PorousFlow simulation and the variable numb...
Kernel = energy_density * rate_of_solid_volumetric_expansion where energy_density = (1 - porosity) * ...
Real computedEnergyQpJac(unsigned int jvar)
Derivative of energy part of the residual with respect to the Variable with variable number jvar.
virtual GenericReal< is_ad > computeQpResidual() override
Real computedVolQpJac(unsigned int jvar)
Derivative of volumetric-strain part of the residual with respect to the Variable with variable numbe...
PorousFlowHeatVolumetricExpansionTempl(const InputParameters &parameters)
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
Base class for PorousFlow kernels that use mass-lumped (nodal) material properties.