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("coupled_variables", "Vector of variable arguments of the mobility"); 81 498 : return params; 82 0 : } 83 : 84 : template <typename T> 85 : void 86 116 : CHBulk<T>::initialSetup() 87 : { 88 348 : validateNonlinearCoupling<Real>("mob_name"); 89 116 : } 90 : 91 : template <typename T> 92 : RealGradient 93 8699036 : CHBulk<T>::precomputeQpResidual() 94 : { 95 8699036 : return _M[_qp] * computeGradDFDCons(Residual); 96 : } 97 : 98 : template <typename T> 99 : RealGradient 100 85466480 : CHBulk<T>::precomputeQpJacobian() 101 : { 102 85466480 : RealGradient grad_value = _M[_qp] * computeGradDFDCons(Jacobian) + 103 85466480 : _dMdc[_qp] * _phi[_j][_qp] * computeGradDFDCons(Residual); 104 : 105 85466480 : return grad_value; 106 : } 107 : 108 : template <typename T> 109 : Real 110 22962176 : CHBulk<T>::computeQpOffDiagJacobian(unsigned int jvar) 111 : { 112 : // get the coupled variable jvar is referring to 113 : const unsigned int cvar = mapJvarToCvar(jvar); 114 : 115 22962176 : return (*_dMdarg[cvar])[_qp] * _phi[_j][_qp] * computeGradDFDCons(Residual) * _grad_test[_i][_qp]; 116 : }