NekPy
uses the Boost.Python
library to provide a set of high-quality, hand-written Python
bindings for selected functions and classes in Nektar++.
It is worth noting that Python (CPython, the standard Python implementation written in C,
in particular) includes C API and that everything in Python is strictly speaking a C structure
called PyObject
. Hence, defining a new class, method etc. in Python is in reality creating a
new PyObject
structure.
Boost.Python is essentially a wrapper for Python C API which conveniently exports C++
classes and methods into PyObjects
. At compilation time a dynamic library is created which
is then imported to Python, as shown in Figure 18.1.
A typical snippet could look something like:
NekPy
uses the Boost.NumPy
library, contained in Boost 1.63+, to automatically convert C++
Array<OneD, >
objects to and from the commonly-used numpy.ndarray
object, which makes
the integration more seamless between Python and C++.