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 "MaskedExponential.h" 11 : 12 : registerMooseObject("PhaseFieldApp", MaskedExponential); 13 : 14 : InputParameters 15 46 : MaskedExponential::validParams() 16 : { 17 46 : InputParameters params = Kernel::validParams(); 18 92 : params.addRequiredCoupledVar("w", "Chemical potential for the defect species"); 19 92 : params.addRequiredCoupledVar("T", "Temperature"); 20 46 : params.addClassDescription( 21 : "Kernel to add dilute solution term to Poisson's equation for electrochemical sintering"); 22 92 : params.addParam<MaterialPropertyName>( 23 : "mask", "hm", "Mask function that specifies where this kernel is active"); 24 92 : params.addRequiredParam<MaterialPropertyName>("n_eq", "Equilibrium defect concentration"); 25 92 : params.addRequiredParam<int>("species_charge", "Charge of species this kernel is being used for"); 26 92 : params.addCoupledVar("args", "Vector of nonlinear variable arguments this object depends on"); 27 92 : params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024"); 28 46 : return params; 29 0 : } 30 : 31 24 : MaskedExponential::MaskedExponential(const InputParameters & parameters) 32 : : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters), 33 24 : _w_var(coupled("w")), 34 24 : _w(coupledValue("w")), 35 24 : _temp_name(coupledName("T", 0)), 36 24 : _temp_var(coupled("T")), 37 24 : _temp(coupledValue("T")), 38 48 : _mask(getMaterialProperty<Real>("mask")), 39 24 : _prop_dmaskdarg(_n_args), 40 48 : _n_eq(getMaterialProperty<Real>("n_eq")), 41 24 : _prop_dn_eqdT(getMaterialPropertyDerivative<Real>("n_eq", _temp_name)), 42 24 : _prop_dn_eqdarg(_n_args), 43 48 : _z(getParam<int>("species_charge")), 44 24 : _kB(8.617343e-5), // eV/K 45 24 : _e(1.0) // To put energy units in eV 46 : { 47 : // Get derivatives of mask and equilibrium defect concentration 48 144 : for (unsigned int i = 0; i < _n_args; ++i) 49 : { 50 120 : _prop_dmaskdarg[i] = &getMaterialPropertyDerivative<Real>("mask", i); 51 120 : _prop_dn_eqdarg[i] = &getMaterialPropertyDerivative<Real>("n_eq", i); 52 : } 53 24 : } 54 : 55 : void 56 24 : MaskedExponential::initialSetup() 57 : { 58 72 : validateNonlinearCoupling<Real>("mask"); 59 48 : validateNonlinearCoupling<Real>("n_eq"); 60 24 : } 61 : 62 : Real 63 684800 : MaskedExponential::computeQpResidual() 64 : { 65 684800 : return _mask[_qp] * _z * _e * _n_eq[_qp] * _test[_i][_qp] * 66 684800 : std::exp((_w[_qp] - _z * _e * _u[_qp]) / _kB / _temp[_qp]); 67 : } 68 : 69 : Real 70 460800 : MaskedExponential::computeQpJacobian() 71 : { 72 460800 : return -_mask[_qp] * _z * _z * _e * _e / _kB / _temp[_qp] * _n_eq[_qp] * _test[_i][_qp] * 73 460800 : _phi[_j][_qp] * std::exp((_w[_qp] - _z * _e * _u[_qp]) / _kB / _temp[_qp]); 74 : } 75 : 76 : Real 77 1433600 : MaskedExponential::computeQpOffDiagJacobian(unsigned int jvar) 78 : { 79 : // Handle chemical potential explicitly since it appears in the residual 80 1433600 : if (jvar == _w_var) 81 358400 : return _mask[_qp] * _z * _e * _n_eq[_qp] / _kB / _temp[_qp] * 82 358400 : std::exp((_w[_qp] - _z * _e * _u[_qp]) / _kB / _temp[_qp]) * _phi[_j][_qp] * 83 358400 : _test[_i][_qp]; 84 : 85 : // Handle temperature explicitly since it appears in the residual 86 1075200 : if (jvar == _temp_var) 87 0 : return _mask[_qp] * _z * _e * std::exp((_w[_qp] - _z * _e * _u[_qp]) / _kB / _temp[_qp]) * 88 0 : (_prop_dn_eqdT[_qp] - 89 0 : _n_eq[_qp] * (_w[_qp] - _z * _e * _u[_qp]) / _kB / _temp[_qp] / _temp[_qp]) * 90 0 : _phi[_j][_qp] * _test[_i][_qp]; 91 : 92 : // General expression for remaining variable dependencies that don't appear in the residual 93 : // for all other vars get the coupled variable jvar is referring to 94 : const unsigned int cvar = mapJvarToCvar(jvar); 95 : 96 1075200 : return _z * _e * std::exp((_w[_qp] - _z * _e * _u[_qp]) / _kB / _temp[_qp]) * 97 1075200 : ((*_prop_dmaskdarg[cvar])[_qp] + (*_prop_dn_eqdarg[cvar])[_qp]) * _test[_i][_qp] * 98 1075200 : _phi[_j][_qp]; 99 : }