24#include <unordered_map>
29#include "fourdst/config/config.h"
30#include "fourdst/logging/logging.h"
55 os <<
"<CanonicalComposition: "
130 [[nodiscard]] std::string
symbol()
const;
145 [[nodiscard]]
double mass_fraction(
double meanMolarMass)
const;
260 fourdst::config::Config&
m_config = fourdst::config::Config::getInstance();
261 fourdst::logging::LogManager&
m_logManager = fourdst::logging::LogManager::getInstance();
342 explicit Composition(
const std::vector<std::string>& symbols);
354 explicit Composition(
const std::set<std::string>& symbols);
373 Composition(
const std::vector<std::string>& symbols,
const std::vector<double>& fractions,
bool massFracMode=
true);
402 void registerSymbol(
const std::string& symbol,
bool massFracMode=
true);
417 void registerSymbol(
const std::vector<std::string>& symbols,
bool massFracMode=
true);
449 void registerSpecies(
const std::vector<fourdst::atomic::Species>& species,
bool massFracMode=
true);
480 double setMassFraction(
const std::string& symbol,
const double& mass_fraction);
491 std::vector<double>
setMassFraction(
const std::vector<std::string>& symbols,
const std::vector<double>& mass_fractions);
511 std::vector<double>
setMassFraction(
const std::vector<fourdst::atomic::Species>& species,
const std::vector<double>& mass_fractions);
523 double setNumberFraction(
const std::string& symbol,
const double& number_fraction);
533 std::vector<double>
setNumberFraction(
const std::vector<std::string>& symbols,
const std::vector<double>& number_fractions);
553 std::vector<double>
setNumberFraction(
const std::vector<fourdst::atomic::Species>& species,
const std::vector<double>& number_fractions);
575 [[nodiscard]] std::unordered_map<std::string, double>
getMassFraction()
const;
653 [[nodiscard]] std::pair<CompositionEntry, GlobalComposition>
getComposition(
const std::string& symbol)
const;
698 [[nodiscard]]
Composition subset(
const std::vector<std::string>& symbols,
const std::string& method=
"norm")
const;
705 [[nodiscard]]
bool hasSymbol(
const std::string& symbol)
const;
void setCompositionMode(bool massFracMode)
Sets the composition mode (mass fraction vs. number fraction).
std::pair< std::unordered_map< std::string, CompositionEntry >, GlobalComposition > getComposition() const
Gets all composition entries and the global composition data.
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.
void registerSymbol(const std::string &symbol, bool massFracMode=true)
Registers a new symbol for inclusion in the composition.
Composition()=default
Default constructor.
Composition operator+(const Composition &other) const
Overloads the + operator to mix two compositions with a 50/50 fraction.
friend std::ostream & operator<<(std::ostream &os, const Composition &composition)
Overloaded output stream operator for Composition.
std::set< std::string > m_registeredSymbols
The registered symbols.
Composition mix(const Composition &other, double fraction) const
Mixes this composition with another to produce a new composition.
std::set< fourdst::atomic::Species > getRegisteredSpecies() const
Get a set of all species that are registered in the composition.
bool finalizeNumberFracMode(bool norm)
Finalizes the composition in number fraction mode.
double setMassFraction(const std::string &symbol, const double &mass_fraction)
Sets the mass fraction for a given symbol.
double m_meanParticleMass
The mean particle mass of the composition (\sum_{i} \frac{n_i}{m_i}. where n_i is the number fraction...
void registerSpecies(const fourdst::atomic::Species &species, bool massFracMode=true)
Registers a new species by extracting its symbol.
Composition & operator=(Composition const &other)
Assignment operator.
double getMeanParticleMass() const
Compute the mean particle mass of the composition.
bool m_massFracMode
True if mass fraction mode, false if number fraction mode.
double getMolarAbundance(const std::string &symbol) const
Gets the molar abundance (X_i / A_i) for a given symbol.
fourdst::logging::LogManager & m_logManager
bool hasSymbol(const std::string &symbol) const
Checks if a symbol is registered in the composition.
bool finalize(bool norm=false)
Finalizes the composition, making it ready for querying.
std::unordered_map< std::string, double > getNumberFraction() const
Gets the number fractions of all species in the composition.
double setNumberFraction(const std::string &symbol, const double &number_fraction)
Sets the number fraction for a given symbol.
std::set< std::string > getRegisteredSymbols() const
Gets the registered symbols.
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.
fourdst::config::Config & m_config
static bool isValidSymbol(const std::string &symbol)
Checks if the given symbol is valid by checking against the global species database.
double getMeanAtomicNumber() const
Compute the mean atomic number of the composition.
bool m_finalized
True if the composition is finalized.
~Composition()=default
Default destructor.
std::unordered_map< std::string, CompositionEntry > m_compositions
The compositions.
auto begin()
Returns an iterator to the beginning of the composition map.
CanonicalComposition getCanonicalComposition(bool harsh=false) const
Gets the current canonical composition (X, Y, Z).
bool contains(const fourdst::atomic::Species &isotope) const
Checks if a given isotope is present in the composition.
std::unordered_map< std::string, double > getMassFraction() const
Gets the mass fractions of all species in the composition.
double m_specificNumberDensity
The specific number density of the composition (\sum_{i} X_i m_i. Where X_i is the number fraction of...
bool isValidComposition(const std::vector< double > &fractions) const
Checks if the given fractions are valid (sum to ~1.0).
auto end()
Returns an iterator to the end of the composition map.
auto begin() const
Returns a const iterator to the beginning of the composition map.
auto end() const
Returns a const iterator to the end of the composition map.
Represents an atomic species (isotope) with its fundamental physical properties.
Represents the canonical (X, Y, Z) composition of stellar material.
friend std::ostream & operator<<(std::ostream &os, const CanonicalComposition &composition)
Overloads the stream insertion operator for easy printing.
double Y
Mass fraction of Helium.
double X
Mass fraction of Hydrogen.
double Z
Mass fraction of Metals.
double m_relAbundance
The relative abundance, used internally for conversions. For mass fraction mode, this is X_i / A_i; f...
bool getMassFracMode() const
Gets the mode of the composition entry.
CompositionEntry()
Default constructor. Initializes a default entry (H-1), but in an uninitialized state.
bool m_massFracMode
The mode of the composition entry. True if mass fraction, false if number fraction.
double m_numberFraction
The number fraction (mole fraction) of the species. Valid only if m_massFracMode is false.
double number_fraction() const
Gets the number fraction of the species.
bool m_initialized
True if the composition entry has been initialized with a valid species.
bool setMassFracMode(double meanMolarMass)
Switches the mode to mass fraction mode.
void setMassFraction(double mass_fraction)
Sets the mass fraction of the species.
std::string symbol() const
Gets the chemical symbol of the species.
void setSpecies(const std::string &symbol)
Sets the species for the composition entry. This can only be done once.
double mass_fraction() const
Gets the mass fraction of the species.
bool setNumberFracMode(double totalMoles)
Switches the mode to number fraction mode.
atomic::Species m_isotope
The atomic::Species object containing detailed isotope data.
void setNumberFraction(double number_fraction)
Sets the number fraction of the species.
double rel_abundance() const
Gets the relative abundance of the species.
std::string m_symbol
The chemical symbol of the species (e.g., "H-1", "Fe-56").
double m_massFraction
The mass fraction of the species. Valid only if m_massFracMode is true.
friend std::ostream & operator<<(std::ostream &os, const CompositionEntry &entry)
Overloaded output stream operator for CompositionEntry.
atomic::Species isotope() const
Gets the isotope data for the species.
Represents global properties of a finalized composition.
double specificNumberDensity
The specific number density (moles per unit mass, sum of X_i/M_i), where X_i is mass fraction and M_i...
friend std::ostream & operator<<(std::ostream &os, const GlobalComposition &comp)
double meanParticleMass
The mean mass per particle (inverse of specific number density). Units: g/mol.