diff --git a/modules/phase_field/include/kernels/CHBulk.h b/modules/phase_field/include/kernels/CHBulk.h index 9c451a80f57c..60ce40c7597f 100644 --- a/modules/phase_field/include/kernels/CHBulk.h +++ b/modules/phase_field/include/kernels/CHBulk.h @@ -11,25 +11,20 @@ #include "JvarMapInterface.h" #include "DerivativeMaterialInterface.h" -//Forward Declarations -class CHBulk; - -template<> -InputParameters validParams(); /** This is the Cahn-Hilliard equation base class that implements the bulk or local energy term of the equation. * See M.R. Tonks et al. / Computational Materials Science 51 (2012) 20–29 for more information. * Note that the function computeGradDFDCons MUST be overridden in any kernel that inherits from * CHBulk. Use CHMath as an example of how this works. **/ - +template class CHBulk : public DerivativeMaterialInterface > { public: - CHBulk(const InputParameters & parameters); -protected: + static InputParameters validParams(); +protected: virtual RealGradient precomputeQpResidual(); virtual RealGradient precomputeQpJacobian(); virtual Real computeQpOffDiagJacobian(unsigned int jvar); @@ -42,10 +37,67 @@ class CHBulk : public DerivativeMaterialInterface > virtual RealGradient computeGradDFDCons(PFFunctionType type) = 0; - const MaterialProperty & _M; - const MaterialProperty & _dMdc; + const MaterialProperty & _M; + const MaterialProperty & _dMdc; - std::vector *> _dMdarg; + std::vector *> _dMdarg; }; +template +CHBulk::CHBulk(const InputParameters & parameters) : + DerivativeMaterialInterface >(parameters), + _M(getMaterialProperty("mob_name")), + _dMdc(getMaterialPropertyDerivative("mob_name", _var.name())) +{ + // Get number of coupled variables + unsigned int nvar = _coupled_moose_vars.size(); + + // reserve space for derivatives + _dMdarg.resize(nvar); + + // Iterate over all coupled variables + for (unsigned int i = 0; i < nvar; ++i) + _dMdarg[i] = &getMaterialPropertyDerivative("mob_name", _coupled_moose_vars[i]->name()); +} + +template +InputParameters +CHBulk::validParams() +{ + InputParameters params = ::validParams(); + params.addClassDescription("Cahn-Hilliard base Kernel"); + params.addParam("mob_name", "M", "The mobility used with the kernel"); + params.addCoupledVar("args", "Vector of arguments to mobility"); + return params; +} + +template +RealGradient +CHBulk::precomputeQpResidual() +{ + return _M[_qp] * computeGradDFDCons(Residual); +} + +template +RealGradient +CHBulk::precomputeQpJacobian() +{ + RealGradient grad_value = _M[_qp] * computeGradDFDCons(Jacobian) + + _dMdc[_qp] * _phi[_j][_qp] * computeGradDFDCons(Residual); + + return grad_value; +} + +template +Real +CHBulk::computeQpOffDiagJacobian(unsigned int jvar) +{ + // get the coupled variable jvar is referring to + unsigned int cvar; + if (!mapJvarToCvar(jvar, cvar)) + return 0.0; + + return (*_dMdarg[cvar])[_qp] * _phi[_j][_qp] * computeGradDFDCons(Residual) * _grad_test[_i][_qp]; +} + #endif //CHBULK_H diff --git a/modules/phase_field/src/kernels/CHBulk.C b/modules/phase_field/src/kernels/CHBulk.C deleted file mode 100644 index 04d2655c9c29..000000000000 --- a/modules/phase_field/src/kernels/CHBulk.C +++ /dev/null @@ -1,60 +0,0 @@ -/****************************************************************/ -/* MOOSE - Multiphysics Object Oriented Simulation Environment */ -/* */ -/* All contents are licensed under LGPL V2.1 */ -/* See LICENSE for full restrictions */ -/****************************************************************/ -#include "CHBulk.h" - -template<> -InputParameters validParams() -{ - InputParameters params = validParams(); - params.addClassDescription("Cahn-Hilliard Kernel"); - params.addParam("mob_name", "M", "The mobility used with the kernel"); - params.addCoupledVar("args", "Vector of arguments to mobility"); - return params; -} - -CHBulk::CHBulk(const InputParameters & parameters) : - DerivativeMaterialInterface >(parameters), - _M(getMaterialProperty("mob_name")), - _dMdc(getMaterialPropertyDerivative("mob_name", _var.name())) -{ - // Get number of coupled variables - unsigned int nvar = _coupled_moose_vars.size(); - - // reserve space for derivatives - _dMdarg.resize(nvar); - - // Iterate over all coupled variables - for (unsigned int i = 0; i < nvar; ++i) - _dMdarg[i] = &getMaterialPropertyDerivative("mob_name", _coupled_moose_vars[i]->name()); -} - -RealGradient -CHBulk::precomputeQpResidual() -{ - return _M[_qp]*computeGradDFDCons(Residual); -} - -RealGradient -CHBulk::precomputeQpJacobian() -{ - RealGradient grad_value = _M[_qp] * computeGradDFDCons(Jacobian) - + _dMdc[_qp] * _phi[_j][_qp] * computeGradDFDCons(Residual); - - return grad_value; -} - -Real -CHBulk::computeQpOffDiagJacobian(unsigned int jvar) -{ - // get the coupled variable jvar is referring to - unsigned int cvar; - if (!mapJvarToCvar(jvar, cvar)) - return 0.0; - - return (*_dMdarg[cvar])[_qp] * _phi[_j][_qp] * computeGradDFDCons(Residual) * _grad_test[_i][_qp]; -} -