https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CoupledConvectionReactionSub.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
11
13
16{
18 params.addParam<Real>("weight", 1.0, "Weight of the equilibrium species");
19 params.addCoupledVar("log_k", 0.0, "Equilibrium constant of dissociation equilibrium reaction");
20 params.addParam<Real>("sto_u",
21 1.0,
22 "Stoichiometric coef of the primary species the kernel "
23 "operates on in the equilibrium reaction");
24 params.addCoupledVar(
25 "gamma_u", 1.0, "Activity coefficient of primary species that this kernel operates on");
26 params.addParam<std::vector<Real>>(
27 "sto_v",
28 {},
29 "The stoichiometric coefficients of coupled primary species in equilibrium reaction");
30 params.addRequiredCoupledVar("p", "Pressure");
31 params.addCoupledVar("v", "List of coupled primary species");
32 params.addCoupledVar("gamma_v", 1.0, "Activity coefficients of coupled primary species");
33 params.addCoupledVar("gamma_eq", 1.0, "Activity coefficient of this equilibrium species");
34 RealVectorValue g(0, 0, 0);
35 params.addParam<RealVectorValue>("gravity", g, "Gravity vector (default is (0, 0, 0))");
36 params.addClassDescription("Convection of equilibrium species");
37 return params;
38}
39
42 _weight(getParam<Real>("weight")),
43 _log_k(coupledValue("log_k")),
44 _sto_u(getParam<Real>("sto_u")),
45 _sto_v(getParam<std::vector<Real>>("sto_v")),
46 _cond(getMaterialProperty<Real>("conductivity")),
47 _gravity(getParam<RealVectorValue>("gravity")),
48 _density(getDefaultMaterialProperty<Real>("density")),
49 _grad_p(coupledGradient("p")),
50 _pvar(coupled("p")),
51 _vars(coupledIndices("v")),
52 _vals(coupledValues("v")),
53 _grad_vals(coupledGradients("v")),
54 _gamma_u(coupledValue("gamma_u")),
55 _gamma_v(isCoupled("gamma_v")
56 ? coupledValues("gamma_v") // have value
57 : std::vector<const VariableValue *>(coupledComponents("v"),
58 &coupledValue("gamma_v"))), // default
59 _gamma_eq(coupledValue("gamma_eq"))
60{
61 const unsigned int n = coupledComponents("v");
62
63 // Check that the correct number of coupled values have been provided
64 if (_sto_v.size() != n)
65 mooseError("The number of stoichiometric coefficients in sto_v is not equal to the number of "
66 "coupled species in ",
67 _name);
68
69 if (isCoupled("gamma_v"))
70 if (coupledComponents("gamma_v") != n)
71 mooseError("The number of activity coefficients in gamma_v is not equal to the number of "
72 "coupled species in ",
73 _name);
74}
75
76Real
78{
79 RealVectorValue darcy_vel = -_cond[_qp] * (_grad_p[_qp] - _density[_qp] * _gravity);
80 RealGradient d_u =
81 _sto_u * _gamma_u[_qp] * std::pow(_gamma_u[_qp] * _u[_qp], _sto_u - 1.0) * _grad_u[_qp];
82 RealGradient d_var_sum(0.0, 0.0, 0.0);
83 const Real d_v_u = std::pow(_gamma_u[_qp] * _u[_qp], _sto_u);
84
85 for (unsigned int i = 0; i < _vals.size(); ++i)
86 {
87 d_u *= std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i]);
88
89 RealGradient d_var = d_v_u * _sto_v[i] * (*_gamma_v[i])[_qp] *
90 std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 1.0) *
91 (*_grad_vals[i])[_qp];
92
93 for (unsigned int j = 0; j < _vals.size(); ++j)
94 if (j != i)
95 d_var *= std::pow((*_gamma_v[i])[_qp] * (*_vals[j])[_qp], _sto_v[j]);
96
97 d_var_sum += d_var;
98 }
99
100 mooseAssert(_gamma_eq[_qp] > 0.0, "Activity coefficient must be greater than zero");
101 return _weight * std::pow(10.0, _log_k[_qp]) * _test[_i][_qp] * darcy_vel * (d_u + d_var_sum) /
102 _gamma_eq[_qp];
103}
104
105Real
107{
108 RealVectorValue darcy_vel = -_cond[_qp] * (_grad_p[_qp] - _density[_qp] * _gravity);
109
110 RealGradient d_u_1 =
111 _sto_u * _gamma_u[_qp] * std::pow(_gamma_u[_qp] * _u[_qp], _sto_u - 1.0) * _grad_phi[_j][_qp];
112 RealGradient d_u_2 = _phi[_j][_qp] * _sto_u * (_sto_u - 1.0) * _gamma_u[_qp] * _gamma_u[_qp] *
113 std::pow(_gamma_u[_qp] * _u[_qp], _sto_u - 2.0) * _grad_u[_qp];
114
115 RealGradient d_var_sum(0.0, 0.0, 0.0);
116 const Real d_v_u =
117 _sto_u * _gamma_u[_qp] * std::pow(_gamma_u[_qp] * _u[_qp], _sto_u - 1.0) * _phi[_j][_qp];
118
119 for (unsigned int i = 0; i < _vals.size(); ++i)
120 {
121 d_u_1 *= std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i]);
122 d_u_2 *= std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i]);
123
124 RealGradient d_var = d_v_u * _sto_v[i] * (*_gamma_v[i])[_qp] *
125 std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 1.0) *
126 (*_grad_vals[i])[_qp];
127 for (unsigned int j = 0; j < _vals.size(); ++j)
128 if (j != i)
129 d_var *= std::pow((*_gamma_v[i])[_qp] * (*_vals[j])[_qp], _sto_v[j]);
130
131 d_var_sum += d_var;
132 }
133
134 RealGradient d_u_j = d_u_1 + d_u_2;
135 return _weight * std::pow(10.0, _log_k[_qp]) * _test[_i][_qp] * darcy_vel * (d_u_j + d_var_sum) /
136 _gamma_eq[_qp];
137}
138
139Real
141{
142 if (jvar == _pvar)
143 {
144 RealVectorValue ddarcy_vel_dp = -_cond[_qp] * _grad_phi[_j][_qp];
145
146 RealGradient d_u =
147 _sto_u * _gamma_u[_qp] * std::pow(_gamma_u[_qp] * _u[_qp], _sto_u - 1.0) * _grad_u[_qp];
148 RealGradient d_var_sum(0.0, 0.0, 0.0);
149 const Real d_v_u = std::pow(_gamma_u[_qp] * _u[_qp], _sto_u);
150
151 for (unsigned int i = 0; i < _vals.size(); ++i)
152 {
153 d_u *= std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i]);
154
155 RealGradient d_var = d_v_u * _sto_v[i] * (*_gamma_v[i])[_qp] *
156 std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 1.0) *
157 (*_grad_vals[i])[_qp];
158 for (unsigned int j = 0; j < _vals.size(); ++j)
159 if (j != i)
160 d_var *= std::pow((*_gamma_v[i])[_qp] * (*_vals[j])[_qp], _sto_v[j]);
161
162 d_var_sum += d_var;
163 }
164 return _weight * std::pow(10.0, _log_k[_qp]) * _test[_i][_qp] * ddarcy_vel_dp *
165 (d_u + d_var_sum) / _gamma_eq[_qp];
166 }
167
168 if (_vals.size() == 0)
169 return 0.0;
170
171 RealVectorValue darcy_vel = -_cond[_qp] * (_grad_p[_qp] - _density[_qp] * _gravity);
172 RealGradient diff1 =
173 _sto_u * _gamma_u[_qp] * std::pow(_gamma_u[_qp] * _u[_qp], _sto_u - 1.0) * _grad_u[_qp];
174 for (unsigned int i = 0; i < _vals.size(); ++i)
175 {
176 if (jvar == _vars[i])
177 diff1 *= _sto_v[i] * (*_gamma_v[i])[_qp] *
178 std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 1.0) * _phi[_j][_qp];
179 else
180 diff1 *= std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i]);
181 }
182
183 Real val_u = std::pow(_gamma_u[_qp] * _u[_qp], _sto_u);
184 RealGradient diff2_1(1.0, 1.0, 1.0);
185 RealGradient diff2_2(1.0, 1.0, 1.0);
186 for (unsigned int i = 0; i < _vals.size(); ++i)
187 if (jvar == _vars[i])
188 {
189 diff2_1 = _sto_v[i] * (*_gamma_v[i])[_qp] * (*_gamma_v[i])[_qp] * (_sto_v[i] - 1.0) *
190 std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 2.0) * _phi[_j][_qp] *
191 (*_grad_vals[i])[_qp];
192 diff2_2 = _sto_v[i] * (*_gamma_v[i])[_qp] *
193 std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 1.0) *
194 _grad_phi[_j][_qp];
195 }
196
197 RealGradient diff2 = val_u * (diff2_1 + diff2_2);
198 for (unsigned int i = 0; i < _vals.size(); ++i)
199 if (jvar != _vars[i])
200 {
201 diff2 *= std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i]);
202 }
203
204 RealGradient diff3;
205 RealGradient diff3_sum(0.0, 0.0, 0.0);
206 Real val_jvar = 0.0;
207 unsigned int var = 0;
208
209 for (unsigned int i = 0; i < _vals.size(); ++i)
210 if (jvar == _vars[i])
211 {
212 var = i;
213 val_jvar = val_u * _sto_v[i] * (*_gamma_v[i])[_qp] *
214 std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 1.0) * _phi[_j][_qp];
215 }
216
217 for (unsigned int i = 0; i < _vals.size(); ++i)
218 if (i != var)
219 {
220 diff3 = val_jvar * _sto_v[i] * (*_gamma_v[i])[_qp] *
221 std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 1.0) *
222 (*_grad_vals[i])[_qp];
223
224 for (unsigned int j = 0; j < _vals.size(); ++j)
225 if (j != var && j != i)
226 diff3 *= std::pow((*_gamma_v[i])[_qp] * (*_vals[j])[_qp], _sto_v[j]);
227
228 diff3_sum += diff3;
229 }
230
231 return _weight * std::pow(10.0, _log_k[_qp]) * _test[_i][_qp] * darcy_vel *
232 (diff1 + diff2 + diff3_sum) / _gamma_eq[_qp];
233}
registerMooseObject("ChemicalReactionsApp", CoupledConvectionReactionSub)
void mooseError(Args &&... args)
Convection of primary species in given equilibrium species.
const std::vector< const VariableValue * > _gamma_v
Activity coefficients of coupled primary species in the equilibrium species.
const VariableGradient & _grad_p
Pressure gradient.
const MaterialProperty< Real > & _cond
Hydraulic conductivity.
const Real _sto_u
Stoichiometric coefficient of the primary species.
const VariableValue & _log_k
Equilibrium constant for the equilibrium species in association form.
const std::vector< const VariableValue * > _vals
Coupled primary species concentrations.
const unsigned int _pvar
Pressure variable number.
const std::vector< const VariableGradient * > _grad_vals
Coupled gradients of primary species concentrations.
const VariableValue & _gamma_u
Activity coefficient of primary species in the equilibrium species.
const Real _weight
Weight of the equilibrium species concentration in the total primary species concentration.
CoupledConvectionReactionSub(const InputParameters &parameters)
const std::vector< unsigned int > _vars
Coupled primary species variable numbers.
const VariableValue & _gamma_eq
Activity coefficient of equilibrium species.
const MaterialProperty< Real > & _density
Fluid density.
const RealVectorValue _gravity
Gravity.
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
const std::vector< Real > _sto_v
Stoichiometric coefficients of the coupled primary species.
void addRequiredCoupledVar(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()
VariableValueTempl< false > VariableValue