https://mooseframework.inl.gov
GeochemistryUnitConverter.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 "GeochemistryConstants.h"
12 
14 {
15 
16 Real
17 fromMoles(Real moles,
18  const GeochemistryUnit unit,
19  const std::string & species_name,
21 {
22  Real factor = 0.0; // return moles * factor
23  if (mgd.basis_species_index.count(species_name) != 0)
24  factor = conversionFactor(unit,
25  mgd.basis_species_index.at(species_name),
26  species_name,
30  else if (mgd.eqm_species_index.count(species_name) != 0)
31  factor = conversionFactor(unit,
32  mgd.eqm_species_index.at(species_name),
33  species_name,
37  else if (mgd.kin_species_index.count(species_name) != 0)
38  factor = conversionFactor(unit,
39  mgd.kin_species_index.at(species_name),
40  species_name,
44  else
45  mooseError("GeochemistryUnitConverter: ",
46  species_name,
47  " is not a basis, equilibrium or kinetic species");
48  return moles * factor;
49 }
50 
51 Real
52 toMoles(Real quantity,
53  const GeochemistryUnit unit,
54  const std::string & species_name,
56 {
57  return quantity / fromMoles(1.0, unit, species_name, mgd);
58 }
59 
60 Real
62  unsigned ind,
63  const std::string & name,
64  const std::vector<Real> & mol_weight,
65  const std::vector<Real> & mol_volume,
66  const std::vector<bool> & is_mineral)
67 {
68  Real factor = 1.0;
69  switch (unit)
70  {
74  factor = 1.0;
75  break;
78  factor = 1E-3 * mol_weight[ind];
79  break;
82  factor = mol_weight[ind];
83  break;
86  factor = 1.0E3 * mol_weight[ind];
87  break;
90  factor = 1.0E6 * mol_weight[ind];
91  break;
93  if (!is_mineral[ind])
94  mooseError("GeochemistryUnitConverter: Cannot use CM3 units for species ",
95  name,
96  " because it is not a mineral");
97  factor = mol_volume[ind];
98  break;
99  }
100  return factor;
101 }
102 } // namespace GeochemistryUnitConverter
std::vector< Real > eqm_species_molecular_weight
all quantities have a molecular weight (g)
std::vector< bool > kin_species_mineral
kin_species_mineral[j] = true iff the j^th kinetic species is a mineral
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::vector< Real > kin_species_molecular_weight
all quantities have a molecular weight (g/mol)
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
Real toMoles(Real quantity, const GeochemistryUnit unit, const std::string &species_name, const ModelGeochemicalDatabase &mgd)
Calculates the amount of moles corresponding to "quantity" "unit"s of species name, OR calculates the molality corresponding to "quantity" "unit"s of species name, whichever is appropriate.
std::unordered_map< std::string, unsigned > kin_species_index
kin_species_index[name] = index of the kinetic species, within all ModelGeochemicalDatabase internal ...
Real fromMoles(Real moles, const GeochemistryUnit unit, const std::string &species_name, const ModelGeochemicalDatabase &mgd)
Calculates the amount of "unit"s of species_name in 1 mole, OR in 1 molal, whichever is appropriate...
const std::string name
Definition: Setup.h:20
std::vector< Real > basis_species_molecular_weight
all quantities have a molecular weight (g)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< Real > eqm_species_molecular_volume
all quantities have a molecular volume (cm^3) (only nonzero for minerals, however) ...
std::vector< bool > basis_species_mineral
basis_species_mineral[j] = true iff the j^th basis species is a mineral
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) ...
Real conversionFactor(const GeochemistryUnit unit, unsigned ind, const std::string &name, const std::vector< Real > &mol_weight, const std::vector< Real > &mol_volume, const std::vector< bool > &is_mineral)
Calculates the number of "unit" in 1 mole of substance, OR calculates the number of "unit" in 1 molal...
Utilities to convert to and from mole units.