www.mooseframework.org
CoupledDiffusionReactionSub.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>(
15  "weight",
16  1.0,
17  "Weight of equilibrium species concentration in the primary species concentration");
18  params.addParam<Real>(
19  "log_k", 0.0, "Equilibrium constant of the equilbrium reaction in dissociation form");
20  params.addParam<Real>("sto_u",
21  1.0,
22  "Stoichiometric coef of the primary species this kernel "
23  "operates on in the equilibrium reaction");
24  params.addRequiredParam<std::vector<Real>>(
25  "sto_v", "The stoichiometric coefficients of coupled primary species");
26  params.addCoupledVar("v", "List of coupled primary species in this equilibrium species");
27  params.addClassDescription("Diffusion of equilibrium species");
28  return params;
29 }
30 
32  : Kernel(parameters),
33  _diffusivity(getMaterialProperty<Real>("diffusivity")),
34  _weight(getParam<Real>("weight")),
35  _log_k(getParam<Real>("log_k")),
36  _sto_u(getParam<Real>("sto_u")),
37  _sto_v(getParam<std::vector<Real>>("sto_v"))
38 {
39  const unsigned int n = coupledComponents("v");
40  _vars.resize(n);
41  _vals.resize(n);
42  _grad_vals.resize(n);
43 
44  for (unsigned int i = 0; i < n; ++i)
45  {
46  _vars[i] = coupled("v", i);
47  _vals[i] = &coupledValue("v", i);
48  _grad_vals[i] = &coupledGradient("v", i);
49  }
50 }
51 
52 Real
54 {
55  RealGradient diff1 = _sto_u * std::pow(_u[_qp], _sto_u - 1.0) * _grad_u[_qp];
56  for (unsigned int i = 0; i < _vals.size(); ++i)
57  diff1 *= std::pow((*_vals[i])[_qp], _sto_v[i]);
58 
59  RealGradient diff2_sum(0.0, 0.0, 0.0);
60  const Real d_val = std::pow(_u[_qp], _sto_u);
61  for (unsigned int i = 0; i < _vals.size(); ++i)
62  {
63  RealGradient diff2 =
64  d_val * _sto_v[i] * std::pow((*_vals[i])[_qp], _sto_v[i] - 1.0) * (*_grad_vals[i])[_qp];
65 
66  for (unsigned int j = 0; j < _vals.size(); ++j)
67  if (j != i)
68  diff2 *= std::pow((*_vals[j])[_qp], _sto_v[j]);
69 
70  diff2_sum += diff2;
71  }
72 
73  return _weight * std::pow(10.0, _log_k) * _diffusivity[_qp] * _grad_test[_i][_qp] *
74  (diff1 + diff2_sum);
75 }
76 
77 Real
79 {
80  RealGradient diff1_1 = _sto_u * std::pow(_u[_qp], _sto_u - 1.0) * _grad_phi[_j][_qp];
81  RealGradient diff1_2 =
82  _phi[_j][_qp] * _sto_u * (_sto_u - 1.0) * std::pow(_u[_qp], _sto_u - 2.0) * _grad_u[_qp];
83  for (unsigned int i = 0; i < _vals.size(); ++i)
84  {
85  diff1_1 *= std::pow((*_vals[i])[_qp], _sto_v[i]);
86  diff1_2 *= std::pow((*_vals[i])[_qp], _sto_v[i]);
87  }
88 
89  RealGradient diff1 = diff1_1 + diff1_2;
90  Real d_val = _sto_u * std::pow(_u[_qp], _sto_u - 1.0) * _phi[_j][_qp];
91  RealGradient diff2_sum(0.0, 0.0, 0.0);
92  for (unsigned int i = 0; i < _vals.size(); ++i)
93  {
94  RealGradient diff2 =
95  d_val * _sto_v[i] * std::pow((*_vals[i])[_qp], _sto_v[i] - 1.0) * (*_grad_vals[i])[_qp];
96  for (unsigned int j = 0; j < _vals.size(); ++j)
97  if (j != i)
98  diff2 *= std::pow((*_vals[j])[_qp], _sto_v[j]);
99 
100  diff2_sum += diff2;
101  }
102 
103  return _weight * std::pow(10.0, _log_k) * _diffusivity[_qp] * _grad_test[_i][_qp] *
104  (diff1 + diff2_sum);
105 }
106 
107 Real
109 {
110  // If no coupled species, return 0
111  if (_vals.size() == 0)
112  return 0.0;
113 
114  // If jvar is not one of the coupled species, return 0
115  if (std::find(_vars.begin(), _vars.end(), jvar) == _vars.end())
116  return 0.0;
117 
118  RealGradient diff1 = _sto_u * std::pow(_u[_qp], _sto_u - 1.0) * _grad_u[_qp];
119  for (unsigned int i = 0; i < _vals.size(); ++i)
120  {
121  if (jvar == _vars[i])
122  diff1 *= _sto_v[i] * std::pow((*_vals[i])[_qp], _sto_v[i] - 1.0) * _phi[_j][_qp];
123  else
124  diff1 *= std::pow((*_vals[i])[_qp], _sto_v[i]);
125  }
126 
127  Real val_u = std::pow(_u[_qp], _sto_u);
128 
129  RealGradient diff2_1(1.0, 1.0, 1.0);
130  RealGradient diff2_2(1.0, 1.0, 1.0);
131 
132  for (unsigned int i = 0; i < _vals.size(); ++i)
133  if (jvar == _vars[i])
134  {
135  diff2_1 = _sto_v[i] * (_sto_v[i] - 1.0) * std::pow((*_vals[i])[_qp], _sto_v[i] - 2.0) *
136  _phi[_j][_qp] * (*_grad_vals[i])[_qp];
137  diff2_2 = _sto_v[i] * std::pow((*_vals[i])[_qp], _sto_v[i] - 1.0) * _grad_phi[_j][_qp];
138  }
139 
140  RealGradient diff2 = val_u * (diff2_1 + diff2_2);
141 
142  for (unsigned int i = 0; i < _vals.size(); ++i)
143  if (jvar != _vars[i])
144  diff2 *= std::pow((*_vals[i])[_qp], _sto_v[i]);
145 
146  RealGradient diff3;
147  RealGradient diff3_sum(0.0, 0.0, 0.0);
148  Real val_jvar = 0.0;
149  unsigned int var = 0;
150 
151  for (unsigned int i = 0; i < _vals.size(); ++i)
152  if (jvar == _vars[i])
153  {
154  var = i;
155  val_jvar = val_u * _sto_v[i] * std::pow((*_vals[i])[_qp], _sto_v[i] - 1.0) * _phi[_j][_qp];
156  }
157 
158  for (unsigned int i = 0; i < _vals.size(); ++i)
159  if (i != var)
160  {
161  diff3 = val_jvar * _sto_v[i] * std::pow((*_vals[i])[_qp], _sto_v[i] - 1.0) *
162  (*_grad_vals[i])[_qp];
163 
164  for (unsigned int j = 0; j < _vals.size(); ++j)
165  if (j != var && j != i)
166  diff3 *= std::pow((*_vals[j])[_qp], _sto_v[j]);
167 
168  diff3_sum += diff3;
169  }
170 
171  return _weight * std::pow(10.0, _log_k) * _diffusivity[_qp] * _grad_test[_i][_qp] *
172  (diff1 + diff2 + diff3_sum);
173 }
std::vector< const VariableGradient * > _grad_vals
Coupled gradients of primary species concentrations.
const Real _weight
Weight of the equilibrium species concentration in the total primary species concentration.
CoupledDiffusionReactionSub(const InputParameters &parameters)
InputParameters validParams< CoupledDiffusionReactionSub >()
virtual Real computeQpResidual() override
std::vector< const VariableValue * > _vals
Coupled primary species concentrations.
virtual Real computeQpJacobian() override
const std::vector< Real > _sto_v
Stoichiometric coefficients of the coupled primary species.
const Real _sto_u
Stoichiometric coefficient of the primary species.
const Real _log_k
Equilibrium constant for the equilibrium species in association form.
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
const MaterialProperty< Real > & _diffusivity
Material property of dispersion-diffusion coefficient.
std::vector< unsigned int > _vars
Coupled primary species variable numbers.
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override