https://mooseframework.inl.gov
PorousFlow2PhasePS.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 "PorousFlow2PhasePS.h"
12 
13 registerMooseObject("PorousFlowApp", PorousFlow2PhasePS);
15 
16 template <bool is_ad>
19 {
21  params.addRequiredCoupledVar("phase0_porepressure",
22  "Variable that is the porepressure of phase 0 (the liquid phase)");
23  params.addRequiredCoupledVar("phase1_saturation",
24  "Variable that is the saturation of phase 1 (the gas phase)");
25  params.addRequiredParam<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 situation, and derivatives of these with "
29  "respect to the PorousFlowVariables.");
30  return params;
31 }
32 
33 template <bool is_ad>
35  : PorousFlowVariableBaseTempl<is_ad>(parameters),
36  _phase0_porepressure(_nodal_material
37  ? this->template coupledGenericDofValue<is_ad>("phase0_porepressure")
38  : this->template coupledGenericValue<is_ad>("phase0_porepressure")),
39  _phase0_gradp_qp(this->template coupledGenericGradient<is_ad>("phase0_porepressure")),
40  _phase0_porepressure_varnum(coupled("phase0_porepressure")),
41  _pvar(_dictator.isPorousFlowVariable(_phase0_porepressure_varnum)
42  ? _dictator.porousFlowVariableNum(_phase0_porepressure_varnum)
43  : 0),
44 
45  _phase1_saturation(_nodal_material
46  ? this->template coupledGenericDofValue<is_ad>("phase1_saturation")
47  : this->template coupledGenericValue<is_ad>("phase1_saturation")),
48  _phase1_grads_qp(this->template coupledGenericGradient<is_ad>("phase1_saturation")),
49  _phase1_saturation_varnum(coupled("phase1_saturation")),
50  _svar(_dictator.isPorousFlowVariable(_phase1_saturation_varnum)
51  ? _dictator.porousFlowVariableNum(_phase1_saturation_varnum)
52  : 0),
53 
54  _pc_uo(this->template getUserObject<PorousFlowCapillaryPressure>("capillary_pressure"))
55 {
56  if (_dictator.numPhases() != 2)
57  mooseError("The Dictator proclaims that the number of phases is ",
58  _dictator.numPhases(),
59  " whereas PorousFlow2PhasePS can only be used for 2-phase simulation. Be aware "
60  "that the Dictator has noted your mistake.");
61 }
62 
63 template <bool is_ad>
64 void
66 {
68  buildQpPPSS();
69 }
70 
71 template <bool is_ad>
72 void
74 {
75  // size stuff correctly and prepare the derivative matrices with zeroes
77 
78  buildQpPPSS();
79  const auto dpc = _pc_uo.dCapillaryPressure(1.0 - _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  if constexpr (!is_ad)
90  {
91  // _porepressure depends on _phase0_porepressure, and its derivative is 1
92  if (_dictator.isPorousFlowVariable(_phase0_porepressure_varnum))
93  {
94  // _phase0_porepressure is a PorousFlow variable
95  for (unsigned phase = 0; phase < _num_phases; ++phase)
96  {
97  (*_dporepressure_dvar)[_qp][phase][_pvar] = 1.0;
98  if (!_nodal_material)
99  (*_dgradp_qp_dgradv)[_qp][phase][_pvar] = 1.0;
100  }
101  }
102 
103  // _saturation is only dependent on _phase1_saturation, and its derivative is +/- 1
104  if (_dictator.isPorousFlowVariable(_phase1_saturation_varnum))
105  {
106  // _phase1_saturation is a PorousFlow variable
107  // _phase1_porepressure depends on saturation through the capillary pressure function
108  (*_dsaturation_dvar)[_qp][0][_svar] = -1.0;
109  (*_dsaturation_dvar)[_qp][1][_svar] = 1.0;
110  (*_dporepressure_dvar)[_qp][1][_svar] = -dpc;
111 
112  if (!_nodal_material)
113  {
114  (*_dgrads_qp_dgradv)[_qp][0][_svar] = -1.0;
115  (*_dgrads_qp_dgradv)[_qp][1][_svar] = 1.0;
116 
117  const auto d2pc_qp = _pc_uo.d2CapillaryPressure(1.0 - _phase1_saturation[_qp]);
118 
119  (*_dgradp_qp_dv)[_qp][1][_svar] = d2pc_qp * (*_grads_qp)[_qp][1];
120  (*_dgradp_qp_dgradv)[_qp][1][_svar] = -dpc;
121  }
122  }
123  }
124 }
125 
126 template <bool is_ad>
127 void
129 {
130  _saturation[_qp][0] = 1.0 - _phase1_saturation[_qp];
131  _saturation[_qp][1] = _phase1_saturation[_qp];
132 
133  const auto pc = _pc_uo.capillaryPressure(1.0 - _phase1_saturation[_qp]);
134  _porepressure[_qp][0] = _phase0_porepressure[_qp];
135  _porepressure[_qp][1] = _phase0_porepressure[_qp] + pc;
136 }
137 
138 template class PorousFlow2PhasePSTempl<false>;
139 template class PorousFlow2PhasePSTempl<true>;
virtual void computeQpProperties() override
virtual void computeQpProperties() override
Material designed to calculate fluid-phase porepressures and saturations at nodes and qps using a spe...
virtual void initQpStatefulProperties() override
void buildQpPPSS()
Assemble std::vectors of porepressure and saturation at the nodes and quadpoints. ...
void mooseError(Args &&... args)
static InputParameters validParams()
PorousFlow2PhasePSTempl(const InputParameters &parameters)
void addRequiredParam(const std::string &name, const std::string &doc_string)
Base class for capillary pressure for multiphase flow in porous media.
Base class for thermophysical variable materials, which assemble materials for primary variables such...
virtual void initQpStatefulProperties() override
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
registerMooseObject("PorousFlowApp", PorousFlow2PhasePS)
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()