www.mooseframework.org
CoupledBEEquilibriumSub.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
8 
9 template <>
10 InputParameters
12 {
13  InputParameters params = validParams<Kernel>();
14  params.addParam<Real>("weight", 1.0, "The weight of the equilibrium species");
15  params.addParam<Real>(
16  "log_k",
17  0.0,
18  "The equilibrium constant of this equilibrium species in the dissociation reaction");
19  params.addParam<Real>(
20  "sto_u",
21  1.0,
22  "The stoichiometric coefficient of the primary variable this kernel operates on");
23  params.addRequiredParam<std::vector<Real>>(
24  "sto_v", "The stoichiometric coefficients of coupled primary species");
25  params.addCoupledVar("v", "Coupled primary species constituting the equilibrium species");
26  params.addClassDescription("Derivative of equilibrium species concentration wrt time");
27  return params;
28 }
29 
30 CoupledBEEquilibriumSub::CoupledBEEquilibriumSub(const InputParameters & parameters)
31  : Kernel(parameters),
32  _weight(getParam<Real>("weight")),
33  _log_k(getParam<Real>("log_k")),
34  _sto_u(getParam<Real>("sto_u")),
35  _sto_v(getParam<std::vector<Real>>("sto_v")),
36  _porosity(getMaterialProperty<Real>("porosity")),
37  _u_old(valueOld())
38 {
39  const unsigned int n = coupledComponents("v");
40  _vars.resize(n);
41  _v_vals.resize(n);
42  _v_vals_old.resize(n);
43 
44  for (unsigned int i = 0; i < n; ++i)
45  {
46  _vars[i] = coupled("v", i);
47  _v_vals[i] = &coupledValue("v", i);
48  _v_vals_old[i] = &coupledValueOld("v", i);
49  }
50 }
51 
52 Real
54 {
55  Real _val_new = std::pow(10.0, _log_k) * std::pow(_u[_qp], _sto_u);
56  Real _val_old = std::pow(10.0, _log_k) * std::pow(_u_old[_qp], _sto_u);
57  for (unsigned int i = 0; i < _v_vals.size(); ++i)
58  {
59  _val_new *= std::pow((*_v_vals[i])[_qp], _sto_v[i]);
60  _val_old *= std::pow((*_v_vals_old[i])[_qp], _sto_v[i]);
61  }
62 
63  return _porosity[_qp] * _weight * _test[_i][_qp] * (_val_new - _val_old) / _dt;
64 }
65 
66 Real
68 {
69  Real _val_new = std::pow(10.0, _log_k) * _sto_u * std::pow(_u[_qp], _sto_u - 1.0) * _phi[_j][_qp];
70  for (unsigned int i = 0; i < _v_vals.size(); ++i)
71  _val_new *= std::pow((*_v_vals[i])[_qp], _sto_v[i]);
72 
73  return _porosity[_qp] * _test[_i][_qp] * _weight * _val_new / _dt;
74 }
75 
76 Real
78 {
79  // If no coupled species, return 0
80  if (_v_vals.size() == 0)
81  return 0.0;
82 
83  // If jvar is not one of the coupled species, return 0
84  if (std::find(_vars.begin(), _vars.end(), jvar) == _vars.end())
85  return 0.0;
86 
87  Real _val_new = std::pow(10.0, _log_k) * std::pow(_u[_qp], _sto_u);
88 
89  for (unsigned int i = 0; i < _vars.size(); ++i)
90  {
91  if (jvar == _vars[i])
92  _val_new *= _sto_v[i] * std::pow((*_v_vals[i])[_qp], _sto_v[i] - 1.0) * _phi[_j][_qp];
93  else
94  _val_new *= std::pow((*_v_vals[i])[_qp], _sto_v[i]);
95  }
96 
97  return _porosity[_qp] * _test[_i][_qp] * _weight * _val_new / _dt;
98 }
CoupledBEEquilibriumSub(const InputParameters &parameters)
InputParameters validParams< CoupledBEEquilibriumSub >()
virtual Real computeQpJacobian() override
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
std::vector< unsigned int > _vars
Coupled primary species variable numbers.
std::vector< const VariableValue * > _v_vals
Coupled primary species concentrations.
const MaterialProperty< Real > & _porosity
Material property of porosity.
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
const Real _log_k
Equilibrium constant for the equilibrium species in association form.
const Real _sto_u
Stoichiometric coefficient of the primary species.
virtual Real computeQpResidual() override
const std::vector< Real > _sto_v
Stoichiometric coefficients of the coupled primary species.
const VariableValue & _u_old
The old values of the primary species concentration.
std::vector< const VariableValue * > _v_vals_old
Coupled old values of primary species concentrations.
const Real _weight
Weight of the equilibrium species concentration in the total primary species concentration.