https://mooseframework.inl.gov
Public Member Functions | Private Attributes | List of all members
GeochemistryIonicStrength Class Reference

Calculators to compute ionic strength and stoichiometric ionic strength. More...

#include <GeochemistryIonicStrength.h>

Public Member Functions

 GeochemistryIonicStrength (Real max_ionic_strength, Real max_stoichiometric_ionic_strength, bool use_only_basis_molality, bool use_only_Cl_molality)
 
bool operator== (const GeochemistryIonicStrength &rhs) const
 
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. More...
 
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. More...
 
void setMaxIonicStrength (Real max_ionic_strength)
 Set the maximum ionic strength. More...
 
Real getMaxIonicStrength () const
 Return the value of maximum ionic strength. More...
 
void setMaxStoichiometricIonicStrength (Real max_stoichiometric_ionic_strength)
 Set the maximum stoichiometric ionic strength. More...
 
Real getMaxStoichiometricIonicStrength () const
 Return the value of maximum stoichiometric ionic strength. More...
 
void setUseOnlyBasisMolality (bool use_only_basis_molality)
 Set the value of use_only_basis_molality. More...
 
Real getUseOnlyBasisMolality () const
 Return the value of use_only_basis_molality. More...
 
void setUseOnlyClMolality (bool use_only_Cl_molality)
 Set the value of use_only_Cl_molality. More...
 
Real getUseOnlyClMolality () const
 Return the value of use_only_Cl_molality. More...
 

Private Attributes

Real _max_ionic_strength
 maximum ionic strength More...
 
Real _max_stoichiometric_ionic_strength
 maximum stoichiometric ionic strength More...
 
bool _use_only_basis_molality
 use only basis molality in the ionic strength calculations More...
 
bool _use_only_Cl_molality
 set the stoichiometric ionic strength to the Cl- molality More...
 

Detailed Description

Calculators to compute ionic strength and stoichiometric ionic strength.

Definition at line 17 of file GeochemistryIonicStrength.h.

Constructor & Destructor Documentation

◆ GeochemistryIonicStrength()

GeochemistryIonicStrength::GeochemistryIonicStrength ( Real  max_ionic_strength,
Real  max_stoichiometric_ionic_strength,
bool  use_only_basis_molality,
bool  use_only_Cl_molality 
)
Parameters
max_ionic_strengthmaximum value of ionic strength ever returned by this class
max_stoichiometric_ionic_strengthmaximum value of stoichiometric ionic strength ever returned by this class
use_only_basis_molalityIf true, use only the basis molalities in the ionic strength and stoichiometric ionic strength calculations. Since basis molality is usually much greater than equilibrium molality, and the whole concept of activity coefficients depending on ionic strength is only approximate in practice, setting use_only_basis_molality=true is often a reasonable approximation, and it can help with convergence of geochemistry algorithms since it eliminates problems associated with unphysical huge equilibrium molalities that can occur during Newton-iteration to the equilibrium solution
use_only_Cl_molalityIf true, set the stoichiometric ionic strength to the Chlorine- molality. Note that this is the method used by the Geochemists Workbench

Definition at line 13 of file GeochemistryIonicStrength.C.

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 }
Real _max_ionic_strength
maximum ionic strength
Real _max_stoichiometric_ionic_strength
maximum stoichiometric ionic strength
bool _use_only_basis_molality
use only basis molality in the ionic strength calculations
bool _use_only_Cl_molality
set the stoichiometric ionic strength to the Cl- molality

Member Function Documentation

◆ getMaxIonicStrength()

Real GeochemistryIonicStrength::getMaxIonicStrength ( ) const

Return the value of maximum ionic strength.

Definition at line 129 of file GeochemistryIonicStrength.C.

130 {
131  return _max_ionic_strength;
132 }
Real _max_ionic_strength
maximum ionic strength

◆ getMaxStoichiometricIonicStrength()

Real GeochemistryIonicStrength::getMaxStoichiometricIonicStrength ( ) const

Return the value of maximum stoichiometric ionic strength.

Definition at line 141 of file GeochemistryIonicStrength.C.

142 {
144 }
Real _max_stoichiometric_ionic_strength
maximum stoichiometric ionic strength

◆ getUseOnlyBasisMolality()

Real GeochemistryIonicStrength::getUseOnlyBasisMolality ( ) const

Return the value of use_only_basis_molality.

Definition at line 153 of file GeochemistryIonicStrength.C.

Referenced by TEST().

154 {
156 }
bool _use_only_basis_molality
use only basis molality in the ionic strength calculations

◆ getUseOnlyClMolality()

Real GeochemistryIonicStrength::getUseOnlyClMolality ( ) const

Return the value of use_only_Cl_molality.

Definition at line 165 of file GeochemistryIonicStrength.C.

Referenced by TEST().

166 {
167  return _use_only_Cl_molality;
168 }
bool _use_only_Cl_molality
set the stoichiometric ionic strength to the Cl- molality

◆ ionicStrength()

Real GeochemistryIonicStrength::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.

Parameters
mgdthe Model Geochemical database
basis_species_molalityMolalities of the basis species in mgd
eqm_species_molalityMolalities of the equilibrium species in mgd
kin_species_molalityMolalities of the kinetic species
Returns
the ionic strength of the aqueous solution

Definition at line 25 of file GeochemistryIonicStrength.C.

Referenced by GeochemicalSystem::getIonicStrength(), GeochemistryActivityCoefficientsDebyeHuckel::setInternalParameters(), GeochemicalSystem::surfacePotPrefactor(), and TEST().

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 }
std::vector< bool > surface_sorption_related
surface_sorption_related[j] = true iff the j^th equilibrium species is involved in surface sorption ...
std::vector< Real > kin_species_charge
all kinetic quantities have a charge (mineral charge = 0)
Real _max_ionic_strength
maximum ionic strength
void mooseError(Args &&... args)
const ModelGeochemicalDatabase mgd
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< Real > basis_species_charge
all quantities have a charge (mineral charge = 0, gas charge = 0, oxide charge = 0) ...
bool _use_only_basis_molality
use only basis molality in the ionic strength calculations
std::vector< Real > eqm_species_charge
all quantities have a charge (mineral charge = 0, gas charge = 0, oxide charge = 0) ...

◆ operator==()

bool GeochemistryIonicStrength::operator== ( const GeochemistryIonicStrength rhs) const
inline

Definition at line 39 of file GeochemistryIonicStrength.h.

40  {
41  return (_max_ionic_strength == rhs._max_ionic_strength) &&
45  };
Real _max_ionic_strength
maximum ionic strength
Real _max_stoichiometric_ionic_strength
maximum stoichiometric ionic strength
bool _use_only_basis_molality
use only basis molality in the ionic strength calculations
bool _use_only_Cl_molality
set the stoichiometric ionic strength to the Cl- molality

◆ setMaxIonicStrength()

void GeochemistryIonicStrength::setMaxIonicStrength ( Real  max_ionic_strength)

Set the maximum ionic strength.

Definition at line 123 of file GeochemistryIonicStrength.C.

Referenced by GeochemicalSolver::solveSystem().

124 {
125  _max_ionic_strength = max_ionic_strength;
126 }
Real _max_ionic_strength
maximum ionic strength

◆ setMaxStoichiometricIonicStrength()

void GeochemistryIonicStrength::setMaxStoichiometricIonicStrength ( Real  max_stoichiometric_ionic_strength)

Set the maximum stoichiometric ionic strength.

Definition at line 135 of file GeochemistryIonicStrength.C.

Referenced by GeochemicalSolver::solveSystem().

136 {
137  _max_stoichiometric_ionic_strength = max_stoichiometric_ionic_strength;
138 }
Real _max_stoichiometric_ionic_strength
maximum stoichiometric ionic strength

◆ setUseOnlyBasisMolality()

void GeochemistryIonicStrength::setUseOnlyBasisMolality ( bool  use_only_basis_molality)

Set the value of use_only_basis_molality.

Definition at line 147 of file GeochemistryIonicStrength.C.

148 {
149  _use_only_basis_molality = use_only_basis_molality;
150 }
bool _use_only_basis_molality
use only basis molality in the ionic strength calculations

◆ setUseOnlyClMolality()

void GeochemistryIonicStrength::setUseOnlyClMolality ( bool  use_only_Cl_molality)

Set the value of use_only_Cl_molality.

Definition at line 159 of file GeochemistryIonicStrength.C.

160 {
161  _use_only_Cl_molality = use_only_Cl_molality;
162 }
bool _use_only_Cl_molality
set the stoichiometric ionic strength to the Cl- molality

◆ stoichiometricIonicStrength()

Real GeochemistryIonicStrength::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.

Parameters
mgdthe Model Geochemical database
basis_species_molalityMolalities of the basis species in mgd
eqm_species_molalityMolalities of the equilibrium species in mgd
kin_species_molalityMolalities of the kinetic species
Returns
the stoichiometric ionic strength of the aqueous solution

Definition at line 61 of file GeochemistryIonicStrength.C.

Referenced by GeochemicalSystem::getStoichiometricIonicStrength(), GeochemistryActivityCoefficientsDebyeHuckel::setInternalParameters(), and TEST().

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 }
std::vector< bool > surface_sorption_related
surface_sorption_related[j] = true iff the j^th equilibrium species is involved in surface sorption ...
std::vector< Real > kin_species_charge
all kinetic quantities have a charge (mineral charge = 0)
void mooseError(Args &&... args)
std::unordered_map< std::string, unsigned > basis_species_index
basis_species_index[name] = index of the basis species, within all ModelGeochemicalDatabase internal ...
const ModelGeochemicalDatabase mgd
std::unordered_map< std::string, unsigned > eqm_species_index
eqm_species_index[name] = index of the equilibrium species (secondary aqueous species, redox couples in equilibrium with the aqueous solution, minerals in equilibrium with the aqueous solution, gases in equilibrium with the aqueous solution) within all ModelGeochemicalDatabase internal datastrcutres, with given name
std::unordered_map< std::string, unsigned > kin_species_index
kin_species_index[name] = index of the kinetic species, within all ModelGeochemicalDatabase internal ...
DenseMatrix< Real > eqm_stoichiometry
eqm_stoichiometry(i, j) = stoichiometric coefficient for equilibrium species "i" in terms of the basi...
Real _max_stoichiometric_ionic_strength
maximum stoichiometric ionic strength
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< Real > basis_species_charge
all quantities have a charge (mineral charge = 0, gas charge = 0, oxide charge = 0) ...
bool _use_only_basis_molality
use only basis molality in the ionic strength calculations
std::vector< Real > eqm_species_charge
all quantities have a charge (mineral charge = 0, gas charge = 0, oxide charge = 0) ...
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
bool _use_only_Cl_molality
set the stoichiometric ionic strength to the Cl- molality

Member Data Documentation

◆ _max_ionic_strength

Real GeochemistryIonicStrength::_max_ionic_strength
private

maximum ionic strength

Definition at line 99 of file GeochemistryIonicStrength.h.

Referenced by getMaxIonicStrength(), ionicStrength(), operator==(), and setMaxIonicStrength().

◆ _max_stoichiometric_ionic_strength

Real GeochemistryIonicStrength::_max_stoichiometric_ionic_strength
private

maximum stoichiometric ionic strength

Definition at line 102 of file GeochemistryIonicStrength.h.

Referenced by getMaxStoichiometricIonicStrength(), operator==(), setMaxStoichiometricIonicStrength(), and stoichiometricIonicStrength().

◆ _use_only_basis_molality

bool GeochemistryIonicStrength::_use_only_basis_molality
private

use only basis molality in the ionic strength calculations

Definition at line 105 of file GeochemistryIonicStrength.h.

Referenced by getUseOnlyBasisMolality(), ionicStrength(), operator==(), setUseOnlyBasisMolality(), and stoichiometricIonicStrength().

◆ _use_only_Cl_molality

bool GeochemistryIonicStrength::_use_only_Cl_molality
private

set the stoichiometric ionic strength to the Cl- molality

Definition at line 108 of file GeochemistryIonicStrength.h.

Referenced by getUseOnlyClMolality(), operator==(), setUseOnlyClMolality(), and stoichiometricIonicStrength().


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