LCOV - code coverage report
Current view: top level - include/kernels - SplitCHWResBase.h (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 28 29 96.6 %
Date: 2025-09-04 07:55:36 Functions: 11 12 91.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             :  * SplitCHWresBase implements the residual for the chemical
      18             :  * potential in the split form of the Cahn-Hilliard
      19             :  * equation in a general way that can be templated to a scalar or
      20             :  * tensor mobility.
      21             :  */
      22             : template <typename T>
      23             : class SplitCHWResBase : public DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>
      24             : {
      25             : public:
      26             :   static InputParameters validParams();
      27             : 
      28             :   SplitCHWResBase(const InputParameters & parameters);
      29             : 
      30             : protected:
      31             :   virtual Real computeQpResidual();
      32             :   virtual Real computeQpJacobian();
      33             :   virtual Real computeQpWJacobian();
      34             :   virtual Real computeQpOffDiagJacobian(unsigned int jvar);
      35             : 
      36             :   const MaterialPropertyName _mob_name;
      37             :   const MaterialProperty<T> & _mob;
      38             : 
      39             :   /// is the kernel used in a coupled form?
      40             :   const bool _is_coupled;
      41             : 
      42             :   /// int label for the chemical potential
      43             :   unsigned int _w_var;
      44             : 
      45             :   /// Variable value for the chemical potential
      46             :   const VariableGradient & _grad_w;
      47             : 
      48             :   /// derivatives of the mobility
      49             :   std::vector<const MaterialProperty<T> *> _dmobdarg;
      50             : };
      51             : 
      52             : template <typename T>
      53         711 : SplitCHWResBase<T>::SplitCHWResBase(const InputParameters & parameters)
      54             :   : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
      55        1422 :     _mob_name(getParam<MaterialPropertyName>("mob_name")),
      56        1422 :     _mob(getMaterialProperty<T>("mob_name")),
      57         711 :     _is_coupled(isCoupled("w")),
      58         711 :     _w_var(_is_coupled ? coupled("w") : _var.number()),
      59         711 :     _grad_w(_is_coupled ? coupledGradient("w") : _grad_u),
      60        1422 :     _dmobdarg(_n_args)
      61             : {
      62             :   // Iterate over all coupled variables
      63         795 :   for (unsigned int i = 0; i < _n_args; ++i)
      64          84 :     _dmobdarg[i] = &getMaterialPropertyDerivative<T>(_mob_name, i);
      65         711 : }
      66             : 
      67             : template <typename T>
      68             : Real
      69    75019159 : SplitCHWResBase<T>::computeQpResidual()
      70             : {
      71    75019159 :   return _mob[_qp] * _grad_w[_qp] * _grad_test[_i][_qp];
      72             : }
      73             : 
      74             : template <typename T>
      75             : Real
      76   196405336 : SplitCHWResBase<T>::computeQpJacobian()
      77             : {
      78   196405336 :   return (_is_coupled && _w_var != _var.number()) ? 0.0 : computeQpWJacobian();
      79             : }
      80             : 
      81             : template <typename T>
      82             : Real
      83   196405336 : SplitCHWResBase<T>::computeQpWJacobian()
      84             : {
      85   196405336 :   return _mob[_qp] * _grad_phi[_j][_qp] * _grad_test[_i][_qp];
      86             : }
      87             : 
      88             : template <typename T>
      89             : Real
      90    41985280 : SplitCHWResBase<T>::computeQpOffDiagJacobian(unsigned int jvar)
      91             : {
      92             :   // c Off-Diagonal Jacobian
      93    41985280 :   if (_w_var == jvar)
      94      665600 :     return computeQpWJacobian();
      95             : 
      96             :   // get the coupled variable jvar is referring to
      97             :   const unsigned int cvar = mapJvarToCvar(jvar);
      98             : 
      99    41319680 :   return (*_dmobdarg[cvar])[_qp] * _phi[_j][_qp] * _grad_w[_qp] * _grad_test[_i][_qp];
     100             : }
     101             : 
     102             : template <typename T>
     103             : InputParameters
     104        1357 : SplitCHWResBase<T>::validParams()
     105             : {
     106        1357 :   InputParameters params = Kernel::validParams();
     107        1357 :   params.addClassDescription(
     108             :       "Split formulation Cahn-Hilliard Kernel for the chemical potential variable");
     109        2714 :   params.addParam<MaterialPropertyName>("mob_name", "mobtemp", "The mobility used with the kernel");
     110        2714 :   params.addCoupledVar("args", "Vector of variable arguments of the mobility");
     111        2714 :   params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024");
     112        2714 :   params.addCoupledVar(
     113             :       "w", "Coupled chemical potential (if not specified kernel variable will be used)");
     114        1357 :   return params;
     115           0 : }

Generated by: LCOV version 1.14