Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems

A type used to represent the chemical formula of a chemical species. More...

#include <ChemicalFormula.hpp>

Public Member Functions

 ChemicalFormula ()
 Construct a default ChemicalFormula object.
 
 ChemicalFormula (const char *formula)
 Construct a ChemicalFormula object with given formula. More...
 
 ChemicalFormula (String formula)
 Construct a ChemicalFormula object with given formula. More...
 
 ChemicalFormula (String formula, Pairs< String, double > symbols, double charge)
 Construct a ChemicalFormula object with given formula, element symbols, and charge. More...
 
auto str () const -> const String &
 Return the chemical formula of the substance as a string.
 
auto elements () const -> const Pairs< String, double > &
 Return the element symbols and their coefficients in the chemical formula.
 
auto symbols () const -> Strings
 Return the element symbols in the chemical formula.
 
auto coefficients () const -> Vec< double >
 Return the coefficients of the elements in the chemical formula.
 
auto coefficient (const String &symbol) const -> double
 Return the coefficient of an element symbol in the chemical formula.
 
auto charge () const -> double
 Return the electric charge of the chemical formula.
 
auto molarMass () const -> double
 Return the molar mass of the chemical formula (in kg/mol). More...
 
auto equivalent (const ChemicalFormula &other) const -> bool
 Return true if another chemical formula is equivalent to this one. More...
 
 operator String () const
 Convert this ChemicalFormula object into a string.
 
 operator Pairs< String, double > () const
 Convert this ChemicalFormula object into a Pairs<String, double>.
 

Static Public Member Functions

static auto equivalent (const ChemicalFormula &f1, const ChemicalFormula &f2) -> bool
 Return true if two chemical formulas are equivalent.
 

Detailed Description

A type used to represent the chemical formula of a chemical species.

Constructor & Destructor Documentation

◆ ChemicalFormula() [1/3]

ChemicalFormula ( const char *  formula)

Construct a ChemicalFormula object with given formula.

Parameters
formulaThe chemical formula of the species (e.g., H2O, CaCO3, CO3--, CO3-2).

◆ ChemicalFormula() [2/3]

ChemicalFormula ( String  formula)

Construct a ChemicalFormula object with given formula.

Parameters
formulaThe chemical formula of the species (e.g., H2O, CaCO3, CO3--, CO3-2).

◆ ChemicalFormula() [3/3]

ChemicalFormula ( String  formula,
Pairs< String, double >  symbols,
double  charge 
)

Construct a ChemicalFormula object with given formula, element symbols, and charge.

Parameters
formulaThe chemical formula of the species (e.g., HCO3-).
symbolsThe element symbols and their coefficients (e.g., {{"H", 1}, {"C", 1}, {"O", 3}} for HCO3-).
chargeThe electric charge in the chemical formula (e.g., -1 for HCO3-).

Member Function Documentation

◆ molarMass()

auto molarMass ( ) const -> double

Return the molar mass of the chemical formula (in kg/mol).

Warning
An error is thrown if the formula contains symbols that do not exist in the periodic table.

◆ equivalent()

auto equivalent ( const ChemicalFormula other) const -> bool

Return true if another chemical formula is equivalent to this one.

Two chemical formulas are equivalent if they have the same elemental composition. Consider Ca++ and Ca+2 for example. These two formulas are equivalent, despite the different convention for indicating charge. Another example is CaCO3 and Ca(CO3). All these formulas have identical symbols and coefficients, and are thus equivalent.


The documentation for this class was generated from the following file: