www.mooseframework.org
PorousFlow2PhasePS.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #include "PorousFlow2PhasePS.h"
10 
11 template <>
12 InputParameters
14 {
15  InputParameters params = validParams<PorousFlowVariableBase>();
16  params.addRequiredCoupledVar("phase0_porepressure",
17  "Variable that is the porepressure of phase 0 (eg, the gas phase)");
18  params.addRequiredCoupledVar("phase1_saturation",
19  "Variable that is the saturation of phase 1 (eg, the water phase)");
20  params.addRangeCheckedParam<Real>(
21  "sat_lr",
22  0.0,
23  "sat_lr >= 0 & sat_lr <= 1",
24  "Liquid residual saturation. Must be between 0 and 1. Default is 0");
25  params.addParam<UserObjectName>("capillary_pressure",
26  "Name of the UserObject defining the capillary pressure");
27  params.addClassDescription("This Material calculates the 2 porepressures and the 2 saturations "
28  "in a 2-phase isothermal situation, and derivatives of these with "
29  "respect to the PorousFlowVariables.");
30  return params;
31 }
32 
33 PorousFlow2PhasePS::PorousFlow2PhasePS(const InputParameters & parameters)
34  : PorousFlowVariableBase(parameters),
35 
36  _phase0_porepressure(_nodal_material ? coupledNodalValue("phase0_porepressure")
37  : coupledValue("phase0_porepressure")),
38  _phase0_gradp_qp(coupledGradient("phase0_porepressure")),
39  _phase0_porepressure_varnum(coupled("phase0_porepressure")),
40  _pvar(_dictator.isPorousFlowVariable(_phase0_porepressure_varnum)
41  ? _dictator.porousFlowVariableNum(_phase0_porepressure_varnum)
42  : 0),
43 
44  _phase1_saturation(_nodal_material ? coupledNodalValue("phase1_saturation")
45  : coupledValue("phase1_saturation")),
46  _phase1_grads_qp(coupledGradient("phase1_saturation")),
47  _phase1_saturation_varnum(coupled("phase1_saturation")),
48  _svar(_dictator.isPorousFlowVariable(_phase1_saturation_varnum)
49  ? _dictator.porousFlowVariableNum(_phase1_saturation_varnum)
50  : 0),
51 
52  _sat_lr(getParam<Real>("sat_lr")),
53  _dseff_ds(1.0 / (1.0 - _sat_lr)),
54  _pc_uo(parameters.isParamSetByUser("capillary_pressure")
55  ? &getUserObject<PorousFlowCapillaryPressure>("capillary_pressure")
56  : nullptr)
57 {
58  if (_dictator.numPhases() != 2)
59  mooseError("The Dictator proclaims that the number of phases is ",
60  _dictator.numPhases(),
61  " whereas PorousFlow2PhasePS can only be used for 2-phase simulation. Be aware "
62  "that the Dictator has noted your mistake.");
63 }
64 
65 void
67 {
69  buildQpPPSS();
70 }
71 
72 void
74 {
75  // size stuff correctly and prepare the derivative matrices with zeroes
77 
78  buildQpPPSS();
79  const Real dpc = dCapillaryPressure_dS(_phase1_saturation[_qp]);
80 
81  if (!_nodal_material)
82  {
83  (*_grads_qp)[_qp][0] = -_phase1_grads_qp[_qp];
84  (*_grads_qp)[_qp][1] = _phase1_grads_qp[_qp];
85  (*_gradp_qp)[_qp][0] = _phase0_gradp_qp[_qp];
86  (*_gradp_qp)[_qp][1] = _phase0_gradp_qp[_qp] - dpc * (*_grads_qp)[_qp][1];
87  }
88 
89  // _porepressure depends on _phase0_porepressure, and its derivative is 1
90  if (_dictator.isPorousFlowVariable(_phase0_porepressure_varnum))
91  {
92  // _phase0_porepressure is a PorousFlow variable
93  for (unsigned phase = 0; phase < _num_phases; ++phase)
94  {
95  _dporepressure_dvar[_qp][phase][_pvar] = 1.0;
96  if (!_nodal_material)
97  (*_dgradp_qp_dgradv)[_qp][phase][_pvar] = 1.0;
98  }
99  }
100 
101  // _saturation is only dependent on _phase1_saturation, and its derivative is +/- 1
102  if (_dictator.isPorousFlowVariable(_phase1_saturation_varnum))
103  {
104  // _phase1_saturation is a porflow variable
105  // _phase1_porepressure depends on saturation through the capillary pressure function
106  _dsaturation_dvar[_qp][0][_svar] = -1.0;
107  _dsaturation_dvar[_qp][1][_svar] = 1.0;
108  _dporepressure_dvar[_qp][1][_svar] = -dpc;
109 
110  if (!_nodal_material)
111  {
112  (*_dgrads_qp_dgradv)[_qp][0][_svar] = -1.0;
113  (*_dgrads_qp_dgradv)[_qp][1][_svar] = 1.0;
114  const Real d2pc_qp = d2CapillaryPressure_dS2(_phase1_saturation[_qp]);
115  (*_dgradp_qp_dv)[_qp][1][_svar] = -d2pc_qp * (*_grads_qp)[_qp][1];
116  (*_dgradp_qp_dgradv)[_qp][1][_svar] = -dpc;
117  }
118  }
119 }
120 
121 void
123 {
124  _saturation[_qp][0] = 1.0 - _phase1_saturation[_qp];
125  _saturation[_qp][1] = _phase1_saturation[_qp];
126  const Real pc = capillaryPressure(_phase1_saturation[_qp]);
127  _porepressure[_qp][0] = _phase0_porepressure[_qp];
128  _porepressure[_qp][1] = _phase0_porepressure[_qp] - pc;
129 }
130 
131 Real
133 {
134  return (saturation - _sat_lr) / (1.0 - _sat_lr);
135 }
136 
137 Real
139 {
140  return _pc_uo->capillaryPressure(saturation);
141 }
142 
143 Real
145 {
146  return _pc_uo->dCapillaryPressure(saturation);
147 }
148 
149 Real
151 {
152  return _pc_uo->d2CapillaryPressure(saturation);
153 }
const unsigned int _pvar
PorousFlow variable number of the phase0 porepressure.
PorousFlow2PhasePS(const InputParameters &parameters)
MaterialProperty< std::vector< std::vector< Real > > > & _dporepressure_dvar
d(porepressure)/d(PorousFlow variable)
void buildQpPPSS()
Assemble std::vectors of porepressure and saturation at the nodes and quadpoints. ...
const VariableGradient & _phase0_gradp_qp
Gradient(phase0_porepressure) at the qps.
const VariableValue & _phase0_porepressure
Nodal or quadpoint value of porepressure of the zero phase (eg, the gas phase)
const unsigned int _phase0_porepressure_varnum
Moose variable number of the phase0 porepressure.
virtual void computeQpProperties() override
MaterialProperty< std::vector< Real > > & _saturation
Computed nodal or qp saturation of the phases.
Base class for capillary pressure for multiphase flow in porous media.
MaterialProperty< std::vector< std::vector< Real > > > & _dsaturation_dvar
d(saturation)/d(PorousFlow variable)
virtual Real dCapillaryPressure(Real saturation) const
Derivative of capillary pressure wrt true saturation.
virtual Real d2CapillaryPressure(Real saturation) const
Second derivative of capillary pressure wrt true saturation.
InputParameters validParams< PorousFlowVariableBase >()
InputParameters validParams< PorousFlow2PhasePS >()
virtual Real capillaryPressure(Real saturation) const
Capillary pressure is calculated as a function of true saturation.
virtual Real effectiveSaturation(Real saturation) const
Effective saturation of liquid phase.
virtual void initQpStatefulProperties() override
const Real _sat_lr
Liquid residual saturation.
const VariableValue & _phase1_saturation
Nodal or quadpoint value of saturation of the one phase (eg, the water phase)
const unsigned int _svar
PorousFlow variable number of the phase1 saturation.
virtual void computeQpProperties() override
const unsigned int _phase1_saturation_varnum
Moose variable number of the phase1 saturation.
virtual Real capillaryPressure(Real saturation) const
Capillary pressure as a function of saturation.
const VariableGradient & _phase1_grads_qp
Gradient(phase1_saturation) at the qps.
const unsigned int _num_phases
Number of phases.
virtual Real d2CapillaryPressure_dS2(Real saturation) const
Second derivative of capillary pressure wrt to saturation.
const PorousFlowCapillaryPressure * _pc_uo
Capillary pressure UserObject Note: This pointer can be replaced with a reference once the deprecated...
void FORTRAN_CALL() saturation(double &P, double &T, int &N, int &nerr)
virtual void initQpStatefulProperties() override
virtual Real dCapillaryPressure_dS(Real seff) const
Derivative of capillary pressure wrt to saturation.
Base class for thermophysical variable materials, which assemble materials for primary variables such...
MaterialProperty< std::vector< Real > > & _porepressure
Computed nodal or quadpoint values of porepressure of the phases.