https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PorousFlow2PhasePP.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 "PorousFlow2PhasePP.h"
12
15
16template <bool is_ad>
19{
21 params.addRequiredCoupledVar("phase0_porepressure",
22 "Variable that is the porepressure of phase "
23 "0 (eg, the water phase). It will be <= "
24 "phase1_porepressure.");
25 params.addRequiredCoupledVar("phase1_porepressure",
26 "Variable that is the porepressure of phase 1 (eg, the gas phase)");
27 params.addRequiredParam<UserObjectName>("capillary_pressure",
28 "Name of the UserObject defining the capillary pressure");
29 params.addClassDescription("This Material calculates the 2 porepressures and the 2 saturations "
30 "in a 2-phase situation, and derivatives of these with "
31 "respect to the PorousFlowVariables");
32 return params;
33}
34
35template <bool is_ad>
37 : PorousFlowVariableBaseTempl<is_ad>(parameters),
38
39 _phase0_porepressure(_nodal_material
40 ? this->template coupledGenericDofValue<is_ad>("phase0_porepressure")
41 : this->template coupledGenericValue<is_ad>("phase0_porepressure")),
42 _phase0_gradp_qp(this->template coupledGenericGradient<is_ad>("phase0_porepressure")),
43 _phase0_porepressure_varnum(coupled("phase0_porepressure")),
44 _p0var(_dictator.isPorousFlowVariable(_phase0_porepressure_varnum)
45 ? _dictator.porousFlowVariableNum(_phase0_porepressure_varnum)
46 : 0),
47
48 _phase1_porepressure(_nodal_material
49 ? this->template coupledGenericDofValue<is_ad>("phase1_porepressure")
50 : this->template coupledGenericValue<is_ad>("phase1_porepressure")),
51 _phase1_gradp_qp(this->template coupledGenericGradient<is_ad>("phase1_porepressure")),
52 _phase1_porepressure_varnum(coupled("phase1_porepressure")),
53 _p1var(_dictator.isPorousFlowVariable(_phase1_porepressure_varnum)
54 ? _dictator.porousFlowVariableNum(_phase1_porepressure_varnum)
55 : 0),
56 _pc_uo(this->template getUserObject<PorousFlowCapillaryPressure>("capillary_pressure"))
57{
58 // These are read with coupledGenericDofValue when at_nodes = true, so they must be
59 // nodal (Lagrange) variables. See #33370.
60 if (this->_nodal_material)
61 this->checkNodalVariables({"phase0_porepressure", "phase1_porepressure"});
62 if (_num_phases != 2)
63 mooseError("The Dictator announces that the number of phases is ",
64 _dictator.numPhases(),
65 " whereas PorousFlow2PhasePP can only be used for 2-phase simulation. When you "
66 "have an efficient government, you have a dictatorship.");
67}
68
69template <bool is_ad>
70void
76
77template <bool is_ad>
78void
80{
81 // size stuff correctly and prepare the derivative matrices with zeroes
83
84 const auto pc = buildQpPPSS();
85 const auto ds = _pc_uo.dSaturation(pc); // dS/d(pc)
86
87 if (!_nodal_material)
88 {
89 (*_gradp_qp)[_qp][0] = _phase0_gradp_qp[_qp];
90 (*_gradp_qp)[_qp][1] = _phase1_gradp_qp[_qp];
91 (*_grads_qp)[_qp][0] = ds * ((*_gradp_qp)[_qp][0] - (*_gradp_qp)[_qp][1]);
92 (*_grads_qp)[_qp][1] = -(*_grads_qp)[_qp][0];
93 }
94
95 // the derivatives of porepressure with respect to porepressure
96 // remain fixed (at unity) throughout the simulation
97 if constexpr (!is_ad)
98 {
99 if (_dictator.isPorousFlowVariable(_phase0_porepressure_varnum))
100 {
101 (*_dporepressure_dvar)[_qp][0][_p0var] = 1.0;
102 if (!_nodal_material)
103 (*_dgradp_qp_dgradv)[_qp][0][_p0var] = 1.0;
104 }
105
106 if (_dictator.isPorousFlowVariable(_phase1_porepressure_varnum))
107 {
108 (*_dporepressure_dvar)[_qp][1][_p1var] = 1.0;
109 if (!_nodal_material)
110 (*_dgradp_qp_dgradv)[_qp][1][_p1var] = 1.0;
111 }
112
113 if (_dictator.isPorousFlowVariable(_phase0_porepressure_varnum))
114 {
115 (*_dsaturation_dvar)[_qp][0][_p0var] = ds;
116 (*_dsaturation_dvar)[_qp][1][_p0var] = -ds;
117 }
118
119 if (_dictator.isPorousFlowVariable(_phase1_porepressure_varnum))
120 {
121 (*_dsaturation_dvar)[_qp][0][_p1var] = -ds;
122 (*_dsaturation_dvar)[_qp][1][_p1var] = ds;
123 }
124
125 if (!_nodal_material)
126 {
127 const auto d2s_qp = _pc_uo.d2Saturation(pc); // d^2(S_qp)/d(pc_qp)^2
128
129 if (_dictator.isPorousFlowVariable(_phase0_porepressure_varnum))
130 {
131 (*_dgrads_qp_dgradv)[_qp][0][_p0var] = ds;
132 (*_dgrads_qp_dv)[_qp][0][_p0var] = d2s_qp * _phase0_gradp_qp[_qp] - _phase1_gradp_qp[_qp];
133 (*_dgrads_qp_dgradv)[_qp][1][_p0var] = -ds;
134 (*_dgrads_qp_dv)[_qp][1][_p0var] = -d2s_qp * _phase0_gradp_qp[_qp] - _phase1_gradp_qp[_qp];
135 }
136
137 if (_dictator.isPorousFlowVariable(_phase1_porepressure_varnum))
138 {
139 (*_dgrads_qp_dgradv)[_qp][0][_p1var] = -ds;
140 (*_dgrads_qp_dv)[_qp][0][_p1var] = -d2s_qp * _phase0_gradp_qp[_qp] - _phase1_gradp_qp[_qp];
141 (*_dgrads_qp_dgradv)[_qp][1][_p1var] = ds;
142 (*_dgrads_qp_dv)[_qp][1][_p1var] = d2s_qp * _phase0_gradp_qp[_qp] - _phase1_gradp_qp[_qp];
143 }
144 }
145 }
146}
147
148template <bool is_ad>
151{
152 _porepressure[_qp][0] = _phase0_porepressure[_qp];
153 _porepressure[_qp][1] = _phase1_porepressure[_qp];
154
155 const auto pc = _phase0_porepressure[_qp] - _phase1_porepressure[_qp]; // this is <= 0
156 const auto sat = _pc_uo.saturation(pc);
157 _saturation[_qp][0] = sat;
158 _saturation[_qp][1] = 1.0 - sat;
159
160 return pc;
161}
162
163template class PorousFlow2PhasePPTempl<false>;
164template class PorousFlow2PhasePPTempl<true>;
void mooseError(Args &&... args)
Moose::GenericType< Real, is_ad > GenericReal
registerMooseObject("PorousFlowApp", PorousFlow2PhasePP)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
Material designed to calculate fluid phase porepressure and saturation for the two-phase situation as...
virtual void initQpStatefulProperties() override
PorousFlow2PhasePPTempl(const InputParameters &parameters)
static InputParameters validParams()
GenericReal< is_ad > buildQpPPSS()
Assemble std::vectors of porepressure and saturation at the nodes and quadpoints, and return the capi...
virtual void computeQpProperties() override
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 computeQpProperties() override
const unsigned int _num_phases
Number of phases.
static InputParameters validParams()
virtual void initQpStatefulProperties() override