6#include "fourdst/logging/logging.h"
14#include "quill/LogMacros.h"
17 std::optional<fourdst::atomic::Species> getSpecies(
const std::string& symbol) {
24 quill::Logger* getLogger() {
25 static quill::Logger* logger = fourdst::logging::LogManager::getInstance().getLogger(
"log");
29 void throw_unknown_symbol(
const std::string& symbol) {
30 LOG_ERROR(getLogger(),
"Symbol {} is not a valid species symbol (not in the species database)", symbol);
37 const std::set<atomic::Species> &species,
38 const std::vector<double> &massFractions
40 const double sum = std::accumulate(
41 massFractions.begin(),
46 if (std::abs(sum - 1.0) > 1e-10) {
48 "Mass fractions must sum to 1.0, got " + std::to_string(sum)
52 if (species.size() != massFractions.size()) {
54 "The number of species and mass fractions must be equal. Got " +
55 std::to_string(species.size()) +
" species and " +
56 std::to_string(massFractions.size()) +
" mass fractions."
62 for (
const auto& [sp, xi] : std::views::zip(species, massFractions)) {
75 std::set<atomic::Species> species;
76 for (
const auto& symbol : symbols) {
77 auto result = getSpecies(symbol);
79 throw_unknown_symbol(symbol);
81 species.insert(result.value());
Manages a collection of chemical species and their abundances.
Exception thrown when a composition is in an invalid or inconsistent state.
Exception thrown when an unknown symbol is encountered.
static const std::unordered_map< std::string, const Species & > species
Map of species names to their corresponding Species objects.
Utilities and types for representing and manipulating chemical compositions.
Composition buildCompositionFromMassFractions(const std::vector< std::string > &symbols, const std::vector< double > &massFractions)
Build a Composition object from symbols and their corresponding mass fractions.