https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
PorousFlowMassFractionAqueousEquilibriumChemistry Class Reference

Material designed to form a std::vector<std::vector> of mass fractions from primary-species concentrations and secondary-species concentrations for an equilibrium aqueous chemistry reaction system. More...

#include <PorousFlowMassFractionAqueousEquilibriumChemistry.h>

Inheritance diagram for PorousFlowMassFractionAqueousEquilibriumChemistry:
[legend]

Public Types

typedef DerivativeMaterialPropertyNameInterface::SymbolName SymbolName
 

Public Member Functions

 PorousFlowMassFractionAqueousEquilibriumChemistry (const InputParameters &parameters)
 
const GenericMaterialProperty< U, is_ad > & getDefaultMaterialProperty (const std::string &name)
 
const GenericMaterialProperty< U, is_ad > & getDefaultMaterialPropertyByName (const std::string &name)
 
void validateDerivativeMaterialPropertyBase (const std::string &base)
 
const MaterialPropertyName derivativePropertyName (const MaterialPropertyName &base, const std::vector< SymbolName > &c) const
 
const MaterialPropertyName derivativePropertyNameFirst (const MaterialPropertyName &base, const SymbolName &c1) const
 
const MaterialPropertyName derivativePropertyNameSecond (const MaterialPropertyName &base, const SymbolName &c1, const SymbolName &c2) const
 
const MaterialPropertyName derivativePropertyNameThird (const MaterialPropertyName &base, const SymbolName &c1, const SymbolName &c2, const SymbolName &c3) const
 
GenericMaterialProperty< U, is_ad > & declarePropertyDerivative (const std::string &base, const std::vector< VariableName > &c)
 
GenericMaterialProperty< U, is_ad > & declarePropertyDerivative (const std::string &base, const std::vector< SymbolName > &c)
 
GenericMaterialProperty< U, is_ad > & declarePropertyDerivative (const std::string &base, const SymbolName &c1, const SymbolName &c2="", const SymbolName &c3="")
 
GenericMaterialProperty< U, is_ad > & declarePropertyDerivative (const std::string &base, const std::vector< VariableName > &c)
 
GenericMaterialProperty< U, is_ad > & declarePropertyDerivative (const std::string &base, const std::vector< SymbolName > &c)
 
GenericMaterialProperty< U, is_ad > & declarePropertyDerivative (const std::string &base, const SymbolName &c1, const SymbolName &c2="", const SymbolName &c3="")
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivative (const std::string &base, const std::vector< VariableName > &c)
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivative (const std::string &base, const std::vector< SymbolName > &c)
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivative (const std::string &base, const SymbolName &c1, const SymbolName &c2="", const SymbolName &c3="")
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivative (const std::string &base, const SymbolName &c1, unsigned int v2, unsigned int v3=libMesh::invalid_uint)
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivative (const std::string &base, unsigned int v1, unsigned int v2=libMesh::invalid_uint, unsigned int v3=libMesh::invalid_uint)
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivative (const std::string &base, const std::vector< VariableName > &c)
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivative (const std::string &base, const std::vector< SymbolName > &c)
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivative (const std::string &base, const SymbolName &c1, const SymbolName &c2="", const SymbolName &c3="")
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivative (const std::string &base, const SymbolName &c1, unsigned int v2, unsigned int v3=libMesh::invalid_uint)
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivative (const std::string &base, unsigned int v1, unsigned int v2=libMesh::invalid_uint, unsigned int v3=libMesh::invalid_uint)
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivativeByName (const MaterialPropertyName &base, const std::vector< VariableName > &c)
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivativeByName (const MaterialPropertyName &base, const std::vector< SymbolName > &c)
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivativeByName (const MaterialPropertyName &base, const SymbolName &c1, const SymbolName &c2="", const SymbolName &c3="")
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivativeByName (const MaterialPropertyName &base, const std::vector< VariableName > &c)
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivativeByName (const MaterialPropertyName &base, const std::vector< SymbolName > &c)
 
const GenericMaterialProperty< U, is_ad > & getMaterialPropertyDerivativeByName (const MaterialPropertyName &base, const SymbolName &c1, const SymbolName &c2="", const SymbolName &c3="")
 
void validateCoupling (const MaterialPropertyName &base, const std::vector< VariableName > &c, bool validate_aux=true)
 
void validateCoupling (const MaterialPropertyName &base, const VariableName &c1="", const VariableName &c2="", const VariableName &c3="")
 
void validateCoupling (const MaterialPropertyName &base, const std::vector< VariableName > &c, bool validate_aux=true)
 
void validateCoupling (const MaterialPropertyName &base, const VariableName &c1="", const VariableName &c2="", const VariableName &c3="")
 
void validateNonlinearCoupling (const MaterialPropertyName &base, const VariableName &c1="", const VariableName &c2="", const VariableName &c3="")
 
void validateNonlinearCoupling (const MaterialPropertyName &base, const VariableName &c1="", const VariableName &c2="", const VariableName &c3="")
 
const MaterialPropertyName propertyName (const MaterialPropertyName &base, const std::vector< SymbolName > &c) const
 
const MaterialPropertyName propertyName (const MaterialPropertyName &base, const std::vector< SymbolName > &c) const
 
const MaterialPropertyName propertyNameFirst (const MaterialPropertyName &base, const SymbolName &c1) const
 
const MaterialPropertyName propertyNameFirst (const MaterialPropertyName &base, const SymbolName &c1) const
 
const MaterialPropertyName propertyNameSecond (const MaterialPropertyName &base, const SymbolName &c1, const SymbolName &c2) const
 
const MaterialPropertyName propertyNameSecond (const MaterialPropertyName &base, const SymbolName &c1, const SymbolName &c2) const
 
const MaterialPropertyName propertyNameThird (const MaterialPropertyName &base, const SymbolName &c1, const SymbolName &c2, const SymbolName &c3) const
 
const MaterialPropertyName propertyNameThird (const MaterialPropertyName &base, const SymbolName &c1, const SymbolName &c2, const SymbolName &c3) const
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Member Functions

virtual void initQpStatefulProperties () override
 
virtual void computeQpProperties () override
 
Real stoichiometry (unsigned reaction_num, unsigned primary_num) const
 The stoichiometric coefficient.
 
virtual void computeQpSecondaryConcentrations ()
 Compute the secondary-species concentration as defined by the chemistry Must be overridden by derived classes.
 
virtual void initQpSecondaryConcentrations ()
 Initialises (at _t_step = 0) the secondary concentrations.
 
void findZeroConcentration (unsigned &zero_conc_index, unsigned &zero_count) const
 Checks gamp[i] = _primary_activity_coefficients[i] * (*_primary[i])[qp].
 
virtual void dQpSecondaryConcentration_dprimary (unsigned reaction_num, std::vector< Real > &dsc) const
 Computes derivative of the secondary concentration with respect to the primary concentrations Must be overridden by derived classes.
 
virtual Real dQpSecondaryConcentration_dT (unsigned reaction_num) const
 Computes derivative of the secondary concentration with respect to the temperature Must be overridden by derived classes.
 
void build_mass_frac (unsigned int qp)
 Builds the mass-fraction variable matrix at the quad point.
 

Protected Attributes

MaterialProperty< std::vector< Real > > & _sec_conc
 Secondary concentrations at quadpoint or nodes.
 
MaterialProperty< std::vector< std::vector< Real > > > & _dsec_conc_dvar
 Derivative of the secondary concentrations with respect to the porous flow variables.
 
const MaterialProperty< Real > & _temperature
 Temperature.
 
const MaterialProperty< std::vector< Real > > & _dtemperature_dvar
 d(temperature)/(d porflow variable)
 
const unsigned int _num_primary
 Number of primary species.
 
const unsigned int _aq_ph
 Aqueous phase number.
 
const unsigned int _aq_i
 Index (into _mf_vars) of the first of the primary species.
 
const unsigned int _num_reactions
 Number of equations in the aqueous geochemistry system.
 
const bool _equilibrium_constants_as_log10
 Whether the equilibium constants are written in their log10 form, or in absolute terms.
 
const unsigned _num_equilibrium_constants
 Number of equilibrium_constants provided.
 
std::vector< const VariableValue * > _equilibrium_constants
 Equilibrium constants (dimensionless)
 
const std::vector< Real > _primary_activity_coefficients
 Activity coefficients for the primary species (dimensionless)
 
const std::vector< Real > _reactions
 Stoichiometry defining the aqeuous geochemistry equilibrium reactions.
 
const std::vector< Real > _secondary_activity_coefficients
 Activity coefficients for the secondary species.
 
GenericMaterialProperty< std::vector< std::vector< Real > >, is_ad > & _mass_frac
 Mass fraction matrix at quadpoint or nodes.
 
GenericMaterialProperty< std::vector< std::vector< RealGradient > >, is_ad > *const _grad_mass_frac
 Gradient of the mass fraction matrix at the quad points.
 
MaterialProperty< std::vector< std::vector< std::vector< Real > > > > *const _dmass_frac_dvar
 Derivative of the mass fraction matrix with respect to the porous flow variables.
 
const unsigned int _num_passed_mf_vars
 Number of mass-fraction variables provided by the user This needs to be num_phases*(_num_components - 1), since the mass fraction of the final component in each phase is determined as 1 - sum{components}(mass fraction of all other components in the phase)
 
std::vector< unsigned int_mf_vars_num
 The variable number of the mass-fraction variables.
 
std::vector< const GenericVariableValue< is_ad > * > _mf_vars
 The mass-fraction variables.
 
std::vector< const GenericVariableGradient< is_ad > * > _grad_mf_vars
 The gradient of the mass-fraction variables.
 
const unsigned int _num_phases
 Number of phases.
 
const unsigned int _num_components
 Number of fluid components.
 
const unsigned int _num_var
 Number of PorousFlow variables.
 

Private Member Functions

bool haveMaterialProperty (const std::string &prop_name)
 
std::vector< VariableName > buildVariableVector (const VariableName &c1, const VariableName &c2, const VariableName &c3)
 
void validateCouplingHelper (const MaterialPropertyName &base, const std::vector< VariableName > &c, const System &system, std::vector< VariableName > &missing)
 
bool isNotObjectVariable (const VariableName &name)
 

Private Attributes

FEProblemBase_dmi_fe_problem
 

Detailed Description

Material designed to form a std::vector<std::vector> of mass fractions from primary-species concentrations and secondary-species concentrations for an equilibrium aqueous chemistry reaction system.

Definition at line 20 of file PorousFlowMassFractionAqueousEquilibriumChemistry.h.

Constructor & Destructor Documentation

◆ PorousFlowMassFractionAqueousEquilibriumChemistry()

PorousFlowMassFractionAqueousEquilibriumChemistry::PorousFlowMassFractionAqueousEquilibriumChemistry ( const InputParameters parameters)

Definition at line 66 of file PorousFlowMassFractionAqueousEquilibriumChemistry.C.

68 : PorousFlowMassFraction(parameters),
69 _sec_conc(_nodal_material
70 ? declareProperty<std::vector<Real>>("PorousFlow_secondary_concentration_nodal")
71 : declareProperty<std::vector<Real>>("PorousFlow_secondary_concentration_qp")),
72 _dsec_conc_dvar(_nodal_material ? declareProperty<std::vector<std::vector<Real>>>(
73 "dPorousFlow_secondary_concentration_nodal_dvar")
74 : declareProperty<std::vector<std::vector<Real>>>(
75 "dPorousFlow_secondary_concentration_qp_dvar")),
76
77 _temperature(_nodal_material ? getMaterialProperty<Real>("PorousFlow_temperature_nodal")
78 : getMaterialProperty<Real>("PorousFlow_temperature_qp")),
80 _nodal_material
81 ? getMaterialProperty<std::vector<Real>>("dPorousFlow_temperature_nodal_dvar")
82 : getMaterialProperty<std::vector<Real>>("dPorousFlow_temperature_qp_dvar")),
83
85 _aq_ph(_dictator.aqueousPhaseNumber()),
87 _num_reactions(getParam<unsigned>("num_reactions")),
88 _equilibrium_constants_as_log10(getParam<bool>("equilibrium_constants_as_log10")),
89 _num_equilibrium_constants(coupledComponents("equilibrium_constants")),
91 _primary_activity_coefficients(getParam<std::vector<Real>>("primary_activity_coefficients")),
92 _reactions(getParam<std::vector<Real>>("reactions")),
93 _secondary_activity_coefficients(getParam<std::vector<Real>>("secondary_activity_coefficients"))
94{
95 if (_dictator.numPhases() < 1)
96 mooseError("PorousFlowMassFractionAqueousEquilibriumChemistry: The number of fluid phases must "
97 "not be zero");
98
99 // correct number of equilibrium constants
101 mooseError("PorousFlowMassFractionAqueousEquilibriumChemistry: The number of "
102 "equilibrium constants is ",
104 " which must be equal to the number of reactions (",
106 ")");
107
108 // correct number of activity coefficients
110 mooseError("PorousFlowMassFractionAqueousEquilibriumChemistry: The number of primary activity "
111 "coefficients is ",
113 " which must be equal to the number of primary species (",
115 ")");
116
117 // correct number of stoichiometry coefficients
118 if (_reactions.size() != _num_reactions * _num_primary)
119 mooseError("PorousFlowMassFractionAqueousEquilibriumChemistry: The number of stoichiometric "
120 "coefficients specified in 'reactions' (",
121 _reactions.size(),
122 ") must be equal to the number of reactions (",
124 ") multiplied by the number of primary species (",
126 ")");
127
128 // correct number of secondary activity coefficients
131 "PorousFlowMassFractionAqueousEquilibriumChemistry: The number of secondary activity "
132 "coefficients is ",
134 " which must be equal to the number of secondary species (",
136 ")");
137
138 // correct number of reactions
139 if (_num_reactions != _dictator.numAqueousEquilibrium())
140 mooseError("PorousFlowMassFractionAqueousEquilibriumChemistry: You have specified the number "
141 "of reactions to be ",
143 " but the Dictator knows that the number of aqueous equilibrium reactions is ",
144 _dictator.numAqueousEquilibrium());
145
146 for (unsigned i = 0; i < _num_equilibrium_constants; ++i)
147 {
148 // If equilibrium_constants are elemental AuxVariables (or constants), we want to use
149 // coupledGenericValue() rather than coupledGenericDofValue()
150 const bool is_nodal = isCoupled("equilibrium_constants")
151 ? getFieldVar("equilibrium_constants", i)->isNodal()
152 : false;
153
155 (_nodal_material && is_nodal ? &coupledDofValues("equilibrium_constants", i)
156 : &coupledValue("equilibrium_constants", i));
157 }
158}
void mooseError(Args &&... args)
PorousFlowMassFractionTempl< false > PorousFlowMassFraction
const std::vector< Real > _reactions
Stoichiometry defining the aqeuous geochemistry equilibrium reactions.
const unsigned int _aq_i
Index (into _mf_vars) of the first of the primary species.
MaterialProperty< std::vector< std::vector< Real > > > & _dsec_conc_dvar
Derivative of the secondary concentrations with respect to the porous flow variables.
std::vector< const VariableValue * > _equilibrium_constants
Equilibrium constants (dimensionless)
const MaterialProperty< std::vector< Real > > & _dtemperature_dvar
d(temperature)/(d porflow variable)
MaterialProperty< std::vector< Real > > & _sec_conc
Secondary concentrations at quadpoint or nodes.
const unsigned _num_equilibrium_constants
Number of equilibrium_constants provided.
const bool _equilibrium_constants_as_log10
Whether the equilibium constants are written in their log10 form, or in absolute terms.
const std::vector< Real > _secondary_activity_coefficients
Activity coefficients for the secondary species.
const std::vector< Real > _primary_activity_coefficients
Activity coefficients for the primary species (dimensionless)
const unsigned int _num_reactions
Number of equations in the aqueous geochemistry system.
const unsigned int _num_components
Number of fluid components.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

Member Function Documentation

◆ build_mass_frac()

template<bool is_ad>
void PorousFlowMassFractionTempl< is_ad >::build_mass_frac ( unsigned int  qp)
protectedinherited

Builds the mass-fraction variable matrix at the quad point.

Parameters
qpthe quad point

◆ computeQpProperties()

void PorousFlowMassFractionAqueousEquilibriumChemistry::computeQpProperties ( )
overrideprotectedvirtual

Reimplemented from PorousFlowMassFractionTempl< is_ad >.

Definition at line 167 of file PorousFlowMassFractionAqueousEquilibriumChemistry.C.

168{
169 // size all properties correctly and populate the non-aqueous phase info
171
172 // size the secondary concentrations
175 for (unsigned r = 0; r < _num_reactions; ++r)
176 _dsec_conc_dvar[_qp][r].assign(_num_var, 0.0);
177
178 // Compute the secondary concentrations
179 if (_t_step == 0 && !_app.isRestarting())
181 else
183
184 // compute _mass_frac[_qp][_aq_ph]
185 _mass_frac[_qp][_aq_ph][_num_components - 1] = 1.0; // the final component is H20
186 for (unsigned i = 0; i < _num_primary; ++i)
187 {
188 _mass_frac[_qp][_aq_ph][i] = (*_mf_vars[_aq_i + i])[_qp];
189 for (unsigned r = 0; r < _num_reactions; ++r)
190 _mass_frac[_qp][_aq_ph][i] += stoichiometry(r, i) * _sec_conc[_qp][r];
191
192 // remove mass-fraction from the H20 component
193 _mass_frac[_qp][_aq_ph][_num_components - 1] -= _mass_frac[_qp][_aq_ph][i];
194 }
195
196 // Compute the derivatives of the secondary concentrations
197 std::vector<std::vector<Real>> dsec(_num_reactions);
198 std::vector<Real> dsec_dT(_num_reactions);
199 for (unsigned r = 0; r < _num_reactions; ++r)
200 {
202 dsec_dT[r] = dQpSecondaryConcentration_dT(r);
203 }
204
205 // Compute the derivatives of the mass_frac wrt the primary concentrations
206 // This is used in _dmass_frac_dvar as well as _grad_mass_frac
207 std::vector<std::vector<Real>> dmf(_num_components);
208 for (unsigned i = 0; i < _num_components; ++i)
209 dmf[i].assign(_num_primary, 0.0);
210 for (unsigned wrt = 0; wrt < _num_primary; ++wrt)
211 {
212 // run through the mass fractions (except the last one) adding to their derivatives
213 // The special case is:
214 dmf[wrt][wrt] = 1.0;
215 // The secondary-species contributions are:
216 for (unsigned i = 0; i < _num_primary; ++i)
217 for (unsigned r = 0; r < _num_reactions; ++r)
218 dmf[i][wrt] += stoichiometry(r, i) * dsec[r][wrt];
219
220 // compute dmf[_num_components - 1]
221 for (unsigned i = 0; i < _num_primary; ++i)
222 dmf[_num_components - 1][wrt] -= dmf[i][wrt];
223 }
224
225 // Compute the derivatives of the mass_frac wrt the temperature
226 // This is used in _dmass_frac_dvar
227 std::vector<Real> dmf_dT(_num_components, 0.0);
228 for (unsigned i = 0; i < _num_components - 1; ++i)
229 {
230 for (unsigned r = 0; r < _num_reactions; ++r)
231 dmf_dT[i] += stoichiometry(r, i) * dsec_dT[r];
232 dmf_dT[_num_components - 1] -= dmf_dT[i];
233 }
234
235 // compute _dmass_frac_dvar[_qp][_aq_ph] and _dsec_conc_dvar[_qp]
236 for (unsigned wrt = 0; wrt < _num_primary; ++wrt)
237 {
238 // derivative with respect to the "wrt"^th primary species concentration
239 if (!_dictator.isPorousFlowVariable(_mf_vars_num[_aq_i + wrt]))
240 continue;
241 const unsigned pf_wrt = _dictator.porousFlowVariableNum(_mf_vars_num[_aq_i + wrt]);
242
243 // run through the mass fractions, building the derivative using dmf
244 for (unsigned i = 0; i < _num_components; ++i)
245 (*_dmass_frac_dvar)[_qp][_aq_ph][i][pf_wrt] = dmf[i][wrt];
246
247 // run through the secondary concentrations, using dsec in the appropriate places
248 for (unsigned r = 0; r < _num_reactions; ++r)
249 _dsec_conc_dvar[_qp][r][pf_wrt] = dsec[r][wrt];
250 }
251
252 // use the derivative wrt temperature
253 for (unsigned i = 0; i < _num_components; ++i)
254 for (unsigned v = 0; v < _num_var; ++v)
255 (*_dmass_frac_dvar)[_qp][_aq_ph][i][v] += dmf_dT[i] * _dtemperature_dvar[_qp][v];
256 for (unsigned r = 0; r < _num_reactions; ++r)
257 for (unsigned v = 0; v < _num_var; ++v)
258 _dsec_conc_dvar[_qp][r][v] += dsec_dT[r] * _dtemperature_dvar[_qp][v];
259
260 // compute the gradient, if needed
261 // NOTE: The derivative d(grad_mass_frac)/d(var) != d(mass_frac)/d(var) * grad_phi
262 // because mass fraction is a nonlinear function of the primary variables
263 // This means that the Jacobian in PorousFlowDispersiveFlux will be wrong
264 if (!_nodal_material)
265 {
266 (*_grad_mass_frac)[_qp][_aq_ph][_num_components - 1] = 0.0;
267 for (unsigned comp = 0; comp < _num_components - 1; ++comp)
268 {
269 (*_grad_mass_frac)[_qp][_aq_ph][comp] = 0.0;
270 for (unsigned wrt = 0; wrt < _num_primary; ++wrt)
271 (*_grad_mass_frac)[_qp][_aq_ph][comp] +=
272 dmf[comp][wrt] * (*_grad_mf_vars[_aq_i + wrt])[_qp];
273 (*_grad_mass_frac)[_qp][_aq_ph][_num_components - 1] -= (*_grad_mass_frac)[_qp][_aq_ph][comp];
274 }
275 }
276}
const double v
virtual void resize(const std::size_t size) override final
virtual void dQpSecondaryConcentration_dprimary(unsigned reaction_num, std::vector< Real > &dsc) const
Computes derivative of the secondary concentration with respect to the primary concentrations Must be...
Real stoichiometry(unsigned reaction_num, unsigned primary_num) const
The stoichiometric coefficient.
virtual Real dQpSecondaryConcentration_dT(unsigned reaction_num) const
Computes derivative of the secondary concentration with respect to the temperature Must be overridden...
virtual void computeQpSecondaryConcentrations()
Compute the secondary-species concentration as defined by the chemistry Must be overridden by derived...
virtual void initQpSecondaryConcentrations()
Initialises (at _t_step = 0) the secondary concentrations.
GenericMaterialProperty< std::vector< std::vector< Real > >, is_ad > & _mass_frac
Mass fraction matrix at quadpoint or nodes.
std::vector< const GenericVariableValue< is_ad > * > _mf_vars
The mass-fraction variables.
GenericMaterialProperty< std::vector< std::vector< RealGradient > >, is_ad > *const _grad_mass_frac
Gradient of the mass fraction matrix at the quad points.
virtual void computeQpProperties() override
std::vector< unsigned int > _mf_vars_num
The variable number of the mass-fraction variables.
std::vector< const GenericVariableGradient< is_ad > * > _grad_mf_vars
The gradient of the mass-fraction variables.
MaterialProperty< std::vector< std::vector< std::vector< Real > > > > *const _dmass_frac_dvar
Derivative of the mass fraction matrix with respect to the porous flow variables.
const unsigned int _num_var
Number of PorousFlow variables.

Referenced by initQpStatefulProperties().

◆ computeQpSecondaryConcentrations()

void PorousFlowMassFractionAqueousEquilibriumChemistry::computeQpSecondaryConcentrations ( )
protectedvirtual

Compute the secondary-species concentration as defined by the chemistry Must be overridden by derived classes.

Definition at line 311 of file PorousFlowMassFractionAqueousEquilibriumChemistry.C.

312{
313 for (unsigned r = 0; r < _num_reactions; ++r)
314 {
315 _sec_conc[_qp][r] = 1.0;
316 for (unsigned i = 0; i < _num_primary; ++i)
317 {
318 const Real gamp = _primary_activity_coefficients[i] * (*_mf_vars[_aq_i + i])[_qp];
319 if (gamp <= 0.0)
320 {
321 if (stoichiometry(r, i) < 0.0)
322 _sec_conc[_qp][r] = std::numeric_limits<Real>::max();
323 else if (stoichiometry(r, i) == 0.0)
324 _sec_conc[_qp][r] *= 1.0;
325 else
326 {
327 _sec_conc[_qp][r] = 0.0;
328 break;
329 }
330 }
331 else
332 _sec_conc[_qp][r] *= std::pow(gamp, stoichiometry(r, i));
333 }
334 _sec_conc[_qp][r] *=
335 (_equilibrium_constants_as_log10 ? std::pow(10.0, (*_equilibrium_constants[r])[_qp])
336 : (*_equilibrium_constants[r])[_qp]);
338 }
339}

Referenced by computeQpProperties().

◆ dQpSecondaryConcentration_dprimary()

void PorousFlowMassFractionAqueousEquilibriumChemistry::dQpSecondaryConcentration_dprimary ( unsigned  reaction_num,
std::vector< Real > &  dsc 
) const
protectedvirtual

Computes derivative of the secondary concentration with respect to the primary concentrations Must be overridden by derived classes.

Parameters
reaction_numThe reaction number corresponding to the secondary-species concentration
dscdsc[i] = d(secondaryConcentration[reaction_num])/d(primary_species[i])

Definition at line 342 of file PorousFlowMassFractionAqueousEquilibriumChemistry.C.

344{
345 dsc.assign(_num_primary, 0.0);
346
347 /*
348 * the derivatives are straightforward if all primary > 0.
349 *
350 * If more than one primary = 0 then I set the derivatives to zero, even though it could be argued
351 * that with certain stoichiometric coefficients you might have derivative = 0/0 and it might be
352 * appropriate to set this to a non-zero finite value.
353 *
354 * If exactly one primary = 0 and its stoichiometry = 1 then the derivative wrt this one is
355 * nonzero.
356 * If exactly one primary = 0 and its stoichiometry > 1 then all derivatives are zero.
357 * If exactly one primary = 0 and its stoichiometry < 1 then the derivative wrt this one is
358 * infinity
359 */
360
361 unsigned zero_count = 0;
362 unsigned zero_conc_index = 0;
363 findZeroConcentration(zero_conc_index, zero_count);
364
365 if (zero_count == 0)
366 {
367 for (unsigned i = 0; i < _num_primary; ++i)
368 dsc[i] = stoichiometry(reaction_num, i) * _sec_conc[_qp][reaction_num] /
369 (*_mf_vars[_aq_i + i])[_qp];
370 }
371 else
372 {
373 // count the number of primary <= 0, and record the one that's zero
374 if (zero_count == 1 and stoichiometry(reaction_num, zero_conc_index) == 1.0)
375 {
376 Real conc_without_zero = 1.0;
377 for (unsigned i = 0; i < _num_primary; ++i)
378 {
379 if (i == zero_conc_index)
380 conc_without_zero *= _primary_activity_coefficients[i];
381 else
382 conc_without_zero *=
383 std::pow(_primary_activity_coefficients[i] * (*_mf_vars[_aq_i + i])[_qp],
384 stoichiometry(reaction_num, i));
385 }
386 conc_without_zero *= (_equilibrium_constants_as_log10
387 ? std::pow(10.0, (*_equilibrium_constants[reaction_num])[_qp])
388 : (*_equilibrium_constants[reaction_num])[_qp]);
389 conc_without_zero /= _secondary_activity_coefficients[reaction_num];
390 dsc[zero_conc_index] = conc_without_zero;
391 }
392 else if (zero_count == 1 && stoichiometry(reaction_num, zero_conc_index) < 1.0)
393 dsc[zero_conc_index] = std::numeric_limits<Real>::max();
394
395 // all other cases have dsc = 0
396 }
397}
void findZeroConcentration(unsigned &zero_conc_index, unsigned &zero_count) const
Checks gamp[i] = _primary_activity_coefficients[i] * (*_primary[i])[qp].

Referenced by computeQpProperties().

◆ dQpSecondaryConcentration_dT()

Real PorousFlowMassFractionAqueousEquilibriumChemistry::dQpSecondaryConcentration_dT ( unsigned  reaction_num) const
protectedvirtual

Computes derivative of the secondary concentration with respect to the temperature Must be overridden by derived classes.

Parameters
reaction_numThe reaction number corresponding to the secondary-species concentration
dscdsc[i] = d(secondaryConcentration[reaction_num])/d(primary_species[i])

Definition at line 400 of file PorousFlowMassFractionAqueousEquilibriumChemistry.C.

402{
403 return 0.0;
404}

Referenced by computeQpProperties().

◆ findZeroConcentration()

void PorousFlowMassFractionAqueousEquilibriumChemistry::findZeroConcentration ( unsigned &  zero_conc_index,
unsigned &  zero_count 
) const
protected

Checks gamp[i] = _primary_activity_coefficients[i] * (*_primary[i])[qp].

Returns: if all of these are positive, then zero_count = 0, zero_conc_index = 0 if one of these is zero, then zero_count = 1, zero_conc_index = the index of the zero gamp if more than one is zero, then zero_count = 2, and zero_conc_index is the index of the 2nd zero

Definition at line 287 of file PorousFlowMassFractionAqueousEquilibriumChemistry.C.

289{
290 zero_count = 0;
291 for (unsigned i = 0; i < _num_primary; ++i)
292 {
293 if (_primary_activity_coefficients[i] * (*_mf_vars[_aq_i + i])[_qp] <= 0.0)
294 {
295 zero_count += 1;
296 zero_conc_index = i;
297 if (zero_count > 1)
298 return;
299 }
300 }
301 return;
302}

Referenced by dQpSecondaryConcentration_dprimary().

◆ initQpSecondaryConcentrations()

void PorousFlowMassFractionAqueousEquilibriumChemistry::initQpSecondaryConcentrations ( )
protectedvirtual

Initialises (at _t_step = 0) the secondary concentrations.

Definition at line 305 of file PorousFlowMassFractionAqueousEquilibriumChemistry.C.

306{
307 _sec_conc[_qp].assign(_num_reactions, 0.0);
308}

Referenced by computeQpProperties().

◆ initQpStatefulProperties()

void PorousFlowMassFractionAqueousEquilibriumChemistry::initQpStatefulProperties ( )
overrideprotectedvirtual

◆ stoichiometry()

Real PorousFlowMassFractionAqueousEquilibriumChemistry::stoichiometry ( unsigned  reaction_num,
unsigned  primary_num 
) const
protected

The stoichiometric coefficient.

Parameters
reaction_numReaction number (0, ..., _num_reactions - 1)
primary_numThe number of the primary species (0, ..., _num_primary - 1)

Definition at line 279 of file PorousFlowMassFractionAqueousEquilibriumChemistry.C.

281{
282 const unsigned index = reaction_num * _num_primary + primary_num;
283 return _reactions[index];
284}

Referenced by computeQpProperties(), computeQpSecondaryConcentrations(), and dQpSecondaryConcentration_dprimary().

◆ validParams()

InputParameters PorousFlowMassFractionAqueousEquilibriumChemistry::validParams ( )
static

Definition at line 15 of file PorousFlowMassFractionAqueousEquilibriumChemistry.C.

16{
19 "mass_fraction_vars",
20 "List of variables that represent the mass fractions. For the aqueous phase these are "
21 "concentrations of the primary species with units m^{3}(chemical)/m^{3}(fluid phase). For "
22 "the other phases (if any) these will typically be initialised to zero and will not change "
23 "throughout the simulation. Format is 'f_ph0^c0 f_ph0^c1 f_ph0^c2 ... f_ph0^c(N-2) f_ph1^c0 "
24 "f_ph1^c1 fph1^c2 ... fph1^c(N-2) ... fphP^c0 f_phP^c1 fphP^c2 ... fphP^c(N-2)' where "
25 "N=number of primary species and P=num_phases, and it is assumed that "
26 "f_ph^c(N-1)=1-sum(f_ph^c,{c,0,N-2}) so that f_ph^c(N-1) need not be given.");
27 params.addRequiredParam<unsigned>("num_reactions",
28 "Number of equations in the system of chemical reactions");
29 params.addParam<bool>("equilibrium_constants_as_log10",
30 false,
31 "If true, the equilibrium constants are written in their log10 form, eg, "
32 "-2. If false, the equilibrium constants are written in absolute terms, "
33 "eg, 0.01");
34 params.addRequiredCoupledVar("equilibrium_constants",
35 "Equilibrium constant for each equation (dimensionless). If these "
36 "are temperature dependent AuxVariables, the Jacobian will not be "
37 "exact");
38 params.addRequiredParam<std::vector<Real>>(
39 "primary_activity_coefficients",
40 "Activity coefficients for the primary species (dimensionless) (one for each)");
41 params.addRequiredParam<std::vector<Real>>(
42 "reactions",
43 "A matrix defining the aqueous reactions. The matrix is entered as a long vector: the first "
44 "row is "
45 "entered first, followed by the second row, etc. There should be num_reactions rows. All "
46 "primary species should appear only on the LHS of each reaction (and there should be just "
47 "one secondary species on the RHS, by definition) so they may have negative coefficients. "
48 "Each row should have number of primary_concentrations entries, which are the stoichiometric "
49 "coefficients. The first coefficient must always correspond to the first primary species, "
50 "etc");
51 params.addRequiredParam<std::vector<Real>>(
52 "secondary_activity_coefficients",
53 "Activity coefficients for the secondary species (dimensionless) (one for each reaction)");
54 params.addPrivateParam<std::string>("pf_material_type", "mass_fraction");
56 "This Material forms a std::vector<std::vector ...> of mass-fractions "
57 "(total concentrations of primary species (m^{3}(primary species)/m^{3}(solution)) and since "
58 "this is for an aqueous system only, mass-fraction equals volume-fraction) corresponding to "
59 "an "
60 "aqueous equilibrium chemistry system. The first mass fraction is the "
61 "concentration of the first primary species, etc, and the last mass "
62 "fraction is the concentration of H2O.");
63 return params;
64}
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addPrivateParam(const std::string &name, const T &value)
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)

Member Data Documentation

◆ _aq_i

const unsigned int PorousFlowMassFractionAqueousEquilibriumChemistry::_aq_i
protected

Index (into _mf_vars) of the first of the primary species.

Definition at line 95 of file PorousFlowMassFractionAqueousEquilibriumChemistry.h.

Referenced by computeQpProperties(), computeQpSecondaryConcentrations(), dQpSecondaryConcentration_dprimary(), and findZeroConcentration().

◆ _aq_ph

const unsigned int PorousFlowMassFractionAqueousEquilibriumChemistry::_aq_ph
protected

Aqueous phase number.

Definition at line 92 of file PorousFlowMassFractionAqueousEquilibriumChemistry.h.

Referenced by computeQpProperties().

◆ _dmass_frac_dvar

template<bool is_ad>
MaterialProperty<std::vector<std::vector<std::vector<Real> > > >* const PorousFlowMassFractionTempl< is_ad >::_dmass_frac_dvar
protectedinherited

Derivative of the mass fraction matrix with respect to the porous flow variables.

Definition at line 34 of file PorousFlowMassFraction.h.

Referenced by computeQpProperties().

◆ _dsec_conc_dvar

MaterialProperty<std::vector<std::vector<Real> > >& PorousFlowMassFractionAqueousEquilibriumChemistry::_dsec_conc_dvar
protected

Derivative of the secondary concentrations with respect to the porous flow variables.

Definition at line 80 of file PorousFlowMassFractionAqueousEquilibriumChemistry.h.

Referenced by computeQpProperties().

◆ _dtemperature_dvar

const MaterialProperty<std::vector<Real> >& PorousFlowMassFractionAqueousEquilibriumChemistry::_dtemperature_dvar
protected

d(temperature)/(d porflow variable)

Definition at line 86 of file PorousFlowMassFractionAqueousEquilibriumChemistry.h.

Referenced by computeQpProperties().

◆ _equilibrium_constants

std::vector<const VariableValue *> PorousFlowMassFractionAqueousEquilibriumChemistry::_equilibrium_constants
protected

◆ _equilibrium_constants_as_log10

const bool PorousFlowMassFractionAqueousEquilibriumChemistry::_equilibrium_constants_as_log10
protected

Whether the equilibium constants are written in their log10 form, or in absolute terms.

Definition at line 101 of file PorousFlowMassFractionAqueousEquilibriumChemistry.h.

Referenced by computeQpSecondaryConcentrations(), and dQpSecondaryConcentration_dprimary().

◆ _grad_mass_frac

template<bool is_ad>
GenericMaterialProperty<std::vector<std::vector<RealGradient> >, is_ad>* const PorousFlowMassFractionTempl< is_ad >::_grad_mass_frac
protectedinherited

Gradient of the mass fraction matrix at the quad points.

Definition at line 31 of file PorousFlowMassFraction.h.

Referenced by computeQpProperties().

◆ _grad_mf_vars

template<bool is_ad>
std::vector<const GenericVariableGradient<is_ad> *> PorousFlowMassFractionTempl< is_ad >::_grad_mf_vars
protectedinherited

The gradient of the mass-fraction variables.

Definition at line 60 of file PorousFlowMassFraction.h.

Referenced by computeQpProperties(), and PorousFlowMassFractionTempl< is_ad >::PorousFlowMassFractionTempl().

◆ _mass_frac

template<bool is_ad>
GenericMaterialProperty<std::vector<std::vector<Real> >, is_ad>& PorousFlowMassFractionTempl< is_ad >::_mass_frac
protectedinherited

Mass fraction matrix at quadpoint or nodes.

Definition at line 28 of file PorousFlowMassFraction.h.

Referenced by computeQpProperties().

◆ _mf_vars

template<bool is_ad>
std::vector<const GenericVariableValue<is_ad> *> PorousFlowMassFractionTempl< is_ad >::_mf_vars
protectedinherited

◆ _mf_vars_num

template<bool is_ad>
std::vector<unsigned int> PorousFlowMassFractionTempl< is_ad >::_mf_vars_num
protectedinherited

The variable number of the mass-fraction variables.

Definition at line 54 of file PorousFlowMassFraction.h.

Referenced by computeQpProperties(), and PorousFlowMassFractionTempl< is_ad >::PorousFlowMassFractionTempl().

◆ _num_components

const unsigned int PorousFlowMaterialVectorBase::_num_components
protectedinherited

◆ _num_equilibrium_constants

const unsigned PorousFlowMassFractionAqueousEquilibriumChemistry::_num_equilibrium_constants
protected

Number of equilibrium_constants provided.

Definition at line 104 of file PorousFlowMassFractionAqueousEquilibriumChemistry.h.

Referenced by PorousFlowMassFractionAqueousEquilibriumChemistry().

◆ _num_passed_mf_vars

template<bool is_ad>
const unsigned int PorousFlowMassFractionTempl< is_ad >::_num_passed_mf_vars
protectedinherited

Number of mass-fraction variables provided by the user This needs to be num_phases*(_num_components - 1), since the mass fraction of the final component in each phase is determined as 1 - sum{components}(mass fraction of all other components in the phase)

Definition at line 51 of file PorousFlowMassFraction.h.

Referenced by PorousFlowMassFractionTempl< is_ad >::PorousFlowMassFractionTempl().

◆ _num_phases

const unsigned int PorousFlowMaterialVectorBase::_num_phases
protectedinherited

◆ _num_primary

const unsigned int PorousFlowMassFractionAqueousEquilibriumChemistry::_num_primary
protected

◆ _num_reactions

const unsigned int PorousFlowMassFractionAqueousEquilibriumChemistry::_num_reactions
protected

◆ _num_var

const unsigned int PorousFlowMaterialVectorBase::_num_var
protectedinherited

◆ _primary_activity_coefficients

const std::vector<Real> PorousFlowMassFractionAqueousEquilibriumChemistry::_primary_activity_coefficients
protected

◆ _reactions

const std::vector<Real> PorousFlowMassFractionAqueousEquilibriumChemistry::_reactions
protected

Stoichiometry defining the aqeuous geochemistry equilibrium reactions.

Definition at line 113 of file PorousFlowMassFractionAqueousEquilibriumChemistry.h.

Referenced by PorousFlowMassFractionAqueousEquilibriumChemistry(), and stoichiometry().

◆ _sec_conc

MaterialProperty<std::vector<Real> >& PorousFlowMassFractionAqueousEquilibriumChemistry::_sec_conc
protected

◆ _secondary_activity_coefficients

const std::vector<Real> PorousFlowMassFractionAqueousEquilibriumChemistry::_secondary_activity_coefficients
protected

◆ _temperature

const MaterialProperty<Real>& PorousFlowMassFractionAqueousEquilibriumChemistry::_temperature
protected

Temperature.

Definition at line 83 of file PorousFlowMassFractionAqueousEquilibriumChemistry.h.


The documentation for this class was generated from the following files: