1#ifndef AMREX_NEIGHBORPARTICLES_H_
2#define AMREX_NEIGHBORPARTICLES_H_
3#include <AMReX_Config.H>
34template <
typename T_ParticleType,
int T_NArrayReal=0,
int T_NArrayInt=0,
58 struct NeighborIndexMap {
69 NeighborIndexMap(
int dlevel,
int dgrid,
int dtile,
int dindex,
70 int slevel,
int sgrid,
int stile,
int sindex,
int tnum)
71 : dst_level(dlevel), dst_grid(dgrid), dst_tile(dtile), dst_index(dindex),
72 src_level(slevel), src_grid(sgrid), src_tile(stile), src_index(sindex),
76 friend std::ostream& operator<< (std::ostream& os,
const NeighborIndexMap& nim)
78 os << nim.dst_level <<
" " << nim.dst_grid <<
" " << nim.dst_tile <<
" " << nim.dst_index
79 << nim.src_level <<
" " << nim.src_grid <<
" " << nim.src_tile <<
" " << nim.src_index
82 amrex::Error(
"operator<<(ostream&, const NeighborIndexMap& nim) failed");
89 struct NeighborCopyTag {
97 NeighborCopyTag () =
default;
99 NeighborCopyTag (
int a_level,
int a_grid,
int a_tile) :
100 level(a_level), grid(a_grid), tile(a_tile)
103 bool operator< (
const NeighborCopyTag& other)
const {
104 if (level != other.level) {
return level < other.level; }
105 if (grid != other.grid) {
return grid < other.grid; }
106 if (tile != other.tile) {
return tile < other.tile; }
108 if (periodic_shift[0] != other.periodic_shift[0])
109 return periodic_shift[0] < other.periodic_shift[0];,
110 if (periodic_shift[1] != other.periodic_shift[1])
111 return periodic_shift[1] < other.periodic_shift[1];,
112 if (periodic_shift[2] != other.periodic_shift[2])
113 return periodic_shift[2] < other.periodic_shift[2];
118 bool operator== (
const NeighborCopyTag& other)
const {
119 return (level == other.level) && (grid == other.grid) && (tile == other.tile)
121 && (periodic_shift[0] == other.periodic_shift[0]),
122 && (periodic_shift[1] == other.periodic_shift[1]),
123 && (periodic_shift[2] == other.periodic_shift[2])
127 bool operator!= (
const NeighborCopyTag& other)
const
132 friend std::ostream& operator<< (std::ostream& os,
const NeighborCopyTag& tag)
134 os << tag.level <<
" " << tag.grid <<
" " << tag.tile <<
" " << tag.periodic_shift;
136 amrex::Error(
"operator<<(ostream&, const NeighborCopyTag&) failed");
142 struct InverseCopyTag
150 friend std::ostream&
operator<< (std::ostream& os,
const InverseCopyTag& tag)
152 os << tag.src_level <<
" " << tag.src_grid <<
" " << tag.src_tile <<
" " << tag.src_index;
154 amrex::Error(
"operator<<(ostream&, const InverseCopyTag&) failed");
159 struct NeighborCommTag {
161 NeighborCommTag (
int pid,
int lid,
int gid,
int tid)
162 : proc_id(pid), level_id(lid), grid_id(gid), tile_id(tid)
170 bool operator< (
const NeighborCommTag& other)
const {
171 return (proc_id < other.proc_id ||
172 (proc_id == other.proc_id &&
173 grid_id < other.grid_id) ||
174 (proc_id == other.proc_id &&
175 grid_id == other.grid_id &&
176 tile_id < other.tile_id) ||
177 (proc_id == other.proc_id &&
178 grid_id == other.grid_id &&
179 tile_id == other.tile_id &&
180 level_id < other.level_id));
183 bool operator== (
const NeighborCommTag& other)
const {
184 return ( (proc_id == other.proc_id) &&
185 (grid_id == other.grid_id) &&
186 (tile_id == other.tile_id) &&
187 (level_id == other.level_id));
190 friend std::ostream& operator<< (std::ostream& os,
const NeighborCommTag& tag)
192 os << tag.proc_id <<
" " << tag.level_id <<
" " << tag.grid_id <<
" " << tag.tile_id;
194 amrex::Error(
"operator<<(ostream&, const NeighborCommTag&) failed");
256 void sumNeighbors (
int real_start_comp,
int real_num_comp,
257 int int_start_comp,
int int_num_comp);
272 template <
class CheckPair>
278 template <
class CheckPair,
class OtherPCType>
280 Vector<std::map<std::pair<int, int>,
287 template <
class CheckPair>
288 void buildNeighborList (CheckPair
const& check_pair,
int type_ind,
int* ref_ratio,
289 int num_bin_types=1,
bool sort=
false);
291 template <
class CheckPair>
301 return neighbors[lev][std::make_pair(grid,tile)];
306 return neighbors[lev][std::make_pair(grid,tile)];
309 template <
typename T,
310 std::enable_if_t<std::is_same_v<T,bool>,
int> = 0>
318 template <
typename T,
319 std::enable_if_t<std::is_same_v<T,bool>,
int> = 0>
327 void Redistribute (
int lev_min=0,
int lev_max=-1,
int nGrow=0,
int local=0,
328 bool remove_negative=
true)
336 const int lev_min = 0;
337 const int lev_max = 0;
341 this->
Redistribute(lev_min, lev_max, nGrow, local, remove_negative);
349 void fillNeighborsCPU ();
350 void sumNeighborsCPU (
int real_start_comp,
int real_num_comp,
351 int int_start_comp,
int int_num_comp);
352 void updateNeighborsCPU (
bool reuse_rcv_counts=
true);
353 void clearNeighborsCPU ();
401 int real_start_comp,
int real_num_comp,
402 int int_start_comp,
int int_num_comp);
409 template <
typename P>
412 int nGrow,
const NeighborCopyTag& src_tag,
const MyParIter& pti);
414 template <
typename P>
417 const IntVect& nGrow,
const NeighborCopyTag& src_tag,
const MyParIter& pti);
464 { return periodic_shift[0] < other.periodic_shift[0]; },
466 { return periodic_shift[1] < other.periodic_shift[1]; },
468 { return periodic_shift[2] < other.periodic_shift[2]; }
480 std::map<int, std::vector<std::vector<NeighborCode> > >
m_grid_map;
507template <
int T_NStructReal,
int T_NStructInt,
int T_NArrayReal=0,
int T_NArrayInt=0>
511template <
int T_NArrayReal,
int T_NArrayInt,
516 T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
A collection of Boxes stored in an Array.
Definition AMReX_BoxArray.H:564
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:43
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:75
Definition AMReX_NeighborList.H:311
Definition AMReX_NeighborParticles.H:39
void AddIntComp(T communicate=true)
Definition AMReX_NeighborParticles.H:320
void fillNeighbors()
Definition AMReX_NeighborParticlesI.H:668
std::pair< int, int > PairIndex
Definition AMReX_NeighborParticles.H:210
void clearNeighbors()
Definition AMReX_NeighborParticlesI.H:713
Vector< Long > rcvs
Definition AMReX_NeighborParticles.H:438
void selectActualNeighbors(CheckPair const &check_pair, int num_cells=1)
Definition AMReX_NeighborParticlesI.H:1014
amrex::BoxArray m_cached_neighbor_ba
Definition AMReX_NeighborParticles.H:476
Vector< int > ghost_int_comp
Definition AMReX_NeighborParticles.H:443
static bool enable_inverse
Definition AMReX_NeighborParticles.H:447
const ParticleTile & GetNeighbors(int lev, int grid, int tile) const
Definition AMReX_NeighborParticles.H:304
~NeighborParticleContainer_impl() override=default
NeighborParticleContainer_impl & operator=(const NeighborParticleContainer_impl &)=delete
void setRealCommComp(int i, bool value)
Definition AMReX_NeighborParticlesI.H:74
void sumNeighbors(int real_start_comp, int real_num_comp, int int_start_comp, int int_num_comp)
Definition AMReX_NeighborParticlesI.H:681
static constexpr int RealCommCompStart
Definition AMReX_NeighborParticles.H:206
std::map< int, amrex::Gpu::DeviceVector< NeighborCode > > m_code_array
Definition AMReX_NeighborParticles.H:483
int numIntCommComps() const
Definition AMReX_NeighborParticles.H:371
void fillNeighborsMPI(bool reuse_rcv_counts)
void buildNeighborList(CheckPair const &check_pair, bool sort=false)
Definition AMReX_NeighborParticlesI.H:728
typename ParticleContainerType::PTDType PTDType
Definition AMReX_NeighborParticles.H:216
void printNeighborList()
Definition AMReX_NeighborParticlesI.H:1126
typename ParticleContainerType::ConstPTDType ConstPTDType
Definition AMReX_NeighborParticles.H:217
void updateNeighborsGPU(bool boundary_neighbors_only=false)
Definition AMReX_NeighborParticlesGPUImpl.H:345
void GetNeighborCommTags()
Definition AMReX_NeighborParticlesI.H:214
friend std::ostream & operator<<(std::ostream &os, const InverseCopyTag &tag)
Definition AMReX_NeighborParticles.H:150
void getNeighborTags(Vector< NeighborCopyTag > &tags, const P &p, int nGrow, const NeighborCopyTag &src_tag, const MyParIter &pti)
Definition AMReX_NeighborParticlesI.H:563
NeighborParticleContainer_impl(NeighborParticleContainer_impl &&)=default
void setEnableInverse(bool flag)
Definition AMReX_NeighborParticles.H:356
Vector< int > neighbor_procs
Definition AMReX_NeighborParticles.H:437
void buildNeighborCopyOp(bool use_boundary_neighbor=false)
Definition AMReX_NeighborParticlesGPUImpl.H:188
NeighborListContainerType m_neighbor_list
Definition AMReX_NeighborParticles.H:498
ParticleTile & GetNeighbors(int lev, int grid, int tile)
Definition AMReX_NeighborParticles.H:299
static bool use_mask
Definition AMReX_NeighborParticles.H:445
void sumNeighborsMPI(std::map< int, Vector< char > > ¬_ours, int real_start_comp, int real_num_comp, int int_start_comp, int int_num_comp)
void buildNeighborMask()
Definition AMReX_NeighborParticlesGPUImpl.H:115
ParticleCopyPlan neighbor_copy_plan
Definition AMReX_NeighborParticles.H:489
int m_num_neighbor_cells
Definition AMReX_NeighborParticles.H:428
size_t cdata_size
Definition AMReX_NeighborParticles.H:427
static constexpr int IntCommCompStart
Definition AMReX_NeighborParticles.H:207
NeighborParticleContainer_impl(const NeighborParticleContainer_impl &)=delete
Vector< std::map< PairIndex, Vector< InverseCopyTag > > > inverse_tags
Definition AMReX_NeighborParticles.H:421
void RedistributeLocal(bool remove_negative=true)
Definition AMReX_NeighborParticles.H:334
bool enableInverse()
Definition AMReX_NeighborParticles.H:362
typename ParticleContainerType::ParticleTileType ParticleTile
Definition AMReX_NeighborParticles.H:214
ParticleCopyOp neighbor_copy_op
Definition AMReX_NeighborParticles.H:488
Vector< std::map< PairIndex, IntVector > > neighbor_list
Definition AMReX_NeighborParticles.H:423
typename ParticleContainerType::SuperParticleType SuperParticleType
Definition AMReX_NeighborParticles.H:44
static constexpr int NStructReal
Definition AMReX_NeighborParticles.H:204
void fillNeighborsGPU()
Definition AMReX_NeighborParticlesGPUImpl.H:324
IntVect computeRefFac(int src_lev, int lev)
Definition AMReX_NeighborParticlesI.H:271
void updateNeighbors(bool boundary_neighbors_only=false)
Definition AMReX_NeighborParticlesI.H:695
void initializeCommComps()
Definition AMReX_NeighborParticlesI.H:60
typename ParticleContainerType::AoS AoS
Definition AMReX_NeighborParticles.H:212
std::map< NeighborCommTag, Vector< char > > NeighborCommMap
Definition AMReX_NeighborParticles.H:211
std::map< int, Vector< char > > send_data
Definition AMReX_NeighborParticles.H:440
void GetCommTagsBox(Vector< NeighborCommTag > &tags, int lev, const Box &in_box)
Definition AMReX_NeighborParticlesI.H:291
bool hasNeighbors() const
Definition AMReX_NeighborParticles.H:502
Gpu::PinnedVector< char > pinned_rcv_buffer
Definition AMReX_NeighborParticles.H:495
static constexpr int num_mask_comps
grid, tile, level
Definition AMReX_NeighborParticles.H:426
amrex::PODVector< char, PolymorphicArenaAllocator< char > > snd_buffer
Definition AMReX_NeighborParticles.H:491
Vector< std::map< PairIndex, Vector< Vector< NeighborCopyTag > > > > buffer_tag_cache
Definition AMReX_NeighborParticles.H:432
Vector< std::map< std::pair< int, int >, amrex::Gpu::DeviceVector< int > > > m_boundary_particle_ids
Definition AMReX_NeighborParticles.H:500
Vector< std::map< PairIndex, int > > local_neighbor_sizes
Definition AMReX_NeighborParticles.H:433
typename ParticleContainerType::ParIterType MyParIter
Definition AMReX_NeighborParticles.H:209
typename ParticleContainerType::ParticleVector ParticleVector
Definition AMReX_NeighborParticles.H:213
bool areMasksValid()
Definition AMReX_NeighborParticlesI.H:149
Vector< std::unique_ptr< iMultiFab > > mask_ptr
Definition AMReX_NeighborParticles.H:430
Vector< std::map< PairIndex, ParticleTile > > neighbors
Definition AMReX_NeighborParticles.H:422
typename ParticleContainerType::IntVector IntVector
Definition AMReX_NeighborParticles.H:215
void calcCommSize()
Definition AMReX_NeighborParticlesI.H:92
void clearNeighborsGPU()
Definition AMReX_NeighborParticlesGPUImpl.H:402
bool m_has_neighbors
Definition AMReX_NeighborParticles.H:504
amrex::PODVector< char, PolymorphicArenaAllocator< char > > rcv_buffer
Definition AMReX_NeighborParticles.H:492
static constexpr int NArrayInt
Definition AMReX_NeighborParticles.H:203
Vector< NeighborCommTag > local_neighbors
Definition AMReX_NeighborParticles.H:429
void BuildMasks()
Definition AMReX_NeighborParticlesI.H:174
Long num_snds
Definition AMReX_NeighborParticles.H:439
void resizeContainers(int num_levels)
Definition AMReX_NeighborParticlesI.H:1146
bool m_neighbor_mask_initialized
Definition AMReX_NeighborParticles.H:475
Gpu::PinnedVector< char > pinned_snd_buffer
Definition AMReX_NeighborParticles.H:494
std::map< int, amrex::Gpu::DeviceVector< Box > > m_isec_boxes
Definition AMReX_NeighborParticles.H:485
Vector< int > ghost_real_comp
Definition AMReX_NeighborParticles.H:442
void setIntCommComp(int i, bool value)
Definition AMReX_NeighborParticlesI.H:83
std::map< int, std::vector< std::vector< NeighborCode > > > m_grid_map
Definition AMReX_NeighborParticles.H:480
std::map< int, amrex::Gpu::DeviceVector< int > > m_code_offsets
Definition AMReX_NeighborParticles.H:486
int numRealCommComps() const
Definition AMReX_NeighborParticles.H:370
void Regrid(const DistributionMapping &dmap, const BoxArray &ba)
Definition AMReX_NeighborParticlesI.H:112
static constexpr int NArrayReal
Definition AMReX_NeighborParticles.H:202
void Redistribute(int lev_min=0, int lev_max=-1, int nGrow=0, int local=0, bool remove_negative=true)
Definition AMReX_NeighborParticles.H:327
static constexpr int NStructInt
Definition AMReX_NeighborParticles.H:205
void cacheNeighborInfo()
Definition AMReX_NeighborParticlesI.H:339
typename ParticleContainerType::ParticleType ParticleType
Definition AMReX_NeighborParticles.H:43
static constexpr size_t pdata_size
Definition AMReX_NeighborParticles.H:424
void AddRealComp(T communicate=true)
Definition AMReX_NeighborParticles.H:311
amrex::DistributionMapping m_cached_neighbor_dm
Definition AMReX_NeighborParticles.H:477
Dynamically allocated vector for trivially copyable data.
Definition AMReX_PODVector.H:308
Definition AMReX_ParGDB.H:13
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition AMReX_ParticleContainer.H:149
typename ParticleTileType::ConstParticleTileDataType ConstPTDType
Definition AMReX_ParticleContainer.H:198
void Redistribute(int lev_min=0, int lev_max=-1, int nGrow=0, int local=0, bool remove_negative=true)
Redistribute puts all the particles back in the right places (for some value of right)
Definition AMReX_ParticleContainerI.H:1238
void AddIntComp(std::string const &name, int communicate=1)
Definition AMReX_ParticleContainer.H:1326
Particle< NStructReal+NArrayReal, NStructInt+NArrayInt > SuperParticleType
The type of the "SuperParticle" which stored all components in AoS form.
Definition AMReX_ParticleContainer.H:174
static constexpr int NArrayInt
Number of extra integer components stored in struct-of-array form.
Definition AMReX_ParticleContainer.H:162
static constexpr int NArrayReal
Number of extra Real components stored in struct-of-array form.
Definition AMReX_ParticleContainer.H:160
typename ParticleTileType::AoS AoS
Definition AMReX_ParticleContainer.H:199
typename AoS::ParticleVector ParticleVector
Definition AMReX_ParticleContainer.H:204
static constexpr int NStructInt
Number of extra integer components in the particle struct.
Definition AMReX_ParticleContainer.H:158
int NumRealComps() const
Definition AMReX_ParticleContainer.H:1362
static constexpr int NStructReal
Number of extra Real components in the particle struct.
Definition AMReX_ParticleContainer.H:156
int NumIntComps() const
Definition AMReX_ParticleContainer.H:1363
typename ParticleTileType::ParticleTileDataType PTDType
Definition AMReX_ParticleContainer.H:197
typename SoA::IntVector IntVector
Definition AMReX_ParticleContainer.H:203
ParIter_impl< ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor > ParIterType
Definition AMReX_ParticleContainer.H:206
std::conditional_t< is_rtsoa_pc, ParticleTileRT< typename ParticleType::RealType, typename ParticleType::IntType >, ParticleTile< ParticleType, NArrayReal, NArrayInt, Allocator > > ParticleTileType
Definition AMReX_ParticleContainer.H:191
void AddRealComp(std::string const &name, int communicate=1)
Definition AMReX_ParticleContainer.H:1293
T_ParticleType ParticleType
Definition AMReX_ParticleContainer.H:151
amrex_long Long
Definition AMReX_INT.H:30
Definition AMReX_Amr.cpp:50
amrex::ArenaAllocator< T > DefaultAllocator
Definition AMReX_GpuAllocators.H:205
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:33
bool operator==(A1 const &a1, A2 const &a2)
Definition AMReX_GpuAllocators.H:214
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition AMReX.cpp:235
Definition AMReX_ParticleUtil.H:390
Definition AMReX_NeighborParticles.H:17
Box grid_box
Definition AMReX_NeighborParticles.H:19
IntVect periodic_shift
Definition AMReX_NeighborParticles.H:20
int grid_id
Definition AMReX_NeighborParticles.H:18
Definition AMReX_NeighborParticles.H:451
IntVect periodic_shift
Definition AMReX_NeighborParticles.H:454
Box box
Definition AMReX_NeighborParticles.H:453
int grid_id
Definition AMReX_NeighborParticles.H:452
bool operator<(const NeighborTask &other) const
Definition AMReX_NeighborParticles.H:459
NeighborTask(int a_grid_id, const Box &a_box, const IntVect &a_periodic_shift)
Definition AMReX_NeighborParticles.H:456
Definition AMReX_ParticleCommunication.H:66
Definition AMReX_ParticleCommunication.H:92