1 #ifndef AMREX_NEIGHBOR_LIST_H_
2 #define AMREX_NEIGHBOR_LIST_H_
3 #include <AMReX_Config.H>
16 typename SrcData,
typename DstData,
17 typename N1,
typename N2>
20 const SrcData& src_tile,
const DstData& dst_tile,
22 noexcept -> decltype(check_pair(src_tile.m_aos[i], dst_tile.m_aos[j]))
24 return check_pair(src_tile.m_aos[i], dst_tile.m_aos[j]);
28 typename SrcData,
typename DstData,
29 typename N1,
typename N2>
32 const SrcData& src_tile,
const DstData& ,
34 noexcept -> decltype(check_pair(src_tile.m_aos, i, j))
36 return check_pair(src_tile.m_aos, i, j);
40 typename SrcData,
typename DstData,
41 typename N1,
typename N2>
44 const SrcData& src_tile,
const DstData& ,
46 noexcept -> decltype(check_pair(src_tile, i, j))
48 return check_pair(src_tile, i, j);
53 typename SrcData,
typename DstData,
54 typename N1,
typename N2,
typename N3,
typename N4,
typename N5>
57 const SrcData& src_tile,
const DstData& dst_tile,
58 N1 i, N2 j, N3 , N4 , N5 )
59 noexcept -> decltype(check_pair(src_tile.m_aos[i], dst_tile.m_aos[j]))
61 return check_pair(src_tile.m_aos[i], dst_tile.m_aos[j]);
65 typename SrcData,
typename DstData,
66 typename N1,
typename N2,
typename N3,
typename N4,
typename N5>
69 const SrcData& src_tile,
const DstData& ,
70 N1 i, N2 j, N3 , N4 , N5 )
71 noexcept -> decltype(check_pair(src_tile.m_aos, i, j))
73 return check_pair(src_tile.m_aos, i, j);
77 typename SrcData,
typename DstData,
78 typename N1,
typename N2,
typename N3,
typename N4,
typename N5>
81 const SrcData& src_tile,
const DstData& ,
82 N1 i, N2 j, N3 , N4 , N5 )
83 noexcept -> decltype(check_pair(src_tile, i, j))
85 return check_pair(src_tile, i, j);
89 typename SrcData,
typename DstData,
90 typename N1,
typename N2,
typename N3,
typename N4,
typename N5>
93 const SrcData& src_tile,
const DstData& ,
94 N1 i, N2 j, N3 type, N4 ghost_i, N5 ghost_pid)
95 noexcept -> decltype(check_pair(src_tile, i, j, type, ghost_i, ghost_pid))
97 return check_pair(src_tile, i, j, type, ghost_i, ghost_pid);
101 template <
class ParticleType>
107 iterator (
int start,
int stop,
const unsigned int * nbor_list_ptr, ParticleType* pstruct)
133 const_iterator (
int start,
int stop,
const unsigned int * nbor_list_ptr,
const ParticleType* pstruct)
193 Neighbors (
int i,
const unsigned int *nbor_offsets_ptr,
const unsigned int *nbor_list_ptr,
194 ParticleType* pstruct)
209 template <
class ParticleType>
214 ParticleType* pstruct)
229 template<
typename A,
typename B,
230 std::enable_if_t<std::is_same_v<std::remove_cv_t<A>,
231 std::remove_cv_t<B> >,
int> = 0>
237 template<
typename A,
typename B,
238 std::enable_if_t<!std::is_same_v<std::remove_cv_t<A>,
239 std::remove_cv_t<B> >,
int> = 0>
240 bool isSame (A
const* , B
const* )
245 template <
class ParticleType>
250 template <
class PTile,
class CheckPair>
253 CheckPair&& check_pair,
int num_cells=1)
267 build(ptile, ptile, std::forward<CheckPair>(check_pair), off_bins_v, dxi_v, plo_v,
268 lo_v, hi_v, num_cells, 1,
nullptr );
271 template <
class PTile,
class CheckPair>
273 CheckPair&& check_pair,
281 int* bin_type_array=
nullptr)
283 build(ptile, ptile, std::forward<CheckPair>(check_pair), off_bins_v, dxi_v, plo_v,
284 lo_v, hi_v, num_cells, num_bin_types, bin_type_array );
287 template <
class SrcTile,
class TargetTile,
class CheckPair>
289 TargetTile& target_tile,
290 CheckPair
const& check_pair,
298 int* bin_type_array=
nullptr)
302 bool is_same =
isSame(&src_tile, &target_tile);
307 auto& aos = target_tile.GetArrayOfStructs();
308 const auto dst_ptile_data = target_tile.getConstParticleTileData();
311 auto*
const pstruct_ptr = aos().dataPtr();
313 const int np_total = aos.size();
314 const int np_real = src_tile.numRealParticles();
316 auto const* off_bins_p = off_bins_v.
data();
317 auto const* dxi_p = dxi_v.data();
318 auto const* plo_p = plo_v.data();
319 auto const* lo_p = lo_v.
data();
320 auto const* hi_p = hi_v.
data();
321 BinMapper bm(off_bins_p, dxi_p, plo_p, lo_p, hi_p, bin_type_array);
328 std::memcpy( &tot_bins, off_bins_p + num_bin_types,
sizeof(
int) );
336 const int np_size = (num_bin_types > 1) ? np_total : np_real;
346 const auto src_ptile_data = src_tile.getConstParticleTileData();
347 const auto* src_pstruct_ptr = src_tile.GetArrayOfStructs()().dataPtr();
352 int type_i = bin_type_array ? bin_type_array[i] : 0;
353 bool ghost_i = (i >= np_real);
354 for (
int type(type_i); type<num_bin_types; ++type) {
355 int off_bins = off_bins_p[type];
358 static_cast<int>(amrex::Math::floor((src_pstruct_ptr[i].pos(0)-plo_p[type][0])*dxi_p[type][0])) - lo_p[type].
x,
359 static_cast<int>(amrex::Math::floor((src_pstruct_ptr[i].pos(1)-plo_p[type][1])*dxi_p[type][1])) - lo_p[type].y,
360 static_cast<int>(amrex::Math::floor((src_pstruct_ptr[i].pos(2)-plo_p[type][2])*dxi_p[type][2])) - lo_p[type].z));
361 auto iv3 = iv.
dim3();
367 int nx = hi_p[type].x-lo_p[type].x+1;
368 int ny = hi_p[type].y-lo_p[type].y+1;
369 int nz = hi_p[type].z-lo_p[type].z+1;
374 int index = (ii * ny + jj) * nz + kk + off_bins;
375 for (
auto p = poffset[index]; p < poffset[index+1]; ++p) {
376 const auto& pid = pperm[p];
377 bool ghost_pid = (pid >= np_real);
378 if (is_same && (pid == i)) {
continue; }
380 src_ptile_data, dst_ptile_data,
381 i, pid, type, ghost_i, ghost_pid)) {
390 pnbor_counts[i] = count;
399 unsigned int total_nbors;
412 int type_i = bin_type_array ? bin_type_array[i] : 0;
413 bool ghost_i = (i >= np_real);
414 for (
int type(type_i); type<num_bin_types; ++type) {
415 int off_bins = off_bins_p[type];
418 static_cast<int>(amrex::Math::floor((src_pstruct_ptr[i].pos(0)-plo_p[type][0])*dxi_p[type][0])) - lo_p[type].
x,
419 static_cast<int>(amrex::Math::floor((src_pstruct_ptr[i].pos(1)-plo_p[type][1])*dxi_p[type][1])) - lo_p[type].y,
420 static_cast<int>(amrex::Math::floor((src_pstruct_ptr[i].pos(2)-plo_p[type][2])*dxi_p[type][2])) - lo_p[type].z));
421 auto iv3 = iv.
dim3();
427 int nx = hi_p[type].x-lo_p[type].x+1;
428 int ny = hi_p[type].y-lo_p[type].y+1;
429 int nz = hi_p[type].z-lo_p[type].z+1;
434 int index = (ii * ny + jj) * nz + kk + off_bins;
435 for (
auto p = poffset[index]; p < poffset[index+1]; ++p) {
436 const auto& pid = pperm[p];
437 bool ghost_pid = (pid >= np_real);
438 if (is_same && (pid == i)) {
continue; }
440 src_ptile_data, dst_ptile_data,
441 i, pid, type, ghost_i, ghost_pid)) {
442 pm_nbor_list[pnbor_offset[i] + n] = pid;
482 amrex::Print() <<
"Particle " << i <<
" could collide with: ";
483 for (
unsigned int j = host_nbor_offsets[i]; j < host_nbor_offsets[i+1]; ++j) {
#define BL_PROFILE(a)
Definition: AMReX_BLProfiler.H:551
#define AMREX_FOR_1D(...)
Definition: AMReX_GpuLaunch.nolint.H:41
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
#define AMREX_D_DECL(a, b, c)
Definition: AMReX_SPACE.H:104
AMREX_GPU_HOST_DEVICE Long numPts() const noexcept
Returns the number of points contained in the BoxND.
Definition: AMReX_Box.H:346
GpuArray< Real, AMREX_SPACEDIM > InvCellSizeArray() const noexcept
Definition: AMReX_CoordSys.H:87
index_type * offsetsPtr() noexcept
returns the pointer to the offsets array
Definition: AMReX_DenseBins.H:510
void build(N nitems, const_pointer_input_type v, const Box &bx, F &&f)
Populate the bins with a set of items.
Definition: AMReX_DenseBins.H:130
index_type * permutationPtr() noexcept
returns the pointer to the permutation array
Definition: AMReX_DenseBins.H:507
Rectangular problem domain geometry.
Definition: AMReX_Geometry.H:73
GpuArray< Real, AMREX_SPACEDIM > ProbLoArray() const noexcept
Definition: AMReX_Geometry.H:186
static void streamSynchronize() noexcept
Definition: AMReX_GpuDevice.cpp:641
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 dim3() const noexcept
Definition: AMReX_IntVect.H:163
Definition: AMReX_NeighborList.H:247
Gpu::DeviceVector< unsigned int > & GetList()
Definition: AMReX_NeighborList.H:467
Gpu::DeviceVector< unsigned int > m_nbor_counts
Definition: AMReX_NeighborList.H:497
void build(SrcTile &src_tile, TargetTile &target_tile, CheckPair const &check_pair, const Gpu::DeviceVector< int > &off_bins_v, const Gpu::DeviceVector< GpuArray< Real, AMREX_SPACEDIM >> &dxi_v, const Gpu::DeviceVector< GpuArray< Real, AMREX_SPACEDIM >> &plo_v, const Gpu::DeviceVector< Dim3 > &lo_v, const Gpu::DeviceVector< Dim3 > &hi_v, int num_cells=1, int num_bin_types=1, int *bin_type_array=nullptr)
Definition: AMReX_NeighborList.H:288
Gpu::DeviceVector< unsigned int > & GetCounts()
Definition: AMReX_NeighborList.H:464
const Gpu::DeviceVector< unsigned int > & GetList() const
Definition: AMReX_NeighborList.H:468
const Gpu::DeviceVector< unsigned int > & GetOffsets() const
Definition: AMReX_NeighborList.H:462
void print()
Definition: AMReX_NeighborList.H:470
Gpu::DeviceVector< unsigned int > & GetOffsets()
Definition: AMReX_NeighborList.H:461
const Gpu::DeviceVector< unsigned int > & GetCounts() const
Definition: AMReX_NeighborList.H:465
void build(PTile &ptile, CheckPair &&check_pair, const Gpu::DeviceVector< int > &off_bins_v, const Gpu::DeviceVector< GpuArray< Real, AMREX_SPACEDIM >> &dxi_v, const Gpu::DeviceVector< GpuArray< Real, AMREX_SPACEDIM >> &plo_v, const Gpu::DeviceVector< Dim3 > &lo_v, const Gpu::DeviceVector< Dim3 > &hi_v, int num_cells=1, int num_bin_types=1, int *bin_type_array=nullptr)
Definition: AMReX_NeighborList.H:272
Gpu::DeviceVector< unsigned int > m_nbor_list
Definition: AMReX_NeighborList.H:496
ParticleType * m_pstruct
Definition: AMReX_NeighborList.H:492
Gpu::DeviceVector< unsigned int > m_nbor_offsets
Definition: AMReX_NeighborList.H:495
NeighborData< ParticleType > data()
Definition: AMReX_NeighborList.H:454
void build(PTile &ptile, const amrex::Box &bx, const amrex::Geometry &geom, CheckPair &&check_pair, int num_cells=1)
Definition: AMReX_NeighborList.H:251
int numParticles() const
Definition: AMReX_NeighborList.H:459
DenseBins< ParticleType > m_bins
Definition: AMReX_NeighborList.H:499
Definition: AMReX_PODVector.H:246
T * data() noexcept
Definition: AMReX_PODVector.H:593
iterator begin() noexcept
Definition: AMReX_PODVector.H:601
void push_back(const T &a_value)
Definition: AMReX_PODVector.H:556
This class provides the user with a few print options.
Definition: AMReX_Print.H:35
void copyAsync(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
A host-to-device copy routine. Note this is just a wrapper around memcpy, so it assumes contiguous st...
Definition: AMReX_GpuContainers.H:233
OutIter exclusive_scan(InIter begin, InIter end, OutIter result)
Definition: AMReX_Scan.H:1377
static constexpr DeviceToHost deviceToHost
Definition: AMReX_GpuContainers.H:99
void streamSynchronize() noexcept
Definition: AMReX_GpuDevice.H:237
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void * memcpy(void *dest, const void *src, std::size_t count)
Definition: AMReX_GpuUtility.H:214
void dtoh_memcpy(void *p_h, const void *p_d, const std::size_t sz) noexcept
Definition: AMReX_GpuDevice.H:301
AMREX_GPU_HOST_DEVICE auto call_check_pair(F const &check_pair, const SrcData &src_tile, const DstData &dst_tile, N1 i, N2 j) noexcept -> decltype(check_pair(src_tile.m_aos[i], dst_tile.m_aos[j]))
Definition: AMReX_NeighborList.H:19
constexpr int iz
Definition: AMReX_Interp_3D_C.H:37
constexpr int iy
Definition: AMReX_Interp_2D_C.H:33
constexpr int ix
Definition: AMReX_Interp_2D_C.H:32
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & max(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:35
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & min(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:21
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 ubound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:315
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 lbound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:308
bool isSame(A const *pa, B const *pb)
Definition: AMReX_NeighborList.H:232
Definition: AMReX_FabArrayCommI.H:896
Definition: AMReX_ParticleUtil.H:296
Definition: AMReX_NeighborList.H:211
ParticleType * m_pstruct
Definition: AMReX_NeighborList.H:226
AMREX_GPU_HOST_DEVICE amrex::Neighbors< ParticleType > getNeighbors(int i) const
Definition: AMReX_NeighborList.H:221
NeighborData(const Gpu::DeviceVector< unsigned int > &offsets, const Gpu::DeviceVector< unsigned int > &list, ParticleType *pstruct)
Definition: AMReX_NeighborList.H:212
const unsigned int * m_nbor_list_ptr
Definition: AMReX_NeighborList.H:225
const unsigned int * m_nbor_offsets_ptr
Definition: AMReX_NeighborList.H:224
Definition: AMReX_NeighborList.H:131
const unsigned int * m_nbor_list_ptr
Definition: AMReX_NeighborList.H:152
AMREX_GPU_HOST_DEVICE const_iterator(int start, int stop, const unsigned int *nbor_list_ptr, const ParticleType *pstruct)
Definition: AMReX_NeighborList.H:133
AMREX_GPU_HOST_DEVICE bool operator!=(const_iterator const &) const
Definition: AMReX_NeighborList.H:141
int m_stop
Definition: AMReX_NeighborList.H:151
AMREX_GPU_HOST_DEVICE unsigned int index() const
Definition: AMReX_NeighborList.H:147
int m_index
Definition: AMReX_NeighborList.H:150
const ParticleType * m_pstruct
Definition: AMReX_NeighborList.H:153
AMREX_GPU_HOST_DEVICE const ParticleType & operator*() const
Definition: AMReX_NeighborList.H:144
AMREX_GPU_HOST_DEVICE void operator++()
Definition: AMReX_NeighborList.H:138
Definition: AMReX_NeighborList.H:105
const unsigned int * m_nbor_list_ptr
Definition: AMReX_NeighborList.H:126
AMREX_GPU_HOST_DEVICE iterator(int start, int stop, const unsigned int *nbor_list_ptr, ParticleType *pstruct)
Definition: AMReX_NeighborList.H:107
ParticleType * m_pstruct
Definition: AMReX_NeighborList.H:127
AMREX_GPU_HOST_DEVICE ParticleType & operator*() const
Definition: AMReX_NeighborList.H:118
int m_stop
Definition: AMReX_NeighborList.H:125
AMREX_GPU_HOST_DEVICE void operator++()
Definition: AMReX_NeighborList.H:112
AMREX_GPU_HOST_DEVICE unsigned int index() const
Definition: AMReX_NeighborList.H:121
int m_index
Definition: AMReX_NeighborList.H:124
AMREX_GPU_HOST_DEVICE bool operator!=(iterator const &) const
Definition: AMReX_NeighborList.H:115
Definition: AMReX_NeighborList.H:103
AMREX_GPU_HOST_DEVICE iterator end() noexcept
Definition: AMReX_NeighborList.H:163
AMREX_GPU_HOST_DEVICE const_iterator begin() const noexcept
Definition: AMReX_NeighborList.H:169
ParticleType * m_pstruct
Definition: AMReX_NeighborList.H:206
int m_i
Definition: AMReX_NeighborList.H:203
AMREX_GPU_HOST_DEVICE Neighbors(int i, const unsigned int *nbor_offsets_ptr, const unsigned int *nbor_list_ptr, ParticleType *pstruct)
Definition: AMReX_NeighborList.H:193
AMREX_GPU_HOST_DEVICE const_iterator cbegin() const noexcept
Definition: AMReX_NeighborList.H:181
AMREX_GPU_HOST_DEVICE const_iterator end() const noexcept
Definition: AMReX_NeighborList.H:175
const unsigned int * m_nbor_offsets_ptr
Definition: AMReX_NeighborList.H:204
AMREX_GPU_HOST_DEVICE const_iterator cend() const noexcept
Definition: AMReX_NeighborList.H:187
const unsigned int * m_nbor_list_ptr
Definition: AMReX_NeighborList.H:205
AMREX_GPU_HOST_DEVICE iterator begin() noexcept
Definition: AMReX_NeighborList.H:157