1#ifndef AMREX_NEIGHBORPARTICLES_H_
2#define AMREX_NEIGHBORPARTICLES_H_
3#include <AMReX_Config.H>
33template <
int NStructReal,
int NStructInt,
int NArrayReal=0,
int NArrayInt=0>
52 struct NeighborIndexMap {
63 NeighborIndexMap(
int dlevel,
int dgrid,
int dtile,
int dindex,
64 int slevel,
int sgrid,
int stile,
int sindex,
int tnum)
65 : dst_level(dlevel), dst_grid(dgrid), dst_tile(dtile), dst_index(dindex),
66 src_level(slevel), src_grid(sgrid), src_tile(stile), src_index(sindex),
70 friend std::ostream& operator<< (std::ostream& os,
const NeighborIndexMap& nim)
72 os << nim.dst_level <<
" " << nim.dst_grid <<
" " << nim.dst_tile <<
" " << nim.dst_index
73 << nim.src_level <<
" " << nim.src_grid <<
" " << nim.src_tile <<
" " << nim.src_index
76 amrex::Error(
"operator<<(ostream&, const NeighborIndexMap& nim) failed");
83 struct NeighborCopyTag {
91 NeighborCopyTag () =
default;
93 NeighborCopyTag (
int a_level,
int a_grid,
int a_tile) :
94 level(a_level), grid(a_grid), tile(a_tile)
97 bool operator< (
const NeighborCopyTag& other)
const {
98 if (level != other.level) {
return level < other.level; }
99 if (grid != other.grid) {
return grid < other.grid; }
100 if (tile != other.tile) {
return tile < other.tile; }
102 if (periodic_shift[0] != other.periodic_shift[0])
103 return periodic_shift[0] < other.periodic_shift[0];,
104 if (periodic_shift[1] != other.periodic_shift[1])
105 return periodic_shift[1] < other.periodic_shift[1];,
106 if (periodic_shift[2] != other.periodic_shift[2])
107 return periodic_shift[2] < other.periodic_shift[2];
112 bool operator== (
const NeighborCopyTag& other)
const {
113 return (level == other.level) && (grid == other.grid) && (tile == other.tile)
115 && (periodic_shift[0] == other.periodic_shift[0]),
116 && (periodic_shift[1] == other.periodic_shift[1]),
117 && (periodic_shift[2] == other.periodic_shift[2])
121 bool operator!= (
const NeighborCopyTag& other)
const
126 friend std::ostream& operator<< (std::ostream& os,
const NeighborCopyTag& tag)
128 os << tag.level <<
" " << tag.grid <<
" " << tag.tile <<
" " << tag.periodic_shift;
130 amrex::Error(
"operator<<(ostream&, const NeighborCopyTag&) failed");
136 struct InverseCopyTag
144 friend std::ostream&
operator<< (std::ostream& os,
const InverseCopyTag& tag)
146 os << tag.src_level <<
" " << tag.src_grid <<
" " << tag.src_tile <<
" " << tag.src_index;
148 amrex::Error(
"operator<<(ostream&, const InverseCopyTag&) failed");
153 struct NeighborCommTag {
155 NeighborCommTag (
int pid,
int lid,
int gid,
int tid)
156 : proc_id(pid), level_id(lid), grid_id(gid), tile_id(tid)
164 bool operator< (
const NeighborCommTag& other)
const {
165 return (proc_id < other.proc_id ||
166 (proc_id == other.proc_id &&
167 grid_id < other.grid_id) ||
168 (proc_id == other.proc_id &&
169 grid_id == other.grid_id &&
170 tile_id < other.tile_id) ||
171 (proc_id == other.proc_id &&
172 grid_id == other.grid_id &&
173 tile_id == other.tile_id &&
174 level_id < other.level_id));
177 bool operator== (
const NeighborCommTag& other)
const {
178 return ( (proc_id == other.proc_id) &&
179 (grid_id == other.grid_id) &&
180 (tile_id == other.tile_id) &&
181 (level_id == other.level_id));
184 friend std::ostream& operator<< (std::ostream& os,
const NeighborCommTag& tag)
186 os << tag.proc_id <<
" " << tag.level_id <<
" " << tag.grid_id <<
" " << tag.tile_id;
188 amrex::Error(
"operator<<(ostream&, const NeighborCommTag&) failed");
241 void sumNeighbors (
int real_start_comp,
int real_num_comp,
242 int int_start_comp,
int int_num_comp);
257 template <
class CheckPair>
263 template <
class CheckPair,
class OtherPCType>
271 template <
class CheckPair>
272 void buildNeighborList (CheckPair
const& check_pair,
int type_ind,
int* ref_ratio,
273 int num_bin_types=1,
bool sort=
false);
275 template <
class CheckPair>
285 return neighbors[lev][std::make_pair(grid,tile)];
290 return neighbors[lev][std::make_pair(grid,tile)];
293 template <
typename T,
294 std::enable_if_t<std::is_same_v<T,bool>,
int> = 0>
303 template <
typename T,
304 std::enable_if_t<std::is_same_v<T,bool>,
int> = 0>
313 void Redistribute (
int lev_min=0,
int lev_max=-1,
int nGrow=0,
int local=0,
314 bool remove_negative=
true)
323 const int lev_min = 0;
324 const int lev_max = 0;
328 this->
Redistribute(lev_min, lev_max, nGrow, local, remove_negative);
336 void fillNeighborsCPU ();
337 void sumNeighborsCPU (
int real_start_comp,
int real_num_comp,
338 int int_start_comp,
int int_num_comp);
339 void updateNeighborsCPU (
bool reuse_rcv_counts=
true);
340 void clearNeighborsCPU ();
385 int real_start_comp,
int real_num_comp,
386 int int_start_comp,
int int_num_comp);
395 int nGrow,
const NeighborCopyTag& src_tag,
const MyParIter& pti);
399 const IntVect& nGrow,
const NeighborCopyTag& src_tag,
const MyParIter& pti);
446 { return periodic_shift[0] < other.periodic_shift[0]; },
448 { return periodic_shift[1] < other.periodic_shift[1]; },
450 { return periodic_shift[2] < other.periodic_shift[2]; }
462 std::map<int, std::vector<std::vector<NeighborCode> > >
m_grid_map;
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
A collection of Boxes stored in an Array.
Definition AMReX_BoxArray.H:568
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:43
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:74
Definition AMReX_NeighborList.H:249
Definition AMReX_NeighborParticles.H:36
bool m_has_neighbors
Definition AMReX_NeighborParticles.H:486
void setRealCommComp(int i, bool value)
Definition AMReX_NeighborParticlesI.H:60
size_t cdata_size
Definition AMReX_NeighborParticles.H:409
std::pair< int, int > PairIndex
Definition AMReX_NeighborParticles.H:197
const ParticleTile & GetNeighbors(int lev, int grid, int tile) const
Definition AMReX_NeighborParticles.H:288
bool enableInverse()
Definition AMReX_NeighborParticles.H:349
void selectActualNeighbors(CheckPair const &check_pair, int num_cells=1)
Definition AMReX_NeighborParticlesI.H:978
IntVect computeRefFac(int src_lev, int lev)
Definition AMReX_NeighborParticlesI.H:248
void getNeighborTags(Vector< NeighborCopyTag > &tags, const ParticleType &p, int nGrow, const NeighborCopyTag &src_tag, const MyParIter &pti)
Definition AMReX_NeighborParticlesI.H:538
typename ParticleContainerType::SuperParticleType SuperParticleType
Definition AMReX_NeighborParticles.H:40
void GetNeighborCommTags()
Definition AMReX_NeighborParticlesI.H:192
Gpu::PinnedVector< char > pinned_snd_buffer
Definition AMReX_NeighborParticles.H:476
Vector< std::map< PairIndex, ParticleTile > > neighbors
Definition AMReX_NeighborParticles.H:404
void printNeighborList()
Definition AMReX_NeighborParticlesI.H:1092
ParticleTile & GetNeighbors(int lev, int grid, int tile)
Definition AMReX_NeighborParticles.H:283
void calcCommSize()
Definition AMReX_NeighborParticlesI.H:76
Vector< NeighborCommTag > local_neighbors
Definition AMReX_NeighborParticles.H:411
void AddRealComp(T communicate=true)
Definition AMReX_NeighborParticles.H:295
void sumNeighborsMPI(std::map< int, Vector< char > > ¬_ours, int real_start_comp, int real_num_comp, int int_start_comp, int int_num_comp)
bool areMasksValid()
Definition AMReX_NeighborParticlesI.H:129
ParticleCopyPlan neighbor_copy_plan
Definition AMReX_NeighborParticles.H:471
typename ParticleContainer< NStructReal, NStructInt, NArrayReal, NArrayInt >::AoS AoS
Definition AMReX_NeighborParticles.H:199
ParticleCopyOp neighbor_copy_op
Definition AMReX_NeighborParticles.H:470
static bool enable_inverse
Definition AMReX_NeighborParticles.H:429
friend std::ostream & operator<<(std::ostream &os, const InverseCopyTag &tag)
Definition AMReX_NeighborParticles.H:144
void AddIntComp(T communicate=true)
Definition AMReX_NeighborParticles.H:305
~NeighborParticleContainer() override=default
Gpu::PinnedVector< char > pinned_rcv_buffer
Definition AMReX_NeighborParticles.H:477
amrex::DistributionMapping m_cached_neighbor_dm
Definition AMReX_NeighborParticles.H:459
std::map< int, Vector< char > > send_data
Definition AMReX_NeighborParticles.H:422
bool hasNeighbors() const
Definition AMReX_NeighborParticles.H:484
void initializeCommComps()
Definition AMReX_NeighborParticlesI.H:47
typename ParticleContainer< NStructReal, NStructInt, NArrayReal, NArrayInt >::IntVector IntVector
Definition AMReX_NeighborParticles.H:202
Vector< int > ghost_int_comp
Definition AMReX_NeighborParticles.H:425
void resizeContainers(int num_levels)
Definition AMReX_NeighborParticlesI.H:1111
Vector< std::map< PairIndex, IntVector > > neighbor_list
Definition AMReX_NeighborParticles.H:405
void GetCommTagsBox(Vector< NeighborCommTag > &tags, int lev, const Box &in_box)
Definition AMReX_NeighborParticlesI.H:267
bool m_neighbor_mask_initialized
Definition AMReX_NeighborParticles.H:457
std::map< int, std::vector< std::vector< NeighborCode > > > m_grid_map
Definition AMReX_NeighborParticles.H:462
Vector< Long > rcvs
Definition AMReX_NeighborParticles.H:420
static bool use_mask
Definition AMReX_NeighborParticles.H:427
void buildNeighborList(CheckPair const &check_pair, bool sort=false)
Definition AMReX_NeighborParticlesI.H:696
Vector< int > neighbor_procs
Definition AMReX_NeighborParticles.H:419
Vector< std::map< std::pair< int, int >, amrex::Gpu::DeviceVector< int > > > m_boundary_particle_ids
Definition AMReX_NeighborParticles.H:482
NeighborListContainerType m_neighbor_list
Definition AMReX_NeighborParticles.H:480
void Regrid(const DistributionMapping &dmap, const BoxArray &ba)
Definition AMReX_NeighborParticlesI.H:95
Vector< std::map< PairIndex, Vector< Vector< NeighborCopyTag > > > > buffer_tag_cache
Definition AMReX_NeighborParticles.H:414
void fillNeighborsMPI(bool reuse_rcv_counts)
void RedistributeLocal(bool remove_negative=true)
Definition AMReX_NeighborParticles.H:321
typename ParticleContainer< NStructReal, NStructInt, NArrayReal, NArrayInt >::ParticleTileType ParticleTile
Definition AMReX_NeighborParticles.H:201
void updateNeighbors(bool boundary_neighbors_only=false)
Definition AMReX_NeighborParticlesI.H:665
std::map< int, amrex::Gpu::DeviceVector< Box > > m_isec_boxes
Definition AMReX_NeighborParticles.H:467
NeighborParticleContainer(NeighborParticleContainer &&)=default
amrex::PODVector< char, PolymorphicArenaAllocator< char > > snd_buffer
Definition AMReX_NeighborParticles.H:473
void sumNeighbors(int real_start_comp, int real_num_comp, int int_start_comp, int int_num_comp)
Definition AMReX_NeighborParticlesI.H:652
void BuildMasks()
Definition AMReX_NeighborParticlesI.H:153
static constexpr size_t pdata_size
Definition AMReX_NeighborParticles.H:406
Long num_snds
Definition AMReX_NeighborParticles.H:421
int m_num_neighbor_cells
Definition AMReX_NeighborParticles.H:410
void setEnableInverse(bool flag)
Definition AMReX_NeighborParticles.H:343
void clearNeighborsGPU()
Definition AMReX_NeighborParticlesGPUImpl.H:308
void cacheNeighborInfo()
Definition AMReX_NeighborParticlesI.H:314
Vector< std::map< PairIndex, Vector< InverseCopyTag > > > inverse_tags
Definition AMReX_NeighborParticles.H:403
typename ParticleContainerType::ParticleType ParticleType
Definition AMReX_NeighborParticles.H:39
void clearNeighbors()
Definition AMReX_NeighborParticlesI.H:682
void buildNeighborCopyOp(bool use_boundary_neighbor=false)
Definition AMReX_NeighborParticlesGPUImpl.H:127
Vector< int > ghost_real_comp
Definition AMReX_NeighborParticles.H:424
Vector< std::map< PairIndex, int > > local_neighbor_sizes
Definition AMReX_NeighborParticles.H:415
void updateNeighborsGPU(bool boundary_neighbors_only=false)
Definition AMReX_NeighborParticlesGPUImpl.H:252
void fillNeighbors()
Definition AMReX_NeighborParticlesI.H:640
NeighborParticleContainer & operator=(const NeighborParticleContainer &)=delete
void Redistribute(int lev_min=0, int lev_max=-1, int nGrow=0, int local=0, bool remove_negative=true)
Definition AMReX_NeighborParticles.H:313
Vector< std::unique_ptr< iMultiFab > > mask_ptr
Definition AMReX_NeighborParticles.H:412
void setIntCommComp(int i, bool value)
Definition AMReX_NeighborParticlesI.H:68
std::map< int, amrex::Gpu::DeviceVector< int > > m_code_offsets
Definition AMReX_NeighborParticles.H:468
std::map< int, amrex::Gpu::DeviceVector< NeighborCode > > m_code_array
Definition AMReX_NeighborParticles.H:465
typename ParticleContainer< NStructReal, NStructInt, NArrayReal, NArrayInt >::ParticleVector ParticleVector
Definition AMReX_NeighborParticles.H:200
NeighborParticleContainer(const NeighborParticleContainer &)=delete
void buildNeighborMask()
Definition AMReX_NeighborParticlesGPUImpl.H:55
std::map< NeighborCommTag, Vector< char > > NeighborCommMap
Definition AMReX_NeighborParticles.H:198
static constexpr int num_mask_comps
grid, tile, level
Definition AMReX_NeighborParticles.H:408
amrex::PODVector< char, PolymorphicArenaAllocator< char > > rcv_buffer
Definition AMReX_NeighborParticles.H:474
amrex::BoxArray m_cached_neighbor_ba
Definition AMReX_NeighborParticles.H:458
void fillNeighborsGPU()
Definition AMReX_NeighborParticlesGPUImpl.H:232
Dynamically allocated vector for trivially copyable data.
Definition AMReX_PODVector.H:308
Definition AMReX_ParGDB.H:13
Definition AMReX_ParIter.H:118
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition AMReX_ParticleContainer.H:149
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
typename ParticleTileType::AoS AoS
Definition AMReX_ParticleContainer.H:199
typename AoS::ParticleVector ParticleVector
Definition AMReX_ParticleContainer.H:204
typename SoA::IntVector IntVector
Definition AMReX_ParticleContainer.H:203
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:49
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:234
Definition AMReX_NeighborParticles.H:17
IntVect periodic_shift
Definition AMReX_NeighborParticles.H:19
int grid_id
Definition AMReX_NeighborParticles.H:18
Definition AMReX_NeighborParticles.H:433
bool operator<(const NeighborTask &other) const
Definition AMReX_NeighborParticles.H:441
IntVect periodic_shift
Definition AMReX_NeighborParticles.H:436
Box box
Definition AMReX_NeighborParticles.H:435
int grid_id
Definition AMReX_NeighborParticles.H:434
NeighborTask(int a_grid_id, const Box &a_box, const IntVect &a_periodic_shift)
Definition AMReX_NeighborParticles.H:438
Definition AMReX_ParticleCommunication.H:58
Definition AMReX_ParticleCommunication.H:81