Skip to content

Commit

Permalink
Particle Container: Runtime Arguments (#222)
Browse files Browse the repository at this point in the history
* Particle Runtime Args: New Bindings

* ParticleContainer Tests: w/ Runtime Attributes

* Debugging

* Updated Add Component APIs
  • Loading branch information
ax3l authored Apr 2, 2024
1 parent 971c4ec commit 304698a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Base/PODVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ void make_PODVector(py::module &m, std::string typestr, std::string allocstr)
.def(py::init<>())
.def(py::init<std::size_t>(), py::arg("size"))
.def(py::init<PODVector_type&>(), py::arg("other"))
.def("assign", [](PODVector_type & pv, T const & value){
pv.assign(pv.size(), value);
}, py::arg("value"), "assign the same value to every element")
.def("push_back", py::overload_cast<const T&>(&PODVector_type::push_back))
.def("pop_back", &PODVector_type::pop_back)
.def("clear", &PODVector_type::clear)
Expand Down
6 changes: 6 additions & 0 deletions src/Particle/ParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ void make_ParticleContainer_and_Iterators (py::module &m, std::string allocstr)
.def_property_readonly("num_position_components", [](const py::object&){ return AMREX_SPACEDIM; })
.def_property_readonly("byte_spread", &ParticleContainerType::ByteSpread)

// runtime components
.def("add_real_comp", &ParticleContainerType::template AddRealComp<bool>,
py::arg("communicate")=true, "add a new runtime component with type Real")
.def("add_int_comp", &ParticleContainerType::template AddIntComp<bool>,
py::arg("communicate")=true, "add a new runtime component with type Int")

.def_property_readonly("finest_level", &ParticleContainerBase::finestLevel)

// ParticleContainer ( const ParticleContainer &) = delete;
Expand Down
34 changes: 34 additions & 0 deletions tests/test_particleContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ def particle_container(Npart, std_geometry, distmap, boxarr, std_real_box):

iseed = 1
pc.init_random(Npart, iseed, myt, False, std_real_box)

# add runtime components: 1 real 2 int
pc.add_real_comp(True)
pc.add_int_comp(True)
pc.add_int_comp(True)

# assign some values to runtime components
for lvl in range(pc.finest_level + 1):
for pti in pc.iterator(pc, level=lvl):
soa = pti.soa()
soa.get_real_data(2).assign(1.2345)
soa.get_int_data(1).assign(42)
soa.get_int_data(2).assign(33)

return pc


Expand All @@ -58,6 +72,20 @@ def soa_particle_container(Npart, std_geometry, distmap, boxarr, std_real_box):

iseed = 1
pc.init_random(Npart, iseed, myt, False, std_real_box)

# add runtime components: 1 real 2 int
pc.add_real_comp(True)
pc.add_int_comp(True)
pc.add_int_comp(True)

# assign some values to runtime components
for lvl in range(pc.finest_level + 1):
for pti in pc.iterator(pc, level=lvl):
soa = pti.soa()
soa.get_real_data(8).assign(1.2345)
soa.get_int_data(0).assign(42)
soa.get_int_data(1).assign(33)

return pc


Expand Down Expand Up @@ -315,6 +343,7 @@ def test_per_cell(empty_particle_container, std_geometry, std_particle):
def test_soa_pc_numpy(soa_particle_container, Npart):
"""Used in docs/source/usage/compute.rst"""
pc = soa_particle_container
assert pc.number_of_particles_at_level(0) == Npart

class Config:
have_gpu = False
Expand Down Expand Up @@ -358,6 +387,7 @@ class Config:
def test_pc_numpy(particle_container, Npart):
"""Used in docs/source/usage/compute.rst"""
pc = particle_container
assert pc.number_of_particles_at_level(0) == Npart

class Config:
have_gpu = False
Expand Down Expand Up @@ -414,6 +444,8 @@ def test_pc_df(particle_container, Npart):
print(df.columns)
print(df)

assert len(df.columns) == 14


@pytest.mark.skipif(
importlib.util.find_spec("pandas") is None, reason="pandas is not available"
Expand Down Expand Up @@ -502,3 +534,5 @@ def test_pc_df_mpi(particle_container, Npart):
# only rank 0
print(df.columns)
print(df)

assert len(df.columns) == 14

0 comments on commit 304698a

Please sign in to comment.