LCOV - code coverage report
Current view: top level - src/materials - PorousFlow2PhasePS.C (source / functions) Hit Total Coverage
Test: idaholab/moose porous_flow: #32971 (54bef8) with base c6cf66 Lines: 61 64 95.3 %
Date: 2026-05-29 20:38:56 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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"
      11             : #include "PorousFlowCapillaryPressure.h"
      12             : 
      13             : registerMooseObject("PorousFlowApp", PorousFlow2PhasePS);
      14             : registerMooseObject("PorousFlowApp", ADPorousFlow2PhasePS);
      15             : 
      16             : template <bool is_ad>
      17             : InputParameters
      18        2624 : PorousFlow2PhasePSTempl<is_ad>::validParams()
      19             : {
      20        2624 :   InputParameters params = PorousFlowVariableBaseTempl<is_ad>::validParams();
      21        5248 :   params.addRequiredCoupledVar("phase0_porepressure",
      22             :                                "Variable that is the porepressure of phase 0 (the liquid phase)");
      23        5248 :   params.addRequiredCoupledVar("phase1_saturation",
      24             :                                "Variable that is the saturation of phase 1 (the gas phase)");
      25        5248 :   params.addRequiredParam<UserObjectName>("capillary_pressure",
      26             :                                           "Name of the UserObject defining the capillary pressure");
      27        2624 :   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        2624 :   return params;
      31           0 : }
      32             : 
      33             : template <bool is_ad>
      34        2025 : PorousFlow2PhasePSTempl<is_ad>::PorousFlow2PhasePSTempl(const InputParameters & parameters)
      35             :   : PorousFlowVariableBaseTempl<is_ad>(parameters),
      36        4050 :     _phase0_porepressure(_nodal_material
      37         774 :                              ? this->template coupledGenericDofValue<is_ad>("phase0_porepressure")
      38        3276 :                              : this->template coupledGenericValue<is_ad>("phase0_porepressure")),
      39        2025 :     _phase0_gradp_qp(this->template coupledGenericGradient<is_ad>("phase0_porepressure")),
      40        2025 :     _phase0_porepressure_varnum(coupled("phase0_porepressure")),
      41        2025 :     _pvar(_dictator.isPorousFlowVariable(_phase0_porepressure_varnum)
      42        2025 :               ? _dictator.porousFlowVariableNum(_phase0_porepressure_varnum)
      43             :               : 0),
      44             : 
      45        4050 :     _phase1_saturation(_nodal_material
      46        2025 :                            ? this->template coupledGenericDofValue<is_ad>("phase1_saturation")
      47        3276 :                            : this->template coupledGenericValue<is_ad>("phase1_saturation")),
      48        2025 :     _phase1_grads_qp(this->template coupledGenericGradient<is_ad>("phase1_saturation")),
      49        2025 :     _phase1_saturation_varnum(coupled("phase1_saturation")),
      50        2025 :     _svar(_dictator.isPorousFlowVariable(_phase1_saturation_varnum)
      51        2025 :               ? _dictator.porousFlowVariableNum(_phase1_saturation_varnum)
      52             :               : 0),
      53             : 
      54        4050 :     _pc_uo(this->template getUserObject<PorousFlowCapillaryPressure>("capillary_pressure"))
      55             : {
      56        2025 :   if (_dictator.numPhases() != 2)
      57           0 :     mooseError("The Dictator proclaims that the number of phases is ",
      58           0 :                _dictator.numPhases(),
      59             :                " whereas PorousFlow2PhasePS can only be used for 2-phase simulation.  Be aware "
      60             :                "that the Dictator has noted your mistake.");
      61        2025 : }
      62             : 
      63             : template <bool is_ad>
      64             : void
      65       13246 : PorousFlow2PhasePSTempl<is_ad>::initQpStatefulProperties()
      66             : {
      67       13246 :   PorousFlowVariableBaseTempl<is_ad>::initQpStatefulProperties();
      68       13246 :   buildQpPPSS();
      69       13246 : }
      70             : 
      71             : template <bool is_ad>
      72             : void
      73     1144504 : PorousFlow2PhasePSTempl<is_ad>::computeQpProperties()
      74             : {
      75             :   // size stuff correctly and prepare the derivative matrices with zeroes
      76     1144504 :   PorousFlowVariableBaseTempl<is_ad>::computeQpProperties();
      77             : 
      78     1144504 :   buildQpPPSS();
      79     1167404 :   const auto dpc = _pc_uo.dCapillaryPressure(1.0 - _phase1_saturation[_qp]);
      80             : 
      81     1144504 :   if (!_nodal_material)
      82             :   {
      83      658666 :     (*_grads_qp)[_qp][0] = -_phase1_grads_qp[_qp];
      84      635766 :     (*_grads_qp)[_qp][1] = _phase1_grads_qp[_qp];
      85      635766 :     (*_gradp_qp)[_qp][0] = _phase0_gradp_qp[_qp];
      86      658666 :     (*_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     1121604 :     if (_dictator.isPorousFlowVariable(_phase0_porepressure_varnum))
      93             :     {
      94             :       // _phase0_porepressure is a PorousFlow variable
      95     2930400 :       for (unsigned phase = 0; phase < _num_phases; ++phase)
      96             :       {
      97     1953600 :         (*_dporepressure_dvar)[_qp][phase][_pvar] = 1.0;
      98     1953600 :         if (!_nodal_material)
      99     1078912 :           (*_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     1121604 :     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      978816 :       (*_dsaturation_dvar)[_qp][0][_svar] = -1.0;
     109      978816 :       (*_dsaturation_dvar)[_qp][1][_svar] = 1.0;
     110      978816 :       (*_dporepressure_dvar)[_qp][1][_svar] = -dpc;
     111             : 
     112      978816 :       if (!_nodal_material)
     113             :       {
     114      541472 :         (*_dgrads_qp_dgradv)[_qp][0][_svar] = -1.0;
     115      541472 :         (*_dgrads_qp_dgradv)[_qp][1][_svar] = 1.0;
     116             : 
     117      541472 :         const auto d2pc_qp = _pc_uo.d2CapillaryPressure(1.0 - _phase1_saturation[_qp]);
     118             : 
     119      541472 :         (*_dgradp_qp_dv)[_qp][1][_svar] = d2pc_qp * (*_grads_qp)[_qp][1];
     120      541472 :         (*_dgradp_qp_dgradv)[_qp][1][_svar] = -dpc;
     121             :       }
     122             :     }
     123             :   }
     124     1144504 : }
     125             : 
     126             : template <bool is_ad>
     127             : void
     128     1157750 : PorousFlow2PhasePSTempl<is_ad>::buildQpPPSS()
     129             : {
     130     1181040 :   _saturation[_qp][0] = 1.0 - _phase1_saturation[_qp];
     131     1157750 :   _saturation[_qp][1] = _phase1_saturation[_qp];
     132             : 
     133     1181040 :   const auto pc = _pc_uo.capillaryPressure(1.0 - _phase1_saturation[_qp]);
     134     1157750 :   _porepressure[_qp][0] = _phase0_porepressure[_qp];
     135     1157750 :   _porepressure[_qp][1] = _phase0_porepressure[_qp] + pc;
     136     1157750 : }
     137             : 
     138             : template class PorousFlow2PhasePSTempl<false>;
     139             : template class PorousFlow2PhasePSTempl<true>;

Generated by: LCOV version 1.14