LCOV - code coverage report
Current view: top level - include/kernels - ACBulk.h (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 24 25 96.0 %
Date: 2025-09-04 07:55:36 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             : #pragma once
      11             : 
      12             : #include "KernelValue.h"
      13             : #include "JvarMapInterface.h"
      14             : #include "DerivativeMaterialInterface.h"
      15             : 
      16             : /**
      17             :  * This is the Allen-Cahn equation base class that implements the bulk or
      18             :  * local energy term of the equation. It is templated on the type of the mobility,
      19             :  * which can be either a number (Real) or a tensor (RealValueTensor).
      20             :  * Note that the function computeDFDOP MUST be overridden in any kernel that inherits from
      21             :  * ACBulk.
      22             :  */
      23             : template <typename T>
      24             : class ACBulk : public DerivativeMaterialInterface<JvarMapKernelInterface<KernelValue>>
      25             : {
      26             : public:
      27             :   ACBulk(const InputParameters & parameters);
      28             : 
      29             :   static InputParameters validParams();
      30             :   virtual void initialSetup();
      31             : 
      32             : protected:
      33             :   virtual Real precomputeQpResidual();
      34             :   virtual Real precomputeQpJacobian();
      35             :   virtual Real computeQpOffDiagJacobian(unsigned int jvar);
      36             : 
      37             :   enum PFFunctionType
      38             :   {
      39             :     Jacobian,
      40             :     Residual
      41             :   };
      42             : 
      43             :   virtual Real computeDFDOP(PFFunctionType type) = 0;
      44             : 
      45             :   /// Mobility
      46             :   const MaterialProperty<T> & _L;
      47             : 
      48             :   /// Mobility derivative w.r.t. order parameter
      49             :   const MaterialProperty<T> & _dLdop;
      50             : 
      51             :   /// Mobility derivative w.r.t coupled variables
      52             :   std::vector<const MaterialProperty<T> *> _dLdarg;
      53             : };
      54             : 
      55             : template <typename T>
      56        7618 : ACBulk<T>::ACBulk(const InputParameters & parameters)
      57             :   : DerivativeMaterialInterface<JvarMapKernelInterface<KernelValue>>(parameters),
      58        7618 :     _L(getMaterialProperty<T>("mob_name")),
      59        7618 :     _dLdop(getMaterialPropertyDerivative<T>("mob_name", _var.name())),
      60       15236 :     _dLdarg(_n_args)
      61             : {
      62             :   // Iterate over all coupled variables
      63       50320 :   for (unsigned int i = 0; i < _n_args; ++i)
      64       42702 :     _dLdarg[i] = &getMaterialPropertyDerivative<T>("mob_name", i);
      65        7618 : }
      66             : 
      67             : template <typename T>
      68             : InputParameters
      69       14469 : ACBulk<T>::validParams()
      70             : {
      71       14469 :   InputParameters params = JvarMapKernelInterface<KernelValue>::validParams();
      72       14469 :   params.addClassDescription("Allen-Cahn base Kernel");
      73       28938 :   params.addParam<MaterialPropertyName>("mob_name", "L", "The mobility used with the kernel");
      74       14469 :   return params;
      75           0 : }
      76             : 
      77             : template <typename T>
      78             : void
      79        6580 : ACBulk<T>::initialSetup()
      80             : {
      81       19740 :   validateNonlinearCoupling<Real>("mob_name");
      82        6580 : }
      83             : 
      84             : template <typename T>
      85             : Real
      86   708645152 : ACBulk<T>::precomputeQpResidual()
      87             : {
      88             :   // Get free energy derivative from function
      89   708645152 :   Real dFdop = computeDFDOP(Residual);
      90             : 
      91             :   // Set residual
      92   708645152 :   return _L[_qp] * dFdop;
      93             : }
      94             : 
      95             : template <typename T>
      96             : Real
      97   462734432 : ACBulk<T>::precomputeQpJacobian()
      98             : {
      99             :   // Get free energy derivative and Jacobian
     100   462734432 :   Real dFdop = computeDFDOP(Residual);
     101             : 
     102   462734432 :   Real JdFdop = computeDFDOP(Jacobian);
     103             : 
     104             :   // Set Jacobian value using product rule
     105   462734432 :   return _L[_qp] * JdFdop + _dLdop[_qp] * _phi[_j][_qp] * dFdop;
     106             : }
     107             : 
     108             : template <typename T>
     109             : Real
     110   583951744 : ACBulk<T>::computeQpOffDiagJacobian(unsigned int jvar)
     111             : {
     112             :   // Get the coupled variable jvar is referring to
     113             :   const unsigned int cvar = mapJvarToCvar(jvar);
     114             : 
     115             :   // Set off-diagonal Jacobian term from mobility derivatives
     116   583951744 :   return (*_dLdarg[cvar])[_qp] * _phi[_j][_qp] * computeDFDOP(Residual) * _test[_i][_qp];
     117             : }

Generated by: LCOV version 1.14