Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParticleContainer: More Pythonic Properties #229

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 changes: 6 additions & 6 deletions tests/test_soa.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
def test_soa_init():
soa = amr.StructOfArrays_2_1_default()
print("--test init --")
print("num real components", soa.NumRealComps())
print("num int components", soa.NumIntComps())
assert soa.NumRealComps() == 2 and soa.NumIntComps() == 1
print("num real components", soa.num_real_comps)
print("num int components", soa.num_int_comps)
assert soa.num_real_comps == 2 and soa.num_int_comps == 1

soa.define(1, 3)
print("--test define --")
print("num real components", soa.NumRealComps())
print("num int components", soa.NumIntComps())
assert soa.NumRealComps() == 3 and soa.NumIntComps() == 4
print("num real components", soa.num_real_comps)
print("num int components", soa.num_int_comps)
assert soa.num_real_comps == 3 and soa.num_int_comps == 4
print("num particles", soa.numParticles())
print("num real particles", soa.numRealParticles())
print("num totalparticles", soa.numTotalParticles())
Expand Down