https://mooseframework.inl.gov
Loading...
Searching...
No Matches
AqueousEquilibriumRxnAux.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.addCoupledVar("log_k", 0.0, "The equilibrium constant in dissociation form");
19 params.addRequiredParam<std::vector<Real>>("sto_v",
20 "The stoichiometric coefficient of reactants");
22 "v", "The list of primary species participating in this equilibrium species");
23 params.addCoupledVar("gamma", 1.0, "Activity coefficient of this secondary equilibrium species");
24 params.addCoupledVar("gamma_v", 1.0, "Activity coefficients of coupled primary species");
25 params.addClassDescription("Concentration of secondary equilibrium species");
26 return params;
27}
28
30 : AuxKernel(parameters),
31 _log_k(coupledValue("log_k")),
32 _sto_v(getParam<std::vector<Real>>("sto_v")),
33 _gamma_eq(coupledValue("gamma")),
34 _vals(coupledValues("v")),
35 _gamma_v(isCoupled("gamma_v")
36 ? coupledValues("gamma_v") // have value
37 : std::vector<const VariableValue *>(coupledComponents("v"),
38 &coupledValue("gamma_v"))) // default
39{
40 const unsigned int n = coupledComponents("v");
41
42 // Check that the correct number of stoichiometric coefficients have been provided
43 if (_sto_v.size() != n)
44 mooseError("The number of stoichiometric coefficients in sto_v is not equal to the number of "
45 "coupled species in ",
46 _name);
47
48 // Check that the correct number of activity coefficients have been provided (if applicable)
49 if (isCoupled("gamma_v"))
50 if (coupledComponents("gamma_v") != n)
51 mooseError("The number of activity coefficients in gamma_v is not equal to the number of "
52 "coupled species in ",
53 _name);
54}
55
56Real
58{
59 Real conc_product = 1.0;
60
61 for (unsigned int i = 0; i < _vals.size(); ++i)
62 conc_product *= std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i]);
63
64 mooseAssert(_gamma_eq[_qp] > 0.0, "Activity coefficient must be greater than zero");
65 return std::pow(10.0, _log_k[_qp]) * conc_product / _gamma_eq[_qp];
66}
registerMooseObject("ChemicalReactionsApp", AqueousEquilibriumRxnAux)
Calculates equilibrium species concentration according to the mass action law.
const VariableValue & _gamma_eq
Activity coefficient of equilibrium species.
const std::vector< Real > _sto_v
Stoichiometric coefficients of coupled primary species.
const std::vector< const VariableValue * > _gamma_v
Activity coefficients of coupled primary species.
AqueousEquilibriumRxnAux(const InputParameters &parameters)
virtual Real computeValue() override
static InputParameters validParams()
const std::vector< const VariableValue * > _vals
Coupled primary species.
const VariableValue & _log_k
Equilibrium constant.
static InputParameters validParams()
unsigned int coupledComponents(const std::string &var_name) const
virtual bool isCoupled(const std::string &var_name, unsigned int i=0) const
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void addCoupledVar(const std::string &name, const std::string &doc_string)
void mooseError(Args &&... args) const
const std::string & _name
VariableValueTempl< false > VariableValue