https://mooseframework.inl.gov
PorousFlowPorosity.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 
10 #include "PorousFlowPorosity.h"
11 
12 registerMooseObject("PorousFlowApp", PorousFlowPorosity);
13 
16 {
18  params.addParam<bool>(
19  "mechanical", false, "If true, porosity will be a function of total volumetric strain");
20  params.addParam<bool>(
21  "fluid", false, "If true, porosity will be a function of effective porepressure");
22  params.addParam<bool>("thermal", false, "If true, porosity will be a function of temperature");
23  params.addParam<bool>("chemical", false, "If true, porosity will be a function of precipitate");
24  params.addRequiredCoupledVar("porosity_zero",
25  "The porosity at zero volumetric strain and "
26  "reference temperature and reference effective "
27  "porepressure and reference chemistry. This must be a real number "
28  "or a constant monomial variable (not a linear lagrange or other "
29  "type of variable)");
30  params.addParam<Real>("thermal_expansion_coeff",
31  "Volumetric thermal expansion coefficient of the drained porous solid "
32  "skeleton (only used if thermal=true)");
33  params.addRangeCheckedParam<Real>(
34  "biot_coefficient", 1, "biot_coefficient>=0 & biot_coefficient<=1", "Biot coefficient");
35  params.addParam<Real>("biot_coefficient_prime",
36  "Biot coefficient that appears in the term (biot_coefficient_prime - 1) * "
37  "(P - reference_porepressure) / solid_bulk. If not provided, this "
38  "defaults to the standard biot_coefficient");
39  params.addParam<MooseFunctorName>(
40  "solid_bulk", "Bulk modulus of the drained porous solid skeleton (only used if fluid=true)");
41  params.addCoupledVar(
42  "reference_temperature", 0.0, "Reference temperature (only used if thermal=true)");
43  params.addCoupledVar(
44  "reference_porepressure", 0.0, "Reference porepressure (only used if fluid=true)");
45  params.addCoupledVar("reference_chemistry",
46  "Reference values of the solid mineral concentrations "
47  "(m^3(precipitate)/m^3(porous material)), entered as "
48  "a vector (one value per mineral). (Only used if chemical=true)");
49  params.addCoupledVar(
50  "initial_mineral_concentrations",
51  "Initial mineral concentrations (m^3(precipitate)/m^3(porous material)), entered as "
52  "a vector (one value per mineral). (Only used if chemical=true)");
53  params.addParam<std::vector<Real>>("chemical_weights",
54  "When chemical=true, porosity is a linear combination of the "
55  "solid mineral concentrations multiplied by these weights. "
56  "Default=1 for all minerals.");
57  params.addClassDescription("This Material calculates the porosity PorousFlow simulations");
58  return params;
59 }
60 
63 
64  _mechanical(getParam<bool>("mechanical")),
65  _fluid(getParam<bool>("fluid")),
66  _thermal(getParam<bool>("thermal")),
67  _chemical(getParam<bool>("chemical")),
68  _phi0(coupledValue("porosity_zero")),
69  _biot(getParam<Real>("biot_coefficient")),
70  _exp_coeff(isParamValid("thermal_expansion_coeff") ? getParam<Real>("thermal_expansion_coeff")
71  : 0.0),
72  _solid_bulk(isParamValid("solid_bulk") ? &(getFunctor<Real>("solid_bulk")) : nullptr),
73  _coeff(isParamValid("biot_coefficient_prime") ? (getParam<Real>("biot_coefficient_prime") - 1.0)
74  : (_biot - 1.0)),
75 
76  _t_reference(_nodal_material ? coupledDofValues("reference_temperature")
77  : coupledValue("reference_temperature")),
78  _p_reference(_nodal_material ? coupledDofValues("reference_porepressure")
79  : coupledValue("reference_porepressure")),
80  _num_c_ref(coupledComponents("reference_chemistry")),
81  _c_reference(_num_c_ref),
82  _num_initial_c(coupledComponents("initial_mineral_concentrations")),
83  _initial_c(_num_initial_c),
84  _c_weights(isParamValid("chemical_weights") ? getParam<std::vector<Real>>("chemical_weights")
85  : std::vector<Real>(_num_c_ref, 1.0)),
86 
87  _porosity_old(_chemical ? (_nodal_material
88  ? &getMaterialPropertyOld<Real>("PorousFlow_porosity_nodal")
89  : &getMaterialPropertyOld<Real>("PorousFlow_porosity_qp"))
90  : nullptr),
91  _vol_strain_qp(_mechanical ? &getMaterialProperty<Real>("PorousFlow_total_volumetric_strain_qp")
92  : nullptr),
93  _dvol_strain_qp_dvar(_mechanical ? &getMaterialProperty<std::vector<RealGradient>>(
94  "dPorousFlow_total_volumetric_strain_qp_dvar")
95  : nullptr),
96 
97  _pf(_fluid ? (_nodal_material
98  ? &getMaterialProperty<Real>("PorousFlow_effective_fluid_pressure_nodal")
99  : &getMaterialProperty<Real>("PorousFlow_effective_fluid_pressure_qp"))
100  : nullptr),
101  _dpf_dvar(_fluid ? (_nodal_material ? &getMaterialProperty<std::vector<Real>>(
102  "dPorousFlow_effective_fluid_pressure_nodal_dvar")
103  : &getMaterialProperty<std::vector<Real>>(
104  "dPorousFlow_effective_fluid_pressure_qp_dvar"))
105  : nullptr),
106 
107  _temperature(_thermal
108  ? (_nodal_material ? &getMaterialProperty<Real>("PorousFlow_temperature_nodal")
109  : &getMaterialProperty<Real>("PorousFlow_temperature_qp"))
110  : nullptr),
111  _dtemperature_dvar(
112  _thermal
113  ? (_nodal_material
114  ? &getMaterialProperty<std::vector<Real>>("dPorousFlow_temperature_nodal_dvar")
115  : &getMaterialProperty<std::vector<Real>>("dPorousFlow_temperature_qp_dvar"))
116  : nullptr),
117 
118  _mineral_conc_old(_chemical ? (_nodal_material ? &getMaterialPropertyOld<std::vector<Real>>(
119  "PorousFlow_mineral_concentration_nodal")
120  : &getMaterialPropertyOld<std::vector<Real>>(
121  "PorousFlow_mineral_concentration_qp"))
122  : nullptr),
123  _reaction_rate(_chemical ? (_nodal_material ? &getMaterialProperty<std::vector<Real>>(
124  "PorousFlow_mineral_reaction_rate_nodal")
125  : &getMaterialProperty<std::vector<Real>>(
126  "PorousFlow_mineral_reaction_rate_qp"))
127  : nullptr),
128  _dreaction_rate_dvar(_chemical ? (_nodal_material
129  ? &getMaterialProperty<std::vector<std::vector<Real>>>(
130  "dPorousFlow_mineral_reaction_rate_nodal_dvar")
131  : &getMaterialProperty<std::vector<std::vector<Real>>>(
132  "dPorousFlow_mineral_reaction_rate_qp_dvar"))
133  : nullptr),
134  _aq_ph(_dictator.aqueousPhaseNumber()),
135  _saturation(_chemical
136  ? (_nodal_material
137  ? &getMaterialProperty<std::vector<Real>>("PorousFlow_saturation_nodal")
138  : &getMaterialProperty<std::vector<Real>>("PorousFlow_saturation_qp"))
139  : nullptr),
140  _dsaturation_dvar(_chemical
141  ? (_nodal_material ? &getMaterialProperty<std::vector<std::vector<Real>>>(
142  "dPorousFlow_saturation_nodal_dvar")
143  : &getMaterialProperty<std::vector<std::vector<Real>>>(
144  "dPorousFlow_saturation_qp_dvar"))
145  : nullptr)
146 {
147  if (_thermal && !isParamValid("thermal_expansion_coeff"))
148  mooseError("PorousFlowPorosity: When thermal=true you must provide a thermal_expansion_coeff");
149  if (_fluid && !_solid_bulk)
150  mooseError("PorousFlowPorosity: When fluid=true you must provide a solid_bulk");
151  if (_chemical && _num_c_ref != _dictator.numAqueousKinetic())
152  mooseError("PorousFlowPorosity: When chemical=true you must provide the reference_chemistry "
153  "values. The Dictator proclaims there should be ",
154  _dictator.numAqueousKinetic(),
155  " of these");
156  if (_chemical && _num_initial_c != _dictator.numAqueousKinetic())
157  mooseError("PorousFlowPorosity: When chemical=true you must provide the "
158  "initial_mineral_concentrations. "
159  "The Dictator proclaims there should be ",
160  _dictator.numAqueousKinetic(),
161  " of these");
162  if (_chemical && _c_weights.size() != _dictator.numAqueousKinetic())
163  mooseError(
164  "PorousFlowPorosity: When chemical=true you must provde the correct number of "
165  "chemical_weights (which the Dictator knows is ",
166  _dictator.numAqueousKinetic(),
167  ") or do not provide any chemical_weights and use the default value of 1 for each mineral");
168 
169  for (unsigned i = 0; i < _num_c_ref; ++i)
170  {
171  _c_reference[i] = (_nodal_material ? &coupledDofValues("reference_chemistry", i)
172  : &coupledValue("reference_chemistry", i));
173  _initial_c[i] = (_nodal_material ? &coupledDofValues("initial_mineral_concentrations", i)
174  : &coupledValue("initial_mineral_concentrations", i));
175  }
176 }
177 
178 Real
180 {
181  /*
182  *
183  * Note the use of the OLD value of porosity here.
184  * This strategy, which breaks the cyclic dependency between porosity
185  * and mineral concentration, is used in
186  * Kernel: PorousFlowPreDis
187  * Material: PorousFlowPorosity
188  * Material: PorousFlowAqueousPreDisChemistry
189  * Material: PorousFlowAqueousPreDisMineral
190  *
191  */
192  Real result = _biot;
193  if (_chemical)
194  {
195  if (_t_step == 0 && !_app.isRestarting())
196  for (unsigned i = 0; i < _num_c_ref; ++i)
197  result -= _c_weights[i] * (*_initial_c[i])[_qp];
198  else
199  for (unsigned i = 0; i < _num_c_ref; ++i)
200  result -= _c_weights[i] * ((*_mineral_conc_old)[_qp][i] + _dt * (*_porosity_old)[_qp] *
201  (*_saturation)[_qp][_aq_ph] *
202  (*_reaction_rate)[_qp][i]);
203  }
204  return result;
205 }
206 
207 Real
209 {
210  Real result = 0.0;
211  if (_chemical && (_t_step >= 1 || _app.isRestarting()))
212  for (unsigned i = 0; i < _num_c_ref; ++i)
213  result -= _c_weights[i] * _dt * (*_porosity_old)[_qp] *
214  ((*_saturation)[_qp][_aq_ph] * (*_dreaction_rate_dvar)[_qp][i][pvar] +
215  (*_dsaturation_dvar)[_qp][_aq_ph][pvar] * (*_reaction_rate)[_qp][i]);
216  return result;
217 }
218 
219 Real
221 {
222  // note the [0] below: _phi0 is a constant monomial and we use [0] regardless of _nodal_material
223  Real result = _phi0[0];
224  if (_chemical)
225  {
226  if (_t_step == 0 && !_app.isRestarting())
227  for (unsigned i = 0; i < _num_c_ref; ++i)
228  result -= _c_weights[i] * ((*_initial_c[i])[_qp] - (*_c_reference[i])[_qp]);
229  else
230  for (unsigned i = 0; i < _num_c_ref; ++i)
231  result -= _c_weights[i] * ((*_mineral_conc_old)[_qp][i] +
232  _dt * (*_porosity_old)[_qp] * (*_saturation)[_qp][_aq_ph] *
233  (*_reaction_rate)[_qp][i] -
234  (*_c_reference[i])[_qp]);
235  }
236  return result;
237 }
238 
239 Real
240 PorousFlowPorosity::datZeroQp(unsigned pvar) const
241 {
242  Real result = 0.0;
243  if (_chemical && (_t_step >= 1 || _app.isRestarting()))
244  for (unsigned i = 0; i < _num_c_ref; ++i)
245  result -= _c_weights[i] * _dt * (*_porosity_old)[_qp] *
246  ((*_saturation)[_qp][_aq_ph] * (*_dreaction_rate_dvar)[_qp][i][pvar] +
247  (*_dsaturation_dvar)[_qp][_aq_ph][pvar] * (*_reaction_rate)[_qp][i]);
248  return result;
249 }
250 
251 Real
253 {
254  Real result = 0.0;
255 
256  if (_thermal)
257  result += _exp_coeff * ((*_temperature)[_qp] - _t_reference[_qp]);
258 
259  if (_fluid)
260  {
261  Real solid_bulk;
262  // Using Qp 0 can leverage the functor caching
263  // TODO: Find a way to effectively use subdomain-constant-ness
264  unsigned int qp_used = (_constant_option == ConstantTypeEnum::NONE) ? _qp : 0;
265  if (_nodal_material)
266  {
267  const std::set<SubdomainID> subdomain_set = {_current_elem->subdomain_id()};
268  const Moose::NodeArg space_arg = {_current_elem->node_ptr(qp_used), &subdomain_set};
269  solid_bulk = (*_solid_bulk)(space_arg, Moose::currentState());
270  }
271  else if (_bnd)
272  {
273  const Moose::ElemSideQpArg space_arg = {
274  _current_elem, _current_side, qp_used, _qrule, _q_point[qp_used]};
275  solid_bulk = (*_solid_bulk)(space_arg, Moose::currentState());
276  }
277  else
278  {
279  const Moose::ElemQpArg space_arg = {_current_elem, qp_used, _qrule, _q_point[qp_used]};
280  solid_bulk = (*_solid_bulk)(space_arg, Moose::currentState());
281  }
282  if (solid_bulk <= 0)
283  mooseError("PorousFlowPorosity: solid_bulk must be larger than Zero");
284  result += _coeff / solid_bulk * ((*_pf)[_qp] - _p_reference[_qp]);
285  }
286 
287  if (_mechanical)
288  {
289  // Note that in the following _strain[_qp] is evaluated at q quadpoint
290  // So _porosity_nodal[_qp], which should be the nodal value of porosity
291  // actually uses the strain at a quadpoint. This
292  // is OK for LINEAR elements, as strain is constant over the element anyway.
293  const unsigned qp_to_use =
294  (_nodal_material && (_bnd || _strain_at_nearest_qp) ? nearestQP(_qp) : _qp);
295  result += -(*_vol_strain_qp)[qp_to_use];
296  }
297 
298  return result;
299 }
300 
301 Real
303 {
304  Real result = 0.0;
305 
306  if (_thermal)
307  result += _exp_coeff * (*_dtemperature_dvar)[_qp][pvar];
308 
309  if (_fluid)
310  {
311  Real solid_bulk;
312  // Using Qp 0 can leverage the functor caching
313  // TODO: Find a way to effectively use subdomain-constant-ness
314  unsigned int qp_used = (_constant_option == ConstantTypeEnum::NONE) ? _qp : 0;
315  if (_nodal_material)
316  {
317  const std::set<SubdomainID> subdomain_set = {_current_elem->subdomain_id()};
318  const Moose::NodeArg space_arg = {_current_elem->node_ptr(qp_used), &subdomain_set};
319  solid_bulk = (*_solid_bulk)(space_arg, Moose::currentState());
320  }
321  else if (_bnd)
322  {
323  const Moose::ElemSideQpArg space_arg = {
324  _current_elem, _current_side, qp_used, _qrule, _q_point[qp_used]};
325  solid_bulk = (*_solid_bulk)(space_arg, Moose::currentState());
326  }
327  else
328  {
329  const Moose::ElemQpArg space_arg = {_current_elem, qp_used, _qrule, _q_point[qp_used]};
330  solid_bulk = (*_solid_bulk)(space_arg, Moose::currentState());
331  }
332  if (solid_bulk <= 0)
333  mooseError("PorousFlowPorosity: solid_bulk must be larger than Zero.");
334  result += _coeff / solid_bulk * (*_dpf_dvar)[_qp][pvar];
335  }
336 
337  return result;
338 }
339 
342 {
343  RealGradient result(0.0, 0.0, 0.0);
344  if (_mechanical)
345  {
346  const unsigned qp_to_use =
347  (_nodal_material && (_bnd || _strain_at_nearest_qp) ? nearestQP(_qp) : _qp);
348  result += -(*_dvol_strain_qp_dvar)[qp_to_use][pvar];
349  }
350  return result;
351 }
const Real _coeff
Short-hand number (biot-1). Please note: this variable is not yet divided by solid_bulk.
Base class Material designed to provide the porosity.
const Real _biot
Biot coefficient.
const VariableValue & _t_reference
Reference temperature.
const VariableValue & _phi0
Porosity at zero strain and zero porepressure and zero temperature.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const bool _strain_at_nearest_qp
When calculating nodal porosity, use the strain at the nearest quadpoint to the node.
void mooseError(Args &&... args)
virtual RealGradient ddecayQp_dgradvar(unsigned pvar) const override
d(decay)/d(grad(PorousFlow variable pvar))
const MaterialProperty< std::vector< Real > > *const _mineral_conc_old
Old value of mineral concentration at the quadpoints or nodes.
const bool _thermal
Porosity is a function of temperature.
std::vector< Real > _c_weights
Weights for the mineral concentrations.
const bool _chemical
Porosity is a function of chemistry.
virtual Real datZeroQp(unsigned pvar) const override
d(a)/d(PorousFlow variable pvar)
const unsigned _num_c_ref
Number of reference mineral concentrations provided by user.
const MaterialProperty< Real > *const _porosity_old
Old value of porosity.
const unsigned int _aq_ph
Aqueous phase number.
registerMooseObject("PorousFlowApp", PorousFlowPorosity)
std::vector< const VariableValue * > _initial_c
Reference mineral concentrations.
const Real _exp_coeff
Thermal expansion coefficient of the solid porous skeleton.
const VariableValue & _p_reference
Reference porepressure.
const unsigned _num_initial_c
Number of reference mineral concentrations provided by user.
const Moose::Functor< Real > * _solid_bulk
Drained bulk modulus of the porous skeleton (as a functor; can be variable, function, etc.) Only used if _fluid is True.
const bool _fluid
Porosity is a function of effective porepressure.
void addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
PorousFlowPorosity(const InputParameters &parameters)
std::vector< const VariableValue * > _c_reference
Reference mineral concentrations.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Material designed to provide the porosity in PorousFlow simulations chemistry + biot + (phi0 - refere...
virtual Real atZeroQp() const override
Returns "b" at the quadpoint (porosity = a + (b - a) * exp(decay))
const bool _mechanical
Porosity is a function of volumetric strain.
virtual Real datNegInfinityQp(unsigned pvar) const override
d(a)/d(PorousFlow variable pvar)
void addClassDescription(const std::string &doc_string)
virtual Real decayQp() const override
Returns "decay" at the quadpoint (porosity = a + (b - a) * exp(decay))
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
virtual Real atNegInfinityQp() const override
Returns "a" at the quadpoint (porosity = a + (b - a) * exp(decay))
StateArg currentState()
virtual Real ddecayQp_dvar(unsigned pvar) const override
d(decay)/d(PorousFlow variable pvar)
static InputParameters validParams()