| Cantera 3.0.0

Loading...
Searching...
No Matches
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
19 class ReactionDataDelegator : public Delegator, public ReactionData
20{
21 public:
22 ReactionDataDelegator();
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
31 using ReactionData::update;
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
68 class ReactionRateDelegator : public Delegator, public ReactionRate
69{
70 public:
71 ReactionRateDelegator();
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
Arrhenius.h
Header for reaction rates that involve Arrhenius-type kinetics.
Delegator.h
ReactionRate.h
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
Cantera::Delegator
Delegate member functions of a C++ class to externally-specified functions.
Definition Delegator.h:104
Cantera::Kinetics
Public interface for kinetics managers.
Definition Kinetics.h:126
Cantera::NotImplementedError
An error indicating that an unimplemented function has been called.
Definition ctexceptions.h:195
Cantera::ReactionDataDelegator
Delegate methods of the ReactionData class to external functions.
Definition ReactionRateDelegator.h:20
Cantera::ReactionDataDelegator::m_wrappedSolution
shared_ptr< ExternalHandle > m_wrappedSolution
An external language's wrapper for the Solution object where this ReactionData object is being used.
Definition ReactionRateDelegator.h:55
Cantera::ReactionDataDelegator::m_wrappedData
shared_ptr< ExternalHandle > m_wrappedData
An external language's wrapper for this ReactionData object.
Definition ReactionRateDelegator.h:58
Cantera::ReactionDataDelegator::getWrapper
shared_ptr< ExternalHandle > getWrapper() const
Get the external language wrapper for this ReactionData object.
Definition ReactionRateDelegator.h:40
Cantera::ReactionDataDelegator::update
bool update(const ThermoPhase &phase, const Kinetics &kin) override
Update data container based on thermodynamic phase state.
Definition ReactionRateDelegator.cpp:23
Cantera::ReactionDataDelegator::update
void update(double T) override
Update data container based on temperature T
Definition ReactionRateDelegator.h:26
Cantera::ReactionDataDelegator::m_rateType
string m_rateType
The reaction rate type.
Definition ReactionRateDelegator.h:51
Cantera::ReactionDataDelegator::m_update
function< double(void *)> m_update
Delegated update method taking the Solution wrapper as its argument.
Definition ReactionRateDelegator.h:61
Cantera::ReactionDataDelegator::setWrapper
void setWrapper(shared_ptr< ExternalHandle > wrapper)
Set the external language wrapper for this ReactionData object.
Definition ReactionRateDelegator.h:45
Cantera::ReactionDataDelegator::setType
void setType(const string &name)
Set the type of the ReactionData class.
Definition ReactionRateDelegator.h:35
Cantera::ReactionRateDelegator
Delegate methods of the ReactionRate class to external functions.
Definition ReactionRateDelegator.h:69
Cantera::ReactionRateDelegator::newMultiRate
unique_ptr< MultiRateBase > newMultiRate() const override
Create a rate evaluator for reactions of a particular derived type.
Definition ReactionRateDelegator.cpp:61
Cantera::ReactionRateDelegator::evalFromStruct
double evalFromStruct(const ReactionDataDelegator &shared_data)
Evaluate reaction rate.
Definition ReactionRateDelegator.h:89
Cantera::ReactionRateDelegator::validate
void validate(const string &equation, const Kinetics &kin) override
Validate the reaction rate expression.
Definition ReactionRateDelegator.cpp:70
Cantera::ReactionRateDelegator::getParameters
void getParameters(AnyMap &node) const override
Get parameters.
Definition ReactionRateDelegator.h:97
Cantera::ReactionRateDelegator::m_rateType
string m_rateType
The name of the reaction rate type.
Definition ReactionRateDelegator.h:105
Cantera::ReactionRateDelegator::m_evalFromStruct
function< double(void *)> m_evalFromStruct
Delegated evalFromStruct method taking a pointer to the corresponding ReactionData wrapper object.
Definition ReactionRateDelegator.h:109
Cantera::ReactionRateDelegator::setType
void setType(const string &type)
Set the reaction type based on the user-provided reaction rate parameterization.
Definition ReactionRateDelegator.h:76
Cantera::ReactionRateDelegator::type
const string type() const override
String identifying reaction rate specialization.
Definition ReactionRateDelegator.h:80
Cantera::ReactionRateDelegator::setParameters
void setParameters(const AnyMap &node, const UnitStack &units) override
Set parameters.
Definition ReactionRateDelegator.h:93
Cantera::ReactionRate
Abstract base class for reaction rate definitions; this base class is used by user-facing APIs to acc...
Definition ReactionRate.h:49
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition ThermoPhase.h:390
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::ReactionData
Data container holding shared data used for ReactionRate calculation.
Definition ReactionData.h:27
Cantera::ReactionData::update
virtual void update(double T)
Update data container based on temperature T
Definition ReactionData.h:36
Cantera::UnitStack
Unit aggregation utility.
Definition Units.h:105