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 303 : KKSPhaseChemicalPotential::validParams() 19 : { 20 303 : InputParameters params = Kernel::validParams(); 21 303 : 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 606 : params.addRequiredCoupledVar( 25 : "cb", "Phase b concentration"); // note that ca is u, the non-linear variable! 26 606 : 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 606 : 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 606 : params.addParam<Real>("ka", 35 606 : 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 606 : params.addParam<Real>("kb", 39 606 : 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 606 : params.addCoupledVar( 43 : "args_a", 44 : "Vector of further parameters to Fa (optional, to add in second cross derivatives of Fa)"); 45 606 : params.addCoupledVar( 46 : "args_b", 47 : "Vector of further parameters to Fb (optional, to add in second cross derivatives of Fb)"); 48 303 : return params; 49 0 : } 50 : 51 159 : KKSPhaseChemicalPotential::KKSPhaseChemicalPotential(const InputParameters & parameters) 52 : : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters), 53 159 : _cb_var(coupled("cb")), 54 159 : _cb_name(coupledName("cb", 0)), 55 : // first derivatives 56 159 : _dfadca(getMaterialPropertyDerivative<Real>("fa_name", _var.name())), 57 159 : _dfbdcb(getMaterialPropertyDerivative<Real>("fb_name", _cb_name)), 58 : // second derivatives d2F/dx*dca for jacobian diagonal elements 59 159 : _d2fadca2(getMaterialPropertyDerivative<Real>("fa_name", _var.name(), _var.name())), 60 159 : _d2fbdcbca(getMaterialPropertyDerivative<Real>("fb_name", _cb_name, _var.name())), 61 159 : _d2fadcadarg(_n_args), 62 159 : _d2fbdcbdarg(_n_args), 63 : // site fractions 64 318 : _ka(getParam<Real>("ka")), 65 477 : _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 396 : for (std::size_t i = 0; i < _n_args; ++i) 75 : { 76 237 : _d2fadcadarg[i] = &getMaterialPropertyDerivative<Real>("fa_name", _var.name(), i); 77 237 : _d2fbdcbdarg[i] = &getMaterialPropertyDerivative<Real>("fb_name", _cb_name, i); 78 : } 79 159 : } 80 : 81 : void 82 114 : KKSPhaseChemicalPotential::initialSetup() 83 : { 84 342 : validateNonlinearCoupling<Real>("fa_name"); 85 228 : validateNonlinearCoupling<Real>("fb_name"); 86 114 : } 87 : 88 : Real 89 9656280 : KKSPhaseChemicalPotential::computeQpResidual() 90 : { 91 : // enforce _dfadca==_dfbdcb 92 9656280 : return _test[_i][_qp] * (_dfadca[_qp] / _ka - _dfbdcb[_qp] / _kb); 93 : } 94 : 95 : Real 96 6072000 : KKSPhaseChemicalPotential::computeQpJacobian() 97 : { 98 : // for on diagonal we return the d/dca derivative of the residual 99 6072000 : return _test[_i][_qp] * _phi[_j][_qp] * (_d2fadca2[_qp] / _ka - _d2fbdcbca[_qp] / _kb); 100 : } 101 : 102 : Real 103 6351360 : KKSPhaseChemicalPotential::computeQpOffDiagJacobian(unsigned int jvar) 104 : { 105 : // get the coupled variable jvar is referring to 106 : const unsigned int cvar = mapJvarToCvar(jvar); 107 : 108 6351360 : return _test[_i][_qp] * _phi[_j][_qp] * 109 6351360 : ((*_d2fadcadarg[cvar])[_qp] / _ka - (*_d2fbdcbdarg[cvar])[_qp] / _kb); 110 : }