PRISM
 v0.0.0
Loading...
Searching...
No Matches
NetworkParser.h
1//* This file is a part of PRISM: Plasma Reaction Input SysteM,
2//* A library for parcing chemical reaction networks for plasma chemistry
3//* https://github.com/NCSU-ComPS-Group/prism
4//*
5//* Licensed under MIT, please see LICENSE for details
6//* https://opensource.org/license/mit
7//*
8//* Copyright 2024, North Carolina State University
9//* ALL RIGHTS RESERVED
10//*
11#pragma once
12
13#include "PrismConstants.h"
14
15#include <vector>
16#include <string>
17#include <unordered_map>
18#include "yaml-cpp/yaml.h"
19namespace prism
20{
21
22class Reaction;
23class Species;
24class SpeciesFactory;
25class BibTexHelper;
26class TableWriterBase;
28
33class NetworkParser
34{
35public:
37 static NetworkParser & instance();
39 void clear();
46 void parseNetwork(const std::string & file);
47
48// These methods are only available in testing mode
49// this allows for easier unit testing and should never
50// be made available for end users
51#ifdef TESTING
52 void setCheckRefs(const bool check_refs) { _check_refs = check_refs; }
53 void setReadXsecFiles(const bool read_xsec_files) { _read_xsec_files = read_xsec_files; }
54#endif
55
56 // Various getter methods for the different categories of reactions
57 // note these methods will exit the program if you have any errors in your reaction network
58 // we do not let users to perform a simulation with errors in the network or with lack of
59 // documentation
67 const std::vector<std::shared_ptr<Reaction>> & rateBasedReactions() const
68 {
69 preventInvalidDataFetch();
70 return _rate_based;
71 }
72
79 const std::vector<std::shared_ptr<Reaction>> & xsecBasedReactions() const
80 {
81 preventInvalidDataFetch();
82 return _xsec_based;
83 }
84
91 const std::vector<std::shared_ptr<const Reaction>> & tabulatedXSecReactions() const
92 {
93 preventInvalidDataFetch();
94 return _tabulated_xsec_based;
95 }
96
103 const std::vector<std::shared_ptr<const Reaction>> & functionXSecReactions() const
104 {
105 preventInvalidDataFetch();
106 return _function_xsec_based;
107 }
108
115 const std::vector<std::shared_ptr<const Reaction>> & tabulatedRateReactions() const
116 {
117 preventInvalidDataFetch();
118 return _tabulated_rate_based;
119 }
120
127 const std::vector<std::shared_ptr<const Reaction>> & functionRateReactions() const
128 {
129 preventInvalidDataFetch();
130 return _function_rate_based;
131 }
132
139 const std::vector<std::shared_ptr<const Species>> & transientSpecies() const;
147 const std::vector<std::string> & speciesNames() const;
148
156 const std::vector<std::shared_ptr<Species>> & species() const;
157
163 void writeReactionTable(const std::string & file) const;
169 void writeReactionTable(const std::string & file, TableWriterBase & writer) const;
175 void writeSpeciesSummary(const std::string & file);
182 void writeSpeciesSummary(const std::string & file, SpeciesSummaryWriterBase & writer) const;
183
184private:
186 NetworkParser();
188 NetworkParser(const NetworkParser &) = delete;
190 NetworkParser & operator=(const NetworkParser &) = delete;
191 SpeciesFactory & _factory;
192 BibTexHelper & _bib_helper;
195 static NetworkParser * _instance;
197 bool _network_has_errors;
199 bool _network_has_bib_errors;
202 bool _check_refs;
205 bool _read_xsec_files;
207 std::unordered_map<std::string, YAML::Node> _networks;
209 std::unordered_map<std::string, std::string> _bibs;
211 std::unordered_map<std::string, std::string> _data_paths;
213 std::unordered_map<std::string, std::string> _delimiters;
214 ReactionId _rate_id;
215 ReactionId _xsec_id;
223 void checkFile(const std::string & file) const;
230 void checkBibFile(const YAML::Node & network, const std::string & file) const;
231
244 void parseReactions(const YAML::Node & inputs,
245 ReactionId * rxn_id,
246 std::vector<std::shared_ptr<Reaction>> * rxn_list,
247 std::vector<std::shared_ptr<const Reaction>> * tabulated_rxn_list,
248 std::vector<std::shared_ptr<const Reaction>> * function_rxn_list,
249 const std::string & type,
250 const std::string & data_path,
251 const std::string & bib_file,
252 const std::string & _delimiter);
253
254 void tableHelper(TableWriterBase & writer,
255 void (TableWriterBase::*beginTable)(),
256 void (TableWriterBase::*endTable)(),
257 void (TableWriterBase::*addReaction)(const std::shared_ptr<const Reaction> & r),
258 const std::vector<std::shared_ptr<const Reaction>> & rxn_list) const;
265 void preventInvalidDataFetch() const;
266
270 std::vector<std::shared_ptr<Reaction>> _rate_based;
271 std::vector<std::shared_ptr<const Reaction>> _tabulated_rate_based;
272 std::vector<std::shared_ptr<const Reaction>> _function_rate_based;
273 std::vector<std::shared_ptr<Reaction>> _xsec_based;
274 std::vector<std::shared_ptr<const Reaction>> _tabulated_xsec_based;
275 std::vector<std::shared_ptr<const Reaction>> _function_xsec_based;
277};
278}
Class for collecting and managing cite keys from the user provided bib files.
Definition BibTexHelper.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:365
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:161
void writeReactionTable(const std::string &file, TableWriterBase &writer) const
Writes the latex table representation of the reaction mechanism this method uses whatever custom tabl...
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:79
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:103
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:91
void writeSpeciesSummary(const std::string &file, SpeciesSummaryWriterBase &writer) const
Writes a summary of the species in the network to a file this method uses whatever custom summary wri...
static NetworkParser & instance()
Getter for the singleton instance.
Definition NetworkParser.C:47
void writeSpeciesSummary(const std::string &file)
Writes a summary of the species in the network to a file this method using the default summary writer...
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:127
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:115
void clear()
Resets the parser to a fresh state, as if no networks have been processed.
Definition NetworkParser.C:57
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:67
void writeReactionTable(const std::string &file) const
Writes the latex table representation of the reaction mechanism this method uses the default table wr...
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:358
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:372
Stores all of the data needed to perform calculations with a specific reaction.
Definition Reaction.h:73
This factory creates and stores, and passes around all of the species that exist in a reaction mechan...
Definition SpeciesFactory.h:31
Definition SpeciesSummaryWriterBase.h:23
The species object which represents the products and reactants in the reaction.
Definition Species.h:47
Definition TableWriterBase.h:22