Skip to content

Commit 5487d0d

Browse files
authored
ParticleContainer: WarpX 1D and 2D (#237)
More specializations.
1 parent eb24d03 commit 5487d0d

File tree

5 files changed

+57
-12
lines changed

5 files changed

+57
-12
lines changed

src/Base/PODVector.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,5 @@ void make_PODVector(py::module &m, std::string typestr)
137137
void init_PODVector(py::module& m) {
138138
make_PODVector<ParticleReal> (m, "real");
139139
make_PODVector<int> (m, "int");
140+
make_PODVector<uint64_t> (m, "uint64");
140141
}

src/Particle/Particle.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ void init_Particle(py::module& m) {
327327
make_Particle< 3, 2 > (m);
328328
make_Particle< 4, 0 > (m); // HiPACE++ 22.07
329329
make_Particle< 5, 0 > (m); // ImpactX 22.07
330+
make_Particle< 6, 0 > (m); // WarpX 24.01+
330331
//make_Particle< 7, 0 > (m); // WarpX 24.01+
331332
make_Particle< 8, 0 > (m); // ImpactX 24.01+
332333
make_Particle< 37, 1> (m); // HiPACE++ 22.07

src/Particle/ParticleContainer_WarpX.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ void init_ParticleContainer_WarpX(py::module& m) {
1616
make_ParticleContainer_and_Iterators<Particle<0, 0>, 4, 0>(m); // WarpX 22.07 - 23.12 1D-3D
1717
//make_ParticleContainer_and_Iterators<Particle<0, 0>, 5, 0> (m); // WarpX 22.07 - 23.12 RZ
1818

19-
make_ParticleContainer_and_Iterators<SoAParticle<7, 0>, 7, 0>(m); // WarpX 24.01+ 1D-3D
19+
#if AMREX_SPACEDIM == 1
20+
make_ParticleContainer_and_Iterators<SoAParticle<5, 0>, 5, 0>(m); // WarpX 24.01+ 1D
21+
#elif AMREX_SPACEDIM == 2
22+
make_ParticleContainer_and_Iterators<SoAParticle<6, 0>, 6, 0>(m); // WarpX 24.01+ 2D
23+
#elif AMREX_SPACEDIM == 3
24+
make_ParticleContainer_and_Iterators<SoAParticle<7, 0>, 7, 0>(m); // WarpX 24.01+ 3D
25+
#endif
2026
}

src/Particle/ParticleTile.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ void make_ParticleTileData(py::module &m)
3030
using ParticleTileDataType = ParticleTileData<T_ParticleType, NArrayReal, NArrayInt>;
3131
using SuperParticleType = Particle<NStructReal + NArrayReal, NStructInt + NArrayInt>;
3232

33-
auto const particle_tile_data_type =
34-
std::string("ParticleTileData_") + std::to_string(NStructReal) + "_" +
35-
std::to_string(NStructInt) + "_" + std::to_string(NArrayReal) + "_" +
33+
auto particle_tile_data_type = std::string("ParticleTileData_");
34+
if (T_ParticleType::is_soa_particle)
35+
particle_tile_data_type += "pureSoA_";
36+
particle_tile_data_type +=
37+
std::to_string(NStructReal) + "_" +
38+
std::to_string(NStructInt) + "_" +
39+
std::to_string(NArrayReal) + "_" +
3640
std::to_string(NArrayInt);
41+
3742
py::class_<ParticleTileDataType>(m, particle_tile_data_type.c_str())
3843
.def(py::init())
3944
.def_readonly("m_size", &ParticleTileDataType::m_size)
@@ -63,9 +68,14 @@ void make_ParticleTile(py::module &m, std::string allocstr)
6368
using ParticleTileType = ParticleTile<T_ParticleType, NArrayReal, NArrayInt, Allocator>;
6469
using SuperParticleType = Particle<NStructReal + NArrayReal, NStructInt + NArrayInt>;
6570

66-
auto const particle_tile_type = std::string("ParticleTile_") + std::to_string(NStructReal) + "_" +
67-
std::to_string(NStructInt) + "_" + std::to_string(NArrayReal) + "_" +
68-
std::to_string(NArrayInt) + "_" + allocstr;
71+
auto particle_tile_type = std::string("ParticleTile_");
72+
if (T_ParticleType::is_soa_particle)
73+
particle_tile_type += "pureSoA_";
74+
particle_tile_type += std::to_string(NStructReal) + "_" +
75+
std::to_string(NStructInt) + "_" +
76+
std::to_string(NArrayReal) + "_" +
77+
std::to_string(NArrayInt) + "_" + allocstr;
78+
6979
auto py_particle_tile = py::class_<ParticleTileType>(m, particle_tile_type.c_str())
7080
.def(py::init())
7181
.def_readonly_static("NAR", &ParticleTileType::NAR)
@@ -184,15 +194,27 @@ void init_ParticleTile(py::module& m) {
184194
// AMReX legacy AoS position + id/cpu particle ype
185195
using ParticleType_0_0 = Particle<0, 0>;
186196
using ParticleType_1_1 = Particle<1, 1>;
197+
#if AMREX_SPACEDIM == 1
198+
using SoAParticleType_5_0 = SoAParticle<5, 0>;
199+
#elif AMREX_SPACEDIM == 2
200+
using SoAParticleType_6_0 = SoAParticle<6, 0>;
201+
#elif AMREX_SPACEDIM == 3
187202
using SoAParticleType_7_0 = SoAParticle<7, 0>;
203+
#endif
188204
using SoAParticleType_8_0 = SoAParticle<8, 0>;
189205

190206
// TODO: we might need to move all or most of the defines in here into a
191207
// test/example submodule, so they do not collide with downstream projects
192208
make_ParticleTile<ParticleType_1_1, 2, 1> (m);
193209
make_ParticleTile<ParticleType_0_0, 4, 0> (m); // HiPACE++ 22.07
194210
make_ParticleTile<ParticleType_0_0, 5, 0> (m); // ImpactX 22.07
195-
make_ParticleTile<SoAParticleType_7_0, 7, 0> (m); // ImpactX 24.01+
211+
#if AMREX_SPACEDIM == 1
212+
make_ParticleTile<SoAParticleType_5_0, 5, 0> (m); // WarpX 24.01+ 1D
213+
#elif AMREX_SPACEDIM == 2
214+
make_ParticleTile<SoAParticleType_6_0, 6, 0> (m); // WarpX 24.01+ 2D
215+
#elif AMREX_SPACEDIM == 3
216+
make_ParticleTile<SoAParticleType_7_0, 7, 0> (m); // WarpX 24.01+ 3D
217+
#endif
196218
make_ParticleTile<SoAParticleType_8_0, 8, 0> (m); // ImpactX 24.01+
197219
make_ParticleTile<ParticleType_0_0, 37, 1> (m); // HiPACE++ 22.07
198220
}

src/Particle/StructOfArrays.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ void make_StructOfArrays(py::module &m, std::string allocstr)
2020

2121
using SOAType = StructOfArrays<NReal, NInt, Allocator, use64BitIdCpu>;
2222

23-
auto const soa_name = std::string("StructOfArrays_") + std::to_string(NReal) + "_" +
24-
std::to_string(NInt) + "_" + allocstr;
25-
py::class_<SOAType>(m, soa_name.c_str())
23+
auto soa_name = std::string("StructOfArrays_") + std::to_string(NReal) + "_" +
24+
std::to_string(NInt);
25+
if (use64BitIdCpu)
26+
soa_name += "_idcpu";
27+
soa_name += "_" + allocstr;
28+
29+
py::class_<SOAType> py_SoA(m, soa_name.c_str());
30+
py_SoA
2631
.def(py::init())
2732
.def("define", &SOAType::define)
2833
.def_property_readonly("num_real_comps", &SOAType::NumRealComps,
@@ -58,6 +63,10 @@ void make_StructOfArrays(py::module &m, std::string allocstr)
5863
.def("getNumNeighbors", &SOAType::getNumNeighbors)
5964
.def("resize", &SOAType::resize)
6065
;
66+
if (use64BitIdCpu)
67+
py_SoA.def("GetIdCPUData", py::overload_cast<>(&SOAType::GetIdCPUData),
68+
py::return_value_policy::reference_internal,
69+
"Get access to a particle IdCPU component Array");
6170
}
6271

6372
template <int NReal, int NInt, bool use64BitIdCpu=false>
@@ -92,7 +101,13 @@ void init_StructOfArrays(py::module& m) {
92101
make_StructOfArrays< 2, 1>(m);
93102
make_StructOfArrays< 4, 0>(m); // HiPACE++ 22.08 - 23.12
94103
make_StructOfArrays< 5, 0>(m); // ImpactX 22.07 - 23.12
95-
make_StructOfArrays< 7, 0, true>(m); // WarpX 24.01+
104+
#if AMREX_SPACEDIM == 1
105+
make_StructOfArrays< 5, 0, true>(m); // WarpX 24.01+ 1D
106+
#elif AMREX_SPACEDIM == 2
107+
make_StructOfArrays< 6, 0, true>(m); // WarpX 24.01+ 2D
108+
#elif AMREX_SPACEDIM == 3
109+
make_StructOfArrays< 7, 0, true>(m); // WarpX 24.01+ 3D
110+
#endif
96111
make_StructOfArrays< 8, 0, true>(m); // ImpactX 24.01+
97112
make_StructOfArrays<37, 1>(m); // HiPACE++ 22.09 - 23.12
98113
}

0 commit comments

Comments
 (0)