24#include <unordered_map>
28#include <unordered_set>
31#include "fourdst/config/config.h"
32#include "fourdst/logging/logging.h"
58 os <<
"<CanonicalComposition: "
118 std::optional<double>
Ye;
119 std::optional<std::size_t>
hash;
157 static quill::Logger* logger = logging::LogManager::getInstance().getLogger(
"log");
196 explicit Composition(
const std::vector<std::string>& symbols);
211 explicit Composition(
const std::vector<atomic::Species>& species);
223 explicit Composition(
const std::set<std::string>& symbols);
238 explicit Composition(
const std::set<atomic::Species>& species);
240 explicit Composition(
const std::unordered_set<std::string>& symbols);
241 explicit Composition(
const std::unordered_set<atomic::Species>& species);
258 Composition(
const std::vector<std::string>& symbols,
const std::vector<double>& molarAbundances);
274 Composition(
const std::vector<atomic::Species>& species,
const std::vector<double>& molarAbundances);
291 Composition(
const std::set<std::string>& symbols,
const std::vector<double>& molarAbundances);
293 explicit Composition(
const std::unordered_map<std::string, double>& symbolMolarAbundances);
294 explicit Composition(
const std::map<std::string, double>& symbolMolarAbundances);
296 explicit Composition(
const std::unordered_map<atomic::Species, double>& speciesMolarAbundances);
297 explicit Composition(
const std::map<atomic::Species, double>& speciesMolarAbundances);
392 void registerSpecies(
const std::vector<atomic::Species>& species)
noexcept;
407 [[nodiscard]]
bool contains(
const std::string& symbol)
const override;
413 [[nodiscard]]
size_t size() const noexcept override;
432 const std::
string& symbol,
433 const
double& molar_abundance
456 const
atomic::Species& species,
457 const
double& molar_abundance
476 const std::vector<std::
string>& symbols,
477 const std::vector<
double>& molar_abundances
499 const std::vector<
atomic::Species>& species,
500 const std::vector<
double>& molar_abundances
520 const std::set<std::
string>& symbols,
521 const std::vector<
double>& molar_abundances
544 const std::set<
atomic::Species>& species,
545 const std::vector<
double>& molar_abundances
584 [[nodiscard]]
double getMassFraction(const std::
string& symbol) const override;
613 [[nodiscard]]
double getNumberFraction(const std::
string& symbol) const override;
651 [[nodiscard]]
double getMolarAbundance(const std::
string& symbol) const override;
740 [[nodiscard]]
size_t getSpeciesIndex(const std::
string& symbol) const override;
854 [[nodiscard]] std::size_t
hash()
const override;
859 if (a.size() != b.size())
return false;
861 if (a.getRegisteredSpecies() != b.getRegisteredSpecies())
864 return a.hash() == b.hash();
Abstract base class for chemical composition representations.
Manages a collection of chemical species and their abundances.
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.
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...
detail::CompositionIterator< true > const_iterator
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.
static std::vector< atomic::Species > symbolVectorToSpeciesVector(const std::vector< std::string > &symbols)
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.
std::unique_ptr< CompositionAbstract > clone() const override
std::size_t hash() const override
iterator begin() override
Returns an iterator to the beginning of the molar abundance map.
detail::CompositionIterator< false > iterator
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::vector< atomic::Species > m_species
detail::CompositionIterator< false > end() override
Returns an iterator to the end of the molar abundance map.
detail::CompositionIterator< true > end() const override
Returns a const iterator to the end of the molar abundance map.
CanonicalComposition getCanonicalComposition() const
Compute the canonical composition (X, Y, Z) of the composition.
std::vector< double > m_molarAbundances
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.
std::expected< std::ptrdiff_t, SpeciesIndexLookupError > findSpeciesIndex(const atomic::Species &species) const noexcept
const_iterator begin() const override
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.
const std::vector< atomic::Species > & getRegisteredSpecies() const noexcept override
Get a set of all species that are registered in 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...
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.
bool operator==(const Composition &a, const Composition &b) noexcept
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::size_t > hash
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).