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 "KernelGrad.h" 13 : #include "JvarMapInterface.h" 14 : #include "DerivativeMaterialInterface.h" 15 : 16 : /** 17 : * This is the Cahn-Hilliard 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 : * See M.R. Tonks et al. / Computational Materials Science 51 (2012) 20-29 for more information. 21 : * Note that the function computeGradDFDCons MUST be overridden in any kernel that inherits from 22 : * CHBulk. Use CHMath as an example of how this works. 23 : */ 24 : template <typename T> 25 : class CHBulk : public DerivativeMaterialInterface<JvarMapKernelInterface<KernelGrad>> 26 : { 27 : public: 28 : CHBulk(const InputParameters & parameters); 29 : 30 : static InputParameters validParams(); 31 : virtual void initialSetup(); 32 : 33 : protected: 34 : virtual RealGradient precomputeQpResidual(); 35 : virtual RealGradient precomputeQpJacobian(); 36 : virtual Real computeQpOffDiagJacobian(unsigned int jvar); 37 : 38 : enum PFFunctionType 39 : { 40 : Jacobian, 41 : Residual 42 : }; 43 : 44 : virtual RealGradient computeGradDFDCons(PFFunctionType type) = 0; 45 : 46 : /// Mobility 47 : const MaterialProperty<T> & _M; 48 : 49 : /// Mobility derivative w.r.t. concentration 50 : const MaterialProperty<T> & _dMdc; 51 : 52 : /// Mobility derivative w.r.t coupled variables 53 : std::vector<const MaterialProperty<T> *> _dMdarg; 54 : }; 55 : 56 : template <typename T> 57 263 : CHBulk<T>::CHBulk(const InputParameters & parameters) 58 : : DerivativeMaterialInterface<JvarMapKernelInterface<KernelGrad>>(parameters), 59 263 : _M(getMaterialProperty<T>("mob_name")), 60 526 : _dMdc(getMaterialPropertyDerivative<T>("mob_name", _var.name())) 61 : { 62 : // Get number of coupled variables 63 263 : unsigned int nvar = _coupled_moose_vars.size(); 64 : 65 : // reserve space for derivatives 66 263 : _dMdarg.resize(nvar); 67 : 68 : // Iterate over all coupled variables 69 314 : for (unsigned int i = 0; i < nvar; ++i) 70 51 : _dMdarg[i] = &getMaterialPropertyDerivative<T>("mob_name", _coupled_moose_vars[i]->name()); 71 263 : } 72 : 73 : template <typename T> 74 : InputParameters 75 498 : CHBulk<T>::validParams() 76 : { 77 498 : InputParameters params = KernelGrad::validParams(); 78 498 : params.addClassDescription("Cahn-Hilliard base Kernel"); 79 996 : params.addParam<MaterialPropertyName>("mob_name", "M", "The mobility used with the kernel"); 80 996 : params.addCoupledVar("args", "Vector of variable arguments of the mobility"); 81 996 : params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024"); 82 498 : return params; 83 0 : } 84 : 85 : template <typename T> 86 : void 87 116 : CHBulk<T>::initialSetup() 88 : { 89 348 : validateNonlinearCoupling<Real>("mob_name"); 90 116 : } 91 : 92 : template <typename T> 93 : RealGradient 94 8698316 : CHBulk<T>::precomputeQpResidual() 95 : { 96 8698316 : return _M[_qp] * computeGradDFDCons(Residual); 97 : } 98 : 99 : template <typename T> 100 : RealGradient 101 85466000 : CHBulk<T>::precomputeQpJacobian() 102 : { 103 85466000 : RealGradient grad_value = _M[_qp] * computeGradDFDCons(Jacobian) + 104 85466000 : _dMdc[_qp] * _phi[_j][_qp] * computeGradDFDCons(Residual); 105 : 106 85466000 : return grad_value; 107 : } 108 : 109 : template <typename T> 110 : Real 111 22962176 : CHBulk<T>::computeQpOffDiagJacobian(unsigned int jvar) 112 : { 113 : // get the coupled variable jvar is referring to 114 : const unsigned int cvar = mapJvarToCvar(jvar); 115 : 116 22962176 : return (*_dMdarg[cvar])[_qp] * _phi[_j][_qp] * computeGradDFDCons(Residual) * _grad_test[_i][_qp]; 117 : }