SERiF 0.0.1a
3+1D Stellar Structure and Evolution
Loading...
Searching...
No Matches
network.cpp
Go to the documentation of this file.
1/* ***********************************************************************
2//
3// Copyright (C) 2025 -- The 4D-STAR Collaboration
4// File Authors: Aaron Dotter, Emily Boudreaux
5// Last Modified: March 21, 2025
6//
7// 4DSSE is free software; you can use it and/or modify
8// it under the terms and restrictions the GNU General Library Public
9// License version 3 (GPLv3) as published by the Free Software Foundation.
10//
11// 4DSSE is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14// See the GNU Library General Public License for more details.
15//
16// You should have received a copy of the GNU Library General Public License
17// along with this software; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19//
20// *********************************************************************** */
21#include "network.h"
22
23#include <ranges>
24
25#include "approx8.h"
26#include "probe.h"
27#include "quill/LogMacros.h"
28#include "reaclib.h"
29#include "reactions.h"
30
31namespace serif::network {
33 m_config(serif::config::Config::getInstance()),
34 m_logManager(serif::probe::LogManager::getInstance()),
35 m_logger(m_logManager.getLogger("log")),
36 m_format(format),
37 m_constants(serif::constant::Constants::getInstance()){
38 if (format == NetworkFormat::UNKNOWN) {
39 LOG_ERROR(m_logger, "nuclearNetwork::Network::Network() called with UNKNOWN format");
40 throw std::runtime_error("nuclearNetwork::Network::Network() called with UNKNOWN format");
41 }
42 }
43
45 return m_format;
46 }
47
49 const NetworkFormat oldFormat = m_format;
50 m_format = format;
51 return oldFormat;
52 }
53
55 NetOut netOut;
56 switch (m_format) {
57 case APPROX8: {
59 netOut = network.evaluate(netIn);
60 break;
61 }
62 case UNKNOWN: {
63 LOG_ERROR(m_logger, "Network format {} is not implemented.", FormatStringLookup.at(m_format));
64 throw std::runtime_error("Network format not implemented.");
65 }
66 default: {
67 LOG_ERROR(m_logger, "Unknown network format.");
68 throw std::runtime_error("Unknown network format.");
69 }
70 }
71 return netOut;
72 }
73
74 serif::network::reaclib::REACLIBReactionSet build_reaclib_nuclear_network(const serif::composition::Composition &composition) {
75 using namespace serif::network::reaclib;
76 REACLIBReactionSet reactions;
78
79 if (!s_initialized) {
80 LOG_INFO(serif::probe::LogManager::getInstance().getLogger("log"), "REACLIB reactions not initialized. Calling initializeAllReaclibReactions()...");
81 initializeAllReaclibReactions();
82 }
83
84 for (const auto &reaction: s_all_reaclib_reactions | std::views::values) {
85 bool gotReaction = true;
86 const auto& reactants = reaction.reactants();
87 for (const auto& reactant : reactants) {
88 if (!composition.contains(reactant)) {
89 gotReaction = false;
90 break; // If any reactant is not in the composition, skip this reaction
91 }
92 }
93 if (gotReaction) {
94 LOG_INFO(logger, "Adding reaction {} to REACLIB reaction set.", reaction.id());
95 reactions.add_reaction(reaction);
96 }
97 }
98 reactions.sort();
99 return reactions;
100 }
101
102 serif::network::reaclib::REACLIBReactionSet build_reaclib_nuclear_network(const serif::composition::Composition &composition, const double culling, const double T9) {
103 using namespace serif::network::reaclib;
104 REACLIBReactionSet allReactions = build_reaclib_nuclear_network(composition);
105 REACLIBReactionSet reactions;
106 for (const auto& reaction : allReactions) {
107 if (reaction.calculate_rate(T9) >= culling) {
108 reactions.add_reaction(reaction);
109 }
110 }
111 return reactions;
112 }
113
114}
Header file for the Approx8 nuclear reaction network.
Manages the composition of elements.
virtual NetOut evaluate(const NetIn &netIn)
Evaluate the network based on the input parameters.
Definition network.cpp:54
NetworkFormat setFormat(const NetworkFormat format)
Definition network.cpp:48
serif::probe::LogManager & m_logManager
Log manager instance.
Definition network.h:135
NetworkFormat m_format
Format of the network.
Definition network.h:138
NetworkFormat getFormat() const
Definition network.cpp:44
Network(const NetworkFormat format=NetworkFormat::APPROX8)
Definition network.cpp:32
serif::constant::Constants & m_constants
Definition network.h:139
quill::Logger * m_logger
Logger instance.
Definition network.h:136
serif::config::Config & m_config
Configuration instance.
Definition network.h:134
Class for the Approx8 nuclear reaction network.
Definition approx8.h:294
quill::Logger * getLogger(const std::string &loggerName)
Get a logger by name.
Definition probe.cpp:219
static LogManager & getInstance()
Get the singleton instance of LogManager.
Definition probe.h:103
@ APPROX8
Approx8 nuclear reaction network format.
Definition network.h:37
serif::network::reaclib::REACLIBReactionSet build_reaclib_nuclear_network(const serif::composition::Composition &composition)
Definition network.cpp:74
static std::unordered_map< NetworkFormat, std::string > FormatStringLookup
Definition network.h:42
The Probe namespace contains utility functions for debugging and logging.
Definition probe.cpp:45
Input structure for the network evaluation.
Definition network.h:65
Output structure for the network evaluation.
Definition network.h:89