GridFire 0.0.1a
General Purpose Nuclear Network
Loading...
Searching...
No Matches
logging.cpp
Go to the documentation of this file.
3
4#include <sstream>
5#include <iomanip>
6#include <algorithm>
7#include <ranges>
8#include <string_view>
9#include <string>
10#include <iostream>
11#include <vector>
12
14 const DynamicEngine& engine,
15 std::vector<double> const& Y,
16 const double T9,
17 const double rho
18) {
19 auto const& timescales = engine.getSpeciesTimescales(Y, T9, rho);
20
21 // Figure out how wide the "Species" column needs to be:
22 std::size_t maxNameLen = std::string_view("Species").size();
23 for (const auto &key: timescales | std::views::keys) {
24 std::string_view name = key.name();
25 maxNameLen = std::max(maxNameLen, name.size());
26 }
27
28 // Pick a fixed width for the timescale column:
29 constexpr int timescaleWidth = 12;
30
31 std::ostringstream ss;
32 ss << "== Timescales (s) ==\n";
33
34 // Header row
35 ss << std::left << std::setw(static_cast<int>(maxNameLen) + 2) << "Species"
36 << std::right << std::setw(timescaleWidth) << "Timescale (s)" << "\n";
37
38 // Underline
39 ss << std::string(static_cast<int>(maxNameLen) + 2 + timescaleWidth, '=') << "\n";
40
41 ss << std::scientific;
42
43 // Data rows
44 for (auto const& [species, timescale] : timescales) {
45 const std::string_view name = species.name();
46 ss << std::left << std::setw(static_cast<int>(maxNameLen) + 2) << name;
47
48 if (std::isinf(timescale)) {
49 ss << std::right << std::setw(timescaleWidth) << "inf" << "\n";
50 } else {
51 ss << std::right << std::setw(timescaleWidth)
52 << std::scientific << std::setprecision(3) << timescale << "\n";
53 }
54 }
55
56 // Footer underline
57 ss << std::string(static_cast<int>(maxNameLen) + 2 + timescaleWidth, '=') << "\n";
58
59 return ss.str();
60}
Abstract class for engines supporting Jacobian and stoichiometry operations.
virtual std::unordered_map< fourdst::atomic::Species, double > getSpeciesTimescales(const std::vector< double > &Y, double T9, double rho) const =0
Compute timescales for all species in the network.
Abstract interfaces for reaction network engines in GridFire.
std::string formatNuclearTimescaleLogString(const DynamicEngine &engine, const std::vector< double > &Y, const double T9, const double rho)
Formats a map of nuclear species timescales into a human-readable string.
Definition logging.cpp:13