GridFire 0.0.1a
General Purpose Nuclear Network
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 "gridfire/network.h"
24
25#include <ranges>
26
27#include "quill/LogMacros.h"
28
29namespace gridfire {
30 std::vector<double> NetIn::MolarAbundance() const {
31 std::vector <double> y;
32 y.reserve(composition.getRegisteredSymbols().size());
33 const auto [fst, snd] = composition.getComposition();
34 for (const auto &name: fst | std::views::keys) {
35 y.push_back(composition.getMolarAbundance(name));
36 }
37 return y;
38 }
39
40
42 m_config(fourdst::config::Config::getInstance()),
43 m_logManager(fourdst::logging::LogManager::getInstance()),
44 m_logger(m_logManager.getLogger("log")),
45 m_format(format),
46 m_constants(fourdst::constant::Constants::getInstance()){
47 if (format == NetworkFormat::UNKNOWN) {
48 LOG_ERROR(m_logger, "nuclearNetwork::Network::Network() called with UNKNOWN format");
49 m_logger->flush_log();
50 throw std::runtime_error("nuclearNetwork::Network::Network() called with UNKNOWN format");
51 }
52 }
53
55 return m_format;
56 }
57
59 const NetworkFormat oldFormat = m_format;
60 m_format = format;
61 return oldFormat;
62 }
63
64 reaction::LogicalReactionSet build_reaclib_nuclear_network(const fourdst::composition::Composition &composition, bool reverse) {
65 using namespace reaction;
66 std::vector<Reaction> reaclibReactions;
67 auto logger = fourdst::logging::LogManager::getInstance().getLogger("log");
68
69 for (const auto &reaction: reaclib::get_all_reactions()) {
70 if (reaction.is_reverse() != reverse) {
71 continue; // Skip reactions that do not match the requested direction
72 }
73 bool gotReaction = true;
74 const auto& reactants = reaction.reactants();
75 for (const auto& reactant : reactants) {
76 if (!composition.contains(reactant)) {
77 gotReaction = false;
78 break; // If any reactant is not in the composition, skip this reaction
79 }
80 }
81 if (gotReaction) {
82 LOG_TRACE_L3(logger, "Adding reaction {} to REACLIB reaction set.", reaction.peName());
83 reaclibReactions.push_back(reaction);
84 }
85 }
86 const ReactionSet reactionSet(reaclibReactions);
87 return packReactionSetToLogicalReactionSet(reactionSet);
88 }
89
90 // Trim whitespace from both ends of a string
91 std::string trim_whitespace(const std::string& str) {
92 auto startIt = str.begin();
93 auto endIt = str.end();
94
95 while (startIt != endIt && std::isspace(static_cast<unsigned char>(*startIt))) {
96 ++startIt;
97 }
98 if (startIt == endIt) {
99 return "";
100 }
101 auto ritr = std::find_if(str.rbegin(), std::string::const_reverse_iterator(startIt),
102 [](unsigned char ch){ return !std::isspace(ch); });
103 return std::string(startIt, ritr.base());
104 }
105
106}
fourdst::logging::LogManager & m_logManager
Log manager instance.
Definition network.h:97
Network(const NetworkFormat format=NetworkFormat::APPROX8)
Definition network.cpp:41
NetworkFormat getFormat() const
Definition network.cpp:54
NetworkFormat m_format
Format of the network.
Definition network.h:100
NetworkFormat setFormat(const NetworkFormat format)
Definition network.cpp:58
quill::Logger * m_logger
Logger instance.
Definition network.h:98
fourdst::config::Config & m_config
Configuration instance.
Definition network.h:96
fourdst::constant::Constants & m_constants
Definition network.h:101
const reaction::LogicalReactionSet & get_all_reactions()
Provides global access to the fully initialized REACLIB reaction set.
Definition reaclib.cpp:138
TemplatedReactionSet< LogicalReaction > LogicalReactionSet
A set of logical reactions.
Definition reaction.h:557
NetworkFormat
Definition network.h:41
@ UNKNOWN
Definition network.h:44
std::string trim_whitespace(const std::string &str)
Definition network.cpp:91
reaction::LogicalReactionSet build_reaclib_nuclear_network(const fourdst::composition::Composition &composition, bool reverse)
Definition network.cpp:64
Defines classes for representing and managing nuclear reactions.
fourdst::composition::Composition composition
Composition of the network.
Definition network.h:54
std::vector< double > MolarAbundance() const
Definition network.cpp:30