File reaction.hxx#

Defines

REACTION_H#
namespace hermes

Typedefs

using OPTYPE = GuardedOptions&&(GuardedOptions&&, Field3D)#
struct ReactionBase : public Component#
#include <reaction.hxx>

Temporary struct to use as a base class for all reactions components.

Ensures reaction strings are paired up correctly with component classes.

Todo:

Remove this when all reaction classes have been refactored to inherit from Reaction.

Subclassed by OpenADAS, OpenADASChargeExchange, SOLKITHydrogenChargeExchange, hermes::Reaction

Public Functions

inline ReactionBase(Permissions &&permissions)#

Public Static Functions

static inline std::size_t incremented_instance_num()#
static inline void reset_instance_counter()#

Protected Attributes

std::size_t inst_num#

Private Static Functions

static inline std::size_t &instance_num_ref()#
struct Reaction : public hermes::ReactionBase#
#include <reaction.hxx>

Struct intended to act as a base for all reactions.

Stores a ReactionParser for manipulating the reaction string and reads data via (a subclass of) ReactionData. Also computes generic population change source terms in transfrom_impl and records reaction ‘channels’ that can be used to override the default strategy for distributing momentum and energy between reaction products.

Subclassed by hermes::CXReaction, hermes::IznRecReaction

Public Functions

Reaction(std::string name, Options &options)#

Construct a new Reaction object.

Extract reaction data options, parse the reaction string, set some permissions and options that apply to all reactions.

Parameters:
  • name

  • options – Options object

virtual void outputVars(Options &state) final#

Copy all diagnostics into the output, setting the appropriate metadata at the same time. Subclasses can’t override - instead, they should make add_diagnostic() calls in their constructor.

Parameters:

state – the output state to update

Protected Functions

void add_diagnostic(const std::string &sp_name, const std::string &diag_name, const std::string &long_diag_name, ReactionDiagnosticType type, const std::string &data_source, DiagnosticTransformerType transformer = negate, const std::string &standard_name = "")#

Add a new reaction diagnostic.

Adds a new entry in the diagnostic (multi)map. The (non-unique) key is < sp_name, type >

Parameters:
  • sp_name – Species with which the diagnostic will be associated

  • diag_name – Label used in the output (and to store it temporarily in the state)

  • diag_desc – Description to use as the ‘long_name’ output attribute

  • diag_type – enum identifying the diagnostic type, also used to determine source name

  • data_source – Name to use as the ‘source’ output attribute

  • standard_name – Optional string to use as the ‘standard_name’ output attribute. Defaults to diag_name.

  • transformer – Optional transformer function to use when modifying the diagnostic (default is ‘negate’, i.e. the diagnostic has the opposite sign to the source)

void init_channel_weights(GuardedOptions &state)#

Set weights for any reactant => product momentum / energy channel that hasn’t already been specified via set_energy_channel_weight and set_momentum_channel_weight.

Note

Can’t be done at construction because the species masses may not be set.

Parameters:

state – Current sim state

void set_energy_channel_weight(const std::string &reactant_name, const std::string &product_name, BoutReal weight)#

Specify what fraction of a reactant’s energy is transferred to a particular product.

Parameters:
  • reactant_name – Name of the reactant species.

  • product_name – Name of the product species.

  • weight – Fraction of the energy to transfer.

void set_momentum_channel_weight(const std::string &reactant_name, const std::string &product_name, BoutReal weight)#

Specify what fraction of a reactant’s momentum is transferred to a particular product.

Parameters:
  • reactant_name – Name of the reactant species.

  • product_name – Name of the product species.

  • weight – Fraction of the momentum to transfer.

inline virtual void transform_additional([[maybe_unused]] GuardedOptions &state, [[maybe_unused]] const RateData &rate_calc_results)#

A hook with which subclasses can perform additional transform tasks, over and above those implemented in Reaction::transform. (Subclasses MAY define)

Parameters:
  • state

  • rate_calc_results

template<OPTYPE operation>
inline void update_source(GuardedOptions &state, const std::string &sp_name, ReactionDiagnosticType type, const Field3D &update_with_field)#

Update both a species source term and the corresponding diagnostics (if any exist and if diagnostics are enabled), determining the key in the state from the type. See alternative form of update_source for further details.

template<OPTYPE operation>
inline void update_source(GuardedOptions &state, const std::string &sp_name, ReactionDiagnosticType type, const std::string &sp_data_key, const Field3D &update_with_field)#

Update both a species source term and the corresponding diagnostics (if any exist and if diagnostics are enabled)

Template Parameters:

operation – function to call on the state to update the source term and the diagnostic. Either Component::add, Component::subtract or Component::set

Parameters:
  • state – the state to update

  • sp_name – the name of the species to update

  • type – the type of source/diagnostic to update

  • sp_data_key – label/key for the field in the state object, i.e. state[“species”][sp_name][sp_data_key]

  • update_with_field – the field used in the update

Protected Attributes

std::unique_ptr<ReactionParser> parser#

Reaction string parser.

std::unique_ptr<ReactionData> rate_data#

Reaction data.

Options &units#

Units and normalisations extracted to member vars for convenience.

BoutReal Tnorm#
BoutReal Nnorm#
BoutReal FreqNorm#
BoutReal rate_multiplier#

Rate multipliers, extracted from input options.

BoutReal radiation_multiplier#
bool diagnose#

Output diagnostics?

std::multimap<std::pair<std::string, ReactionDiagnosticType>, ReactionDiagnostic> diagnostics#

map of (species_name,diagnostic_type)->diagnostic_object

bool do_parallel_averaging = true#

Whether to use parallel averaging when calculating reaction rates (Defaults to true)

Private Functions

void get_reaction_settings(Options &options, std::string &reaction_str, ReactionDataTypes &data_type, std::string &data_id)#

Extract reaction string and data type and data ID for this reaction from the input options, or set suitable defaults for the type and ID if they aren’t specified.

The current input file format (all reactions in a single, comma-separated string) is a bit awkward, but is being preserved for now. ReactionBase sets this->inst_num according to the order of instantiation for each reaction object, then this function extracts the reaction string, data type and data ID using inst_num as an index, setting suitable type and ID defaults if either are omitted.

Parameters:
  • options

  • name

  • reaction_str[out] the extracted reaction string

  • data_type[out] the extracted data type enum or a default if no type specified

  • data_id[out] the extracted data id or a default if no id specified

virtual void transform_impl(GuardedOptions &state) final override#

Add density, momentum and energy sources that apply to all reactions (e.g. those driven by species population changes), then call transform_additional() to allow subclasses to add other terms.

Parameters:

state

void zero_diagnostics(GuardedOptions &state)#

Reset the temporary values of the diagnostics stored in the state.

Parameters:

state

Private Members

std::map<std::string, std::map<std::string, BoutReal>> energy_channels#
std::map<std::string, std::map<std::string, BoutReal>> momentum_channels#
const std::string name#

Label used in the state for reaction configuration.

std::map<std::string, BoutReal> pfactors#

Participation factors of all species - currently set to 1!