From 9781ae7f2d8e26f7a3c034bd640c6076dae75637 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Thu, 27 Apr 2023 14:19:22 -0700 Subject: [PATCH] ParticleContainer: More Pure SoA Init Functions Depends on upstream. --- src/Particle/ParticleContainer.H | 40 +++++++++++++++----------------- src/Particle/ParticleTile.cpp | 16 ++++++------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/Particle/ParticleContainer.H b/src/Particle/ParticleContainer.H index 02f5c34f..a8a12297 100644 --- a/src/Particle/ParticleContainer.H +++ b/src/Particle/ParticleContainer.H @@ -131,11 +131,17 @@ void make_Iterators (py::module &m, std::string allocstr) template void make_ParticleInitData (py::module &m) { using ParticleType = T_ParticleType; - using ParticleInitData = ParticleInitType; - // depends on https://github.com/AMReX-Codes/amrex/pull/3280 - // using ParticleInitData = ParticleInitType; - std::string const suffix = particle_type_suffix(); + //using ParticleInitData = typename ParticleContainerType::ParticleInitData; + using ParticleInitData = typename std::conditional< + ParticleType::is_soa_particle, + // SoA Particle: init w/o positions and id/cpu, but explicitly listed in define + ParticleInitTypeSoA, + // legacy particle: init w/o positions and id/cpu, only implicitly listed in define + ParticleInitType + >::type; + + std::string const suffix = particle_type_suffix(); auto const particle_init_data_type = std::string("ParticleInitType_") + suffix; auto py_particle_init_data = py::class_(m, particle_init_data_type.c_str()) @@ -221,14 +227,16 @@ void make_ParticleContainer_and_Iterators (py::module &m, std::string allocstr) // const IntVect* Nrep = nullptr); // void InitFromBinaryFile (const std::string& file, int extradata); - // void InitFromBinaryMetaFile - // void InitRandom (Long icount, ULong iseed, - // const ParticleInitData& mass, - // bool serialize = false, RealBox bx = RealBox()); - .def("Increment", &ParticleContainerType::Increment) // TODO pure SoA - //.def("IncrementWithTotal", &ParticleContainerType::IncrementWithTotal, py::arg("mf"), py::arg("level"), py::arg("local")=false) // TODO pure SoA + // TODO for pure SoA + // depends on https://github.com/AMReX-Codes/amrex/pull/3280 + .def("InitRandom", py::overload_cast(&ParticleContainerType::InitRandom)) + //.def("InitRandomPerBox", py::overload_cast(&ParticleContainerType::InitRandomPerBox)) // TODO pure SoA + .def("InitOnePerCell", &ParticleContainerType::InitOnePerCell) // TODO pure SoA + + .def("Increment", &ParticleContainerType::Increment) + .def("IncrementWithTotal", &ParticleContainerType::IncrementWithTotal, py::arg("mf"), py::arg("level"), py::arg("local")=false) .def("Redistribute", &ParticleContainerType::Redistribute, py::arg("lev_min")=0, py::arg("lev_max")=-1, py::arg("nGrow")=0, py::arg("local")=0, py::arg("remove_negative")=true) .def("SortParticlesByCell", &ParticleContainerType::SortParticlesByCell) @@ -361,15 +369,6 @@ void make_ParticleContainer_and_Iterators (py::module &m, std::string allocstr) // } ; - // TODO for pure SoA - // depends on https://github.com/AMReX-Codes/amrex/pull/3280 - if constexpr (!T_ParticleType::is_soa_particle) { - py_pc - .def("InitRandom", py::overload_cast(&ParticleContainerType::InitRandom)) // TODO pure SoA - .def("InitRandomPerBox", py::overload_cast(&ParticleContainerType::InitRandomPerBox)) // TODO pure SoA - .def("InitOnePerCell", &ParticleContainerType::InitOnePerCell); - } - using iterator = amrex::ParIter_impl; make_Iterators< false, iterator, Allocator >(m, allocstr); using const_iterator = amrex::ParConstIter_impl; @@ -383,8 +382,7 @@ void make_ParticleContainer_and_Iterators (py::module &m) { // TODO for pure SoA // depends on https://github.com/AMReX-Codes/amrex/pull/3280 - if constexpr (!T_ParticleType::is_soa_particle) - make_ParticleInitData(m); + make_ParticleInitData(m); // see Src/Base/AMReX_GpuContainers.H // !AMREX_USE_GPU: DefaultAllocator = std::allocator diff --git a/src/Particle/ParticleTile.cpp b/src/Particle/ParticleTile.cpp index a2e9d2e5..a76c2d94 100644 --- a/src/Particle/ParticleTile.cpp +++ b/src/Particle/ParticleTile.cpp @@ -37,11 +37,11 @@ void make_ParticleTileData(py::module &m) { std::to_string(NArrayInt); py::class_(m, particle_tile_data_type.c_str()) .def(py::init()) - .def_readonly("m_size", &ParticleTileDataType::m_size) + //.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::template getSuperParticle) - .def("setSuperParticle", &ParticleTileDataType::setSuperParticle) + //.def("getSuperParticle", &ParticleTileDataType::template getSuperParticle) + //.def("setSuperParticle", &ParticleTileDataType::setSuperParticle) // setter & getter .def("__setitem__", [](ParticleTileDataType &pdt, int const v, SuperParticleType const value) { pdt.setSuperParticle(value, v); }) @@ -73,11 +73,11 @@ 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::template size) - .def("numParticles", &ParticleTileType::template numParticles) - .def("numRealParticles", &ParticleTileType::template numRealParticles) - .def("numNeighborParticles", &ParticleTileType::template numNeighborParticles) - .def("numTotalParticles", &ParticleTileType::template 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)