ReactionNetworkUtils

commentnote

For the [ReactionNetwork] syntax parser, see this page instead. This utility is currently used by the [Physics] syntax.

Reaction network parser using a Parsed Expression Grammar

The chemical reactions module includes a reaction network parser this utility that enables chemical reactions to be specified in a natural form in the input file. This parser is notably used by the AqueousReactionsEquilibriumPhysics.

The input file syntax for reactions has to be written in the following form:

Individual reactions are provided with the reactant species on the left hand side, while the product species follow the -> sign, followed by metadata in between square brackets. A linebreak is used to delimit reactions, so that multiple reactions can be entered.

commentnote

The AqueousReactionsEquilibriumPhysics currently only supports one product species per reaction, on the right hand side, as shown in the second equation in the example.

are coefficients which have to be floating point number in the regular non-scientific notation. Metadata keys and values are parsed as strings. The values may be floating point numbers or names of properties, though AqueousReactionsEquilibriumPhysics only supports numbers at this time. The parsing of the metadata is implemented in the classes using this utility.

Troubleshooting

If the reaction network parsing fails, it will error with:

    mooseError("Failed to parse reaction.");
(modules/chemical_reactions/src/utils/ReactionNetworkUtils.C)

In that case, you may examine the expected syntax below. The grammar is used by the parser to understand the input. *, +, ? and other symbols use the same rules as for regular expression parsing.

  parser parser(R"(
    Reactions     <- (_ Reaction _ Newline?)* _
    Reaction      <- TermList _ '->' _ TermList _ Metadata?
    TermList      <- Term (_ Term)*
    Term          <- Coefficient? Species
    Coefficient   <- Float
    Float         <- [+-]? (_)? ([0-9]+)? ('.' [0-9]+)?
    Species       <- BaseSpecies State? Charge?
    BaseSpecies   <- [a-zA-Z][a-zA-Z0-9_]*
    State         <- '(' [a-z]{1,3} ')'
    Charge        <- ('^'? [0-9]* [+-])
    Metadata      <- '[' _ Pair (_ ',' _ Pair)* _ ']'
    Pair          <- Key _ '=' _ Value
    Key           <- [A-Za-z_][A-Za-z0-9_]*
    Value         <- [A-Za-z0-9_.-]+
    Newline       <- [\r\n]+
    ~_            <- [ \t]*
  )");
(modules/chemical_reactions/src/utils/ReactionNetworkUtils.C)