feat(GridFire): brought gridfire up to where network module in SERiF was before splitting it off

This commit is contained in:
2025-06-21 13:18:38 -04:00
parent a6bab8f037
commit 8bc48b8d19
37 changed files with 18155 additions and 39796 deletions

View File

@@ -14,14 +14,11 @@ network_headers = files(
dependencies = [
boost_dep,
const_dep,
quill_dep,
mfem_dep,
config_dep,
probe_dep,
species_weight_dep,
composition_dep,
reaclib_reactions_dep,
cppad_dep,
log_dep
]
# Define the libnetwork library so it can be linked against by other parts of the build system
@@ -39,4 +36,4 @@ network_dep = declare_dependency(
)
# Make headers accessible
install_headers(network_headers, subdir : '4DSSE/network')
install_headers(network_headers, subdir : '4DSSE/network')

View File

@@ -72,7 +72,7 @@ The coefficients to the fit are from reaclib.jinaweb.org .
*/
namespace serif::network::approx8{
namespace gridfire::approx8{
// using namespace std;
using namespace boost::numeric::odeint;
@@ -245,7 +245,7 @@ namespace serif::network::approx8{
// a Jacobian matrix for implicit solvers
void Jacobian::operator() ( const vector_type &y, matrix_type &J, double /* t */, vector_type &dfdt ) const {
serif::constant::Constants& constants = serif::constant::Constants::getInstance();
fourdst::constant::Constants& constants = fourdst::constant::Constants::getInstance();
const double avo = constants.get("N_a").value;
const double clight = constants.get("c").value;
// EOS
@@ -350,7 +350,7 @@ namespace serif::network::approx8{
}
void ODE::operator() ( const vector_type &y, vector_type &dydt, double /* t */) const {
const serif::constant::Constants& constants = serif::constant::Constants::getInstance();
const fourdst::constant::Constants& constants = fourdst::constant::Constants::getInstance();
const double avo = constants.get("N_a").value;
const double clight = constants.get("c").value;
@@ -501,7 +501,7 @@ namespace serif::network::approx8{
netOut.num_steps = num_steps;
const std::vector<std::string> symbols = {"H-1", "He-3", "He-4", "C-12", "N-14", "O-16", "Ne-20", "Mg-24"};
netOut.composition = serif::composition::Composition(symbols, outComposition);
netOut.composition = fourdst::composition::Composition(symbols, outComposition);
return netOut;
}

View File

@@ -21,9 +21,9 @@
#include <boost/numeric/odeint.hpp>
namespace serif::network {
namespace gridfire {
GraphNetwork::GraphNetwork(
const serif::composition::Composition &composition
const fourdst::composition::Composition &composition
):
Network(REACLIB),
m_reactions(build_reaclib_nuclear_network(composition)) {
@@ -31,7 +31,7 @@ namespace serif::network {
}
GraphNetwork::GraphNetwork(
const serif::composition::Composition &composition,
const fourdst::composition::Composition &composition,
const double cullingThreshold,
const double T9
):
@@ -65,8 +65,8 @@ namespace serif::network {
}
for (const auto& name: uniqueSpeciesNames) {
auto it = serif::atomic::species.find(name);
if (it != serif::atomic::species.end()) {
auto it = fourdst::atomic::species.find(name);
if (it != fourdst::atomic::species.end()) {
m_networkSpecies.push_back(it->second);
m_networkSpeciesMap.insert({name, it->second});
} else {
@@ -104,7 +104,7 @@ namespace serif::network {
}
// --- Basic Accessors and Queries ---
const std::vector<serif::atomic::Species>& GraphNetwork::getNetworkSpecies() const {
const std::vector<fourdst::atomic::Species>& GraphNetwork::getNetworkSpecies() const {
// Returns a constant reference to the vector of unique species in the network.
LOG_DEBUG(m_logger, "Providing access to network species vector. Size: {}.", m_networkSpecies.size());
return m_networkSpecies;
@@ -116,16 +116,16 @@ namespace serif::network {
return m_reactions;
}
bool GraphNetwork::involvesSpecies(const serif::atomic::Species& species) const {
bool GraphNetwork::involvesSpecies(const fourdst::atomic::Species& species) const {
// Checks if a given species is present in the network's species map for efficient lookup.
const bool found = m_networkSpeciesMap.contains(species.name());
LOG_DEBUG(m_logger, "Checking if species '{}' is involved in the network: {}.", species.name(), found ? "Yes" : "No");
return found;
}
std::unordered_map<serif::atomic::Species, int> GraphNetwork::getNetReactionStoichiometry(const reaclib::REACLIBReaction& reaction) const {
std::unordered_map<fourdst::atomic::Species, int> GraphNetwork::getNetReactionStoichiometry(const reaclib::REACLIBReaction& reaction) const {
// Calculates the net stoichiometric coefficients for species in a given reaction.
std::unordered_map<serif::atomic::Species, int> stoichiometry;
std::unordered_map<fourdst::atomic::Species, int> stoichiometry;
// Iterate through reactants, decrementing their counts
for (const auto& reactant : reaction.reactants()) {
@@ -208,7 +208,7 @@ namespace serif::network {
return true; // All reactions passed the conservation check
}
void GraphNetwork::validateComposition(const serif::composition::Composition &composition, double culling, double T9) {
void GraphNetwork::validateComposition(const fourdst::composition::Composition &composition, double culling, double T9) {
// Check if the requested network has already been cached.
// PERF: Rebuilding this should be pretty fast but it may be a good point of optimization in the future.
@@ -246,11 +246,11 @@ namespace serif::network {
size_t reactionColumnIndex = 0;
for (const auto& reaction : m_reactions) {
// Get the net stoichiometry for the current reaction
std::unordered_map<serif::atomic::Species, int> netStoichiometry = getNetReactionStoichiometry(reaction);
std::unordered_map<fourdst::atomic::Species, int> netStoichiometry = getNetReactionStoichiometry(reaction);
// Iterate through the species and their coefficients in the stoichiometry map
for (const auto& pair : netStoichiometry) {
const serif::atomic::Species& species = pair.first; // The Species object
const fourdst::atomic::Species& species = pair.first; // The Species object
const int coefficient = pair.second; // The stoichiometric coefficient
// Find the row index for this species
@@ -452,7 +452,7 @@ namespace serif::network {
}
std::vector<double> finalAbundances(Y.begin(), Y.begin() + numSpecies);
serif::composition::Composition outputComposition(speciesNames, finalAbundances);
fourdst::composition::Composition outputComposition(speciesNames, finalAbundances);
outputComposition.finalize(true);
NetOut netOut;

View File

@@ -23,18 +23,17 @@
#include <ranges>
#include "approx8.h"
#include "probe.h"
#include "quill/LogMacros.h"
#include "reaclib.h"
#include "reactions.h"
namespace serif::network {
namespace gridfire {
Network::Network(const NetworkFormat format) :
m_config(serif::config::Config::getInstance()),
m_logManager(serif::probe::LogManager::getInstance()),
m_config(fourdst::config::Config::getInstance()),
m_logManager(fourdst::logging::LogManager::getInstance()),
m_logger(m_logManager.getLogger("log")),
m_format(format),
m_constants(serif::constant::Constants::getInstance()){
m_constants(fourdst::constant::Constants::getInstance()){
if (format == NetworkFormat::UNKNOWN) {
LOG_ERROR(m_logger, "nuclearNetwork::Network::Network() called with UNKNOWN format");
throw std::runtime_error("nuclearNetwork::Network::Network() called with UNKNOWN format");
@@ -71,13 +70,13 @@ namespace serif::network {
return netOut;
}
serif::network::reaclib::REACLIBReactionSet build_reaclib_nuclear_network(const serif::composition::Composition &composition) {
using namespace serif::network::reaclib;
reaclib::REACLIBReactionSet build_reaclib_nuclear_network(const fourdst::composition::Composition &composition) {
using namespace reaclib;
REACLIBReactionSet reactions;
auto logger = serif::probe::LogManager::getInstance().getLogger("log");
auto logger = fourdst::logging::LogManager::getInstance().getLogger("log");
if (!s_initialized) {
LOG_INFO(serif::probe::LogManager::getInstance().getLogger("log"), "REACLIB reactions not initialized. Calling initializeAllReaclibReactions()...");
LOG_INFO(logger, "REACLIB reactions not initialized. Calling initializeAllReaclibReactions()...");
initializeAllReaclibReactions();
}
@@ -99,8 +98,8 @@ namespace serif::network {
return reactions;
}
serif::network::reaclib::REACLIBReactionSet build_reaclib_nuclear_network(const serif::composition::Composition &composition, const double culling, const double T9) {
using namespace serif::network::reaclib;
reaclib::REACLIBReactionSet build_reaclib_nuclear_network(const fourdst::composition::Composition &composition, const double culling, const double T9) {
using namespace reaclib;
REACLIBReactionSet allReactions = build_reaclib_nuclear_network(composition);
REACLIBReactionSet reactions;
for (const auto& reaction : allReactions) {

View File

@@ -31,10 +31,10 @@
* This is a general nuclear reaction network; however, it does not currently manage reverse reactions, weak reactions,
* or other reactions which become much more relevant for more extreme astrophysical sources.
*
* @see serif::network::GraphNetwork
* @see gridfire::GraphNetwork
*/
namespace serif::network {
namespace gridfire {
/**
* @brief Concept to check if a type is either double or CppAD::AD<double>.
@@ -80,7 +80,7 @@ namespace serif::network {
* @brief Construct a GraphNetwork from a composition.
* @param composition The composition specifying the initial isotopic abundances.
*/
explicit GraphNetwork(const serif::composition::Composition &composition);
explicit GraphNetwork(const fourdst::composition::Composition &composition);
/**
* @brief Construct a GraphNetwork from a composition with culling and temperature.
@@ -90,7 +90,7 @@ namespace serif::network {
*
* @see serif::network::build_reaclib_nuclear_network
*/
explicit GraphNetwork(const serif::composition::Composition &composition,
explicit GraphNetwork(const fourdst::composition::Composition &composition,
const double cullingThreshold, const double T9);
/**
@@ -123,7 +123,7 @@ namespace serif::network {
* }
* @endcode
*/
[[nodiscard]] const std::vector<serif::atomic::Species>& getNetworkSpecies() const;
[[nodiscard]] const std::vector<fourdst::atomic::Species>& getNetworkSpecies() const;
/**
* @brief Get the set of REACLIB reactions in the network.
@@ -149,7 +149,7 @@ namespace serif::network {
* }
* @endcode
*/
[[nodiscard]] std::unordered_map<serif::atomic::Species, int> getNetReactionStoichiometry(
[[nodiscard]] std::unordered_map<fourdst::atomic::Species, int> getNetReactionStoichiometry(
const reaclib::REACLIBReaction &reaction) const;
/**
@@ -162,7 +162,7 @@ namespace serif::network {
* if (net.involvesSpecies(mySpecies)) { ... }
* @endcode
*/
[[nodiscard]] bool involvesSpecies(const serif::atomic::Species& species) const;
[[nodiscard]] bool involvesSpecies(const fourdst::atomic::Species& species) const;
/**
* @brief Detect cycles in the reaction network (not implemented).
@@ -190,9 +190,9 @@ namespace serif::network {
reaclib::REACLIBReactionSet m_reactions; ///< Set of REACLIB reactions in the network.
std::unordered_map<std::string_view, const reaclib::REACLIBReaction> m_reactionIDMap; ///< Map from reaction ID to REACLIBReaction. //PERF: This makes copies of REACLIBReaction and could be a performance bottleneck.
std::vector<serif::atomic::Species> m_networkSpecies; ///< Vector of unique species in the network.
std::unordered_map<std::string_view, serif::atomic::Species> m_networkSpeciesMap; ///< Map from species name to Species object.
std::unordered_map<serif::atomic::Species, size_t> m_speciesToIndexMap; ///< Map from species to their index in the stoichiometry matrix.
std::vector<fourdst::atomic::Species> m_networkSpecies; ///< Vector of unique species in the network.
std::unordered_map<std::string_view, fourdst::atomic::Species> m_networkSpeciesMap; ///< Map from species name to Species object.
std::unordered_map<fourdst::atomic::Species, size_t> m_speciesToIndexMap; ///< Map from species to their index in the stoichiometry matrix.
boost::numeric::ublas::compressed_matrix<int> m_stoichiometryMatrix; ///< Stoichiometry matrix (species x reactions).
boost::numeric::ublas::compressed_matrix<double> m_jacobianMatrix; ///< Jacobian matrix (species x species).
@@ -357,7 +357,7 @@ namespace serif::network {
* @param culling Culling threshold.
* @param T9 Temperature in 10^9 K.
*/
void validateComposition(const serif::composition::Composition &composition, double culling, double T9);
void validateComposition(const fourdst::composition::Composition &composition, double culling, double T9);
// --- Simple Derivative Calculations ---
@@ -494,7 +494,7 @@ namespace serif::network {
template <IsArithmeticOrAD GeneralScalarType>
GeneralScalarType GraphNetwork::calculateReactionRate(const reaclib::REACLIBReaction &reaction, const std::vector<GeneralScalarType> &Y,
const GeneralScalarType T9, const GeneralScalarType rho) const {
const auto &constants = serif::constant::Constants::getInstance();
const auto &constants = fourdst::constant::Constants::getInstance();
const auto u = constants.get("u"); // Atomic mass unit in g/mol
const GeneralScalarType uValue = static_cast<GeneralScalarType>(u.value); // Convert to double for calculations

View File

@@ -22,7 +22,7 @@
#include <vector>
#include "probe.h"
#include "logging.h"
#include "config.h"
#include "quill/Logger.h"
#include "composition.h"
@@ -132,7 +132,7 @@ namespace gridfire {
protected:
fourdst::config::Config& m_config; ///< Configuration instance
fourdst::probe::LogManager& m_logManager; ///< Log manager instance
fourdst::logging::LogManager& m_logManager; ///< Log manager instance
quill::Logger* m_logger; ///< Logger instance
NetworkFormat m_format; ///< Format of the network