https://mooseframework.inl.gov
GeochemicalDatabaseReader.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 
12 #include "nlohmann/json.h"
13 #include "MooseTypes.h"
14 
25 {
27 
28  std::string name;
29  std::map<std::string, Real> elements;
33 };
34 
46 {
48 
49  std::string name;
50  std::map<std::string, Real> basis_species;
51  std::vector<Real> equilibrium_const;
55 };
56 
69 {
71 
72  std::string name;
74  std::map<std::string, Real> basis_species;
75  std::vector<Real> equilibrium_const;
78  std::map<std::string, Real> sorption_sites;
79 };
80 
92 {
94 
95  std::string name;
96  std::map<std::string, Real> basis_species;
97  std::vector<Real> equilibrium_const;
99  std::vector<Real> chi;
103 };
104 
116 {
118 
119  std::string name;
120  std::map<std::string, Real> basis_species;
121  std::vector<Real> equilibrium_const;
125 };
126 
135 {
137 
138  std::string name;
139  std::map<std::string, Real> basis_species;
141 };
142 
152 {
154 
155  std::string name;
156  std::map<std::string, Real> basis_species;
161 };
162 
171 {
173 
174  std::vector<Real> adh;
175  std::vector<Real> bdh;
176  std::vector<Real> bdot;
177 };
178 
186 {
188 
189  std::string name;
191 };
192 
199 {
201  GeochemistryNeutralSpeciesActivity(std::vector<std::vector<Real>> coeffs)
202  : a(coeffs[0]), b(coeffs[1]), c(coeffs[2]), d(coeffs[3]){};
203 
204  std::vector<Real> a;
205  std::vector<Real> b;
206  std::vector<Real> c;
207  std::vector<Real> d;
208 };
209 
214 {
215 public:
228  GeochemicalDatabaseReader(const FileName filename,
229  const bool reexpress_free_electron = true,
230  const bool use_piecewise_interpolation = false,
231  const bool remove_all_extrapolated_secondary_species = false);
232 
237  void read(const FileName filename);
238 
244  void validate(const FileName filename, const nlohmann::json & db);
245 
251  void reexpressFreeElectron();
252 
257  std::string getActivityModel() const;
258 
263  std::string getFugacityModel() const;
264 
269  std::string getLogKModel() const;
270 
275  std::vector<std::string> getBasisSpeciesNames() const { return _bs_names; };
276 
281  std::vector<std::string> getEquilibriumSpeciesNames() const { return _es_names; };
282 
287  std::vector<std::string> getMineralSpeciesNames() const { return _ms_names; };
288 
293  const std::vector<Real> & getTemperatures() const;
294 
299  std::vector<Real> getPressures();
300 
305  const GeochemistryDebyeHuckel & getDebyeHuckel() const;
306 
312  std::map<std::string, GeochemistryBasisSpecies>
313  getBasisSpecies(const std::vector<std::string> & names);
314 
320  std::map<std::string, GeochemistryEquilibriumSpecies>
321  getEquilibriumSpecies(const std::vector<std::string> & names);
322 
328  std::map<std::string, GeochemistryMineralSpecies>
329  getMineralSpecies(const std::vector<std::string> & names);
330 
335  std::map<std::string, GeochemistryElements> getElements();
336 
342  std::map<std::string, GeochemistryGasSpecies>
343  getGasSpecies(const std::vector<std::string> & names);
344 
350  std::map<std::string, GeochemistryRedoxSpecies>
351  getRedoxSpecies(const std::vector<std::string> & names);
352 
358  std::map<std::string, GeochemistryOxideSpecies>
359  getOxideSpecies(const std::vector<std::string> & names);
360 
366  std::map<std::string, GeochemistrySurfaceSpecies>
367  getSurfaceSpecies(const std::vector<std::string> & names);
368 
373  const std::map<std::string, GeochemistryNeutralSpeciesActivity> &
375 
382  std::vector<std::string> equilibriumReactions(const std::vector<std::string> & names) const;
383 
389  std::vector<std::string> mineralReactions(const std::vector<std::string> & names) const;
390 
396  std::vector<std::string> gasReactions(const std::vector<std::string> & names) const;
397 
403  std::vector<std::string> redoxReactions(const std::vector<std::string> & names) const;
404 
410  std::vector<std::string> oxideReactions(const std::vector<std::string> & names) const;
411 
417  std::string getSpeciesData(const std::string name) const;
418 
423  const FileName & filename() const;
424 
426  bool isSecondarySpecies(const std::string & name) const;
427 
433  bool isBasisSpecies(const std::string & name) const;
434  bool isRedoxSpecies(const std::string & name) const;
435  bool isGasSpecies(const std::string & name) const;
436  bool isMineralSpecies(const std::string & name) const;
437  bool isOxideSpecies(const std::string & name) const;
438  bool isSurfaceSpecies(const std::string & name) const;
439 
441  bool isSorbingMineral(const std::string & name) const;
442 
444  std::vector<std::string> mineralSpeciesNames() const;
445 
447  std::vector<std::string> secondarySpeciesNames() const;
448 
450  std::vector<std::string> redoxCoupleNames() const;
451 
453  std::vector<std::string> surfaceSpeciesNames() const;
454 
455 protected:
462 
467  void setTemperatures();
468 
473  void setDebyeHuckel();
474 
480 
482  const FileName _filename;
484  nlohmann::json _root;
486  std::vector<std::string> _bs_names;
488  std::vector<std::string> _es_names;
490  std::vector<std::string> _ms_names;
492  std::vector<Real> _temperature_points;
494  std::vector<Real> _pressure_points;
496  std::map<std::string, GeochemistryElements> _elements;
498  std::map<std::string, GeochemistryBasisSpecies> _basis_species;
500  std::map<std::string, GeochemistryEquilibriumSpecies> _equilibrium_species;
502  std::map<std::string, GeochemistryMineralSpecies> _mineral_species;
504  std::map<std::string, GeochemistryGasSpecies> _gas_species;
506  std::map<std::string, GeochemistryRedoxSpecies> _redox_species;
508  std::map<std::string, GeochemistryOxideSpecies> _oxide_species;
510  std::map<std::string, GeochemistrySurfaceSpecies> _surface_species;
514  std::map<std::string, GeochemistryNeutralSpeciesActivity> _neutral_species_activity;
515  // Helper for converting json node to Real from string
516  static Real getReal(const nlohmann::json & node);
517 
518 private:
526  std::vector<std::string>
527  printReactions(const std::vector<std::string> & names,
528  const std::vector<std::map<std::string, Real>> & basis_species) const;
529 };
std::map< std::string, GeochemistrySurfaceSpecies > getSurfaceSpecies(const std::vector< std::string > &names)
Get the surface sorbing species information.
std::map< std::string, GeochemistryEquilibriumSpecies > getEquilibriumSpecies(const std::vector< std::string > &names)
Get the secondary equilibrium species information.
std::vector< Real > getPressures()
Get the pressure points that the equilibrium constant is defined at.
std::string getActivityModel() const
Get the activity model type.
Data structure for elements.
Data structure for basis (primary) species.
std::map< std::string, Real > basis_species
const GeochemistryDebyeHuckel & getDebyeHuckel() const
Get the Debye-Huckel activity coefficients.
std::vector< std::string > _es_names
List of secondary equilibrium species to read from database.
Data structure for mineral species.
std::vector< std::string > redoxCoupleNames() const
Returns a list of all the names of the "redox couples" in the database.
std::map< std::string, GeochemistryMineralSpecies > getMineralSpecies(const std::vector< std::string > &names)
Get the mineral species information.
std::map< std::string, GeochemistryGasSpecies > getGasSpecies(const std::vector< std::string > &names)
Get the gas species information.
void validate(const FileName filename, const nlohmann::json &db)
Validate the thermodynamic database.
std::vector< std::string > getBasisSpeciesNames() const
Get the list of basis (primary) species read from database.
std::vector< std::string > getMineralSpeciesNames() const
Get the list of secondary mineral species read from database.
std::map< std::string, GeochemistryRedoxSpecies > _redox_species
Redox species (couples) data read from the database.
Data structure for redox species.
Data structure for oxide species.
std::vector< std::string > redoxReactions(const std::vector< std::string > &names) const
Generates a formatted vector of strings representing all redox reactions.
const FileName & filename() const
Filename of database.
std::string getLogKModel() const
Get the equilibrium constant model type.
nlohmann::json _root
JSON data.
Data structure for sorbing surface species.
std::string getFugacityModel() const
Get the fugacity model type.
std::map< std::string, GeochemistryGasSpecies > _gas_species
Gas species data read from the database.
std::map< std::string, Real > basis_species
std::string getSpeciesData(const std::string name) const
String representation of JSON species object contents.
bool isSorbingMineral(const std::string &name) const
returns True iff name is the name of a sorbing mineral
std::map< std::string, GeochemistryNeutralSpeciesActivity > _neutral_species_activity
Neutral species activity coefficients.
std::vector< std::string > mineralSpeciesNames() const
Returns a list of all the names of the "mineral species" in the database.
Data structure for Debye-Huckel activity coefficients.
const FileName _filename
Database filename.
bool isOxideSpecies(const std::string &name) const
std::vector< std::string > _bs_names
List of basis (primary) species names read from database.
const std::vector< Real > & getTemperatures() const
Get the temperature points that the equilibrium constant is defined at.
GeochemistryDebyeHuckel _debye_huckel
Debye-Huckel activity coefficients.
std::vector< std::string > surfaceSpeciesNames() const
Returns a list of all the names of the "surface species" in the database.
Data structure for mineral species.
const GeochemicalDatabaseReader db("database/moose_testdb.json", true, true, false)
std::map< std::string, GeochemistryMineralSpecies > _mineral_species
Mineral species data read from the database.
std::map< std::string, Real > basis_species
void removeExtrapolatedSecondarySpecies()
After parsing the database file, remove any secondary species that have extrapolated equilibrium cons...
GeochemistryNeutralSpeciesActivity(std::vector< std::vector< Real >> coeffs)
GeochemicalDatabaseReader(const FileName filename, const bool reexpress_free_electron=true, const bool use_piecewise_interpolation=false, const bool remove_all_extrapolated_secondary_species=false)
Parse the file.
const std::string name
Definition: Setup.h:20
Data structure for neutral species activity coefficients.
std::map< std::string, GeochemistryBasisSpecies > getBasisSpecies(const std::vector< std::string > &names)
Get the basis (primary) species information.
void setDebyeHuckel()
Copy the Debye-Huckel parameters (if any) found in the database into _debye_huckel.
std::map< std::string, GeochemistryOxideSpecies > _oxide_species
Oxide species data read from the database.
void read(const FileName filename)
Parse the thermodynamic database.
bool isGasSpecies(const std::string &name) const
static Real getReal(const nlohmann::json &node)
void setTemperatures()
Copy the temperature points (if any) found in the database into _temperature_points.
void reexpressFreeElectron()
Sometimes the free electron&#39;s equilibrium reaction is defined in terms of O2(g) which is not a basis ...
std::vector< Real > _temperature_points
Temperature points in database.
std::map< std::string, GeochemistryElements > getElements()
Get all the elements.
std::map< std::string, Real > basis_species
std::vector< std::string > equilibriumReactions(const std::vector< std::string > &names) const
Generates a formatted vector of strings representing all aqueous equilibrium reactions.
std::map< std::string, GeochemistryEquilibriumSpecies > _equilibrium_species
Secondary equilibrium species and free electron data read from the database.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< std::string > getEquilibriumSpeciesNames() const
Get the list of secondary equilibrium species read from database.
std::map< std::string, Real > sorption_sites
bool isSecondarySpecies(const std::string &name) const
Returns true if name is a "secondary species" or "free electron" in the database. ...
Data structure for secondary equilibrium species.
std::map< std::string, GeochemistrySurfaceSpecies > _surface_species
Surface sorbing species data read from the database.
std::vector< std::string > secondarySpeciesNames() const
Returns a list of all the names of the "secondary species" and "free electron" in the database...
bool isSurfaceSpecies(const std::string &name) const
std::vector< std::string > oxideReactions(const std::vector< std::string > &names) const
Generates a formatted vector of strings representing all oxide reactions.
std::map< std::string, Real > basis_species
std::map< std::string, GeochemistryOxideSpecies > getOxideSpecies(const std::vector< std::string > &names)
Get the oxide species information.
bool isMineralSpecies(const std::string &name) const
std::map< std::string, Real > elements
const std::map< std::string, GeochemistryNeutralSpeciesActivity > & getNeutralSpeciesActivity() const
Get the neutral species activity coefficients.
std::map< std::string, GeochemistryBasisSpecies > _basis_species
Basis species data read from the database.
std::vector< Real > equilibrium_const
std::map< std::string, Real > basis_species
std::map< std::string, GeochemistryRedoxSpecies > getRedoxSpecies(const std::vector< std::string > &names)
Get the redox species (couples) information.
std::vector< Real > _pressure_points
Pressure points in database.
std::vector< std::string > printReactions(const std::vector< std::string > &names, const std::vector< std::map< std::string, Real >> &basis_species) const
Generates a formatted vector of strings representing all reactions.
void setNeutralSpeciesActivity()
Copy the Debye-Huckel parameters for computing neutral species activity (if any) found in the databas...
std::vector< std::string > gasReactions(const std::vector< std::string > &names) const
Generates a formatted vector of strings representing all gas reactions.
std::map< std::string, GeochemistryElements > _elements
Elements and their molecular weight read from the database.
Class for reading geochemical reactions from a MOOSE geochemical database.
bool isRedoxSpecies(const std::string &name) const
std::vector< std::string > mineralReactions(const std::vector< std::string > &names) const
Generates a formatted vector of strings representing all mineral reactions.
std::vector< std::string > _ms_names
List of secondary mineral species to read from database.
bool isBasisSpecies(const std::string &name) const
Checks if species is of given type.