LCOV - code coverage report
Current view: top level - include/kernels - SplitCHWResBase.h (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #32971 (54bef8) with base c6cf66 Lines: 27 28 96.4 %
Date: 2026-05-29 20:38:39 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         491 : SplitCHWResBase<T>::SplitCHWResBase(const InputParameters & parameters)
      54             :   : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
      55         982 :     _mob_name(getParam<MaterialPropertyName>("mob_name")),
      56         982 :     _mob(getMaterialProperty<T>("mob_name")),
      57         491 :     _is_coupled(isCoupled("w")),
      58         491 :     _w_var(_is_coupled ? coupled("w") : _var.number()),
      59         491 :     _grad_w(_is_coupled ? coupledGradient("w") : _grad_u),
      60         982 :     _dmobdarg(_n_args)
      61             : {
      62             :   // Iterate over all coupled variables
      63         547 :   for (unsigned int i = 0; i < _n_args; ++i)
      64          56 :     _dmobdarg[i] = &getMaterialPropertyDerivative<T>(_mob_name, i);
      65         491 : }
      66             : 
      67             : template <typename T>
      68             : Real
      69    61023084 : SplitCHWResBase<T>::computeQpResidual()
      70             : {
      71    61023084 :   return _mob[_qp] * _grad_w[_qp] * _grad_test[_i][_qp];
      72             : }
      73             : 
      74             : template <typename T>
      75             : Real
      76   162213490 : SplitCHWResBase<T>::computeQpJacobian()
      77             : {
      78   162213490 :   return (_is_coupled && _w_var != _var.number()) ? 0.0 : computeQpWJacobian();
      79             : }
      80             : 
      81             : template <typename T>
      82             : Real
      83   162213490 : SplitCHWResBase<T>::computeQpWJacobian()
      84             : {
      85   162213490 :   return _mob[_qp] * _grad_phi[_j][_qp] * _grad_test[_i][_qp];
      86             : }
      87             : 
      88             : template <typename T>
      89             : Real
      90    35144960 : SplitCHWResBase<T>::computeQpOffDiagJacobian(unsigned int jvar)
      91             : {
      92             :   // c Off-Diagonal Jacobian
      93    35144960 :   if (_w_var == jvar)
      94      563200 :     return computeQpWJacobian();
      95             : 
      96             :   // get the coupled variable jvar is referring to
      97             :   const unsigned int cvar = mapJvarToCvar(jvar);
      98             : 
      99    34581760 :   return (*_dmobdarg[cvar])[_qp] * _phi[_j][_qp] * _grad_w[_qp] * _grad_test[_i][_qp];
     100             : }
     101             : 
     102             : template <typename T>
     103             : InputParameters
     104         917 : SplitCHWResBase<T>::validParams()
     105             : {
     106         917 :   InputParameters params = Kernel::validParams();
     107         917 :   params.addClassDescription(
     108             :       "Split formulation Cahn-Hilliard Kernel for the chemical potential variable");
     109        1834 :   params.addParam<MaterialPropertyName>("mob_name", "mobtemp", "The mobility used with the kernel");
     110        1834 :   params.addCoupledVar("coupled_variables", "Vector of variable arguments of the mobility");
     111        1834 :   params.addCoupledVar(
     112             :       "w", "Coupled chemical potential (if not specified kernel variable will be used)");
     113         917 :   return params;
     114           0 : }

Generated by: LCOV version 1.14