MCPcopy Create free account
hub / github.com/Cantera/cantera / registerRateDataBuilder

Method registerRateDataBuilder

src/extensions/PythonExtensionManager.cpp:112–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112void PythonExtensionManager::registerRateDataBuilder(
113 const string& moduleName, const string& className, const string& rateName)
114{
115 // Make sure the helper module has been loaded
116 PythonExtensionManager mgr;
117 // Create a function that links a C++ ReactionDataDelegator
118 // object and a Python ExtensibleRateData object of a particular type, and register
119 // this function for making that link
120 auto builder = [moduleName, className](ReactionDataDelegator& delegator) {
121 PyObject* extData = ct_newPythonExtensibleRateData(&delegator,
122 moduleName, className);
123 if (extData == nullptr) {
124 throw CanteraError("PythonExtensionManager::registerPythonRateDataBuilder",
125 "Problem in ct_newPythonExtensibleRateData:\n{}",
126 getPythonExceptionInfo());
127 }
128 auto handle = make_shared<PythonHandle>(extData, false);
129 Py_XDECREF(extData);
130 delegator.setWrapper(handle);
131 };
132 mgr.registerReactionDataLinker(rateName, "python", builder);
133
134 // Create a function that will link a Python Solution object to the C++ Solution
135 // object that gets passed to the Reaction
136 auto solnLinker = [](shared_ptr<Solution> soln) {
137 PyObject* pySoln = ct_wrapSolution(soln);
138 if (pySoln == nullptr) {
139 throw CanteraError("PythonExtensionManager::registerPythonRateDataBuilder",
140 "Problem in ct_wrapSolution:\n{}",
141 getPythonExceptionInfo());
142 }
143 auto handle = make_shared<PythonHandle>(pySoln, false);
144 Py_XDECREF(pySoln);
145 return handle;
146 };
147 mgr.registerSolutionLinker("python", solnLinker);
148}
149
150};

Callers

nothing calls this directly

Calls 5

CanteraErrorClass · 0.85
getPythonExceptionInfoFunction · 0.85
setWrapperMethod · 0.80

Tested by

no test coverage detected