13template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
14 template<
class>
class Allocator,
class CellAssignor>
18 num_real_comm_comps = 0;
19 int comm_comps_start = 0;
20 if constexpr (!ParticleType::is_soa_particle) {
21 comm_comps_start += AMREX_SPACEDIM + NStructReal;
23 for (
int i = comm_comps_start; i < comm_comps_start + NumRealComps(); ++i) {
24 if (h_redistribute_real_comp[i]) {++num_real_comm_comps;}
27 num_int_comm_comps = 0;
28 comm_comps_start = 2 + NStructInt;
29 for (
int i = comm_comps_start; i < comm_comps_start + NumIntComps(); ++i) {
30 if (h_redistribute_int_comp[i]) {++num_int_comm_comps;}
33 if constexpr (ParticleType::is_soa_particle) {
34 particle_size =
sizeof(uint64_t);
38 superparticle_size = particle_size +
39 num_real_comm_comps*
sizeof(
ParticleReal) + num_int_comm_comps*
sizeof(
int);
42template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
43 template<
class>
class Allocator,
class CellAssignor>
47 levelDirectoriesCreated =
false;
52 if constexpr (ParticleType::is_soa_particle)
54 h_redistribute_real_comp.resize(NArrayReal,
true);
56 h_redistribute_real_comp.resize(AMREX_SPACEDIM + NStructReal + NArrayReal,
true);
58 h_redistribute_int_comp.resize(2 + NStructInt + NArrayInt,
true);
63 m_soa_rdata_names.clear();
64 for (
int i=0; i<NArrayReal; ++i)
66 m_soa_rdata_names.push_back(getDefaultCompNameReal<ParticleType>(i));
68 m_soa_idata_names.clear();
69 for (
int i=0; i<NArrayInt; ++i)
71 m_soa_idata_names.push_back(getDefaultCompNameInt<ParticleType>(i));
74 static bool initialized =
false;
77 static_assert(
sizeof(ParticleType)%
sizeof(RealType) == 0,
78 "sizeof ParticleType is not a multiple of sizeof RealType");
80 ParmParse
pp(
"particles");
82 Vector<int> tilesize(AMREX_SPACEDIM);
83 if (
pp.
queryarr(
"tile_size", tilesize, 0, AMREX_SPACEDIM)) {
84 for (
int i=0; i<AMREX_SPACEDIM; ++i) { tile_size[i] = tilesize[i]; }
87 static_assert(std::is_standard_layout_v<ParticleType>,
88 "Particle type must be standard layout");
92 pp.
query(
"use_prepost", usePrePost);
93 pp.
query(
"do_unlink", doUnlink);
94 pp.
queryAdd(
"do_mem_efficient_sort", memEfficientSort);
95 pp.
queryAdd(
"use_comms_arena", use_comms_arena);
102 typename ParticleType,
105 template<
class>
class Allocator,
110 std::vector<std::string>
const & rdata_name, std::vector<std::string>
const & idata_name
117 std::set<std::string>
const unique_r_names(rdata_name.begin(), rdata_name.end());
118 std::set<std::string>
const unique_i_names(idata_name.begin(), idata_name.end());
122 for (
int i=0; i<NArrayReal; ++i)
124 m_soa_rdata_names.at(i) = rdata_name.at(i);
126 for (
int i=0; i<NArrayInt; ++i)
128 m_soa_idata_names.at(i) = idata_name.at(i);
133 typename ParticleType,
136 template<
class>
class Allocator,
142 return std::find(m_soa_rdata_names.begin(), m_soa_rdata_names.end(), name) != std::end(m_soa_rdata_names);
145template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
146 template<
class>
class Allocator,
class CellAssignor>
150 return std::find(m_soa_idata_names.begin(), m_soa_idata_names.end(), name) != std::end(m_soa_idata_names);
154 typename ParticleType,
157 template<
class>
class Allocator,
163 const auto it = std::find(m_soa_rdata_names.begin(), m_soa_rdata_names.end(), name);
165 if (it == m_soa_rdata_names.end())
167 throw std::runtime_error(
"GetRealCompIndex: Component " + name +
" does not exist!");
171 return std::distance(m_soa_rdata_names.begin(), it);
176 typename ParticleType,
179 template<
class>
class Allocator,
185 const auto it = std::find(m_soa_idata_names.begin(), m_soa_idata_names.end(), name);
187 if (it == m_soa_idata_names.end())
189 throw std::runtime_error(
"GetIntCompIndex: Component " + name +
" does not exist!");
193 return std::distance(m_soa_idata_names.begin(), it);
197template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
198 template<
class>
class Allocator,
class CellAssignor>
199template <
typename P,
typename Assignor>
204 const auto& domain = geom.
Domain();
208 return Assignor{}(p, plo, dxi, domain);
211template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
212 template<
class>
class Allocator,
class CellAssignor>
221 int local_grid)
const
227 lev_max = finestLevel();
232 AMREX_ASSERT(nGrow == 0 || (nGrow >= 0 && lev_min == lev_max));
234 std::vector< std::pair<int, Box> > isects;
236 for (
int lev = lev_max; lev >= lev_min; lev--) {
237 const IntVect& iv = Index(p, lev);
238 if (lev == pld.
m_lev) {
252 const BoxArray& ba = ParticleBoxArray(lev);
255 if (local_grid < 0) {
256 bool findfirst = (nGrow == 0) ?
true :
false;
258 grid = isects.empty() ? -1 : isects[0].first;
259 if (nGrow > 0 && isects.size() > 1) {
260 for (
auto & isect : isects) {
262 for (
int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
274 grid = (*redistribute_mask_ptr)[local_grid](iv, 0);
292template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
293 template<
class>
class Allocator,
class CellAssignor>
301 int local_grid)
const
306 if (!Geom(0).isAnyPeriodic()) {
return false; }
309 lev_max = finestLevel();
317 p_prime.
pos(1) = p.pos(1);,
318 p_prime.
pos(2) = p.pos(2));
319 if (PeriodicShift(p_prime)) {
320 std::vector< std::pair<int,Box> > isects;
321 for (
int lev = lev_max; lev >= lev_min; lev--) {
325 const BoxArray& ba = ParticleBoxArray(lev);
328 if (local_grid < 0) {
331 grid = isects.empty() ? -1 : isects[0].first;
334 if (ba[local_grid].contains(iv))
341 grid = isects.empty() ? -1 : isects[0].first;
344 grid = (*redistribute_mask_ptr)[local_grid](Index(p, lev), 0);
351 p.pos(1) = p_prime.
pos(1);,
352 p.pos(2) = p_prime.
pos(2););
371template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
372 template<
class>
class Allocator,
class CellAssignor>
378 const auto& geom = Geom(0);
379 const auto plo = geom.ProbLoArray();
380 const auto phi = geom.ProbHiArray();
381 const auto rlo = geom.ProbLoArrayInParticleReal();
382 const auto rhi = geom.ProbHiArrayInParticleReal();
383 const auto is_per = geom.isPeriodicArray();
388template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
389 template<
class>
class Allocator,
class CellAssignor>
399 bool ok = Where(p, pld);
401 if (!ok && Geom(0).isAnyPeriodic())
412 amrex::AllPrint()<<
"Invalidating out-of-domain particle: " << p <<
'\n';
417 p.id().make_invalid();
423template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
424 template<
class>
class Allocator,
class CellAssignor>
429 m_particles.reserve(maxLevel()+1);
432template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
433 template<
class>
class Allocator,
class CellAssignor>
438 int nlevs = std::max(0, finestLevel()+1);
439 m_particles.resize(nlevs);
442template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
443 template<
class>
class Allocator,
class CellAssignor>
447 int lev_min,
int lev_max,
int nGrow,
int local_grid)
const
450 if (Geom(0).outsideRoundoffDomain(
AMREX_D_DECL(p.pos(0), p.pos(1), p.pos(2))))
453 success = EnforcePeriodicWhere(p, pld, lev_min, lev_max, local_grid);
454 if (!success && lev_min == 0)
457 p.id().make_invalid();
463 success = Where(p, pld, lev_min, lev_max, 0, local_grid);
468 success = (nGrow > 0) && Where(p, pld, lev_min, lev_min, nGrow);
474 amrex::Abort(
"ParticleContainer::locateParticle(): invalid particle.");
478template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
479 template<
class>
class Allocator,
class CellAssignor>
484 for (
int lev = 0; lev <= finestLevel(); lev++) {
485 nparticles += NumberOfParticlesAtLevel(lev,only_valid,
true);
493template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
494 template<
class>
class Allocator,
class CellAssignor>
498 AMREX_ASSERT(lev >= 0 && lev <
int(m_particles.size()));
501 ParticleDistributionMap(lev));
505 int gid = pti.index();
508 const auto& ptile = ParticlesAt(lev, pti);
509 const int np = ptile.numParticles();
510 auto const ptd = ptile.getConstParticleTileData();
514 using ReduceTuple =
typename decltype(reduce_data)::Type;
516 reduce_op.
eval(np, reduce_data,
519 return (ptd.id(i).is_valid()) ? 1 : 0;
522 int np_valid = amrex::get<0>(reduce_data.value(reduce_op));
523 np_per_grid_local[gid] += np_valid;
526 np_per_grid_local[gid] += pti.numParticles();
535 nparticles[pti.index()] = np_per_grid_local[pti.index()];
549template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
555 if (level < 0 || level >=
int(m_particles.size())) {
return nparticles; }
560 using ReduceTuple =
typename decltype(reduce_data)::Type;
562 for (
const auto& kv : GetParticles(level)) {
563 const auto& ptile = kv.second;
564 auto const ptd = ptile.getConstParticleTileData();
566 reduce_op.
eval(ptile.numParticles(), reduce_data,
569 return (ptd.id(i).is_valid()) ? 1 : 0;
573 nparticles =
static_cast<Long>(amrex::get<0>(reduce_data.value(reduce_op)));
576 for (
const auto& kv : GetParticles(level)) {
577 const auto& ptile = kv.second;
578 nparticles += ptile.numParticles();
589template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
591template <
typename I, std::enable_if_t<std::is_
integral_v<I> && (sizeof(I) >= sizeof(Long)),
int> FOO>
595 AMREX_ASSERT(lev >= 0 && lev <
int(m_particles.size()));
601 for (ParConstIterType pti(*
this, lev); pti.isValid(); ++pti)
603 int gid = pti.index();
604 mem[gid] +=
static_cast<I
>(pti.capacity());
612template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
613 template<
class>
class Allocator,
class CellAssignor>
620 for (
unsigned lev = 0; lev < m_particles.size(); lev++) {
621 const auto& pmap = m_particles[lev];
622 for (
const auto& kv : pmap) {
623 const auto& ptile = kv.second;
624 cnt += ptile.numParticles();
628 Long mn = cnt, mx = mn;
640 amrex::Print() <<
"ParticleContainer spread across MPI nodes - bytes (num particles): [Min: "
648 <<
" (" << cnt <<
")]\n";
653 return {mn*sz, mx*sz, cnt*sz};
656template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
664 for (
unsigned lev = 0; lev < m_particles.size(); lev++) {
665 const auto& pmap = m_particles[lev];
666 for (
const auto& kv : pmap) {
667 const auto& ptile = kv.second;
668 cnt += ptile.capacity();
672 Long mn = cnt, mx = mn;
683 amrex::Print() <<
"ParticleContainer spread across MPI nodes - bytes: [Min: "
694 return {mn, mx, cnt};
697template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
698 template<
class>
class Allocator,
class CellAssignor>
702 for (
unsigned lev = 0; lev < m_particles.size(); lev++) {
703 auto& pmap = m_particles[lev];
704 for (
auto& kv : pmap) {
705 auto& ptile = kv.second;
706 ptile.shrink_to_fit();
717template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
718 template<
class>
class Allocator,
class CellAssignor>
725 if (m_particles.empty()) {
return; }
726 AMREX_ASSERT(lev >= 0 && lev <
int(m_particles.size()));
729 const auto& geom = Geom(lev);
730 const auto plo = geom.ProbLoArray();
731 const auto dxi = geom.InvCellSizeArray();
732 const auto domain = geom.Domain();
734 [=]
AMREX_GPU_DEVICE (
const typename ParticleTileType::ConstParticleTileDataType& ptd,
int ip,
737 const auto p = ptd[ip];
738 CellAssignor assignor;
739 IntVect iv = assignor(p, plo, dxi, domain);
744template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
745 template<
class>
class Allocator,
class CellAssignor>
749 BL_PROFILE(
"ParticleContainer::IncrementWithTotal(lev)");
751 return TotalNumberOfParticles(
true, local);
754template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
755 template<
class>
class Allocator,
class CellAssignor>
759 BL_PROFILE(
"ParticleContainer::RemoveParticlesAtLevel()");
760 if (level >=
int(this->m_particles.size())) {
return; }
762 if (!this->m_particles[level].empty())
768template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
769 template<
class>
class Allocator,
class CellAssignor>
773 BL_PROFILE(
"ParticleContainer::RemoveParticlesNotAtFinestLevel()");
774 AMREX_ASSERT(this->finestLevel()+1 ==
int(this->m_particles.size()));
778 for (
unsigned lev = 0; lev < m_particles.size() - 1; ++lev) {
779 auto& pmap = m_particles[lev];
781 for (
auto& kv : pmap) {
782 const auto& pbx = kv.second;
783 cnt += pbx.numParticles();
792 if (this->m_verbose > 1 && cnt > 0) {
794 <<
" particles not in finest level\n";
810 template <
typename SrcData>
812 int operator() (
const SrcData& src,
int src_i)
const noexcept
821 template <
typename DstData,
typename SrcData>
824 int src_i,
int dst_i)
const noexcept
834template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
835 template<
class>
class Allocator,
class CellAssignor>
837ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
838::CreateVirtualParticles (
int level,
AoS& virts)
const
841 CreateVirtualParticles(level, ptile);
842 ptile.GetArrayOfStructs().swap(virts);
845template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
846 template<
class>
class Allocator,
class CellAssignor>
851 BL_PROFILE(
"ParticleContainer::CreateVirtualParticles()");
855 if (level >=
static_cast<int>(m_particles.size())) {
859 std::string
const& aggregation_type = AggregationType();
860 int aggregation_buffer = AggregationBuffer();
862 if (aggregation_type ==
"None")
864 auto virts_offset = virts.numParticles();
867 const auto& src_tile = ParticlesAt(level, pti);
869 auto np = src_tile.numParticles();
870 virts.resize(virts_offset+np);
875 if (aggregation_type ==
"Cell")
878 int nComp = AMREX_SPACEDIM + NStructReal + NArrayReal;
881 MultiFab mf(ParticleBoxArray(level), ParticleDistributionMap(level),
nComp, nGhost);
883 nComp = 1 + NStructInt + NArrayInt;
884 iMultiFab imf(ParticleBoxArray(level), ParticleDistributionMap(level),
nComp, nGhost);
886 const auto& geom = Geom(level);
887 const auto plo = geom.ProbLoArray();
888 const auto dxi = geom.InvCellSizeArray();
889 const auto domain = geom.Domain();
892 bl_buffer.
complementIn(Geom(level).Domain(), ParticleBoxArray(level));
893 BoxArray buffer(std::move(bl_buffer));
894 buffer.
grow(aggregation_buffer);
897 locator.
build(buffer, geom);
907 if(assign_buffer_grid(iv)==-1)
910 for (
int i = 0; i < NArrayReal; ++i)
915 for (
int i = 0; i < AMREX_SPACEDIM; ++i)
920 for (
int i = 1; i < NStructReal; ++i)
925 for (
int i = 0; i < 1; ++i)
941 if(assign_buffer_grid(iv)==-1)
944 if(partData(iv,0)==0)
948 for (
int i = 0; i < NStructInt; ++i)
952 for (
int i = 0; i < NArrayInt; ++i)
961 virts.resize(imf.
sum(0));
966 const auto bx = mfi.tilebox();
967 const auto partData = mf.
array(mfi);
968 const auto imf_arr = imf.
array(mfi);
971 auto *offsets_ptr = offsets.
dataPtr();
973 auto dst = virts.getParticleTileData();
976 if(imf_arr(i,j,k,0)!=0)
978 const auto idx = last_offset + offsets_ptr[
988 p.rdata(0) =
static_cast<ParticleReal>(partData(i,j,k,AMREX_SPACEDIM));;
990 for (
int n = 0; n < AMREX_SPACEDIM; ++n)
992 p.pos(n) =
static_cast<ParticleReal>(partData(i,j,k,n) / p.rdata(0));
995 for (
int n = 1; n < NStructReal; ++n)
997 p.rdata(n) =
static_cast<ParticleReal>(partData(i,j,k,AMREX_SPACEDIM+n) / p.rdata(0));
1000 for (
int n = 0; n < NArrayReal; ++n)
1002 dst.rdata(n)[idx] =
static_cast<ParticleReal>(partData(i,j,k,AMREX_SPACEDIM+NStructReal+n));
1005 for (
int n = 0; n < NStructInt; ++n)
1007 p.idata(n) = imf_arr(i,j,k,1+n);
1010 for (
int n = 0; n < NArrayInt; ++n)
1012 dst.idata(n)[idx] = imf_arr(i,j,k,1+NStructInt+n);
1017 last_offset+=next_offset;
1022 auto virts_offset = last_offset;
1025 const auto& src_tile = ParticlesAt(level, pti);
1027 auto np = src_tile.numParticles();
1028 virts.resize(virts_offset+np);
1032 virts.resize(virts_offset);
1051 template <
typename SrcData>
1057 const auto p_boxes = amrex::get<0>(tup_min);
1058 const auto p_boxes_max = amrex::get<0>(tup_max);
1059 const auto p_levs_max = amrex::get<1>(tup_max);
1060 return p_boxes_max >=0 && p_boxes ==
m_gid && p_levs_max ==
m_lev_max;
1067 template <
typename DstData,
typename SrcData>
1070 int src_i,
int dst_i)
const noexcept
1079template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1080 template<
class>
class Allocator,
class CellAssignor>
1082ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1083::CreateGhostParticles (
int level,
int nGrow,
AoS& ghosts)
const
1086 CreateGhostParticles(level, nGrow, ptile);
1087 ptile.GetArrayOfStructs().swap(ghosts);
1090template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1091 template<
class>
class Allocator,
class CellAssignor>
1096 BL_PROFILE(
"ParticleContainer::CreateGhostParticles()");
1100 if (level >=
static_cast<int>(m_particles.size())) {
1104 if (! m_particle_locator.isValid(GetParGDB())) {
1105 m_particle_locator.build(GetParGDB());
1108 m_particle_locator.setGeometry(GetParGDB());
1110 auto ghost_offset = ghosts.numParticles();
1113 const auto& src_tile = ParticlesAt(level, pti);
1114 int gid = pti.index();
1116 auto np = src_tile.numParticles();
1117 ghosts.resize(ghost_offset+np);
1120 ghosts.resize(ghost_offset);
1124template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1125 template<
class>
class Allocator,
class CellAssignor>
1130 BL_PROFILE(
"ParticleContainer::clearParticles()");
1132 for (
int lev = 0; lev < static_cast<int>(m_particles.size()); ++lev)
1134 for (
auto& kv : m_particles[lev]) { kv.second.resize(0); }
1135 particle_detail::clearEmptyEntries(m_particles[lev]);
1139template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1140 template<
class>
class Allocator,
class CellAssignor>
1141template <class PCType, std::enable_if_t<IsParticleContainer<PCType>::value,
int> foo>
1146 using PData =
typename ParticleTileType::ConstParticleTileDataType;
1150template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1151 template<
class>
class Allocator,
class CellAssignor>
1152template <class PCType, std::enable_if_t<IsParticleContainer<PCType>::value,
int> foo>
1157 using PData =
typename ParticleTileType::ConstParticleTileDataType;
1161template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1162 template<
class>
class Allocator,
class CellAssignor>
1163template <
class F,
class PCType,
1164 std::enable_if_t<IsParticleContainer<PCType>::value,
int> foo,
1165 std::enable_if_t<! std::is_integral_v<F>,
int> bar>
1170 BL_PROFILE(
"ParticleContainer::copyParticles");
1172 addParticles(other, std::forward<F>(f), local);
1175template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1176 template<
class>
class Allocator,
class CellAssignor>
1177template <
class F,
class PCType,
1178 std::enable_if_t<IsParticleContainer<PCType>::value,
int> foo,
1179 std::enable_if_t<! std::is_integral_v<F>,
int> bar>
1184 BL_PROFILE(
"ParticleContainer::addParticles");
1187 for (
int lev = 0; lev < other.numLevels(); ++lev)
1190 const auto& plevel_other = other.GetParticles(lev);
1191 for(
MFIter mfi = other.MakeMFIter(lev); mfi.isValid(); ++mfi)
1193 auto index = std::make_pair(mfi.index(), mfi.LocalTileIndex());
1194 if(plevel_other.find(index) == plevel_other.end()) {
continue; }
1196 DefineAndReturnParticleTile(lev, mfi.index(), mfi.LocalTileIndex());
1201#pragma omp parallel if (Gpu::notInLaunchRegion())
1203 for (
int lev = 0; lev < other.numLevels(); ++lev)
1205 const auto& plevel_other = other.GetParticles(lev);
1206 for(
MFIter mfi = other.MakeMFIter(lev); mfi.isValid(); ++mfi)
1208 auto index = std::make_pair(mfi.index(), mfi.LocalTileIndex());
1209 if(plevel_other.find(index) == plevel_other.end()) {
continue; }
1212 auto& ptile = ParticlesAt(lev, mfi.index(), mfi.LocalTileIndex());
1213 const auto& ptile_other = plevel_other.at(index);
1214 auto np = ptile_other.numParticles();
1215 if (np == 0) {
continue; }
1217 auto dst_index = ptile.numParticles();
1218 ptile.resize(dst_index + np);
1221 static_cast<decltype(np)
>(0), dst_index, np);
1223 ptile.resize(dst_index + count);
1227 if (! local) { Redistribute(); }
1233template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1234 template<
class>
class Allocator,
class CellAssignor>
1242 !is_rtsoa_pc || NumRuntimeRealComps() >= AMREX_SPACEDIM,
1243 "ParticleContainer with RTSoA requires at least AMREX_SPACEDIM "
1244 "runtime real components for positions"
1250 RedistributeGPU(lev_min, lev_max, nGrow, local, remove_negative);
1254 RedistributeCPU(lev_min, lev_max, nGrow, local, remove_negative);
1257 RedistributeCPU(lev_min, lev_max, nGrow, local, remove_negative);
1263template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1264 template<
class>
class Allocator,
class CellAssignor>
1265template <
class index_type>
1270 auto& ptile = ParticlesAt(lev, mfi);
1271 const size_t np = ptile.numParticles();
1272 const size_t np_total = np + ptile.numNeighborParticles();
1274 if (memEfficientSort) {
1278 ptile_tmp.define(m_num_runtime_real, m_num_runtime_int,
1279 &m_soa_rdata_names, &m_soa_idata_names, arena());
1280 ptile_tmp.resize(np_total);
1285 ptile.swap(ptile_tmp);
1297template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1298 template<
class>
class Allocator,
class CellAssignor>
1303 BL_PROFILE(
"ParticleContainer::SortParticlesByBin()");
1307 for (
int lev = 0; lev < numLevels(); ++lev)
1312 const auto domain = geom.
Domain();
1316 auto& ptile = ParticlesAt(lev, mfi);
1317 const size_t np = ptile.numParticles();
1323 m_bins.build(np, ptile.getParticleTileData(), ntiles,
1330template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1331 template<
class>
class Allocator,
class CellAssignor>
1336 BL_PROFILE(
"ParticleContainer::SortParticlesForDeposition()");
1338 for (
int lev = 0; lev < numLevels(); ++lev)
1344 const auto& ptile = ParticlesAt(lev, mfi);
1345 const size_t np = ptile.numParticles();
1349 using index_type =
typename decltype(m_bins)::index_type;
1351 PermutationForDeposition<index_type>(perm, np, ptile, box, geom, idx_type);
1360template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1361 template<
class>
class Allocator,
class CellAssignor>
1373 BL_PROFILE(
"ParticleContainer::RedistributeGPU()");
1376 int theEffectiveFinestLevel = m_gdb->finestLevel();
1377 while (!m_gdb->LevelDefined(theEffectiveFinestLevel)) { theEffectiveFinestLevel--; }
1379 if (
int(m_particles.size()) < theEffectiveFinestLevel+1) {
1381 amrex::Print() <<
"ParticleContainer::Redistribute() resizing containers from "
1382 << m_particles.size() <<
" to "
1383 << theEffectiveFinestLevel + 1 <<
'\n';
1385 m_particles.resize(theEffectiveFinestLevel+1);
1386 m_dummy_mf.resize(theEffectiveFinestLevel+1);
1389 for (
int lev = 0; lev < theEffectiveFinestLevel+1; ++lev) { RedefineDummyMF(lev); }
1391 int finest_lev_particles;
1392 if (lev_max == -1) {
1393 lev_max = theEffectiveFinestLevel;
1394 finest_lev_particles = m_particles.size() - 1;
1396 finest_lev_particles = lev_max;
1400 this->defineBufferMap();
1402 if (! m_particle_locator.isValid(GetParGDB())) { m_particle_locator.build(GetParGDB()); }
1403 m_particle_locator.setGeometry(GetParGDB());
1404 auto assign_grid = m_particle_locator.getGridAssignor();
1408 int num_levels = finest_lev_particles + 1;
1409 op.setNumLevels(num_levels);
1410 Vector<std::map<int, int> > new_sizes(num_levels);
1411 const auto plo = Geom(0).ProbLoArray();
1412 const auto phi = Geom(0).ProbHiArray();
1413 const auto rlo = Geom(0).ProbLoArrayInParticleReal();
1414 const auto rhi = Geom(0).ProbHiArrayInParticleReal();
1415 const auto is_per = Geom(0).isPeriodicArray();
1416 for (
int lev = lev_min; lev <= finest_lev_particles; ++lev)
1418 auto& plev = m_particles[lev];
1419 for (
auto& kv : plev)
1421 int gid = kv.first.first;
1422 int tid = kv.first.second;
1423 auto index = std::make_pair(gid, tid);
1425 auto& src_tile = plev[index];
1426 const size_t np = src_tile.numParticles();
1429 std::forward<CellAssignor>(CellAssignor{}),
1431 plo, phi, rlo, rhi, is_per, lev, gid, tid,
1432 lev_min, lev_max, nGrow, remove_negative);
1434 int num_move = np - num_stay;
1435 new_sizes[lev][gid] = num_stay;
1436 op.resize(gid, lev, num_move);
1438 auto p_boxes = op.m_boxes[lev][gid].dataPtr();
1439 auto p_levs = op.m_levels[lev][gid].dataPtr();
1440 auto p_src_indices = op.m_src_indices[lev][gid].dataPtr();
1441 auto p_periodic_shift = op.m_periodic_shift[lev][gid].dataPtr();
1442 auto ptd = src_tile.getParticleTileData();
1446 const auto p = ptd[i + num_stay];
1448 if (!p.id().is_valid())
1455 const auto tup = assign_grid(p, lev_min, lev_max, nGrow,
1456 std::forward<CellAssignor>(CellAssignor{}));
1457 p_boxes[i] = amrex::get<0>(tup);
1458 p_levs[i] = amrex::get<1>(tup);
1461 p_src_indices[i] = i+num_stay;
1467 ParticleCopyPlan plan;
1469 plan.build(*
this, op, h_redistribute_int_comp,
1470 h_redistribute_real_comp, local);
1476 if (use_comms_arena) {
1484 for (
int lev = lev_min; lev <= lev_max; ++lev)
1486 auto& plev = m_particles[lev];
1487 for (
auto& kv : plev)
1489 int gid = kv.first.first;
1490 int tid = kv.first.second;
1491 auto index = std::make_pair(gid, tid);
1492 auto& tile = plev[index];
1493 tile.resize(new_sizes[lev][gid]);
1497 for (
int lev = lev_min; lev <= lev_max; lev++)
1499 particle_detail::clearEmptyEntries(m_particles[lev]);
1502 if (
int(m_particles.size()) > theEffectiveFinestLevel+1) {
1503 if (m_verbose > 0) {
1504 amrex::Print() <<
"ParticleContainer::Redistribute() resizing m_particles from "
1505 << m_particles.size() <<
" to " << theEffectiveFinestLevel+1 <<
'\n';
1509 m_particles.resize(theEffectiveFinestLevel + 1);
1510 m_dummy_mf.resize(theEffectiveFinestLevel + 1);
1515 plan.buildMPIFinish(BufferMap());
1517 this->ReserveForRedistribute(plan);
1528 if (snd_buffer.arena()->isPinned()) {
1529 plan.buildMPIFinish(BufferMap());
1535 plan.buildMPIFinish(BufferMap());
1540 this->ReserveForRedistribute(plan);
1556template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1557 template<
class>
class Allocator,
class CellAssignor>
1559ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1562 BL_PROFILE(
"ParticleContainer::ReserveForRedistribute()");
1564 std::map<ParticleTileType*, int> addsizes;
1566 for (
int lev = 0; lev < this->BufferMap().numLevels(); ++lev) {
1567 for (
MFIter mfi = this->MakeMFIter(lev); mfi.
isValid(); ++mfi) {
1568 int gid = mfi.
index();
1570 auto& tile = this->DefineAndReturnParticleTile(lev, gid, tid);
1571 int num_copies = plan.
m_box_counts_h[this->BufferMap().gridAndLevToBucket(gid, lev)];
1572 if (num_copies > 0) {
1573 addsizes[&tile] += num_copies;
1585 auto& tile = this->DefineAndReturnParticleTile(lev, gid, tid);
1586 addsizes[&tile] += copy_size;
1590 ParticleTileType::reserve(addsizes);
1596template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1597 template<
class>
class Allocator,
class CellAssignor>
1602 BL_PROFILE(
"ParticleContainer::RedistributeCPU()");
1604 const int MyProc = ParallelContext::MyProcSub();
1607 if (local > 0) { BuildRedistributeMask(0, local); }
1611 int theEffectiveFinestLevel = m_gdb->finestLevel();
1613 while (!m_gdb->LevelDefined(theEffectiveFinestLevel)) {
1614 theEffectiveFinestLevel--;
1617 if (
int(m_particles.size()) < theEffectiveFinestLevel+1) {
1619 amrex::Print() <<
"ParticleContainer::Redistribute() resizing containers from "
1620 << m_particles.size() <<
" to "
1621 << theEffectiveFinestLevel + 1 <<
'\n';
1623 m_particles.resize(theEffectiveFinestLevel+1);
1624 m_dummy_mf.resize(theEffectiveFinestLevel+1);
1629 for (
int lev = 0; lev < theEffectiveFinestLevel+1; ++lev) {
1630 RedefineDummyMF(lev);
1633 int finest_lev_particles;
1634 if (lev_max == -1) {
1635 lev_max = theEffectiveFinestLevel;
1636 finest_lev_particles = m_particles.size() - 1;
1638 finest_lev_particles = lev_max;
1643 std::map<int, Vector<char> > not_ours;
1645 int num_threads = OpenMP::get_max_threads();
1648 std::map<int, Vector<Vector<char> > > tmp_remote;
1650 ptile_local.resize(theEffectiveFinestLevel+1);
1653 for (
int lev = lev_min; lev <= lev_max; lev++) {
1654 for (
MFIter mfi(*m_dummy_mf[lev], this->do_tiling ? this->tile_size : IntVect::TheZeroVector());
1657 ptile_local[lev][index].resize(num_threads);
1658 for (
int t = 0; t < num_threads; ++t) {
1659 ptile_local[lev][index][t].define(m_num_runtime_real, m_num_runtime_int,
1660 &m_soa_rdata_names, &m_soa_idata_names, arena());
1665 for (
int i = 0; i < neighbor_procs.size(); ++i) {
1666 tmp_remote[neighbor_procs[i]].resize(num_threads);
1669 for (
int i = 0; i < ParallelContext::NProcsSub(); ++i) {
1670 tmp_remote[i].resize(num_threads);
1676 for (
int lev = lev_min; lev <= finest_lev_particles; lev++) {
1677 auto& pmap = m_particles[lev];
1681 for (
auto& kv : pmap)
1683 grid_tile_ids.push_back(kv.first);
1684 ptile_ptrs.push_back(&(kv.second));
1688#pragma omp parallel for
1690 for (
int pmap_it = 0; pmap_it < static_cast<int>(ptile_ptrs.
size()); ++pmap_it)
1692 int thread_num = OpenMP::get_thread_num();
1693 int grid = grid_tile_ids[pmap_it].first;
1694 int tile = grid_tile_ids[pmap_it].second;
1696 unsigned npart = ptile_ptrs[pmap_it]->numParticles();
1699 auto particle_tile = ptile_ptrs[pmap_it];
1700 auto ptd = particle_tile->getParticleTileData();
1703 Long last = npart - 1;
1705 while (pindex <= last) {
1706 decltype(
auto) p = ptd[pindex];
1708 if ((remove_negative ==
false) && (!ptd.id(pindex).is_valid())) {
1713 if (!ptd.id(pindex).is_valid()) {
1715 correctCellVectors(last, pindex, grid, p);
1720 locateParticle(p, pld, lev_min, lev_max, nGrow, local ? grid : -1);
1722 particlePostLocate(p, pld, lev);
1724 if (!ptd.id(pindex).is_valid()) {
1726 correctCellVectors(last, pindex, grid, p);
1731 const int who = ParallelContext::global_to_local_rank(ParticleDistributionMap(pld.
m_lev)[pld.
m_grid]);
1732 if (who == MyProc) {
1738 auto& dst = ptile_local[pld.
m_lev][index][thread_num];
1739 auto old_size = dst.
size();
1740 auto new_size = old_size + 1;
1741 dst.resize(new_size, GrowthStrategy::Geometric);
1742 auto dst_ptd = dst.getParticleTileData();
1746 ptd.id(pindex).make_invalid();
1749 auto& particles_to_send = tmp_remote[who][thread_num];
1750 auto old_size = particles_to_send.size();
1751 auto new_size = old_size + superparticle_size;
1752 particles_to_send.resize(new_size);
1754 ptd.packParticleData(particles_to_send.data(), pindex, old_size,
1755 h_redistribute_real_comp.data(), h_redistribute_int_comp.data());
1757 ptd.id(pindex).make_invalid();
1760 if (!ptd.id(pindex).is_valid()) {
1762 correctCellVectors(last, pindex, grid, p);
1770 Long tot_npart = particle_tile->numTotalParticles();
1772 if (last != npart - 1) {
1775 while (last < tot_npart) {
1780 particle_tile->resize(pindex);
1786 for (
int lev = lev_min; lev <= lev_max; lev++) {
1787 particle_detail::clearEmptyEntries(m_particles[lev]);
1791 for (
int lev = lev_min; lev <= lev_max; lev++) {
1796 for (
auto pmap_it = ptile_local[lev].
begin(); pmap_it != ptile_local[lev].end(); pmap_it++)
1798 DefineAndReturnParticleTile(lev, pmap_it->first.first, pmap_it->first.second);
1799 grid_tile_ids.push_back(pmap_it->first);
1803#pragma omp parallel for
1805 for (
int pit = 0; pit < static_cast<int>(grid_tile_ids.
size()); ++pit)
1807 auto index = grid_tile_ids[pit];
1808 auto& dst_ptile = ParticlesAt(lev, index.first, index.second);
1809 auto& src_ptile = ptile_local[lev][index];
1811 for (
int i = 0; i < num_threads; ++i) {
1813 Long to_copy = src_ptile[i].numParticles();
1814 Long old_size = dst_ptile.numTotalParticles();
1815 Long new_size = old_size + to_copy;
1816 dst_ptile.resize(new_size);
1818 auto dst_ptd = dst_ptile.getParticleTileData();
1819 auto src_ptd = src_ptile[i].getParticleTileData();
1821 for (
Long j = 0; j < to_copy; ++j) {
1825 src_ptile[i].resize(0);
1826 src_ptile[i].shrink_to_fit();
1831 for (
auto& map_it : tmp_remote) {
1832 int who = map_it.first;
1838 for (
auto& kv : tmp_remote)
1840 dest_proc_ids.push_back(kv.first);
1841 pbuff_ptrs.push_back(&(kv.second));
1845#pragma omp parallel for
1847 for (
int pmap_it = 0; pmap_it < static_cast<int>(pbuff_ptrs.
size()); ++pmap_it)
1849 int who = dest_proc_ids[pmap_it];
1851 for (
int i = 0; i < num_threads; ++i) {
1852 not_ours[who].insert(not_ours[who].
end(), tmp[i].begin(), tmp[i].end());
1853 tmp[i].erase(tmp[i].
begin(), tmp[i].end());
1857 particle_detail::clearEmptyEntries(not_ours);
1859 if (
int(m_particles.size()) > theEffectiveFinestLevel+1) {
1861 if (m_verbose > 0) {
1862 amrex::Print() <<
"ParticleContainer::Redistribute() resizing m_particles from "
1863 << m_particles.size() <<
" to " << theEffectiveFinestLevel+1 <<
'\n';
1867 m_particles.resize(theEffectiveFinestLevel + 1);
1868 m_dummy_mf.resize(theEffectiveFinestLevel + 1);
1871 if (ParallelContext::NProcsSub() == 1) {
1875 RedistributeMPI(not_ours, lev_min, lev_max, nGrow, local);
1880 if (m_verbose > 0) {
1886 Lazy::QueueReduction( [=] ()
mutable {
1888 ParallelReduce::Max(stoptime, ParallelContext::IOProcessorNumberSub(),
1889 ParallelContext::CommunicatorSub());
1891 amrex::Print() <<
"ParticleContainer::Redistribute() time: " << stoptime <<
"\n\n";
1898template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1899 template<
class>
class Allocator,
class CellAssignor>
1903 int lev_min,
int lev_max,
int nGrow,
int local)
1905 BL_PROFILE(
"ParticleContainer::RedistributeMPI()");
1911 using buffer_type =
unsigned long long;
1913 std::map<int, Vector<buffer_type> > mpi_snd_data;
1914 for (
const auto& kv : not_ours)
1916 auto nbt = (kv.second.size() +
sizeof(buffer_type)-1)/
sizeof(buffer_type);
1917 mpi_snd_data[kv.first].resize(nbt);
1918 std::memcpy((
char*) mpi_snd_data[kv.first].data(), kv.second.data(), kv.second.size());
1921 const int NProcs = ParallelContext::NProcsSub();
1922 const int NNeighborProcs = neighbor_procs.size();
1925 Vector<Long> Snds(NProcs, 0), Rcvs(NProcs, 0);
1932 BuildRedistributeMask(0, local);
1933 NumSnds = doHandShakeLocal(not_ours, neighbor_procs, Snds, Rcvs);
1940 const int SeqNum = ParallelDescriptor::SeqNum();
1942 if ((! local) && NumSnds == 0) {
1948 Long tot_snds_this_proc = 0;
1949 Long tot_rcvs_this_proc = 0;
1950 for (
int i = 0; i < NNeighborProcs; ++i) {
1951 tot_snds_this_proc += Snds[neighbor_procs[i]];
1952 tot_rcvs_this_proc += Rcvs[neighbor_procs[i]];
1954 if ( (tot_snds_this_proc == 0) && (tot_rcvs_this_proc == 0) ) {
1959 Vector<int> RcvProc;
1960 Vector<std::size_t> rOffset;
1962 std::size_t TotRcvInts = 0;
1963 std::size_t TotRcvBytes = 0;
1964 for (
int i = 0; i <
NProcs; ++i) {
1966 RcvProc.push_back(i);
1967 rOffset.push_back(TotRcvInts);
1968 TotRcvBytes += Rcvs[i];
1969 auto nbt = (Rcvs[i] +
sizeof(buffer_type)-1)/
sizeof(buffer_type);
1974 const auto nrcvs =
static_cast<int>(RcvProc.size());
1975 Vector<MPI_Status> stats(nrcvs);
1976 Vector<MPI_Request> rreqs(nrcvs);
1979 Vector<unsigned long long> recvdata(TotRcvInts);
1982 for (
int i = 0; i < nrcvs; ++i) {
1983 const auto Who = RcvProc[i];
1984 const auto offset = rOffset[i];
1985 const auto Cnt = (Rcvs[Who] +
sizeof(buffer_type)-1)/
sizeof(buffer_type);
1987 AMREX_ASSERT(Cnt <
size_t(std::numeric_limits<int>::max()));
1990 rreqs[i] = ParallelDescriptor::Arecv(&recvdata[
offset], Cnt, Who, SeqNum,
1991 ParallelContext::CommunicatorSub()).req();
1995 for (
const auto& kv : mpi_snd_data) {
1996 const auto Who = kv.first;
1997 const auto Cnt = kv.second.size();
2003 ParallelDescriptor::Send(kv.second.data(), Cnt, Who, SeqNum,
2004 ParallelContext::CommunicatorSub());
2008 ParallelDescriptor::Waitall(rreqs, stats);
2012 int npart = TotRcvBytes / superparticle_size;
2014 Vector<int> rcv_levs(npart);
2015 Vector<int> rcv_grid(npart);
2016 Vector<int> rcv_tile(npart);
2019 ParticleLocData pld;
2020 for (
int j = 0; j < nrcvs; ++j)
2022 const auto offset = rOffset[j];
2023 const auto Who = RcvProc[j];
2024 const auto Cnt = Rcvs[Who] / superparticle_size;
2025 for (
int i = 0; i <
int(Cnt); ++i)
2027 char* pbuf = ((
char*) &recvdata[
offset]) + i*superparticle_size;
2029 Particle<NStructReal, NStructInt> p;
2031 if constexpr (ParticleType::is_soa_particle) {
2032 std::memcpy(&p.m_idcpu, pbuf,
sizeof(uint64_t));
2035 std::memcpy(&pos[0], pbuf +
sizeof(uint64_t), AMREX_SPACEDIM*
sizeof(ParticleReal));
2040 std::memcpy(&p, pbuf,
sizeof(ParticleType));
2043 bool success = Where(p, pld, lev_min, lev_max, 0);
2046 success = (nGrow > 0) && Where(p, pld, lev_min, lev_min, nGrow);
2047 pld.m_grown_gridbox = pld.m_gridbox;
2051 amrex::Abort(
"RedistributeMPI_locate:: invalid particle.");
2054 rcv_levs[ipart] = pld.m_lev;
2055 rcv_grid[ipart] = pld.m_grid;
2056 rcv_tile[ipart] = pld.m_tile;
2066#ifndef AMREX_USE_GPU
2068 for (
int i = 0; i < nrcvs; ++i)
2070 const auto offset = rOffset[i];
2071 const auto Who = RcvProc[i];
2072 const auto Cnt = Rcvs[Who] / superparticle_size;
2073 for (
int j = 0; j <
int(Cnt); ++j)
2075 auto& ptile = m_particles[rcv_levs[ipart]][std::make_pair(rcv_grid[ipart],
2077 auto old_size = ptile.numTotalParticles();
2078 auto new_size = old_size + 1;
2079 ptile.resize(new_size, GrowthStrategy::Geometric);
2081 char* pbuf = ((
char*) &recvdata[
offset]) + j*superparticle_size;
2083 if constexpr (ParticleType::is_soa_particle) {
2085 std::memcpy(&idcpudata, pbuf,
sizeof(uint64_t));
2086 pbuf +=
sizeof(uint64_t);
2087 ptile.GetStructOfArrays().GetIdCPUData()[old_size] = idcpudata;
2090 std::memcpy(&p, pbuf,
sizeof(ParticleType));
2091 pbuf +=
sizeof(ParticleType);
2092 ptile.GetArrayOfStructs()[old_size] = p;
2095 int array_comp_start = 0;
2096 if constexpr (!ParticleType::is_soa_particle) {
2097 array_comp_start = AMREX_SPACEDIM + NStructReal;
2099 for (
int comp = 0; comp < NumRealComps(); ++comp) {
2100 if (h_redistribute_real_comp[array_comp_start + comp]) {
2102 std::memcpy(&rdata, pbuf,
sizeof(ParticleReal));
2104 ptile.GetStructOfArrays().GetRealData(comp)[old_size] = rdata;
2106 ptile.GetStructOfArrays().GetRealData(comp)[old_size] = 0.0;
2110 array_comp_start = 2 + NStructInt;
2111 for (
int comp = 0; comp < NumIntComps(); ++comp) {
2112 if (h_redistribute_int_comp[array_comp_start + comp]) {
2114 std::memcpy(&idata, pbuf,
sizeof(
int));
2115 pbuf +=
sizeof(
int);
2116 ptile.GetStructOfArrays().GetIntData(comp)[old_size] = idata;
2118 ptile.GetStructOfArrays().GetIntData(comp)[old_size] = 0;
2126 Vector<std::map<std::pair<int, int>, Gpu::HostVector<ParticleType> > > host_particles;
2127 host_particles.reserve(15);
2128 host_particles.resize(finestLevel()+1);
2130 Vector<std::map<std::pair<int, int>,
2131 std::vector<Gpu::HostVector<ParticleReal> > > > host_real_attribs;
2132 host_real_attribs.reserve(15);
2133 host_real_attribs.resize(finestLevel()+1);
2135 Vector<std::map<std::pair<int, int>,
2136 std::vector<Gpu::HostVector<int> > > > host_int_attribs;
2137 host_int_attribs.reserve(15);
2138 host_int_attribs.resize(finestLevel()+1);
2140 Vector<std::map<std::pair<int, int>, Gpu::HostVector<uint64_t> > > host_idcpu;
2141 host_idcpu.reserve(15);
2142 host_idcpu.resize(finestLevel()+1);
2145 for (
int i = 0; i < nrcvs; ++i)
2147 const auto offset = rOffset[i];
2148 const auto Who = RcvProc[i];
2149 const auto Cnt = Rcvs[Who] / superparticle_size;
2150 for (
auto j =
decltype(Cnt)(0); j < Cnt; ++j)
2152 int lev = rcv_levs[ipart];
2153 std::pair<int, int> ind(std::make_pair(rcv_grid[ipart], rcv_tile[ipart]));
2155 char* pbuf = ((
char*) &recvdata[
offset]) + j*superparticle_size;
2157 host_real_attribs[lev][ind].resize(NumRealComps());
2158 host_int_attribs[lev][ind].resize(NumIntComps());
2160 if constexpr (ParticleType::is_soa_particle) {
2162 std::memcpy(&idcpudata, pbuf,
sizeof(uint64_t));
2163 pbuf +=
sizeof(uint64_t);
2164 host_idcpu[lev][ind].push_back(idcpudata);
2167 std::memcpy(&p, pbuf,
sizeof(ParticleType));
2168 pbuf +=
sizeof(ParticleType);
2169 host_particles[lev][ind].push_back(p);
2172 host_real_attribs[lev][ind].resize(NumRealComps());
2173 host_int_attribs[lev][ind].resize(NumIntComps());
2176 int array_comp_start = 0;
2177 if constexpr (!ParticleType::is_soa_particle) {
2178 array_comp_start = AMREX_SPACEDIM + NStructReal;
2180 for (
int comp = 0; comp < NumRealComps(); ++comp) {
2181 if (h_redistribute_real_comp[array_comp_start + comp]) {
2183 std::memcpy(&rdata, pbuf,
sizeof(ParticleReal));
2185 host_real_attribs[lev][ind][comp].push_back(rdata);
2187 host_real_attribs[lev][ind][comp].push_back(0.0);
2192 array_comp_start = 2 + NStructInt;
2193 for (
int comp = 0; comp < NumIntComps(); ++comp) {
2194 if (h_redistribute_int_comp[array_comp_start + comp]) {
2196 std::memcpy(&idata, pbuf,
sizeof(
int));
2197 pbuf +=
sizeof(
int);
2198 host_int_attribs[lev][ind][comp].push_back(idata);
2200 host_int_attribs[lev][ind][comp].push_back(0);
2207 for (
int host_lev = 0; host_lev < static_cast<int>(host_particles.size()); ++host_lev)
2209 for (
auto& kv : host_particles[host_lev]) {
2210 auto grid = kv.first.first;
2211 auto tile = kv.first.second;
2212 const auto& src_tile = kv.second;
2214 auto& dst_tile = GetParticles(host_lev)[std::make_pair(grid,tile)];
2215 auto old_size = dst_tile.size();
2216 auto new_size = old_size + src_tile.size();
2217 dst_tile.resize(new_size);
2219 if constexpr (ParticleType::is_soa_particle) {
2220 Gpu::copyAsync(Gpu::hostToDevice,
2221 host_idcpu[host_lev][std::make_pair(grid,tile)].
begin(),
2222 host_idcpu[host_lev][std::make_pair(grid,tile)].
end(),
2223 dst_tile.GetStructOfArrays().GetIdCPUData().begin() + old_size);
2225 Gpu::copyAsync(Gpu::hostToDevice,
2226 src_tile.begin(), src_tile.end(),
2227 dst_tile.GetArrayOfStructs().begin() + old_size);
2230 for (
int i = 0; i < NumRealComps(); ++i) {
2231 Gpu::copyAsync(Gpu::hostToDevice,
2232 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
2233 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
2234 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
2237 for (
int i = 0; i < NumIntComps(); ++i) {
2238 Gpu::copyAsync(Gpu::hostToDevice,
2239 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
2240 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
2241 dst_tile.GetStructOfArrays().GetIntData(i).begin() + old_size);
2246 Gpu::Device::streamSynchronize();
2256template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
2257 template<
class>
class Allocator,
class CellAssignor>
2263 if (lev_max == -1) {
2264 lev_max = finestLevel();
2270template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
2271 template<
class>
class Allocator,
class CellAssignor>
2277 ptile.GetArrayOfStructs().swap(particles);
2278 AddParticlesAtLevel(ptile, level, nGrow);
2281template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
2282 template<
class>
class Allocator,
class CellAssignor>
2287 BL_PROFILE(
"ParticleContainer::AddParticlesAtLevel()");
2289 if (
int(m_particles.size()) < level+1)
2293 amrex::Print() <<
"ParticleContainer::AddParticlesAtLevel resizing m_particles from "
2294 << m_particles.size()
2298 m_particles.resize(level+1);
2299 m_dummy_mf.resize(level+1);
2300 for (
int lev = 0; lev < level+1; ++lev) {
2301 RedefineDummyMF(lev);
2305 auto& ptile = DefineAndReturnParticleTile(level, 0, 0);
2306 int old_np = ptile.size();
2307 int num_to_add = particles.size();
2308 int new_np = old_np + num_to_add;
2309 ptile.resize(new_np);
2311 Redistribute(level, level, nGrow);
2312 particles.resize(0);
2316template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
2317 template<
class>
class Allocator,
class CellAssignor>
2324 int particle_lvl_offset)
const
2326 BL_PROFILE(
"ParticleContainer::AssignCellDensitySingleLevel()");
2328 if (rho_index != 0) {
amrex::Abort(
"AssignCellDensitySingleLevel only works if rho_index = 0"); }
2332 if (OnSameGrids(lev, mf_to_be_filled)) {
2335 mf_pointer = &mf_to_be_filled;
2340 mf_pointer =
new MultiFab(ParticleBoxArray(lev),
2341 ParticleDistributionMap(lev),
2342 ncomp, mf_to_be_filled.
nGrow());
2349 if (mf_pointer->
nGrow() < 1) {
2350 amrex::Error(
"Must have at least one ghost cell when in AssignCellDensitySingleLevel");
2355 const auto dxi = Geom(lev).InvCellSizeArray();
2356 const auto plo = Geom(lev).ProbLoArray();
2357 const auto pdxi = Geom(lev + particle_lvl_offset).InvCellSizeArray();
2359 if (Geom(lev).isAnyPeriodic() && ! Geom(lev).isAllPeriodic())
2361 amrex::Error(
"AssignCellDensitySingleLevel: problem must be periodic in no or all directions");
2368#pragma omp parallel if (Gpu::notInLaunchRegion())
2373 const Long np = pti.numParticles();
2374 auto ptd = pti.GetParticleTile().getConstParticleTileData();
2376 auto rhoarr = fab.
array();
2379 if (Gpu::notInLaunchRegion())
2381 tile_box = pti.tilebox();
2383 local_rho.
resize(tile_box,ncomp);
2384 local_rho.
setVal<RunOn::Host>(0.0);
2385 rhoarr = local_rho.
array();
2389 if (particle_lvl_offset == 0)
2394 amrex_deposit_cic(p, ncomp, rhoarr, plo, dxi);
2402 amrex_deposit_particle_dx_cic(p, ncomp, rhoarr, plo, dxi, pdxi);
2407 if (Gpu::notInLaunchRegion())
2409 fab.
atomicAdd<RunOn::Host>(local_rho, tile_box, tile_box, 0, 0, ncomp);
2420 for (
int n = 1; n < ncomp; n++)
2424 (*mf_pointer)[mfi].protected_divide<RunOn::Device>((*mf_pointer)[mfi],0,n,1);
2431 const Real* dx = Geom(lev).CellSize();
2438 if (mf_pointer != &mf_to_be_filled)
2440 mf_to_be_filled.
ParallelCopy(*mf_pointer,0,0,ncomp,0,0);
2448 ParallelReduce::Max(stoptime, ParallelContext::IOProcessorNumberSub(),
2449 ParallelContext::CommunicatorSub());
2451 amrex::Print() <<
"ParticleContainer::AssignCellDensitySingleLevel) time: "
2452 << stoptime <<
'\n';
2456template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
2457 template<
class>
class Allocator,
class CellAssignor>
2462 int old_size = m_num_runtime_real;
2464 m_runtime_comps_defined = (new_size > 0);
2465 m_num_runtime_real = new_size;
2466 int cur_size = h_redistribute_real_comp.size();
2467 h_redistribute_real_comp.resize(cur_size-old_size+new_size, communicate);
2470 for (
int lev = 0; lev < numLevels(); ++lev) {
2472 auto& tile = DefineAndReturnParticleTile(lev, pti);
2473 auto np = tile.numParticles();
2474 if (np > 0 && new_size > old_size) {
2475 auto& soa = tile.GetStructOfArrays();
2482template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
2483 template<
class>
class Allocator,
class CellAssignor>
2488 int old_size = m_num_runtime_int;
2490 m_runtime_comps_defined = (new_size > 0);
2491 m_num_runtime_int = new_size;
2492 int cur_size = h_redistribute_int_comp.size();
2493 h_redistribute_int_comp.resize(cur_size-old_size+new_size, communicate);
2496 for (
int lev = 0; lev < numLevels(); ++lev) {
2498 auto& tile = DefineAndReturnParticleTile(lev, pti);
2499 auto np = tile.numParticles();
2500 if (np > 0 && new_size > old_size) {
2501 auto& soa = tile.GetStructOfArrays();
#define BL_PROFILE_VAR_START(vname)
Definition AMReX_BLProfiler.H:562
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:551
#define BL_PROFILE_VAR_STOP(vname)
Definition AMReX_BLProfiler.H:563
#define BL_PROFILE_SYNC_STOP()
Definition AMReX_BLProfiler.H:645
#define BL_PROFILE_SYNC_START_TIMED(fname)
Definition AMReX_BLProfiler.H:644
#define BL_PROFILE_VAR_NS(fname, vname)
Definition AMReX_BLProfiler.H:561
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_ALWAYS_ASSERT(EX)
Definition AMReX_BLassert.H:50
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_FOR_1D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:97
#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:15
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1139
#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:2482
Array4< T const > array() const noexcept
Definition AMReX_BaseFab.H:382
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:1400
A collection of Boxes stored in an Array.
Definition AMReX_BoxArray.H:568
IndexType ixType() const noexcept
Return index type of this BoxArray.
Definition AMReX_BoxArray.H:858
BoxArray & grow(int n)
Grow each Box in the BoxArray by the specified amount.
Definition AMReX_BoxArray.cpp:706
std::vector< std::pair< int, Box > > intersections(const Box &bx) const
Return intersections of Box and BoxArray.
Definition AMReX_BoxArray.cpp:1186
Box getCellCenteredBox(int index) const noexcept
Return cell-centered box at element index of this BoxArray.
Definition AMReX_BoxArray.H:748
static bool SameRefs(const BoxArray &lhs, const BoxArray &rhs)
whether two BoxArrays share the same data
Definition AMReX_BoxArray.H:841
A class for managing a List of Boxes that share a common IndexType. This class implements operations ...
Definition AMReX_BoxList.H:52
BoxList & complementIn(const Box &b, const BoxList &bl)
Definition AMReX_BoxList.cpp:307
__host__ __device__ BoxND & grow(int i) noexcept
Definition AMReX_Box.H:641
__host__ __device__ bool contains(const IntVectND< dim > &p) const noexcept
Return true if argument is contained within BoxND.
Definition AMReX_Box.H:212
GpuArray< Real, 3 > InvCellSizeArray() const noexcept
Definition AMReX_CoordSys.H:87
A Fortran Array of REALs.
Definition AMReX_FArrayBox.H:231
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:110
int nGrow(int direction=0) const noexcept
Return the grow factor that defines the region of definition.
Definition AMReX_FabArrayBase.H:78
const DistributionMapping & DistributionMap() const noexcept
Return constant reference to associated DistributionMapping.
Definition AMReX_FabArrayBase.H:131
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:95
void ParallelCopy(const FabArray< FAB > &src, const Periodicity &period=Periodicity::NonPeriodic(), CpOp op=FabArrayBase::COPY)
Definition AMReX_FabArray.H:850
Array4< typename FabArray< FAB >::value_type const > array(const MFIter &mfi) const noexcept
Definition AMReX_FabArray.H:566
void setVal(value_type val)
Set all components in the entire region of each FAB to val.
Definition AMReX_FabArray.H:2657
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:74
const Box & Domain() const noexcept
Returns our rectangular domain.
Definition AMReX_Geometry.H:211
GpuArray< Real, 3 > ProbLoArray() const noexcept
Definition AMReX_Geometry.H:187
static void streamSynchronize() noexcept
Definition AMReX_GpuDevice.cpp:855
__host__ __device__ bool cellCentered() const noexcept
True if the IndexTypeND is CELL based in all directions.
Definition AMReX_IndexType.H:104
__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:679
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:85
int LocalTileIndex() const noexcept
The current local tile index in the current grid;.
Definition AMReX_MFIter.H:178
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:169
Box validbox() const noexcept
Return the valid Box in which the current tile resides.
Definition AMReX_MFIter.H:160
int index() const noexcept
The index into the underlying BoxArray of the current FAB.
Definition AMReX_MFIter.H:172
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:1417
Dynamically allocated vector for trivially copyable data.
Definition AMReX_PODVector.H:308
size_type size() const noexcept
Definition AMReX_PODVector.H:648
void resize(size_type a_new_size, GrowthStrategy strategy=GrowthStrategy::Poisson)
Definition AMReX_PODVector.H:728
T * dataPtr() noexcept
Definition AMReX_PODVector.H:670
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:1044
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:2032
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:1946
virtual void reserveData()
Definition AMReX_ParticleContainerBase.cpp:41
virtual void resizeData()
Definition AMReX_ParticleContainerBase.cpp:46
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition AMReX_ParticleContainer.H:149
void addParticles(const PCType &other, bool local=false)
Add particles from other to this ParticleContainer. local controls whether or not to call Redistribut...
Definition AMReX_ParticleContainerI.H:1155
IntVect Index(const P &p, int lev) const
Definition AMReX_ParticleContainerI.H:201
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:109
typename ParticleTileType::AoS AoS
Definition AMReX_ParticleContainer.H:199
void SetParticleSize()
Definition AMReX_ParticleContainerI.H:16
void RemoveParticlesAtLevel(int level)
The Following methods are for managing Virtual and Ghost Particles.
Definition AMReX_ParticleContainerI.H:757
void clearParticles()
Clear all the particles in this container. This does not free memory.
Definition AMReX_ParticleContainerI.H:1128
void Increment(MultiFab &mf, int level)
Definition AMReX_ParticleContainerI.H:720
bool HasIntComp(std::string const &name)
Definition AMReX_ParticleContainerI.H:148
void ShrinkToFit()
Definition AMReX_ParticleContainerI.H:700
bool HasRealComp(std::string const &name)
Definition AMReX_ParticleContainerI.H:140
void resizeData() override
This resizes the vector of dummy MultiFabs used by the ParticleContainer for the current number of le...
Definition AMReX_ParticleContainerI.H:435
Long IncrementWithTotal(MultiFab &mf, int level, bool local=false)
Definition AMReX_ParticleContainerI.H:747
Long NumberOfParticlesAtLevel(int level, bool only_valid=true, bool only_local=false) const
Returns # of particles at specified the level.
Definition AMReX_ParticleContainerI.H:551
void SortParticlesByCell()
Sort the particles on each tile by cell, using Fortran ordering.
Definition AMReX_ParticleContainerI.H:1292
int GetRealCompIndex(std::string const &name)
Definition AMReX_ParticleContainerI.H:161
int GetIntCompIndex(std::string const &name)
Definition AMReX_ParticleContainerI.H:183
void RemoveParticlesNotAtFinestLevel()
Definition AMReX_ParticleContainerI.H:771
Vector< Long > NumberOfParticlesInGrid(int level, bool only_valid=true, bool only_local=false) const
Definition AMReX_ParticleContainerI.H:496
void copyParticles(const PCType &other, bool local=false)
Copy particles from other to this ParticleContainer. Will clear all the particles from this container...
Definition AMReX_ParticleContainerI.H:1144
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:392
void CapacityOfParticlesInGrid(LayoutData< I > &mem, int lev) const
Return capacity of memory for particles at specific grid.
Definition AMReX_ParticleContainerI.H:593
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:481
void reserveData() override
This reserves data in the vector of dummy MultiFabs used by the ParticleContainer for the maximum num...
Definition AMReX_ParticleContainerI.H:426
T_ParticleType ParticleType
Definition AMReX_ParticleContainer.H:151
Definition AMReX_ParticleLocator.H:104
AssignGrid< BinIteratorFactory > getGridAssignor() const noexcept
Definition AMReX_ParticleLocator.H:183
void build(const BoxArray &ba, const Geometry &geom)
Definition AMReX_ParticleLocator.H:111
This class provides the user with a few print options.
Definition AMReX_Print.H:35
Definition AMReX_Reduce.H:453
Definition AMReX_Reduce.H:612
std::enable_if_t< IsFabArray< MF >::value > eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition AMReX_Reduce.H:746
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
Long size() const noexcept
Definition AMReX_Vector.H:53
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:79
amrex_particle_real ParticleReal
Floating Point Type for Particles.
Definition AMReX_REAL.H:90
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:1290
void SumBoundary(const Periodicity &period=Periodicity::NonPeriodic(), bool deterministic=false)
Sum values in overlapped cells.
Definition AMReX_FabArray.H:3588
__host__ __device__ BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Grow BoxND in all directions by given amount.
Definition AMReX_Box.H:1280
Arena * The_Comms_Arena()
Definition AMReX_Arena.cpp:865
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 Sum(T &v, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:221
void Sum(T &v, int root, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:352
__host__ __device__ AMREX_FORCE_INLINE void AddNoRet(T *sum, T value) noexcept
Definition AMReX_GpuAtomic.H:284
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
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:92
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
int NProcs()
Process ID in MPI_COMM_WORLD.
Definition AMReX_MPMD.cpp:122
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 Bcast(void *, int, MPI_Datatype, int, MPI_Comm)
Definition AMReX_ParallelDescriptor.cpp:1295
int SeqNum() noexcept
Returns sequential message sequence numbers, usually used as tags for send/recv.
Definition AMReX_ParallelDescriptor.H:696
void GatherLayoutDataToVector(const LayoutData< T > &sendbuf, Vector< T > &recvbuf, int root)
Gather LayoutData values to a vector on root.
Definition AMReX_ParallelDescriptor.H:1295
static constexpr RetSum retSum
Definition AMReX_Scan.H:32
Definition AMReX_Amr.cpp:49
__host__ __device__ void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:139
int nComp(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2851
__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:185
void communicateParticlesStart(const PC &pc, ParticleCopyPlan &plan, const SndBuffer &snd_buffer, RcvBuffer &rcv_buffer)
Definition AMReX_ParticleCommunication.H:505
std::enable_if_t< std::is_integral_v< T > > ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:193
__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 unpackRemotes(PC &pc, const ParticleCopyPlan &plan, Buffer &rcv_buffer, UnpackPolicy const &policy)
Definition AMReX_ParticleCommunication.H:605
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
Long doHandShake(const std::map< int, Vector< char > > ¬_ours, Vector< Long > &Snds, Vector< Long > &Rcvs)
Definition AMReX_ParticleMPIUtil.cpp:25
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:519
void ReorderParticles(PTile &ptile, const index_type *permutations)
Reorder particles on the tile ptile using a the permutations array.
Definition AMReX_ParticleUtil.H:946
__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:417
__host__ __device__ int numTilesInBox(const Box &box, const bool a_do_tiling, const IntVect &a_tile_size)
Definition AMReX_ParticleUtil.H:233
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:30
__host__ __device__ Dim3 begin(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:2006
double second() noexcept
Definition AMReX_Utility.cpp:940
void communicateParticlesFinish(const ParticleCopyPlan &plan)
Definition AMReX_ParticleCommunication.cpp:384
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:393
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:33
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:188
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition AMReX.cpp:234
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
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:35
int Verbose() noexcept
Definition AMReX.cpp:179
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, int lev_min, int lev_max, int nGrow, bool remove_negative)
Definition AMReX_ParticleUtil.H:650
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:240
const int[]
Definition AMReX_BLProfiler.cpp:1664
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:274
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:2015
void unpackBuffer(PC &pc, const ParticleCopyPlan &plan, const Buffer &snd_buffer, UnpackPolicy const &policy)
Definition AMReX_ParticleCommunication.H:440
void packBuffer(const PC &pc, const ParticleCopyOp &op, const ParticleCopyPlan &plan, Buffer &snd_buffer)
Definition AMReX_ParticleCommunication.H:336
__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:337
Definition AMReX_ParticleLocator.H:216
A multidimensional array accessor.
Definition AMReX_Array4.H:283
Definition AMReX_ParticleContainerI.H:1038
amrex::AmrAssignGrid< amrex::DenseBinIteratorFactory< amrex::Box > > m_assign_grid
Definition AMReX_ParticleContainerI.H:1041
int m_lev_max
Definition AMReX_ParticleContainerI.H:1040
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:1047
int m_nGrow
Definition AMReX_ParticleContainerI.H:1040
int m_lev_min
Definition AMReX_ParticleContainerI.H:1040
AMREX_GPU_HOST_DEVICE int operator()(const SrcData &src, int src_i) const noexcept
Definition AMReX_ParticleContainerI.H:1053
int m_gid
Definition AMReX_ParticleContainerI.H:1040
Definition AMReX_ParticleLocator.H:14
Definition AMReX_ParticleUtil.H:390
Definition AMReX_DenseBins.H:32
Definition AMReX_ParticleContainerI.H:799
Box m_domain
Definition AMReX_ParticleContainerI.H:803
GpuArray< Real, 3 > m_dxi
Definition AMReX_ParticleContainerI.H:802
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:805
AMREX_GPU_HOST_DEVICE int operator()(const SrcData &src, int src_i) const noexcept
Definition AMReX_ParticleContainerI.H:812
amrex::AssignGrid< amrex::DenseBinIteratorFactory< amrex::Box > > m_assign_buffer_grid
Definition AMReX_ParticleContainerI.H:801
GpuArray< Real, 3 > m_plo
Definition AMReX_ParticleContainerI.H:802
Definition AMReX_ParticleUtil.H:304
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:43
Definition AMReX_GpuControl.H:184
Definition AMReX_ParticleCommunication.H:81
Vector< int > m_rcv_box_ids
Definition AMReX_ParticleCommunication.H:90
Vector< int > m_rcv_box_counts
Definition AMReX_ParticleCommunication.H:88
Vector< int > m_rcv_box_levs
Definition AMReX_ParticleCommunication.H:92
int m_nrcvs
Definition AMReX_ParticleCommunication.H:95
Gpu::HostVector< unsigned int > m_box_counts_h
Definition AMReX_ParticleCommunication.H:85
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_ParticleCommunication.H:34