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