diff --git a/src/Base/PODVector.cpp b/src/Base/PODVector.cpp index 109745b7..2e11d121 100644 --- a/src/Base/PODVector.cpp +++ b/src/Base/PODVector.cpp @@ -61,6 +61,9 @@ void make_PODVector(py::module &m, std::string typestr, std::string allocstr) .def(py::init<>()) .def(py::init(), py::arg("size")) .def(py::init(), 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(&PODVector_type::push_back)) .def("pop_back", &PODVector_type::pop_back) .def("clear", &PODVector_type::clear) diff --git a/src/Particle/ParticleContainer.H b/src/Particle/ParticleContainer.H index dfd1eafa..5f44c342 100644 --- a/src/Particle/ParticleContainer.H +++ b/src/Particle/ParticleContainer.H @@ -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, + py::arg("communicate")=true, "add a new runtime component with type Real") + .def("add_int_comp", &ParticleContainerType::template AddIntComp, + py::arg("communicate")=true, "add a new runtime component with type Int") + .def_property_readonly("finest_level", &ParticleContainerBase::finestLevel) // ParticleContainer ( const ParticleContainer &) = delete; diff --git a/tests/test_particleContainer.py b/tests/test_particleContainer.py index 44c531a6..b62f6882 100644 --- a/tests/test_particleContainer.py +++ b/tests/test_particleContainer.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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" @@ -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