GridFire v0.7.6rc4.0 General Purpose Nuclear Network

Loading...
Searching...
No Matches
Namespaces | Classes | Concepts | Enumerations | Functions | Variables
gridfire::utils Namespace Reference

## Namespaces
namespace | hashing

## Classes
class | Column
class | ColumnBase
class | Table
class | TableBase

## Concepts
concept | Streamable

## Enumerations
enum class | SUNDIALS_RET_CODE_TYPES { CVODE , KINSOL }

## Functions
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
template<typename T>
std::size_t | hash_combine (std::size_t seed, const T &v)
std::size_t | fast_mix (std::size_t h) noexcept
std::size_t | hash_state (const fourdst::composition::CompositionAbstract &comp, const double T9, const double rho, const reaction::ReactionSet &reactions) noexcept
std::string | formatNuclearTimescaleLogString (engine::scratch::StateBlob &ctx, const engine::DynamicEngine &engine, const fourdst::composition::Composition &composition, double T9, double rho)
| Formats a map of nuclear species timescales into a human-readable string.
template<std::ranges::input_range Container, typename Elem = std::ranges::range_reference_t<Container>, typename Transform = std::identity, typename Pred = bool(*)(const std::ranges::range_value_t<Container>&)> requires std::invocable<Transform, Elem> && Streamable<std::invoke_result_t<Transform, Elem>> && std::predicate<Pred, Elem>
static std::string | iterable_to_delimited_string (const Container &container, const std::string_view delimiter=", ", Transform transform={}, Pred pred=[](const auto &){ return true;}) noexcept
const std::unordered_map< int, std::string > & | sundials_retcode_map (const SUNDIALS_RET_CODE_TYPES type)
void | check_cvode_flag (const int flag, const std::string &func_name)
N_Vector | init_sun_vector (uint64_t size, SUNContext sun_ctx)
void | check_sundials_flag (const int flag, const std::string &func_name, const SUNDIALS_RET_CODE_TYPES type)
size_t | visual_width (const std::string &s)
std::string | format_table (const std::string &tableName, const std::vector< std::unique_ptr< ColumnBase > > &columns)
std::string | format_table (const TableBase &table)
void | print_table (const std::string &tableName, const std::vector< std::unique_ptr< ColumnBase > > &columns)
void | print_table (const TableBase &table)
void | to_csv (const std::string &filename, const std::vector< std::unique_ptr< ColumnBase > > &columns)
nlohmann::json | to_json (const std::vector< std::unique_ptr< ColumnBase > > &columns)
void | to_json_file (const std::string &filename, const std::vector< std::vector< std::unique_ptr< ColumnBase > > > &tables, const std::vector< std::string > &tableNames)

## Variables
static std::unordered_map< int, std::string > | cvode_ret_code_map
static std::unordered_map< int, std::string > | kinsol_ret_code_map

## Enumeration Type Documentation

## ◆ SUNDIALS_RET_CODE_TYPES

enum class gridfire::utils::SUNDIALS_RET_CODE_TYPES
| strong

Enumerator
CVODE |
KINSOL |

## Function Documentation

## ◆ check_cvode_flag()

void gridfire::utils::check_cvode_flag | ( | const int | flag,
|  | const std::string & | func_name )
| inline

## ◆ check_sundials_flag()

void gridfire::utils::check_sundials_flag | ( | const int | flag,
|  | const std::string & | func_name,
|  | const SUNDIALS_RET_CODE_TYPES | type )
| inline

## ◆ fast_mix()

std::size_t gridfire::utils::fast_mix | ( | std::size_t | h | ) |
| inline noexcept

## ◆ format_table() [1/2]

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

## ◆ format_table() [2/2]

std::string gridfire::utils::format_table | ( | const TableBase & | table | ) |
| inline

## ◆ formatNuclearTimescaleLogString()

std::string gridfire::utils::formatNuclearTimescaleLogString | ( | engine::scratch::StateBlob & | ctx,
|  | const engine::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

  ctx |
  engine | A constant reference to a `DynamicEngine` object, used to calculate the species timescales.
  composition | The current composition of the plasma
  T9 | The temperature in units of 10^9 K.
  rho | The 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
// ==========================
gridfire::utils::formatNuclearTimescaleLogString
std::string formatNuclearTimescaleLogString(engine::scratch::StateBlob &ctx, const engine::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 )
| inline noexcept

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

  a | The mass number (A) of the isotope.
  z | The 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_combine()

template<typename T>

std::size_t gridfire::utils::hash_combine | ( | std::size_t | seed,
|  | const T & | v )

## ◆ hash_reaction()

std::uint64_t gridfire::utils::hash_reaction | ( | const reaction::Reaction & | reaction | ) |
| inline noexcept

## ◆ hash_state()

std::size_t gridfire::utils::hash_state | ( | const fourdst::composition::CompositionAbstract & | comp,
|  | const double | T9,
|  | const double | rho,
|  | const reaction::ReactionSet & | reactions )
| inline noexcept

## ◆ init_sun_vector()

N_Vector gridfire::utils::init_sun_vector | ( | uint64_t | size,
|  | SUNContext | sun_ctx )
| inline

## ◆ iterable_to_delimited_string()

template<std::ranges::input_range Container, typename Elem = std::ranges::range_reference_t<Container>, typename Transform = std::identity, typename Pred = bool(*)(const std::ranges::range_value_t<Container>&)>
requires std::invocable<Transform, Elem> && Streamable<std::invoke_result_t<Transform, Elem>> && std::predicate<Pred, Elem>

static std::string gridfire::utils::iterable_to_delimited_string | ( | const Container & | container,
|  | const std::string_view | delimiter = ", ",
|  | Transform | transform = {},
|  | Pred | pred = [](const auto&){ return true; } )
| static noexcept

## ◆ print_table() [1/2]

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

## ◆ print_table() [2/2]

void gridfire::utils::print_table | ( | const TableBase & | table | ) |
| inline

## ◆ sundials_retcode_map()

const std::unordered_map< int, std::string > & gridfire::utils::sundials_retcode_map | ( | const SUNDIALS_RET_CODE_TYPES | type | ) |
| inline

## ◆ to_csv()

void gridfire::utils::to_csv | ( | const std::string & | filename,
|  | const std::vector< std::unique_ptr< ColumnBase > > & | columns )
| inline

## ◆ to_json()

nlohmann::json gridfire::utils::to_json | ( | const std::vector< std::unique_ptr< ColumnBase > > & | columns | ) |
| inline

## ◆ to_json_file()

void gridfire::utils::to_json_file | ( | const std::string & | filename,
|  | const std::vector< std::vector< std::unique_ptr< ColumnBase > > > & | tables,
|  | const std::vector< std::string > & | tableNames )
| inline

## ◆ visual_width()

size_t gridfire::utils::visual_width | ( | const std::string & | s | ) |
| inline

## Variable Documentation

## ◆ cvode_ret_code_map

std::unordered_map<int, std::string> gridfire::utils::cvode_ret_code_map
| inline static

## ◆ kinsol_ret_code_map

std::unordered_map<int, std::string> gridfire::utils::kinsol_ret_code_map
| inline static

Initial value:
{
{0, "KIN_SUCCESS: The solver succeeded."},
{1, "KIN_INITIAL_GUESS_OKAY: The guess, u=u0, satisfied the system F(u) = 0 within the tolerances specified"},
{2, "KIN_STEP_LT_STPTOL: KINSOL stopped based on scaled step length. This means that the current iterate may be an approximate solution of the given nonlinear system, but it is also quite possible that the algorithm is “stalled” (making insufficient progress) near an invalid solution, or that the scalar, scsteptol, is too large."},
{99, "KIN_WARNING: KINSOL succeeded but in an unusual way"},
{-1, "KIN_MEM_NULL: The KINSOL memory pointer is NULL."},
{-2, "KIN_ILL_INPUT: An illegal value was specified for an input argument."},
{-3, "KIN_NO_MALLOC: The KINSOL memory structure has not been allocated."},
{-4, "KIN_MEM_FAIL: A memory allocation failed."},
{-5, "KIN_LINESEARCH_NONCONV: The line search algorithm was unable to find an iterate sufficiently distinct from the current iterate."},
{-6, "KIN_MAXITER_REACHED: The maximum number of iterations was reached before convergence."},
{-7, "KIN_MXNEWT_5X_EXCEEDED: Five consecutive steps have been taken that satisfy a scaled step length test."},
{-8, "KIN_LINESEARCH_BCFAIL: The line search algorithm was unable to satisfy the beta-condition for nbcf fails iterations."},
{-9, "KIN_LINSOLV_NO_RECOVERY: The linear solver's solve function failed recoverably, but the Jacobian data is already current."},
{-10, "KIN_LINIT_FAIL: The linear solver's init routine failed."},
{-11, "KIN_LSETUP_FAIL: The linear solver's setup function failed in an unrecoverable manner."},
{-12, "KIN_LSOLVE_FAIL: The linear solver's solve function failed in an unrecoverable manner."},
{-13, "KIN_SYSFUNC_FAIL: The system function failed in an unrecoverable manner."},
{-14, "KIN_FIRST_SYSFUNC_ERR: The system function failed at the first call."},
{-15, "KIN_REPTD_SYSFUNC_ERR: Unable to correct repeated recoverable system function errors."},
{-16, "KIN_VECTOROP_ERR: A vector operation failed."},
{-17, "KIN_CONTEXT_ERR: A context error occurred."},
{-18, "KIN_DAMPING_FN_ERR: The damping function failed."},
{-19, "KIN_DEPTH_FN_ERR: The depth function failed."}
}