24#include <unordered_map>
29#include "fourdst/config/config.h"
30#include "fourdst/logging/logging.h"
56 os <<
"<CanonicalComposition: "
113 std::optional<double>
Ye;
145 static quill::Logger* logger = logging::LogManager::getInstance().getLogger(
"log");
177 explicit Composition(
const std::vector<std::string>& symbols);
192 explicit Composition(
const std::vector<atomic::Species>& species);
204 explicit Composition(
const std::set<std::string>& symbols);
219 explicit Composition(
const std::set<atomic::Species>& species);
236 Composition(
const std::vector<std::string>& symbols,
const std::vector<double>& molarAbundances);
252 Composition(
const std::vector<atomic::Species>& species,
const std::vector<double>& molarAbundances);
269 Composition(
const std::set<std::string>& symbols,
const std::vector<double>& molarAbundances);
360 void registerSpecies(
const std::vector<atomic::Species>& species)
noexcept;
375 [[nodiscard]]
bool contains(
const std::string& symbol)
const override;
381 [[nodiscard]]
size_t size() const noexcept override;
400 const std::
string& symbol,
401 const
double& molar_abundance
424 const
atomic::Species& species,
425 const
double& molar_abundance
444 const std::vector<std::
string>& symbols,
445 const std::vector<
double>& molar_abundances
467 const std::vector<
atomic::Species>& species,
468 const std::vector<
double>& molar_abundances
488 const std::set<std::
string>& symbols,
489 const std::vector<
double>& molar_abundances
512 const std::set<
atomic::Species>& species,
513 const std::vector<
double>& molar_abundances
552 [[nodiscard]]
double getMassFraction(const std::
string& symbol) const override;
581 [[nodiscard]]
double getNumberFraction(const std::
string& symbol) const override;
619 [[nodiscard]]
double getMolarAbundance(const std::
string& symbol) const override;
708 [[nodiscard]]
size_t getSpeciesIndex(const std::
string& symbol) const override;
816 [[nodiscard]]
auto end()
const {
Abstract base class for chemical composition representations.
CompositionCache m_cache
Cache for computed properties to avoid redundant calculations.
~Composition() override=default
Default destructor.
size_t getSpeciesIndex(const std::string &symbol) const override
get the index in the sorted vector representation for a given symbol
bool contains(const atomic::Species &species) const noexcept override
Checks if a given species is present in the composition.
Composition()=default
Default constructor.
void setMolarAbundance(const std::string &symbol, const double &molar_abundance)
Sets the molar abundance for a given symbol.
const std::set< atomic::Species > & getRegisteredSpecies() const noexcept override
Get a set of all species that are registered in the composition.
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 detai...
void registerSpecies(const atomic::Species &species) noexcept
Registers a new species by extracting its symbol.
void registerSymbol(const std::string &symbol)
Registers a new symbol for inclusion in the composition.
std::set< std::string > getRegisteredSymbols() const noexcept override
Gets the registered symbols.
std::set< atomic::Species > m_registeredSpecies
Set of registered species in the composition.
static quill::Logger * getLogger()
Gets the logger instance for the Composition class. This is static to ensure that all composition obj...
Composition & operator=(Composition const &other)
Assignment operator.
double getElectronAbundance() const noexcept override
Compute the electron abundance of the composition.
size_t size() const noexcept override
Gets the number of registered species in the composition.
std::unordered_map< atomic::Species, double > getMassFraction() const noexcept override
Gets the mass fractions of all species in the composition.
std::map< atomic::Species, double > m_molarAbundances
Map of species to their molar abundances.
CanonicalComposition getCanonicalComposition() const
Compute the canonical composition (X, Y, Z) of the composition.
auto begin()
Returns an iterator to the beginning of the molar abundance map.
std::vector< double > getMolarAbundanceVector() const noexcept override
Get a uniform vector representation of the molar abundances stored in the composition object sorted s...
double getMolarAbundance(const std::string &symbol) const override
Gets the molar abundances of all species in the composition.
auto end()
Returns an iterator to the end of the molar abundance map.
auto begin() const
Returns a const iterator to the beginning of the molar abundance map.
std::vector< double > getNumberFractionVector() const noexcept override
Get a uniform vector representation of the number fractions stored in the composition object sorted s...
atomic::Species getSpeciesAtIndex(size_t index) const override
Get the species at a given index in the sorted vector representation.
auto end() const
Returns a const iterator to the end of the molar abundance map.
std::vector< double > getMassFractionVector() const noexcept override
Get a uniform vector representation of the mass fraction stored in the composition object sorted such...
double getMeanParticleMass() const noexcept override
Compute the mean particle mass of the composition.
Contains canonical information about atomic species and elements used by 4D-STAR.
Utilities and types for representing and manipulating chemical compositions.
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.
Caches computed properties of the composition to avoid redundant calculations.
std::optional< std::vector< atomic::Species > > sortedSpecies
Cached vector of sorted species (by mass).
std::optional< std::vector< double > > numberFractions
Cached vector of number fractions.
std::optional< CanonicalComposition > canonicalComp
Cached canonical composition data.
std::optional< std::vector< double > > molarAbundances
Cached vector of molar abundances.
std::optional< std::vector< std::string > > sortedSymbols
Cached vector of sorted species (by mass).
void clear()
Clears all cached values.
std::optional< std::vector< double > > massFractions
Cached vector of mass fractions.
std::optional< double > Ye
Cached electron abundance.
bool is_clear() const
Checks if the cache is clear (i.e., all cached values are empty).