https://mooseframework.inl.gov
Loading...
Searching...
No Matches
GeochemistryIonicStrength.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#include "libmesh/utility.h"
12
14 Real max_stoichiometric_ionic_strength,
15 bool use_only_basis_molality,
16 bool use_only_Cl_molality)
17 : _max_ionic_strength(max_ionic_strength),
18 _max_stoichiometric_ionic_strength(max_stoichiometric_ionic_strength),
19 _use_only_basis_molality(use_only_basis_molality),
20 _use_only_Cl_molality(use_only_Cl_molality)
21{
22}
23
24Real
26 const std::vector<Real> & basis_species_molality,
27 const std::vector<Real> & eqm_species_molality,
28 const std::vector<Real> & kin_species_molality) const
29{
30 const unsigned num_basis = mgd.basis_species_charge.size();
31 const unsigned num_eqm = mgd.eqm_species_charge.size();
32 const unsigned num_kin = mgd.kin_species_charge.size();
33 if (num_basis != basis_species_molality.size())
34 mooseError("Ionic strength calculation: Number of basis species in mgd not equal to the size "
35 "of basis_species_molality");
36 if (num_eqm != eqm_species_molality.size())
37 mooseError("Ionic strength calculation: Number of equilibrium species in mgd not equal to the "
38 "size of eqm_species_molality");
39 if (num_kin != kin_species_molality.size())
40 mooseError("Ionic strength calculation: Number of kinetic species in mgd not equal to the size "
41 "of kin_species_molality");
42
43 Real ionic_strength = 0.0;
44 for (unsigned i = 0; i < num_basis; ++i)
45 ionic_strength += Utility::pow<2>(mgd.basis_species_charge[i]) * basis_species_molality[i];
47 {
48 for (unsigned i = 0; i < num_eqm; ++i)
50 ionic_strength += Utility::pow<2>(mgd.eqm_species_charge[i]) * eqm_species_molality[i];
51 for (unsigned i = 0; i < num_kin; ++i)
52 ionic_strength += Utility::pow<2>(mgd.kin_species_charge[i]) * kin_species_molality[i] /
53 basis_species_molality[0]; // kin_species_molality is actually the number of
54 // moles of the kinetic species
55 }
56
57 return std::max(0.0, std::min(_max_ionic_strength, 0.5 * ionic_strength));
58}
59
60Real
63 const std::vector<Real> & basis_species_molality,
64 const std::vector<Real> & eqm_species_molality,
65 const std::vector<Real> & kin_species_molality) const
66{
67 const unsigned num_basis = mgd.basis_species_charge.size();
68 const unsigned num_eqm = mgd.eqm_species_charge.size();
69 const unsigned num_kin = mgd.kin_species_charge.size();
70 if (num_basis != basis_species_molality.size())
71 mooseError("Stoichiometric ionic strength calculation: Number of basis species in mgd not "
72 "equal to the size of basis_species_molality");
73 if (num_eqm != eqm_species_molality.size())
74 mooseError("Stoichiometric ionic strength calculation: Number of equilibrium species in mgd "
75 "not equal to the size of eqm_species_molality");
76 if (num_kin != kin_species_molality.size())
77 mooseError("Stoichiometric ionic strength calculation: Number of kinetic species in mgd not "
78 "equal to the size of kin_species_molality");
79
80 Real ionic_strength = 0.0;
82 {
83 if (mgd.basis_species_index.count("Cl-"))
84 ionic_strength = basis_species_molality[mgd.basis_species_index.at("Cl-")];
85 else if (mgd.eqm_species_index.count("Cl-"))
86 ionic_strength = eqm_species_molality[mgd.eqm_species_index.at("Cl-")];
87 else if (mgd.kin_species_index.count("Cl-"))
88 ionic_strength = kin_species_molality[mgd.kin_species_index.at("Cl-")];
89 else
90 mooseError("GeochemistryIonicStrength: attempting to compute stoichiometric ionic strength "
91 "using only the Cl- molality, but Cl- does not appear in the geochemical system");
92 return std::max(0.0, std::min(_max_stoichiometric_ionic_strength, ionic_strength));
93 }
94
95 for (unsigned i = 0; i < num_basis; ++i)
96 ionic_strength += Utility::pow<2>(mgd.basis_species_charge[i]) * basis_species_molality[i];
98 {
99 for (unsigned i = 0; i < num_eqm; ++i)
101 {
102
103 if (mgd.eqm_species_charge[i] != 0.0)
104 ionic_strength += Utility::pow<2>(mgd.eqm_species_charge[i]) * eqm_species_molality[i];
105 else
106 {
107 for (unsigned j = 0; j < num_basis; ++j)
108 ionic_strength += Utility::pow<2>(mgd.basis_species_charge[j]) *
109 eqm_species_molality[i] * mgd.eqm_stoichiometry(i, j);
110 }
111 }
112 for (unsigned i = 0; i < num_kin;
113 ++i) // kin_species_molality is actually the number of moles, not molality
114 if (mgd.kin_species_charge[i] != 0.0)
115 ionic_strength += Utility::pow<2>(mgd.kin_species_charge[i]) * kin_species_molality[i] /
116 basis_species_molality[0];
117 }
118
119 return std::max(0.0, std::min(_max_stoichiometric_ionic_strength, 0.5 * ionic_strength));
120}
121
122void
124{
125 _max_ionic_strength = max_ionic_strength;
126}
127
128Real
133
134void
136{
137 _max_stoichiometric_ionic_strength = max_stoichiometric_ionic_strength;
138}
139
140Real
145
146void
148{
149 _use_only_basis_molality = use_only_basis_molality;
150}
151
152Real
157
158void
160{
161 _use_only_Cl_molality = use_only_Cl_molality;
162}
163
164Real
const ModelGeochemicalDatabase mgd
void mooseError(Args &&... args)
Real _max_ionic_strength
maximum ionic strength
Real stoichiometricIonicStrength(const ModelGeochemicalDatabase &mgd, const std::vector< Real > &basis_species_molality, const std::vector< Real > &eqm_species_molality, const std::vector< Real > &kin_species_molality) const
Compute stoichiometric ionic strength.
void setUseOnlyBasisMolality(bool use_only_basis_molality)
Set the value of use_only_basis_molality.
Real getMaxIonicStrength() const
Return the value of maximum ionic strength.
Real getMaxStoichiometricIonicStrength() const
Return the value of maximum stoichiometric ionic strength.
bool _use_only_basis_molality
use only basis molality in the ionic strength calculations
Real ionicStrength(const ModelGeochemicalDatabase &mgd, const std::vector< Real > &basis_species_molality, const std::vector< Real > &eqm_species_molality, const std::vector< Real > &kin_species_molality) const
Compute ionic strength.
Real getUseOnlyClMolality() const
Return the value of use_only_Cl_molality.
void setUseOnlyClMolality(bool use_only_Cl_molality)
Set the value of use_only_Cl_molality.
void setMaxStoichiometricIonicStrength(Real max_stoichiometric_ionic_strength)
Set the maximum stoichiometric ionic strength.
Real getUseOnlyBasisMolality() const
Return the value of use_only_basis_molality.
void setMaxIonicStrength(Real max_ionic_strength)
Set the maximum ionic strength.
bool _use_only_Cl_molality
set the stoichiometric ionic strength to the Cl- molality
Real _max_stoichiometric_ionic_strength
maximum stoichiometric ionic strength
GeochemistryIonicStrength(Real max_ionic_strength, Real max_stoichiometric_ionic_strength, bool use_only_basis_molality, bool use_only_Cl_molality)
Data structure to hold all relevant information from the database file.
DenseMatrix< Real > eqm_stoichiometry
eqm_stoichiometry(i, j) = stoichiometric coefficient for equilibrium species "i" in terms of the basi...
std::vector< Real > basis_species_charge
all quantities have a charge (mineral charge = 0, gas charge = 0, oxide charge = 0)
std::vector< bool > surface_sorption_related
surface_sorption_related[j] = true iff the j^th equilibrium species is involved in surface sorption
std::unordered_map< std::string, unsigned > eqm_species_index
eqm_species_index[name] = index of the equilibrium species (secondary aqueous species,...
std::vector< Real > kin_species_charge
all kinetic quantities have a charge (mineral charge = 0)
std::unordered_map< std::string, unsigned > basis_species_index
basis_species_index[name] = index of the basis species, within all ModelGeochemicalDatabase internal ...
std::unordered_map< std::string, unsigned > kin_species_index
kin_species_index[name] = index of the kinetic species, within all ModelGeochemicalDatabase internal ...
std::vector< Real > eqm_species_charge
all quantities have a charge (mineral charge = 0, gas charge = 0, oxide charge = 0)