Cantera  3.1.0b1
Loading...
Searching...
No Matches
ExtensionManager.h
Go to the documentation of this file.
1//! @file ExtensionManager.h
2
3#ifndef CT_EXTENSIONMANAGER_H
4#define CT_EXTENSIONMANAGER_H
5
6// This file is part of Cantera. See License.txt in the top-level directory or
7// at https://cantera.org/license.txt for license and copyright information.
8
10
11namespace Cantera
12{
13
14class ReactionDataDelegator;
15class Solution;
16
17//! A base class for managing the lifetime of an external object, such as a Python
18//! object used by a Delegator
20{
21public:
23 ExternalHandle(const ExternalHandle&) = delete;
24 virtual ~ExternalHandle() = default;
25
26 //! Get the underlying external object
27 virtual void* get() {
28 throw NotImplementedError("ExternalHandle::get");
29 }
30};
31
32//! Base class for managing user-defined %Cantera extensions written in other languages
33//!
34//! @since New in %Cantera 3.0
36{
37public:
38 virtual ~ExtensionManager() = default;
39
40 //! Register ReactionRate defined in a user extension with ReactionRateFactory
41 //! @param extensionName
42 virtual void registerRateBuilders(const string& extensionName) {
43 throw NotImplementedError("ExtensionManager::registerRateBuilders");
44 };
45
46 //! Register a user-defined ReactionRate implementation with ReactionRateFactory
47 //! @param extensionName The name of the library/module containing the user-defined
48 //! rate. For example, the module name for rates implemented in Python.
49 //! @param className The name of the rate in the user's code. For example, the
50 //! Python class name
51 //! @param rateName The name used to construct a rate of this type using
52 //! the newReactionRate() function or from a YAML input file
53 virtual void registerRateBuilder(const string& extensionName,
54 const string& className, const string& rateName)
55 {
56 throw NotImplementedError("ExtensionManager::registerRateBuilder");
57 }
58
59 //! Register a user-defined ReactionData implementation
60 //! @param extensionName The name of the library/module containing the user-defined
61 //! type. For example, the module name for rates implemented in Python.
62 //! @param className The name of the data object in the user's code. For example,
63 //! the Python class name
64 //! @param rateName The name of the corresponding reaction rate type
65 virtual void registerRateDataBuilder(const string& extensionName,
66 const string& className, const string& rateName)
67 {
68 throw NotImplementedError("ExtensionManager::registerRateDataBuilder");
69 }
70
71 //! Create an object in an external language that wraps the specified ReactionData
72 //! object
73 //!
74 //! @param rateName The name of the reaction rate type, which corresponds to the
75 //! name used to register the wrapper generator using registerReactionDataLinker
76 //! @param data The ReactionData object to be wrapped
77 static void wrapReactionData(const string& rateName, ReactionDataDelegator& data);
78
79 //! Create an object in an external language that wraps the specified Solution
80 //! object.
81 //!
82 //! @param wrapperType A name specifying the wrapper type, which corresponds to
83 //! the name used to register the wrapper generator using registerSolutionLinker
84 //! @param soln The Solution object to be wrapped
85 static shared_ptr<ExternalHandle> wrapSolution(const string& wrapperType,
86 shared_ptr<Solution> soln);
87
88 //! Register a function that can be used to create wrappers for ReactionData objects
89 //! in an external language and link them to the corresponding C++ object
90 //!
91 //! @param rateName The name of the reaction rate type
92 //! @param wrapperName The name used for Solution wrappers to be used with this
93 //! object, corresponding to a type registered with registerSolutionLinker().
94 //! @param link Function that creates ReactionData wrapper and links it to the
95 //! provided C++ object
96 static void registerReactionDataLinker(const string& rateName,
97 const string& wrapperName, function<void(ReactionDataDelegator&)> link);
98
99 //! Register a function that can be used to create wrappers for Solution objects in
100 //! an external language and link it to the corresponding C++ objects
101 static void registerSolutionLinker(const string& wrapperName,
102 function<shared_ptr<ExternalHandle>(shared_ptr<Solution>)> link);
103
104 //! Get the Solution wrapper type corresponding to the specified user-defined
105 //! reaction rate type.
106 static string getSolutionWrapperType(const string& userType);
107
108protected:
109 //! Functions for wrapping and linking ReactionData objects
110 static map<string, function<void(ReactionDataDelegator&)>> s_ReactionData_linkers;
111
112 //! Functions for wrapping and linking Solution objects
113 static map<string,
114 function<shared_ptr<ExternalHandle>(shared_ptr<Solution>)>> s_Solution_linkers;
115
116 //! Mapping from user-defined rate types to Solution wrapper types
117 static map<string, string> s_userTypeToWrapperType;
118};
119
120}
121
122#endif
Base class for managing user-defined Cantera extensions written in other languages.
static void registerSolutionLinker(const string &wrapperName, function< shared_ptr< ExternalHandle >(shared_ptr< Solution >)> link)
Register a function that can be used to create wrappers for Solution objects in an external language ...
static void wrapReactionData(const string &rateName, ReactionDataDelegator &data)
Create an object in an external language that wraps the specified ReactionData object.
static map< string, string > s_userTypeToWrapperType
Mapping from user-defined rate types to Solution wrapper types.
virtual void registerRateBuilders(const string &extensionName)
Register ReactionRate defined in a user extension with ReactionRateFactory.
virtual void registerRateDataBuilder(const string &extensionName, const string &className, const string &rateName)
Register a user-defined ReactionData implementation.
virtual void registerRateBuilder(const string &extensionName, const string &className, const string &rateName)
Register a user-defined ReactionRate implementation with ReactionRateFactory.
static string getSolutionWrapperType(const string &userType)
Get the Solution wrapper type corresponding to the specified user-defined reaction rate type.
static void registerReactionDataLinker(const string &rateName, const string &wrapperName, function< void(ReactionDataDelegator &)> link)
Register a function that can be used to create wrappers for ReactionData objects in an external langu...
static map< string, function< shared_ptr< ExternalHandle >(shared_ptr< Solution >)> > s_Solution_linkers
Functions for wrapping and linking Solution objects.
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.
static map< string, function< void(ReactionDataDelegator &)> > s_ReactionData_linkers
Functions for wrapping and linking ReactionData objects.
A base class for managing the lifetime of an external object, such as a Python object used by a Deleg...
virtual void * get()
Get the underlying external object.
An error indicating that an unimplemented function has been called.
Delegate methods of the ReactionData class to external functions.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595