LCOV - code coverage report
Current view: top level - include/kernels - MatDiffusionBase.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: fef103 Lines: 35 43 81.4 %
Date: 2025-09-03 20:01:23 Functions: 6 7 85.7 %
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             : #pragma once
      11             : 
      12             : #include "Kernel.h"
      13             : #include "JvarMapInterface.h"
      14             : #include "DerivativeMaterialInterface.h"
      15             : 
      16             : /**
      17             :  * This class template implements a diffusion kernel with a mobility that can vary
      18             :  * spatially and can depend on variables in the simulation. Two classes are derived from
      19             :  * this template, MatDiffusion for isotropic diffusion and MatAnisoDiffusion for
      20             :  * anisotropic diffusion.
      21             :  *
      22             :  * \tparam T Type of the diffusion coefficient parameter. This can be Real for
      23             :  *           isotropic diffusion or RealTensorValue for the general anisotropic case.
      24             :  */
      25             : template <typename T>
      26             : class MatDiffusionBase : public DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>
      27             : {
      28             : public:
      29             :   static InputParameters validParams();
      30             : 
      31             :   MatDiffusionBase(const InputParameters & parameters);
      32             : 
      33             :   virtual void initialSetup() override;
      34             : 
      35             : protected:
      36             :   virtual Real computeQpResidual() override;
      37             :   virtual Real computeQpJacobian() override;
      38             :   virtual Real computeQpOffDiagJacobian(unsigned int jvar) override;
      39             :   virtual Real computeQpCJacobian();
      40             : 
      41             :   /// diffusion coefficient
      42             :   const MaterialProperty<T> & _D;
      43             : 
      44             :   /// diffusion coefficient derivative w.r.t. the kernel variable
      45             :   const MaterialProperty<T> & _dDdc;
      46             : 
      47             :   /// diffusion coefficient derivatives w.r.t. coupled variables
      48             :   std::vector<const MaterialProperty<T> *> _dDdarg;
      49             : 
      50             :   /// is the kernel used in a coupled form?
      51             :   const bool _is_coupled;
      52             : 
      53             :   /// int label for the Concentration
      54             :   unsigned int _v_var;
      55             : 
      56             :   /// Gradient of the concentration
      57             :   const VariableGradient & _grad_v;
      58             : };
      59             : 
      60             : template <typename T>
      61             : InputParameters
      62       17753 : MatDiffusionBase<T>::validParams()
      63             : {
      64       17753 :   InputParameters params = Kernel::validParams();
      65      106518 :   params.addDeprecatedParam<MaterialPropertyName>(
      66             :       "D_name",
      67             :       "The name of the diffusivity",
      68             :       "This parameter has been renamed to 'diffusivity', which is more mnemonic and more conducive "
      69             :       "to passing a number literal");
      70       71012 :   params.addParam<MaterialPropertyName>(
      71             :       "diffusivity", "D", "The diffusivity value or material property");
      72       71012 :   params.addCoupledVar("args",
      73             :                        "Optional vector of arguments for the diffusivity. If provided and "
      74             :                        "diffusivity is a derivative parsed material, Jacobian contributions from "
      75             :                        "the diffusivity will be automatically computed");
      76       71012 :   params.addCoupledVar("conc", "Deprecated! Use 'v' instead");
      77       53259 :   params.addCoupledVar("v",
      78             :                        "Coupled concentration variable for kernel to operate on; if this "
      79             :                        "is not specified, the kernel's nonlinear variable will be used as "
      80             :                        "usual");
      81       17753 :   return params;
      82           0 : }
      83             : 
      84             : template <typename T>
      85        1813 : MatDiffusionBase<T>::MatDiffusionBase(const InputParameters & parameters)
      86             :   : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
      87        3626 :     _D(isParamValid("D_name") ? getMaterialProperty<T>("D_name")
      88        7252 :                               : getMaterialProperty<T>("diffusivity")),
      89       12691 :     _dDdc(getMaterialPropertyDerivative<T>(isParamValid("D_name") ? "D_name" : "diffusivity",
      90        1813 :                                            _var.name())),
      91        3626 :     _dDdarg(_coupled_moose_vars.size()),
      92        3626 :     _is_coupled(isCoupled("v")),
      93        5439 :     _v_var(_is_coupled ? coupled("v") : (isCoupled("conc") ? coupled("conc") : _var.number())),
      94        5439 :     _grad_v(_is_coupled ? coupledGradient("v")
      95        9065 :                         : (isCoupled("conc") ? coupledGradient("conc") : _grad_u))
      96             : {
      97             :   // deprecated variable parameter conc
      98        5439 :   if (isCoupled("conc"))
      99           0 :     mooseDeprecated("In '", name(), "' the parameter 'conc' is deprecated, please use 'v' instead");
     100             : 
     101             :   // fetch derivatives
     102        1939 :   for (unsigned int i = 0; i < _dDdarg.size(); ++i)
     103         882 :     _dDdarg[i] = &getMaterialPropertyDerivative<T>(
     104         630 :         isParamValid("D_name") ? "D_name" : "diffusivity", _coupled_moose_vars[i]->name());
     105        1813 : }
     106             : 
     107             : template <typename T>
     108             : void
     109        1773 : MatDiffusionBase<T>::initialSetup()
     110             : {
     111        5319 :   validateNonlinearCoupling<Real>(parameters().isParamSetByUser("D_name") ? "D_name"
     112             :                                                                           : "diffusivity");
     113        1773 : }
     114             : 
     115             : template <typename T>
     116             : Real
     117    51070041 : MatDiffusionBase<T>::computeQpResidual()
     118             : {
     119    51070041 :   return _D[_qp] * _grad_v[_qp] * _grad_test[_i][_qp];
     120             : }
     121             : 
     122             : template <typename T>
     123             : Real
     124    33731402 : MatDiffusionBase<T>::computeQpJacobian()
     125             : {
     126    33731402 :   Real sum = _phi[_j][_qp] * _dDdc[_qp] * _grad_v[_qp] * _grad_test[_i][_qp];
     127    33731402 :   if (!_is_coupled)
     128    33731402 :     sum += computeQpCJacobian();
     129             : 
     130    33731402 :   return sum;
     131             : }
     132             : 
     133             : template <typename T>
     134             : Real
     135           0 : MatDiffusionBase<T>::computeQpOffDiagJacobian(unsigned int jvar)
     136             : {
     137             :   // get the coupled variable jvar is referring to
     138           0 :   const unsigned int cvar = mapJvarToCvar(jvar);
     139             : 
     140           0 :   Real sum = (*_dDdarg[cvar])[_qp] * _phi[_j][_qp] * _grad_v[_qp] * _grad_test[_i][_qp];
     141             : 
     142           0 :   if (_v_var == jvar)
     143           0 :     sum += computeQpCJacobian();
     144             : 
     145           0 :   return sum;
     146             : }
     147             : 
     148             : template <typename T>
     149             : Real
     150    33731402 : MatDiffusionBase<T>::computeQpCJacobian()
     151             : {
     152    33731402 :   return _D[_qp] * _grad_phi[_j][_qp] * _grad_test[_i][_qp];
     153             : }

Generated by: LCOV version 1.14