LCOV - code coverage report
Current view: top level - src/materials - PorousFlow2PhasePS.C (source / functions) Hit Total Coverage
Test: porous_flow Test Coverage Lines: 76 80 95.0 %
Date: 2017-11-17 17:48:31 Functions: 10 11 90.9 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "PorousFlow2PhasePS.h"
       9             : #include "PorousFlowCapillaryPressure.h"
      10             : 
      11             : template <>
      12             : InputParameters
      13          45 : validParams<PorousFlow2PhasePS>()
      14             : {
      15          45 :   InputParameters params = validParams<PorousFlowVariableBase>();
      16         135 :   params.addRequiredCoupledVar("phase0_porepressure",
      17          45 :                                "Variable that is the porepressure of phase 0 (eg, the gas phase)");
      18         135 :   params.addRequiredCoupledVar("phase1_saturation",
      19          45 :                                "Variable that is the saturation of phase 1 (eg, the water phase)");
      20         180 :   params.addRangeCheckedParam<Real>(
      21             :       "sat_lr",
      22             :       0.0,
      23             :       "sat_lr >= 0 & sat_lr <= 1",
      24          45 :       "Liquid residual saturation.  Must be between 0 and 1. Default is 0");
      25         135 :   params.addParam<UserObjectName>("capillary_pressure",
      26          45 :                                   "Name of the UserObject defining the capillary pressure");
      27          90 :   params.addClassDescription("This Material calculates the 2 porepressures and the 2 saturations "
      28             :                              "in a 2-phase isothermal situation, and derivatives of these with "
      29          45 :                              "respect to the PorousFlowVariables.");
      30          45 :   return params;
      31             : }
      32             : 
      33         135 : PorousFlow2PhasePS::PorousFlow2PhasePS(const InputParameters & parameters)
      34             :   : PorousFlowVariableBase(parameters),
      35             : 
      36         405 :     _phase0_porepressure(_nodal_material ? coupledNodalValue("phase0_porepressure")
      37         303 :                                          : coupledValue("phase0_porepressure")),
      38         270 :     _phase0_gradp_qp(coupledGradient("phase0_porepressure")),
      39         270 :     _phase0_porepressure_varnum(coupled("phase0_porepressure")),
      40         135 :     _pvar(_dictator.isPorousFlowVariable(_phase0_porepressure_varnum)
      41         135 :               ? _dictator.porousFlowVariableNum(_phase0_porepressure_varnum)
      42             :               : 0),
      43             : 
      44         405 :     _phase1_saturation(_nodal_material ? coupledNodalValue("phase1_saturation")
      45         303 :                                        : coupledValue("phase1_saturation")),
      46         270 :     _phase1_grads_qp(coupledGradient("phase1_saturation")),
      47         270 :     _phase1_saturation_varnum(coupled("phase1_saturation")),
      48         135 :     _svar(_dictator.isPorousFlowVariable(_phase1_saturation_varnum)
      49         135 :               ? _dictator.porousFlowVariableNum(_phase1_saturation_varnum)
      50             :               : 0),
      51             : 
      52         405 :     _sat_lr(getParam<Real>("sat_lr")),
      53         135 :     _dseff_ds(1.0 / (1.0 - _sat_lr)),
      54         270 :     _pc_uo(parameters.isParamSetByUser("capillary_pressure")
      55         405 :                ? &getUserObject<PorousFlowCapillaryPressure>("capillary_pressure")
      56        1620 :                : nullptr)
      57             : {
      58         135 :   if (_dictator.numPhases() != 2)
      59             :     mooseError("The Dictator proclaims that the number of phases is ",
      60           0 :                _dictator.numPhases(),
      61             :                " whereas PorousFlow2PhasePS can only be used for 2-phase simulation.  Be aware "
      62           0 :                "that the Dictator has noted your mistake.");
      63         135 : }
      64             : 
      65             : void
      66        1688 : PorousFlow2PhasePS::initQpStatefulProperties()
      67             : {
      68        1688 :   PorousFlowVariableBase::initQpStatefulProperties();
      69        1688 :   buildQpPPSS();
      70        1688 : }
      71             : 
      72             : void
      73      179272 : PorousFlow2PhasePS::computeQpProperties()
      74             : {
      75             :   // size stuff correctly and prepare the derivative matrices with zeroes
      76      179272 :   PorousFlowVariableBase::computeQpProperties();
      77             : 
      78      179272 :   buildQpPPSS();
      79      358544 :   const Real dpc = dCapillaryPressure_dS(_phase1_saturation[_qp]);
      80             : 
      81      179272 :   if (!_nodal_material)
      82             :   {
      83      305172 :     (*_grads_qp)[_qp][0] = -_phase1_grads_qp[_qp];
      84      101724 :     (*_grads_qp)[_qp][1] = _phase1_grads_qp[_qp];
      85      305172 :     (*_gradp_qp)[_qp][0] = _phase0_gradp_qp[_qp];
      86      101724 :     (*_gradp_qp)[_qp][1] = _phase0_gradp_qp[_qp] - dpc * (*_grads_qp)[_qp][1];
      87             :   }
      88             : 
      89             :   // _porepressure depends on _phase0_porepressure, and its derivative is 1
      90      179272 :   if (_dictator.isPorousFlowVariable(_phase0_porepressure_varnum))
      91             :   {
      92             :     // _phase0_porepressure is a PorousFlow variable
      93      889400 :     for (unsigned phase = 0; phase < _num_phases; ++phase)
      94             :     {
      95      711520 :       _dporepressure_dvar[_qp][phase][_pvar] = 1.0;
      96      355760 :       if (!_nodal_material)
      97      401328 :         (*_dgradp_qp_dgradv)[_qp][phase][_pvar] = 1.0;
      98             :     }
      99             :   }
     100             : 
     101             :   // _saturation is only dependent on _phase1_saturation, and its derivative is +/- 1
     102      179272 :   if (_dictator.isPorousFlowVariable(_phase1_saturation_varnum))
     103             :   {
     104             :     // _phase1_saturation is a porflow variable
     105             :     // _phase1_porepressure depends on saturation through the capillary pressure function
     106      358544 :     _dsaturation_dvar[_qp][0][_svar] = -1.0;
     107      179272 :     _dsaturation_dvar[_qp][1][_svar] = 1.0;
     108      358544 :     _dporepressure_dvar[_qp][1][_svar] = -dpc;
     109             : 
     110      179272 :     if (!_nodal_material)
     111             :     {
     112      203448 :       (*_dgrads_qp_dgradv)[_qp][0][_svar] = -1.0;
     113      101724 :       (*_dgrads_qp_dgradv)[_qp][1][_svar] = 1.0;
     114      203448 :       const Real d2pc_qp = d2CapillaryPressure_dS2(_phase1_saturation[_qp]);
     115      406896 :       (*_dgradp_qp_dv)[_qp][1][_svar] = -d2pc_qp * (*_grads_qp)[_qp][1];
     116      203448 :       (*_dgradp_qp_dgradv)[_qp][1][_svar] = -dpc;
     117             :     }
     118             :   }
     119      179272 : }
     120             : 
     121             : void
     122      180960 : PorousFlow2PhasePS::buildQpPPSS()
     123             : {
     124      542880 :   _saturation[_qp][0] = 1.0 - _phase1_saturation[_qp];
     125      180960 :   _saturation[_qp][1] = _phase1_saturation[_qp];
     126      180960 :   const Real pc = capillaryPressure(_phase1_saturation[_qp]);
     127      542880 :   _porepressure[_qp][0] = _phase0_porepressure[_qp];
     128      180960 :   _porepressure[_qp][1] = _phase0_porepressure[_qp] - pc;
     129      180960 : }
     130             : 
     131             : Real
     132           0 : PorousFlow2PhasePS::effectiveSaturation(Real saturation) const
     133             : {
     134           0 :   return (saturation - _sat_lr) / (1.0 - _sat_lr);
     135             : }
     136             : 
     137             : Real
     138      180960 : PorousFlow2PhasePS::capillaryPressure(Real saturation) const
     139             : {
     140      180960 :   return _pc_uo->capillaryPressure(saturation);
     141             : }
     142             : 
     143             : Real
     144      179272 : PorousFlow2PhasePS::dCapillaryPressure_dS(Real saturation) const
     145             : {
     146      179272 :   return _pc_uo->dCapillaryPressure(saturation);
     147             : }
     148             : 
     149             : Real
     150      101724 : PorousFlow2PhasePS::d2CapillaryPressure_dS2(Real saturation) const
     151             : {
     152      101724 :   return _pc_uo->d2CapillaryPressure(saturation);
     153        2499 : }

Generated by: LCOV version 1.11