https://mooseframework.inl.gov
PertinentGeochemicalSystem.h
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 
10 #pragma once
11 
14 #include <unordered_map>
15 #include "DenseMatrix.h"
16 #include <libmesh/dense_vector.h>
17 
26 {
28 
29  bool operator==(const SurfaceComplexationInfo & rhs) const
30  {
32  };
33 
35  std::map<std::string, Real> sorption_sites;
36 };
37 
59 {
61  const std::vector<Real> & promoting_indices,
62  const std::vector<Real> & promoting_monod_indices,
63  const std::vector<Real> & promoting_half_saturation,
64  unsigned progeny_index,
72 
73  bool operator==(const KineticRateDefinition & rhs) const
74  {
80  };
81 
82  unsigned kinetic_species_index;
83  std::vector<Real> promoting_indices;
84  std::vector<Real> promoting_monod_indices;
85  std::vector<Real> promoting_half_saturation;
86  unsigned progeny_index;
88 };
89 
100 {
106  : original_database(&db), swap_to_original_basis(DenseMatrix<Real>()){};
107 
108  bool operator==(const ModelGeochemicalDatabase & rhs) const
109  {
110  return (original_database == rhs.original_database) &&
123  (eqm_species_gas == rhs.eqm_species_gas) &&
135  (redox_log10K == rhs.redox_log10K) &&
137  (gas_chi == rhs.gas_chi) && (kin_species_index == rhs.kin_species_index) &&
145  (kin_rate == rhs.kin_rate) &&
149  };
150 
153 
158  std::unordered_map<std::string, unsigned> basis_species_index;
159 
161  std::vector<std::string> basis_species_name;
162 
164  std::vector<bool> basis_species_mineral;
165 
167  std::vector<bool> basis_species_gas;
168 
170  std::vector<bool> basis_species_transported;
171 
173  std::vector<Real> basis_species_charge;
174 
176  std::vector<Real> basis_species_radius;
177 
180 
183 
190  std::unordered_map<std::string, unsigned> eqm_species_index;
191 
193  std::vector<std::string> eqm_species_name;
194 
196  std::vector<bool> eqm_species_mineral;
197 
199  std::vector<bool> eqm_species_gas;
200 
202  std::vector<bool> eqm_species_transported;
203 
205  std::vector<Real> eqm_species_charge;
206 
208  std::vector<Real> eqm_species_radius;
209 
211  std::vector<Real> eqm_species_molecular_weight;
212 
214  std::vector<Real> eqm_species_molecular_volume;
215 
221 
227 
232  std::vector<std::string> surface_sorption_name;
233 
239  std::vector<Real> surface_sorption_area;
240 
242  std::vector<bool> surface_sorption_related;
243 
251  std::vector<unsigned> surface_sorption_number;
252 
257  std::string redox_lhs;
258 
273 
279 
285  std::unordered_map<std::string, SurfaceComplexationInfo> surface_complexation_info;
286 
294  std::unordered_map<std::string, std::vector<Real>> gas_chi;
295 
300  std::unordered_map<std::string, unsigned> kin_species_index;
301 
303  std::vector<std::string> kin_species_name;
304 
306  std::vector<bool> kin_species_mineral;
307 
309  std::vector<bool> kin_species_transported;
310 
312  std::vector<Real> kin_species_charge;
313 
315  std::vector<Real> kin_species_molecular_weight;
316 
318  std::vector<Real> kin_species_molecular_volume;
319 
325 
331 
337  std::vector<KineticRateDefinition> kin_rate;
338 
344  std::vector<unsigned> have_swapped_out_of_basis;
345 
351  std::vector<unsigned> have_swapped_into_basis;
352 
368 };
369 
383 {
384 public:
451  const std::vector<std::string> & basis_species,
452  const std::vector<std::string> & minerals,
453  const std::vector<std::string> & gases,
454  const std::vector<std::string> & kinetic_minerals,
455  const std::vector<std::string> & kinetic_redox,
456  const std::vector<std::string> & kinetic_surface_species,
457  const std::string & redox_ox,
458  const std::string & redox_e);
459 
462 
468  void addKineticRate(const KineticRateUserDescription & description);
469 
474  unsigned getIndexOfOriginalBasisSpecies(const std::string & name) const;
475 
479  std::vector<std::string> originalBasisNames() const;
480 
481 private:
484 
486  std::unordered_map<std::string, unsigned> _basis_index;
487 
489  std::vector<GeochemistryBasisSpecies> _basis_info;
490 
492  std::unordered_map<std::string, unsigned> _mineral_index;
493 
495  std::vector<GeochemistryMineralSpecies> _mineral_info;
496 
498  std::unordered_map<std::string, unsigned> _gas_index;
499 
501  std::vector<GeochemistryGasSpecies> _gas_info;
502 
504  std::unordered_map<std::string, unsigned> _kinetic_mineral_index;
505 
507  std::vector<GeochemistryMineralSpecies> _kinetic_mineral_info;
508 
510  std::unordered_map<std::string, unsigned> _kinetic_redox_index;
511 
513  std::vector<GeochemistryRedoxSpecies> _kinetic_redox_info;
514 
516  std::unordered_map<std::string, unsigned> _kinetic_surface_index;
517 
519  std::vector<GeochemistrySurfaceSpecies> _kinetic_surface_info;
520 
522  std::unordered_map<std::string, unsigned> _secondary_index;
523 
525  std::vector<GeochemistryEquilibriumSpecies> _secondary_info;
526 
531  const std::string _redox_ox;
532 
534  const std::string _redox_e;
535 
538 
542  void buildBasis(const std::vector<std::string> & basis_species);
543 
548  void buildMinerals(const std::vector<std::string> & minerals);
549 
559  void buildAllMinerals(const std::vector<std::string> & minerals);
560 
564  void buildGases(const std::vector<std::string> & gases);
565 
570  void buildKineticMinerals(const std::vector<std::string> & kinetic_minerals);
571 
576  void buildKineticRedox(const std::vector<std::string> & kinetic_redox);
577 
582  void buildKineticSurface(const std::vector<std::string> & kinetic_surface);
583 
589  void buildSecondarySpecies();
590 
595  bool checkRedoxe();
596 
602  void checkMinerals(const std::vector<GeochemistryMineralSpecies> & mineral_info) const;
603 
608  void checkGases() const;
609 
614  void checkKineticRedox() const;
615 
620  void checkKineticSurfaceSpecies() const;
621 
625  void createModel();
626 
633  void buildRedoxeInfo(std::vector<Real> & redox_e_stoichiometry,
634  std::vector<Real> & redox_e_log10K);
635 };
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 > surface_sorption_area
surface_sorption_area[k] = specific surface area [m^2/g] for the k^th mineral involved in surface sor...
DenseMatrix< Real > redox_stoichiometry
redox_stoichiometry(i, j) = stoichiometric coefficients for i^th redox species that is in disequilibr...
std::vector< Real > eqm_species_molecular_weight
all quantities have a molecular weight (g)
std::string redox_lhs
the name of the species on the left-hand side of the redox equations.
ModelGeochemicalDatabase(const GeochemicalDatabaseReader &db)
Constructor sets original_database.
void buildGases(const std::vector< std::string > &gases)
using the gas list, this method builds _gas_index and _gas_info
std::vector< bool > kin_species_mineral
kin_species_mineral[j] = true iff the j^th kinetic species is a mineral
A single rate expression for the kinetic species with index kinetic_species_index.
std::vector< bool > basis_species_transported
basis_species_transported[j] = true iff the j^th basis species is transported in reactive-transport s...
unsigned getIndexOfOriginalBasisSpecies(const std::string &name) const
std::vector< Real > kin_species_charge
all kinetic quantities have a charge (mineral charge = 0)
std::vector< std::string > surface_sorption_name
surface_sorption_name[k] = name of the mineral involved in surface sorption.
bool operator==(const ModelGeochemicalDatabase &rhs) const
void buildKineticMinerals(const std::vector< std::string > &kinetic_minerals)
using the kinetic_minerals list, this method builds _kinetic_mineral_index and _kinetic_mineral_info ...
void buildKineticRedox(const std::vector< std::string > &kinetic_redox)
using the kinetic_redox list, this method builds _kinetic_redox_index and _kinetic_redox_info ...
std::vector< bool > eqm_species_gas
eqm_species_gas[i] = true iff the i^th equilibrium species is a gas
std::unordered_map< std::string, unsigned > _basis_index
given a species name, return its index in the corresponding "info" std::vector
std::vector< GeochemistryBasisSpecies > _basis_info
a vector of all relevant species
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 > _mineral_index
given a species name, return its index in the corresponding "info" std::vector
void createModel()
Fully populate the ModelGeochemicalDatabase.
DenseMatrix< Real > kin_stoichiometry
kin_stoichiometry(i, j) = stoichiometric coefficient for kinetic species "i" in terms of the basis sp...
std::vector< Real > kin_species_molecular_weight
all quantities have a molecular weight (g/mol)
void buildAllMinerals(const std::vector< std::string > &minerals)
If minerals = {"*"} then populate _mineral_index and _mineral_info with all relevant minerals This is...
std::vector< Real > kin_species_molecular_volume
all quantities have a molecular volume (cm^3/mol) (only nonzero for minerals, however) ...
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 checkKineticSurfaceSpecies() const
Check that all kinetic surface species in the _kinetic_surface_species list have reactions that invol...
DenseMatrix< Real > redox_log10K
redox_log10K(i, j) = log10(equilibrium constant) for i^th redox species at the j^th temperature point...
std::vector< GeochemistryMineralSpecies > _mineral_info
a vector of all relevant species
std::vector< GeochemistrySurfaceSpecies > _kinetic_surface_info
a vector of all relevant species
ModelGeochemicalDatabase _model
The important datastructure built by this class.
DenseMatrix< Real > swap_to_original_basis
Swap matrix that allows expression in terms of the original basis.
std::unordered_map< std::string, unsigned > kin_species_index
kin_species_index[name] = index of the kinetic species, within all ModelGeochemicalDatabase internal ...
void checkGases() const
Check that all gases in the "gases" list have reactions that involve only the basis_species or second...
void buildBasis(const std::vector< std::string > &basis_species)
using the basis_species list, this method builds _basis_index and _basis_info
DenseMatrix< Real > eqm_stoichiometry
eqm_stoichiometry(i, j) = stoichiometric coefficient for equilibrium species "i" in terms of the basi...
bool operator==(const KineticRateDefinition &rhs) const
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)
void buildRedoxeInfo(std::vector< Real > &redox_e_stoichiometry, std::vector< Real > &redox_e_log10K)
Extract the stoichiometry and log10K for the _redox_e species.
PertinentGeochemicalSystem(const GeochemicalDatabaseReader &db, const std::vector< std::string > &basis_species, const std::vector< std::string > &minerals, const std::vector< std::string > &gases, const std::vector< std::string > &kinetic_minerals, const std::vector< std::string > &kinetic_redox, const std::vector< std::string > &kinetic_surface_species, const std::string &redox_ox, const std::string &redox_e)
std::vector< unsigned > surface_sorption_number
surface_sorption_number[j] = the index of the surface potential that should be used to modify the equ...
const ModelGeochemicalDatabase & modelGeochemicalDatabase() const
Return a reference to the ModelGeochemicalDatabase structure.
void checkKineticRedox() const
Check that all kinetic redox species in the _kinetic_redox list have reactions that involve only the ...
KineticRateDefinition(unsigned kinetic_species_index, const std::vector< Real > &promoting_indices, const std::vector< Real > &promoting_monod_indices, const std::vector< Real > &promoting_half_saturation, unsigned progeny_index, const KineticRateUserDescription &description)
void addKineticRate(const KineticRateUserDescription &description)
Adds a rate description for kinetic_species.
std::unordered_map< std::string, unsigned > _kinetic_redox_index
given a species name, return its index in the corresponding "info" std::vector
const std::string name
Definition: Setup.h:20
void buildSecondarySpecies()
Extract all relevant "redox couples" and "secondary species" and "surface species" from the database...
std::map< std::string, Real > sorption_sites
Constructs and stores a minimal amount of information that is pertinent to the user-defined geochemic...
std::vector< Real > promoting_monod_indices
std::unordered_map< std::string, unsigned > _secondary_index
given a species name, return its index in the corresponding "info" std::vector
std::unordered_map< std::string, unsigned > _kinetic_surface_index
given a species name, return its index in the corresponding "info" std::vector
std::vector< GeochemistryMineralSpecies > _kinetic_mineral_info
a vector of all relevant species
std::unordered_map< std::string, std::vector< Real > > gas_chi
Holds info on gas fugacity "chi" parameters.
DenseMatrix< Real > kin_log10K
kin_log10K(i, j) = log10(equilibrium constant for the i^th kinetic species at the j^th temperature po...
std::vector< bool > kin_species_transported
kin_species_transported[j] = true iff the j^th kinetic species is transported in reactive-transport s...
std::vector< Real > eqm_species_radius
all quantities have an ionic radius (Angstrom) for computing activity (mineral radius = 0...
void buildKineticSurface(const std::vector< std::string > &kinetic_surface)
using the kinetic_surface list, this method builds _kinetic_surface_index and _kinetic_surface_info ...
DenseMatrix< Real > eqm_log10K
eqm_log10K(i, j) = log10(equilibrium constant) for i^th equilibrium species at the j^th temperature p...
std::vector< GeochemistryRedoxSpecies > _kinetic_redox_info
a vector of all relevant species
void checkMinerals(const std::vector< GeochemistryMineralSpecies > &mineral_info) const
Check that all minerals in mineral_info have reactions that involve only the basis_species or seconda...
std::vector< Real > basis_species_molecular_weight
all quantities have a molecular weight (g)
std::vector< Real > promoting_indices
std::vector< GeochemistryGasSpecies > _gas_info
a vector of all relevant species
const GeochemicalDatabaseReader * original_database
a pointer to the original database used to build this ModelGeochemicalDatabase
Data structure designed to hold information related to sorption via surface complexation.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< bool > eqm_species_transported
eqm_species_transported[i] = true iff the i^th eqm species is transported in reactive-transport sims ...
std::vector< Real > promoting_half_saturation
std::vector< Real > eqm_species_molecular_volume
all quantities have a molecular volume (cm^3) (only nonzero for minerals, however) ...
std::vector< std::string > originalBasisNames() const
std::vector< Real > basis_species_charge
all quantities have a charge (mineral charge = 0, gas charge = 0, oxide charge = 0) ...
Holds a user-specified description of a kinetic rate.
GeochemicalDatabaseReader _db
The database.
std::vector< unsigned > have_swapped_into_basis
Species that have been swapped into the basis.
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
bool operator==(const SurfaceComplexationInfo &rhs) const
std::vector< Real > eqm_species_charge
all quantities have a charge (mineral charge = 0, gas charge = 0, oxide charge = 0) ...
std::vector< std::string > kin_species_name
kin_species_name[j] = name of the j^th kinetic species
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
std::vector< Real > basis_species_molecular_volume
all quantities have a molecular volume (cm^3) (only nonzero for minerals, however) ...
std::vector< GeochemistryEquilibriumSpecies > _secondary_info
a vector of all relevant species
const std::string _redox_e
The name of the free electron involved in redox reactions.
std::unordered_map< std::string, unsigned > _gas_index
given a species name, return its index in the corresponding "info" std::vector
const std::string _redox_ox
The name of the oxygen in all disequilibrium-redox equations, eg O2(aq), which must be a basis specie...
std::unordered_map< std::string, SurfaceComplexationInfo > surface_complexation_info
Holds info on surface complexation, if any, in the model.
std::unordered_map< std::string, unsigned > _kinetic_mineral_index
given a species name, return its index in the corresponding "info" std::vector
std::vector< std::string > eqm_species_name
eqm_species_name[i] = name of the i^th eqm species
void buildMinerals(const std::vector< std::string > &minerals)
using the minerals list, this method builds _mineral_index and _mineral_info, unless minerals = {"*"}...
std::vector< std::string > basis_species_name
basis_species_name[j] = name of the j^th basis species
KineticRateUserDescription description
Class for reading geochemical reactions from a MOOSE geochemical database.
std::vector< unsigned > have_swapped_out_of_basis
Species that have been swapped out of the basis.
std::vector< KineticRateDefinition > kin_rate
rates given to kinetic species.