GridFire v0.7.0-alpha
General Purpose Nuclear Network
Loading...
Searching...
No Matches
gridfire::utils Namespace Reference

Namespaces

namespace  hashing
 

Classes

class  Column
 
class  ColumnBase
 

Functions

double massFractionFromMolarAbundanceAndComposition (const fourdst::composition::Composition &composition, const fourdst::atomic::Species &species, const double Yi)
 
std::vector< double > massFractionFromMolarAbundanceAndMolarMass (const std::vector< double > &molarAbundances, const std::vector< double > &molarMasses) noexcept
 Convert a vector of molar abundances into a vector of mass fractions.
 
std::vector< double > molarMassVectorFromComposition (const fourdst::composition::Composition &composition)
 
uint_fast32_t hash_atomic (const uint16_t a, const uint8_t z) noexcept
 Generate a unique hash for an isotope given its mass number (A) and atomic number (Z).
 
std::uint64_t hash_reaction (const reaction::Reaction &reaction) noexcept
 
std::string formatNuclearTimescaleLogString (const DynamicEngine &engine, const fourdst::composition::Composition &composition, double T9, double rho)
 Formats a map of nuclear species timescales into a human-readable string.
 
std::string format_table (const std::string &tableName, const std::vector< std::unique_ptr< ColumnBase > > &columns)
 

Function Documentation

◆ format_table()

std::string gridfire::utils::format_table ( const std::string & tableName,
const std::vector< std::unique_ptr< ColumnBase > > & columns )
inline

◆ formatNuclearTimescaleLogString()

std::string gridfire::utils::formatNuclearTimescaleLogString ( const DynamicEngine & engine,
const fourdst::composition::Composition & composition,
double T9,
double rho )

Formats a map of nuclear species timescales into a human-readable string.

This function takes a reaction network engine and the current plasma conditions to calculate the characteristic timescales for each species. It then formats this information into a neatly aligned ASCII table, which is suitable for logging or printing to the console.

Parameters
engineA constant reference to a DynamicEngine object, used to calculate the species timescales.
compositionThe current composition of the plasma
T9The temperature in units of 10^9 K.
rhoThe plasma density in g/cm^3.
Returns
A std::string containing the formatted table of species and their timescales.

Pre-conditions

  • The engine must be in a valid state.
  • The size of the Y vector must be consistent with the number of species expected by the engine.

Algorithm

  1. Calls the getSpeciesTimescales method on the provided engine to get the timescale for each species under the given conditions.
  2. Determines the maximum length of the species names to dynamically set the width of the "Species" column for proper alignment.
  3. Uses a std::ostringstream to build the output string.
  4. Constructs a header for the table with titles "Species" and "Timescale (s)".
  5. Iterates through the map of timescales, adding a row to the table for each species.
  6. Timescales are formatted in scientific notation with 3 digits of precision.
  7. Special handling is included to print "inf" for infinite timescales.
  8. The final string, including header and footer lines, is returned.

Usage

// Assume 'my_engine' is a valid DynamicEngine object and Y, T9, rho are initialized.
std::string log_output = gridfire::utils::formatNuclearTimescaleLogString(my_engine, Y, T9, rho);
std::cout << log_output;
// Example Output:
// == Timescales (s) ==
// Species Timescale (s)
// ==========================
// h1 1.234e+05
// he4 inf
// c12 8.765e-02
// ==========================
std::string formatNuclearTimescaleLogString(const DynamicEngine &engine, const fourdst::composition::Composition &composition, double T9, double rho)
Formats a map of nuclear species timescales into a human-readable string.
Definition logging.cpp:12

◆ hash_atomic()

uint_fast32_t gridfire::utils::hash_atomic ( const uint16_t a,
const uint8_t z )
inlinenoexcept

Generate a unique hash for an isotope given its mass number (A) and atomic number (Z).

This function combines the mass number and atomic number into a single 32-bit integer by shifting the mass number 8 bits to the left and OR'ing it with the atomic number. This ensures a unique representation for each isotope within physically possible ranges.

Parameters
aThe mass number (A) of the isotope.
zThe atomic number (Z) of the isotope.
Returns
A unique 32-bit hash representing the isotope. This is computed as (A << 8) | Z into an uint32_t.

◆ hash_reaction()

std::uint64_t gridfire::utils::hash_reaction ( const reaction::Reaction & reaction)
inlinenoexcept

◆ massFractionFromMolarAbundanceAndComposition()

double gridfire::utils::massFractionFromMolarAbundanceAndComposition ( const fourdst::composition::Composition & composition,
const fourdst::atomic::Species & species,
const double Yi )
inline

◆ massFractionFromMolarAbundanceAndMolarMass()

std::vector< double > gridfire::utils::massFractionFromMolarAbundanceAndMolarMass ( const std::vector< double > & molarAbundances,
const std::vector< double > & molarMasses )
inlinenoexcept

Convert a vector of molar abundances into a vector of mass fractions.

Parameters
molarAbundancesVector of molar abundances
molarMassesVector of molar masses
Note
The vectors molarAbundances and molarMasses must be parallel. This function does not provide any checks to ensure that the correct molar mass is being used with the correct molar abundance.
Returns
A vector of molar masses such that each molar mass < 1 and the sum of all is = 1

◆ molarMassVectorFromComposition()

std::vector< double > gridfire::utils::molarMassVectorFromComposition ( const fourdst::composition::Composition & composition)
inline