30 template <
typename T_ParticleType,
int T_NArrayReal=0,
int T_NArrayInt=0>
34 if constexpr (T_ParticleType::is_soa_particle)
36 std::to_string(T_NArrayReal) +
"_" +
37 std::to_string(T_NArrayInt);
39 suffix = std::to_string(T_ParticleType::NReal) +
"_" +
40 std::to_string(T_ParticleType::NInt) +
"_" +
41 std::to_string(T_NArrayReal) +
"_" +
42 std::to_string(T_NArrayInt);
47 template <
bool is_const,
typename T_ParIterBase>
50 using namespace amrex;
52 using iterator_base = T_ParIterBase;
53 using container =
typename iterator_base::ContainerType;
54 using ParticleType =
typename container::ParticleType;
55 constexpr
int NArrayReal = container::NArrayReal;
56 constexpr
int NArrayInt = container::NArrayInt;
58 std::string
const suffix = particle_type_suffix<ParticleType, NArrayReal, NArrayInt>();
59 std::string particle_it_base_name = std::string(
"Par");
60 if (is_const) particle_it_base_name +=
"Const";
61 particle_it_base_name +=
"IterBase_" + suffix +
"_" + allocstr;
62 auto py_it_base = py::class_<iterator_base, MFIter>(m, particle_it_base_name.c_str(), py::dynamic_attr())
63 .def(py::init<container&, int>(),
66 py::keep_alive<1, 2>(),
67 py::arg(
"particle_container"), py::arg(
"level"))
72 .def(
"particle_tile", &iterator_base::GetParticleTile,
73 py::return_value_policy::reference_internal)
74 .def(
"soa", &iterator_base::GetStructOfArrays,
75 py::return_value_policy::reference_internal)
77 .def_property_readonly_static(
"is_soa_particle", [](
const py::object&){
return ParticleType::is_soa_particle;})
78 .def_property_readonly(
"size", &iterator_base::numParticles,
79 "the number of particles on this tile")
80 .def_property_readonly(
"num_particles", &iterator_base::numParticles)
81 .def_property_readonly(
"num_real_particles", &iterator_base::numRealParticles)
82 .def_property_readonly(
"num_neighbor_particles", &iterator_base::numNeighborParticles)
83 .def_property_readonly(
"level", &iterator_base::GetLevel)
84 .def_property_readonly(
"pair_index", &iterator_base::GetPairIndex)
85 .def_property_readonly(
"is_valid", &iterator_base::isValid)
86 .def(
"geom", &iterator_base::Geom, py::arg(
"level"))
89 .def(
"_incr", &iterator_base::operator++)
90 .def(
"finalize", &iterator_base::Finalize)
94 if constexpr (!ParticleType::is_soa_particle)
96 &iterator_base::GetArrayOfStructs,
97 py::return_value_policy::reference_internal);
103 using namespace amrex;
105 using iterator = T_ParIter;
106 using container =
typename iterator::ContainerType;
107 using ParticleType =
typename container::ParticleType;
108 constexpr
int NArrayReal = container::NArrayReal;
109 constexpr
int NArrayInt = container::NArrayInt;
112 make_Base_Iterators< is_const, iterator_base >(m, allocstr);
114 std::string
const suffix = particle_type_suffix<ParticleType, NArrayReal, NArrayInt>();
115 auto particle_it_name = std::string(
"Par");
116 if (is_const) particle_it_name +=
"Const";
117 particle_it_name += std::string(
"Iter_") + suffix +
"_" + allocstr;
118 py::class_<iterator, iterator_base>(m, particle_it_name.c_str())
120 [particle_it_name](iterator
const & pti) {
121 std::string
r =
"<amrex." + particle_it_name +
" (";
122 if( !pti.isValid() ) { r.append(
"in"); }
127 .def(py::init<container&, int>(),
128 py::arg(
"particle_container"), py::arg(
"level"))
131 .def_property_readonly_static(
"is_soa_particle", [](
const py::object&){
return ParticleType::is_soa_particle;})
135 template <
typename T_ParticleType,
int T_NArrayReal=0,
int T_NArrayInt=0>
137 using namespace amrex;
139 using ParticleType = T_ParticleType;
144 std::string
const suffix = particle_type_suffix<T_ParticleType, T_NArrayReal, T_NArrayInt>();
145 auto const particle_init_data_type =
146 std::string(
"ParticleInitType_") + suffix;
147 auto py_particle_init_data = py::class_<ParticleInitData>(m, particle_init_data_type.c_str())
149 .def_property_readonly_static(
"is_soa_particle", [](
const py::object&){
return ParticleType::is_soa_particle;})
150 .def_readwrite(
"real_array_data", &ParticleInitData::real_array_data)
151 .def_readwrite(
"int_array_data", &ParticleInitData::int_array_data)
155 if constexpr (!ParticleType::is_soa_particle)
156 py_particle_init_data
157 .def_readwrite(
"real_struct_data", &ParticleInitData::real_struct_data)
158 .def_readwrite(
"int_struct_data", &ParticleInitData::int_struct_data);
161 template <
typename T_ParticleType,
int T_NArrayReal=0,
int T_NArrayInt=0,
165 using namespace amrex;
167 using ParticleType = T_ParticleType;
169 ParticleType, T_NArrayReal, T_NArrayInt,
172 using ParticleInitData =
typename ParticleContainerType::ParticleInitData;
173 using ParticleTileType =
typename ParticleContainerType::ParticleTileType;
175 std::string
const suffix = particle_type_suffix<T_ParticleType, T_NArrayReal, T_NArrayInt>();
176 auto const particle_container_type = std::string(
"ParticleContainer_") + suffix +
"_" + allocstr;
177 auto py_pc = py::class_<ParticleContainerType>(m, particle_container_type.c_str())
179 .def(py::init<const Geometry&, const DistributionMapping&, const BoxArray&>())
189 .def_property_readonly_static(
"is_soa_particle", [](
const py::object&){
return ParticleType::is_soa_particle;})
190 .def_property_readonly_static(
"num_struct_real", [](
const py::object&){
return ParticleContainerType::NStructReal; })
191 .def_property_readonly_static(
"num_struct_int", [](
const py::object&){
return ParticleContainerType::NStructInt; })
192 .def_property_readonly_static(
"num_array_real", [](
const py::object&){
return ParticleContainerType::NArrayReal; })
193 .def_property_readonly_static(
"num_array_int", [](
const py::object&){
return ParticleContainerType::NArrayInt; })
195 .def_property_readonly(
"num_real_comps", &ParticleContainerType::NumRealComps,
196 "The number of compile-time and runtime Real components in SoA")
197 .def_property_readonly(
"num_int_comps", &ParticleContainerType::NumIntComps,
198 "The number of compile-time and runtime int components in SoA")
199 .def_property_readonly(
"num_runtime_real_comps", &ParticleContainerType::NumRuntimeRealComps,
200 "The number of runtime Real components in SoA")
201 .def_property_readonly(
"num_runtime_int_comps", &ParticleContainerType::NumRuntimeIntComps,
202 "The number of runtime Int components in SoA")
204 .def_property_readonly(
"num_position_components", [](
const py::object&){
return AMREX_SPACEDIM; })
205 .def_property_readonly(
"byte_spread", &ParticleContainerType::ByteSpread)
208 .def(
"add_real_comp", &ParticleContainerType::template AddRealComp<bool>,
209 py::arg(
"communicate")=
true,
"add a new runtime component with type Real")
210 .def(
"add_int_comp", &ParticleContainerType::template AddIntComp<bool>,
211 py::arg(
"communicate")=
true,
"add a new runtime component with type Int")
225 (&ParticleContainerType::Define))
232 (&ParticleContainerType::Define))
239 (&ParticleContainerType::Define))
241 .def(
"num_local_tiles_at_level", &ParticleContainerType::numLocalTilesAtLevel)
243 .def(
"reserve_data", &ParticleContainerType::reserveData)
244 .def(
"resize_data", &ParticleContainerType::resizeData)
256 .def(
"increment", &ParticleContainerType::Increment)
258 .def(
"redistribute", &ParticleContainerType::Redistribute, py::arg(
"lev_min")=0, py::arg(
"lev_max")=-1,
259 py::arg(
"nGrow")=0, py::arg(
"local")=0, py::arg(
"remove_negative")=
true)
260 .def(
"sort_particles_by_cell", &ParticleContainerType::SortParticlesByCell)
261 .def(
"sort_particles_by_bin", &ParticleContainerType::SortParticlesByBin)
262 .def(
"OK", &ParticleContainerType::OK, py::arg(
"lev_min") = 0, py::arg(
"lev_max") = -1, py::arg(
"nGrow")=0)
263 .def(
"print_capacity", &ParticleContainerType::PrintCapacity)
264 .def(
"shrink_t_fit", &ParticleContainerType::ShrinkToFit)
266 .def(
"number_of_particles_at_level", &ParticleContainerType::NumberOfParticlesAtLevel,
267 py::arg(
"level"), py::arg(
"only_valid")=
true, py::arg(
"only_local")=
false)
269 .def(
"number_of_particles_in_grid", &ParticleContainerType::NumberOfParticlesInGrid,
270 py::arg(
"level"), py::arg(
"only_valid")=
true, py::arg(
"only_local")=
false)
275 .def(
"total_number_of_particles", &ParticleContainerType::TotalNumberOfParticles,
276 py::arg(
"only_valid")=
true, py::arg(
"only_local")=
false)
277 .def(
"remove_particles_at_level", &ParticleContainerType::RemoveParticlesAtLevel)
278 .def(
"remove_particles_not_at_finestLevel", &ParticleContainerType::RemoveParticlesNotAtFinestLevel)
290 .def(
"add_particles_at_level", py::overload_cast<ParticleTileType&, int, int>(&ParticleContainerType::AddParticlesAtLevel),
291 py::arg(
"particles"), py::arg(
"level"), py::arg(
"ngrow")=0)
293 .def(
"clear_particles", &ParticleContainerType::clearParticles)
318 .def(
"write_plotfile",
320 [](ParticleContainerType
const & pc, std::string
const & dir, std::string
const & name){
321 return pc.WritePlotFile(dir, name);
323 py::arg(
"dir"), py::arg(
"name")
346 .def(
"get_particles", py::overload_cast<int>(&ParticleContainerType::GetParticles), py::return_value_policy::reference_internal, py::arg(
"level"))
399 .def(
"init_random", py::overload_cast<Long, ULong, const ParticleInitData&, bool, RealBox>(&ParticleContainerType::InitRandom))
404 if constexpr (!T_ParticleType::is_soa_particle) {
406 .def(
"init_random_per_box", py::overload_cast<Long, ULong, const ParticleInitData&>(&ParticleContainerType::InitRandomPerBox))
407 .def(
"init_one_per_cell", &ParticleContainerType::InitOnePerCell)
412 make_Iterators< false, iterator, Allocator >(m, allocstr);
414 make_Iterators< true, const_iterator, Allocator >(m, allocstr);
418 .def_property_readonly_static(
"iterator", [](py::object ){
return py::type::of<iterator>(); },
419 "amrex iterator for particle boxes")
420 .def_property_readonly_static(
"const_iterator", [](py::object ){
return py::type::of<const_iterator>(); },
421 "amrex constant iterator for particle boxes (read-only)")
427 template <
typename T_ParticleType,
int T_NArrayReal=0,
int T_NArrayInt=0>
430 if constexpr (T_ParticleType::is_soa_particle) {
431 make_Particle<T_NArrayReal, T_NArrayInt>(m);
432 make_StructOfArrays<T_NArrayReal, T_NArrayInt, true> (m);
436 T_ParticleType::NReal,
440 T_ParticleType::NReal + T_NArrayReal,
441 T_ParticleType::NInt + T_NArrayInt
444 make_ArrayOfStructs<T_ParticleType::NReal, T_ParticleType::NInt> (m);
445 make_StructOfArrays<T_NArrayReal, T_NArrayInt> (m);
448 make_ParticleTile<T_ParticleType, T_NArrayReal, T_NArrayInt> (m);
450 make_ParticleInitData<T_ParticleType, T_NArrayReal, T_NArrayInt>(m);
467 std::allocator>(m,
"std");
void make_Particle(py::module &m)
Definition: Particle.H:39
void make_Iterators(py::module &m, std::string allocstr)
Definition: ParticleContainer.H:101
void make_Base_Iterators(py::module &m, std::string allocstr)
Definition: ParticleContainer.H:48
void make_ParticleContainer_and_Iterators(py::module &m, std::string allocstr)
Definition: ParticleContainer.H:163
void make_ParticleInitData(py::module &m)
Definition: ParticleContainer.H:136
std::string particle_type_suffix()
Definition: ParticleContainer.H:31