25#include <unordered_map>
33#include "atomicSpecies.h"
42 os <<
"<CanonicalComposition: "
107 std::string
symbol()
const;
145 serif::atomic::Species
isotope()
const;
218 serif::config::Config&
m_config = serif::config::Config::getInstance();
293 explicit Composition(
const std::vector<std::string>& symbols);
304 explicit Composition(
const std::set<std::string>& symbols);
318 Composition(
const std::vector<std::string>& symbols,
const std::vector<double>& mass_fractions,
bool massFracMode=
true);
338 void registerSymbol(
const std::string& symbol,
bool massFracMode=
true);
351 void registerSymbol(
const std::vector<std::string>& symbols,
bool massFracMode=
true);
370 double setMassFraction(
const std::string& symbol,
const double& mass_fraction);
385 std::vector<double>
setMassFraction(
const std::vector<std::string>& symbols,
const std::vector<double>& mass_fractions);
393 double setNumberFraction(
const std::string& symbol,
const double& number_fraction);
401 std::vector<double>
setNumberFraction(
const std::vector<std::string>& symbols,
const std::vector<double>& number_fractions);
414 [[nodiscard]] std::unordered_map<std::string, double>
getMassFraction()
const;
441 [[nodiscard]] std::pair<CompositionEntry, GlobalComposition>
getComposition(
const std::string& symbol)
const;
467 Composition subset(
const std::vector<std::string>& symbols, std::string method=
"norm")
const;
474 bool hasSymbol(
const std::string& symbol)
const;
476 bool contains(
const serif::atomic::Species& isotope)
const;
bool hasSymbol(const std::string &symbol) const
Check if a symbol is registered.
std::unordered_map< std::string, double > getMassFraction() const
Gets the mass fractions of all compositions.
bool isValidComposition(const std::vector< double > &fractions) const
Checks if the given mass fractions are valid.
double getMeanAtomicNumber() const
Compute the mean atomic mass number of the composition.
bool contains(const serif::atomic::Species &isotope) const
friend std::ostream & operator<<(std::ostream &os, const Composition &composition)
Overloaded output stream operator for Composition.
double m_meanParticleMass
The mean particle mass of the composition (\sum_{i} \frac{n_i}{m_i}. where n_i is the number fraction...
bool finalizeMassFracMode(bool norm)
Finalizes the composition in mass fraction mode.
std::set< std::string > getRegisteredSymbols() const
Gets the registered symbols.
serif::config::Config & m_config
Composition()=default
Default constructor.
Composition mix(const Composition &other, double fraction) const
Mix two compositions together with a given fraction.
serif::probe::LogManager & m_logManager
~Composition()=default
Default destructor.
double m_specificNumberDensity
The specific number density of the composition (\sum_{i} X_i m_i. Where X_i is the number fraction of...
void registerSymbol(const std::string &symbol, bool massFracMode=true)
Registers a new symbol.
std::set< std::string > m_registeredSymbols
The registered symbols.
Composition subset(const std::vector< std::string > &symbols, std::string method="norm") const
Gets a subset of the composition.
std::unordered_map< std::string, double > getNumberFraction() const
Gets the number fractions of all compositions.
bool finalize(bool norm=false)
Finalizes the composition.
double setMassFraction(const std::string &symbol, const double &mass_fraction)
Sets the mass fraction for a given symbol.
bool m_finalized
True if the composition is finalized.
bool finalizeNumberFracMode(bool norm)
Finalizes the composition in number fraction mode.
std::pair< std::unordered_map< std::string, CompositionEntry >, GlobalComposition > getComposition() const
Gets all composition entries and the global composition.
Composition & operator=(Composition const &other)
Composition operator+(const Composition &other) const
Overloads the + operator to mix two compositions together with a fraction of 0.5.
bool m_massFracMode
True if mass fraction mode, false if number fraction mode.
CanonicalComposition getCanonicalComposition(bool harsh=false) const
Gets the current canonical composition (X, Y, Z).
double getMeanParticleMass() const
Compute the mean particle mass of the composition.
std::unordered_map< std::string, CompositionEntry > m_compositions
The compositions.
double setNumberFraction(const std::string &symbol, const double &number_fraction)
Sets the number fraction for a given symbol.
void validateComposition(const std::vector< double > &fractions) const
Validates the given mass fractions.
void setCompositionMode(bool massFracMode)
Sets the composition mode.
static bool isValidSymbol(const std::string &symbol)
Checks if the given symbol is valid.
Class to manage logging operations.
static LogManager & getInstance()
Get the singleton instance of LogManager.
double X
Mass fraction of Hydrogen.
friend std::ostream & operator<<(std::ostream &os, const CanonicalComposition &composition)
double Z
Mass fraction of Metals.
double Y
Mass fraction of Helium.
std::string symbol() const
Gets the chemical symbol of the species.
serif::atomic::Species isotope() const
Gets the isotope of the species.
double rel_abundance() const
Gets the relative abundance of the species.
bool setNumberFracMode(double totalMoles)
Sets the mode to number fraction mode.
void setNumberFraction(double number_fraction)
Sets the number fraction of the species.
bool m_massFracMode
The mode of the composition entry. True if mass fraction, false if number fraction.
void setMassFraction(double mass_fraction)
Sets the mass fraction of the species.
serif::atomic::Species m_isotope
The isotope of the species.
double m_numberFraction
The number fraction of the species.
void setSpecies(const std::string &symbol)
Sets the species for the composition entry.
double number_fraction() const
Gets the number fraction of the species.
double mass_fraction() const
Gets the mass fraction of the species.
double m_relAbundance
The relative abundance of the species for converting between mass and number fractions.
bool setMassFracMode(double meanMolarMass)
Sets the mode to mass fraction mode.
std::string m_symbol
The chemical symbol of the species.
CompositionEntry()
Default constructor.
double m_massFraction
The mass fraction of the species.
bool m_initialized
True if the composition entry has been initialized.
friend std::ostream & operator<<(std::ostream &os, const CompositionEntry &entry)
Overloaded output stream operator for CompositionEntry.
bool getMassFracMode() const
Gets the mode of the composition entry.
Represents the global composition of a system. This tends to be used after finalize and is primarily ...
friend std::ostream & operator<<(std::ostream &os, const GlobalComposition &comp)
double meanParticleMass
The mean particle mass of the composition (\sum_{i} \frac{n_i}{m_i}. where n_i is the number fraction...
double specificNumberDensity
The specific number density of the composition (\sum_{i} X_i m_i. Where X_i is the number fraction of...