PRISM
 v0.0.0
Loading...
Searching...
No Matches
NetworkParser.h
1#pragma once
2
3#include "Constants.h"
4
5#include <vector>
6#include <string>
7#include <unordered_map>
8#include "yaml-cpp/yaml.h"
9namespace prism
10{
11
12class Reaction;
13class Species;
14class SpeciesFactory;
15class BibTexHelper;
16class TableWriterBase;
17class SpeciesSummaryWriterBase;
18
24{
25public:
27 static NetworkParser & instance();
29 void clear();
36 void parseNetwork(const std::string & file);
37
38// These methods are only available in testing mode
39// this allows for easier unit testing and should never
40// be made available for end users
41#ifdef TESTING
42 void setCheckRefs(const bool check_refs) { _check_refs = check_refs; }
43 void setReadXsecFiles(const bool read_xsec_files) { _read_xsec_files = read_xsec_files; }
44#endif
45
53 void setDelimiter(const std::string & delimiter);
58 void writeSpeciesSummary(const std::string & file);
59
60 // Various getter methods for the different categories of reactions
61 // note these methods will exit the program if you have any errors in your reaction network
62 // we do not let users to perform a simulation with errors in the network or with lack of
63 // documentation
71 const std::vector<std::shared_ptr<Reaction>> & rateBasedReactions() const
72 {
73 preventInvalidDataFetch();
74 return _rate_based;
75 }
83 const std::vector<std::shared_ptr<Reaction>> & xsecBasedReactions() const
84 {
85 preventInvalidDataFetch();
86 return _xsec_based;
87 }
95 const std::vector<std::shared_ptr<const Reaction>> & tabulatedXSecReactions() const
96 {
97 preventInvalidDataFetch();
98 return _tabulated_xsec_based;
99 }
107 const std::vector<std::shared_ptr<const Reaction>> & functionXSecReactions() const
108 {
109 preventInvalidDataFetch();
110 return _function_xsec_based;
111 }
119 const std::vector<std::shared_ptr<const Reaction>> & tabulatedRateReactions() const
120 {
121 preventInvalidDataFetch();
122 return _tabulated_rate_based;
123 }
131 const std::vector<std::shared_ptr<const Reaction>> & functionRateReactions() const
132 {
133 preventInvalidDataFetch();
134 return _function_rate_based;
135 }
143 const std::vector<std::shared_ptr<const Species>> & transientSpecies() const;
151 const std::vector<std::string> & speciesNames() const;
152
160 const std::vector<std::shared_ptr<Species>> & species() const;
161
162 void writeReactionTable(const std::string & file) const;
163 void writeReactionTable(const std::string & file, TableWriterBase & writer) const;
164 void writeSpeciesSummary(const std::string & file, SpeciesSummaryWriterBase & writer) const;
165
166private:
170 NetworkParser(const NetworkParser &) = delete;
172 NetworkParser & operator=(const NetworkParser &) = delete;
173 SpeciesFactory & _factory;
174 BibTexHelper & _bib_helper;
177 static NetworkParser * _instance;
179 std::string _delimiter;
181 bool _network_has_errors;
183 bool _network_has_bib_errors;
186 bool _check_refs;
189 bool _read_xsec_files;
191 std::unordered_map<std::string, YAML::Node> _networks;
193 std::unordered_map<std::string, std::string> _bibs;
195 std::unordered_map<std::string, std::string> _data_paths;
196 ReactionId _rate_id;
197 ReactionId _xsec_id;
205 void checkFile(const std::string & file) const;
212 void checkBibFile(const std::string & file) const;
213
226 void parseReactions(const YAML::Node & inputs,
227 ReactionId * rxn_id,
228 std::vector<std::shared_ptr<Reaction>> * rxn_list,
229 std::vector<std::shared_ptr<const Reaction>> * tabulated_rxn_list,
230 std::vector<std::shared_ptr<const Reaction>> * function_rxn_list,
231 const std::string & type,
232 const std::string & data_path,
233 const std::string & bib_file);
234
235 void tableHelper(TableWriterBase & writer,
236 void (TableWriterBase::*beginTable)(),
237 void (TableWriterBase::*endTable)(),
238 void (TableWriterBase::*addReaction)(const std::shared_ptr<const Reaction> & r),
239 const std::vector<std::shared_ptr<const Reaction>> & rxn_list) const;
246 void preventInvalidDataFetch() const;
247
251 std::vector<std::shared_ptr<Reaction>> _rate_based;
252 std::vector<std::shared_ptr<const Reaction>> _tabulated_rate_based;
253 std::vector<std::shared_ptr<const Reaction>> _function_rate_based;
254 std::vector<std::shared_ptr<Reaction>> _xsec_based;
255 std::vector<std::shared_ptr<const Reaction>> _tabulated_xsec_based;
256 std::vector<std::shared_ptr<const Reaction>> _function_xsec_based;
258};
259}
Class for collecting and managing cite keys from the user provided bib files.
Definition BibTexHelper.h:14
This is the class that processes reaction networks and allows for interaction with the data contained...
Definition NetworkParser.h:24
const std::vector< std::shared_ptr< Species > > & species() const
Gets all of the species in the network This function will also exist the program if there are any err...
Definition NetworkParser.C:331
void parseNetwork(const std::string &file)
Method goes through all of the reactions in this network constructs Reaction objects and then puts th...
Definition NetworkParser.C:156
const std::vector< std::shared_ptr< Reaction > > & xsecBasedReactions() const
Gets all of the reactions in the xsec-based block that have cross section data in a file.
Definition NetworkParser.h:83
const std::vector< std::shared_ptr< const Reaction > > & functionXSecReactions() const
Gets all of the reactions in the xsec-based block that have cross section that can be represented wit...
Definition NetworkParser.h:107
const std::vector< std::shared_ptr< const Reaction > > & tabulatedXSecReactions() const
Gets all of the reactions in the xsec-based block that have cross section data in a file.
Definition NetworkParser.h:95
static NetworkParser & instance()
Getter for the singleton instance.
Definition NetworkParser.C:39
void setDelimiter(const std::string &delimiter)
Sets the delimiter for the networks which have some tabulated data.
Definition NetworkParser.C:49
void writeSpeciesSummary(const std::string &file)
Writes a summary of the species in the network to a file.
const std::vector< std::shared_ptr< const Reaction > > & functionRateReactions() const
Gets all of the reactions in the xsec-based block that have rate data that can be represented with a ...
Definition NetworkParser.h:131
const std::vector< std::shared_ptr< const Reaction > > & tabulatedRateReactions() const
Gets all of the reactions in the xsec-based block that have rate data in a file.
Definition NetworkParser.h:119
void clear()
Resets the parser to a fresh state, as if no networks have been processed.
Definition NetworkParser.C:62
const std::vector< std::shared_ptr< Reaction > > & rateBasedReactions() const
Gets all of the reactions in the xsec-based block that have cross section data in a file.
Definition NetworkParser.h:71
const std::vector< std::string > & speciesNames() const
Gets the names of all of the species in the network This function will also exist the program if ther...
Definition NetworkParser.C:324
const std::vector< std::shared_ptr< const Species > > & transientSpecies() const
Gets all of the species in the network that have a non-zero This function will also exist the program...
Definition NetworkParser.C:338
Stores all of the data needed to perform calculations with a specific reaction.
Definition Reaction.h:63
This factory creates and stores, and passes around all of the species that exist in a reaction mechan...
Definition SpeciesFactory.h:21
Definition SpeciesSummaryWriterBase.h:13
Definition TableWriterBase.h:12