www.mooseframework.org
PorousFlowPorosityExponentialBase.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
14 {
16  params.addParam<bool>("strain_at_nearest_qp",
17  false,
18  "When calculating nodal porosity that depends on strain, use the strain at "
19  "the nearest quadpoint. This adds a small extra computational burden, and "
20  "is not necessary for simulations involving only linear lagrange elements. "
21  " If you set this to true, you will also want to set the same parameter to "
22  "true for related Kernels and Materials");
23  params.addParam<bool>("ensure_positive",
24  true,
25  "Modify the usual exponential relationships that "
26  "governs porosity so that porosity is always "
27  "positive");
28  params.addClassDescription("Base class Material for porosity that is computed via an exponential "
29  "relationship with coupled variables (strain, porepressure, "
30  "temperature, chemistry)");
31  return params;
32 }
33 
35  const InputParameters & parameters)
36  : PorousFlowPorosityBase(parameters),
37  _strain_at_nearest_qp(getParam<bool>("strain_at_nearest_qp")),
38  _ensure_positive(getParam<bool>("ensure_positive"))
39 {
40 }
41 
42 void
44 {
45  const Real a = atNegInfinityQp();
46  const Real b = atZeroQp();
47  mooseAssert(a > b, "PorousFlowPorosityExponentialBase a must be larger than b");
48  const Real decay = decayQp();
49 
50  if (decay <= 0.0 || !_ensure_positive)
51  _porosity[_qp] = a + (b - a) * std::exp(decay);
52  else
53  {
54  const Real c = std::log(a / (a - b));
55  const Real expx = std::exp(-decay / c);
56  _porosity[_qp] = a + (b - a) * std::exp(c * (1.0 - expx));
57  }
58 }
59 
60 void
62 {
63  const Real a = atNegInfinityQp();
64  const Real b = atZeroQp();
65  const Real decay = decayQp();
66  Real exp_term = 1.0; // set appropriately below
67 
68  Real deriv = 0.0; // = d(porosity)/d(decay)
69  if (decay <= 0.0 || !_ensure_positive)
70  {
71  exp_term = std::exp(decay);
72  _porosity[_qp] = a + (b - a) * exp_term;
73  deriv = _porosity[_qp] - a;
74  }
75  else
76  {
77  const Real c = std::log(a / (a - b));
78  const Real expx = std::exp(-decay / c);
79  // note that at decay = 0, we have expx = 1, so porosity = a + b - a = b
80  // and at decay = infinity, expx = 0, so porosity = a + (b - a) * a / (a - b) = 0
81  exp_term = std::exp(c * (1.0 - expx));
82  _porosity[_qp] = a + (b - a) * exp_term;
83  deriv = (_porosity[_qp] - a) * expx;
84  }
85 
86  (*_dporosity_dvar)[_qp].resize(_num_var);
87  (*_dporosity_dgradvar)[_qp].resize(_num_var);
88  for (unsigned int v = 0; v < _num_var; ++v)
89  {
90  (*_dporosity_dvar)[_qp][v] = ddecayQp_dvar(v) * deriv;
91  (*_dporosity_dgradvar)[_qp][v] = ddecayQp_dgradvar(v) * deriv;
92 
93  const Real da = datNegInfinityQp(v);
94  const Real db = datZeroQp(v);
95  (*_dporosity_dvar)[_qp][v] += da * (1 - exp_term) + db * exp_term;
96 
97  if (!(decay <= 0.0 || !_ensure_positive))
98  {
99  const Real c = std::log(a / (a - b));
100  const Real expx = std::exp(-decay / c);
101  const Real dc = (a - b) * (da * b / a - db) / std::pow(a, 2);
102  (*_dporosity_dvar)[_qp][v] += (b - a) * exp_term * dc * (1 - expx - expx / c);
103  }
104  }
105 }
const bool _ensure_positive
for decayQp() > 0, porosity can be negative when using porosity = a + (b - a) * exp(decay).
virtual Real atZeroQp() const =0
Returns "b" at the quadpoint (porosity = a + (b - a) * exp(decay))
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
PorousFlowPorosityExponentialBase(const InputParameters &parameters)
const GeochemicalDatabaseReader db("database/moose_testdb.json", true, true, false)
static InputParameters validParams()
Real deriv(unsigned n, unsigned alpha, unsigned beta, Real x)
virtual Real datZeroQp(unsigned pvar) const =0
d(a)/d(PorousFlow variable pvar)
Base class Material designed to provide the porosity.
virtual Real decayQp() const =0
Returns "decay" at the quadpoint (porosity = a + (b - a) * exp(decay))
const unsigned int _num_var
Number of PorousFlow variables.
virtual Real atNegInfinityQp() const =0
Returns "a" at the quadpoint (porosity = a + (b - a) * exp(decay))
virtual RealGradient ddecayQp_dgradvar(unsigned pvar) const =0
d(decay)/d(grad(PorousFlow variable pvar))
GenericMaterialProperty< Real, is_ad > & _porosity
Computed porosity at the nodes or quadpoints.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
Definition: NS.h:82
virtual Real datNegInfinityQp(unsigned pvar) const =0
d(a)/d(PorousFlow variable pvar)
virtual Real ddecayQp_dvar(unsigned pvar) const =0
d(decay)/d(PorousFlow variable pvar)
void addClassDescription(const std::string &doc_string)
MooseUnits pow(const MooseUnits &, int)