feat(network): added ReaclibNetwork and functions to build network

This commit is contained in:
2025-06-18 15:22:58 -04:00
parent cbaab3d04c
commit d00e5646e7
5 changed files with 8890 additions and 8824 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -18,6 +18,7 @@ dependencies = [
probe_dep,
species_weight_dep,
composition_dep,
reaclib_reactions_dep,
]
# Define the libnetwork library so it can be linked against by other parts of the build system

View File

@@ -20,9 +20,13 @@
// *********************************************************************** */
#include "network.h"
#include <ranges>
#include "approx8.h"
#include "probe.h"
#include "quill/LogMacros.h"
#include "reaclib.h"
#include "reactions.h"
namespace serif::network {
Network::Network(const NetworkFormat format) :
@@ -65,4 +69,43 @@ namespace serif::network {
}
return netOut;
}
serif::network::reaclib::REACLIBReactionSet build_reaclib_nuclear_network(const serif::composition::Composition &composition) {
using namespace serif::network::reaclib;
REACLIBReactionSet reactions;
if (!s_initialized) {
LOG_INFO(serif::probe::LogManager::getInstance().getLogger("log"), "REACLIB reactions not initialized. Calling initializeAllReaclibReactions()...");
initializeAllReaclibReactions();
}
for (const auto &reaction: s_all_reaclib_reactions | std::views::values) {
bool gotReaction = true;
const auto& reactants = reaction.reactants();
for (const auto& reactant : reactants) {
if (!composition.contains(reactant)) {
gotReaction = false;
break; // If any reactant is not in the composition, skip this reaction
}
}
if (gotReaction) {
reactions.add_reaction(reaction);
}
}
reactions.sort();
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;
REACLIBReactionSet allReactions = build_reaclib_nuclear_network(composition);
REACLIBReactionSet reactions;
for (const auto& reaction : allReactions) {
if (reaction.calculate_rate(T9) >= culling) {
reactions.add_reaction(reaction);
}
}
return reactions;
}
}

View File

@@ -26,6 +26,7 @@
#include "config.h"
#include "quill/Logger.h"
#include "composition.h"
#include "reaclib.h"
#include <unordered_map>
namespace serif::network {
@@ -105,7 +106,7 @@ namespace serif::network {
explicit Network(const NetworkFormat format = NetworkFormat::APPROX8);
virtual ~Network() = default;
NetworkFormat getFormat() const;
[[nodiscard]] NetworkFormat getFormat() const;
NetworkFormat setFormat(const NetworkFormat format);
/**
@@ -124,6 +125,19 @@ namespace serif::network {
NetworkFormat m_format; ///< Format of the network
};
class ReaclibNetwork final : public Network {
public:
explicit ReaclibNetwork(const NetworkFormat format = NetworkFormat::APPROX8);
explicit ReaclibNetwork(serif::composition::Composition composition, const NetworkFormat format = NetworkFormat::APPROX8);
NetOut evaluate(const NetIn &netIn) override;
private:
serif::network::reaclib::REACLIBReactionSet m_reactions; ///< Set of REACLIB reactions
};
serif::network::reaclib::REACLIBReactionSet build_reaclib_nuclear_network(const serif::composition::Composition &composition);
serif::network::reaclib::REACLIBReactionSet build_reaclib_nuclear_network(const serif::composition::Composition &composition, double culling, double T9 = 1.0);
} // namespace nuclearNetwork