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