Skip to content

Commit

Permalink
ParticleContainer: More Pythonic Properties (#229)
Browse files Browse the repository at this point in the history
Rename a couple of properties to be more pythonic.
  • Loading branch information
ax3l authored Dec 6, 2023
1 parent 420cb42 commit 6f2da44
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions src/Particle/ParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ void make_ParticleContainer_and_Iterators (py::module &m, std::string allocstr)
.def_property_readonly_static("NArrayReal", [](const py::object&){return ParticleContainerType::NArrayReal; })
.def_property_readonly_static("NArrayInt", [](const py::object&){return ParticleContainerType::NArrayInt; })

.def_property_readonly("NumRealComps", &ParticleContainerType::NumRealComps,
.def_property_readonly("num_real_comps", &ParticleContainerType::NumRealComps,
"The number of compile-time and runtime Real components in SoA")
.def_property_readonly("NumIntComps", &ParticleContainerType::NumIntComps,
.def_property_readonly("num_int_comps", &ParticleContainerType::NumIntComps,
"The number of compile-time and runtime int components in SoA")
.def_property_readonly("NumRuntimeRealComps", &ParticleContainerType::NumRuntimeRealComps,
.def_property_readonly("num_runtime_real_comps", &ParticleContainerType::NumRuntimeRealComps,
"The number of runtime Real components in SoA")
.def_property_readonly("NumRuntimeIntComps", &ParticleContainerType::NumRuntimeIntComps,
.def_property_readonly("num_runtime_int_comps", &ParticleContainerType::NumRuntimeIntComps,
"The number of runtime Int components in SoA")

.def_property_readonly("finest_level", &ParticleContainerBase::finestLevel)
Expand Down Expand Up @@ -231,8 +231,8 @@ void make_ParticleContainer_and_Iterators (py::module &m, std::string allocstr)

.def("numLocalTilesAtLevel", &ParticleContainerType::numLocalTilesAtLevel)

.def("reserveData", &ParticleContainerType::reserveData)
.def("resizeData", &ParticleContainerType::resizeData)
.def("reserve_data", &ParticleContainerType::reserveData)
.def("resize_data", &ParticleContainerType::resizeData)

// void InitFromAsciiFile (const std::string& file, int extradata,
// const IntVect* Nrep = nullptr);
Expand Down
4 changes: 2 additions & 2 deletions src/Particle/StructOfArrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ void make_StructOfArrays(py::module &m, std::string allocstr)
py::class_<SOAType>(m, soa_name.c_str())
.def(py::init())
.def("define", &SOAType::define)
.def("NumRealComps", &SOAType::NumRealComps,
.def_property_readonly("num_real_comps", &SOAType::NumRealComps,
"Get the number of compile-time + runtime Real components")
.def("NumIntComps", &SOAType::NumIntComps,
.def_property_readonly("num_int_comps", &SOAType::NumIntComps,
"Get the number of compile-time + runtime Int components")

// compile-time components
Expand Down
8 changes: 4 additions & 4 deletions src/amrex/StructOfArrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def soa_to_numpy(self, copy=False):
if self.size() == 0:
raise ValueError("SoA is empty.")

for idx_real in range(self.NumRealComps()):
for idx_real in range(self.num_real_comps):
soa_view.real.append(self.GetRealData(idx_real).to_numpy(copy=copy))

for idx_int in range(self.NumIntComps()):
for idx_int in range(self.num_int_comps):
soa_view.int.append(self.GetIntData(idx_int).to_numpy(copy=copy))

return soa_view
Expand Down Expand Up @@ -70,10 +70,10 @@ def soa_to_cupy(self, copy=False):
if self.size() == 0:
raise ValueError("SoA is empty.")

for idx_real in range(self.NumRealComps()):
for idx_real in range(self.num_real_comps):
soa_view.real.append(self.GetRealData(idx_real).to_cupy(copy=copy))

for idx_int in range(self.NumIntComps()):
for idx_int in range(self.num_int_comps):
soa_view.int.append(self.GetIntData(idx_int).to_cupy(copy=copy))

return soa_view
Expand Down
4 changes: 2 additions & 2 deletions tests/test_particleContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_pc_init():
# lvl = 0
for lvl in range(pc.finest_level + 1):
print(f"at level {lvl}:")
for pti in amr.ParIter_1_1_2_1_default(pc, level=lvl):
for pti in pc.iterator(pc, level=lvl):
print("...")
assert pti.num_particles == 1
assert pti.num_real_particles == 1
Expand Down Expand Up @@ -158,7 +158,7 @@ def test_pc_init():

# read-only
for lvl in range(pc.finest_level + 1):
for pti in amr.ParConstIter_1_1_2_1_default(pc, level=lvl):
for pti in pc.const_iterator(pc, level=lvl):
assert pti.num_particles == 1
assert pti.num_real_particles == 1
assert pti.num_neighbor_particles == 0
Expand Down
12 chan