https://mooseframework.inl.gov
PorousFlowPreDis.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 "PorousFlowPreDis.h"
11 
12 registerMooseObject("PorousFlowApp", PorousFlowPreDis);
13 registerMooseObject("PorousFlowApp", ADPorousFlowPreDis);
14 
15 template <bool is_ad>
18 {
20  params.set<MultiMooseEnum>("vector_tags") = "time";
21  params.set<MultiMooseEnum>("matrix_tags") = "system time";
22  params.addRequiredParam<std::vector<Real>>(
23  "mineral_density",
24  "Density (kg(precipitate)/m^3(precipitate)) of each secondary species in the "
25  "aqueous precipitation-dissolution reaction system");
26  params.addRequiredParam<UserObjectName>(
27  "PorousFlowDictator", "The UserObject that holds the list of PorousFlow variable names.");
28  params.addRequiredParam<std::vector<Real>>("stoichiometry",
29  "A vector of stoichiometric coefficients for the "
30  "primary species that is the Variable of this Kernel: "
31  "one for each precipitation-dissolution reaction "
32  "(these are one columns of the 'reactions' matrix)");
33  params.addClassDescription("Precipitation-dissolution of chemical species");
34  return params;
35 }
36 
37 template <bool is_ad>
39  : PorousFlowLumpedKernelBaseTempl<is_ad>(parameters),
40  _mineral_density(this->template getParam<std::vector<Real>>("mineral_density")),
41  _dictator(this->template getUserObject<PorousFlowDictator>("PorousFlowDictator")),
42  _aq_ph(_dictator.aqueousPhaseNumber()),
43  _porosity_old(this->template getMaterialPropertyOld<Real>("PorousFlow_porosity_nodal")),
44  _saturation(this->template getGenericMaterialProperty<std::vector<Real>, is_ad>(
45  "PorousFlow_saturation_nodal")),
46  _dsaturation_dvar(is_ad ? nullptr
47  : &this->template getMaterialProperty<std::vector<std::vector<Real>>>(
48  "dPorousFlow_saturation_nodal_dvar")),
49  _reaction_rate(this->template getGenericMaterialProperty<std::vector<Real>, is_ad>(
50  "PorousFlow_mineral_reaction_rate_nodal")),
51  _dreaction_rate_dvar(is_ad
52  ? nullptr
53  : &this->template getMaterialProperty<std::vector<std::vector<Real>>>(
54  "dPorousFlow_mineral_reaction_rate_nodal_dvar")),
55  _stoichiometry(this->template getParam<std::vector<Real>>("stoichiometry"))
56 {
57  /* Not needed due to PorousFlow_mineral_reaction_rate already checking this condition
58  if (_dictator.numPhases() < 1)
59  mooseError("PorousFlowPreDis: The number of fluid phases must not be zero");
60  */
61 
63  this->paramError(
64  "mineral_density",
65  "The Dictator proclaims that the number of precipitation-dissolution secondary "
66  "species in this simulation is ",
68  " whereas you have provided ",
69  _mineral_density.size(),
70  ". The Dictator does not take such mistakes lightly");
71 
73  this->paramError(
74  "stoichiometry",
75  "The Dictator proclaims that the number of precipitation-dissolution secondary "
76  "species in this simulation is ",
78  " whereas you have provided ",
79  _stoichiometry.size(),
80  ". The Dictator does not take such mistakes lightly");
81 }
82 
83 template <bool is_ad>
86 {
87  /*
88  *
89  * Note the use of the OLD value of porosity here.
90  * This strategy, which breaks the cyclic dependency between porosity
91  * and mineral concentration, is used in
92  * Kernel: PorousFlowPreDis
93  * Material: PorousFlowPorosity
94  * Material: PorousFlowAqueousPreDisChemistry
95  * Material: PorousFlowAqueousPreDisMineral
96  *
97  */
98  GenericReal<is_ad> res = 0.0;
99  for (unsigned r = 0; r < _dictator.numAqueousKinetic(); ++r)
100  res += _stoichiometry[r] * _mineral_density[r] * _reaction_rate[_i][r];
101  return _test[_i][_qp] * res * _porosity_old[_i] * _saturation[_i][_aq_ph];
102 }
103 
104 template <bool is_ad>
105 Real
107 {
108  if constexpr (!is_ad)
109  {
111  if (_dictator.notPorousFlowVariable(_var.number()))
112  return 0.0;
113  return computeQpJac(_dictator.porousFlowVariableNum(_var.number()));
114  }
115  return 0.0;
116 }
117 
118 template <bool is_ad>
119 Real
121 {
122  if constexpr (!is_ad)
123  {
125  if (_dictator.notPorousFlowVariable(jvar))
126  return 0.0;
127  return computeQpJac(_dictator.porousFlowVariableNum(jvar));
128  }
129  else
130  libmesh_ignore(jvar);
131  return 0.0;
132 }
133 
134 template <bool is_ad>
135 Real
137 {
138  if constexpr (!is_ad)
139  {
140  if (_i != _j)
141  return 0.0;
142 
143  Real res = 0.0;
144  Real dres = 0.0;
145  for (unsigned r = 0; r < _dictator.numAqueousKinetic(); ++r)
146  {
147  dres += _stoichiometry[r] * _mineral_density[r] * (*_dreaction_rate_dvar)[_i][r][pvar];
148  res += _stoichiometry[r] * _mineral_density[r] * _reaction_rate[_i][r];
149  }
150 
151  return _test[_i][_qp] *
152  (dres * _saturation[_i][_aq_ph] + res * (*_dsaturation_dvar)[_i][_aq_ph][pvar]) *
153  _porosity_old[_i];
154  }
155  else
156  libmesh_ignore(pvar);
157  return 0.0;
158 }
159 
160 template class PorousFlowPreDisTempl<false>;
161 template class PorousFlowPreDisTempl<true>;
Moose::GenericType< Real, is_ad > GenericReal
const std::vector< Real > _stoichiometry
Stoichiometric coefficients.
void paramError(const std::string &param, Args... args) const
static InputParameters validParams()
T & set(const std::string &name, bool quiet_mode=false)
const std::vector< Real > _mineral_density
Density of the mineral species.
void addRequiredParam(const std::string &name, const std::string &doc_string)
void libmesh_ignore(const Args &...)
static InputParameters validParams()
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
virtual Real computeQpJacobian() override
unsigned int numAqueousKinetic() const
The number of aqueous kinetic secondary species.
registerMooseObject("PorousFlowApp", PorousFlowPreDis)
const PorousFlowDictator & _dictator
PorousFlowDictator UserObject.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This holds maps between the nonlinear variables used in a PorousFlow simulation and the variable numb...
void addClassDescription(const std::string &doc_string)
Kernel = sum (stoichiometry * density * porosity_old * saturation * reaction_rate) where the sum is o...
Base class for PorousFlow kernels that use mass-lumped (nodal) material properties.
Real computeQpJac(unsigned int pvar)
Derivative of residual wrt PorousFlow variable pvar (non-AD path only)
PorousFlowPreDisTempl(const InputParameters &parameters)
virtual GenericReal< is_ad > computeQpResidual() override