LCOV - code coverage report
Current view: top level - src/fvkernels - FVPorousFlowHeatAdvection.C (source / functions) Hit Total Coverage
Test: idaholab/moose porous_flow: #31405 (292dce) with base fef103 Lines: 51 53 96.2 %
Date: 2025-09-04 07:55:56 Functions: 3 3 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 "FVPorousFlowHeatAdvection.h"
      11             : #include "PorousFlowDictator.h"
      12             : 
      13             : registerADMooseObject("PorousFlowApp", FVPorousFlowHeatAdvection);
      14             : 
      15             : InputParameters
      16          41 : FVPorousFlowHeatAdvection::validParams()
      17             : {
      18          41 :   InputParameters params = FVFluxKernel::validParams();
      19             :   RealVectorValue g(0, 0, -9.81);
      20          82 :   params.addParam<RealVectorValue>("gravity", g, "Gravity vector. Defaults to (0, 0, -9.81)");
      21          82 :   params.addRequiredParam<UserObjectName>("PorousFlowDictator",
      22             :                                           "The PorousFlowDictator UserObject");
      23          41 :   params.set<unsigned short>("ghost_layers") = 2;
      24          41 :   params.addClassDescription("Heat flux advected by the fluid");
      25          41 :   return params;
      26           0 : }
      27             : 
      28          22 : FVPorousFlowHeatAdvection::FVPorousFlowHeatAdvection(const InputParameters & params)
      29             :   : FVFluxKernel(params),
      30          22 :     _dictator(getUserObject<PorousFlowDictator>("PorousFlowDictator")),
      31          22 :     _num_phases(_dictator.numPhases()),
      32          44 :     _density(getADMaterialProperty<std::vector<Real>>("PorousFlow_fluid_phase_density_qp")),
      33          22 :     _density_neighbor(
      34          22 :         getNeighborADMaterialProperty<std::vector<Real>>("PorousFlow_fluid_phase_density_qp")),
      35          44 :     _viscosity(getADMaterialProperty<std::vector<Real>>("PorousFlow_viscosity_qp")),
      36          22 :     _viscosity_neighbor(
      37          22 :         getNeighborADMaterialProperty<std::vector<Real>>("PorousFlow_viscosity_qp")),
      38          44 :     _enthalpy(getADMaterialProperty<std::vector<Real>>("PorousFlow_fluid_phase_enthalpy_qp")),
      39          22 :     _enthalpy_neighbor(
      40          22 :         getNeighborADMaterialProperty<std::vector<Real>>("PorousFlow_fluid_phase_enthalpy_qp")),
      41          44 :     _relperm(getADMaterialProperty<std::vector<Real>>("PorousFlow_relative_permeability_qp")),
      42          22 :     _relperm_neighbor(
      43          22 :         getNeighborADMaterialProperty<std::vector<Real>>("PorousFlow_relative_permeability_qp")),
      44          44 :     _permeability(getADMaterialProperty<RealTensorValue>("PorousFlow_permeability_qp")),
      45          22 :     _permeability_neighbor(
      46          22 :         getNeighborADMaterialProperty<RealTensorValue>("PorousFlow_permeability_qp")),
      47          44 :     _pressure(getADMaterialProperty<std::vector<Real>>("PorousFlow_porepressure_qp")),
      48          22 :     _pressure_neighbor(
      49          22 :         getNeighborADMaterialProperty<std::vector<Real>>("PorousFlow_porepressure_qp")),
      50          44 :     _grad_p(getADMaterialProperty<std::vector<RealGradient>>("PorousFlow_grad_porepressure_qp")),
      51          66 :     _gravity(getParam<RealVectorValue>("gravity"))
      52             : {
      53          22 : }
      54             : 
      55             : ADReal
      56       89913 : FVPorousFlowHeatAdvection::computeQpResidual()
      57             : {
      58       89913 :   ADReal flux = 0.0;
      59             :   ADRealGradient pressure_grad;
      60             :   ADRealTensorValue mobility;
      61             : 
      62      179826 :   for (const auto p : make_range(_num_phases))
      63             :   {
      64             :     // If we are on a boundary face, use the gradient computed in _grad_p
      65       89913 :     if (onBoundary(*_face_info))
      66             :     {
      67        3526 :       const auto & gradp = -_grad_p[_qp][p];
      68        3526 :       pressure_grad = gradp + _density[_qp][p] * _gravity;
      69             : 
      70        7052 :       mobility = _enthalpy[_qp][p] * _relperm[_qp][p] * _permeability[_qp] * _density[_qp][p] /
      71        7052 :                  _viscosity[_qp][p];
      72             :     }
      73             :     else
      74             :     {
      75             :       // If we are on an internal face, calculate the gradient explicitly
      76       86387 :       const auto & p_elem = _pressure[_qp][p];
      77       86387 :       const auto & p_neighbor = _pressure_neighbor[_qp][p];
      78             : 
      79      172774 :       const auto gradp = (p_elem - p_neighbor) * _face_info->eCN() / _face_info->dCNMag();
      80             : 
      81      172774 :       const auto mobility_element = _enthalpy[_qp][p] * _relperm[_qp][p] * _permeability[_qp] *
      82      172774 :                                     _density[_qp][p] / _viscosity[_qp][p];
      83             : 
      84           0 :       const auto mobility_neighbor = _enthalpy_neighbor[_qp][p] * _relperm_neighbor[_qp][p] *
      85      172774 :                                      _permeability_neighbor[_qp] * _density_neighbor[_qp][p] /
      86      172774 :                                      _viscosity_neighbor[_qp][p];
      87             : 
      88       86387 :       pressure_grad = gradp + _density[_qp][p] * _gravity;
      89             : 
      90       86387 :       interpolate(Moose::FV::InterpMethod::Upwind,
      91             :                   mobility,
      92             :                   mobility_element,
      93             :                   mobility_neighbor,
      94             :                   pressure_grad,
      95       86387 :                   *_face_info,
      96             :                   true);
      97             :     }
      98             : 
      99       89913 :     flux += mobility * pressure_grad * _normal;
     100             :   }
     101             : 
     102       89913 :   return flux;
     103             : }

Generated by: LCOV version 1.14