PRISM
 v0.0.0
Loading...
Searching...
No Matches
Reaction.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 <utility>
14#include <string>
15#include <vector>
16#include <unordered_map>
17#include "yaml-cpp/yaml.h"
18#include "Species.h"
19#include "PrismConstants.h"
20#include <functional>
21namespace prism
22{
28{
30 double energy;
32 double value;
33
39 bool operator<(const TabulatedReactionData & other) const { return energy < other.energy; }
45 bool operator<(const double other) const { return energy < other; }
50 bool operator==(const TabulatedReactionData & other) const
51 {
52 return (energy == other.energy) && (value == other.value);
53 }
54};
55
61{
63 SpeciesId id;
65 unsigned int occurances;
66};
67
73{
74public:
96 Reaction(const YAML::Node & rxn_input,
97 const int rxn_id = 0,
98 const std::string & data_path = "",
99 const std::string & bib_file = "",
100 const bool check_refs = true,
101 const bool read_xsec_files = true,
102 const std::string & delimiter = " ");
103
107 const std::string & expression() const { return _expression; }
111 const std::string & latexRepresentation() const { return _latex_expression; }
119 ReactionId id() const { return _id; }
123 const std::vector<std::string> & references() const { return _references; }
127 const std::vector<std::string> & notes() const { return _notes; }
131 bool hasTabulatedData() const { return _has_tabulated_data; }
135 double deltaEnergyElectron() const { return _delta_eps_e; }
139 double deltaEnergyGas() const { return _delta_eps_g; }
143 const std::vector<SpeciesData> & reactantData() const { return _reactant_data; }
147 const std::vector<SpeciesData> & productData() const { return _product_data; }
151 bool isElastic() const { return _is_elastic; }
156 const std::vector<std::shared_ptr<const Species>> species() const;
160 const std::string getReferencesAsString() const;
166 const std::vector<double> & functionParams() const;
172 const std::vector<TabulatedReactionData> & tabulatedData() const;
181 int getStoicCoeffByName(const std::string & s_expression) const;
189 int getStoicCoeffById(const SpeciesId id) const;
194 bool operator==(const Reaction & other) const;
196 bool operator!=(const Reaction & other) const;
206 double sampleData(const double T_e, const double T_g = 0) const { return _sampler(T_e, T_g); }
207
208 std::string to_string() const;
209
210 friend std::string to_string(const std::shared_ptr<prism::Reaction> & s);
211 friend std::string to_string(const std::shared_ptr<const prism::Reaction> & s);
212 friend std::ostream & operator<<(std::ostream & os, const std::shared_ptr<prism::Reaction> & s);
213 friend std::ostream & operator<<(std::ostream & os,
214 const std::shared_ptr<const prism::Reaction> & s);
215
216private:
218 friend class SpeciesFactory;
219 friend class NetworkParser;
224 std::string checkExpression(const YAML::Node & rxn_input);
225
230 unsigned int getCoeff(std::string & s);
231
236 void setSides();
238 void validateReaction();
240 void setLatexRepresentation();
242 void substituteLumped();
244 void checkReferences();
246 void collectUniqueSpecies();
248 void setSpeciesData();
254 double interpolator(const double T_e, const double T_g) const;
256 double constantRate(const double T_e, const double T_g) const;
257 double partialArrhenius1(const double T_e, const double T_g) const;
258 double partialArrhenius2(const double T_e, const double T_g) const;
259 double partialArrhenius3(const double T_e, const double T_g) const;
260 double fullArrhenius(const double T_e, const double T_g) const;
262 std::function<double(double, double)> _sampler;
264 const ReactionId _id;
266 const std::string _data_path;
268 const std::string _expression;
270 const double _delta_eps_e;
272 const double _delta_eps_g;
274 const bool _is_elastic;
276 const std::string _bib_file;
278 const std::vector<std::string> _references;
280 bool _has_tabulated_data;
282 std::vector<std::string> _notes;
284 std::vector<double> _params;
286 std::vector<TabulatedReactionData> _tabulated_data;
288 std::vector<std::weak_ptr<Species>> _species;
290 std::unordered_map<std::string, int> _stoic_coeffs;
292 std::unordered_map<SpeciesId, int> _id_stoic_map;
294 std::string _latex_expression;
295
299 std::vector<std::weak_ptr<Species>> _reactants;
300 std::vector<std::weak_ptr<Species>> _products;
301 std::unordered_map<std::string, unsigned int> _reactant_count;
302 std::unordered_map<std::string, unsigned int> _product_count;
309 std::vector<SpeciesData> _reactant_data;
310 std::vector<SpeciesData> _product_data;
312};
313}
314
315template <>
316struct std::hash<prism::Reaction>
317{
325 size_t operator()(const prism::Reaction & obj) const;
326};
Stores all of the data needed to perform calculations with a specific reaction.
Definition Reaction.h:73
double deltaEnergyElectron() const
Self descriptive getter method.
Definition Reaction.h:135
const std::vector< std::shared_ptr< const Species > > species() const
Getter method for the list of species in this reaction this is a relatively expensive method and call...
Definition Reaction.C:195
const std::string getReferencesAsString() const
Getter method for getting cite keys formatted for LaTeX.
Definition Reaction.C:681
bool hasTabulatedData() const
Self descriptive getter method.
Definition Reaction.h:131
const std::string & latexRepresentation() const
Self descriptive getter method.
Definition Reaction.h:111
Reaction(const YAML::Node &rxn_input, const int rxn_id=0, const std::string &data_path="", const std::string &bib_file="", const bool check_refs=true, const bool read_xsec_files=true, const std::string &delimiter=" ")
Definition Reaction.C:29
bool operator!=(const Reaction &other) const
returns not == operator overload
Definition Reaction.C:675
const std::string & expression() const
Self descriptive getter method.
Definition Reaction.h:107
const std::vector< std::string > & references() const
Self descriptive getter method.
Definition Reaction.h:123
bool operator==(const Reaction &other) const
equality operator override and compares the reaction name the latex name of the reaction and the reac...
Definition Reaction.C:660
const std::vector< TabulatedReactionData > & tabulatedData() const
Retrurns a reference to the struct containing data read from a file.
Definition Reaction.C:650
const std::vector< SpeciesData > & reactantData() const
Self descriptive getter method.
Definition Reaction.h:143
int getStoicCoeffById(const SpeciesId id) const
Get the stoiciometric coefficient for a species in this reaction by its id.
Definition Reaction.C:705
double deltaEnergyGas() const
Self descriptive getter method.
Definition Reaction.h:139
bool isElastic() const
Wether or not the user set a reaction as elastic or not.
Definition Reaction.h:151
const std::vector< SpeciesData > & productData() const
Self descriptive getter method.
Definition Reaction.h:147
int getStoicCoeffByName(const std::string &s_expression) const
Get the stoiciometric coefficient for a species in this reaction by the name that represents it Ex: "...
Definition Reaction.C:694
friend class SpeciesFactory
SpeciesFactor is a friend so that it can access the species in this reaction.
Definition Reaction.h:218
double sampleData(const double T_e, const double T_g=0) const
Samples data at the point T_e and T_g based on the provided parameters If the reaction object has tab...
Definition Reaction.h:206
const std::vector< double > & functionParams() const
Returns a reference to the function parameters if there is functional data.
Definition Reaction.C:640
const std::vector< std::string > & notes() const
Self descriptive getter method.
Definition Reaction.h:127
ReactionId id() const
Self descriptive getter method note that Reactions ids are based on the block reactions are in all re...
Definition Reaction.h:119
Struct for quickly accessing data about which speies are in a reaction.
Definition Reaction.h:61
SpeciesId id
the unique id for the species (guaranteed to be in the range 0-(n-1) where n in the number unique spe...
Definition Reaction.h:63
unsigned int occurances
the number of times the species occurs on a side of the reaction
Definition Reaction.h:65
Struct for holding tabulated data read from user provided files.
Definition Reaction.h:28
bool operator<(const double other) const
< operator only compares the energy values this is used for sorting and to be able to use other stand...
Definition Reaction.h:45
double value
where the data from the secdon column of the file is stored
Definition Reaction.h:32
bool operator<(const TabulatedReactionData &other) const
< operator only compares the energy values this is used for sorting and to be able to use other stand...
Definition Reaction.h:39
double energy
where the data from the first column of the file is stored
Definition Reaction.h:30
bool operator==(const TabulatedReactionData &other) const
equality operator checks to make sure both values are in the struct are the same
Definition Reaction.h:50
size_t operator()(const prism::Reaction &obj) const
Override for the hash method hash is based on std::string representation of the reaction the reaction...