File reaction_parser.hxx#
Defines
-
REACTION_PARSER_H#
Enums
Functions
-
static inline void count_species(std::string expr, std::map<std::string, int> &counts, std::vector<std::string> &ordered_species_names)#
-
class ReactionParser#
- #include <reaction_parser.hxx>
A class to parse reaction strings and extract the stoichiometric vector (net population changes for each species). Also used to retrieve the names of species in various useful subsets (reactants, products, non-electron species, etc.)
Public Functions
-
ReactionParser(const std::string &reaction_str)#
-
inline const std::string get_reaction_str() const#
Public getter for underlying reaction string.
-
template<typename ...FilterTypes>
inline std::string get_single_species(std::vector<std::string> species_names, species_filter first_filter, FilterTypes... other_filters) const# Apply one or more filters to a list of species names and return the one and only match.
Variadic so that it can be applied recursively.
- Throws:
BoutException – if there isn’t exactly one match.
- Template Parameters:
FilterTypes –
- Parameters:
species_names – the list of species names to filter
first_filter – the first filter
other_filters – zero or more other filters
- Returns:
std::string the matching species name
-
template<typename ...FilterTypes>
inline std::string get_single_species(FilterTypes... filters) const# Apply one or more filters to the list of species identified by the parser and return the one and only match.
- Throws:
BoutException – if there is more than one match.
- Template Parameters:
FilterTypes –
- Parameters:
filters – one or more instances of species_filter
- Returns:
std::string the matching species name
-
std::vector<std::string> get_species() const#
Get the names of all species identified by the parser.
- Returns:
std::vector<std::string> the list of species names
-
std::vector<std::string> get_species(species_filter filter) const#
Apply a filter to the list of species identified by the parser.
- Parameters:
filter – the filter to apply
- Returns:
std::vector<std::string> the filterered list of species names
-
std::vector<std::string> get_species(std::vector<std::string> species_names, species_filter filter) const#
Apply a filter to a list of species names.
- Parameters:
species_names – the list of species names to filter
filter – the filter to apply
- Returns:
std::vector<std::string> the filtered list of names
-
template<typename ...FilterTypes>
inline std::vector<std::string> get_species(std::vector<std::string> species_names, species_filter first_filter, FilterTypes... other_filters) const# Apply multiple filters to a list of species names.
Variadic so that it can be applied recursively.
- Template Parameters:
FilterTypes –
- Parameters:
species_names – the list of species names to filter
first_filter – the first filter
other_filters – other filters
- Returns:
std::vector<std::string> the filtered list of names
-
template<typename ...FilterTypes>
inline std::vector<std::string> get_species(FilterTypes... filters) const# Apply multiple filters to the list of species identified by the parser.
Variadic so that it can be applied recursively.
- Template Parameters:
FilterTypes –
- Parameters:
filters – one or more instances of species_filter
- Returns:
std::vector<std::string> the filtered list of names
-
const std::multimap<std::string, int> &get_mom_energy_pop_changes() const#
Return a map of population changes to use when computing momentum and energy transfer. For non-symmetric reactions, this is the normal stoichiometry vector; for symmetric reactions, it returns the ‘split’ version, where species names are repeated, with -ve values for reactants and +ve values for products.
- Returns:
const std::map<std::string, int>&
-
inline std::string get_reactant_by_position(std::size_t pos) const#
Get a reactant by its position in the reaction string (first reactant at position 1)
- Parameters:
pos –
- Returns:
std::string
-
inline std::string get_product_by_position(std::size_t pos) const#
Get a product by its position in the reaction string (first product at position 1)
- Parameters:
pos –
- Returns:
std::string
-
bool is_symmetric() const#
Check if the reaction is symmetric (LHS == RHS, allowing reordering of terms).
- Returns:
true if the reaction is symmetric
- Returns:
false otherwise
-
int pop_change(const std::string sp_name) const#
Get the overall population change of a species.
- Parameters:
sp_name – the species name
- Returns:
int the population change
-
int pop_change_product(const std::string sp_name) const#
Get the population change of a product species. If the left and right sides of the reaction string are the same, return the change on the PRODUCT SIDE ONLY, otherwise return the usual net population change.
- Parameters:
sp_name – the species name
- Returns:
int the population change
-
int pop_change_reactant(const std::string sp_name) const#
Get the population change of a reactant species. If the left and right sides of the reaction string are the same, return the change on the REACTANT SIDE ONLY, otherwise return the usual net population change.
- Parameters:
sp_name – the species name
- Returns:
int the population change
Private Functions
-
void diff_reactants_products(const std::map<std::string, int> &R, const std::map<std::string, int> &P)#
Util function to compute the stoichiometric ‘vector’ (map) by taking the difference between the reactant and product population changes. Also computes a separate version used for momentum and energy sources. This second map differs from the first if the reaction is symmetric, in which case each species appear twice, once with the (-ve) reactant pop. change and once with the (+ve) product pop. change.
- Parameters:
R – the reactant population changes
P – the product population changes
Private Members
-
const std::string reaction_str#
The reaction string.
-
std::map<std::string, int> reactants#
Map of species name => population change for reactants.
-
std::map<std::string, int> products#
Map of species name => population change for products.
-
std::map<std::string, int> stoich#
Stoichiometric ‘vector’ (map of species name => population change)
-
std::multimap<std::string, int> mom_energy_stoich#
‘Split’ stoichiometric values. useful when dealing with symmetric reactions. Species names appear twice, once with the -ve (reactant) pop. change, once with the +ve (product) pop. change.
-
std::vector<std::string> ordered_reactants#
-
std::vector<std::string> ordered_products#
-
bool symmetric#
Flag to identify reactions where LHS == RHS (e.g. symmetric CX)
-
ReactionParser(const std::string &reaction_str)#