Cantera  3.1.0a1
ReactionRateDelegator.cpp
Go to the documentation of this file.
1 //! @file ReactionRateDelegator.cpp
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 
9 
10 namespace Cantera
11 {
12 
13 ReactionDataDelegator::ReactionDataDelegator()
14 {
15  install("update", m_update,
16  [](void*) {
17  throw NotImplementedError("ReactionDataDelegator::update");
18  return 0.0; // necessary to set lambda's function signature
19  }
20  );
21 }
22 
23 bool ReactionDataDelegator::update(const ThermoPhase& phase, const Kinetics& kin)
24 {
25  if (!m_wrappedSolution) {
27  auto soln = kin.root();
28  if (!soln) {
29  throw CanteraError("ReactionDataDelegator::update",
30  "Phase must be instantiated as a Solution to use extensible "
31  "reactions of type '{}'", m_rateType);
32  }
33  if (soln->getExternalHandle(wrapperType)) {
34  m_wrappedSolution = soln->getExternalHandle(wrapperType);
35  } else {
37  }
38  }
39  double needsUpdate = m_update(m_wrappedSolution->get());
40  return needsUpdate != 0.0;
41 }
42 
43 ReactionRateDelegator::ReactionRateDelegator()
44 {
45  install("evalFromStruct", m_evalFromStruct,
46  [](void*) {
47  throw NotImplementedError("ReactionRateDelegator::evalFromStruct");
48  return 0.0; // necessary to set lambda's function signature
49  }
50  );
51  install("setParameters", m_setParameters,
52  [this](const AnyMap& node, const UnitStack& units) {
53  ReactionRate::setParameters(node, units); });
54  install("getParameters", m_getParameters,
55  [this](AnyMap& node) { ReactionRate::getParameters(node); });
56  install("validate", m_validate,
57  [](const string& equation, void* soln) {
58  throw NotImplementedError("ReactionRateDelegator::validate"); });
59 }
60 
61 unique_ptr<MultiRateBase> ReactionRateDelegator::newMultiRate() const
62 {
63  auto multirate = make_unique<MultiRate<ReactionRateDelegator,
65  multirate->sharedData().setType(m_rateType);
66  ExtensionManager::wrapReactionData(m_rateType, multirate->sharedData());
67  return multirate;
68 }
69 
70 void ReactionRateDelegator::validate(const string& equation, const Kinetics& kin)
71 {
72  auto soln = kin.root();
73  if (!soln) {
74  throw CanteraError("ReactionRateDelegator::validate",
75  "Phase must be instantiated as a Solution to use extensible "
76  "reactions of type '{}'", m_rateType);
77  }
79  auto wrappedSoln = soln->getExternalHandle(wrapperType);
80  if (!wrappedSoln) {
81  wrappedSoln = ExtensionManager::wrapSolution(wrapperType, soln);
82  }
83 
84  try {
85  m_validate(equation, wrappedSoln->get());
86  } catch (CanteraError& err) {
87  throw InputFileError("'" + m_rateType + "' validate", m_input,
88  err.getMessage());
89  }
90 }
91 
92 }
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:66
virtual string getMessage() const
Method overridden by derived classes to format the error message.
void install(const string &name, function< void()> &target, const function< void()> &func)
Install a function with the signature void() as being delegatable.
Definition: Delegator.h:301
static void wrapReactionData(const string &rateName, ReactionDataDelegator &data)
Create an object in an external language that wraps the specified ReactionData object.
static string getSolutionWrapperType(const string &userType)
Get the Solution wrapper type corresponding to the specified user-defined reaction rate type.
static shared_ptr< ExternalHandle > wrapSolution(const string &wrapperType, shared_ptr< Solution > soln)
Create an object in an external language that wraps the specified Solution object.
Error thrown for problems processing information contained in an AnyMap or AnyValue.
Definition: AnyMap.h:738
Public interface for kinetics managers.
Definition: Kinetics.h:125
shared_ptr< Solution > root() const
Get the Solution object containing this Kinetics object and associated ThermoPhase objects.
Definition: Kinetics.h:1397
A class template handling ReactionRate specializations.
Definition: MultiRate.h:22
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.
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 setType(const string &name)
Set the type of the ReactionData class.
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.
void validate(const string &equation, const Kinetics &kin) override
Validate the reaction rate expression.
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.
virtual void setParameters(const AnyMap &node, const UnitStack &units)
Set parameters.
Definition: ReactionRate.h:101
AnyMap m_input
Input data used for specific models.
Definition: ReactionRate.h:230
virtual void getParameters(AnyMap &node) const
Get parameters.
Definition: ReactionRate.h:224
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:390
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:564