www.mooseframework.org
AqueousEquilibriumRxnAux.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
12 registerMooseObject("ChemicalReactionsApp", AqueousEquilibriumRxnAux);
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");
21  params.addRequiredCoupledVar(
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 
56 Real
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 }
virtual bool isCoupled(const std::string &var_name, unsigned int i=0) const
const std::vector< Real > _sto_v
Stoichiometric coefficients of coupled primary species.
const std::vector< const VariableValue * > _vals
Coupled primary species.
void addRequiredParam(const std::string &name, const std::string &doc_string)
AqueousEquilibriumRxnAux(const InputParameters &parameters)
const VariableValue & _gamma_eq
Activity coefficient of equilibrium species.
registerMooseObject("ChemicalReactionsApp", AqueousEquilibriumRxnAux)
const std::string _name
void addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
const std::vector< const VariableValue * > _gamma_v
Activity coefficients of coupled primary species.
OutputTools< Real >::VariableValue VariableValue
unsigned int coupledComponents(const std::string &var_name) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Calculates equilibrium species concentration according to the mass action law.
virtual Real computeValue() override
void mooseError(Args &&... args) const
static InputParameters validParams()
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()
const VariableValue & _log_k
Equilibrium constant.
MooseUnits pow(const MooseUnits &, int)