LCOV - code coverage report
Current view: top level - src/materials - PorousFlowPermeabilityExponential.C (source / functions) Hit Total Coverage
Test: idaholab/moose porous_flow: #31405 (292dce) with base fef103 Lines: 50 50 100.0 %
Date: 2025-09-04 07:55:56 Functions: 6 6 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 "PorousFlowPermeabilityExponential.h"
      11             : 
      12             : registerMooseObject("PorousFlowApp", PorousFlowPermeabilityExponential);
      13             : registerMooseObject("PorousFlowApp", ADPorousFlowPermeabilityExponential);
      14             : 
      15             : template <bool is_ad>
      16             : InputParameters
      17         340 : PorousFlowPermeabilityExponentialTempl<is_ad>::validParams()
      18             : {
      19         340 :   InputParameters params = PorousFlowPermeabilityBase::validParams();
      20         680 :   MooseEnum poroperm_function("log_k ln_k exp_k", "exp_k");
      21         680 :   params.addParam<MooseEnum>("poroperm_function",
      22             :                              poroperm_function,
      23             :                              "Form of the function relating porosity and permeability. The options "
      24             :                              "are: log_k (log k = A phi + B); ln_k (ln k = A phi + B); exp_k (k = "
      25             :                              "B exp(A phi)); where k is permeability, phi is porosity, A and B are "
      26             :                              "empirical constants.");
      27         680 :   params.addParam<RealTensorValue>("k_anisotropy",
      28             :                                    "A tensor to multiply the calculated scalar "
      29             :                                    "permeability, in order to obtain anisotropy if "
      30             :                                    "required. Defaults to isotropic permeability "
      31             :                                    "if not specified.");
      32         680 :   params.addRequiredParam<Real>("A", "Empirical constant; see poroperm_function.");
      33         680 :   params.addRequiredParam<Real>("B", "Empirical constant; see poroperm_function.");
      34         340 :   params.addClassDescription(
      35             :       "This Material calculates the permeability tensor from an exponential function of porosity: "
      36             :       "k = k_ijk * BB exp(AA phi), where k_ijk is a tensor providing the anisotropy, phi is "
      37             :       "porosity, and AA and BB are empirical constants. The user can provide input for the "
      38             :       "function expressed in ln k, log k or exponential forms (see poroperm_function).");
      39         340 :   return params;
      40         340 : }
      41             : 
      42             : template <bool is_ad>
      43         264 : PorousFlowPermeabilityExponentialTempl<is_ad>::PorousFlowPermeabilityExponentialTempl(
      44             :     const InputParameters & parameters)
      45             :   : PorousFlowPermeabilityBaseTempl<is_ad>(parameters),
      46         264 :     _A(this->template getParam<Real>("A")),
      47         528 :     _B(this->template getParam<Real>("B")),
      48         528 :     _k_anisotropy(parameters.isParamValid("k_anisotropy")
      49         528 :                       ? this->template getParam<RealTensorValue>("k_anisotropy")
      50             :                       : RealTensorValue(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)),
      51         264 :     _porosity_qp(this->template getGenericMaterialProperty<Real, is_ad>("PorousFlow_porosity_qp")),
      52         264 :     _dporosity_qp_dvar(is_ad ? nullptr
      53         198 :                              : &this->template getMaterialProperty<std::vector<Real>>(
      54             :                                    "dPorousFlow_porosity_qp_dvar")),
      55         264 :     _dporosity_qp_dgradvar(is_ad ? nullptr
      56         198 :                                  : &this->template getMaterialProperty<std::vector<RealGradient>>(
      57             :                                        "dPorousFlow_porosity_qp_dgradvar")),
      58         528 :     _poroperm_function(this->template getParam<MooseEnum>("poroperm_function")
      59         264 :                            .template getEnum<PoropermFunction>())
      60             : {
      61         264 :   switch (_poroperm_function)
      62             :   {
      63          66 :     case PoropermFunction::log_k:
      64          66 :       _AA = _A * std::log(10.0);
      65          66 :       _BB = std::pow(10.0, _B);
      66          66 :       break;
      67             : 
      68          66 :     case PoropermFunction::ln_k:
      69          66 :       _AA = _A;
      70          66 :       _BB = std::exp(_B);
      71          66 :       break;
      72             : 
      73         132 :     case PoropermFunction::exp_k:
      74         132 :       _AA = _A;
      75         132 :       _BB = _B;
      76         132 :       break;
      77             :   }
      78             : 
      79             :   // Make sure that derivatives are included in the Jacobian calculations
      80         264 :   _dictator.usePermDerivs(true);
      81         264 : }
      82             : 
      83             : template <bool is_ad>
      84             : void
      85        1296 : PorousFlowPermeabilityExponentialTempl<is_ad>::computeQpProperties()
      86             : {
      87        1944 :   _permeability_qp[_qp] = _k_anisotropy * _BB * std::exp(_porosity_qp[_qp] * _AA);
      88             : 
      89             :   if constexpr (!is_ad)
      90             :   {
      91         972 :     (*_dpermeability_qp_dvar)[_qp].resize(_num_var, RealTensorValue());
      92        1944 :     for (unsigned int v = 0; v < _num_var; ++v)
      93         972 :       (*_dpermeability_qp_dvar)[_qp][v] =
      94         972 :           _AA * _permeability_qp[_qp] * (*_dporosity_qp_dvar)[_qp][v];
      95             : 
      96         972 :     (*_dpermeability_qp_dgradvar)[_qp].resize(LIBMESH_DIM);
      97        3888 :     for (const auto i : make_range(Moose::dim))
      98             :     {
      99        2916 :       (*_dpermeability_qp_dgradvar)[_qp][i].resize(_num_var, RealTensorValue());
     100        5832 :       for (unsigned int v = 0; v < _num_var; ++v)
     101        2916 :         (*_dpermeability_qp_dgradvar)[_qp][i][v] =
     102        2916 :             _AA * _permeability_qp[_qp] * (*_dporosity_qp_dgradvar)[_qp][v](i);
     103             :     }
     104             :   }
     105        1296 : }
     106             : 
     107             : template class PorousFlowPermeabilityExponentialTempl<false>;
     108             : template class PorousFlowPermeabilityExponentialTempl<true>;

Generated by: LCOV version 1.14