Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_ParticleContainerI.H
Go to the documentation of this file.
2
3#include <algorithm>
4#include <iterator>
5#include <set>
6#include <stdexcept>
7#include <string>
8#include <type_traits>
9#include <utility>
10#include <vector>
11
12namespace amrex {
13
14template <typename ParticleType, int NArrayReal, int NArrayInt,
15 template<class> class Allocator, class CellAssignor>
16void
18{
19 num_real_comm_comps = 0;
20 int comm_comps_start = 0;
21 if constexpr (!ParticleType::is_soa_particle) {
22 comm_comps_start += AMREX_SPACEDIM + NStructReal;
23 }
24 for (int i = comm_comps_start; i < comm_comps_start + NumRealComps(); ++i) {
25 if (h_redistribute_real_comp[i]) {++num_real_comm_comps;}
26 }
27
28 num_int_comm_comps = 0;
29 comm_comps_start = 2 + NStructInt;
30 for (int i = comm_comps_start; i < comm_comps_start + NumIntComps(); ++i) {
31 if (h_redistribute_int_comp[i]) {++num_int_comm_comps;}
32 }
33
34 if constexpr (ParticleType::is_soa_particle) {
35 particle_size = sizeof(uint64_t); // idcpu
36 } else {
37 particle_size = sizeof(ParticleType);
38 }
39 superparticle_size = particle_size +
40 num_real_comm_comps*sizeof(ParticleReal) + num_int_comm_comps*sizeof(int);
41}
42
43template <typename ParticleType, int NArrayReal, int NArrayInt,
44 template<class> class Allocator, class CellAssignor>
45void
47{
48 levelDirectoriesCreated = false;
49 usePrePost = false;
50 doUnlink = true;
51
52 // by default communicate all components
53 if constexpr (ParticleType::is_soa_particle)
54 {
55 h_redistribute_real_comp.resize(NArrayReal, true);
56 } else {
57 h_redistribute_real_comp.resize(AMREX_SPACEDIM + NStructReal + NArrayReal, true);
58 }
59 h_redistribute_int_comp.resize(2 + NStructInt + NArrayInt, true);
60
61 SetParticleSize();
62
63 // add default names for SoA Real and Int compile-time arguments
64 m_soa_rdata_names.clear();
65 for (int i=0; i<NArrayReal; ++i)
66 {
67 m_soa_rdata_names.push_back(getDefaultCompNameReal<ParticleType>(i));
68 }
69 m_soa_idata_names.clear();
70 for (int i=0; i<NArrayInt; ++i)
71 {
72 m_soa_idata_names.push_back(getDefaultCompNameInt<ParticleType>(i));
73 }
74
75 static bool initialized = false;
76 if ( ! initialized)
77 {
78 static_assert(sizeof(ParticleType)%sizeof(RealType) == 0,
79 "sizeof ParticleType is not a multiple of sizeof RealType");
80
81 ParmParse pp("particles");
82 pp.queryAdd("do_tiling", do_tiling);
83 Vector<int> tilesize(AMREX_SPACEDIM);
84 if (pp.queryarr("tile_size", tilesize, 0, AMREX_SPACEDIM)) {
85 for (int i=0; i<AMREX_SPACEDIM; ++i) { tile_size[i] = tilesize[i]; }
86 }
87
88 static_assert(std::is_standard_layout_v<ParticleType>,
89 "Particle type must be standard layout");
90 // && std::is_trivial<ParticleType>::value,
91 // "Particle type must be standard layout and trivial.");
92
93 pp.query("use_prepost", usePrePost);
94 pp.query("do_unlink", doUnlink);
95 pp.queryAdd("do_mem_efficient_sort", memEfficientSort);
96 pp.queryAdd("use_comms_arena", use_comms_arena);
97
98 initialized = true;
99 }
100}
101
102template<
103 typename ParticleType,
104 int NArrayReal,
105 int NArrayInt,
106 template<class> class Allocator,
107 class CellAssignor
108>
109void
111 std::vector<std::string> const & rdata_name, std::vector<std::string> const & idata_name
112)
113{
114 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(std::ssize(rdata_name) == NArrayReal, "rdata_name must be equal to NArrayReal");
115 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(std::ssize(idata_name) == NArrayInt, "idata_name must be equal to NArrayInt");
116
117 // ensure names for components are unique
118 std::set<std::string> const unique_r_names(rdata_name.begin(), rdata_name.end());
119 std::set<std::string> const unique_i_names(idata_name.begin(), idata_name.end());
120 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(rdata_name.size() == unique_r_names.size(), "SetSoACompileTimeNames: Provided names in rdata_name are not unique!");
121 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(idata_name.size() == unique_i_names.size(), "SetSoACompileTimeNames: Provided names in idata_name are not unique!");
122
123 for (int i=0; i<NArrayReal; ++i)
124 {
125 m_soa_rdata_names.at(i) = rdata_name.at(i);
126 }
127 for (int i=0; i<NArrayInt; ++i)
128 {
129 m_soa_idata_names.at(i) = idata_name.at(i);
130 }
131}
132
133template<
134 typename ParticleType,
135 int NArrayReal,
136 int NArrayInt,
137 template<class> class Allocator,
138 class CellAssignor
139>
140bool
142{
143 return std::ranges::find(m_soa_rdata_names, name) != std::end(m_soa_rdata_names);
144}
145
146template <typename ParticleType, int NArrayReal, int NArrayInt,
147 template<class> class Allocator, class CellAssignor>
148bool
150{
151 return std::ranges::find(m_soa_idata_names, name) != std::end(m_soa_idata_names);
152}
153
154template<
155 typename ParticleType,
156 int NArrayReal,
157 int NArrayInt,
158 template<class> class Allocator,
159 class CellAssignor
160>
161int
163{
164 const auto it = std::ranges::find(m_soa_rdata_names, name);
165
166 if (it == m_soa_rdata_names.end())
167 {
168 throw std::runtime_error("GetRealCompIndex: Component " + name + " does not exist!");
169 }
170 else
171 {
172 return std::distance(m_soa_rdata_names.begin(), it);
173 }
174}
175
176template<
177 typename ParticleType,
178 int NArrayReal,
179 int NArrayInt,
180 template<class> class Allocator,
181 class CellAssignor
182>
183int
185{
186 const auto it = std::ranges::find(m_soa_idata_names, name);
187
188 if (it == m_soa_idata_names.end())
189 {
190 throw std::runtime_error("GetIntCompIndex: Component " + name + " does not exist!");
191 }
192 else
193 {
194 return std::distance(m_soa_idata_names.begin(), it);
195 }
196}
197
198template <typename ParticleType, int NArrayReal, int NArrayInt,
199 template<class> class Allocator, class CellAssignor>
200template <typename P, typename Assignor>
203{
204 const Geometry& geom = Geom(lev);
205 const auto& domain = geom.Domain();
206 const auto& plo = geom.ProbLoArray();
207 const auto& dxi = geom.InvCellSizeArray();
208
209 return Assignor{}(p, plo, dxi, domain);
210}
211
212template <typename ParticleType, int NArrayReal, int NArrayInt,
213 template<class> class Allocator, class CellAssignor>
214template <typename P>
215bool
217::Where (const P& p,
218 ParticleLocData& pld,
219 int lev_min,
220 int lev_max,
221 IntVect nGrow,
222 int local_grid) const
223{
224
225 AMREX_ASSERT(m_gdb != nullptr);
226
227 if (lev_max == -1) {
228 lev_max = finestLevel();
229 }
230
231 AMREX_ASSERT(lev_max <= finestLevel());
232
233 AMREX_ASSERT(nGrow == 0 || (nGrow.allGE(0) && lev_min == lev_max));
234
235 std::vector< std::pair<int, Box> > isects;
236
237 for (int lev = lev_max; lev >= lev_min; lev--) {
238 const IntVect& iv = Index(p, lev);
239 if (lev == pld.m_lev) {
240 // The fact that we are here means this particle does not belong to any finer grids.
241 if (pld.m_grid >= 0) {
242 if (pld.m_grown_gridbox.contains(iv)) {
243 pld.m_cell = iv;
244 if (!pld.m_tilebox.contains(iv)) {
245 pld.m_tile = getTileIndex(iv, pld.m_gridbox, do_tiling, tile_size, pld.m_tilebox);
246 }
247 return true;
248 }
249 }
250 }
251
252 int grid;
253 const BoxArray& ba = ParticleBoxArray(lev);
255
256 if (local_grid < 0) {
257 bool findfirst = (nGrow == 0) ? true : false;
258 ba.intersections(Box(iv, iv), isects, findfirst, nGrow);
259 grid = isects.empty() ? -1 : isects[0].first;
260 if (nGrow != 0 && std::ssize(isects) > 1) {
261 for (auto & isect : isects) {
262 Box bx = ba.getCellCenteredBox(isect.first);
263 for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
264 Box gbx = bx;
266 gr[dir] = nGrow[dir];
267 gbx.grow(gr);
268 if (gbx.contains(iv)) {
269 grid = isect.first;
270 }
271 }
272 }
273 }
274 } else {
275 grid = (*redistribute_mask_ptr)[local_grid](iv, 0);
276 }
277
278 if (grid >= 0) {
279 const Box& bx = ba.getCellCenteredBox(grid);
280 pld.m_lev = lev;
281 pld.m_grid = grid;
282 pld.m_tile = getTileIndex(iv, bx, do_tiling, tile_size, pld.m_tilebox);
283 pld.m_cell = iv;
284 pld.m_gridbox = bx;
285 pld.m_grown_gridbox = amrex::grow(bx, nGrow);
286 return true;
287 }
288 }
289
290 return false;
291}
292
293template <typename ParticleType, int NArrayReal, int NArrayInt,
294 template<class> class Allocator, class CellAssignor>
295template <typename P>
296bool
299 ParticleLocData& pld,
300 int lev_min,
301 int lev_max,
302 int local_grid) const
303{
304
305 AMREX_ASSERT(m_gdb != nullptr);
306
307 if (!Geom(0).isAnyPeriodic()) { return false; }
308
309 if (lev_max == -1) {
310 lev_max = finestLevel();
311 }
312
313 AMREX_ASSERT(lev_max <= finestLevel());
314
315 // Create a copy "dummy" particle to check for periodic outs.
316 Particle<0, 0> p_prime;
317 AMREX_D_TERM(p_prime.pos(0) = p.pos(0);,
318 p_prime.pos(1) = p.pos(1);,
319 p_prime.pos(2) = p.pos(2));
320 if (PeriodicShift(p_prime)) {
321 std::vector< std::pair<int,Box> > isects;
322 for (int lev = lev_max; lev >= lev_min; lev--) {
323
324 int grid;
325 IntVect iv;
326 const BoxArray& ba = ParticleBoxArray(lev);
328
329 if (local_grid < 0) {
330 iv = Index<amrex::Particle<0, 0>, DefaultAssignor>(p_prime, lev);
331 ba.intersections(Box(iv, iv), isects, true, 0);
332 grid = isects.empty() ? -1 : isects[0].first;
333 } else {
334 iv = Index<amrex::Particle<0, 0>, DefaultAssignor>(p_prime, lev);
335 if (ba[local_grid].contains(iv))
336 {
337 grid = local_grid;
338 }
339 else
340 {
341 ba.intersections(Box(iv, iv), isects, true, 0);
342 grid = isects.empty() ? -1 : isects[0].first;
343 if(grid == -1)
344 {
345 grid = (*redistribute_mask_ptr)[local_grid](Index(p, lev), 0);
346 }
347 }
348 }
349
350 if (grid >= 0) {
351 AMREX_D_TERM(p.pos(0) = p_prime.pos(0);,
352 p.pos(1) = p_prime.pos(1);,
353 p.pos(2) = p_prime.pos(2););
354
355 const Box& bx = ba.getCellCenteredBox(grid);
356
357 pld.m_lev = lev;
358 pld.m_grid = grid;
359 pld.m_tile = getTileIndex(iv, bx, do_tiling, tile_size, pld.m_tilebox);
360 pld.m_cell = iv;
361 pld.m_gridbox = bx;
362 pld.m_grown_gridbox = bx;
363 return true;
364 }
365 }
366 }
367
368 return false;
369}
370
371
372template <typename ParticleType, int NArrayReal, int NArrayInt,
373 template<class> class Allocator, class CellAssignor>
374template <typename P>
375bool
378{
379 const auto& geom = Geom(0);
380 const auto plo = geom.ProbLoArray();
381 const auto phi = geom.ProbHiArray();
382 const auto rlo = geom.ProbLoArrayInParticleReal();
383 const auto rhi = geom.ProbHiArrayInParticleReal();
384 const auto is_per = geom.isPeriodicArray();
386 return enforcePeriodic(p, plo, phi, rlo, rhi, is_per);
387}
388
389template <typename ParticleType, int NArrayReal, int NArrayInt,
390 template<class> class Allocator, class CellAssignor>
394 bool /*update*/,
395 bool verbose,
396 ParticleLocData pld) const
397{
398 AMREX_ASSERT(m_gdb != nullptr);
399
400 bool ok = Where(p, pld);
401
402 if (!ok && Geom(0).isAnyPeriodic())
403 {
404 // Attempt to shift the particle back into the domain if it
405 // crossed a periodic boundary.
406 PeriodicShift(p);
407 ok = Where(p, pld);
408 }
409
410 if (!ok) {
411 // invalidate the particle.
412 if (verbose) {
413 amrex::AllPrint()<< "Invalidating out-of-domain particle: " << p << '\n';
414 }
415
416 AMREX_ASSERT(p.id().is_valid());
417
418 p.id().make_invalid();
419 }
420
421 return pld;
422}
423
424template <typename ParticleType, int NArrayReal, int NArrayInt,
425 template<class> class Allocator, class CellAssignor>
426void
432
433template <typename ParticleType, int NArrayReal, int NArrayInt,
434 template<class> class Allocator, class CellAssignor>
435void
437{
439 int nlevs = std::max(0, finestLevel()+1);
440 m_particles.resize(nlevs);
441}
442
443template <typename ParticleType, int NArrayReal, int NArrayInt,
444 template<class> class Allocator, class CellAssignor>
445template <typename P>
446void
448 int lev_min, int lev_max, IntVect nGrow, int local_grid) const
449{
450 bool success;
451 if (Geom(0).outsideRoundoffDomain(AMREX_D_DECL(p.pos(0), p.pos(1), p.pos(2))))
452 {
453 // Note that EnforcePeriodicWhere may shift the particle if it is successful.
454 success = EnforcePeriodicWhere(p, pld, lev_min, lev_max, local_grid);
455 if (!success && lev_min == 0)
456 {
457 // The particle has left the domain; invalidate it.
458 p.id().make_invalid();
459 success = true;
460 }
461 }
462 else
463 {
464 success = Where(p, pld, lev_min, lev_max, IntVect(0), local_grid);
465 }
466
467 if (!success)
468 {
469 success = (nGrow != 0) && Where(p, pld, lev_min, lev_min, nGrow);
470 pld.m_grown_gridbox = pld.m_gridbox; // reset grown box for subsequent calls.
471 }
473 if (!success)
475 amrex::Abort("ParticleContainer::locateParticle(): invalid particle.");
476 }
477}
478
479template <typename ParticleType, int NArrayReal, int NArrayInt,
480 template<class> class Allocator, class CellAssignor>
481Long
483{
484 Long nparticles = 0;
485 for (int lev = 0; lev <= finestLevel(); lev++) {
486 nparticles += NumberOfParticlesAtLevel(lev,only_valid,true);
487 }
488 if (!only_local) {
490 }
491 return nparticles;
492}
493
494template <typename ParticleType, int NArrayReal, int NArrayInt,
495 template<class> class Allocator, class CellAssignor>
498{
499 AMREX_ASSERT(lev >= 0 && lev < std::ssize(m_particles));
500
501 LayoutData<Long> np_per_grid_local(ParticleBoxArray(lev),
502 ParticleDistributionMap(lev));
503
504 for (ParConstIterType pti(*this, lev); pti.isValid(); ++pti)
505 {
506 int gid = pti.index();
507 if (only_valid)
508 {
509 const auto& ptile = ParticlesAt(lev, pti);
510 const int np = ptile.numParticles();
511 auto const ptd = ptile.getConstParticleTileData();
512
513 ReduceOps<ReduceOpSum> reduce_op;
514 ReduceData<int> reduce_data(reduce_op);
515 using ReduceTuple = typename decltype(reduce_data)::Type;
516
517 reduce_op.eval(np, reduce_data,
518 [=] AMREX_GPU_DEVICE (int i) -> ReduceTuple
519 {
520 return (ptd.id(i).is_valid()) ? 1 : 0;
521 });
522
523 int np_valid = amrex::get<0>(reduce_data.value(reduce_op));
524 np_per_grid_local[gid] += np_valid;
525 } else
526 {
527 np_per_grid_local[gid] += pti.numParticles();
528 }
529 }
530
531 Vector<Long> nparticles(np_per_grid_local.size(), 0);
532 if (only_local)
533 {
534 for (ParConstIterType pti(*this, lev); pti.isValid(); ++pti)
535 {
536 nparticles[pti.index()] = np_per_grid_local[pti.index()];
537 }
538 }
539 else
540 {
541 ParallelDescriptor::GatherLayoutDataToVector(np_per_grid_local, nparticles,
543 ParallelDescriptor::Bcast(nparticles.data(), nparticles.size(),
546 }
547
548 return nparticles;
549}
550
551template <typename ParticleType, int NArrayReal, int NArrayInt,
552 template<class> class Allocator, class CellAssignor>
554{
555 Long nparticles = 0;
556
557 if (level < 0 || level >= std::ssize(m_particles)) { return nparticles; }
558
559 if (only_valid) {
560 ReduceOps<ReduceOpSum> reduce_op;
561 ReduceData<unsigned long long> reduce_data(reduce_op);
562 using ReduceTuple = typename decltype(reduce_data)::Type;
563
564 for (const auto& kv : GetParticles(level)) {
565 const auto& ptile = kv.second;
566 auto const ptd = ptile.getConstParticleTileData();
567
568 reduce_op.eval(ptile.numParticles(), reduce_data,
569 [=] AMREX_GPU_DEVICE (int i) -> ReduceTuple
570 {
571 return (ptd.id(i).is_valid()) ? 1 : 0;
572 });
573 }
574
575 nparticles = static_cast<Long>(amrex::get<0>(reduce_data.value(reduce_op)));
576 }
577 else {
578 for (const auto& kv : GetParticles(level)) {
579 const auto& ptile = kv.second;
580 nparticles += ptile.numParticles();
581 }
582 }
583
584 if (!only_local) {
586 }
587
588 return nparticles;
590
591template <typename ParticleType, int NArrayReal, int NArrayInt,
592 template<class> class Allocator, class CellAssignor>
593template <std::integral Int>
594requires (sizeof(Int) >= sizeof(Long))
595void
597{
598 AMREX_ASSERT(lev >= 0 && lev < std::ssize(m_particles));
599
600 AMREX_ASSERT(BoxArray::SameRefs(mem.boxArray(), ParticleBoxArray(lev)) &&
601 mem.DistributionMap() == ParticleDistributionMap(lev));
602
603 [[maybe_unused]] Gpu::NoSyncRegion no_sync{};
604 for (ParConstIterType pti(*this, lev); pti.isValid(); ++pti)
605 {
606 int gid = pti.index();
607 mem[gid] += static_cast<Int>(pti.capacity());
608 }
610
611//
612// This includes both valid and invalid particles since invalid particles still take up space.
613//
614
615template <typename ParticleType, int NArrayReal, int NArrayInt,
616 template<class> class Allocator, class CellAssignor>
617std::array<Long, 3>
620{
621 Long cnt = 0;
622
623 for (unsigned lev = 0; lev < m_particles.size(); lev++) {
624 const auto& pmap = m_particles[lev];
625 for (const auto& kv : pmap) {
626 const auto& ptile = kv.second;
627 cnt += ptile.numParticles();
628 }
629 }
630
631 Long mn = cnt, mx = mn;
632
633 const int IOProc = ParallelContext::IOProcessorNumberSub();
634 const Long sz = sizeof(ParticleType)+NumRealComps()*sizeof(ParticleReal)+NumIntComps()*sizeof(int);
635
636#ifdef AMREX_LAZY
637 Lazy::QueueReduction( [=] () mutable {
638#endif
642
643 amrex::Print() << "ParticleContainer spread across MPI nodes - bytes (num particles): [Min: "
644 << mn*sz
645 << " (" << mn << ")"
646 << ", Max: "
647 << mx*sz
648 << " (" << mx << ")"
649 << ", Total: "
650 << cnt*sz
651 << " (" << cnt << ")]\n";
652#ifdef AMREX_LAZY
653 });
654#endif
655
656 return {mn*sz, mx*sz, cnt*sz};
658
659template <typename ParticleType, int NArrayReal, int NArrayInt,
660 template<class> class Allocator, class CellAssignor>
661std::array<Long, 3>
664{
665 Long cnt = 0;
667 for (unsigned lev = 0; lev < m_particles.size(); lev++) {
668 const auto& pmap = m_particles[lev];
669 for (const auto& kv : pmap) {
670 const auto& ptile = kv.second;
671 cnt += ptile.capacity();
672 }
673 }
674
675 Long mn = cnt, mx = mn;
676
677 const int IOProc = ParallelContext::IOProcessorNumberSub();
678
679#ifdef AMREX_LAZY
680 Lazy::QueueReduction( [=] () mutable {
681#endif
686 amrex::Print() << "ParticleContainer spread across MPI nodes - bytes: [Min: "
687 << mn
688 << ", Max: "
689 << mx
690 << ", Total: "
691 << cnt
692 << "]\n";
693#ifdef AMREX_LAZY
694 });
695#endif
696
697 return {mn, mx, cnt};
698}
699
700template <typename ParticleType, int NArrayReal, int NArrayInt,
701 template<class> class Allocator, class CellAssignor>
702void
704{
705 for (unsigned lev = 0; lev < m_particles.size(); lev++) {
706 auto& pmap = m_particles[lev];
707 for (auto& kv : pmap) {
708 auto& ptile = kv.second;
709 ptile.shrink_to_fit();
710 }
711 }
712}
720template <typename ParticleType, int NArrayReal, int NArrayInt,
721 template<class> class Allocator, class CellAssignor>
722void
725 BL_PROFILE("ParticleContainer::Increment");
726
727 AMREX_ASSERT(OK());
728 if (m_particles.empty()) { return; }
729 AMREX_ASSERT(lev >= 0 && lev < std::ssize(m_particles));
730 AMREX_ASSERT(numParticlesOutOfRange(*this, 0) == 0);
731
732 const auto& geom = Geom(lev);
733 const auto plo = geom.ProbLoArray();
734 const auto dxi = geom.InvCellSizeArray();
735 const auto domain = geom.Domain();
736 amrex::ParticleToMesh(*this, mf, lev,
737 [=] AMREX_GPU_DEVICE (const typename ParticleTileType::ConstParticleTileDataType& ptd, int ip,
738 amrex::Array4<amrex::Real> const& count)
739 {
740 const auto p = ptd[ip];
741 CellAssignor assignor;
742 IntVect iv = assignor(p, plo, dxi, domain);
743 amrex::Gpu::Atomic::AddNoRet(&count(iv), 1.0_rt);
744 }, false);
745}
746
747template <typename ParticleType, int NArrayReal, int NArrayInt,
748 template<class> class Allocator, class CellAssignor>
749Long
751{
752 BL_PROFILE("ParticleContainer::IncrementWithTotal(lev)");
753 Increment(mf, lev);
754 return TotalNumberOfParticles(true, local);
755}
756
757template <typename ParticleType, int NArrayReal, int NArrayInt,
758 template<class> class Allocator, class CellAssignor>
759void
761{
762 BL_PROFILE("ParticleContainer::RemoveParticlesAtLevel()");
763 if (level >= std::ssize(this->m_particles)) { return; }
764
765 if (!this->m_particles[level].empty())
766 {
767 ParticleLevel().swap(this->m_particles[level]);
768 }
769}
770
771template <typename ParticleType, int NArrayReal, int NArrayInt,
772 template<class> class Allocator, class CellAssignor>
773void
775{
776 BL_PROFILE("ParticleContainer::RemoveParticlesNotAtFinestLevel()");
777 AMREX_ASSERT(this->finestLevel()+1 == std::ssize(this->m_particles));
778
779 Long cnt = 0;
780
781 for (unsigned lev = 0; lev < m_particles.size() - 1; ++lev) {
782 auto& pmap = m_particles[lev];
783 if (!pmap.empty()) {
784 for (auto& kv : pmap) {
785 const auto& pbx = kv.second;
786 cnt += pbx.numParticles();
787 }
788 ParticleLevel().swap(pmap);
789 }
790 }
791
792 //
793 // Print how many particles removed on each processor if any were removed.
794 //
795 if (this->m_verbose > 1 && cnt > 0) {
796 amrex::AllPrint() << "Processor " << ParallelContext::MyProcSub() << " removed " << cnt
797 << " particles not in finest level\n";
798 }
799}
800
802{
803
807
809 const GpuArray<Real, AMREX_SPACEDIM> & dxi, const Box& domain)
810 : m_assign_buffer_grid(assign_buffer_grid), m_plo(plo), m_dxi(dxi), m_domain(domain)
811 {}
812
813 template <typename SrcData>
815 int operator() (const SrcData& src, int src_i) const noexcept
816 {
817 auto iv = getParticleCell(src, src_i, m_plo, m_dxi, m_domain);
818 return (m_assign_buffer_grid(iv).first != -1);
819 }
820};
821
823{
824 template <typename DstData, typename SrcData>
826 void operator() (DstData& dst, const SrcData& src,
827 int src_i, int dst_i) const noexcept
828 {
829 copyParticle(dst, src, src_i, dst_i);
830
832 dst.cpu(dst_i) = 0;
833 }
834};
835
836
837template <typename ParticleType, int NArrayReal, int NArrayInt,
838 template<class> class Allocator, class CellAssignor>
839void
840ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
841::CreateVirtualParticles (int level, AoS& virts) const
842{
843 ParticleTileType ptile;
844 CreateVirtualParticles(level, ptile);
845 ptile.GetArrayOfStructs().swap(virts);
846}
847
848template <typename ParticleType, int NArrayReal, int NArrayInt,
849 template<class> class Allocator, class CellAssignor>
850void
853{
854 BL_PROFILE("ParticleContainer::CreateVirtualParticles()");
855 AMREX_ASSERT(level > 0);
856 AMREX_ASSERT(virts.empty());
857
858 if (level >= std::ssize(m_particles)) {
859 return;
860 }
861
862 std::string const& aggregation_type = AggregationType();
863 int aggregation_buffer = AggregationBuffer();
864
865 if (aggregation_type == "None")
866 {
867 auto virts_offset = virts.numParticles();
868 for(ParConstIterType pti(*this, level); pti.isValid(); ++pti)
869 {
870 const auto& src_tile = ParticlesAt(level, pti);
871
872 auto np = src_tile.numParticles();
873 virts.resize(virts_offset+np);
874 transformParticles(virts, src_tile, 0, virts_offset, np, TransformerVirt());
875 virts_offset += np;
876 }
877 }
878 if (aggregation_type == "Cell")
879 {
880 //Components would be based on
881 int nComp = AMREX_SPACEDIM + NStructReal + NArrayReal;
882 // NArrayReal, NStructInt, NArrayInt behavior as before
883 int nGhost = 0;
884 MultiFab mf(ParticleBoxArray(level), ParticleDistributionMap(level), nComp, nGhost);
885
886 nComp = 1 + NStructInt + NArrayInt;
887 iMultiFab imf(ParticleBoxArray(level), ParticleDistributionMap(level), nComp, nGhost);
888
889 const auto& geom = Geom(level);
890 const auto plo = geom.ProbLoArray();
891 const auto dxi = geom.InvCellSizeArray();
892 const auto domain = geom.Domain();
893
894 BoxList bl_buffer;
895 bl_buffer.complementIn(Geom(level).Domain(), ParticleBoxArray(level));
896 BoxArray buffer(std::move(bl_buffer));
897 buffer.grow(aggregation_buffer);
898
900 locator.build(buffer, geom, do_tiling, tile_size);
901 AssignGrid<DenseBinIteratorFactory<Box>> assign_buffer_grid = locator.getGridAssignor();
902
903 amrex::ParticleToMesh(*this, mf, level,
904 [=] AMREX_GPU_DEVICE (const ParticleType& p,
905 amrex::Array4<amrex::Real> const& partData,
908 {
909 auto iv = getParticleCell(p, plo_loc, dxi_loc, domain);
910 if(assign_buffer_grid(iv).first == -1)
911 {
912 //Ordering may make this not unique
913 for (int i = 0; i < NArrayReal; ++i)
914 {
915 amrex::Gpu::Atomic::AddNoRet(&partData(iv,AMREX_SPACEDIM+NStructReal+i), partData(iv,AMREX_SPACEDIM)!=0.0 ? static_cast<Real>(0) : static_cast<Real>(p.rdata(NStructReal+i)));
916 }
917 //Add the rdata(0)-weighted sum of position
918 for (int i = 0; i < AMREX_SPACEDIM; ++i)
919 {
920 amrex::Gpu::Atomic::AddNoRet(&partData(iv,i), static_cast<Real>((p.rdata(0)*p.pos(i))));
921 }
922 //Add the rdata(0)-weighted sum of other rdata fields
923 for (int i = 1; i < NStructReal; ++i)
924 {
925 amrex::Gpu::Atomic::AddNoRet(&partData(iv,AMREX_SPACEDIM+i), static_cast<Real>((p.rdata(0)*p.rdata(i))));
926 }
927 //Add the rdata(0) sum
928 for (int i = 0; i < 1; ++i)
929 {
930 amrex::Gpu::Atomic::AddNoRet(&partData(iv,AMREX_SPACEDIM+i), static_cast<Real>(p.rdata(0)));
931 }
932 }
933
934 }); //skipping extra false argument, doing mf.setVal(0) at beginning
935
936 amrex::ParticleToMesh(*this, imf, level,
937 [=] AMREX_GPU_DEVICE (const ParticleType& p,
938 amrex::Array4<int> const& partData,
941 {
942
943 auto iv = getParticleCell(p, plo_loc, dxi_loc, domain);
944 if(assign_buffer_grid(iv).first == -1)
945 {
946 //if this cell has no particle id info, do a straight copy to store idata
947 if(partData(iv,0)==0)
948 {
949 //Add 1 to indicate at least 1 particle at cell iv
950 amrex::Gpu::Atomic::AddNoRet(&partData(iv,0), 1);
951 for (int i = 0; i < NStructInt; ++i)
952 {
953 amrex::Gpu::Atomic::AddNoRet(&partData(iv,1+i), p.idata(i));
954 }
955 for (int i = 0; i < NArrayInt; ++i)
956 {
957 amrex::Gpu::Atomic::AddNoRet(&partData(iv,1+NStructInt+i), p.idata(NStructInt+i));
958 }
959 }
960 }
961 });
962
963 //There may be a better way to ensure virts is the right length
964 virts.resize(imf.sum(0));
965
966 int last_offset = 0;
967 for (MFIter mfi(mf); mfi.isValid(); ++mfi)
968 {
969 const auto bx = mfi.tilebox();
970 const auto partData = mf.array(mfi);
971 const auto imf_arr = imf.array(mfi);
972
973 Gpu::DeviceVector<int> offsets(bx.numPts());
974 auto *offsets_ptr = offsets.dataPtr();
975 int next_offset = Scan::ExclusiveSum((int) bx.numPts(),(imf_arr.ptr(bx.smallEnd(),0)),(offsets.dataPtr()),Scan::retSum);
976 auto dst = virts.getParticleTileData();
977 ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k)
978 {
979 if(imf_arr(i,j,k,0)!=0)
980 {
981 const auto idx = last_offset + offsets_ptr[
982 imf_arr.get_offset(IntVectND<3>{i,j,k})
983 ];
984
985 dst.cpu(idx) = 0;
987
988 auto& p = dst[idx];
989 //Set rdata(0) first so we can normalize the weighted fields
990 //Note that this does not work for soa PC
991 p.rdata(0) = static_cast<ParticleReal>(partData(i,j,k,AMREX_SPACEDIM));;
992 //Set pos with the normalized weighted field
993 for (int n = 0; n < AMREX_SPACEDIM; ++n)
994 {
995 p.pos(n) = static_cast<ParticleReal>(partData(i,j,k,n) / p.rdata(0));
996 }
997 //Set rdata(n>0) with the normalized weighted field for NStructReal
998 for (int n = 1; n < NStructReal; ++n)
999 {
1000 p.rdata(n) = static_cast<ParticleReal>(partData(i,j,k,AMREX_SPACEDIM+n) / p.rdata(0));
1001 }
1002 //Set rdata(n>0) with the normalized weighted field for NArrayReal
1003 for (int n = 0; n < NArrayReal; ++n)
1004 {
1005 dst.rdata(n)[idx] = static_cast<ParticleReal>(partData(i,j,k,AMREX_SPACEDIM+NStructReal+n));
1006 }
1007 //Set idata with the "first" particles idata field for NStructInt
1008 for (int n = 0; n < NStructInt; ++n)
1009 {
1010 p.idata(n) = imf_arr(i,j,k,1+n);
1011 }
1012 //Set idata with the "first" particles idata field for NArrayInt
1013 for (int n = 0; n < NArrayInt; ++n)
1014 {
1015 dst.idata(n)[idx] = imf_arr(i,j,k,1+NStructInt+n);
1016 }
1017 }
1018
1019 });
1020 last_offset+=next_offset;
1022 }
1023
1024 // last_offset should equal virts.numParticles()
1025 auto virts_offset = last_offset;
1026 for(ParConstIterType pti(*this, level); pti.isValid(); ++pti)
1027 {
1028 const auto& src_tile = ParticlesAt(level, pti);
1029
1030 auto np = src_tile.numParticles();
1031 virts.resize(virts_offset+np);
1032 virts_offset += filterAndTransformParticles(virts, src_tile, FilterVirt(assign_buffer_grid,plo,dxi,domain), TransformerVirt(),0,virts_offset);
1034 }
1035 virts.resize(virts_offset);
1037 }
1038}
1039
1041{
1042
1045
1051 : m_lev_min(level), m_lev_max(level+1), m_nGrow(nGrow), m_gid(gid), m_assign_grid(assign_grid)
1052 {}
1053
1054 template <typename SrcData>
1056 int operator() (const SrcData& src, int src_i) const noexcept
1057 {
1058 const auto tup_min = (m_assign_grid)(src[src_i], m_lev_min, m_lev_max, m_nGrow, DefaultAssignor{});
1059 const auto tup_max = (m_assign_grid)(src[src_i], m_lev_max, m_lev_max, m_nGrow, DefaultAssignor{});
1060 const auto p_boxes = amrex::get<0>(tup_min);
1061 const auto p_boxes_max = amrex::get<0>(tup_max);
1062 const auto p_levs_max = amrex::get<2>(tup_max);
1063 return p_boxes_max >=0 && p_boxes == m_gid && p_levs_max == m_lev_max;
1064 }
1065};
1066
1068{
1069
1070 template <typename DstData, typename SrcData>
1072 void operator() (DstData& dst, const SrcData& src,
1073 int src_i, int dst_i) const noexcept
1074 {
1075 copyParticle(dst, src, src_i, dst_i);
1076
1077 dst.id(dst_i) = LongParticleIds::GhostParticleID;
1078 dst.cpu(dst_i) = 0;
1079 }
1080};
1081
1082template <typename ParticleType, int NArrayReal, int NArrayInt,
1083 template<class> class Allocator, class CellAssignor>
1084void
1085ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1086::CreateGhostParticles (int level, int nGrow, AoS& ghosts) const
1087{
1088 ParticleTileType ptile;
1089 CreateGhostParticles(level, nGrow, ptile);
1090 ptile.GetArrayOfStructs().swap(ghosts);
1091}
1092
1093template <typename ParticleType, int NArrayReal, int NArrayInt,
1094 template<class> class Allocator, class CellAssignor>
1095void
1097::CreateGhostParticles (int level, int nGrow, ParticleTileType& ghosts) const
1098{
1099 BL_PROFILE("ParticleContainer::CreateGhostParticles()");
1100 AMREX_ASSERT(ghosts.empty());
1101 AMREX_ASSERT(level < finestLevel());
1102
1103 if (level >= std::ssize(m_particles)) {
1104 return;
1105 }
1106
1107 if (! m_particle_locator.isValid(GetParGDB(), do_tiling, tile_size)) {
1108 m_particle_locator.build(GetParGDB(), do_tiling, tile_size);
1109 }
1110
1111 m_particle_locator.setGeometry(GetParGDB());
1112 AmrAssignGrid<DenseBinIteratorFactory<Box>> assign_grid = m_particle_locator.getGridAssignor();
1113 auto ghost_offset = ghosts.numParticles();
1114 for(ParConstIterType pti(*this, level); pti.isValid(); ++pti)
1115 {
1116 const auto& src_tile = ParticlesAt(level, pti);
1117 int gid = pti.index();
1118
1119 auto np = src_tile.numParticles();
1120 ghosts.resize(ghost_offset+np);
1121 ghost_offset += filterAndTransformParticles(ghosts, src_tile, AssignGridFilter(assign_grid,gid,level,nGrow), TransformerGhost(),0,ghost_offset);
1122 }
1123 ghosts.resize(ghost_offset);
1125}
1126
1127template <typename ParticleType, int NArrayReal, int NArrayInt,
1128 template<class> class Allocator, class CellAssignor>
1129void
1132{
1133 BL_PROFILE("ParticleContainer::clearParticles()");
1134
1135 for (int lev = 0; lev < std::ssize(m_particles); ++lev)
1136 {
1137 for (auto& kv : m_particles[lev]) { kv.second.resize(0); }
1138 particle_detail::clearEmptyEntries(m_particles[lev]);
1139 }
1140}
1141
1142template <typename ParticleType, int NArrayReal, int NArrayInt,
1143 template<class> class Allocator, class CellAssignor>
1144template <class PCType>
1146void
1148copyParticles (const PCType& other, bool local)
1149{
1150 using PData = typename ParticleTileType::ConstParticleTileDataType;
1151 copyParticles(other, [] AMREX_GPU_HOST_DEVICE (const PData& /*data*/, int /*i*/) { return 1; }, local);
1152}
1153
1154template <typename ParticleType, int NArrayReal, int NArrayInt,
1155 template<class> class Allocator, class CellAssignor>
1156template <class PCType>
1158void
1160addParticles (const PCType& other, bool local)
1161{
1162 using PData = typename ParticleTileType::ConstParticleTileDataType;
1163 addParticles(other, [] AMREX_GPU_HOST_DEVICE (const PData& /*data*/, int /*i*/) { return 1; }, local);
1164}
1165
1166template <typename ParticleType, int NArrayReal, int NArrayInt,
1167 template<class> class Allocator, class CellAssignor>
1168template <class F, class PCType>
1169requires ((IsParticleContainer<PCType>::value) && (!std::is_integral_v<F>))
1170void
1172copyParticles (const PCType& other, F&& f, bool local)
1173{
1174 BL_PROFILE("ParticleContainer::copyParticles");
1175 clearParticles();
1176 addParticles(other, std::forward<F>(f), local);
1177}
1178
1179template <typename ParticleType, int NArrayReal, int NArrayInt,
1180 template<class> class Allocator, class CellAssignor>
1181template <class F, class PCType>
1182requires ((IsParticleContainer<PCType>::value) && (!std::is_integral_v<F>))
1183void
1185addParticles (const PCType& other, F const& f, bool local)
1186{
1187 BL_PROFILE("ParticleContainer::addParticles");
1188
1189 // touch all tiles in serial
1190 for (int lev = 0; lev < other.numLevels(); ++lev)
1191 {
1192 [[maybe_unused]] Gpu::NoSyncRegion no_sync{};
1193 const auto& plevel_other = other.GetParticles(lev);
1194 for(MFIter mfi = other.MakeMFIter(lev); mfi.isValid(); ++mfi)
1195 {
1196 auto index = std::make_pair(mfi.index(), mfi.LocalTileIndex());
1197 if(!plevel_other.contains(index)) { continue; }
1198
1199 DefineAndReturnParticleTile(lev, mfi.index(), mfi.LocalTileIndex());
1200 }
1201 }
1202
1203#ifdef AMREX_USE_OMP
1204#pragma omp parallel if (Gpu::notInLaunchRegion())
1205#endif
1206 for (int lev = 0; lev < other.numLevels(); ++lev)
1207 {
1208 const auto& plevel_other = other.GetParticles(lev);
1209 for(MFIter mfi = other.MakeMFIter(lev); mfi.isValid(); ++mfi)
1210 {
1211 auto index = std::make_pair(mfi.index(), mfi.LocalTileIndex());
1212 if(!plevel_other.contains(index)) { continue; }
1213
1214 // this has already had define() called above
1215 auto& ptile = ParticlesAt(lev, mfi.index(), mfi.LocalTileIndex());
1216 const auto& ptile_other = plevel_other.at(index);
1217 auto np = ptile_other.numParticles();
1218 if (np == 0) { continue; }
1219
1220 auto dst_index = ptile.numParticles();
1221 ptile.resize(dst_index + np);
1222
1223 auto count = amrex::filterParticles(ptile, ptile_other, f,
1224 static_cast<decltype(np)>(0), dst_index, np);
1225
1226 ptile.resize(dst_index + count);
1227 }
1228 }
1229
1230 if (! local) { Redistribute(); }
1231}
1232
1233//
1234// This redistributes valid particles and discards invalid ones.
1235//
1236template <typename ParticleType, int NArrayReal, int NArrayInt,
1237 template<class> class Allocator, class CellAssignor>
1238void
1240::Redistribute (int lev_min, int lev_max, IntVect nGrow,
1241 bool local, IntVect max_cells_moved, bool remove_negative)
1242{
1243 BL_PROFILE_SYNC_START_TIMED("SyncBeforeComms: Redist");
1244
1246 !is_rtsoa_pc || NumRuntimeRealComps() >= AMREX_SPACEDIM,
1247 "ParticleContainer with RTSoA requires at least AMREX_SPACEDIM "
1248 "runtime real components for positions"
1249 );
1250
1251 Redistribute_impl(lev_min, lev_max, nGrow, local, max_cells_moved,
1252 remove_negative);
1255}
1256
1257template <typename ParticleType, int NArrayReal, int NArrayInt,
1258 template<class> class Allocator, class CellAssignor>
1259template <class index_type>
1260void
1262::ReorderParticles (int lev, const MFIter& mfi, const index_type* permutations)
1263{
1264 auto& ptile = ParticlesAt(lev, mfi);
1265 const size_t np = ptile.numParticles();
1266 const size_t np_total = np + ptile.numNeighborParticles();
1267
1268 if (memEfficientSort) {
1269 amrex::ReorderParticles(ptile, permutations);
1270 } else {
1271 ParticleTileType ptile_tmp;
1272 ptile_tmp.define(m_num_runtime_real, m_num_runtime_int,
1273 &m_soa_rdata_names, &m_soa_idata_names, arena());
1274 ptile_tmp.resize(np_total);
1275 // copy re-ordered particles
1276 gatherParticles(ptile_tmp, ptile, np, permutations);
1277 // copy neighbor particles
1278 amrex::copyParticles(ptile_tmp, ptile, np, np, np_total-np);
1279 ptile.swap(ptile_tmp);
1280 }
1281}
1282
1283template <typename ParticleType, int NArrayReal, int NArrayInt,
1284 template<class> class Allocator, class CellAssignor>
1285void
1290
1291template <typename ParticleType, int NArrayReal, int NArrayInt,
1292 template<class> class Allocator, class CellAssignor>
1293void
1296{
1297 BL_PROFILE("ParticleContainer::SortParticlesByBin()");
1298
1299 if (bin_size == IntVect::TheZeroVector()) { return; }
1300
1301 for (int lev = 0; lev < numLevels(); ++lev)
1302 {
1303 const Geometry& geom = Geom(lev);
1304 const auto dxi = geom.InvCellSizeArray();
1305 const auto plo = geom.ProbLoArray();
1306 const auto domain = geom.Domain();
1307
1308 for(MFIter mfi = MakeMFIter(lev); mfi.isValid(); ++mfi)
1309 {
1310 auto& ptile = ParticlesAt(lev, mfi);
1311 const size_t np = ptile.numParticles();
1313 const Box& box = mfi.validbox();
1314
1315 int ntiles = numTilesInBox(box, true, bin_size);
1316
1317 m_bins.build(np, ptile.getParticleTileData(), ntiles,
1318 GetParticleBin{.plo = plo, .dxi = dxi, .domain = domain,
1319 .bin_size = bin_size, .box = box});
1320 ReorderParticles(lev, mfi, m_bins.permutationPtr());
1321 }
1322 }
1323}
1324
1325template <typename ParticleType, int NArrayReal, int NArrayInt,
1326 template<class> class Allocator, class CellAssignor>
1327void
1328ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1329::SortParticlesForDeposition (IntVect idx_type)
1330{
1331 BL_PROFILE("ParticleContainer::SortParticlesForDeposition()");
1332
1333 for (int lev = 0; lev < numLevels(); ++lev)
1334 {
1335 const Geometry& geom = Geom(lev);
1336
1337 for(MFIter mfi = MakeMFIter(lev); mfi.isValid(); ++mfi)
1338 {
1339 const auto& ptile = ParticlesAt(lev, mfi);
1340 const size_t np = ptile.numParticles();
1341
1342 const Box& box = mfi.validbox();
1343
1344 using index_type = typename decltype(m_bins)::index_type;
1346 PermutationForDeposition<index_type>(perm, np, ptile, box, geom, idx_type);
1347 ReorderParticles(lev, mfi, perm.dataPtr());
1348 }
1349 }
1350}
1351
1352template <typename ParticleType, int NArrayReal, int NArrayInt,
1353 template<class> class Allocator, class CellAssignor>
1355int
1357::hostPartitionTile (ParticleTileType& src_tile,
1358 int lev, int gid, int tid,
1359 int lev_min, int lev_max, IntVect nGrow, bool local,
1360 bool remove_negative, int myproc,
1362 Gpu::DeviceVector<int>& levels,
1364 Gpu::DeviceVector<int>& src_indices,
1365 Gpu::DeviceVector<IntVect>& periodic_shift)
1366{
1367 ParticleLocData pld;
1368 auto ptd = src_tile.getParticleTileData();
1369 int num_move = 0;
1370
1371 Long last = src_tile.numParticles() - 1;
1372 Long pindex = 0;
1373 int who = -1;
1374 while (pindex <= last) {
1375 decltype(auto) p = ptd[pindex];
1376
1377 // remove invalid if needed
1378 if (!ptd.id(pindex).is_valid()) {
1379 if (remove_negative) {
1380 copyParticle(ptd, ptd, last, pindex);
1381 correctCellVectors(last, pindex, gid, p);
1382 --last;
1383 } else {
1384 ++pindex;
1385 }
1386 continue;
1387 }
1388
1389 // Fast path: if on the finest level, try the last good location first
1390 // If not on finest level, we need to do the full locate because even if
1391 // the last assignment works, the particle might belong on a finer level.
1392 if (lev == lev_max && pld.m_tile == tid && pld.m_grid == gid && pld.m_lev == lev && who == myproc) {
1393 const auto iv = Index(p, lev);
1394 if (pld.m_tilebox.contains(iv)) {
1395 ++pindex;
1396 continue; // don't need correctCellVectors or particlePostLocate if it stays where it is
1397 }
1398 }
1399
1400 // full locate
1401 locateParticle(p, pld, lev_min, lev_max, nGrow, local ? gid : -1);
1402 particlePostLocate(p, pld, lev);
1403
1404 // particle may have been invalidated, so check if we need to remove again.
1405 if (!ptd.id(pindex).is_valid()) {
1406 copyParticle(ptd, ptd, last, pindex);
1407 correctCellVectors(last, pindex, gid, p);
1408 --last;
1409 continue;
1410 }
1411
1412 // flag particle for move if needed
1413 who = BufferMap().procID(pld.m_grid, pld.m_tile, pld.m_lev);
1414 if (pld.m_lev != lev || pld.m_grid != gid || pld.m_tile != tid || who != myproc) {
1415 // the particle is valid but needs to be sent somewhere else
1416 swapParticle(ptd, ptd, last, pindex);
1417 correctCellVectors(last, pindex, gid, p);
1418 boxes[num_move] = pld.m_grid;
1419 levels[num_move] = pld.m_lev;
1420 tiles[num_move] = pld.m_tile;
1421 src_indices[num_move] = static_cast<int>(last);
1422 ++num_move;
1423 --last;
1424 continue;
1425 }
1426
1427 ++pindex; // if here, particle stays
1428 }
1429
1430 boxes.resize(num_move);
1431 levels.resize(num_move);
1432 tiles.resize(num_move);
1433 src_indices.resize(num_move);
1434 periodic_shift.resize(num_move);
1435
1436 return static_cast<int>(pindex);
1437}
1438
1439//
1440// Shared implementation of Redistribute
1441//
1442template <typename ParticleType, int NArrayReal, int NArrayInt,
1443 template<class> class Allocator, class CellAssignor>
1444void
1445ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1446::Redistribute_impl (int lev_min, int lev_max, IntVect nGrow,
1447 bool local, IntVect max_cells_moved, bool remove_negative)
1448{
1449 BL_PROFILE("ParticleContainer::Redistribute_impl()");
1450 BL_PROFILE_VAR_NS("Redistribute_partition", blp_partition);
1451
1452 int theEffectiveFinestLevel = m_gdb->finestLevel();
1453 while (!m_gdb->LevelDefined(theEffectiveFinestLevel)) { theEffectiveFinestLevel--; }
1454
1455 if (std::ssize(m_particles) < theEffectiveFinestLevel+1) {
1456 if (Verbose()) {
1457 amrex::Print() << "ParticleContainer::Redistribute() resizing containers from "
1458 << m_particles.size() << " to "
1459 << theEffectiveFinestLevel + 1 << '\n';
1460 }
1461 m_particles.resize(theEffectiveFinestLevel+1);
1462 m_dummy_mf.resize(theEffectiveFinestLevel+1);
1463 }
1464
1465 for (int lev = 0; lev < theEffectiveFinestLevel+1; ++lev) { RedefineDummyMF(lev); }
1466
1467 int finest_lev_particles;
1468 if (lev_max == -1) {
1469 lev_max = theEffectiveFinestLevel;
1470 finest_lev_particles = m_particles.size() - 1;
1471 } else {
1472 finest_lev_particles = lev_max;
1473 }
1474 AMREX_ASSERT(lev_max <= finestLevel());
1475
1476 if (local) {
1477 AMREX_ASSERT(max_cells_moved.allGE(0));
1478 AMREX_ASSERT(numParticlesOutOfRange(*this, lev_min, lev_max,
1479 max_cells_moved) == 0);
1480 }
1482 this->defineBufferMap();
1483
1484#ifndef AMREX_USE_GPU
1485 const bool use_mask_lookup = local && lev_min == 0 && lev_max == 0
1486 && RedistributeMaskLooksCheap(0, max_cells_moved);
1487 if (use_mask_lookup) { BuildRedistributeMask(0, max_cells_moved); }
1488#else
1489 if (! m_particle_locator.isValid(GetParGDB(), do_tiling, tile_size)) { m_particle_locator.build(GetParGDB(), do_tiling, tile_size); }
1490 m_particle_locator.setGeometry(GetParGDB());
1491#endif
1492
1493 BL_PROFILE_VAR_START(blp_partition);
1494 ParticleCopyOp op;
1495 int num_levels = finest_lev_particles + 1;
1496 op.setNumLevels(num_levels);
1497 Vector<std::map<std::pair<int, int>, int> > new_sizes(num_levels);
1498#ifndef AMREX_USE_GPU
1499 const int myproc = ParallelContext::MyProcSub();
1500#endif
1501#ifdef AMREX_USE_GPU
1502 auto assign_grid = m_particle_locator.getGridAssignor();
1503 const auto plo = Geom(0).ProbLoArray();
1504 const auto phi = Geom(0).ProbHiArray();
1505 const auto rlo = Geom(0).ProbLoArrayInParticleReal();
1506 const auto rhi = Geom(0).ProbHiArrayInParticleReal();
1507 const auto is_per = Geom(0).isPeriodicArray();
1508#endif
1509
1510#if defined(AMREX_USE_OMP) || defined(AMREX_USE_GPU)
1511 Vector<std::pair<int, int> > grid_tile_ids;
1512 Vector<ParticleTileType*> ptile_ptrs;
1513 Vector<int> plevs;
1514 Vector<int*> new_size_ptrs;
1515#ifndef AMREX_USE_GPU
1517 Vector<Gpu::DeviceVector<int>*> level_ptrs;
1519 Vector<Gpu::DeviceVector<int>*> src_index_ptrs;
1520 Vector<Gpu::DeviceVector<IntVect>*> periodic_shift_ptrs;
1521#endif
1522 std::size_t num_tiles = 0;
1523 for (int lev = lev_min; lev <= finest_lev_particles; ++lev) {
1524 for (auto const& kv : m_particles[lev]) {
1525 if (kv.second.numParticles() != 0) {
1526 ++num_tiles;
1528 }
1529 }
1530 grid_tile_ids.reserve(num_tiles);
1531 ptile_ptrs.reserve(num_tiles);
1532 plevs.reserve(num_tiles);
1533 new_size_ptrs.reserve(num_tiles);
1534#ifndef AMREX_USE_GPU
1535 box_ptrs.reserve(num_tiles);
1536 level_ptrs.reserve(num_tiles);
1537 tile_ptrs.reserve(num_tiles);
1538 src_index_ptrs.reserve(num_tiles);
1539 periodic_shift_ptrs.reserve(num_tiles);
1540#endif
1541 for (int lev = lev_min; lev <= finest_lev_particles; lev++) {
1542 auto& pmap = m_particles[lev];
1543 for (auto& kv : pmap)
1544 {
1545 const auto np = kv.second.numParticles();
1546 if (np == 0) { continue; }
1547
1548 grid_tile_ids.push_back(kv.first);
1549 ptile_ptrs.push_back(&(kv.second));
1550 plevs.push_back(lev);
1551 auto index = std::make_pair(kv.first.first, kv.first.second);
1552 auto& new_size = new_sizes[lev][index];
1553 new_size = 0;
1554 new_size_ptrs.push_back(&new_size);
1555#ifndef AMREX_USE_GPU
1556 op.resize(kv.first.first, kv.first.second, lev, static_cast<int>(np));
1557 auto& boxes = op.m_boxes[lev][index];
1558 auto& levels = op.m_levels[lev][index];
1559 auto& tiles = op.m_tiles[lev][index];
1560 auto& src_indices = op.m_src_indices[lev][index];
1561 auto& periodic_shift = op.m_periodic_shift[lev][index];
1562 box_ptrs.push_back(&boxes);
1563 level_ptrs.push_back(&levels);
1564 tile_ptrs.push_back(&tiles);
1565 src_index_ptrs.push_back(&src_indices);
1566 periodic_shift_ptrs.push_back(&periodic_shift);
1567#endif
1568 }
1569 }
1570#endif
1571
1572#if defined(AMREX_USE_OMP) || defined(AMREX_USE_GPU)
1573#ifdef AMREX_USE_OMP
1574#pragma omp parallel for
1575#endif
1576 for (int pmap_it = 0; pmap_it < static_cast<int>(ptile_ptrs.size()); ++pmap_it)
1577 {
1578 int lev = plevs[pmap_it];
1579 int gid = grid_tile_ids[pmap_it].first;
1580 int tid = grid_tile_ids[pmap_it].second;
1581 auto& src_tile = *ptile_ptrs[pmap_it];
1582 const size_t np = src_tile.numParticles();
1583 if (np == 0) {continue;}
1584
1585#ifndef AMREX_USE_GPU
1586 auto& boxes = *box_ptrs[pmap_it];
1587 auto& levels = *level_ptrs[pmap_it];
1588 auto& tiles = *tile_ptrs[pmap_it];
1589 auto& src_indices = *src_index_ptrs[pmap_it];
1590 auto& periodic_shift = *periodic_shift_ptrs[pmap_it];
1591 *new_size_ptrs[pmap_it] = hostPartitionTile(src_tile,
1592 lev, gid, tid,
1593 lev_min, lev_max, nGrow, use_mask_lookup,
1594 remove_negative, myproc,
1595 boxes, levels, tiles,
1596 src_indices, periodic_shift);
1597#else // GPU algorithm
1598 int num_stay = partitionParticlesByDest(src_tile, assign_grid,
1599 std::forward<CellAssignor>(CellAssignor{}),
1600 BufferMap(),
1601 plo, phi, rlo, rhi, is_per, lev, gid, tid,
1602 lev_min, lev_max, nGrow, remove_negative);
1603
1604 int num_move = np - num_stay;
1605 *new_size_ptrs[pmap_it] = num_stay;
1606 op.resize(gid, tid, lev, num_move);
1607
1608 auto index = std::make_pair(gid, tid);
1609 auto* p_boxes = op.m_boxes[lev][index].dataPtr();
1610 auto* p_levs = op.m_levels[lev][index].dataPtr();
1611 auto* p_tiles = op.m_tiles[lev][index].dataPtr();
1612 auto* p_src_indices = op.m_src_indices[lev][index].dataPtr();
1613 auto* p_periodic_shift = op.m_periodic_shift[lev][index].dataPtr();
1614 auto ptd = src_tile.getParticleTileData();
1615
1616 amrex::ParallelFor(num_move, [=] AMREX_GPU_DEVICE (int i)
1617 {
1618 const auto p = ptd[i + num_stay];
1619
1620 if (!p.id().is_valid())
1621 {
1622 p_boxes[i] = -1;
1623 p_tiles[i] = -1;
1624 p_levs[i] = -1;
1625 }
1626 else
1627 {
1628 const auto tup = assign_grid(p, lev_min, lev_max, nGrow,
1629 std::forward<CellAssignor>(CellAssignor{}));
1630 p_boxes[i] = amrex::get<0>(tup);
1631 p_tiles[i] = amrex::get<1>(tup);
1632 p_levs[i] = amrex::get<2>(tup);
1633 }
1634 p_periodic_shift[i] = IntVect(AMREX_D_DECL(0,0,0));
1635 p_src_indices[i] = i+num_stay;
1636 });
1637#endif
1638 }
1639#else
1640 for (int lev = lev_min; lev <= finest_lev_particles; ++lev) {
1641 auto& pmap = m_particles[lev];
1642 for (auto& kv : pmap)
1643 {
1644 auto& src_tile = kv.second;
1645 const auto np = src_tile.numParticles();
1646 if (np == 0) { continue; }
1647
1648 int gid = kv.first.first;
1649 int tid = kv.first.second;
1650 auto index = std::make_pair(gid, tid);
1651 auto& new_size = new_sizes[lev][index];
1652 new_size = 0;
1653
1654 op.resize(gid, tid, lev, static_cast<int>(np));
1655 auto& boxes = op.m_boxes[lev][index];
1656 auto& levels = op.m_levels[lev][index];
1657 auto& tiles = op.m_tiles[lev][index];
1658 auto& src_indices = op.m_src_indices[lev][index];
1659 auto& periodic_shift = op.m_periodic_shift[lev][index];
1660 new_size = hostPartitionTile(src_tile,
1661 lev, gid, tid,
1662 lev_min, lev_max, nGrow, use_mask_lookup,
1663 remove_negative, myproc,
1664 boxes, levels, tiles,
1665 src_indices, periodic_shift);
1666 }
1667 }
1668#endif
1669 BL_PROFILE_VAR_STOP(blp_partition);
1670
1671 ParticleCopyPlan plan;
1672
1673 plan.build(*this, op, h_redistribute_int_comp,
1674 h_redistribute_real_comp, local, max_cells_moved);
1675
1676 // by default, this uses The_Arena();
1679
1680 if (use_comms_arena) {
1681 snd_buffer.setArena(The_Comms_Arena());
1682 rcv_buffer.setArena(The_Comms_Arena());
1683 }
1684
1685 packBuffer(*this, op, plan, snd_buffer);
1686
1687 // clear particles from container
1688 for (int lev = lev_min; lev <= lev_max; ++lev)
1689 {
1690 auto& plev = m_particles[lev];
1691 for (auto& kv : plev)
1692 {
1693 int gid = kv.first.first;
1694 int tid = kv.first.second;
1695 auto index = std::make_pair(gid, tid);
1696 auto& tile = plev[index];
1697 tile.resize(new_sizes[lev][index]);
1698 }
1699 }
1700
1701 for (int lev = lev_min; lev <= lev_max; lev++)
1702 {
1703 particle_detail::clearEmptyEntries(m_particles[lev]);
1704 }
1705
1706 if (std::ssize(m_particles) > theEffectiveFinestLevel+1) {
1707 if (m_verbose > 0) {
1708 amrex::Print() << "ParticleContainer::Redistribute() resizing m_particles from "
1709 << m_particles.size() << " to " << theEffectiveFinestLevel+1 << '\n';
1710 }
1711 AMREX_ASSERT(std::ssize(m_particles) >= 2);
1712
1713 m_particles.resize(theEffectiveFinestLevel + 1);
1714 m_dummy_mf.resize(theEffectiveFinestLevel + 1);
1715 }
1716
1718 {
1719 plan.buildMPIFinish(BufferMap());
1720 communicateParticlesStart(*this, plan, snd_buffer, rcv_buffer);
1721 this->ReserveForRedistribute(plan);
1722 unpackBuffer(*this, plan, snd_buffer, RedistributeUnpackPolicy());
1724 unpackRemotes(*this, plan, rcv_buffer, RedistributeUnpackPolicy());
1725 }
1726 else
1727 {
1729 Gpu::PinnedVector<char> pinned_snd_buffer;
1730 Gpu::PinnedVector<char> pinned_rcv_buffer;
1731
1732 if (snd_buffer.arena()->isPinned()) {
1733 plan.buildMPIFinish(BufferMap());
1735 communicateParticlesStart(*this, plan, snd_buffer, pinned_rcv_buffer);
1736 } else {
1737 pinned_snd_buffer.resize(snd_buffer.size());
1738 Gpu::dtoh_memcpy_async(pinned_snd_buffer.dataPtr(), snd_buffer.dataPtr(), snd_buffer.size());
1739 plan.buildMPIFinish(BufferMap());
1741 communicateParticlesStart(*this, plan, pinned_snd_buffer, pinned_rcv_buffer);
1742 }
1743
1744 this->ReserveForRedistribute(plan);
1745
1746 rcv_buffer.resize(pinned_rcv_buffer.size());
1747 unpackBuffer(*this, plan, snd_buffer, RedistributeUnpackPolicy());
1749 Gpu::htod_memcpy_async(rcv_buffer.dataPtr(), pinned_rcv_buffer.dataPtr(), pinned_rcv_buffer.size());
1750 unpackRemotes(*this, plan, rcv_buffer, RedistributeUnpackPolicy());
1751 }
1752
1754 AMREX_ASSERT(numParticlesOutOfRange(*this, lev_min, lev_max, nGrow) == 0);
1755}
1756
1757template <typename ParticleType, int NArrayReal, int NArrayInt,
1758 template<class> class Allocator, class CellAssignor>
1759void
1760ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1761::ReserveForRedistribute (ParticleCopyPlan const& plan)
1762{
1763 BL_PROFILE("ParticleContainer::ReserveForRedistribute()");
1764
1765 std::map<ParticleTileType*, int> addsizes;
1766
1767 for (int lev = 0; lev < this->BufferMap().numLevels(); ++lev) {
1768 for (MFIter mfi = this->MakeMFIter(lev); mfi.isValid(); ++mfi) {
1769 int gid = mfi.index();
1770 int tid = mfi.LocalTileIndex();
1771 auto& tile = this->DefineAndReturnParticleTile(lev, gid, tid);
1772 int num_copies = plan.m_box_counts_h[this->BufferMap().gridAndTileAndLevToBucket(gid, tid, lev)];
1773 if (num_copies > 0) {
1774 addsizes[&tile] += num_copies;
1775 }
1776 }
1777 }
1778
1779 if (plan.m_nrcvs > 0) {
1780 for (int i = 0; i < std::ssize(plan.m_rcv_box_counts); ++i) {
1781 int copy_size = plan.m_rcv_box_counts[i];
1782 int lev = plan.m_rcv_box_levs[i];
1783 int gid = plan.m_rcv_box_ids[i];
1784 int tid = plan.m_rcv_box_tids[i];
1785 auto& tile = this->DefineAndReturnParticleTile(lev, gid, tid);
1786 addsizes[&tile] += copy_size;
1787 }
1788 }
1789
1790 ParticleTileType::reserve(addsizes);
1791}
1792
1793template <typename ParticleType, int NArrayReal, int NArrayInt,
1794 template<class> class Allocator, class CellAssignor>
1795bool
1797{
1798 BL_PROFILE("ParticleContainer::OK()");
1799
1800 if (lev_max == -1) {
1801 lev_max = finestLevel();
1802 }
1803
1804 return (m_dummy_mf.size() >= lev_max+1 && numParticlesOutOfRange(*this, lev_min, lev_max, nGrow) == 0);
1805}
1806
1807template <typename ParticleType, int NArrayReal, int NArrayInt,
1808 template<class> class Allocator, class CellAssignor>
1809void
1811::AddParticlesAtLevel (AoS& particles, int level, int nGrow)
1812{
1813 ParticleTileType ptile;
1814 ptile.GetArrayOfStructs().swap(particles);
1815 AddParticlesAtLevel(ptile, level, nGrow);
1816}
1817
1818template <typename ParticleType, int NArrayReal, int NArrayInt,
1819 template<class> class Allocator, class CellAssignor>
1820void
1822::AddParticlesAtLevel (ParticleTileType& particles, int level, int nGrow)
1823{
1824 BL_PROFILE("ParticleContainer::AddParticlesAtLevel()");
1825
1826 if (std::ssize(m_particles) < level+1)
1827 {
1828 if (Verbose())
1829 {
1830 amrex::Print() << "ParticleContainer::AddParticlesAtLevel resizing m_particles from "
1831 << m_particles.size()
1832 << " to "
1833 << level+1 << '\n';
1834 }
1835 m_particles.resize(level+1);
1836 m_dummy_mf.resize(level+1);
1837 for (int lev = 0; lev < level+1; ++lev) {
1838 RedefineDummyMF(lev);
1839 }
1840 }
1841
1842 auto& ptile = DefineAndReturnParticleTile(level, 0, 0);
1843 int old_np = ptile.size();
1844 int num_to_add = particles.size();
1845 int new_np = old_np + num_to_add;
1846 ptile.resize(new_np);
1847 amrex::copyParticles(ptile, particles, 0, old_np, num_to_add);
1848 Redistribute(level, level, nGrow);
1849 particles.resize(0);
1850}
1851
1852// This is the single-level version for cell-centered density
1853template <typename ParticleType, int NArrayReal, int NArrayInt,
1854 template<class> class Allocator, class CellAssignor>
1855void
1857AssignCellDensitySingleLevel (int rho_index,
1858 MultiFab& mf_to_be_filled,
1859 int lev,
1860 int ncomp,
1861 int particle_lvl_offset) const
1862{
1863 BL_PROFILE("ParticleContainer::AssignCellDensitySingleLevel()");
1864
1865 if (rho_index != 0) { amrex::Abort("AssignCellDensitySingleLevel only works if rho_index = 0"); }
1866
1867 MultiFab* mf_pointer;
1868
1869 if (OnSameGrids(lev, mf_to_be_filled)) {
1870 // If we are already working with the internal mf defined on the
1871 // particle_box_array, then we just work with this.
1872 mf_pointer = &mf_to_be_filled;
1873 }
1874 else {
1875 // If mf_to_be_filled is not defined on the particle_box_array, then we need
1876 // to make a temporary here and copy into mf_to_be_filled at the end.
1877 mf_pointer = new MultiFab(ParticleBoxArray(lev),
1878 ParticleDistributionMap(lev),
1879 ncomp, mf_to_be_filled.nGrow());
1880 }
1881
1882 // We must have ghost cells for each FAB so that a particle in one grid can spread
1883 // its effect to an adjacent grid by first putting the value into ghost cells of its
1884 // own grid. The mf->SumBoundary call then adds the value from one grid's ghost cell
1885 // to another grid's valid region.
1886 if (mf_pointer->nGrow() < 1) {
1887 amrex::Error("Must have at least one ghost cell when in AssignCellDensitySingleLevel");
1888 }
1889
1890 const auto strttime = amrex::second();
1891
1892 const auto dxi = Geom(lev).InvCellSizeArray();
1893 const auto plo = Geom(lev).ProbLoArray();
1894 const auto pdxi = Geom(lev + particle_lvl_offset).InvCellSizeArray();
1895
1896 if (Geom(lev).isAnyPeriodic() && ! Geom(lev).isAllPeriodic())
1897 {
1898 amrex::Error("AssignCellDensitySingleLevel: problem must be periodic in no or all directions");
1899 }
1900
1901 mf_pointer->setVal(0);
1902
1904#ifdef AMREX_USE_OMP
1905#pragma omp parallel if (Gpu::notInLaunchRegion())
1906#endif
1907 {
1908 FArrayBox local_rho;
1909 for (ParConstIter pti(*this, lev); pti.isValid(); ++pti) {
1910 const Long np = pti.numParticles();
1911 auto ptd = pti.GetParticleTile().getConstParticleTileData();
1912 FArrayBox& fab = (*mf_pointer)[pti];
1913 auto rhoarr = fab.array();
1914#ifdef AMREX_USE_OMP
1915 Box tile_box;
1916 if (Gpu::notInLaunchRegion())
1917 {
1918 tile_box = pti.tilebox();
1919 tile_box.grow(mf_pointer->nGrow());
1920 local_rho.resize(tile_box,ncomp);
1921 local_rho.setVal<RunOn::Host>(0.0);
1922 rhoarr = local_rho.array();
1923 }
1924#endif
1925
1926 if (particle_lvl_offset == 0)
1927 {
1929 {
1930 auto p = ptd[i];
1931 amrex_deposit_cic(p, ncomp, rhoarr, plo, dxi);
1932 });
1933 }
1934 else
1935 {
1937 {
1938 auto p = ptd[i];
1939 amrex_deposit_particle_dx_cic(p, ncomp, rhoarr, plo, dxi, pdxi);
1940 });
1941 }
1942
1943#ifdef AMREX_USE_OMP
1944 if (Gpu::notInLaunchRegion())
1945 {
1946 fab.atomicAdd<RunOn::Host>(local_rho, tile_box, tile_box, 0, 0, ncomp);
1947 }
1948#endif
1949 }
1950 }
1951
1952 mf_pointer->SumBoundary(Geom(lev).periodicity());
1953
1954 // If ncomp > 1, first divide the momenta (component n)
1955 // by the mass (component 0) in order to get velocities.
1956 // Be careful not to divide by zero.
1957 for (int n = 1; n < ncomp; n++)
1958 {
1959 for (MFIter mfi(*mf_pointer); mfi.isValid(); ++mfi)
1960 {
1961 (*mf_pointer)[mfi].protected_divide<RunOn::Device>((*mf_pointer)[mfi],0,n,1);
1962 }
1963 }
1964
1965 // Only multiply the first component by (1/vol) because this converts mass
1966 // to density. If there are additional components (like velocity), we don't
1967 // want to divide those by volume.
1968 const Real* dx = Geom(lev).CellSize();
1969 const Real vol = AMREX_D_TERM(dx[0], *dx[1], *dx[2]);
1970
1971 mf_pointer->mult(Real(1.0)/vol, 0, 1, mf_pointer->nGrow());
1972
1973 // If mf_to_be_filled is not defined on the particle_box_array, then we need
1974 // to copy here from mf_pointer into mf_to_be_filled.
1975 if (mf_pointer != &mf_to_be_filled)
1976 {
1977 mf_to_be_filled.ParallelCopy(*mf_pointer,0,0,ncomp,0,0);
1978 delete mf_pointer;
1979 }
1980
1981 if (m_verbose > 1)
1982 {
1983 auto stoptime = amrex::second() - strttime;
1984
1985 ParallelReduce::Max(stoptime, ParallelContext::IOProcessorNumberSub(),
1986 ParallelContext::CommunicatorSub());
1987
1988 amrex::Print() << "ParticleContainer::AssignCellDensitySingleLevel) time: "
1989 << stoptime << '\n';
1990 }
1991}
1992
1993template <typename ParticleType, int NArrayReal, int NArrayInt,
1994 template<class> class Allocator, class CellAssignor>
1995void
1997ResizeRuntimeRealComp (int new_size, bool communicate)
1998{
1999 int old_size = m_num_runtime_real;
2000
2001 m_runtime_comps_defined = (new_size > 0);
2002 m_num_runtime_real = new_size;
2003 int cur_size = h_redistribute_real_comp.size();
2004 h_redistribute_real_comp.resize(cur_size-old_size+new_size, communicate);
2005 SetParticleSize();
2006
2007 for (int lev = 0; lev < numLevels(); ++lev) {
2008 for (ParIterType pti(*this,lev); pti.isValid(); ++pti) {
2009 auto& tile = DefineAndReturnParticleTile(lev, pti);
2010 auto np = tile.numParticles();
2011 if (np > 0 && new_size > old_size) {
2012 auto& soa = tile.GetStructOfArrays();
2013 soa.resize(np);
2014 }
2015 }
2016 }
2017}
2018
2019template <typename ParticleType, int NArrayReal, int NArrayInt,
2020 template<class> class Allocator, class CellAssignor>
2021void
2023ResizeRuntimeIntComp (int new_size, bool communicate)
2024{
2025 int old_size = m_num_runtime_int;
2026
2027 m_runtime_comps_defined = (new_size > 0);
2028 m_num_runtime_int = new_size;
2029 int cur_size = h_redistribute_int_comp.size();
2030 h_redistribute_int_comp.resize(cur_size-old_size+new_size, communicate);
2031 SetParticleSize();
2032
2033 for (int lev = 0; lev < numLevels(); ++lev) {
2034 for (ParIterType pti(*this,lev); pti.isValid(); ++pti) {
2035 auto& tile = DefineAndReturnParticleTile(lev, pti);
2036 auto np = tile.numParticles();
2037 if (np > 0 && new_size > old_size) {
2038 auto& soa = tile.GetStructOfArrays();
2039 soa.resize(np);
2040 }
2041 }
2042 }
2043}
2044
2045}
#define BL_PROFILE_VAR_START(vname)
Definition AMReX_BLProfiler.H:604
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:593
#define BL_PROFILE_VAR_STOP(vname)
Definition AMReX_BLProfiler.H:605
#define BL_PROFILE_SYNC_STOP()
Definition AMReX_BLProfiler.H:709
#define BL_PROFILE_SYNC_START_TIMED(fname)
Definition AMReX_BLProfiler.H:708
#define BL_PROFILE_VAR_NS(fname, vname)
Definition AMReX_BLProfiler.H:603
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:124
#define AMREX_HOST_DEVICE_FOR_1D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:105
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
amrex::ParmParse pp
Input file parser instance for the given namespace.
Definition AMReX_HypreIJIface.cpp:18
while parser_exe_t p
Definition AMReX_Parser_Exe_Body.H:33
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Print on all processors of the default communicator.
Definition AMReX_Print.H:113
BaseFab< T > & atomicAdd(const BaseFab< T > &x) noexcept
Atomic FAB addition (a[i] <- a[i] + b[i]).
Definition AMReX_BaseFab.H:2628
Array4< T const > array() const noexcept
Create an Array4 view over all components.
Definition AMReX_BaseFab.H:475
void setVal(T const &x, const Box &bx, int dcomp, int ncomp) noexcept
The setVal functions set sub-regions in the BaseFab to a constant value. This most general form speci...
Definition AMReX_BaseFab.H:1538
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:681
IndexType ixType() const noexcept
Return index type of this BoxArray.
Definition AMReX_BoxArray.H:1268
BoxArray & grow(int n)
Grow each Box by n cells in every direction.
Definition AMReX_BoxArray.cpp:722
std::vector< std::pair< int, Box > > intersections(const Box &bx) const
Return all intersections of bx with this BoxArray.
Definition AMReX_BoxArray.cpp:1202
Box getCellCenteredBox(int index) const noexcept
Return cell-centered box at element index of this BoxArray.
Definition AMReX_BoxArray.H:1099
static bool SameRefs(const BoxArray &lhs, const BoxArray &rhs)
whether two BoxArrays share the same data
Definition AMReX_BoxArray.H:1251
A list of Boxes sharing a common IndexType.
Definition AMReX_BoxList.H:109
BoxList & complementIn(const Box &b, const BoxList &bl)
Set this BoxList to the complement of BoxList bl in Box b.
Definition AMReX_BoxList.cpp:312
__host__ __device__ BoxND & grow(int i) noexcept
Grow in all directions by i cells (negative shrinks).
Definition AMReX_Box.H:668
__host__ __device__ bool contains(const IntVectND< dim > &p) const noexcept
Return true if argument is contained within BoxND.
Definition AMReX_Box.H:233
GpuArray< Real, 3 > InvCellSizeArray() const noexcept
Returns the inverse cell sizes as a GpuArray for use on host or device.
Definition AMReX_CoordSys.H:97
A Fortran Array of REALs.
Definition AMReX_FArrayBox.H:237
void resize(const Box &b, int N=1, Arena *ar=nullptr)
For debugging purposes we hide BaseFab version and do some extra work.
Definition AMReX_FArrayBox.cpp:178
int size() const noexcept
Return the number of FABs in the FabArray.
Definition AMReX_FabArrayBase.H:115
int nGrow(int direction=0) const noexcept
Return the grow factor that defines the region of definition.
Definition AMReX_FabArrayBase.H:83
const DistributionMapping & DistributionMap() const noexcept
Return constant reference to associated DistributionMapping.
Definition AMReX_FabArrayBase.H:135
const BoxArray & boxArray() const noexcept
Return a constant reference to the BoxArray that defines the valid region associated with this FabArr...
Definition AMReX_FabArrayBase.H:100
void ParallelCopy(const FabArray< FAB > &src, const Periodicity &period=Periodicity::NonPeriodic(), CpOp op=FabArrayBase::COPY)
Definition AMReX_FabArray.H:971
void setVal(value_type val)
Set all components in the entire region of each FAB to val.
Definition AMReX_FabArray.H:2985
Array4< typename FabArray< FAB >::value_type const > array(const MFIter &mfi) const noexcept
Read-only Array4 view for the FAB referenced by iterator mfi.
Definition AMReX_FabArray.H:621
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:85
const Box & Domain() const noexcept
Returns our rectangular domain.
Definition AMReX_Geometry.H:244
GpuArray< Real, 3 > ProbLoArray() const noexcept
Return the lo end of the problem domain in a GpuArray for device code.
Definition AMReX_Geometry.H:217
static void streamSynchronize() noexcept
Definition AMReX_GpuDevice.cpp:861
__host__ __device__ bool cellCentered() const noexcept
True if the IndexTypeND is CELL based in all directions.
Definition AMReX_IndexType.H:102
__host__ __device__ constexpr bool allGE(const IntVectND< dim > &rhs) const noexcept
Returns true if this is greater than or equal to argument for all components. NOTE: This is NOT a str...
Definition AMReX_IntVect.H:542
__host__ static __device__ constexpr IntVectND< dim > TheZeroVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:771
a one-thingy-per-box distributed object
Definition AMReX_LayoutData.H:13
Iterator for looping ever tiles and boxes of amrex::FabArray based containers.
Definition AMReX_MFIter.H:88
int LocalTileIndex() const noexcept
The current local tile index in the current grid;.
Definition AMReX_MFIter.H:185
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:176
Box validbox() const noexcept
Return the valid Box in which the current tile resides.
Definition AMReX_MFIter.H:167
int index() const noexcept
The index into the underlying BoxArray of the current FAB.
Definition AMReX_MFIter.H:179
A collection (stored as an array) of FArrayBox objects.
Definition AMReX_MultiFab.H:40
void mult(Real val, int comp, int num_comp, int nghost=0)
Scales the value of each cell in the specified subregion of the MultiFab by the scalar val (a[i] <- a...
Definition AMReX_MultiFab.cpp:1499
Dynamically allocated vector for trivially copyable data.
Definition AMReX_PODVector.H:308
size_type size() const noexcept
Definition AMReX_PODVector.H:654
void resize(size_type a_new_size, GrowthStrategy strategy=GrowthStrategy::Poisson)
Definition AMReX_PODVector.H:734
T * dataPtr() noexcept
Definition AMReX_PODVector.H:676
Definition AMReX_ParIter.H:147
Definition AMReX_ParIter.H:118
int queryAdd(std::string_view name, T &ref)
If name is found, the value in the ParmParse database will be stored in the ref argument....
Definition AMReX_ParmParse.H:1061
int queryarr(std::string_view name, std::vector< int > &ref, int start_ix=FIRST, int num_val=ALL) const
Same as queryktharr() but searches for last occurrence of name.
Definition AMReX_ParmParse.cpp:2096
int query(std::string_view name, bool &ref, int ival=FIRST) const
Same as querykth() but searches for the last occurrence of name.
Definition AMReX_ParmParse.cpp:2010
virtual void reserveData()
Definition AMReX_ParticleContainerBase.cpp:70
virtual void resizeData()
Definition AMReX_ParticleContainerBase.cpp:75
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition AMReX_ParticleContainer.H:149
IntVect Index(const P &p, int lev) const
Definition AMReX_ParticleContainerI.H:202
std::map< std::pair< int, int >, ParticleTileType > ParticleLevel
Definition AMReX_ParticleContainer.H:196
void SetSoACompileTimeNames(std::vector< std::string > const &rdata_name, std::vector< std::string > const &idata_name)
Definition AMReX_ParticleContainerI.H:110
typename ParticleTileType::AoS AoS
Definition AMReX_ParticleContainer.H:199
void SetParticleSize()
Definition AMReX_ParticleContainerI.H:17
void RemoveParticlesAtLevel(int level)
The Following methods are for managing Virtual and Ghost Particles.
Definition AMReX_ParticleContainerI.H:760
void clearParticles()
Clear all the particles in this container. This does not free memory.
Definition AMReX_ParticleContainerI.H:1131
void Increment(MultiFab &mf, int level)
Definition AMReX_ParticleContainerI.H:723
bool HasIntComp(std::string const &name)
Definition AMReX_ParticleContainerI.H:149
void ShrinkToFit()
Definition AMReX_ParticleContainerI.H:703
bool HasRealComp(std::string const &name)
Definition AMReX_ParticleContainerI.H:141
void resizeData() override
This resizes the vector of dummy MultiFabs used by the ParticleContainer for the current number of le...
Definition AMReX_ParticleContainerI.H:436
Long IncrementWithTotal(MultiFab &mf, int level, bool local=false)
Definition AMReX_ParticleContainerI.H:750
Long NumberOfParticlesAtLevel(int level, bool only_valid=true, bool only_local=false) const
Returns # of particles at specified the level.
Definition AMReX_ParticleContainerI.H:553
void SortParticlesByCell()
Sort the particles on each tile by cell, using Fortran ordering.
Definition AMReX_ParticleContainerI.H:1286
int GetRealCompIndex(std::string const &name)
Definition AMReX_ParticleContainerI.H:162
int GetIntCompIndex(std::string const &name)
Definition AMReX_ParticleContainerI.H:184
void RemoveParticlesNotAtFinestLevel()
Definition AMReX_ParticleContainerI.H:774
Vector< Long > NumberOfParticlesInGrid(int level, bool only_valid=true, bool only_local=false) const
Definition AMReX_ParticleContainerI.H:497
ParticleLocData Reset(ParticleType &prt, bool update, bool verbose=true, ParticleLocData pld=ParticleLocData()) const
Updates a particle's location (Where), tries to periodic shift any particles that have left the domai...
Definition AMReX_ParticleContainerI.H:393
std::conditional_t< is_rtsoa_pc, ParticleTileRT< typename ParticleType::RealType, typename ParticleType::IntType >, ParticleTile< ParticleType, NArrayReal, NArrayInt, Allocator > > ParticleTileType
Definition AMReX_ParticleContainer.H:191
Long TotalNumberOfParticles(bool only_valid=true, bool only_local=false) const
Returns # of particles at all levels.
Definition AMReX_ParticleContainerI.H:482
void reserveData() override
This reserves data in the vector of dummy MultiFabs used by the ParticleContainer for the maximum num...
Definition AMReX_ParticleContainerI.H:427
T_ParticleType ParticleType
Definition AMReX_ParticleContainer.H:151
Definition AMReX_ParticleLocator.H:137
void build(const BoxArray &ba, const Geometry &geom, bool a_do_tiling=false, const IntVect &a_tile_size=IntVect(1024000, 1024000, 1024000))
Definition AMReX_ParticleLocator.H:144
AssignGrid< BinIteratorFactory > getGridAssignor() const noexcept
Definition AMReX_ParticleLocator.H:220
This class provides the user with a few print options.
Definition AMReX_Print.H:35
Definition AMReX_Reduce.H:438
Type value()
Definition AMReX_Reduce.H:473
Definition AMReX_Reduce.H:597
void eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition AMReX_Reduce.H:734
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
Long size() const noexcept
Definition AMReX_Vector.H:54
A Collection of IArrayBoxes.
Definition AMReX_iMultiFab.H:34
Long sum(int comp, int nghost=0, bool local=false) const
Returns the sum in component comp.
Definition AMReX_iMultiFab.cpp:454
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
amrex_particle_real ParticleReal
Floating Point Type for Particles.
Definition AMReX_REAL.H:91
amrex_long Long
Definition AMReX_INT.H:30
T ExclusiveSum(N n, T const *in, T *out, RetSum a_ret_sum=retSum)
Exclusive sum.
Definition AMReX_Scan.H:1045
void SumBoundary(const Periodicity &period=Periodicity::NonPeriodic(), bool deterministic=false)
Sum values in overlapped cells.
Definition AMReX_FabArray.H:3935
__host__ __device__ BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Return a copy of b grown uniformly by i cells in every direction.
Definition AMReX_Box.H:1326
Arena * The_Comms_Arena()
Definition AMReX_Arena.cpp:889
void Min(KeyValuePair< K, V > &vi, int root, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:287
void Max(KeyValuePair< K, V > &vi, int root, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:254
void Bcast(Gpu::DeviceVector< T > &v, int root, MPI_Comm comm)
Definition AMReX_GpuParallelReduce.H:105
void Sum(Gpu::DeviceVector< T > &v, MPI_Comm comm)
Definition AMReX_GpuParallelReduce.H:37
void Sum(Gpu::DeviceVector< T > &v, int root, MPI_Comm comm)
Definition AMReX_GpuParallelReduce.H:62
__host__ __device__ AMREX_FORCE_INLINE void AddNoRet(T *sum, T value) noexcept
Definition AMReX_GpuAtomic.H:283
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:310
void dtoh_memcpy_async(void *p_h, const void *p_d, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:435
void htod_memcpy_async(void *p_d, const void *p_h, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:421
void QueueReduction(Func f)
Definition AMReX_Lazy.cpp:7
constexpr Long GhostParticleID
Definition AMReX_Particle.H:19
constexpr Long VirtualParticleID
Definition AMReX_Particle.H:20
MPI_Comm CommunicatorSub() noexcept
sub-communicator for current frame
Definition AMReX_ParallelContext.H:70
int MyProcSub() noexcept
my sub-rank in current frame
Definition AMReX_ParallelContext.H:76
int IOProcessorNumberSub() noexcept
IO sub-rank in current frame.
Definition AMReX_ParallelContext.H:78
bool UseGpuAwareMpi()
Definition AMReX_ParallelDescriptor.H:113
void GatherLayoutDataToVector(const LayoutData< T > &sendbuf, Vector< T > &recvbuf, int root)
Gather LayoutData values to a vector on root.
Definition AMReX_ParallelDescriptor.H:1286
static constexpr RetSum retSum
Definition AMReX_Scan.H:34
Definition AMReX_Amr.cpp:50
void gatherParticles(PTile &dst, const PTile &src, N np, const Index *inds)
Gather particles copies particles into contiguous order from an arbitrary order. Specifically,...
Definition AMReX_ParticleTransformation.H:739
__host__ __device__ void swapParticle(const ParticleTileData< T_ParticleType, NAR, NAI > &dst, const ParticleTileData< T_ParticleType, NAR, NAI > &src, int src_i, int dst_i) noexcept
A general single particle swapping routine that can run on the GPU.
Definition AMReX_ParticleTransformation.H:120
__host__ __device__ int getTileIndex(const IntVect &iv, const Box &box, const bool a_do_tiling, const IntVect &a_tile_size, Box &tbx)
Definition AMReX_ParticleUtil.H:191
__host__ __device__ void copyParticle(const ParticleTileData< T_ParticleType, NAR, NAI > &dst, const ConstParticleTileData< T_ParticleType, NAR, NAI > &src, int src_i, int dst_i) noexcept
A general single particle copying routine that can run on the GPU.
Definition AMReX_ParticleTransformation.H:32
void copyParticles(DstTile &dst, const SrcTile &src) noexcept
Copy particles from src to dst. This version copies all the particles, writing them to the beginning ...
Definition AMReX_ParticleTransformation.H:222
void communicateParticlesStart(const PC &pc, ParticleCopyPlan &plan, const SndBuffer &snd_buffer, RcvBuffer &rcv_buffer)
Definition AMReX_ParticleCommunication.H:910
int partitionParticlesByDest(PTile &ptile, const PLocator &ploc, CellAssignor const &assignor, const ParticleBufferMap &pmap, const GpuArray< Real, 3 > &plo, const GpuArray< Real, 3 > &phi, const GpuArray< ParticleReal, 3 > &rlo, const GpuArray< ParticleReal, 3 > &rhi, const GpuArray< int, 3 > &is_per, int lev, int gid, int tid, int lev_min, int lev_max, IntVect nGrow, bool remove_negative)
Definition AMReX_ParticleUtil.H:654
void ReorderParticles(PTile &ptile, const index_type *permutations)
Reorder particles on the tile ptile using a the permutations array.
Definition AMReX_ParticleUtil.H:955
__host__ __device__ bool enforcePeriodic(P &p, amrex::GpuArray< amrex::Real, 3 > const &plo, amrex::GpuArray< amrex::Real, 3 > const &phi, amrex::GpuArray< amrex::ParticleReal, 3 > const &rlo, amrex::GpuArray< amrex::ParticleReal, 3 > const &rhi, amrex::GpuArray< int, 3 > const &is_per) noexcept
Definition AMReX_ParticleUtil.H:423
void ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:202
__host__ __device__ int numTilesInBox(const Box &box, const bool a_do_tiling, const IntVect &a_tile_size)
Definition AMReX_ParticleUtil.H:239
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
void ParticleToMesh(PC const &pc, const Vector< MultiFab * > &mf, int lev_min, int lev_max, F &&f, bool zero_out_input=true, bool vol_weight=true)
Deposit particles onto a hierarchy of MultiFabs.
Definition AMReX_AmrParticles.H:189
void unpackBuffer(PC &pc, const ParticleCopyPlan &plan, const Buffer &snd_buffer, UnpackPolicy const &policy)
Definition AMReX_ParticleCommunication.H:783
double second() noexcept
Definition AMReX_Utility.cpp:919
void packBuffer(const PC &pc, const ParticleCopyOp &op, const ParticleCopyPlan &plan, Buffer &snd_buffer)
Definition AMReX_ParticleCommunication.H:583
int nComp(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.nComp().
Definition AMReX_FabArrayBase.cpp:2939
void communicateParticlesFinish(const ParticleCopyPlan &plan)
Definition AMReX_ParticleCommunication.cpp:445
Index filterAndTransformParticles(DstTile &dst, const SrcTile &src, Index *mask, F const &f, Index src_start, Index dst_start) noexcept
Conditionally copy particles from src to dst based on the value of mask. A transformation will also b...
Definition AMReX_ParticleTransformation.H:516
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
void unpackRemotes(PC &pc, const ParticleCopyPlan &plan, Buffer &rcv_buffer, UnpackPolicy const &policy)
Definition AMReX_ParticleCommunication.H:1010
void Error(const std::string &msg)
Print a message to stderr and abort the program.
Definition AMReX.cpp:238
int numParticlesOutOfRange(Iterator const &pti, int nGrow)
Returns the number of particles that are more than nGrow cells from the box correspond to the input i...
Definition AMReX_ParticleUtil.H:36
int Verbose() noexcept
Return the verbosity level configured via ParmParse or SetVerbose().
Definition AMReX.cpp:184
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:244
const int[]
Definition AMReX_BLProfiler.cpp:1665
Index filterParticles(DstTile &dst, const SrcTile &src, const Index *mask) noexcept
Conditionally copy particles from src to dst based on the value of mask.
Definition AMReX_ParticleTransformation.H:389
void transformParticles(DstTile &dst, const SrcTile &src, F &&f) noexcept
Apply the function f to all the particles in src, writing the result to dst. This version does all th...
Definition AMReX_ParticleTransformation.H:273
__host__ __device__ IntVect getParticleCell(P const &p, amrex::GpuArray< amrex::Real, 3 > const &plo, amrex::GpuArray< amrex::Real, 3 > const &dxi) noexcept
Returns the cell index for a given particle using the provided lower bounds and cell sizes.
Definition AMReX_ParticleUtil.H:343
Definition AMReX_ParticleLocator.H:262
A multidimensional array accessor.
Definition AMReX_Array4.H:289
Definition AMReX_ParticleContainerI.H:1041
amrex::AmrAssignGrid< amrex::DenseBinIteratorFactory< amrex::Box > > m_assign_grid
Definition AMReX_ParticleContainerI.H:1044
int m_lev_max
Definition AMReX_ParticleContainerI.H:1043
AssignGridFilter(amrex::AmrAssignGrid< amrex::DenseBinIteratorFactory< amrex::Box > > assign_grid, int gid, int level, int nGrow)
This filters based on matching grids.
Definition AMReX_ParticleContainerI.H:1050
int m_nGrow
Definition AMReX_ParticleContainerI.H:1043
int m_lev_min
Definition AMReX_ParticleContainerI.H:1043
AMREX_GPU_HOST_DEVICE int operator()(const SrcData &src, int src_i) const noexcept
Definition AMReX_ParticleContainerI.H:1056
int m_gid
Definition AMReX_ParticleContainerI.H:1043
Definition AMReX_ParticleLocator.H:17
Definition AMReX_ParticleUtil.H:396
Definition AMReX_DenseBins.H:110
Definition AMReX_ParticleContainerI.H:802
Box m_domain
Definition AMReX_ParticleContainerI.H:806
GpuArray< Real, 3 > m_dxi
Definition AMReX_ParticleContainerI.H:805
FilterVirt(const amrex::AssignGrid< amrex::DenseBinIteratorFactory< amrex::Box > > &assign_buffer_grid, const GpuArray< Real, 3 > &plo, const GpuArray< Real, 3 > &dxi, const Box &domain)
Definition AMReX_ParticleContainerI.H:808
AMREX_GPU_HOST_DEVICE int operator()(const SrcData &src, int src_i) const noexcept
Definition AMReX_ParticleContainerI.H:815
amrex::AssignGrid< amrex::DenseBinIteratorFactory< amrex::Box > > m_assign_buffer_grid
Definition AMReX_ParticleContainerI.H:804
GpuArray< Real, 3 > m_plo
Definition AMReX_ParticleContainerI.H:805
Definition AMReX_ParticleUtil.H:310
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:52
Definition AMReX_GpuControl.H:180
Definition AMReX_TypeTraits.H:90
Definition AMReX_ParticleCommunication.H:92
Vector< int > m_rcv_box_ids
Definition AMReX_ParticleCommunication.H:366
Vector< int > m_rcv_box_counts
Definition AMReX_ParticleCommunication.H:364
Vector< int > m_rcv_box_levs
Definition AMReX_ParticleCommunication.H:369
Vector< int > m_rcv_box_tids
Definition AMReX_ParticleCommunication.H:367
int m_nrcvs
Definition AMReX_ParticleCommunication.H:372
Gpu::HostVector< unsigned int > m_box_counts_h
Definition AMReX_ParticleCommunication.H:361
A struct used for storing a particle's position in the AMR hierarchy.
Definition AMReX_ParticleContainer.H:93
Box m_grown_gridbox
Definition AMReX_ParticleContainer.H:100
IntVect m_cell
Definition AMReX_ParticleContainer.H:97
int m_grid
Definition AMReX_ParticleContainer.H:95
int m_tile
Definition AMReX_ParticleContainer.H:96
int m_lev
Definition AMReX_ParticleContainer.H:94
Box m_tilebox
Definition AMReX_ParticleContainer.H:99
Box m_gridbox
Definition AMReX_ParticleContainer.H:98
The struct used to store particles.
Definition AMReX_Particle.H:405
__host__ __device__ RealVect pos() const &
Definition AMReX_Particle.H:456
Definition AMReX_ParticleContainerI.H:1068
AMREX_GPU_HOST_DEVICE void operator()(DstData &dst, const SrcData &src, int src_i, int dst_i) const noexcept
Definition AMReX_ParticleContainerI.H:1072
Definition AMReX_ParticleContainerI.H:823
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(DstData &dst, const SrcData &src, int src_i, int dst_i) const noexcept
Definition AMReX_ParticleContainerI.H:826