https://mooseframework.inl.gov
MaskedExponential.C
Go to the documentation of this file.
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 
16 {
18  params.addRequiredCoupledVar("w", "Chemical potential for the defect species");
19  params.addRequiredCoupledVar("T", "Temperature");
20  params.addClassDescription(
21  "Kernel to add dilute solution term to Poisson's equation for electrochemical sintering");
22  params.addParam<MaterialPropertyName>(
23  "mask", "hm", "Mask function that specifies where this kernel is active");
24  params.addRequiredParam<MaterialPropertyName>("n_eq", "Equilibrium defect concentration");
25  params.addRequiredParam<int>("species_charge", "Charge of species this kernel is being used for");
26  params.addCoupledVar("args", "Vector of nonlinear variable arguments this object depends on");
27  params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024");
28  return params;
29 }
30 
33  _w_var(coupled("w")),
34  _w(coupledValue("w")),
35  _temp_name(coupledName("T", 0)),
36  _temp_var(coupled("T")),
37  _temp(coupledValue("T")),
38  _mask(getMaterialProperty<Real>("mask")),
39  _prop_dmaskdarg(_n_args),
40  _n_eq(getMaterialProperty<Real>("n_eq")),
41  _prop_dn_eqdT(getMaterialPropertyDerivative<Real>("n_eq", _temp_name)),
42  _prop_dn_eqdarg(_n_args),
43  _z(getParam<int>("species_charge")),
44  _kB(8.617343e-5), // eV/K
45  _e(1.0) // To put energy units in eV
46 {
47  // Get derivatives of mask and equilibrium defect concentration
48  for (unsigned int i = 0; i < _n_args; ++i)
49  {
50  _prop_dmaskdarg[i] = &getMaterialPropertyDerivative<Real>("mask", i);
51  _prop_dn_eqdarg[i] = &getMaterialPropertyDerivative<Real>("n_eq", i);
52  }
53 }
54 
55 void
57 {
58  validateNonlinearCoupling<Real>("mask");
59  validateNonlinearCoupling<Real>("n_eq");
60 }
61 
62 Real
64 {
65  return _mask[_qp] * _z * _e * _n_eq[_qp] * _test[_i][_qp] *
66  std::exp((_w[_qp] - _z * _e * _u[_qp]) / _kB / _temp[_qp]);
67 }
68 
69 Real
71 {
72  return -_mask[_qp] * _z * _z * _e * _e / _kB / _temp[_qp] * _n_eq[_qp] * _test[_i][_qp] *
73  _phi[_j][_qp] * std::exp((_w[_qp] - _z * _e * _u[_qp]) / _kB / _temp[_qp]);
74 }
75 
76 Real
78 {
79  // Handle chemical potential explicitly since it appears in the residual
80  if (jvar == _w_var)
81  return _mask[_qp] * _z * _e * _n_eq[_qp] / _kB / _temp[_qp] *
82  std::exp((_w[_qp] - _z * _e * _u[_qp]) / _kB / _temp[_qp]) * _phi[_j][_qp] *
83  _test[_i][_qp];
84 
85  // Handle temperature explicitly since it appears in the residual
86  if (jvar == _temp_var)
87  return _mask[_qp] * _z * _e * std::exp((_w[_qp] - _z * _e * _u[_qp]) / _kB / _temp[_qp]) *
88  (_prop_dn_eqdT[_qp] -
89  _n_eq[_qp] * (_w[_qp] - _z * _e * _u[_qp]) / _kB / _temp[_qp] / _temp[_qp]) *
90  _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  return _z * _e * std::exp((_w[_qp] - _z * _e * _u[_qp]) / _kB / _temp[_qp]) *
97  ((*_prop_dmaskdarg[cvar])[_qp] + (*_prop_dn_eqdarg[cvar])[_qp]) * _test[_i][_qp] *
98  _phi[_j][_qp];
99 }
std::vector< const MaterialProperty< Real > * > _prop_dn_eqdarg
unsigned int _w_var
Chemical potential.
registerMooseObject("PhaseFieldApp", MaskedExponential)
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const MaterialProperty< Real > & _n_eq
Equilibrium defect concentration.
const int _z
Species charge.
void addRequiredParam(const std::string &name, const std::string &doc_string)
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
virtual void initialSetup()
MaskedExponential(const InputParameters &parameters)
This kernel implements a term in the variationally-derived equivalent form of Poisson&#39;s equation for ...
const VariableValue & _temp
static InputParameters validParams()
void deprecateCoupledVar(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
const MaterialProperty< Real > & _prop_dn_eqdT
const VariableValue & _w
virtual Real computeQpResidual()
void addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const MaterialProperty< Real > & _mask
Mask.
void addClassDescription(const std::string &doc_string)
const Real _e
Electron charge.
void ErrorVector unsigned int
virtual Real computeQpJacobian()
const Real _kB
Boltzmann constant.
unsigned int _temp_var
std::vector< const MaterialProperty< Real > * > _prop_dmaskdarg