https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
13
16{
18 params.addRequiredCoupledVar("w", "Chemical potential for the defect species");
19 params.addRequiredCoupledVar("T", "Temperature");
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("coupled_variables",
27 "Vector of nonlinear variable arguments this object depends on");
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
55void
57{
58 validateNonlinearCoupling<Real>("mask");
59 validateNonlinearCoupling<Real>("n_eq");
60}
61
62Real
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
69Real
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
76Real
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}
registerMooseObject("PhaseFieldApp", MaskedExponential)
void ErrorVector unsigned int
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void addCoupledVar(const std::string &name, const std::string &doc_string)
static InputParameters validParams()
This kernel implements a term in the variationally-derived equivalent form of Poisson's equation for ...
const Real _kB
Boltzmann constant.
const MaterialProperty< Real > & _mask
Mask.
const int _z
Species charge.
const Real _e
Electron charge.
const VariableValue & _w
unsigned int _w_var
Chemical potential.
MaskedExponential(const InputParameters &parameters)
virtual Real computeQpJacobian()
virtual void initialSetup()
const MaterialProperty< Real > & _n_eq
Equilibrium defect concentration.
const MaterialProperty< Real > & _prop_dn_eqdT
virtual Real computeQpResidual()
std::vector< const MaterialProperty< Real > * > _prop_dn_eqdarg
std::vector< const MaterialProperty< Real > * > _prop_dmaskdarg
static InputParameters validParams()
const VariableValue & _temp
virtual Real computeQpOffDiagJacobian(unsigned int jvar)