Skip to content

Commit

Permalink
Basic Python bindings for CustomHierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed May 3, 2023
1 parent fd14bd8 commit 8d48e2d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/binding/python/Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
* BSD-style license, see pybind11 LICENSE file.
*/

#include <pybind11/cast.h>
#include <pybind11/pybind11.h>

#include "openPMD/CustomHierarchy.hpp"
#include "openPMD/Iteration.hpp"
#include "openPMD/Mesh.hpp"
#include "openPMD/ParticlePatches.hpp"
Expand All @@ -52,6 +54,7 @@ using PyPatchRecordContainer = Container<PatchRecord>;
using PyRecordComponentContainer = Container<RecordComponent>;
using PyMeshRecordComponentContainer = Container<MeshRecordComponent>;
using PyPatchRecordComponentContainer = Container<PatchRecordComponent>;
using PyCustomHierarchyContainer = Container<CustomHierarchy>;
PYBIND11_MAKE_OPAQUE(PyIterationContainer)
PYBIND11_MAKE_OPAQUE(PyMeshContainer)
PYBIND11_MAKE_OPAQUE(PyPartContainer)
Expand All @@ -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)
{
Expand All @@ -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<PyCustomHierarchyContainer, Attributable>(
m, "Custom_Hierarchy_Container");
}
14 changes: 14 additions & 0 deletions src/binding/python/CustomHierarchy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


#include "openPMD/CustomHierarchy.hpp"
#include "openPMD/backend/Attributable.hpp"
#include <pybind11/pybind11.h>

namespace py = pybind11;
using namespace openPMD;

void init_CustomHierarchy(py::module &m)
{
py::class_<CustomHierarchy, Container<CustomHierarchy>, Attributable>(
m, "CustomHierarchy");
}
7 changes: 6 additions & 1 deletion src/binding/python/Iteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include "openPMD/CustomHierarchy.hpp"
#include "openPMD/Iteration.hpp"

#include <ios>
Expand All @@ -32,7 +33,11 @@ using namespace openPMD;

void init_Iteration(py::module &m)
{
py::class_<Iteration, Attributable>(m, "Iteration")
py::class_<
Iteration,
CustomHierarchy,
Container<CustomHierarchy>,
Attributable>(m, "Iteration")
.def(py::init<Iteration const &>())

.def(
Expand Down
2 changes: 2 additions & 0 deletions src/binding/python/openPMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8d48e2d

Please sign in to comment.