Line data Source code
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 : 10 : #include "AqueousEquilibriumRxnAux.h" 11 : 12 : registerMooseObject("ChemicalReactionsApp", AqueousEquilibriumRxnAux); 13 : 14 : InputParameters 15 1746 : AqueousEquilibriumRxnAux::validParams() 16 : { 17 1746 : InputParameters params = AuxKernel::validParams(); 18 3492 : params.addCoupledVar("log_k", 0.0, "The equilibrium constant in dissociation form"); 19 3492 : params.addRequiredParam<std::vector<Real>>("sto_v", 20 : "The stoichiometric coefficient of reactants"); 21 3492 : params.addRequiredCoupledVar( 22 : "v", "The list of primary species participating in this equilibrium species"); 23 3492 : params.addCoupledVar("gamma", 1.0, "Activity coefficient of this secondary equilibrium species"); 24 3492 : params.addCoupledVar("gamma_v", 1.0, "Activity coefficients of coupled primary species"); 25 1746 : params.addClassDescription("Concentration of secondary equilibrium species"); 26 1746 : return params; 27 0 : } 28 : 29 946 : AqueousEquilibriumRxnAux::AqueousEquilibriumRxnAux(const InputParameters & parameters) 30 : : AuxKernel(parameters), 31 946 : _log_k(coupledValue("log_k")), 32 1892 : _sto_v(getParam<std::vector<Real>>("sto_v")), 33 946 : _gamma_eq(coupledValue("gamma")), 34 946 : _vals(coupledValues("v")), 35 2838 : _gamma_v(isCoupled("gamma_v") 36 946 : ? coupledValues("gamma_v") // have value 37 1884 : : std::vector<const VariableValue *>(coupledComponents("v"), 38 3768 : &coupledValue("gamma_v"))) // default 39 : { 40 1892 : const unsigned int n = coupledComponents("v"); 41 : 42 : // Check that the correct number of stoichiometric coefficients have been provided 43 946 : if (_sto_v.size() != n) 44 4 : mooseError("The number of stoichiometric coefficients in sto_v is not equal to the number of " 45 : "coupled species in ", 46 4 : _name); 47 : 48 : // Check that the correct number of activity coefficients have been provided (if applicable) 49 1884 : if (isCoupled("gamma_v")) 50 8 : if (coupledComponents("gamma_v") != n) 51 4 : mooseError("The number of activity coefficients in gamma_v is not equal to the number of " 52 : "coupled species in ", 53 4 : _name); 54 938 : } 55 : 56 : Real 57 514584 : AqueousEquilibriumRxnAux::computeValue() 58 : { 59 : Real conc_product = 1.0; 60 : 61 1290032 : for (unsigned int i = 0; i < _vals.size(); ++i) 62 775448 : 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 514584 : return std::pow(10.0, _log_k[_qp]) * conc_product / _gamma_eq[_qp]; 66 : }