Skip to content

Commit 20206fa

Browse files
committed
ParticleContainer: More Pure SoA Init Functions
Depends on upstream.
1 parent f9b581a commit 20206fa

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

src/Particle/ParticleContainer.H

+19-21
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,17 @@ void make_Iterators (py::module &m, std::string allocstr)
131131
template <typename T_ParticleType, int T_NArrayReal=0, int T_NArrayInt=0>
132132
void make_ParticleInitData (py::module &m) {
133133
using ParticleType = T_ParticleType;
134-
using ParticleInitData = ParticleInitType<ParticleType::NReal, ParticleType::NInt, T_NArrayReal, T_NArrayInt>;
135-
// depends on https://github.com/AMReX-Codes/amrex/pull/3280
136-
// using ParticleInitData = ParticleInitType<ParticleType, T_NArrayReal, T_NArrayInt>;
137134

138-
std::string const suffix = particle_type_suffix<T_ParticleType, T_NArrayReal, T_NArrayInt>();
135+
//using ParticleInitData = typename ParticleContainerType::ParticleInitData;
136+
using ParticleInitData = typename std::conditional<
137+
ParticleType::is_soa_particle,
138+
// SoA Particle: init w/o positions and id/cpu, but explicitly listed in define
139+
ParticleInitTypeSoA<T_NArrayReal - AMREX_SPACEDIM, T_NArrayInt - 2>,
140+
// legacy particle: init w/o positions and id/cpu, only implicitly listed in define
141+
ParticleInitType<ParticleType::NReal, ParticleType::NInt, T_NArrayReal, T_NArrayInt>
142+
>::type;
143+
144+
std::string const suffix = particle_type_suffix<ParticleType, T_NArrayReal, T_NArrayInt>();
139145
auto const particle_init_data_type =
140146
std::string("ParticleInitType_") + suffix;
141147
auto py_particle_init_data = py::class_<ParticleInitData>(m, particle_init_data_type.c_str())
@@ -221,14 +227,16 @@ void make_ParticleContainer_and_Iterators (py::module &m, std::string allocstr)
221227
// const IntVect* Nrep = nullptr);
222228

223229
// void InitFromBinaryFile (const std::string& file, int extradata);
224-
225230
// void InitFromBinaryMetaFile
226-
// void InitRandom (Long icount, ULong iseed,
227-
// const ParticleInitData& mass,
228-
// bool serialize = false, RealBox bx = RealBox());
229231

230-
.def("Increment", &ParticleContainerType::Increment) // TODO pure SoA
231-
//.def("IncrementWithTotal", &ParticleContainerType::IncrementWithTotal, py::arg("mf"), py::arg("level"), py::arg("local")=false) // TODO pure SoA
232+
// TODO for pure SoA
233+
// depends on https://github.com/AMReX-Codes/amrex/pull/3280
234+
.def("InitRandom", py::overload_cast<Long, ULong, const ParticleInitData&, bool, RealBox>(&ParticleContainerType::InitRandom))
235+
//.def("InitRandomPerBox", py::overload_cast<Long, ULong, const ParticleInitData&>(&ParticleContainerType::InitRandomPerBox)) // TODO pure SoA
236+
.def("InitOnePerCell", &ParticleContainerType::InitOnePerCell) // TODO pure SoA
237+
238+
.def("Increment", &ParticleContainerType::Increment)
239+
.def("IncrementWithTotal", &ParticleContainerType::IncrementWithTotal, py::arg("mf"), py::arg("level"), py::arg("local")=false)
232240
.def("Redistribute", &ParticleContainerType::Redistribute, py::arg("lev_min")=0, py::arg("lev_max")=-1,
233241
py::arg("nGrow")=0, py::arg("local")=0, py::arg("remove_negative")=true)
234242
.def("SortParticlesByCell", &ParticleContainerType::SortParticlesByCell)
@@ -361,15 +369,6 @@ void make_ParticleContainer_and_Iterators (py::module &m, std::string allocstr)
361369
// }
362370
;
363371

364-
// TODO for pure SoA
365-
// depends on https://github.com/AMReX-Codes/amrex/pull/3280
366-
if constexpr (!T_ParticleType::is_soa_particle) {
367-
py_pc
368-
.def("InitRandom", py::overload_cast<Long, ULong, const ParticleInitData&, bool, RealBox>(&ParticleContainerType::InitRandom)) // TODO pure SoA
369-
.def("InitRandomPerBox", py::overload_cast<Long, ULong, const ParticleInitData&>(&ParticleContainerType::InitRandomPerBox)) // TODO pure SoA
370-
.def("InitOnePerCell", &ParticleContainerType::InitOnePerCell);
371-
}
372-
373372
using iterator = amrex::ParIter_impl<ParticleType, T_NArrayReal, T_NArrayInt, Allocator>;
374373
make_Iterators< false, iterator, Allocator >(m, allocstr);
375374
using const_iterator = amrex::ParConstIter_impl<ParticleType, T_NArrayReal, T_NArrayInt, Allocator>;
@@ -383,8 +382,7 @@ void make_ParticleContainer_and_Iterators (py::module &m)
383382
{
384383
// TODO for pure SoA
385384
// depends on https://github.com/AMReX-Codes/amrex/pull/3280
386-
if constexpr (!T_ParticleType::is_soa_particle)
387-
make_ParticleInitData<T_ParticleType, T_NArrayReal, T_NArrayInt>(m);
385+
make_ParticleInitData<T_ParticleType, T_NArrayReal, T_NArrayInt>(m);
388386

389387
// see Src/Base/AMReX_GpuContainers.H
390388
// !AMREX_USE_GPU: DefaultAllocator = std::allocator

src/Particle/ParticleTile.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ void make_ParticleTileData(py::module &m) {
3737
std::to_string(NArrayInt);
3838
py::class_<ParticleTileDataType>(m, particle_tile_data_type.c_str())
3939
.def(py::init())
40-
.def_readonly("m_size", &ParticleTileDataType::m_size)
41-
.def_readonly("m_num_runtime_real", &ParticleTileDataType::m_num_runtime_real)
42-
.def_readonly("m_num_runtime_int", &ParticleTileDataType::m_num_runtime_int)
40+
.def_readonly("size", &ParticleTileDataType::m_size)
41+
.def_readonly("num_runtime_real", &ParticleTileDataType::m_num_runtime_real)
42+
.def_readonly("num_runtime_int", &ParticleTileDataType::m_num_runtime_int)
4343
.def("getSuperParticle", &ParticleTileDataType::template getSuperParticle<ParticleType>)
4444
.def("setSuperParticle", &ParticleTileDataType::template setSuperParticle<ParticleType>)
4545
// setter & getter

0 commit comments

Comments
 (0)