16#ifndef CABANA_NEIGHBORLIST_HPP
17#define CABANA_NEIGHBORLIST_HPP
19#include <Kokkos_Core.hpp>
78 KOKKOS_INLINE_FUNCTION
79 static bool isValid(
const std::size_t p,
const std::size_t n )
98 template <std::
size_t NumSpaceDim>
99 KOKKOS_INLINE_FUNCTION
static bool
100 isValid(
const std::size_t p,
const Kokkos::Array<double, NumSpaceDim>,
101 const std::size_t n,
const Kokkos::Array<double, NumSpaceDim> )
114 KOKKOS_INLINE_FUNCTION
115 static bool isValid(
const std::size_t p,
const double,
const double,
116 const double,
const std::size_t n,
const double,
117 const double,
const double )
139 template <std::
size_t NumSpaceDim>
140 KOKKOS_INLINE_FUNCTION
static bool
141 isValid(
const std::size_t p,
const Kokkos::Array<double, NumSpaceDim> xp,
142 const std::size_t n,
const Kokkos::Array<double, NumSpaceDim> xn )
144 return ( ( p != n ) &&
145 ( ( xn[0] > xp[0] ) ||
146 ( ( xn[0] == xp[0] ) &&
147 ( ( xn[1] > xp[1] ) ||
148 ( ( xn[1] == xp[1] ) && ( xn[2] > xp[2] ) ) ) ) ) );
162 KOKKOS_INLINE_FUNCTION
static bool
163 isValid(
const std::size_t p,
const Kokkos::Array<double, 3> xp,
164 const std::size_t n,
const Kokkos::Array<double, 3> xn )
166 return ( ( p != n ) &&
167 ( ( xn[0] > xp[0] ) ||
168 ( ( xn[0] == xp[0] ) &&
169 ( ( xn[1] > xp[1] ) ||
170 ( ( xn[1] == xp[1] ) && ( xn[2] > xp[2] ) ) ) ) ) );
184 KOKKOS_INLINE_FUNCTION
static bool
185 isValid(
const std::size_t p,
const Kokkos::Array<double, 2> xp,
186 const std::size_t n,
const Kokkos::Array<double, 2> xn )
188 return ( ( p != n ) &&
189 ( ( xn[0] > xp[0] ) ||
190 ( ( xn[0] == xp[0] ) && ( ( xn[1] > xp[1] ) ) ) ) );
204 KOKKOS_INLINE_FUNCTION
static bool
205 isValid(
const std::size_t p,
const double xp,
const double yp,
206 const double zp,
const std::size_t n,
const double xn,
207 const double yn,
const double zn )
209 return ( ( p != n ) &&
212 ( ( yn > yp ) || ( ( yn == yp ) && ( zn > zp ) ) ) ) ) );
221template <
class NeighborListType>
229 KOKKOS_INLINE_FUNCTION
233 KOKKOS_INLINE_FUNCTION
237 KOKKOS_INLINE_FUNCTION
239 const std::size_t particle_index );
242 KOKKOS_INLINE_FUNCTION
244 const std::size_t particle_index,
245 const std::size_t neighbor_index );
248 KOKKOS_INLINE_FUNCTION
250 const std::size_t particle_index,
251 const std::size_t neighbor_index );
259template <
class ListType>
260KOKKOS_INLINE_FUNCTION std::size_t
263 std::size_t total_n = 0;
265 for ( std::size_t p = 0; p < num_particles; p++ )
271template <
class ListType>
272KOKKOS_INLINE_FUNCTION std::size_t
273maxNeighbor(
const ListType& list,
const std::size_t num_particles )
275 std::size_t max_n = 0;
276 for ( std::size_t p = 0; p < num_particles; p++ )
291template <
class ExecutionSpace,
class ListType>
292Kokkos::View<int* [2], typename ListType::memory_space>
294 const ListType& list,
const int num_bin )
297 auto num_neigh = Kokkos::View<int*, typename ListType::memory_space>(
298 "particle_count", num_particles );
301 auto extract_functor = KOKKOS_LAMBDA(
const int p )
305 Kokkos::RangePolicy<ExecutionSpace> particle_policy( exec_space, 0,
307 Kokkos::parallel_for(
"Cabana::NeighborList::neighborHistogram::extract",
308 particle_policy, extract_functor );
313 auto histogram = Kokkos::View<int* [2], typename ListType::memory_space>(
314 "particle_count", num_bin, 2 );
315 auto histogram_functor = KOKKOS_LAMBDA(
const int b )
319 static_cast<double>( max_neigh ) /
static_cast<double>( num_bin );
320 if ( num_bin > max_neigh )
323 histogram( b, 0 ) =
static_cast<int>( ( b + 1 ) * bin_width );
324 histogram( b, 1 ) = bin_data.binSize( b );
326 Kokkos::RangePolicy<ExecutionSpace> bin_policy( exec_space, 0, num_bin );
327 Kokkos::parallel_for(
"Cabana::NeighborList::neighborHistogram", bin_policy,
KOKKOS_INLINE_FUNCTION std::size_t maxNeighbor(const ListType &list, const std::size_t num_particles)
Iterate to find the maximum number of neighbors.
Definition Cabana_NeighborList.hpp:273
KOKKOS_INLINE_FUNCTION std::size_t totalNeighbor(const ListType &list, const std::size_t num_particles)
Iterate to get the total number of neighbors.
Definition Cabana_NeighborList.hpp:261
Sorting and binning built on Kokkos BinSort.
Tag for building full neighbor lists.
Definition Cabana_NeighborList.hpp:36
Tag for building half neighbor lists.
Definition Cabana_NeighborList.hpp:49
static KOKKOS_INLINE_FUNCTION bool isValid(const std::size_t p, const double, const double, const double, const std::size_t n, const double, const double, const double)
Check whether neighbor pair is valid.
Definition Cabana_NeighborList.hpp:115
static KOKKOS_INLINE_FUNCTION bool isValid(const std::size_t p, const Kokkos::Array< double, NumSpaceDim >, const std::size_t n, const Kokkos::Array< double, NumSpaceDim >)
Check whether neighbor pair is valid.
Definition Cabana_NeighborList.hpp:100
static KOKKOS_INLINE_FUNCTION bool isValid(const std::size_t p, const Kokkos::Array< double, NumSpaceDim > xp, const std::size_t n, const Kokkos::Array< double, NumSpaceDim > xn)
Check whether neighbor pair is valid.
Definition Cabana_NeighborList.hpp:141
static KOKKOS_INLINE_FUNCTION bool isValid(const std::size_t p, const Kokkos::Array< double, 3 > xp, const std::size_t n, const Kokkos::Array< double, 3 > xn)
Check whether neighbor pair is valid.
Definition Cabana_NeighborList.hpp:163
static KOKKOS_INLINE_FUNCTION bool isValid(const std::size_t p, const Kokkos::Array< double, 2 > xp, const std::size_t n, const Kokkos::Array< double, 2 > xn)
Check whether neighbor pair is valid.
Definition Cabana_NeighborList.hpp:185
static KOKKOS_INLINE_FUNCTION bool isValid(const std::size_t p, const double xp, const double yp, const double zp, const std::size_t n, const double xn, const double yn, const double zn)
Check whether neighbor pair is valid.
Definition Cabana_NeighborList.hpp:205
static KOKKOS_INLINE_FUNCTION bool isValid(const std::size_t p, const std::size_t n)
Check whether neighbor pair is valid.
Definition Cabana_NeighborList.hpp:79
Neighborhood discriminator.
Definition Cabana_NeighborList.hpp:63
Neighbor list interface. Provides an interface callable at the functor level that gives access to nei...
Definition Cabana_NeighborList.hpp:223
typename NeighborListType::memory_space memory_space
Kokkos memory space.
Definition Cabana_NeighborList.hpp:226
KOKKOS_INLINE_FUNCTION std::size_t setNeighbor(NeighborListType &list, const std::size_t particle_index, const std::size_t neighbor_index)
Set the id for a neighbor for a given particle index and neighbor index.
static KOKKOS_INLINE_FUNCTION std::size_t numNeighbor(const NeighborListType &list, const std::size_t particle_index)
Get the number of neighbors for a given particle index.
static KOKKOS_INLINE_FUNCTION std::size_t getNeighbor(const NeighborListType &list, const std::size_t particle_index, const std::size_t neighbor_index)
Get the id for a neighbor for a given particle index and neighbor index.
static KOKKOS_INLINE_FUNCTION std::size_t totalNeighbor(const NeighborListType &list)
Get the total number of neighbors across all particles.
static KOKKOS_INLINE_FUNCTION std::size_t maxNeighbor(const NeighborListType &list)
Get the maximum number of neighbors across all particles.
Tag for neighbor list iteration, ignoring only self neighbors.
Definition Cabana_NeighborList.hpp:57
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36
auto binByKey(KeyViewType keys, const int nbin, const std::size_t begin, const std::size_t end, typename std::enable_if<(Kokkos::is_view< KeyViewType >::value), int >::type *=0)
Bin an AoSoA over a subset of its range based on the associated key values and number of bins....
Definition Cabana_Sort.hpp:413
Kokkos::View< int *[2], typename ListType::memory_space > neighborHistogram(ExecutionSpace exec_space, const std::size_t num_particles, const ListType &list, const int num_bin)
Construct a histogram of neighbors per particle.
Definition Cabana_NeighborList.hpp:293