|
fourdst::libcomposition v2.0.1
Robust atomic species information library
|
Manages a collection of chemical species and their abundances. More...
#include <composition.h>
Classes | |
| struct | CompositionCache |
| Caches computed properties of the composition to avoid redundant calculations. More... | |
Public Member Functions | |
| Composition ()=default | |
| Default constructor. | |
| ~Composition () override=default | |
| Default destructor. | |
| Composition (const std::vector< std::string > &symbols) | |
| Constructs a Composition and registers the given symbols from a vector. | |
| Composition (const std::vector< atomic::Species > &species) | |
| Constructs a Composition and registers the given species from a vector. | |
| Composition (const std::set< std::string > &symbols) | |
| Constructs a Composition and registers the given symbols from a set. | |
| Composition (const std::set< atomic::Species > &species) | |
| Constructs a Composition and registers the given species from a set. | |
| Composition (const std::vector< std::string > &symbols, const std::vector< double > &molarAbundances) | |
| Constructs a Composition from symbols and their corresponding molar abundances. | |
| Composition (const std::vector< atomic::Species > &species, const std::vector< double > &molarAbundances) | |
| Constructs a Composition from species and their corresponding molar abundances. | |
| Composition (const std::set< std::string > &symbols, const std::vector< double > &molarAbundances) | |
| Constructs a Composition from symbols in a set and their corresponding molar abundances. | |
| Composition (const Composition &composition) | |
| Constructs a Composition from another Composition. | |
| Composition & | operator= (Composition const &other) |
| Assignment operator. | |
| void | registerSymbol (const std::string &symbol) |
| Registers a new symbol for inclusion in the composition. | |
| void | registerSymbol (const std::vector< std::string > &symbols) |
| Registers multiple new symbols. | |
| void | registerSpecies (const atomic::Species &species) noexcept |
| Registers a new species by extracting its symbol. | |
| void | registerSpecies (const std::vector< atomic::Species > &species) noexcept |
| Registers a vector of new species. | |
| bool | contains (const atomic::Species &species) const noexcept override |
| Checks if a given species is present in the composition. | |
| bool | contains (const std::string &symbol) const override |
| Checks if a given symbol is present in the composition. | |
| size_t | size () const noexcept override |
| Gets the number of registered species in the composition. | |
| void | setMolarAbundance (const std::string &symbol, const double &molar_abundance) |
| Sets the molar abundance for a given symbol. | |
| void | setMolarAbundance (const atomic::Species &species, const double &molar_abundance) |
| Sets the molar abundance for a given isotope. | |
| void | setMolarAbundance (const std::vector< std::string > &symbols, const std::vector< double > &molar_abundances) |
| Sets the molar abundances for a list of symbols. | |
| void | setMolarAbundance (const std::vector< atomic::Species > &species, const std::vector< double > &molar_abundances) |
| Sets the molar abundances for a list of isotopes. | |
| void | setMolarAbundance (const std::set< std::string > &symbols, const std::vector< double > &molar_abundances) |
| Sets the molar abundances for a set of symbols. | |
| void | setMolarAbundance (const std::set< atomic::Species > &species, const std::vector< double > &molar_abundances) |
| Sets the molar abundances for a set of isotopes. | |
| std::set< std::string > | getRegisteredSymbols () const noexcept override |
| Gets the registered symbols. | |
| const std::set< atomic::Species > & | getRegisteredSpecies () const noexcept override |
| Get a set of all species that are registered in the composition. | |
| std::unordered_map< atomic::Species, double > | getMassFraction () const noexcept override |
| Gets the mass fractions of all species in the composition. | |
| double | getMassFraction (const std::string &symbol) const override |
| Gets the mass fraction for a given symbol. See the overload for species-based lookup for more details on how mass fractions are calculated. | |
| double | getMassFraction (const atomic::Species &species) const override |
| Gets the mass fraction for a given species. | |
| double | getNumberFraction (const std::string &symbol) const override |
| Gets the number fraction for a given symbol. See the overload for species-based lookup for more details on how number fractions are calculated. | |
| double | getNumberFraction (const atomic::Species &species) const override |
| Gets the number fraction for a given species. | |
| std::unordered_map< atomic::Species, double > | getNumberFraction () const noexcept override |
| Gets the number fractions of all species in the composition. | |
| double | getMolarAbundance (const std::string &symbol) const override |
| Gets the molar abundances of all species in the composition. | |
| double | getMolarAbundance (const atomic::Species &species) const override |
| Gets the molar abundance for a given species. | |
| double | getMeanParticleMass () const noexcept override |
| Compute the mean particle mass of the composition. | |
| double | getElectronAbundance () const noexcept override |
| Compute the electron abundance of the composition. | |
| CanonicalComposition | getCanonicalComposition () const |
| Compute the canonical composition (X, Y, Z) of the composition. | |
| std::vector< double > | getMassFractionVector () const noexcept override |
| Get a uniform vector representation of the mass fraction stored in the composition object sorted such that the lightest species is at index 0 and the heaviest is at the last index. | |
| std::vector< double > | getNumberFractionVector () const noexcept override |
| Get a uniform vector representation of the number fractions stored in the composition object sorted such that the lightest species is at index 0 and the heaviest is at the last index. | |
| std::vector< double > | getMolarAbundanceVector () const noexcept override |
| Get a uniform vector representation of the molar abundances stored in the composition object sorted such that the lightest species is at index 0 and the heaviest is at the last index. | |
| size_t | getSpeciesIndex (const std::string &symbol) const override |
| get the index in the sorted vector representation for a given symbol | |
| size_t | getSpeciesIndex (const atomic::Species &species) const override |
| get the index in the sorted vector representation for a given symbol | |
| atomic::Species | getSpeciesAtIndex (size_t index) const override |
| Get the species at a given index in the sorted vector representation. | |
| auto | begin () |
| Returns an iterator to the beginning of the molar abundance map. | |
| auto | begin () const |
| Returns a const iterator to the beginning of the molar abundance map. | |
| auto | end () |
| Returns an iterator to the end of the molar abundance map. | |
| auto | end () const |
| Returns a const iterator to the end of the molar abundance map. | |
Public Member Functions inherited from CompositionAbstract | |
| virtual | ~CompositionAbstract ()=default |
| Virtual destructor. | |
Static Private Member Functions | |
| static quill::Logger * | getLogger () |
| Gets the logger instance for the Composition class. This is static to ensure that all composition objects share the same logger instance. | |
Private Attributes | |
| std::set< atomic::Species > | m_registeredSpecies |
| Set of registered species in the composition. | |
| std::map< atomic::Species, double > | m_molarAbundances |
| Map of species to their molar abundances. | |
| CompositionCache | m_cache |
| Cache for computed properties to avoid redundant calculations. | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const Composition &composition) |
| Overloaded output stream operator for Composition. | |
Manages a collection of chemical species and their abundances.
This class is a primary interface for defining and manipulating material compositions. In order to use the Composition class a user must first register symbols or species. Symbols are the string representation of a species (i.e. deuterium would be "H-2" whereas Beryllium 7 would be "Be-7") and then set the molar abundances. Species are the data structure fourdst::atomic::Species version. Here Deuterium would be represented by the Species fourdst::atomic::H_2 whereas Beryllium 7 would be fourdst::atomic::Be_7. Once the symbols/species have been registered the user can then set molar abundances.
Once the Composition object has been populated the user can query mass fractions, number fractions, electron abundances, mean particle mass, molar abundance, and Canonical (X, Y, Z) composition.
fourdst::composition::buildCompositionFromMassFractions which wll facilitate just that.| This | class throws various exceptions from fourdst::composition::exceptions for invalid operations, such as using unregistered symbols or providing invalid abundances. |
Definition at line 97 of file composition.h.
|
default |
Default constructor.
Creates an empty Composition object. No symbols or species are registered initially; however, the user can register symbols or species later using the provided methods.
|
overridedefault |
Default destructor.
|
explicit |
Constructs a Composition and registers the given symbols from a vector.
| symbols | The symbols to register. |
| exceptions::UnknownSymbolError | if any symbol is invalid. Symbols are invalid if they are not registered at compile time in the atomic species database (fourdst/atomic/species.h). |
Definition at line 84 of file composition.cpp.
|
explicit |
Constructs a Composition and registers the given species from a vector.
| species | The species to register. |
Definition at line 100 of file composition.cpp.
|
explicit |
Constructs a Composition and registers the given symbols from a set.
| symbols | The symbols to register. |
| exceptions::UnknownSymbolError | if any symbol is invalid. Symbols are invalid if they are not registered at compile time in the atomic species database (fourdst/atomic/species.h). |
Definition at line 92 of file composition.cpp.
|
explicit |
Constructs a Composition and registers the given species from a set.
| species | The species to register. |
Definition at line 108 of file composition.cpp.
| fourdst::composition::Composition::Composition | ( | const std::vector< std::string > & | symbols, |
| const std::vector< double > & | molarAbundances ) |
Constructs a Composition from symbols and their corresponding molar abundances.
| symbols | The symbols to register. |
| molarAbundances | The corresponding molar abundances for each symbol. |
| exceptions::UnknownSymbolError | if any symbol is invalid. Symbols are invalid if they are not registered at compile time in the atomic species database (fourdst/atomic/species.h). |
| exceptions::InvalidCompositionError | if the number of symbols does not match the number of molar abundances. |
Definition at line 116 of file composition.cpp.
| fourdst::composition::Composition::Composition | ( | const std::vector< atomic::Species > & | species, |
| const std::vector< double > & | molarAbundances ) |
Constructs a Composition from species and their corresponding molar abundances.
| species | The species to register. |
| molarAbundances | The corresponding molar abundances for each species. |
| exceptions::InvalidCompositionError | if the number of species does not match the number of molar abundances. |
Definition at line 131 of file composition.cpp.
| fourdst::composition::Composition::Composition | ( | const std::set< std::string > & | symbols, |
| const std::vector< double > & | molarAbundances ) |
Constructs a Composition from symbols in a set and their corresponding molar abundances.
| symbols | The symbols to register. |
| molarAbundances | The corresponding molar abundances for each symbol. |
| exceptions::UnknownSymbolError | if any symbol is invalid. Symbols are invalid if they are not registered at compile time in the atomic species database (fourdst/atomic/species.h). |
| exceptions::InvalidCompositionError | if the number of symbols does not match the number of molar abundances. |
Definition at line 146 of file composition.cpp.
| fourdst::composition::Composition::Composition | ( | const Composition & | composition | ) |
Constructs a Composition from another Composition.
| composition | The Composition to copy. |
Definition at line 161 of file composition.cpp.
|
inline |
Returns an iterator to the beginning of the molar abundance map.
Definition at line 753 of file composition.h.
|
inlinenodiscard |
Returns a const iterator to the beginning of the molar abundance map.
Definition at line 774 of file composition.h.
|
nodiscardoverridevirtualnoexcept |
Checks if a given species is present in the composition.
| species | The isotope to check for. |
Implements CompositionAbstract.
Definition at line 509 of file composition.cpp.
|
nodiscardoverridevirtual |
Checks if a given symbol is present in the composition.
| symbol | The symbol to check for. |
| exceptions::UnknownSymbolError | if the symbol is not in the atomic species database. |
Implements CompositionAbstract.
Definition at line 515 of file composition.cpp.
|
inline |
Returns an iterator to the end of the molar abundance map.
Definition at line 795 of file composition.h.
|
inlinenodiscard |
Returns a const iterator to the end of the molar abundance map.
Definition at line 816 of file composition.h.
|
nodiscard |
Compute the canonical composition (X, Y, Z) of the composition.
The canonical composition is defined as:
The canonical composition is computed by summing the mass fractions of all registered species in the composition according to their element type.
| exceptions::InvalidCompositionError | if, after constructing the canonical composition, the sum X + Y + Z is not approximately equal to 1.0 (within a tolerance of 1e-16) |
Definition at line 330 of file composition.cpp.
|
nodiscardoverridevirtualnoexcept |
Compute the electron abundance of the composition.
The electron abundance is calculated using the formula:
where:
Implements CompositionAbstract.
Definition at line 321 of file composition.cpp.
|
inlinestaticprivate |
Gets the logger instance for the Composition class. This is static to ensure that all composition objects share the same logger instance.
Definition at line 144 of file composition.h.
|
nodiscardoverridevirtualnoexcept |
Gets the mass fractions of all species in the composition.
Implements CompositionAbstract.
Definition at line 251 of file composition.cpp.
|
nodiscardoverridevirtual |
Gets the mass fraction for a given species.
The mass fraction X_i for a species is calculated using the formula:
where:
This formula ensures that the mass fractions of all species sum to 1.0.
| species | The species to get the mass fraction for. |
| exceptions::UnregisteredSymbolError | if the isotope is not registered in the composition. |
Implements CompositionAbstract.
Definition at line 235 of file composition.cpp.
|
nodiscardoverridevirtual |
Gets the mass fraction for a given symbol. See the overload for species-based lookup for more details on how mass fractions are calculated.
| symbol | The symbol to get the mass fraction for. |
| exceptions::UnknownSymbolError | if the symbol is not in the atomic species database. |
| exceptions::UnregisteredSymbolError | if the symbol is not in the composition. |
Implements CompositionAbstract.
Definition at line 227 of file composition.cpp.
|
nodiscardoverridevirtualnoexcept |
Get a uniform vector representation of the mass fraction stored in the composition object sorted such that the lightest species is at index 0 and the heaviest is at the last index.
This is primarily useful for external libraries which need to ensure that vector representation uniformity is maintained
Implements CompositionAbstract.
Definition at line 373 of file composition.cpp.
|
nodiscardoverridevirtualnoexcept |
Compute the mean particle mass of the composition.
The mean particle mass is calculated using the formula:
where:
Implements CompositionAbstract.
Definition at line 311 of file composition.cpp.
|
nodiscardoverridevirtual |
Gets the molar abundance for a given species.
| species | The species to get the molar abundance for. |
| exceptions::UnregisteredSymbolError | if the isotope is not registered in the composition. |
Implements CompositionAbstract.
Definition at line 302 of file composition.cpp.
|
nodiscardoverridevirtual |
Gets the molar abundances of all species in the composition.
| exceptions::UnknownSymbolError | if any symbol is not in the atomic species database. |
| exceptions::UnregisteredSymbolError | if any symbol is not in the composition. |
Implements CompositionAbstract.
Definition at line 291 of file composition.cpp.
|
nodiscardoverridevirtualnoexcept |
Get a uniform vector representation of the molar abundances stored in the composition object sorted such that the lightest species is at index 0 and the heaviest is at the last index.
This is primarily useful for external libraries which need to ensure that vector representation uniformity is maintained
Implements CompositionAbstract.
Definition at line 416 of file composition.cpp.
|
nodiscardoverridevirtualnoexcept |
Gets the number fractions of all species in the composition.
Implements CompositionAbstract.
Definition at line 283 of file composition.cpp.
|
nodiscardoverridevirtual |
Gets the number fraction for a given species.
The number fraction Y_i for a species is calculated using the formula:
where:
This formula ensures that the number fractions of all species sum to 1.0.
| species | The species to get the number fraction for. |
| exceptions::UnregisteredSymbolError | if the isotope is not registered in the composition. |
Implements CompositionAbstract.
Definition at line 270 of file composition.cpp.
|
nodiscardoverridevirtual |
Gets the number fraction for a given symbol. See the overload for species-based lookup for more details on how number fractions are calculated.
| symbol | The symbol to get the number fraction for. |
| exceptions::UnknownSymbolError | if the symbol is not in the atomic species database. |
| exceptions::UnregisteredSymbolError | if the symbol is not in the composition. |
Implements CompositionAbstract.
Definition at line 260 of file composition.cpp.
|
nodiscardoverridevirtualnoexcept |
Get a uniform vector representation of the number fractions stored in the composition object sorted such that the lightest species is at index 0 and the heaviest is at the last index.
This is primarily useful for external libraries which need to ensure that vector representation uniformity is maintained
Implements CompositionAbstract.
Definition at line 395 of file composition.cpp.
|
nodiscardoverridevirtualnoexcept |
Get a set of all species that are registered in the composition.
atomic::Species objects registered in the composition.Implements CompositionAbstract.
Definition at line 222 of file composition.cpp.
|
nodiscardoverridevirtualnoexcept |
Gets the registered symbols.
getRegisteredSpecies() instead which returns a constant reference to the internal set. Implements CompositionAbstract.
Definition at line 214 of file composition.cpp.
|
nodiscardoverridevirtual |
Get the species at a given index in the sorted vector representation.
This is primarily useful for external libraries which need to ensure that vector representation uniformity is maintained
| index | The index in the sorted vector representation for which to return the species. Must be in [0, N-1] where N is the number of registered species. |
| std::out_of_range | if the index is out of range. |
Implements CompositionAbstract.
Definition at line 483 of file composition.cpp.
|
nodiscardoverridevirtual |
get the index in the sorted vector representation for a given symbol
This is primarily useful for external libraries which need to ensure that vector representation uniformity is maintained
| species | the species to look up the index for. Note that this is the index species data will be at if you were to call getMolarAbundanceVector(), getMassFractionVector(), or getNumberFractionVector() |
| exceptions::UnregisteredSymbolError | if the symbol is not registered in the composition |
Implements CompositionAbstract.
Definition at line 449 of file composition.cpp.
|
nodiscardoverridevirtual |
get the index in the sorted vector representation for a given symbol
This is primarily useful for external libraries which need to ensure that vector representation uniformity is maintained
| symbol | the symbol to look up the index for. Note that this is the index species data will be at if you were to call getMolarAbundanceVector(), getMassFractionVector(), or getNumberFractionVector() |
| exceptions::UnknownSymbolError | if the symbol is not in the atomic species database. |
| exceptions::UnregisteredSymbolError | if the symbol is not registered in the composition |
Implements CompositionAbstract.
Definition at line 438 of file composition.cpp.
| Composition & fourdst::composition::Composition::operator= | ( | Composition const & | other | ) |
Assignment operator.
| other | The Composition to assign from. |
Definition at line 168 of file composition.cpp.
|
noexcept |
Registers a new species by extracting its symbol.
| species | The species to register. |
fourdst/atomic/species.h header file. These can be accessed directly through their fully qualified names (e.g., fourdst::atomic::C_12 for Carbon-12). Alternatively, these can also be accessed through a string-indexed map located in fourdst/atomic/species.h called fourdst::atomic::species ( e.g., fourdst::atomic::species.at("C-12") for Carbon-12). Definition at line 197 of file composition.cpp.
|
noexcept |
Registers a vector of new species.
| species | The vector of species to register. |
fourdst/atomic/species.h header file. These can be accessed directly through their fully qualified names (e.g., fourdst::atomic::C_12 for Carbon-12). Alternatively, these can also be accessed through a string-indexed map located in fourdst/atomic/species.h called fourdst::atomic::species ( e.g., fourdst::atomic::species.at("C-12") for Carbon-12). Definition at line 206 of file composition.cpp.
| void fourdst::composition::Composition::registerSymbol | ( | const std::string & | symbol | ) |
Registers a new symbol for inclusion in the composition.
A symbol must be registered before its abundance can be set.
| symbol | The symbol to register (e.g., "Fe-56"). |
| exceptions::UnknownSymbolError | if the symbol is not in the atomic species database. |
Definition at line 178 of file composition.cpp.
| void fourdst::composition::Composition::registerSymbol | ( | const std::vector< std::string > & | symbols | ) |
Registers multiple new symbols.
| symbols | The symbols to register. |
| exceptions::UnknownSymbolError | if any symbol is invalid. |
Definition at line 189 of file composition.cpp.
| void fourdst::composition::Composition::setMolarAbundance | ( | const atomic::Species & | species, |
| const double & | molar_abundance ) |
Sets the molar abundance for a given isotope.
| species | The isotope to set the molar abundance for. |
| molar_abundance | The molar abundance to set. |
| exceptions::UnregisteredSymbolError | if the isotope is not registered in the composition. |
| exceptions::InvalidCompositionError | if the molar abundance is negative. |
Definition at line 541 of file composition.cpp.
| void fourdst::composition::Composition::setMolarAbundance | ( | const std::set< atomic::Species > & | species, |
| const std::vector< double > & | molar_abundances ) |
Sets the molar abundances for a set of isotopes.
| species | The isotopes to set the molar abundances for. |
| molar_abundances | The molar abundances to set. |
| exceptions::UnregisteredSymbolError | if any isotope is not registered in the composition. |
| exceptions::InvalidCompositionError | if any molar abundance is negative. |
Definition at line 582 of file composition.cpp.
| void fourdst::composition::Composition::setMolarAbundance | ( | const std::set< std::string > & | symbols, |
| const std::vector< double > & | molar_abundances ) |
Sets the molar abundances for a set of symbols.
| symbols | The symbols to set the molar abundances for. |
| molar_abundances | The molar abundances to set. |
| exceptions::UnknownSymbolError | if any symbol is not in the atomic species database. |
| exceptions::UnregisteredSymbolError | if any symbol is not in the composition. |
| exceptions::InvalidCompositionError | if any molar abundance is negative. |
Definition at line 573 of file composition.cpp.
| void fourdst::composition::Composition::setMolarAbundance | ( | const std::string & | symbol, |
| const double & | molar_abundance ) |
Sets the molar abundance for a given symbol.
| symbol | The symbol to set the molar abundance for. |
| molar_abundance | The molar abundance to set. |
| exceptions::UnknownSymbolError | if the symbol is not in the atomic species database. |
| exceptions::UnregisteredSymbolError | if the symbol is not in the composition. |
| exceptions::InvalidCompositionError | if the molar abundance is negative. |
Definition at line 529 of file composition.cpp.
| void fourdst::composition::Composition::setMolarAbundance | ( | const std::vector< atomic::Species > & | species, |
| const std::vector< double > & | molar_abundances ) |
Sets the molar abundances for a list of isotopes.
| species | The isotopes to set the molar abundances for. |
| molar_abundances | The molar abundances to set. |
| exceptions::UnregisteredSymbolError | if any isotope is not registered in the composition. |
| exceptions::InvalidCompositionError | if any molar abundance is negative. |
Definition at line 564 of file composition.cpp.
| void fourdst::composition::Composition::setMolarAbundance | ( | const std::vector< std::string > & | symbols, |
| const std::vector< double > & | molar_abundances ) |
Sets the molar abundances for a list of symbols.
| symbols | The symbols to set the molar abundances for. |
| molar_abundances | The molar abundances to set. |
| exceptions::UnknownSymbolError | if any symbol is not in the atomic species database. |
| exceptions::UnregisteredSymbolError | if any symbol is not in the composition. |
| exceptions::InvalidCompositionError | if any molar abundance is negative. |
Definition at line 555 of file composition.cpp.
|
nodiscardoverridevirtualnoexcept |
Gets the number of registered species in the composition.
Implements CompositionAbstract.
Definition at line 525 of file composition.cpp.
|
friend |
Overloaded output stream operator for Composition.
| os | The output stream. |
| composition | The Composition to output. |
Definition at line 593 of file composition.cpp.
|
mutableprivate |
Cache for computed properties to avoid redundant calculations.
Definition at line 152 of file composition.h.
|
private |
Map of species to their molar abundances.
Definition at line 150 of file composition.h.
|
private |
Set of registered species in the composition.
Definition at line 149 of file composition.h.