Skip to content

Commit

Permalink
Wrap WarpX instance and start multi particle container
Browse files Browse the repository at this point in the history
* Fix test Python_pass_mpi_comm
* Start wrapper for multiparticle container
* Add return policy

Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
  • Loading branch information
RemiLehe and ax3l committed Jun 13, 2023
1 parent 89e5204 commit cabce53
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Python/pywarpx/_libwarpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ def add_real_comp(self, species_name, pid_name, comm=True):
comm : bool
Should the component be communicated
'''

wx = self.libwarpx_so.WarpX.get_instance()
self.libwarpx_so.warpx_addRealComp(
ctypes.c_char_p(species_name.encode('utf-8')),
ctypes.c_char_p(pid_name.encode('utf-8')), comm
Expand Down
1 change: 1 addition & 0 deletions Source/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ foreach(D IN LISTS WarpX_DIMS)
PRIVATE
# pybind11
WarpX.cpp
MultiParticleContainer.cpp
)
endif()
endforeach()
15 changes: 15 additions & 0 deletions Source/Python/MultiParticleContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Copyright 2021-2022 The WarpX Community
*
* Authors: Axel Huebl, Remi Lehe
* License: BSD-3-Clause-LBNL
*/
#include "pyWarpX.H"

#include <Particles/MultiParticleContainer.H>

namespace py = pybind11;

void init_MultiParticleContainer (py::module& m)
{
py::class_<MultiParticleContainer> mpc(m, "MultiParticleContainer");
}
7 changes: 7 additions & 0 deletions Source/Python/pyWarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace py = pybind11;

// forward declarations of exposed classes
void init_WarpX(py::module&);
void init_MultiParticleContainer (py::module& m);

PYBIND11_MODULE(PYWARPX_MODULE_NAME, m) {
// make sure AMReX types are known
Expand All @@ -53,6 +54,7 @@ PYBIND11_MODULE(PYWARPX_MODULE_NAME, m) {
)pbdoc";

// note: order from parent to child classes
init_MultiParticleContainer(m);
init_WarpX(m);

// API runtime version
Expand Down Expand Up @@ -113,6 +115,11 @@ PYBIND11_MODULE(PYWARPX_MODULE_NAME, m) {
m.def("check_gridding_for_RZ_spectral", &CheckGriddingForRZSpectral,
"Ensure that the grid is setup appropriately with using the RZ spectral solver");

// Expose the WarpX instance
m.def("get_instance", &WarpX::GetInstance,
py::return_value_policy::reference,
"Return a reference to the WarpX object.");

// Expose the python callback function installation and removal functions
m.def("add_python_callback", &InstallPythonCallback);
m.def("remove_python_callback", &ClearPythonCallback);
Expand Down

0 comments on commit cabce53

Please sign in to comment.