www.mooseframework.org
PorousFlowCapillaryPressure.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 
12 template <>
13 InputParameters
15 {
16  InputParameters params = validParams<DiscreteElementUserObject>();
17  params.addRangeCheckedParam<Real>(
18  "sat_lr",
19  0.0,
20  "sat_lr >= 0 & sat_lr < 1",
21  "Liquid residual saturation. Must be between 0 and 1. Default is 0");
22  params.addRangeCheckedParam<Real>("pc_max",
23  1.0e9,
24  "pc_max > 0",
25  "Maximum capillary pressure (Pa). Must be > 0. Default is 1e9");
26  params.addParam<bool>("log_extension",
27  true,
28  "Use a logarithmic extension for low saturation to avoid capillary "
29  "pressure going to infinity. Default is true. Set to false if your "
30  "capillary pressure depends on spatially-dependent variables other than "
31  "saturation, as the log-extension C++ code for this case has yet to be "
32  "implemented");
33  params.addClassDescription("Capillary pressure base class");
34  return params;
35 }
36 
38  : DiscreteElementUserObject(parameters),
39  _sat_lr(getParam<Real>("sat_lr")),
40  _dseff_ds(1.0 / (1.0 - _sat_lr)),
41  _log_ext(getParam<bool>("log_extension")),
42  _pc_max(getParam<Real>("pc_max")),
43  _sat_ext(0.0),
44  _pc_ext(0.0),
45  _slope_ext(0.0),
46  _log10(std::log(10.0))
47 {
48 }
49 
50 void
52 {
53  // If _log_ext = true, calculate the saturation where the the logarithmic
54  // extension meets the raw capillary pressure curve.
55  if (_log_ext)
56  {
59  _slope_ext = (std::log10(_pc_ext) - std::log10(_pc_max)) / _sat_ext;
60  }
61 }
62 
63 Real
64 PorousFlowCapillaryPressure::capillaryPressure(Real saturation, unsigned qp) const
65 {
66  if (_log_ext && saturation < _sat_ext)
68  else
70 }
71 
72 Real
73 PorousFlowCapillaryPressure::dCapillaryPressure(Real saturation, unsigned qp) const
74 {
75  if (_log_ext && saturation < _sat_ext)
77  else
79 }
80 
81 Real
82 PorousFlowCapillaryPressure::d2CapillaryPressure(Real saturation, unsigned qp) const
83 {
84  if (_log_ext && saturation < _sat_ext)
86  else
88 }
89 
90 Real
92 {
93  return (saturation - _sat_lr) / (1.0 - _sat_lr);
94 }
95 
96 Real
97 PorousFlowCapillaryPressure::saturation(Real pc, unsigned qp) const
98 {
99  return effectiveSaturation(pc, qp) * (1.0 - _sat_lr) + _sat_lr;
100 }
101 
102 Real
103 PorousFlowCapillaryPressure::dSaturation(Real pc, unsigned qp) const
104 {
105  return dEffectiveSaturation(pc, qp) * (1.0 - _sat_lr);
106 }
107 
108 Real
109 PorousFlowCapillaryPressure::d2Saturation(Real pc, unsigned qp) const
110 {
111  return d2EffectiveSaturation(pc, qp) * (1.0 - _sat_lr);
112 }
113 
114 Real
116 {
117  return _pc_ext * std::pow(10.0, _slope_ext * (saturation - _sat_ext));
118 }
119 
120 Real
122 {
123  return _pc_ext * _slope_ext * _log10 * std::pow(10.0, _slope_ext * (saturation - _sat_ext));
124 }
125 
126 Real
128 {
129  return _pc_ext * _slope_ext * _slope_ext * _log10 * _log10 *
130  std::pow(10.0, _slope_ext * (saturation - _sat_ext));
131 }
132 
133 Real
135 {
136  // Initial guess for saturation where extension matches curve
137  Real sat = _sat_lr + 0.01;
138 
139  // Calculate the saturation where the extension matches the derivative of the
140  // raw capillary pressure curve
141  const unsigned int max_its = 20;
142  const Real nr_tol = 1.0e-8;
143  unsigned int iter = 0;
144 
145  while (std::abs(interceptFunction(sat)) > nr_tol)
146  {
147  sat = sat - interceptFunction(sat) / interceptFunctionDeriv(sat);
148 
149  iter++;
150  if (iter > max_its)
151  break;
152  }
153 
154  return sat;
155 }
156 
157 Real
159 {
162 
163  return std::log10(pc) - saturation * dpc / (_log10 * pc) - std::log10(_pc_max);
164 }
165 
166 Real
168 {
172 
173  return saturation * (dpc * dpc / pc - d2pc) / (_log10 * pc);
174 }
175 
176 DualReal
177 PorousFlowCapillaryPressure::capillaryPressure(DualReal saturation, unsigned qp) const
178 {
179  const Real Pc = capillaryPressure(saturation.value(), qp);
180  const Real dPc_ds = dCapillaryPressure(saturation.value(), qp);
181 
182  DualReal result = Pc;
183  result.derivatives() = saturation.derivatives() * dPc_ds;
184 
185  return result;
186 }
PorousFlowCapillaryPressure::dSaturation
Real dSaturation(Real pc, unsigned qp=0) const
Derivative of saturation wrt capillary pressure.
Definition: PorousFlowCapillaryPressure.C:103
PorousFlowCapillaryPressure::PorousFlowCapillaryPressure
PorousFlowCapillaryPressure(const InputParameters &parameters)
Definition: PorousFlowCapillaryPressure.C:37
PorousFlowCapillaryPressure::capillaryPressureCurve
virtual Real capillaryPressureCurve(Real saturation, unsigned qp=0) const =0
Raw capillary pressure curve (does not include logarithmic extension)
PorousFlowCapillaryPressure::d2CapillaryPressureLogExt
Real d2CapillaryPressureLogExt(Real s) const
The second derivative of capillary pressure in the logarithmic extension This implementation assumes ...
Definition: PorousFlowCapillaryPressure.C:127
PorousFlowCapillaryPressure::d2EffectiveSaturation
virtual Real d2EffectiveSaturation(Real pc, unsigned qp=0) const =0
Second derivative of effective saturation wrt capillary pressure.
PorousFlowCapillaryPressure::_slope_ext
Real _slope_ext
Gradient of the logarithmic extension This is computed only for qp=0.
Definition: PorousFlowCapillaryPressure.h:247
pow
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
Definition: ExpressionBuilder.h:673
PorousFlowCapillaryPressure::_log10
const Real _log10
log(10)
Definition: PorousFlowCapillaryPressure.h:249
PorousFlowCapillaryPressure::interceptFunction
Real interceptFunction(Real s) const
Calculates the saturation where the logarithmic extension to capillary pressure at low saturation.
Definition: PorousFlowCapillaryPressure.C:158
PorousFlowCapillaryPressure::_sat_ext
Real _sat_ext
Saturation where the logarithmic extension meets the raw curve This is computed only for qp=0.
Definition: PorousFlowCapillaryPressure.h:237
PorousFlowCapillaryPressure::d2CapillaryPressureCurve
virtual Real d2CapillaryPressureCurve(Real saturation, unsigned qp=0) const =0
Second derivative of raw capillary pressure wrt true saturation.
PorousFlowCapillaryPressure.h
PorousFlowCapillaryPressure::effectiveSaturationFromSaturation
Real effectiveSaturationFromSaturation(Real saturation) const
Effective saturation of liquid phase given liquid saturation and residual liquid saturation.
Definition: PorousFlowCapillaryPressure.C:91
PorousFlowCapillaryPressure::_pc_ext
Real _pc_ext
Capillary pressure where the extension meets the raw curve.
Definition: PorousFlowCapillaryPressure.h:242
PorousFlowCapillaryPressure::dCapillaryPressureLogExt
Real dCapillaryPressureLogExt(Real s) const
The derivative of capillary pressure in the logarithmic extension This implementation assumes capilla...
Definition: PorousFlowCapillaryPressure.C:121
PorousFlowCapillaryPressure::effectiveSaturation
virtual Real effectiveSaturation(Real pc, unsigned qp=0) const =0
Effective saturation as a function of capillary pressure.
PorousFlowCapillaryPressure::dEffectiveSaturation
virtual Real dEffectiveSaturation(Real pc, unsigned qp=0) const =0
Derivative of effective saturation wrt capillary pressure.
PorousFlowCapillaryPressure::capillaryPressure
virtual Real capillaryPressure(Real saturation, unsigned qp=0) const
Capillary pressure is calculated as a function of true saturation.
Definition: PorousFlowCapillaryPressure.C:64
PorousFlowCapillaryPressure::dCapillaryPressure
virtual Real dCapillaryPressure(Real saturation, unsigned qp=0) const
Derivative of capillary pressure wrt true saturation.
Definition: PorousFlowCapillaryPressure.C:73
PorousFlowCapillaryPressure::_sat_lr
const Real _sat_lr
Liquid residual saturation.
Definition: PorousFlowCapillaryPressure.h:225
PorousFlowCapillaryPressure::_pc_max
const Real _pc_max
Maximum capillary pressure (Pa). Note: must be <= 0.
Definition: PorousFlowCapillaryPressure.h:231
validParams< PorousFlowCapillaryPressure >
InputParameters validParams< PorousFlowCapillaryPressure >()
Definition: PorousFlowCapillaryPressure.C:14
PorousFlowCapillaryPressure::interceptFunctionDeriv
Real interceptFunctionDeriv(Real s) const
Calculates the saturation where the logarithmic extension to capillary pressure at low saturation.
Definition: PorousFlowCapillaryPressure.C:167
PorousFlowCapillaryPressure::d2Saturation
Real d2Saturation(Real pc, unsigned qp=0) const
Second derivative of saturation wrt capillary pressure.
Definition: PorousFlowCapillaryPressure.C:109
PorousFlowCapillaryPressure::extensionSaturation
Real extensionSaturation() const
Calculates the saturation where the logarithmic extension to capillary pressure meets the raw curve u...
Definition: PorousFlowCapillaryPressure.C:134
PorousFlowCapillaryPressure::d2CapillaryPressure
virtual Real d2CapillaryPressure(Real saturation, unsigned qp=0) const
Second derivative of capillary pressure wrt true saturation.
Definition: PorousFlowCapillaryPressure.C:82
PorousFlowCapillaryPressure::capillaryPressureLogExt
Real capillaryPressureLogExt(Real s) const
The capillary pressure in the logarithmic extension This implementation assumes capillary-pressure is...
Definition: PorousFlowCapillaryPressure.C:115
PorousFlowCapillaryPressure::_log_ext
bool _log_ext
Flag to use a logarithmic extension for low saturation.
Definition: PorousFlowCapillaryPressure.h:229
PorousFlowCapillaryPressure::initialSetup
virtual void initialSetup() override
Definition: PorousFlowCapillaryPressure.C:51
PorousFlowCapillaryPressure::saturation
Real saturation(Real pc, unsigned qp=0) const
Saturation as a function of capillary pressure.
Definition: PorousFlowCapillaryPressure.C:97
PorousFlowCapillaryPressure::dCapillaryPressureCurve
virtual Real dCapillaryPressureCurve(Real saturation, unsigned qp=0) const =0
Derivative of raw capillary pressure wrt true saturation.