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 : #include "KKSPhaseChemicalPotential.h" 11 : #include "MathUtils.h" 12 : 13 : using namespace MathUtils; 14 : 15 : registerMooseObject("PhaseFieldApp", KKSPhaseChemicalPotential); 16 : 17 : InputParameters 18 211 : KKSPhaseChemicalPotential::validParams() 19 : { 20 211 : InputParameters params = Kernel::validParams(); 21 211 : params.addClassDescription("KKS model kernel to enforce the pointwise equality of phase chemical " 22 : "potentials $dF_a/dc_a = dF_b/dc_b$. The non-linear variable of this " 23 : "kernel is $c_a$."); 24 422 : params.addRequiredCoupledVar( 25 : "cb", "Phase b concentration"); // note that ca is u, the non-linear variable! 26 422 : params.addRequiredParam<MaterialPropertyName>("fa_name", 27 : "Base name of the free energy function " 28 : "Fa (f_name in the corresponding " 29 : "derivative function material)"); 30 422 : params.addRequiredParam<MaterialPropertyName>("fb_name", 31 : "Base name of the free energy function " 32 : "Fb (f_name in the corresponding " 33 : "derivative function material)"); 34 422 : params.addParam<Real>("ka", 35 422 : 1.0, 36 : "Site fraction for the ca variable (specify this if ca is a sublattice " 37 : "concentration, and make sure it is a true site fraction eg. 0.6666666) "); 38 422 : params.addParam<Real>("kb", 39 422 : 1.0, 40 : "Site fraction for the cb variable (specify this if ca is a sublattice " 41 : "concentration, and make sure it is a true site fraction eg. 0.6666666) "); 42 422 : params.addCoupledVar( 43 : "args_a", 44 : "Vector of further parameters to Fa (optional, to add in second cross derivatives of Fa)"); 45 422 : params.addCoupledVar( 46 : "args_b", 47 : "Vector of further parameters to Fb (optional, to add in second cross derivatives of Fb)"); 48 211 : return params; 49 0 : } 50 : 51 113 : KKSPhaseChemicalPotential::KKSPhaseChemicalPotential(const InputParameters & parameters) 52 : : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters), 53 113 : _cb_var(coupled("cb")), 54 113 : _cb_name(coupledName("cb", 0)), 55 : // first derivatives 56 113 : _dfadca(getMaterialPropertyDerivative<Real>("fa_name", _var.name())), 57 113 : _dfbdcb(getMaterialPropertyDerivative<Real>("fb_name", _cb_name)), 58 : // second derivatives d2F/dx*dca for jacobian diagonal elements 59 113 : _d2fadca2(getMaterialPropertyDerivative<Real>("fa_name", _var.name(), _var.name())), 60 113 : _d2fbdcbca(getMaterialPropertyDerivative<Real>("fb_name", _cb_name, _var.name())), 61 113 : _d2fadcadarg(_n_args), 62 113 : _d2fbdcbdarg(_n_args), 63 : // site fractions 64 226 : _ka(getParam<Real>("ka")), 65 339 : _kb(getParam<Real>("kb")) 66 : { 67 : #ifdef DEBUG 68 : _console << "KKSPhaseChemicalPotential(" << name() << ") " << _var.name() << ' ' << _cb_name 69 : << '\n'; 70 : #endif 71 : 72 : // lookup table for the material properties representing the derivatives needed for the 73 : // off-diagonal jacobian 74 284 : for (std::size_t i = 0; i < _n_args; ++i) 75 : { 76 171 : _d2fadcadarg[i] = &getMaterialPropertyDerivative<Real>("fa_name", _var.name(), i); 77 171 : _d2fbdcbdarg[i] = &getMaterialPropertyDerivative<Real>("fb_name", _cb_name, i); 78 : } 79 113 : } 80 : 81 : void 82 78 : KKSPhaseChemicalPotential::initialSetup() 83 : { 84 234 : validateNonlinearCoupling<Real>("fa_name"); 85 156 : validateNonlinearCoupling<Real>("fb_name"); 86 78 : } 87 : 88 : Real 89 7918000 : KKSPhaseChemicalPotential::computeQpResidual() 90 : { 91 : // enforce _dfadca==_dfbdcb 92 7918000 : return _test[_i][_qp] * (_dfadca[_qp] / _ka - _dfbdcb[_qp] / _kb); 93 : } 94 : 95 : Real 96 5301840 : KKSPhaseChemicalPotential::computeQpJacobian() 97 : { 98 : // for on diagonal we return the d/dca derivative of the residual 99 5301840 : return _test[_i][_qp] * _phi[_j][_qp] * (_d2fadca2[_qp] / _ka - _d2fbdcbca[_qp] / _kb); 100 : } 101 : 102 : Real 103 5534640 : KKSPhaseChemicalPotential::computeQpOffDiagJacobian(unsigned int jvar) 104 : { 105 : // get the coupled variable jvar is referring to 106 : const unsigned int cvar = mapJvarToCvar(jvar); 107 : 108 5534640 : return _test[_i][_qp] * _phi[_j][_qp] * 109 5534640 : ((*_d2fadcadarg[cvar])[_qp] / _ka - (*_d2fbdcbdarg[cvar])[_qp] / _kb); 110 : }