https://mooseframework.inl.gov
GeochemistryActivityCoefficientsDebyeHuckel.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 
12 
14  const GeochemistryIonicStrength & is_calculator, const GeochemicalDatabaseReader & db)
16  _numT(db.getTemperatures().size()),
17  _database_dh_params(db.getDebyeHuckel()),
18  _database_dh_water((db.getNeutralSpeciesActivity().count("h2o") == 1)
19  ? db.getNeutralSpeciesActivity().at("h2o")
21  _database_dh_neutral((db.getNeutralSpeciesActivity().count("co2") == 1)
22  ? db.getNeutralSpeciesActivity().at("co2")
24  _is_calculator(is_calculator),
25  _ionic_strength(1.0),
26  _sqrt_ionic_strength(1.0),
27  _stoichiometric_ionic_strength(1.0),
28  _num_basis(0),
29  _num_eqm(0),
30  _dh(),
31  _interp_A(db.getTemperatures(),
32  (_database_dh_params.adh.size() == _numT) ? _database_dh_params.adh
33  : std::vector<Real>(_numT, 0.0),
34  db.getLogKModel()),
35  _interp_B(db.getTemperatures(),
36  (_database_dh_params.bdh.size() == _numT) ? _database_dh_params.bdh
37  : std::vector<Real>(_numT, 0.0),
38  db.getLogKModel()),
39  _interp_Bdot(db.getTemperatures(),
40  (_database_dh_params.bdot.size() == _numT) ? _database_dh_params.bdot
41  : std::vector<Real>(_numT, 0.0),
42  db.getLogKModel()),
43  _interp_a_water(db.getTemperatures(),
44  (_database_dh_water.a.size() == _numT) ? _database_dh_water.a
45  : std::vector<Real>(_numT, 0.0),
46  db.getLogKModel()),
47  _interp_b_water(db.getTemperatures(),
48  (_database_dh_water.b.size() == _numT) ? _database_dh_water.b
49  : std::vector<Real>(_numT, 0.0),
50  db.getLogKModel()),
51  _interp_c_water(db.getTemperatures(),
52  (_database_dh_water.c.size() == _numT) ? _database_dh_water.c
53  : std::vector<Real>(_numT, 0.0),
54  db.getLogKModel()),
55  _interp_d_water(db.getTemperatures(),
56  (_database_dh_water.d.size() == _numT) ? _database_dh_water.d
57  : std::vector<Real>(_numT, 0.0),
58  db.getLogKModel()),
59  _interp_a_neutral(db.getTemperatures(),
60  (_database_dh_neutral.a.size() == _numT) ? _database_dh_neutral.a
61  : std::vector<Real>(_numT, 0.0),
62  db.getLogKModel()),
63  _interp_b_neutral(db.getTemperatures(),
64  (_database_dh_neutral.b.size() == _numT) ? _database_dh_neutral.b
65  : std::vector<Real>(_numT, 0.0),
66  db.getLogKModel()),
67  _interp_c_neutral(db.getTemperatures(),
68  (_database_dh_neutral.c.size() == _numT) ? _database_dh_neutral.c
69  : std::vector<Real>(_numT, 0.0),
70  db.getLogKModel()),
71  _interp_d_neutral(db.getTemperatures(),
72  (_database_dh_neutral.d.size() == _numT) ? _database_dh_neutral.d
73  : std::vector<Real>(_numT, 0.0),
74  db.getLogKModel())
75 {
87 }
88 
89 void
91  Real temperature,
93  const std::vector<Real> & basis_species_molality,
94  const std::vector<Real> & eqm_species_molality,
95  const std::vector<Real> & kin_species_molality)
96 {
98  mgd, basis_species_molality, eqm_species_molality, kin_species_molality);
101  mgd, basis_species_molality, eqm_species_molality, kin_species_molality);
103  _num_eqm = mgd.eqm_species_index.size();
104  // Debye-Huckel base parameters
108  // water Debye-Huckel
113  // neutral species Debye-Huckel
118 }
119 
120 const DebyeHuckelParameters &
122 {
123  return _dh;
124 }
125 
126 Real
128 {
131 }
132 
133 void
136  std::vector<Real> & basis_activity_coef,
137  std::vector<Real> & eqm_activity_coef) const
138 {
139  basis_activity_coef.resize(_num_basis);
140  eqm_activity_coef.resize(_num_eqm);
141 
142  for (unsigned basis_i = 1; basis_i < _num_basis; ++basis_i) // don't loop over water
143  if (mgd.basis_species_mineral[basis_i] || mgd.basis_species_gas[basis_i])
144  continue; // these should never be used
145  else if (mgd.basis_species_radius[basis_i] == -0.5)
146  {
147  basis_activity_coef[basis_i] = std::pow(
148  10.0,
151  }
152  else if (mgd.basis_species_radius[basis_i] == -1.0)
153  {
154  basis_activity_coef[basis_i] =
155  std::pow(10.0,
157  _dh.Bdot));
158  }
159  else if (mgd.basis_species_radius[basis_i] == -1.5)
160  {
161  basis_activity_coef[basis_i] = 1.0;
162  }
163  else if (mgd.basis_species_charge[basis_i] == 0.0)
164  {
165  basis_activity_coef[basis_i] = 1.0;
166  }
167  else
168  {
169  basis_activity_coef[basis_i] = std::pow(
170  10.0,
172  mgd.basis_species_radius[basis_i],
174  _dh.A,
175  _dh.B,
176  _dh.Bdot));
177  }
178 
179  for (unsigned eqm_j = 0; eqm_j < _num_eqm; ++eqm_j)
180  if (mgd.eqm_species_mineral[eqm_j] || mgd.eqm_species_gas[eqm_j])
181  continue;
182  else if (mgd.eqm_species_radius[eqm_j] == -0.5)
183  {
184  eqm_activity_coef[eqm_j] = std::pow(
185  10.0,
188  }
189  else if (mgd.eqm_species_radius[eqm_j] == -1.0)
190  {
191  eqm_activity_coef[eqm_j] =
192  std::pow(10.0,
194  _dh.Bdot));
195  }
196  else if (mgd.eqm_species_radius[eqm_j] == -1.5)
197  {
198  eqm_activity_coef[eqm_j] = 1.0;
199  }
200  else if (mgd.eqm_species_charge[eqm_j] == 0.0)
201  {
202  eqm_activity_coef[eqm_j] = 1.0;
203  }
204  else
205  {
206  eqm_activity_coef[eqm_j] = std::pow(
207  10.0,
209  mgd.eqm_species_radius[eqm_j],
211  _dh.A,
212  _dh.B,
213  _dh.Bdot));
214  }
215 }
216 
217 Real
219 {
220  return _ionic_strength;
221 }
222 
223 Real
225 {
227 }
GeochemistryActivityCoefficientsDebyeHuckel(const GeochemistryIonicStrength &is_calculator, const GeochemicalDatabaseReader &db)
Real log10ActCoeffDHBdotNeutral(Real ionic_strength, Real a, Real b, Real c, Real d)
log10(activity coefficient) for neutral species according to the Debye-Huckel B-dot model ...
std::vector< bool > eqm_species_gas
eqm_species_gas[i] = true iff the i^th equilibrium species is a gas
Real _stoichiometric_ionic_strength
current value of stoichiometric ionic strength
Real getIonicStrength() const
Return the current value of ionic strength.
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
EquilibriumConstantInterpolator _interp_c_water
Interpolator object for the Debye-Huckel parameter c_water.
EquilibriumConstantInterpolator _interp_d_neutral
Interpolator object for the Debye-Huckel parameter d_neutral.
const GeochemistryIonicStrength & _is_calculator
ionic-strength calculator
Real getStoichiometricIonicStrength() const
Return the current value of stoichiometric ionic strength.
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
void buildActivityCoefficients(const ModelGeochemicalDatabase &mgd, std::vector< Real > &basis_activity_coef, std::vector< Real > &eqm_activity_coef) const override
Compute the activity coefficients and store them in basis_activity_coef and eqm_activity_coef Note: ...
static const std::string temperature
Definition: NS.h:59
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 waterActivity() const override
Computes and returns the activity of water.
Real log10ActCoeffDHBdotAlternative(Real ionic_strength, Real Bdot)
log10(activity coefficient) alternative expression that is sometimes used in conjunction with the Deb...
EquilibriumConstantInterpolator _interp_a_water
Interpolator object for the Debye-Huckel parameter a_water.
std::vector< Real > basis_species_radius
all quantities have an ionic radius (Angstrom) for computing activity (mineral radius = 0...
const GeochemicalDatabaseReader db("database/moose_testdb.json", true, true, false)
EquilibriumConstantInterpolator _interp_B
Interpolator object for the Debye-Huckel parameter B.
EquilibriumConstantInterpolator _interp_Bdot
Interpolator object for the Debye-Huckel parameter Bdot.
EquilibriumConstantInterpolator _interp_b_water
Interpolator object for the Debye-Huckel parameter b_water.
Data structure for neutral species activity coefficients.
EquilibriumConstantInterpolator _interp_b_neutral
Interpolator object for the Debye-Huckel parameter b_neutral.
virtual void generate()
Calculators to compute ionic strength and stoichiometric ionic strength.
Base class to compute activity coefficients for non-minerals and non-gases (since these species do no...
std::vector< Real > eqm_species_radius
all quantities have an ionic radius (Angstrom) for computing activity (mineral radius = 0...
EquilibriumConstantInterpolator _interp_c_neutral
Interpolator object for the Debye-Huckel parameter c_neutral.
Real lnActivityDHBdotWater(Real stoichiometric_ionic_strength, Real A, Real atilde, Real btilde, Real ctilde, Real dtilde)
ln(activity of water) according to the Debye-Huckel B-dot model
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) ...
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.
EquilibriumConstantInterpolator _interp_d_water
Interpolator object for the Debye-Huckel parameter d_water.
std::vector< bool > basis_species_gas
basis_species_gas[j] = true iff the j^th basis species is a gas
std::vector< bool > basis_species_mineral
basis_species_mineral[j] = true iff the j^th basis species is a mineral
std::vector< Real > eqm_species_charge
all quantities have a charge (mineral charge = 0, gas charge = 0, oxide charge = 0) ...
Data structure to hold all relevant information from the database file.
std::vector< bool > eqm_species_mineral
eqm_species_mineral[i] = true iff the i^th equilibrium species is a mineral
EquilibriumConstantInterpolator _interp_A
Interpolator object for the Debye-Huckel parameter A.
Real log10ActCoeffDHBdot(Real charge, Real ion_size, Real sqrt_ionic_strength, Real A, Real B, Real Bdot)
log10(activity coefficient) according to the Debye-Huckel B-dot model
MooseUnits pow(const MooseUnits &, int)
void setInternalParameters(Real temperature, const ModelGeochemicalDatabase &mgd, const std::vector< Real > &basis_species_molality, const std::vector< Real > &eqm_species_molality, const std::vector< Real > &kin_species_molality) override
Sets internal parameters, such as the ionic strength and Debye-Huckel parameters, prior to computing ...
Class for reading geochemical reactions from a MOOSE geochemical database.
EquilibriumConstantInterpolator _interp_a_neutral
Interpolator object for the Debye-Huckel parameter a_neutral.