https://mooseframework.inl.gov
Enumerations | Functions
GeochemistryUnitConverter Namespace Reference

Utilities to convert to and from mole units. More...

Enumerations

enum  GeochemistryUnit {
  GeochemistryUnit::DIMENSIONLESS, GeochemistryUnit::MOLES, GeochemistryUnit::MOLAL, GeochemistryUnit::KG,
  GeochemistryUnit::G, GeochemistryUnit::MG, GeochemistryUnit::UG, GeochemistryUnit::KG_PER_KG_SOLVENT,
  GeochemistryUnit::G_PER_KG_SOLVENT, GeochemistryUnit::MG_PER_KG_SOLVENT, GeochemistryUnit::UG_PER_KG_SOLVENT, GeochemistryUnit::CM3
}
 

Functions

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. More...
 
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. More...
 
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 of substance, whichever is appropriate. More...
 

Detailed Description

Utilities to convert to and from mole units.

Enumeration Type Documentation

◆ GeochemistryUnit

Function Documentation

◆ conversionFactor()

Real GeochemistryUnitConverter::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 of substance, whichever is appropriate.

Example: if unit = G, this function will return the molecular weight of the substance. Example: if unit = CM3, this function returns the molecular volume of the substance, or will produce an error if the substance is not a mineral. Example: if unit = MG_PER_KG, then the molal quantity returned is 1E3 * (molecular weight of the substance). You will probably want to use toMoles or fromMoles rather than this function.

Parameters
unitThe unit that you wish to convert 1 mol of substance to. If unit is DIMENSIONLESS, MOLES or MOLAL, this returns 1.0. If unit is KG, G, MG, UG or CM3, this function returns the number in 1 mole. If unit is KG_PER_KG_SOLVENT, G_PER_KG_SOLVENT, MG_PER_KG_SOLVENT, UG_PER_KG_SOLVENT, this function returns the number in 1 molal.
indThe index of mol_weight and mol_volume and is_mineral corresponding to the substance
nameThe name of the substance
mol_weightmol_weight[ind] is the molecular weight (g/mol) of the substance
mol_volumemol_volume[ind] is the molecular volume (cm^3/mol) of the substance
is_mineralis_mineral[ind] = true iff the substance is a mineral
Returns
1 mol of substance will be this many "unit"s of that substance

Definition at line 61 of file GeochemistryUnitConverter.C.

Referenced by fromMoles().

67 {
68  Real factor = 1.0;
69  switch (unit)
70  {
71  case GeochemistryUnit::DIMENSIONLESS:
72  case GeochemistryUnit::MOLES:
73  case GeochemistryUnit::MOLAL:
74  factor = 1.0;
75  break;
76  case GeochemistryUnit::KG:
77  case GeochemistryUnit::KG_PER_KG_SOLVENT:
78  factor = 1E-3 * mol_weight[ind];
79  break;
81  case GeochemistryUnit::G_PER_KG_SOLVENT:
82  factor = mol_weight[ind];
83  break;
84  case GeochemistryUnit::MG:
85  case GeochemistryUnit::MG_PER_KG_SOLVENT:
86  factor = 1.0E3 * mol_weight[ind];
87  break;
88  case GeochemistryUnit::UG:
89  case GeochemistryUnit::UG_PER_KG_SOLVENT:
90  factor = 1.0E6 * mol_weight[ind];
91  break;
92  case GeochemistryUnit::CM3:
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 }
void mooseError(Args &&... args)
static const std::string G
Definition: NS.h:166
const std::string name
Definition: Setup.h:20
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ fromMoles()

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

Example: if moles = 2.0 and unit = CM3 and species_name = Halite, this function will return the number of cm^3 in 1 mole of Halite. Example: if moles = 2.0 and unit = MG_PER_KG and species_name = Halite, this function will return the number of mg/kg_solvent_water in a 2.0 molal solution of Halite.

Parameters
molesthe amount of moles of species_name
unitthe unit to convert to. If unit is DIMENSIONLESS, MOLES or MOLAL, this returns quantity. If unit is KG, G, MG, UG or CM3, then "moles" is the mole number. If unit is KG_PER_KG_SOLVENT, G_PER_KG_SOLVENT, MG_PER_KG_SOLVENT, UG_PER_KG_SOLVENT, then "moles" is assumed to be the molality.
species_namethe name of the substance - this should appear in mgd
mgdthe database corresponding to the model, which should contain information about species_name

Definition at line 17 of file GeochemistryUnitConverter.C.

Referenced by TEST(), and toMoles().

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 }
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
std::unordered_map< std::string, unsigned > kin_species_index
kin_species_index[name] = index of the kinetic species, within all ModelGeochemicalDatabase internal ...
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
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...

◆ toMoles()

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

Example: if quantity = 2.0 and unit = CM3 and species_name = Halite, this function will return the number of moles in 2 cm^3 of Halite. Example: if quantity = 2.0 and unit = MG_PER_KG and species_name = Halite, this function will return the molality of a 2 mg/kg_solvent_water Halite solution.

Parameters
quantitythe amount of substance expressed in "unit" units
unitthe unit of measurement of to_convert. If unit is DIMENSIONLESS, MOLES or MOLAL, this returns quantity. If unit is KG, G, MG, UG or CM3, this function returns the number of moles. If unit is KG_PER_KG_SOLVENT, G_PER_KG_SOLVENT, MG_PER_KG_SOLVENT, UG_PER_KG_SOLVENT, this function returns the molality.
species_namethe name of the substance - this should appear in mgd
mgdthe database corresponding to the model, which should contain information about species_name
Returns
the number of moles, or the molality, whichever is appropriate

Definition at line 52 of file GeochemistryUnitConverter.C.

Referenced by GeochemicalSystem::checkAndInitialize(), and TEST().

56 {
57  return quantity / fromMoles(1.0, unit, species_name, mgd);
58 }
const ModelGeochemicalDatabase mgd
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...