Cantera  3.1.0a1
ReactionRateDelegator.h
Go to the documentation of this file.
1 //! @file ReactionRateDelegator.h
2 
3 // This file is part of Cantera. See License.txt in the top-level directory or
4 // at https://cantera.org/license.txt for license and copyright information.
5 
6 #ifndef CT_REACTION_RATE_DELEGATOR_H
7 #define CT_REACTION_RATE_DELEGATOR_H
8 
9 #include "ReactionRate.h"
10 #include "cantera/base/Delegator.h"
11 #include "Arrhenius.h"
12 
13 namespace Cantera
14 {
15 
16 //! Delegate methods of the ReactionData class to external functions
17 //!
18 //! @since New in %Cantera 3.0
20 {
21 public:
23 
24  bool update(const ThermoPhase& phase, const Kinetics& kin) override;
25 
26  void update(double T) override {
27  throw NotImplementedError("ReactionDataDelegator",
28  "Not implemented for delegated reaction rates");
29  }
30 
32 
33  //! Set the type of the ReactionData class. This should match the corresponding
34  //! ReactionRate class's type
35  void setType(const string& name) {
36  m_rateType = name;
37  }
38 
39  //! Get the external language wrapper for this ReactionData object
40  shared_ptr<ExternalHandle> getWrapper() const {
41  return m_wrappedData;
42  }
43 
44  //! Set the external language wrapper for this ReactionData object
45  void setWrapper(shared_ptr<ExternalHandle> wrapper) {
46  m_wrappedData = wrapper;
47  }
48 
49 protected:
50  //! The reaction rate type
51  string m_rateType;
52 
53  //! An external language's wrapper for the Solution object where this ReactionData
54  //! object is being used
55  shared_ptr<ExternalHandle> m_wrappedSolution;
56 
57  //! An external language's wrapper for this ReactionData object
58  shared_ptr<ExternalHandle> m_wrappedData;
59 
60  //! Delegated `update` method taking the Solution wrapper as its argument
61  function<double(void*)> m_update;
62 };
63 
64 //! Delegate methods of the ReactionRate class to external functions
65 //!
66 //! @since New in %Cantera 3.0
67 //! @ingroup otherRateGroup
69 {
70 public:
72 
73  unique_ptr<MultiRateBase> newMultiRate() const override;
74 
75  //! Set the reaction type based on the user-provided reaction rate parameterization
76  void setType(const string& type) {
77  m_rateType = type;
78  }
79 
80  const string type() const override {
81  return m_rateType;
82  }
83 
84  // Delegatable methods
85 
86  //! Evaluate reaction rate
87  //!
88  //! @param shared_data data shared by all reactions of a given type
89  double evalFromStruct(const ReactionDataDelegator& shared_data) {
90  return m_evalFromStruct(shared_data.getWrapper()->get());
91  }
92 
93  void setParameters(const AnyMap& node, const UnitStack& units) override {
94  m_setParameters(node, units);
95  }
96 
97  void getParameters(AnyMap& node) const override {
98  m_getParameters(node);
99  }
100 
101  void validate(const string& equation, const Kinetics& kin) override;
102 
103 private:
104  //! The name of the reaction rate type
105  string m_rateType;
106 
107  //! Delegated `evalFromStruct` method taking a pointer to the corresponding
108  //! ReactionData wrapper object
109  function<double(void*)> m_evalFromStruct;
110 
111  function<void(const string&, void*)> m_validate;
112  function<void(const AnyMap&, const UnitStack&)> m_setParameters;
113  function<void(AnyMap&)> m_getParameters;
114 };
115 
116 }
117 
118 #endif
Header for reaction rates that involve Arrhenius-type kinetics.
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:427
Delegate member functions of a C++ class to externally-specified functions.
Definition: Delegator.h:104
Public interface for kinetics managers.
Definition: Kinetics.h:125
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:195
Delegate methods of the ReactionData class to external functions.
shared_ptr< ExternalHandle > m_wrappedSolution
An external language's wrapper for the Solution object where this ReactionData object is being used.
shared_ptr< ExternalHandle > m_wrappedData
An external language's wrapper for this ReactionData object.
void update(double T) override
Update data container based on temperature T
virtual void update(double T)
Update data container based on temperature T
Definition: ReactionData.h:36
string m_rateType
The reaction rate type.
function< double(void *)> m_update
Delegated update method taking the Solution wrapper as its argument.
void setWrapper(shared_ptr< ExternalHandle > wrapper)
Set the external language wrapper for this ReactionData object.
void setType(const string &name)
Set the type of the ReactionData class.
shared_ptr< ExternalHandle > getWrapper() const
Get the external language wrapper for this ReactionData object.
Delegate methods of the ReactionRate class to external functions.
unique_ptr< MultiRateBase > newMultiRate() const override
Create a rate evaluator for reactions of a particular derived type.
double evalFromStruct(const ReactionDataDelegator &shared_data)
Evaluate reaction rate.
void validate(const string &equation, const Kinetics &kin) override
Validate the reaction rate expression.
void getParameters(AnyMap &node) const override
Get parameters.
string m_rateType
The name of the reaction rate type.
function< double(void *)> m_evalFromStruct
Delegated evalFromStruct method taking a pointer to the corresponding ReactionData wrapper object.
void setType(const string &type)
Set the reaction type based on the user-provided reaction rate parameterization.
const string type() const override
String identifying reaction rate specialization.
void setParameters(const AnyMap &node, const UnitStack &units) override
Set parameters.
Abstract base class for reaction rate definitions; this base class is used by user-facing APIs to acc...
Definition: ReactionRate.h:49
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:390
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:564
Data container holding shared data used for ReactionRate calculation.
Definition: ReactionData.h:27
virtual void update(double T)
Update data container based on temperature T
Definition: ReactionData.h:36
Unit aggregation utility.
Definition: Units.h:105