fourdst::libcomposition v1.5.2
Robust atomic species information library
Loading...
Searching...
No Matches
fourdst::composition::Composition Class Reference

Manages a collection of chemical species and their abundances. More...

#include <composition.h>

Public Member Functions

 Composition ()=default
 Default constructor.
 
 ~Composition ()=default
 Default destructor.
 
bool finalize (bool norm=false)
 Finalizes the composition, making it ready for querying.
 
 Composition (const std::vector< std::string > &symbols)
 Constructs a Composition and registers the given symbols.
 
 Composition (const std::set< std::string > &symbols)
 Constructs a Composition and registers the given symbols from a set.
 
 Composition (const std::vector< std::string > &symbols, const std::vector< double > &fractions, bool massFracMode=true)
 Constructs and finalizes a Composition with the given symbols and fractions.
 
 Composition (const Composition &composition)
 Constructs a Composition from another Composition.
 
Compositionoperator= (Composition const &other)
 Assignment operator.
 
void registerSymbol (const std::string &symbol, bool massFracMode=true)
 Registers a new symbol for inclusion in the composition.
 
void registerSymbol (const std::vector< std::string > &symbols, bool massFracMode=true)
 Registers multiple new symbols.
 
void registerSpecies (const fourdst::atomic::Species &species, bool massFracMode=true)
 Registers a new species by extracting its symbol.
 
void registerSpecies (const std::vector< fourdst::atomic::Species > &species, bool massFracMode=true)
 Registers a vector of new species.
 
std::set< std::string > getRegisteredSymbols () const
 Gets the registered symbols.
 
std::set< fourdst::atomic::SpeciesgetRegisteredSpecies () const
 Get a set of all species that are registered in the composition.
 
double setMassFraction (const std::string &symbol, const double &mass_fraction)
 Sets the mass fraction for a given symbol.
 
std::vector< double > setMassFraction (const std::vector< std::string > &symbols, const std::vector< double > &mass_fractions)
 Sets the mass fraction for multiple symbols.
 
double setMassFraction (const fourdst::atomic::Species &species, const double &mass_fraction)
 Sets the mass fraction for a given species.
 
std::vector< double > setMassFraction (const std::vector< fourdst::atomic::Species > &species, const std::vector< double > &mass_fractions)
 Sets the mass fraction for multiple species.
 
double setNumberFraction (const std::string &symbol, const double &number_fraction)
 Sets the number fraction for a given symbol.
 
std::vector< double > setNumberFraction (const std::vector< std::string > &symbols, const std::vector< double > &number_fractions)
 Sets the number fraction for multiple symbols.
 
double setNumberFraction (const fourdst::atomic::Species &species, const double &number_fraction)
 Sets the number fraction for a given species.
 
std::vector< double > setNumberFraction (const std::vector< fourdst::atomic::Species > &species, const std::vector< double > &number_fractions)
 Sets the number fraction for multiple species.
 
Composition mix (const Composition &other, double fraction) const
 Mixes this composition with another to produce a new composition.
 
std::unordered_map< std::string, double > getMassFraction () const
 Gets the mass fractions of all species in the composition.
 
double getMassFraction (const std::string &symbol) const
 Gets the mass fraction for a given symbol.
 
double getMassFraction (const fourdst::atomic::Species &species) const
 Gets the mass fraction for a given isotope.
 
double getNumberFraction (const std::string &symbol) const
 Gets the number fraction for a given symbol.
 
double getNumberFraction (const fourdst::atomic::Species &species) const
 Gets the number fraction for a given isotope.
 
std::unordered_map< std::string, double > getNumberFraction () const
 Gets the number fractions of all species in the composition.
 
double getMolarAbundance (const std::string &symbol) const
 Gets the molar abundance (X_i / A_i) for a given symbol.
 
double getMolarAbundance (const fourdst::atomic::Species &species) const
 Gets the molar abundance for a given isotope.
 
std::pair< CompositionEntry, GlobalCompositiongetComposition (const std::string &symbol) const
 Gets the composition entry and global composition data for a given symbol.
 
std::pair< CompositionEntry, GlobalCompositiongetComposition (const fourdst::atomic::Species &species) const
 Gets the composition entry and global composition data for a given species.
 
std::pair< std::unordered_map< std::string, CompositionEntry >, GlobalCompositiongetComposition () const
 Gets all composition entries and the global composition data.
 
double getMeanParticleMass () const
 Compute the mean particle mass of the composition.
 
double getMeanAtomicNumber () const
 Compute the mean atomic number of the composition.
 
Composition subset (const std::vector< std::string > &symbols, const std::string &method="norm") const
 Creates a new Composition object containing a subset of species from this one.
 
bool hasSymbol (const std::string &symbol) const
 Checks if a symbol is registered in the composition.
 
bool contains (const fourdst::atomic::Species &isotope) const
 Checks if a given isotope is present in the composition.
 
void setCompositionMode (bool massFracMode)
 Sets the composition mode (mass fraction vs. number fraction).
 
CanonicalComposition getCanonicalComposition (bool harsh=false) const
 Gets the current canonical composition (X, Y, Z).
 
Composition operator+ (const Composition &other) const
 Overloads the + operator to mix two compositions with a 50/50 fraction.
 
auto begin ()
 Returns an iterator to the beginning of the composition map.
 
auto begin () const
 Returns a const iterator to the beginning of the composition map.
 
auto end ()
 Returns an iterator to the end of the composition map.
 
auto end () const
 Returns a const iterator to the end of the composition map.
 

Private Member Functions

bool isValidComposition (const std::vector< double > &fractions) const
 Checks if the given fractions are valid (sum to ~1.0).
 
void validateComposition (const std::vector< double > &fractions) const
 Validates the given fractions, throwing an exception on failure.
 
bool finalizeMassFracMode (bool norm)
 Finalizes the composition in mass fraction mode.
 
bool finalizeNumberFracMode (bool norm)
 Finalizes the composition in number fraction mode.
 

Static Private Member Functions

static bool isValidSymbol (const std::string &symbol)
 Checks if the given symbol is valid by checking against the global species database.
 

Private Attributes

fourdst::config::Config & m_config = fourdst::config::Config::getInstance()
 
fourdst::logging::LogManager & m_logManager = fourdst::logging::LogManager::getInstance()
 
quill::Logger * m_logger = m_logManager.getLogger("log")
 
bool m_finalized = false
 True if the composition is finalized.
 
double m_specificNumberDensity = 0.0
 The specific number density of the composition (\sum_{i} X_i m_i. Where X_i is the number fraction of the ith species and m_i is the mass of the ith species).
 
double m_meanParticleMass = 0.0
 The mean particle mass of the composition (\sum_{i} \frac{n_i}{m_i}. where n_i is the number fraction of the ith species and m_i is the mass of the ith species).
 
bool m_massFracMode = true
 True if mass fraction mode, false if number fraction mode.
 
std::set< std::string > m_registeredSymbols
 The registered symbols.
 
std::unordered_map< std::string, CompositionEntrym_compositions
 The compositions.
 

Friends

std::ostream & operator<< (std::ostream &os, const Composition &composition)
 Overloaded output stream operator for Composition.
 

Detailed Description

Manages a collection of chemical species and their abundances.

This class is a primary interface for defining and manipulating material compositions. It can operate in two modes: mass fraction or number fraction.

Key Rules and Workflow:

  1. Registration: Before setting an abundance for a species, its symbol (e.g., "He-4") must be registered using registerSymbol() or registerSpecies(). All registered species must conform to the same abundance mode (mass or number fraction).
  2. Setting Abundances: Use setMassFraction() or setNumberFraction() to define the composition.
  3. Finalization: Before querying any compositional data (e.g., getMassFraction(), getMeanParticleMass()), the composition must be finalized by calling finalize(). This step validates the composition (abundances sum to ~1.0) and computes global properties.
  4. Modification: Any modification to abundances after finalization will un-finalize the composition, requiring another call to finalize() before data can be retrieved again.
  5. Construction: A pre-finalized composition can be created by providing symbols and valid, normalized abundances to the constructor.
Exceptions
Thisclass throws various exceptions from fourdst::composition::exceptions for invalid operations, such as using unregistered symbols, providing invalid abundances, or accessing data from a non-finalized composition.
Mass Fraction Example:
comp.registerSymbol("H-1");
comp.registerSymbol("He-4");
comp.setMassFraction("H-1", 0.75);
comp.setMassFraction("He-4", 0.25);
if (comp.finalize()) {
double he_mass_frac = comp.getMassFraction("He-4"); // Returns 0.25
}
void registerSymbol(const std::string &symbol, bool massFracMode=true)
Registers a new symbol for inclusion in the composition.
Composition()=default
Default constructor.
double setMassFraction(const std::string &symbol, const double &mass_fraction)
Sets the mass fraction for a given symbol.
bool finalize(bool norm=false)
Finalizes the composition, making it ready for querying.
std::unordered_map< std::string, double > getMassFraction() const
Gets the mass fractions of all species in the composition.
Number Fraction Example:
comp.registerSymbol("H-1", false); // Register in number fraction mode
comp.registerSymbol("He-4", false);
comp.setNumberFraction("H-1", 0.9);
comp.setNumberFraction("He-4", 0.1);
if (comp.finalize()) {
double he_num_frac = comp.getNumberFraction("He-4"); // Returns 0.1
}
double setNumberFraction(const std::string &symbol, const double &number_fraction)
Sets the number fraction for a given symbol.
double getNumberFraction(const std::string &symbol) const
Gets the number fraction for a given symbol.

Definition at line 258 of file composition.h.

Constructor & Destructor Documentation

◆ Composition() [1/5]

fourdst::composition::Composition::Composition ( )
default

Default constructor.

◆ ~Composition()

fourdst::composition::Composition::~Composition ( )
default

Default destructor.

◆ Composition() [2/5]

fourdst::composition::Composition::Composition ( const std::vector< std::string > & symbols)
explicit

Constructs a Composition and registers the given symbols.

Parameters
symbolsThe symbols to register. The composition will be in mass fraction mode by default.
Exceptions
exceptions::InvalidSymbolErrorif any symbol is invalid.
Usage Example:
std::vector<std::string> symbols = {"H-1", "O-16"};
Composition comp(symbols);
comp.setMassFraction("H-1", 0.11);
comp.setMassFraction("O-16", 0.89);
comp.finalize();
Manages a collection of chemical species and their abundances.

Definition at line 151 of file composition.cpp.

◆ Composition() [3/5]

fourdst::composition::Composition::Composition ( const std::set< std::string > & symbols)
explicit

Constructs a Composition and registers the given symbols from a set.

Parameters
symbolsThe symbols to register. The composition will be in mass fraction mode by default.
Exceptions
exceptions::InvalidSymbolErrorif any symbol is invalid.
Usage Example:
std::set<std::string> symbols = {"H-1", "O-16"};
Composition comp(symbols);

Definition at line 157 of file composition.cpp.

◆ Composition() [4/5]

fourdst::composition::Composition::Composition ( const std::vector< std::string > & symbols,
const std::vector< double > & fractions,
bool massFracMode = true )

Constructs and finalizes a Composition with the given symbols and fractions.

This constructor provides a convenient way to create a fully-formed, finalized composition in one step. The provided fractions must be valid and sum to 1.0.

Parameters
symbolsThe symbols to initialize the composition with.
fractionsThe fractions (mass or number) corresponding to the symbols.
massFracModeTrue if fractions are mass fractions, false if they are number fractions. [Default: true]
Exceptions
exceptions::InvalidCompositionErrorif the number of symbols and fractions do not match, or if the fractions do not sum to ~1.0.
exceptions::InvalidSymbolErrorif any symbol is invalid.
Postcondition
The composition is immediately finalized.
Usage Example:
std::vector<std::string> symbols = {"H-1", "O-16"};
std::vector<double> mass_fractions = {0.1119, 0.8881};
Composition comp(symbols, mass_fractions); // Finalized on construction

Definition at line 163 of file composition.cpp.

◆ Composition() [5/5]

fourdst::composition::Composition::Composition ( const Composition & composition)

Constructs a Composition from another Composition.

Parameters
compositionThe Composition to copy.

Definition at line 185 of file composition.cpp.

Member Function Documentation

◆ begin() [1/2]

auto fourdst::composition::Composition::begin ( )
inline

Returns an iterator to the beginning of the composition map.

Returns
An iterator to the beginning.

Definition at line 759 of file composition.h.

◆ begin() [2/2]

auto fourdst::composition::Composition::begin ( ) const
inline

Returns a const iterator to the beginning of the composition map.

Returns
A const iterator to the beginning.

Definition at line 767 of file composition.h.

◆ contains()

bool fourdst::composition::Composition::contains ( const fourdst::atomic::Species & isotope) const
nodiscard

Checks if a given isotope is present in the composition.

Precondition
The composition must be finalized.
Parameters
isotopeThe isotope to check for.
Returns
True if the isotope is in the composition, false otherwise.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.

Definition at line 741 of file composition.cpp.

◆ end() [1/2]

auto fourdst::composition::Composition::end ( )
inline

Returns an iterator to the end of the composition map.

Returns
An iterator to the end.

Definition at line 775 of file composition.h.

◆ end() [2/2]

auto fourdst::composition::Composition::end ( ) const
inline

Returns a const iterator to the end of the composition map.

Returns
A const iterator to the end.

Definition at line 783 of file composition.h.

◆ finalize()

bool fourdst::composition::Composition::finalize ( bool norm = false)

Finalizes the composition, making it ready for querying.

This method checks if the sum of all fractions (mass or number) is approximately 1.0. It also computes global properties like mean particle mass. This must be called before any get... method can be used.

Parameters
normIf true, the composition will be normalized to sum to 1 before validation. [Default: false]
Returns
True if the composition is valid and successfully finalized, false otherwise.
Postcondition
If successful, m_finalized is true and global properties are computed.

Definition at line 389 of file composition.cpp.

◆ finalizeMassFracMode()

bool fourdst::composition::Composition::finalizeMassFracMode ( bool norm)
private

Finalizes the composition in mass fraction mode.

Parameters
normIf true, the composition will be normalized to sum to 1.
Returns
True if the composition is successfully finalized, false otherwise.

Definition at line 402 of file composition.cpp.

◆ finalizeNumberFracMode()

bool fourdst::composition::Composition::finalizeNumberFracMode ( bool norm)
private

Finalizes the composition in number fraction mode.

Parameters
normIf true, the composition will be normalized to sum to 1.
Returns
True if the composition is successfully finalized, false otherwise.

Definition at line 439 of file composition.cpp.

◆ getCanonicalComposition()

CanonicalComposition fourdst::composition::Composition::getCanonicalComposition ( bool harsh = false) const
nodiscard

Gets the current canonical composition (X, Y, Z).

Calculates the total mass fractions for H, He, and metals.

Precondition
The composition must be finalized.
Parameters
harshIf true, this will throw an error if 1 - (X + Y) is not equal to the directly summed Z (within a tolerance). If false, it will only log a warning.
Returns
The CanonicalComposition struct.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.
std::runtime_errorif harsh is true and the canonical composition is not self-consistent.

Definition at line 690 of file composition.cpp.

◆ getComposition() [1/3]

std::pair< std::unordered_map< std::string, CompositionEntry >, GlobalComposition > fourdst::composition::Composition::getComposition ( ) const
nodiscard

Gets all composition entries and the global composition data.

Precondition
The composition must be finalized.
Returns
A pair containing an unordered map of all CompositionEntries and the GlobalComposition.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.

Definition at line 605 of file composition.cpp.

◆ getComposition() [2/3]

std::pair< CompositionEntry, GlobalComposition > fourdst::composition::Composition::getComposition ( const fourdst::atomic::Species & species) const
nodiscard

Gets the composition entry and global composition data for a given species.

Precondition
The composition must be finalized.
Parameters
speciesThe species to get the composition for.
Returns
A pair containing the CompositionEntry and GlobalComposition for the given species.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.
exceptions::UnregisteredSymbolErrorif the species is not in the composition.

Definition at line 600 of file composition.cpp.

◆ getComposition() [3/3]

std::pair< CompositionEntry, GlobalComposition > fourdst::composition::Composition::getComposition ( const std::string & symbol) const
nodiscard

Gets the composition entry and global composition data for a given symbol.

Precondition
The composition must be finalized.
Parameters
symbolThe symbol to get the composition for.
Returns
A pair containing the CompositionEntry and GlobalComposition for the given symbol.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.
exceptions::UnregisteredSymbolErrorif the symbol is not in the composition.

Definition at line 588 of file composition.cpp.

◆ getMassFraction() [1/3]

std::unordered_map< std::string, double > fourdst::composition::Composition::getMassFraction ( ) const
nodiscard

Gets the mass fractions of all species in the composition.

Precondition
The composition must be finalized.
Returns
An unordered map of symbols to their mass fractions.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.

Definition at line 534 of file composition.cpp.

◆ getMassFraction() [2/3]

double fourdst::composition::Composition::getMassFraction ( const fourdst::atomic::Species & species) const
nodiscard

Gets the mass fraction for a given isotope.

Precondition
The composition must be finalized.
Parameters
speciesThe isotope to get the mass fraction for.
Returns
The mass fraction for the given isotope.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.
exceptions::UnregisteredSymbolErrorif the isotope is not registered in the composition.

Definition at line 530 of file composition.cpp.

◆ getMassFraction() [3/3]

double fourdst::composition::Composition::getMassFraction ( const std::string & symbol) const
nodiscard

Gets the mass fraction for a given symbol.

Precondition
The composition must be finalized.
Parameters
symbolThe symbol to get the mass fraction for.
Returns
The mass fraction for the given symbol.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.
exceptions::UnregisteredSymbolErrorif the symbol is not in the composition.

Definition at line 503 of file composition.cpp.

◆ getMeanAtomicNumber()

double fourdst::composition::Composition::getMeanAtomicNumber ( ) const
nodiscard

Compute the mean atomic number of the composition.

Precondition
The composition must be finalized.
Returns
Mean atomic number <Z>.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.

Definition at line 621 of file composition.cpp.

◆ getMeanParticleMass()

double fourdst::composition::Composition::getMeanParticleMass ( ) const
nodiscard

Compute the mean particle mass of the composition.

Precondition
The composition must be finalized.
Returns
Mean particle mass in atomic mass units (g/mol).
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.

Definition at line 613 of file composition.cpp.

◆ getMolarAbundance() [1/2]

double fourdst::composition::Composition::getMolarAbundance ( const fourdst::atomic::Species & species) const
nodiscard

Gets the molar abundance for a given isotope.

Precondition
The composition must be finalized.
Parameters
speciesThe isotope to get the molar abundance for.
Returns
The molar abundance for the given isotope.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.
exceptions::UnregisteredSymbolErrorif the isotope is not registered in the composition.

Definition at line 584 of file composition.cpp.

◆ getMolarAbundance() [2/2]

double fourdst::composition::Composition::getMolarAbundance ( const std::string & symbol) const
nodiscard

Gets the molar abundance (X_i / A_i) for a given symbol.

Precondition
The composition must be finalized.
Parameters
symbolThe symbol to get the molar abundance for.
Returns
The molar abundance for the given symbol.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.
exceptions::UnregisteredSymbolErrorif the symbol is not in the composition.

Definition at line 571 of file composition.cpp.

◆ getNumberFraction() [1/3]

std::unordered_map< std::string, double > fourdst::composition::Composition::getNumberFraction ( ) const
nodiscard

Gets the number fractions of all species in the composition.

Precondition
The composition must be finalized.
Returns
An unordered map of symbols to their number fractions.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.

Definition at line 563 of file composition.cpp.

◆ getNumberFraction() [2/3]

double fourdst::composition::Composition::getNumberFraction ( const fourdst::atomic::Species & species) const
nodiscard

Gets the number fraction for a given isotope.

Precondition
The composition must be finalized.
Parameters
speciesThe isotope to get the number fraction for.
Returns
The number fraction for the given isotope.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.
exceptions::UnregisteredSymbolErrorif the isotope is not registered in the composition.

Definition at line 559 of file composition.cpp.

◆ getNumberFraction() [3/3]

double fourdst::composition::Composition::getNumberFraction ( const std::string & symbol) const
nodiscard

Gets the number fraction for a given symbol.

Precondition
The composition must be finalized.
Parameters
symbolThe symbol to get the number fraction for.
Returns
The number fraction for the given symbol.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.
exceptions::UnregisteredSymbolErrorif the symbol is not in the composition.

Definition at line 543 of file composition.cpp.

◆ getRegisteredSpecies()

std::set< fourdst::atomic::Species > fourdst::composition::Composition::getRegisteredSpecies ( ) const
nodiscard

Get a set of all species that are registered in the composition.

Returns
A set of atomic::Species objects registered in the composition.

Definition at line 255 of file composition.cpp.

◆ getRegisteredSymbols()

std::set< std::string > fourdst::composition::Composition::getRegisteredSymbols ( ) const
nodiscard

Gets the registered symbols.

Returns
A set of registered symbols.

Definition at line 251 of file composition.cpp.

◆ hasSymbol()

bool fourdst::composition::Composition::hasSymbol ( const std::string & symbol) const
nodiscard

Checks if a symbol is registered in the composition.

Parameters
symbolThe symbol to check.
Returns
True if the symbol is registered, false otherwise.

Definition at line 737 of file composition.cpp.

◆ isValidComposition()

bool fourdst::composition::Composition::isValidComposition ( const std::vector< double > & fractions) const
nodiscardprivate

Checks if the given fractions are valid (sum to ~1.0).

Parameters
fractionsThe fractions to check.
Returns
True if the fractions are valid, false otherwise.

Definition at line 270 of file composition.cpp.

◆ isValidSymbol()

bool fourdst::composition::Composition::isValidSymbol ( const std::string & symbol)
staticprivate

Checks if the given symbol is valid by checking against the global species database.

Parameters
symbolThe symbol to check.
Returns
True if the symbol is valid, false otherwise.

Definition at line 283 of file composition.cpp.

◆ mix()

Composition fourdst::composition::Composition::mix ( const Composition & other,
double fraction ) const
nodiscard

Mixes this composition with another to produce a new composition.

The mixing is performed linearly on the mass fractions. The formula for each species is: new_X_i = fraction * this_X_i + (1 - fraction) * other_X_i. The resulting composition is automatically finalized.

Parameters
otherThe other composition to mix with.
fractionThe mixing fraction. A value of 1.0 means the new composition is 100% this, 0.0 means 100% other.
Returns
A new, finalized Composition object representing the mixture.
Precondition
Both this and other compositions must be finalized.
Exceptions
exceptions::CompositionNotFinalizedErrorif either composition is not finalized.
exceptions::InvalidCompositionErrorif the fraction is not between 0 and 1.

Definition at line 473 of file composition.cpp.

◆ operator+()

Composition fourdst::composition::Composition::operator+ ( const Composition & other) const

Overloads the + operator to mix two compositions with a 50/50 fraction.

OVERLOADS.

This is a convenience operator that calls mix(other, 0.5).

Parameters
otherThe other composition to mix with.
Returns
The new, mixed composition.
Precondition
Both compositions must be finalized.
Exceptions
Seemix() for exceptions.

Definition at line 756 of file composition.cpp.

◆ operator=()

Composition & fourdst::composition::Composition::operator= ( Composition const & other)

Assignment operator.

Parameters
otherThe Composition to assign from.
Returns
A reference to this Composition.

Definition at line 194 of file composition.cpp.

◆ registerSpecies() [1/2]

void fourdst::composition::Composition::registerSpecies ( const fourdst::atomic::Species & species,
bool massFracMode = true )

Registers a new species by extracting its symbol.

Parameters
speciesThe species to register.
massFracModeTrue for mass fraction mode, false for number fraction mode.
Exceptions
exceptions::InvalidSymbolErrorif the species' symbol is invalid.
exceptions::CompositionModeErrorif the mode conflicts.
Usage Example:
#include "fourdst/composition/species.h" // Assuming species like H1 are defined here
void registerSpecies(const fourdst::atomic::Species &species, bool massFracMode=true)
Registers a new species by extracting its symbol.
static const std::unordered_map< std::string, const Species & > species
Definition species.h:3580

Definition at line 241 of file composition.cpp.

◆ registerSpecies() [2/2]

void fourdst::composition::Composition::registerSpecies ( const std::vector< fourdst::atomic::Species > & species,
bool massFracMode = true )

Registers a vector of new species.

Parameters
speciesThe vector of species to register.
massFracModeTrue for mass fraction mode, false for number fraction mode.
Exceptions
exceptions::InvalidSymbolErrorif any species' symbol is invalid.
exceptions::CompositionModeErrorif the mode conflicts.
Usage Example:
std::vector<fourdst::atomic::Species> my_species = { ... };
comp.registerSpecies(my_species, false); // Number fraction mode

Definition at line 245 of file composition.cpp.

◆ registerSymbol() [1/2]

void fourdst::composition::Composition::registerSymbol ( const std::string & symbol,
bool massFracMode = true )

Registers a new symbol for inclusion in the composition.

A symbol must be registered before its abundance can be set. The first registration sets the mode (mass/number fraction) for the entire composition.

Parameters
symbolThe symbol to register (e.g., "Fe-56").
massFracModeTrue for mass fraction mode, false for number fraction mode. This is only effective for the first symbol registered.
Exceptions
exceptions::InvalidSymbolErrorif the symbol is not in the atomic species database.
exceptions::CompositionModeErrorif attempting to register with a mode that conflicts with the existing mode.
Usage Example:
comp.registerSymbol("H-1"); // Now in mass fraction mode
comp.registerSymbol("He-4"); // Must also be mass fraction mode

Definition at line 208 of file composition.cpp.

◆ registerSymbol() [2/2]

void fourdst::composition::Composition::registerSymbol ( const std::vector< std::string > & symbols,
bool massFracMode = true )

Registers multiple new symbols.

Parameters
symbolsThe symbols to register.
massFracModeTrue for mass fraction mode, false for number fraction mode.
Exceptions
exceptions::InvalidSymbolErrorif any symbol is invalid.
exceptions::CompositionModeErrorif the mode conflicts with an already set mode.
Usage Example:
std::vector<std::string> symbols = {"H-1", "O-16"};
comp.registerSymbol(symbols);

Definition at line 235 of file composition.cpp.

◆ setCompositionMode()

void fourdst::composition::Composition::setCompositionMode ( bool massFracMode)

Sets the composition mode (mass fraction vs. number fraction).

This function converts all entries in the composition to the specified mode.

Precondition
The composition must be finalized before the mode can be switched.
Parameters
massFracModeTrue to switch to mass fraction mode, false for number fraction mode.
Exceptions
exceptions::CompositionNotFinalizedErrorif the composition is not finalized.
std::runtime_errorif the conversion fails for an unknown reason.

Definition at line 669 of file composition.cpp.

◆ setMassFraction() [1/4]

double fourdst::composition::Composition::setMassFraction ( const fourdst::atomic::Species & species,
const double & mass_fraction )

Sets the mass fraction for a given species.

Parameters
speciesThe species to set the mass fraction for.
mass_fractionThe mass fraction to set.
Returns
The previous mass fraction that was set for the species.
Exceptions
exceptions::UnregisteredSymbolErrorif the species is not registered.
exceptions::CompositionModeErrorif the composition is in number fraction mode.
exceptions::InvalidCompositionErrorif the mass fraction is not between 0 and 1.

Definition at line 324 of file composition.cpp.

◆ setMassFraction() [2/4]

double fourdst::composition::Composition::setMassFraction ( const std::string & symbol,
const double & mass_fraction )

Sets the mass fraction for a given symbol.

Parameters
symbolThe symbol to set the mass fraction for.
mass_fractionThe mass fraction to set (must be in [0, 1]).
Returns
The previous mass fraction that was set for the symbol.
Exceptions
exceptions::UnregisteredSymbolErrorif the symbol is not registered.
exceptions::CompositionModeErrorif the composition is in number fraction mode.
exceptions::InvalidCompositionErrorif the mass fraction is not between 0 and 1.
Postcondition
The composition is marked as not finalized.
Usage Example:
comp.registerSymbol("H-1");
comp.setMassFraction("H-1", 0.7);

Definition at line 287 of file composition.cpp.

◆ setMassFraction() [3/4]

std::vector< double > fourdst::composition::Composition::setMassFraction ( const std::vector< fourdst::atomic::Species > & species,
const std::vector< double > & mass_fractions )

Sets the mass fraction for multiple species.

Parameters
speciesThe vector of species to set the mass fractions for.
mass_fractionsThe vector of mass fractions corresponding to the species.
Returns
A vector of the previous mass fractions that were set.
Exceptions
SeesetMassFraction(const std::vector<std::string>&, const std::vector<double>&) for exceptions.

Definition at line 328 of file composition.cpp.

◆ setMassFraction() [4/4]

std::vector< double > fourdst::composition::Composition::setMassFraction ( const std::vector< std::string > & symbols,
const std::vector< double > & mass_fractions )

Sets the mass fraction for multiple symbols.

Parameters
symbolsThe symbols to set the mass fractions for.
mass_fractionsThe mass fractions corresponding to the symbols.
Returns
A vector of the previous mass fractions that were set.
Exceptions
exceptions::InvalidCompositionErrorif symbol and fraction counts differ.
SeesetMassFraction(const std::string&, const double&) for other exceptions.
Postcondition
The composition is marked as not finalized.

Definition at line 310 of file composition.cpp.

◆ setNumberFraction() [1/4]

double fourdst::composition::Composition::setNumberFraction ( const fourdst::atomic::Species & species,
const double & number_fraction )

Sets the number fraction for a given species.

Parameters
speciesThe species to set the number fraction for.
number_fractionThe number fraction to set for the species.
Returns
The previous number fraction that was set for the species.
Exceptions
exceptions::UnregisteredSymbolErrorif the species is not registered.
exceptions::CompositionModeErrorif the composition is in mass fraction mode.
exceptions::InvalidCompositionErrorif the number fraction is not between 0 and 1.

Definition at line 375 of file composition.cpp.

◆ setNumberFraction() [2/4]

double fourdst::composition::Composition::setNumberFraction ( const std::string & symbol,
const double & number_fraction )

Sets the number fraction for a given symbol.

Parameters
symbolThe symbol to set the number fraction for.
number_fractionThe number fraction to set (must be in [0, 1]).
Returns
The previous number fraction that was set.
Exceptions
exceptions::UnregisteredSymbolErrorif the symbol is not registered.
exceptions::CompositionModeErrorif the composition is in mass fraction mode.
exceptions::InvalidCompositionErrorif the number fraction is not between 0 and 1.
Postcondition
The composition is marked as not finalized.

Definition at line 338 of file composition.cpp.

◆ setNumberFraction() [3/4]

std::vector< double > fourdst::composition::Composition::setNumberFraction ( const std::vector< fourdst::atomic::Species > & species,
const std::vector< double > & number_fractions )

Sets the number fraction for multiple species.

Parameters
speciesThe vector of species to set the number fractions for.
number_fractionsThe vector of number fractions corresponding to the species.
Returns
The vector of the previous number fractions that were set.
Exceptions
SeesetNumberFraction(const std::vector<std::string>&, const std::vector<double>&) for exceptions.

Definition at line 379 of file composition.cpp.

◆ setNumberFraction() [4/4]

std::vector< double > fourdst::composition::Composition::setNumberFraction ( const std::vector< std::string > & symbols,
const std::vector< double > & number_fractions )

Sets the number fraction for multiple symbols.

Parameters
symbolsThe symbols to set the number fractions for.
number_fractionsThe number fractions corresponding to the symbols.
Returns
A vector of the previous number fractions that were set.
Exceptions
exceptions::InvalidCompositionErrorif symbol and fraction counts differ.
SeesetNumberFraction(const std::string&, const double&) for other exceptions.

Definition at line 361 of file composition.cpp.

◆ subset()

Composition fourdst::composition::Composition::subset ( const std::vector< std::string > & symbols,
const std::string & method = "norm" ) const
nodiscard

Creates a new Composition object containing a subset of species from this one.

Parameters
symbolsThe symbols to include in the subset.
methodThe method for handling the abundances of the new subset. Can be "norm" (normalize abundances to sum to 1) or "none" (keep original abundances).
Returns
A new Composition object containing the subset.
Exceptions
exceptions::UnregisteredSymbolErrorif any requested symbol is not in the original composition.
exceptions::InvalidMixingModeif an invalid method is provided.
exceptions::FailedToFinalizeCompositionErrorif normalization fails.

Definition at line 640 of file composition.cpp.

◆ validateComposition()

void fourdst::composition::Composition::validateComposition ( const std::vector< double > & fractions) const
private

Validates the given fractions, throwing an exception on failure.

Parameters
fractionsThe fractions to validate.
Exceptions
exceptions::InvalidCompositionErrorif the fractions are invalid.

Definition at line 263 of file composition.cpp.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Composition & composition )
friend

Overloaded output stream operator for Composition.

Parameters
osThe output stream.
compositionThe Composition to output.
Returns
The output stream.

Definition at line 772 of file composition.cpp.

Member Data Documentation

◆ m_compositions

std::unordered_map<std::string, CompositionEntry> fourdst::composition::Composition::m_compositions
private

The compositions.

Definition at line 270 of file composition.h.

◆ m_config

fourdst::config::Config& fourdst::composition::Composition::m_config = fourdst::config::Config::getInstance()
private

Definition at line 260 of file composition.h.

◆ m_finalized

bool fourdst::composition::Composition::m_finalized = false
private

True if the composition is finalized.

Definition at line 264 of file composition.h.

◆ m_logger

quill::Logger* fourdst::composition::Composition::m_logger = m_logManager.getLogger("log")
private

Definition at line 262 of file composition.h.

◆ m_logManager

fourdst::logging::LogManager& fourdst::composition::Composition::m_logManager = fourdst::logging::LogManager::getInstance()
private

Definition at line 261 of file composition.h.

◆ m_massFracMode

bool fourdst::composition::Composition::m_massFracMode = true
private

True if mass fraction mode, false if number fraction mode.

Definition at line 267 of file composition.h.

◆ m_meanParticleMass

double fourdst::composition::Composition::m_meanParticleMass = 0.0
private

The mean particle mass of the composition (\sum_{i} \frac{n_i}{m_i}. where n_i is the number fraction of the ith species and m_i is the mass of the ith species).

Definition at line 266 of file composition.h.

◆ m_registeredSymbols

std::set<std::string> fourdst::composition::Composition::m_registeredSymbols
private

The registered symbols.

Definition at line 269 of file composition.h.

◆ m_specificNumberDensity

double fourdst::composition::Composition::m_specificNumberDensity = 0.0
private

The specific number density of the composition (\sum_{i} X_i m_i. Where X_i is the number fraction of the ith species and m_i is the mass of the ith species).

Definition at line 265 of file composition.h.


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