https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
15
16template <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
33template <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 // These are read with coupledGenericDofValue when at_nodes = true, so they must be
57 // nodal (Lagrange) variables. See #33370.
58 if (this->_nodal_material)
59 this->checkNodalVariables({"phase0_porepressure", "phase1_saturation"});
60 if (_dictator.numPhases() != 2)
61 mooseError("The Dictator proclaims that the number of phases is ",
62 _dictator.numPhases(),
63 " whereas PorousFlow2PhasePS can only be used for 2-phase simulation. Be aware "
64 "that the Dictator has noted your mistake.");
65}
66
67template <bool is_ad>
68void
74
75template <bool is_ad>
76void
78{
79 // size stuff correctly and prepare the derivative matrices with zeroes
81
82 buildQpPPSS();
83 const auto dpc = _pc_uo.dCapillaryPressure(1.0 - _phase1_saturation[_qp]);
84
85 if (!_nodal_material)
86 {
87 (*_grads_qp)[_qp][0] = -_phase1_grads_qp[_qp];
88 (*_grads_qp)[_qp][1] = _phase1_grads_qp[_qp];
89 (*_gradp_qp)[_qp][0] = _phase0_gradp_qp[_qp];
90 (*_gradp_qp)[_qp][1] = _phase0_gradp_qp[_qp] - dpc * (*_grads_qp)[_qp][1];
91 }
92
93 if constexpr (!is_ad)
94 {
95 // _porepressure depends on _phase0_porepressure, and its derivative is 1
96 if (_dictator.isPorousFlowVariable(_phase0_porepressure_varnum))
97 {
98 // _phase0_porepressure is a PorousFlow variable
99 for (unsigned phase = 0; phase < _num_phases; ++phase)
100 {
101 (*_dporepressure_dvar)[_qp][phase][_pvar] = 1.0;
102 if (!_nodal_material)
103 (*_dgradp_qp_dgradv)[_qp][phase][_pvar] = 1.0;
104 }
105 }
106
107 // _saturation is only dependent on _phase1_saturation, and its derivative is +/- 1
108 if (_dictator.isPorousFlowVariable(_phase1_saturation_varnum))
109 {
110 // _phase1_saturation is a PorousFlow variable
111 // _phase1_porepressure depends on saturation through the capillary pressure function
112 (*_dsaturation_dvar)[_qp][0][_svar] = -1.0;
113 (*_dsaturation_dvar)[_qp][1][_svar] = 1.0;
114 (*_dporepressure_dvar)[_qp][1][_svar] = -dpc;
115
116 if (!_nodal_material)
117 {
118 (*_dgrads_qp_dgradv)[_qp][0][_svar] = -1.0;
119 (*_dgrads_qp_dgradv)[_qp][1][_svar] = 1.0;
120
121 const auto d2pc_qp = _pc_uo.d2CapillaryPressure(1.0 - _phase1_saturation[_qp]);
122
123 (*_dgradp_qp_dv)[_qp][1][_svar] = d2pc_qp * (*_grads_qp)[_qp][1];
124 (*_dgradp_qp_dgradv)[_qp][1][_svar] = -dpc;
125 }
126 }
127 }
128}
129
130template <bool is_ad>
131void
133{
134 _saturation[_qp][0] = 1.0 - _phase1_saturation[_qp];
135 _saturation[_qp][1] = _phase1_saturation[_qp];
136
137 const auto pc = _pc_uo.capillaryPressure(1.0 - _phase1_saturation[_qp]);
138 _porepressure[_qp][0] = _phase0_porepressure[_qp];
139 _porepressure[_qp][1] = _phase0_porepressure[_qp] + pc;
140}
141
142template class PorousFlow2PhasePSTempl<false>;
143template class PorousFlow2PhasePSTempl<true>;
void mooseError(Args &&... args)
registerMooseObject("PorousFlowApp", PorousFlow2PhasePS)
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 porepressures and saturations at nodes and qps using a spe...
void buildQpPPSS()
Assemble std::vectors of porepressure and saturation at the nodes and quadpoints.
static InputParameters validParams()
PorousFlow2PhasePSTempl(const InputParameters &parameters)
virtual void computeQpProperties() override
virtual void initQpStatefulProperties() 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
static InputParameters validParams()
virtual void initQpStatefulProperties() override