https://mooseframework.inl.gov
ReactionNetworkUtils.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "MooseTypes.h"
13 #include <string>
14 #include <optional>
15 
17 {
18 // Helper structs for parsing reaction network
19 struct Term
20 {
21  double coefficient;
22  std::string species;
23  // State is between parenthesis
24  std::optional<std::string> state;
25  std::optional<std::string> charge;
26 
27  // We don't compare the coefficient on purpose, to lump terms with different coefficients
28  // together
29  // NOTE: if you have a need to differentiate terms by terms by coefficients, you'll have
30  // to create a custom comparator
31  friend bool operator<(const Term & a, const Term & b) noexcept
32  {
33  if (a.species != b.species)
34  return a.species < b.species;
35  if (a.state != b.state)
36  return a.state < b.state;
37  return a.charge < b.charge;
38  }
39 };
40 
41 using TermList = std::vector<Term>;
42 using Metadata = std::map<std::string, std::string>;
43 
44 struct Reaction
45 {
49 
51  std::vector<VariableName> getSpecies() const;
54  std::vector<VariableName> getUniqueSpecies() const;
55 
58  std::vector<Real> getStoichiometricCoefficients() const;
64  std::map<VariableName, Real> getUniqueStoichiometricCoefficients() const;
65 
67  std::vector<VariableName> getReactantSpecies() const;
69  std::vector<VariableName> getUniqueReactantSpecies() const;
70 
72  std::vector<std::string> getProductSpecies() const;
74  std::vector<std::string> getUniqueProductSpecies() const;
75 
77  template <typename T>
78  bool hasMetaData(const std::string & key) const;
79 
81  bool hasMetaData(const std::string & key) const;
82 
84  const std::string & getMetaData(const std::string & key) const;
85 };
86 
90 std::vector<Reaction> parseReactionNetwork(const std::string & reaction_network_string,
91  bool output_to_cout);
92 }
93 
94 namespace Moose
95 {
96 std::string stringify(const ReactionNetworkUtils::Reaction & t);
97 }
std::vector< Term > TermList
std::map< std::string, std::string > Metadata
std::vector< std::string > getProductSpecies() const
Get all product species involved in the reaction (on RHS)
const std::string & getMetaData(const std::string &key) const
Get the metadata from the reaction.
std::vector< VariableName > getReactantSpecies() const
Get all reactant species involved in the reaction (on LHS)
std::vector< Real > getStoichiometricCoefficients() const
Get the stoeichiometric coefficients for each species in the reaction The sign used matches the sign ...
std::vector< VariableName > getSpecies() const
Get all species involved in the reaction.
std::string stringify(const T &t)
std::vector< std::string > getUniqueProductSpecies() const
Get all unique product species involved in the reaction (on RHS)
std::map< VariableName, Real > getUniqueStoichiometricCoefficients() const
Get the stoeichiometric coefficients for each unique species in the reaction Note: if a species is bo...
std::vector< Reaction > parseReactionNetwork(const std::string &reaction_network_string, bool output_to_cout)
Parses the reaction network from a string form to a vector a Reaction.
std::vector< VariableName > getUniqueSpecies() const
Get all unique species involved in the reaction Note: a species will only appear once even if both a ...
std::optional< std::string > charge
std::vector< VariableName > getUniqueReactantSpecies() const
Get all unique reactant species involved in the reaction (on LHS)
friend bool operator<(const Term &a, const Term &b) noexcept
std::optional< std::string > state
bool hasMetaData(const std::string &key) const
Whether the reaction has the metadata with the given type.