#include <pybind11/embed.h> // everything needed for embeddingnamespace py = pybind11;//#include "cantera/thermo.h"using namespace Cantera;//#include <iostream>
int main(){
// start the interpreter and keep it alive
py::scoped_interpreter guard{}; py::module calc = py::module::import("setup");
py::object result = calc.attr("example")(); auto* gas = result.cast<ThermoPhase*>(); std::cout << gas->report() << std::endl;}
import cantera as ct
def example(): gas1 = ct.ThermoPhase('gri30.xml') # print gas object
gas1() return gas1
Andy,
This is an interesting idea — I haven’t seen any attempts to work with Cantera Python objects in C++ before. If there’s a way to get this working, it’s going to be somewhat more complex than what you’re trying now. The Python (Cython) ThermoPhase
object is not just a C++ ThermoPhase*
, but it does hold a pointer to the C++ object. I don’t know how pybind11 works, but presumably you need to be able to tell how to get to that pointer. It’s stored as the thermo
member of the underlying _SolutionBase
class, as you can see in _cantera.pyx, which contains the declarations for all of the Cython extension types.
Regards,
Ray