From 8d48e2d6d9b37d52b96f023491019663332ba781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Wed, 3 May 2023 13:55:41 +0200 Subject: [PATCH] Basic Python bindings for CustomHierarchy --- CMakeLists.txt | 1 + src/binding/python/Container.cpp | 7 +++++++ src/binding/python/CustomHierarchy.cpp | 14 ++++++++++++++ src/binding/python/Iteration.cpp | 7 ++++++- src/binding/python/openPMD.cpp | 2 ++ 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/binding/python/CustomHierarchy.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index be018893ac..226af48027 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -602,6 +602,7 @@ if(openPMD_HAVE_PYTHON) src/binding/python/BaseRecordComponent.cpp src/binding/python/ChunkInfo.cpp src/binding/python/Container.cpp + src/binding/python/CustomHierarchy.cpp src/binding/python/Dataset.cpp src/binding/python/Datatype.cpp src/binding/python/Error.cpp diff --git a/src/binding/python/Container.cpp b/src/binding/python/Container.cpp index fbdb96815f..cef9b495c5 100644 --- a/src/binding/python/Container.cpp +++ b/src/binding/python/Container.cpp @@ -24,8 +24,10 @@ * BSD-style license, see pybind11 LICENSE file. */ +#include #include +#include "openPMD/CustomHierarchy.hpp" #include "openPMD/Iteration.hpp" #include "openPMD/Mesh.hpp" #include "openPMD/ParticlePatches.hpp" @@ -52,6 +54,7 @@ using PyPatchRecordContainer = Container; using PyRecordComponentContainer = Container; using PyMeshRecordComponentContainer = Container; using PyPatchRecordComponentContainer = Container; +using PyCustomHierarchyContainer = Container; PYBIND11_MAKE_OPAQUE(PyIterationContainer) PYBIND11_MAKE_OPAQUE(PyMeshContainer) PYBIND11_MAKE_OPAQUE(PyPartContainer) @@ -61,6 +64,7 @@ PYBIND11_MAKE_OPAQUE(PyPatchRecordContainer) PYBIND11_MAKE_OPAQUE(PyRecordComponentContainer) PYBIND11_MAKE_OPAQUE(PyMeshRecordComponentContainer) PYBIND11_MAKE_OPAQUE(PyPatchRecordComponentContainer) +PYBIND11_MAKE_OPAQUE(PyCustomHierarchyContainer) void init_Container(py::module &m) { @@ -85,4 +89,7 @@ void init_Container(py::module &m) ::detail::create_and_bind_container< PyPatchRecordComponentContainer, Attributable>(m, "Patch_Record_Component_Container"); + ::detail:: + create_and_bind_container( + m, "Custom_Hierarchy_Container"); } diff --git a/src/binding/python/CustomHierarchy.cpp b/src/binding/python/CustomHierarchy.cpp new file mode 100644 index 0000000000..aa856bea94 --- /dev/null +++ b/src/binding/python/CustomHierarchy.cpp @@ -0,0 +1,14 @@ + + +#include "openPMD/CustomHierarchy.hpp" +#include "openPMD/backend/Attributable.hpp" +#include + +namespace py = pybind11; +using namespace openPMD; + +void init_CustomHierarchy(py::module &m) +{ + py::class_, Attributable>( + m, "CustomHierarchy"); +} diff --git a/src/binding/python/Iteration.cpp b/src/binding/python/Iteration.cpp index 59a9322039..4db2729525 100644 --- a/src/binding/python/Iteration.cpp +++ b/src/binding/python/Iteration.cpp @@ -21,6 +21,7 @@ #include #include +#include "openPMD/CustomHierarchy.hpp" #include "openPMD/Iteration.hpp" #include @@ -32,7 +33,11 @@ using namespace openPMD; void init_Iteration(py::module &m) { - py::class_(m, "Iteration") + py::class_< + Iteration, + CustomHierarchy, + Container, + Attributable>(m, "Iteration") .def(py::init()) .def( diff --git a/src/binding/python/openPMD.cpp b/src/binding/python/openPMD.cpp index e784d26f3a..e71a55ccee 100644 --- a/src/binding/python/openPMD.cpp +++ b/src/binding/python/openPMD.cpp @@ -41,6 +41,7 @@ void init_Dataset(py::module &); void init_Datatype(py::module &); void init_Error(py::module &); void init_Helper(py::module &); +void init_CustomHierarchy(py::module &); void init_Iteration(py::module &); void init_IterationEncoding(py::module &); void init_Mesh(py::module &); @@ -94,6 +95,7 @@ PYBIND11_MODULE(openpmd_api_cxx, m) init_Dataset(m); init_Datatype(m); init_Helper(m); + init_CustomHierarchy(m); init_Iteration(m); init_IterationEncoding(m); init_BaseRecordComponent(m);