diff --git a/cmake/dependencies/AMReX.cmake b/cmake/dependencies/AMReX.cmake index a377c0eb..e262083a 100644 --- a/cmake/dependencies/AMReX.cmake +++ b/cmake/dependencies/AMReX.cmake @@ -82,7 +82,7 @@ option(pyAMReX_amrex_internal "Download & build AMReX" ON) set(pyAMReX_amrex_repo "https://github.com/AMReX-Codes/amrex.git" CACHE STRING "Repository URI to pull and build AMReX from if(pyAMReX_amrex_internal)") -set(pyAMReX_amrex_branch "15038d466c05fc607a0dd6ad0c192f8ed025281a" +set(pyAMReX_amrex_branch "6b294a5cd3e5c55b36c7d0afe2993501775eb42f" CACHE STRING "Repository branch for pyAMReX_amrex_repo if(pyAMReX_amrex_internal)") diff --git a/setup.py b/setup.py index 7ff70fef..7d1d14ca 100644 --- a/setup.py +++ b/setup.py @@ -109,7 +109,6 @@ def build_extension(self, ext): #'-DAMReX_PARTICLES_PRECISION=' + AMReX_PARTICLES_PRECISION, ## dependency control (developers & package managers) "-DpyAMReX_amrex_internal=" + AMReX_internal, - "-DpyAMReX_amrex_repo=" + AMReX_repo, "-DpyAMReX_pybind11_internal=" + pybind11_internal, # PEP-440 conformant version from package "-DpyAMReX_VERSION_INFO=" + self.distribution.get_version(), @@ -123,6 +122,8 @@ def build_extension(self, ext): # or same dir as calling executable ] # further dependency control (developers & package managers) + if AMReX_repo: + cmake_args.append("-DpyAMReX_amrex_repo=" + AMReX_repo) if AMReX_branch: cmake_args.append("-DpyAMReX_amrex_branch=" + AMReX_branch) if AMReX_src: @@ -185,7 +186,7 @@ def build_extension(self, ext): # CMake dependency control (developers & package managers) AMReX_src = os.environ.get("AMREX_SRC") AMReX_internal = os.environ.get("AMREX_INTERNAL", "ON") -AMReX_repo = os.environ.get("AMREX_REPO", "https://github.com/AMReX-Codes/amrex.git") +AMReX_repo = os.environ.get("AMREX_REPO") AMReX_branch = os.environ.get("AMREX_BRANCH") pybind11_internal = os.environ.get("PYBIND11_INTERNAL", "ON") diff --git a/src/Particle/ArrayOfStructs.cpp b/src/Particle/ArrayOfStructs.cpp index 8cf576b9..8d31b4fa 100644 --- a/src/Particle/ArrayOfStructs.cpp +++ b/src/Particle/ArrayOfStructs.cpp @@ -21,12 +21,12 @@ namespace * * https://numpy.org/doc/stable/reference/arrays.interface.html */ - template class Allocator=DefaultAllocator> py::dict - array_interface(ArrayOfStructs const & aos) + array_interface(ArrayOfStructs const & aos) { - using ParticleType = Particle; + using ParticleType = T_ParticleType; using RealType = typename ParticleType::RealType; auto d = py::dict(); @@ -43,14 +43,14 @@ namespace #if (AMREX_SPACEDIM >= 3) descr.append(py::make_tuple("z", py::format_descriptor::format())); #endif - if (NReal > 0) { - for(int ii=0; ii < NReal; ii++) { + if constexpr (ParticleType::NReal > 0) { + for(int ii=0; ii < ParticleType::NReal; ii++) { descr.append(py::make_tuple("rdata_"+std::to_string(ii),py::format_descriptor::format())); } } descr.append(py::make_tuple("cpuid", py::format_descriptor::format()) ); - if (NInt > 0) { - for(int ii=0; ii < NInt; ++ii) { + if constexpr (ParticleType::NInt > 0) { + for(int ii=0; ii < ParticleType::NInt; ++ii) { descr.append(py::make_tuple("idata_"+std::to_string(ii),py::format_descriptor::format())); } } @@ -61,16 +61,16 @@ namespace } } -template class Allocator=DefaultAllocator> void make_ArrayOfStructs(py::module &m, std::string allocstr) { - using AOSType = ArrayOfStructs; - using ParticleType = Particle; + using AOSType = ArrayOfStructs; + using ParticleType = T_ParticleType; auto const aos_name = std::string("ArrayOfStructs_") - .append(std::to_string(NReal)).append("_") - .append(std::to_string(NInt)).append("_") + .append(std::to_string(ParticleType::NReal)).append("_") + .append(std::to_string(ParticleType::NInt)).append("_") .append(allocstr); py::class_(m, aos_name.c_str()) .def(py::init()) @@ -124,26 +124,29 @@ void make_ArrayOfStructs(py::module &m, std::string allocstr) template void make_ArrayOfStructs(py::module &m) { + // AMReX legacy AoS position + id/cpu particle ype + using ParticleType = Particle; + // see Src/Base/AMReX_GpuContainers.H // !AMREX_USE_GPU: DefaultAllocator = std::allocator // AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator // work-around for https://github.com/pybind/pybind11/pull/4581 - //make_ArrayOfStructs (m, "std"); - //make_ArrayOfStructs (m, "arena"); + //make_ArrayOfStructs (m, "std"); + //make_ArrayOfStructs (m, "arena"); #ifdef AMREX_USE_GPU - make_ArrayOfStructs (m, "std"); - make_ArrayOfStructs (m, "default"); // amrex::ArenaAllocator + make_ArrayOfStructs (m, "std"); + make_ArrayOfStructs (m, "default"); // amrex::ArenaAllocator #else - make_ArrayOfStructs (m, "default"); // std::allocator - make_ArrayOfStructs (m, "arena"); + make_ArrayOfStructs (m, "default"); // std::allocator + make_ArrayOfStructs (m, "arena"); #endif // end work-around - make_ArrayOfStructs (m, "pinned"); + make_ArrayOfStructs (m, "pinned"); #ifdef AMREX_USE_GPU - make_ArrayOfStructs (m, "device"); - make_ArrayOfStructs (m, "managed"); - make_ArrayOfStructs (m, "async"); + make_ArrayOfStructs (m, "device"); + make_ArrayOfStructs (m, "managed"); + make_ArrayOfStructs (m, "async"); #endif } diff --git a/src/Particle/ParticleTile.cpp b/src/Particle/ParticleTile.cpp index 5596ebb0..a88dd342 100644 --- a/src/Particle/ParticleTile.cpp +++ b/src/Particle/ParticleTile.cpp @@ -14,6 +14,7 @@ #include + namespace py = pybind11; using namespace amrex; @@ -21,9 +22,13 @@ using namespace amrex; template void make_Particle(py::module &m); -template +template void make_ParticleTileData(py::module &m) { - using ParticleTileDataType = ParticleTileData; + using ParticleType = T_ParticleType; + constexpr int NStructReal = ParticleType::NReal; + constexpr int NStructInt = ParticleType::NInt; + + using ParticleTileDataType = ParticleTileData; using SuperParticleType = Particle; auto const particle_tile_data_type = @@ -35,21 +40,26 @@ void make_ParticleTileData(py::module &m) { .def_readonly("m_size", &ParticleTileDataType::m_size) .def_readonly("m_num_runtime_real", &ParticleTileDataType::m_num_runtime_real) .def_readonly("m_num_runtime_int", &ParticleTileDataType::m_num_runtime_int) - .def("getSuperParticle", &ParticleTileDataType::getSuperParticle) + .def("getSuperParticle", &ParticleTileDataType::template getSuperParticle) .def("setSuperParticle", &ParticleTileDataType::setSuperParticle) - // setter & getter + // setter & getter .def("__setitem__", [](ParticleTileDataType &pdt, int const v, SuperParticleType const value) { pdt.setSuperParticle(value, v); }) .def("__getitem__", - [](ParticleTileDataType &pdt, int const v) { return pdt.getSuperParticle(v); }); + [](ParticleTileDataType &pdt, int const v) { return pdt.getSuperParticle(v); }) + + ; } -template class Allocator=DefaultAllocator> void make_ParticleTile(py::module &m, std::string allocstr) { - using ParticleTileType = ParticleTile; - using ParticleType = Particle; + using ParticleType = T_ParticleType; + constexpr int NStructReal = ParticleType::NReal; + constexpr int NStructInt = ParticleType::NInt; + + using ParticleTileType = ParticleTile; using SuperParticleType = Particle; auto const particle_tile_type = std::string("ParticleTile_") + std::to_string(NStructReal) + "_" + @@ -66,17 +76,19 @@ void make_ParticleTile(py::module &m, std::string allocstr) .def("GetStructOfArrays", py::overload_cast<>(&ParticleTileType::GetStructOfArrays), py::return_value_policy::reference_internal) .def("empty", &ParticleTileType::empty) - .def("size", &ParticleTileType::size) - .def("numParticles", &ParticleTileType::numParticles) - .def("numRealParticles", &ParticleTileType::numRealParticles) - .def("numNeighborParticles", &ParticleTileType::numNeighborParticles) - .def("numTotalParticles", &ParticleTileType::numTotalParticles) + .def("size", &ParticleTileType::template size) + .def("numParticles", &ParticleTileType::template numParticles) + .def("numRealParticles", &ParticleTileType::template numRealParticles) + .def("numNeighborParticles", &ParticleTileType::template numNeighborParticles) + .def("numTotalParticles", &ParticleTileType::template numTotalParticles) .def("setNumNeighbors", &ParticleTileType::setNumNeighbors) .def("getNumNeighbors", &ParticleTileType::getNumNeighbors) .def("resize", &ParticleTileType::resize) + .def("push_back", [](ParticleTileType& ptile, const ParticleType &p){ ptile.push_back(p);}) // .def("push_back", py::overload_cast(&ParticleTileType::push_back), "Add one particle to this tile.") // .def("push_back", py::overload_cast(&ParticleTileType::push_back), "Add one particle to this tile.") + .def("push_back", [](ParticleTileType& ptile, const SuperParticleType &p) {ptile.push_back(p);}) .def("push_back_real", [](ParticleTileType& ptile, int comp, ParticleReal v) {ptile.push_back_real(comp, v);}) .def("push_back_real", [](ParticleTileType& ptile, @@ -107,50 +119,54 @@ void make_ParticleTile(py::module &m, std::string allocstr) ; } -template +template void make_ParticleTile(py::module &m) { - make_ParticleTileData(m); + make_ParticleTileData(m); // see Src/Base/AMReX_GpuContainers.H // !AMREX_USE_GPU: DefaultAllocator = std::allocator // AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator // work-around for https://github.com/pybind/pybind11/pull/4581 - //make_ParticleTile(m, "std"); - //make_ParticleTile(m, "arena"); #ifdef AMREX_USE_GPU - make_ParticleTile(m, "std"); - make_ParticleTile(m, "default"); // amrex::ArenaAllocator #else - make_ParticleTile(m, "default"); // std::allocator - make_ParticleTile(m, "arena"); #endif // end work-around - make_ParticleTile(m, "pinned"); #ifdef AMREX_USE_GPU - make_ParticleTile(m, "device"); - make_ParticleTile(m, "managed"); - make_ParticleTile(m, "async"); #endif } void init_ParticleTile(py::module& m) { + // AMReX legacy AoS position + id/cpu particle ype + using ParticleType_0_0 = Particle<0, 0>; + using ParticleType_1_1 = Particle<1, 1>; + // TODO: we might need to move all or most of the defines in here into a // test/example submodule, so they do not collide with downstream projects - make_ParticleTile< 1, 1, 2, 1> (m); - make_ParticleTile< 0, 0, 4, 0> (m); // HiPACE++ 22.07 - make_ParticleTile< 0, 0, 5, 0> (m); // ImpactX 22.07 - make_ParticleTile< 0, 0, 7, 0> (m); - make_ParticleTile< 0, 0, 37, 1> (m); // HiPACE++ 22.07 + make_ParticleTile (m); + make_ParticleTile (m); // HiPACE++ 22.07 + make_ParticleTile (m); // ImpactX 22.07 + make_ParticleTile (m); + make_ParticleTile (m); // HiPACE++ 22.07 }