www.mooseframework.org
PorousFlow2PhasePP.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 "PorousFlow2PhasePP.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 "
18  "0 (eg, the water phase). It will be <= "
19  "phase1_porepressure.");
20  params.addRequiredCoupledVar("phase1_porepressure",
21  "Variable that is the porepressure of phase 1 (eg, the gas phase)");
22  params.addParam<UserObjectName>("capillary_pressure",
23  "Name of the UserObject defining the capillary pressure");
24  params.addClassDescription("This Material calculates the 2 porepressures and the 2 saturations "
25  "in a 2-phase isothermal situation, and derivatives of these with "
26  "respect to the PorousFlowVariables");
27  return params;
28 }
29 
30 PorousFlow2PhasePP::PorousFlow2PhasePP(const InputParameters & parameters)
31  : PorousFlowVariableBase(parameters),
32 
33  _phase0_porepressure(_nodal_material ? coupledNodalValue("phase0_porepressure")
34  : coupledValue("phase0_porepressure")),
35  _phase0_gradp_qp(coupledGradient("phase0_porepressure")),
36  _phase0_porepressure_varnum(coupled("phase0_porepressure")),
37  _p0var(_dictator.isPorousFlowVariable(_phase0_porepressure_varnum)
38  ? _dictator.porousFlowVariableNum(_phase0_porepressure_varnum)
39  : 0),
40 
41  _phase1_porepressure(_nodal_material ? coupledNodalValue("phase1_porepressure")
42  : coupledValue("phase1_porepressure")),
43  _phase1_gradp_qp(coupledGradient("phase1_porepressure")),
44  _phase1_porepressure_varnum(coupled("phase1_porepressure")),
45  _p1var(_dictator.isPorousFlowVariable(_phase1_porepressure_varnum)
46  ? _dictator.porousFlowVariableNum(_phase1_porepressure_varnum)
47  : 0),
48  _pc_uo(parameters.isParamSetByUser("capillary_pressure")
49  ? &getUserObject<PorousFlowCapillaryPressure>("capillary_pressure")
50  : nullptr)
51 {
52  if (_num_phases != 2)
53  mooseError("The Dictator announces that the number of phases is ",
54  _dictator.numPhases(),
55  " whereas PorousFlow2PhasePP can only be used for 2-phase simulation. When you "
56  "have an efficient government, you have a dictatorship.");
57 }
58 
59 void
61 {
63  buildQpPPSS();
64 }
65 
66 void
68 {
69  // size stuff correctly and prepare the derivative matrices with zeroes
71 
72  const Real pc = buildQpPPSS();
73  const Real dseff = dEffectiveSaturation_dP(pc); // d(seff)/d(pc)
74 
75  if (!_nodal_material)
76  {
77  (*_gradp_qp)[_qp][0] = _phase0_gradp_qp[_qp];
78  (*_gradp_qp)[_qp][1] = _phase1_gradp_qp[_qp];
79  (*_grads_qp)[_qp][0] = dseff * ((*_gradp_qp)[_qp][0] - (*_gradp_qp)[_qp][1]);
80  (*_grads_qp)[_qp][1] = -(*_grads_qp)[_qp][0];
81  }
82 
83  // the derivatives of porepressure with respect to porepressure
84  // remain fixed (at unity) throughout the simulation
85  if (_dictator.isPorousFlowVariable(_phase0_porepressure_varnum))
86  {
87  _dporepressure_dvar[_qp][0][_p0var] = 1.0;
88  if (!_nodal_material)
89  (*_dgradp_qp_dgradv)[_qp][0][_p0var] = 1.0;
90  }
91  if (_dictator.isPorousFlowVariable(_phase1_porepressure_varnum))
92  {
93  _dporepressure_dvar[_qp][1][_p1var] = 1.0;
94  if (!_nodal_material)
95  (*_dgradp_qp_dgradv)[_qp][1][_p1var] = 1.0;
96  }
97 
98  if (_dictator.isPorousFlowVariable(_phase0_porepressure_varnum))
99  {
100  _dsaturation_dvar[_qp][0][_p0var] = dseff;
101  _dsaturation_dvar[_qp][1][_p0var] = -dseff;
102  }
103  if (_dictator.isPorousFlowVariable(_phase1_porepressure_varnum))
104  {
105  _dsaturation_dvar[_qp][0][_p1var] = -dseff;
106  _dsaturation_dvar[_qp][1][_p1var] = dseff;
107  }
108 
109  if (!_nodal_material)
110  {
111  const Real d2seff_qp = d2EffectiveSaturation_dP2(pc); // d^2(seff_qp)/d(pc_qp)^2
112  if (_dictator.isPorousFlowVariable(_phase0_porepressure_varnum))
113  {
114  (*_dgrads_qp_dgradv)[_qp][0][_p0var] = dseff;
115  (*_dgrads_qp_dv)[_qp][0][_p0var] =
116  d2seff_qp * (_phase0_gradp_qp[_qp] - _phase1_gradp_qp[_qp]);
117  (*_dgrads_qp_dgradv)[_qp][1][_p0var] = -dseff;
118  (*_dgrads_qp_dv)[_qp][1][_p0var] =
119  -d2seff_qp * (_phase0_gradp_qp[_qp] - _phase1_gradp_qp[_qp]);
120  }
121  if (_dictator.isPorousFlowVariable(_phase1_porepressure_varnum))
122  {
123  (*_dgrads_qp_dgradv)[_qp][0][_p1var] = -dseff;
124  (*_dgrads_qp_dv)[_qp][0][_p1var] =
125  -d2seff_qp * (_phase0_gradp_qp[_qp] - _phase1_gradp_qp[_qp]);
126  (*_dgrads_qp_dgradv)[_qp][1][_p1var] = dseff;
127  (*_dgrads_qp_dv)[_qp][1][_p1var] =
128  d2seff_qp * (_phase0_gradp_qp[_qp] - _phase1_gradp_qp[_qp]);
129  }
130  }
131 }
132 
133 Real
135 {
136  _porepressure[_qp][0] = _phase0_porepressure[_qp];
137  _porepressure[_qp][1] = _phase1_porepressure[_qp];
138  const Real pc = _phase0_porepressure[_qp] - _phase1_porepressure[_qp]; // this is <= 0
139  const Real seff = effectiveSaturation(pc);
140  _saturation[_qp][0] = seff;
141  _saturation[_qp][1] = 1.0 - seff;
142  return pc;
143 }
144 
145 Real
147 {
148  return _pc_uo->effectiveSaturation(pc);
149 }
150 
151 Real
153 {
154  return _pc_uo->dEffectiveSaturation(pc);
155 }
156 
157 Real
159 {
160  return _pc_uo->d2EffectiveSaturation(pc);
161 }
virtual Real d2EffectiveSaturation_dP2(Real pressure) const
Second derivative of effective saturation wrt to porepressure.
MaterialProperty< std::vector< std::vector< Real > > > & _dporepressure_dvar
d(porepressure)/d(PorousFlow variable)
const unsigned int _p0var
PorousFlow variable number of the phase0 porepressure.
PorousFlow2PhasePP(const InputParameters &parameters)
const unsigned int _phase0_porepressure_varnum
Moose variable number of the phase0 porepressure.
MaterialProperty< std::vector< Real > > & _saturation
Computed nodal or qp saturation of the phases.
virtual Real effectiveSaturation(Real pc) const =0
Effective saturation as a function of capillary pressure.
Base class for capillary pressure for multiphase flow in porous media.
const VariableValue & _phase0_porepressure
Nodal or quadpoint value of porepressure of the zero phase (eg, the water phase)
MaterialProperty< std::vector< std::vector< Real > > > & _dsaturation_dvar
d(saturation)/d(PorousFlow variable)
InputParameters validParams< PorousFlowVariableBase >()
virtual void initQpStatefulProperties() override
Real buildQpPPSS()
Assemble std::vectors of porepressure and saturation at the nodes and quadpoints, and return the capi...
virtual Real dEffectiveSaturation(Real pc) const =0
Derivative of effective saturation wrt capillary pressure.
const VariableGradient & _phase0_gradp_qp
Gradient(phase0_porepressure) at the qps.
virtual Real effectiveSaturation(Real pressure) const
Effective saturation as a function of porepressure (a negative quantity).
virtual void computeQpProperties() override
const unsigned int _phase1_porepressure_varnum
Moose variable number of the phase1 porepressure.
InputParameters validParams< PorousFlow2PhasePP >()
const unsigned int _p1var
PorousFlow variable number of the phase1 porepressure.
virtual Real dEffectiveSaturation_dP(Real pressure) const
Derivative of effective saturation wrt to p.
const VariableGradient & _phase1_gradp_qp
Gradient(phase1_porepressure) at the qps.
const PorousFlowCapillaryPressure * _pc_uo
Capillary pressure UserObject Note: This pointer can be replaced with a reference once the deprecated...
const unsigned int _num_phases
Number of phases.
virtual void computeQpProperties() override
virtual void initQpStatefulProperties() override
const VariableValue & _phase1_porepressure
Nodal or quadpoint value of porepressure of the one phase (eg, the gas phase)
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.
virtual Real d2EffectiveSaturation(Real pc) const =0
Second derivative of effective saturation wrt capillary pressure.