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"
22#include "gridfire/reaction/reaclib.h"
23#include "gridfire/reaction/reaction.h"
24
25#include <ranges>
26
27#include "quill/LogMacros.h"
28
29 namespace 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
41 Network::Network(const NetworkFormat format) :
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
54 NetworkFormat Network::getFormat() const {
55 return m_format;
56 }
57
58 NetworkFormat Network::setFormat(const NetworkFormat format) {
59 const NetworkFormat oldFormat = m_format;
60 m_format = format;
61 return oldFormat;
62 }
63
64 // Trim whitespace from both ends of a string
65 std::string trim_whitespace(const std::string& str) {
66 auto startIt = str.begin();
67 const auto endIt = str.end();
68
69 while (startIt != endIt && std::isspace(static_cast<unsigned char>(*startIt))) {
70 ++startIt;
71 }
72 if (startIt == endIt) {
73 return "";
74 }
75 const auto ritr = std::find_if(str.rbegin(), std::string::const_reverse_iterator(startIt),
76 [](const unsigned char ch){ return !std::isspace(ch); });
77 return std::string(startIt, ritr.base());
78 }
79
80}
gridfire::Network::m_logManager
fourdst::logging::LogManager & m_logManager
Log manager instance.
Definition network.h:97
gridfire::Network::Network
Network(const NetworkFormat format=NetworkFormat::APPROX8)
Definition network.cpp:41
gridfire::Network::getFormat
NetworkFormat getFormat() const
Definition network.cpp:54
gridfire::Network::m_format
NetworkFormat m_format
Format of the network.
Definition network.h:100
gridfire::Network::setFormat
NetworkFormat setFormat(const NetworkFormat format)
Definition network.cpp:58
gridfire::Network::m_logger
quill::Logger * m_logger
Logger instance.
Definition network.h:98
gridfire::Network::m_config
fourdst::config::Config & m_config
Configuration instance.
Definition network.h:96
gridfire::Network::m_constants
fourdst::constant::Constants & m_constants
Definition network.h:101
gridfire
Definition engine_abstract.h:31
gridfire::NetworkFormat
NetworkFormat
Definition network.h:41
gridfire::UNKNOWN
@ UNKNOWN
Definition network.h:44
gridfire::trim_whitespace
std::string trim_whitespace(const std::string &str)
Definition network.cpp:65
network.h
reaclib.h
reaction.h
Defines classes for representing and managing nuclear reactions.
gridfire::NetIn::composition
fourdst::composition::Composition composition
Composition of the network.
Definition network.h:54
gridfire::NetIn::MolarAbundance
std::vector< double > MolarAbundance() const
Definition network.cpp:30