https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CoupledBEEquilibriumSub.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>(
19 "weight", 1.0, "The weight of the equilibrium species in total concentration");
20 params.addCoupledVar("log_k", 0.0, "The equilibrium constant of this equilibrium species");
21 params.addParam<Real>(
22 "sto_u",
23 1.0,
24 "The stoichiometric coefficient of the primary species this kernel operates on");
25 params.addCoupledVar(
26 "gamma_u", 1.0, "Activity coefficient of primary species that this kernel operates on");
27 params.addParam<std::vector<Real>>(
28 "sto_v", {}, "The stoichiometric coefficients of coupled primary species");
29 params.addCoupledVar("gamma_v", 1.0, "Activity coefficients of coupled primary species");
30 params.addCoupledVar("gamma_eq", 1.0, "Activity coefficient of this equilibrium species");
31 params.addCoupledVar("v", "Coupled primary species constituting the equilibrium species");
32 params.addClassDescription("Derivative of equilibrium species concentration wrt time");
33 return params;
34}
35
37 : TimeDerivative(parameters),
38 _weight(getParam<Real>("weight")),
39 _log_k(coupledValue("log_k")),
40 _sto_u(getParam<Real>("sto_u")),
41 _sto_v(getParam<std::vector<Real>>("sto_v")),
42 _gamma_u(coupledValue("gamma_u")),
43 _gamma_u_old(coupledValueOld("gamma_u")),
44 _gamma_v(isCoupled("gamma_v")
45 ? coupledValues("gamma_v") // have value
46 : std::vector<const VariableValue *>(coupledComponents("v"),
47 &coupledValue("gamma_v"))), // default
48 _gamma_v_old(isCoupled("gamma_v")
49 ? coupledValuesOld("gamma_v") // have value
50 : std::vector<const VariableValue *>(coupledComponents("v"),
51 &coupledValue("gamma_v"))), // default
52 _gamma_eq(coupledValue("gamma_eq")),
53 _gamma_eq_old(coupledValueOld("gamma_eq")),
54 _porosity(getMaterialProperty<Real>("porosity")),
55 _vars(coupledIndices("v")),
56 _v_vals(coupledValues("v")),
57 _v_vals_old(coupledValuesOld("v")),
58 _u_old(valueOld())
59{
60 const unsigned int n = coupledComponents("v");
61
62 // Check that the correct number of coupled values have been provided
63 if (_sto_v.size() != n)
64 mooseError("The number of stoichiometric coefficients in sto_v is not equal to the number of "
65 "coupled species in ",
66 _name);
67
68 if (isCoupled("gamma_v"))
69 if (coupledComponents("gamma_v") != n)
70 mooseError("The number of activity coefficients in gamma_v is not equal to the number of "
71 "coupled species in ",
72 _name);
73}
74
75Real
77{
78 mooseAssert(_gamma_eq[_qp] > 0.0, "Activity coefficient must be greater than zero");
79
80 // Contribution due to primary species that this kernel acts on
81 Real val_new =
82 std::pow(10.0, _log_k[_qp]) * std::pow(_gamma_u[_qp] * _u[_qp], _sto_u) / _gamma_eq[_qp];
83 Real val_old = std::pow(10.0, _log_k[_qp]) * std::pow(_gamma_u_old[_qp] * _u_old[_qp], _sto_u) /
85
86 // Contribution due to coupled primary species
87 for (unsigned int i = 0; i < _vars.size(); ++i)
88 {
89 val_new *= std::pow((*_gamma_v[i])[_qp] * (*_v_vals[i])[_qp], _sto_v[i]);
90 val_old *= std::pow((*_gamma_v_old[i])[_qp] * (*_v_vals_old[i])[_qp], _sto_v[i]);
91 }
92
93 return _porosity[_qp] * _weight * _test[_i][_qp] * (val_new - val_old) / _dt;
94}
95
96Real
98{
99 Real val_new = std::pow(10.0, _log_k[_qp]) * _sto_u * _gamma_u[_qp] *
100 std::pow(_gamma_u[_qp] * _u[_qp], _sto_u - 1.0) * _phi[_j][_qp] / _gamma_eq[_qp];
101
102 for (unsigned int i = 0; i < _vars.size(); ++i)
103 val_new *= std::pow((*_gamma_v[i])[_qp] * (*_v_vals[i])[_qp], _sto_v[i]);
104
105 return _porosity[_qp] * _test[_i][_qp] * _weight * val_new / _dt;
106}
107
108Real
110{
111 // If no coupled species, return 0
112 if (_v_vals.size() == 0)
113 return 0.0;
114
115 // If jvar is not one of the coupled species, return 0
116 if (std::find(_vars.begin(), _vars.end(), jvar) == _vars.end())
117 return 0.0;
118
119 Real val_new =
120 std::pow(10.0, _log_k[_qp]) * std::pow(_gamma_u[_qp] * _u[_qp], _sto_u) / _gamma_eq[_qp];
121
122 for (unsigned int i = 0; i < _vars.size(); ++i)
123 {
124 if (jvar == _vars[i])
125 val_new *= _sto_v[i] * (*_gamma_v[i])[_qp] *
126 std::pow((*_gamma_v[i])[_qp] * (*_v_vals[i])[_qp], _sto_v[i] - 1.0) *
127 _phi[_j][_qp];
128 else
129 val_new *= std::pow((*_gamma_v[i])[_qp] * (*_v_vals[i])[_qp], _sto_v[i]);
130 }
131
132 return _porosity[_qp] * _test[_i][_qp] * _weight * val_new / _dt;
133}
registerMooseObject("ChemicalReactionsApp", CoupledBEEquilibriumSub)
unsigned int coupledComponents(const std::string &var_name) const
virtual bool isCoupled(const std::string &var_name, unsigned int i=0) const
Time derivative of primary species in given equilibrium species.
const Real _weight
Weight of the equilibrium species in the total primary species.
const std::vector< const VariableValue * > _v_vals
Coupled primary species concentrations.
const std::vector< Real > _sto_v
Stoichiometric coefficients of the coupled primary species in the equilibrium species.
const VariableValue & _gamma_eq_old
Old activity coefficient of equilibrium species.
const VariableValue & _gamma_u_old
Old activity coefficient of primary species in the equilibrium species.
const MaterialProperty< Real > & _porosity
Porosity.
static InputParameters validParams()
const VariableValue & _gamma_eq
Activity coefficient of equilibrium species.
const VariableValue & _u_old
Old value of the primary species concentration.
virtual Real computeQpResidual() override
const VariableValue & _gamma_u
Activity coefficient of primary species in the equilibrium species.
const std::vector< const VariableValue * > _gamma_v_old
Old activity coefficients of coupled primary species in the equilibrium species.
CoupledBEEquilibriumSub(const InputParameters &parameters)
const std::vector< unsigned int > _vars
Coupled primary species variable numbers.
const Real _sto_u
Stoichiometric coefficient of the primary species in the equilibrium species.
virtual Real computeQpJacobian() override
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
const std::vector< const VariableValue * > _gamma_v
Activity coefficients of coupled primary species in the equilibrium species.
const std::vector< const VariableValue * > _v_vals_old
Old values of coupled primary species concentrations.
const VariableValue & _log_k
Equilibrium constant for the equilibrium species.
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)
unsigned int _qp
unsigned int _j
unsigned int _i
const VariablePhiValue & _phi
const VariableTestValue & _test
const VariableValue & _u
void mooseError(Args &&... args) const
const std::string & _name
static InputParameters validParams()
VariableValueTempl< false > VariableValue