SERiF 0.0.1a
3+1D Stellar Structure and Evolution
|
Manages the composition of elements. More...
#include <composition.h>
Public Member Functions | |
Composition ()=default | |
Default constructor. | |
~Composition ()=default | |
Default destructor. | |
bool | finalize (bool norm=false) |
Finalizes the composition. | |
Composition (const std::vector< std::string > &symbols) | |
Constructs a Composition with the given symbols. | |
Composition (const std::set< std::string > &symbols) | |
Constructs a Composition with the given symbols as a set. | |
Composition (const std::vector< std::string > &symbols, const std::vector< double > &mass_fractions, bool massFracMode=true) | |
Constructs a Composition with the given symbols and mass fractions. | |
Composition (const Composition &composition) | |
Constructs a Composition from another Composition. | |
Composition & | operator= (Composition const &other) |
void | registerSymbol (const std::string &symbol, bool massFracMode=true) |
Registers a new symbol. | |
void | registerSymbol (const std::vector< std::string > &symbols, bool massFracMode=true) |
Registers multiple new symbols. | |
std::set< std::string > | getRegisteredSymbols () const |
Gets the registered symbols. | |
double | setMassFraction (const std::string &symbol, const double &mass_fraction) |
Sets the mass fraction for a given symbol. | |
std::vector< double > | setMassFraction (const std::vector< std::string > &symbols, const std::vector< double > &mass_fractions) |
Sets the mass fraction for multiple symbols. | |
double | setNumberFraction (const std::string &symbol, const double &number_fraction) |
Sets the number fraction for a given symbol. | |
std::vector< double > | setNumberFraction (const std::vector< std::string > &symbols, const std::vector< double > &number_fractions) |
Sets the number fraction for multiple symbols. | |
Composition | mix (const Composition &other, double fraction) const |
Mix two compositions together with a given fraction. | |
std::unordered_map< std::string, double > | getMassFraction () const |
Gets the mass fractions of all compositions. | |
double | getMassFraction (const std::string &symbol) const |
Gets the mass fraction for a given symbol. | |
double | getNumberFraction (const std::string &symbol) const |
Gets the number fraction for a given symbol. | |
std::unordered_map< std::string, double > | getNumberFraction () const |
Gets the number fractions of all compositions. | |
std::pair< CompositionEntry, GlobalComposition > | getComposition (const std::string &symbol) const |
Gets the composition entry and global composition for a given symbol. | |
std::pair< std::unordered_map< std::string, CompositionEntry >, GlobalComposition > | getComposition () const |
Gets all composition entries and the global composition. | |
double | getMeanParticleMass () const |
Compute the mean particle mass of the composition. | |
double | getMeanAtomicNumber () const |
Compute the mean atomic mass number of the composition. | |
Composition | subset (const std::vector< std::string > &symbols, std::string method="norm") const |
Gets a subset of the composition. | |
bool | hasSymbol (const std::string &symbol) const |
Check if a symbol is registered. | |
bool | contains (const serif::atomic::Species &isotope) const |
void | setCompositionMode (bool massFracMode) |
Sets the composition mode. | |
CanonicalComposition | getCanonicalComposition (bool harsh=false) const |
Gets the current canonical composition (X, Y, Z). | |
Composition | operator+ (const Composition &other) const |
Overloads the + operator to mix two compositions together with a fraction of 0.5. | |
Private Member Functions | |
bool | isValidComposition (const std::vector< double > &fractions) const |
Checks if the given mass fractions are valid. | |
void | validateComposition (const std::vector< double > &fractions) const |
Validates the given mass fractions. | |
bool | finalizeMassFracMode (bool norm) |
Finalizes the composition in mass fraction mode. | |
bool | finalizeNumberFracMode (bool norm) |
Finalizes the composition in number fraction mode. | |
Static Private Member Functions | |
static bool | isValidSymbol (const std::string &symbol) |
Checks if the given symbol is valid. | |
Private Attributes | |
serif::config::Config & | m_config = serif::config::Config::getInstance() |
serif::probe::LogManager & | m_logManager = serif::probe::LogManager::getInstance() |
quill::Logger * | m_logger = m_logManager.getLogger("log") |
bool | m_finalized = false |
True if the composition is finalized. | |
double | m_specificNumberDensity = 0.0 |
The specific number density of the composition (\sum_{i} X_i m_i. Where X_i is the number fraction of the ith species and m_i is the mass of the ith species). | |
double | m_meanParticleMass = 0.0 |
The mean particle mass of the composition (\sum_{i} \frac{n_i}{m_i}. where n_i is the number fraction of the ith species and m_i is the mass of the ith species). | |
bool | m_massFracMode = true |
True if mass fraction mode, false if number fraction mode. | |
std::set< std::string > | m_registeredSymbols |
The registered symbols. | |
std::unordered_map< std::string, CompositionEntry > | m_compositions |
The compositions. | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Composition &composition) |
Overloaded output stream operator for Composition. | |
Manages the composition of elements.
The composition is a collection of elements with their respective mass fractions. The general purpose of this class is to provide a standardized interface for managing the composition of any part of 4DSSE. There are a few rules when using this class.
Example Usage: Constructing a finalized composition with symbols and mass fractions:
Example Usage: Constructing a composition with symbols and finalizing it later:
Definition at line 216 of file composition.h.
|
default |
Default constructor.
|
default |
Default destructor.
|
explicit |
Constructs a Composition with the given symbols.
symbols | The symbols to initialize the composition with. Example Usage: std::vector<std::string> symbols = {"H", "O"};
Composition comp(symbols);
|
Definition at line 146 of file composition.cpp.
|
explicit |
Constructs a Composition with the given symbols as a set.
symbols | The symbols to initialize the composition with. Example Usage: std::set<std::string> symbols = {"H", "O"};
Composition comp(symbols);
|
Definition at line 152 of file composition.cpp.
serif::composition::Composition::Composition | ( | const std::vector< std::string > & | symbols, |
const std::vector< double > & | mass_fractions, | ||
bool | massFracMode = true ) |
Constructs a Composition with the given symbols and mass fractions.
symbols | The symbols to initialize the composition with. |
mass_fractions | The mass fractions corresponding to the symbols. |
massFracMode | True if mass fraction mode, false if number fraction mode. Example Usage: std::vector<std::string> symbols = {"H", "O"};
std::vector<double> mass_fractions = {0.1, 0.9};
Composition comp(symbols, mass_fractions);
|
Definition at line 158 of file composition.cpp.
serif::composition::Composition::Composition | ( | const Composition & | composition | ) |
Constructs a Composition from another Composition.
composition | The Composition to copy. |
Definition at line 180 of file composition.cpp.
bool serif::composition::Composition::contains | ( | const serif::atomic::Species & | isotope | ) | const |
Definition at line 644 of file composition.cpp.
bool serif::composition::Composition::finalize | ( | bool | norm = false | ) |
Finalizes the composition.
norm | If true, the composition will be normalized to sum to 1 [Default False] |
Definition at line 338 of file composition.cpp.
|
private |
Finalizes the composition in mass fraction mode.
norm | If true, the composition will be normalized to sum to 1. |
Definition at line 351 of file composition.cpp.
|
private |
Finalizes the composition in number fraction mode.
norm | If true, the composition will be normalized to sum to 1. |
Definition at line 387 of file composition.cpp.
|
nodiscard |
Gets the current canonical composition (X, Y, Z).
harsh | If true, this will throw an error if X-Y != Z where Z is computed as the sum of all other elements. |
std::runtime_error | if the composition is not finalized or if the canonical composition cannot be computed. |
std::runtime_error | if harsh is true and the canonical composition is not valid. |
Definition at line 593 of file composition.cpp.
|
nodiscard |
Gets all composition entries and the global composition.
Definition at line 510 of file composition.cpp.
|
nodiscard |
Gets the composition entry and global composition for a given symbol.
symbol | The symbol to get the composition for. |
Definition at line 498 of file composition.cpp.
|
nodiscard |
Gets the mass fractions of all compositions.
Definition at line 465 of file composition.cpp.
|
nodiscard |
Gets the mass fraction for a given symbol.
symbol | The symbol to get the mass fraction for. |
Definition at line 449 of file composition.cpp.
|
nodiscard |
Compute the mean atomic mass number of the composition.
Definition at line 526 of file composition.cpp.
|
nodiscard |
Compute the mean particle mass of the composition.
Definition at line 518 of file composition.cpp.
|
nodiscard |
Gets the number fractions of all compositions.
Definition at line 490 of file composition.cpp.
|
nodiscard |
Gets the number fraction for a given symbol.
symbol | The symbol to get the number fraction for. |
Definition at line 474 of file composition.cpp.
|
nodiscard |
Gets the registered symbols.
Definition at line 236 of file composition.cpp.
bool serif::composition::Composition::hasSymbol | ( | const std::string & | symbol | ) | const |
Check if a symbol is registered.
symbol | The symbol to check. |
Definition at line 640 of file composition.cpp.
|
private |
Checks if the given mass fractions are valid.
mass_fractions | The mass fractions to check. |
Definition at line 247 of file composition.cpp.
|
staticprivate |
Checks if the given symbol is valid.
A symbol is valid if it is in the atomic species database (species in atomicSpecies.h). These include all the isotopes from AME2020.
symbol | The symbol to check. |
Definition at line 260 of file composition.cpp.
Composition serif::composition::Composition::mix | ( | const Composition & | other, |
double | fraction ) const |
Mix two compositions together with a given fraction.
other | The other composition to mix with. |
fraction | The fraction of the other composition to mix with. This is the fraction of the other composition wrt. to the current. i.e. fraction=1 would mean that 50% of the new composition is from the other and 50% from the current). |
Definition at line 420 of file composition.cpp.
Composition serif::composition::Composition::operator+ | ( | const Composition & | other | ) | const |
Overloads the + operator to mix two compositions together with a fraction of 0.5.
OVERLOADS.
other | The other composition to mix with. |
Definition at line 659 of file composition.cpp.
Composition & serif::composition::Composition::operator= | ( | Composition const & | other | ) |
Definition at line 189 of file composition.cpp.
void serif::composition::Composition::registerSymbol | ( | const std::string & | symbol, |
bool | massFracMode = true ) |
Registers a new symbol.
symbol | The symbol to register. |
massFracMode | True if mass fraction mode, false if number fraction mode. Example Usage: Composition comp;
comp.registerSymbol("H");
|
Definition at line 203 of file composition.cpp.
void serif::composition::Composition::registerSymbol | ( | const std::vector< std::string > & | symbols, |
bool | massFracMode = true ) |
Registers multiple new symbols.
symbols | The symbols to register. |
massFracMode | True if mass fraction mode, false if number fraction mode. Example Usage: |
Definition at line 230 of file composition.cpp.
void serif::composition::Composition::setCompositionMode | ( | bool | massFracMode | ) |
Sets the composition mode.
massFracMode | True if mass fraction mode, false if number fraction mode. |
Definition at line 572 of file composition.cpp.
double serif::composition::Composition::setMassFraction | ( | const std::string & | symbol, |
const double & | mass_fraction ) |
Sets the mass fraction for a given symbol.
symbol | The symbol to set the mass fraction for. |
mass_fraction | The mass fraction to set. |
Definition at line 264 of file composition.cpp.
std::vector< double > serif::composition::Composition::setMassFraction | ( | const std::vector< std::string > & | symbols, |
const std::vector< double > & | mass_fractions ) |
Sets the mass fraction for multiple symbols.
symbols | The symbols to set the mass fraction for. |
mass_fractions | The mass fractions corresponding to the symbols. |
Definition at line 287 of file composition.cpp.
double serif::composition::Composition::setNumberFraction | ( | const std::string & | symbol, |
const double & | number_fraction ) |
Sets the number fraction for a given symbol.
symbol | The symbol to set the number fraction for. |
number_fraction | The number fraction to set. |
Definition at line 301 of file composition.cpp.
std::vector< double > serif::composition::Composition::setNumberFraction | ( | const std::vector< std::string > & | symbols, |
const std::vector< double > & | number_fractions ) |
Sets the number fraction for multiple symbols.
symbols | The symbols to set the number fraction for. |
number_fractions | The number fractions corresponding to the symbols. |
Definition at line 324 of file composition.cpp.
Composition serif::composition::Composition::subset | ( | const std::vector< std::string > & | symbols, |
std::string | method = "norm" ) const |
Gets a subset of the composition.
symbols | The symbols to include in the subset. |
method | The method to use for the subset (default is "norm"). |
Definition at line 543 of file composition.cpp.
|
private |
Validates the given mass fractions.
mass_fractions | The mass fractions to validate. |
std::invalid_argument | if the mass fractions are invalid. |
Definition at line 240 of file composition.cpp.
|
friend |
Overloaded output stream operator for Composition.
os | The output stream. |
composition | The Composition to output. |
Definition at line 675 of file composition.cpp.
|
private |
The compositions.
Definition at line 228 of file composition.h.
|
private |
Definition at line 218 of file composition.h.
|
private |
True if the composition is finalized.
Definition at line 222 of file composition.h.
|
private |
Definition at line 220 of file composition.h.
|
private |
Definition at line 219 of file composition.h.
|
private |
True if mass fraction mode, false if number fraction mode.
Definition at line 225 of file composition.h.
|
private |
The mean particle mass of the composition (\sum_{i} \frac{n_i}{m_i}. where n_i is the number fraction of the ith species and m_i is the mass of the ith species).
Definition at line 224 of file composition.h.
|
private |
The registered symbols.
Definition at line 227 of file composition.h.
|
private |
The specific number density of the composition (\sum_{i} X_i m_i. Where X_i is the number fraction of the ith species and m_i is the mass of the ith species).
Definition at line 223 of file composition.h.