Cabana 0.8.0-dev
 
Loading...
Searching...
No Matches
Cabana_LinkedCellList.hpp
Go to the documentation of this file.
1/****************************************************************************
2 * Copyright (c) 2018-2023 by the Cabana authors *
3 * All rights reserved. *
4 * *
5 * This file is part of the Cabana library. Cabana is distributed under a *
6 * BSD 3-clause license. For the licensing terms see the LICENSE file in *
7 * the top-level directory. *
8 * *
9 * SPDX-License-Identifier: BSD-3-Clause *
10 ****************************************************************************/
11
16#ifndef CABANA_LINKEDCELLLIST_HPP
17#define CABANA_LINKEDCELLLIST_HPP
18
20#include <Cabana_Slice.hpp>
21#include <Cabana_Sort.hpp>
22#include <Cabana_Utils.hpp>
23#include <impl/Cabana_CartesianGrid.hpp>
24
25#include <Kokkos_Core.hpp>
26#include <Kokkos_Profiling_ScopedRegion.hpp>
27#include <Kokkos_ScatterView.hpp>
28
29#include <cassert>
30
31namespace Cabana
32{
33//---------------------------------------------------------------------------//
35
36template <class Scalar>
38{
40 Impl::CartesianGrid<Scalar> grid;
47
49 LinkedCellStencil() = default;
50
52 LinkedCellStencil( const Scalar neighborhood_radius,
53 const Scalar cell_size_ratio, const Scalar grid_min[3],
54 const Scalar grid_max[3] )
55 {
56 Scalar dx = neighborhood_radius * cell_size_ratio;
57 grid = Impl::CartesianGrid<Scalar>(
58 grid_min[0], grid_min[1], grid_min[2], grid_max[0], grid_max[1],
59 grid_max[2], dx, dx, dx );
60 cell_range = std::ceil( 1 / cell_size_ratio );
61 max_cells_dir = 2 * cell_range + 1;
63 }
64
66 KOKKOS_INLINE_FUNCTION
67 void getCells( const int cell, int& imin, int& imax, int& jmin, int& jmax,
68 int& kmin, int& kmax ) const
69 {
70 int i, j, k;
71 grid.ijkBinIndex( cell, i, j, k );
72
73 kmin = ( k - cell_range > 0 ) ? k - cell_range : 0;
74 kmax =
75 ( k + cell_range + 1 < grid._nz ) ? k + cell_range + 1 : grid._nz;
76
77 jmin = ( j - cell_range > 0 ) ? j - cell_range : 0;
78 jmax =
79 ( j + cell_range + 1 < grid._ny ) ? j + cell_range + 1 : grid._ny;
80
81 imin = ( i - cell_range > 0 ) ? i - cell_range : 0;
82 imax =
83 ( i + cell_range + 1 < grid._nx ) ? i + cell_range + 1 : grid._nx;
84 }
85};
86
87//---------------------------------------------------------------------------//
93template <class MemorySpace, class Scalar = double>
95{
96 public:
98 using memory_space = MemorySpace;
99 static_assert( Kokkos::is_memory_space<MemorySpace>() );
100
102 using execution_space = typename memory_space::execution_space;
104 using size_type = typename memory_space::size_type;
105
107 using CountView = Kokkos::View<int*, memory_space>;
109 using OffsetView = Kokkos::View<size_type*, memory_space>;
112
116 LinkedCellList() = default;
117
128 template <class PositionType>
130 PositionType positions, const Scalar grid_delta[3],
131 const Scalar grid_min[3], const Scalar grid_max[3],
132 typename std::enable_if<( is_slice<PositionType>::value ||
133 Kokkos::is_view<PositionType>::value ),
134 int>::type* = 0 )
135 : _begin( 0 )
136 , _end( size( positions ) )
137 , _grid( grid_min[0], grid_min[1], grid_min[2], grid_max[0],
138 grid_max[1], grid_max[2], grid_delta[0], grid_delta[1],
139 grid_delta[2] )
140 , _cell_stencil( grid_delta[0], 1.0, grid_min, grid_max )
141 , _sorted( false )
142 {
143 std::size_t np = size( positions );
144 allocate( totalBins(), np );
145 build( positions, 0, np );
146 }
147
164 template <class PositionType>
166 PositionType positions, const std::size_t begin, const std::size_t end,
167 const Scalar grid_delta[3], const Scalar grid_min[3],
168 const Scalar grid_max[3],
169 typename std::enable_if<( is_slice<PositionType>::value ||
170 Kokkos::is_view<PositionType>::value ),
171 int>::type* = 0 )
172 : _begin( begin )
173 , _end( end )
174 , _grid( grid_min[0], grid_min[1], grid_min[2], grid_max[0],
175 grid_max[1], grid_max[2], grid_delta[0], grid_delta[1],
176 grid_delta[2] )
177 , _cell_stencil( grid_delta[0], 1.0, grid_min, grid_max )
178 , _sorted( false )
179 {
180 allocate( totalBins(), end - begin );
181 build( positions, begin, end );
182 }
183
196 template <class PositionType>
198 PositionType positions, const Scalar grid_delta[3],
199 const Scalar grid_min[3], const Scalar grid_max[3],
200 const Scalar neighborhood_radius, const Scalar cell_size_ratio = 1,
201 typename std::enable_if<( is_slice<PositionType>::value ||
202 Kokkos::is_view<PositionType>::value ),
203 int>::type* = 0 )
204 : _begin( 0 )
205 , _end( size( positions ) )
206 , _grid( grid_min[0], grid_min[1], grid_min[2], grid_max[0],
207 grid_max[1], grid_max[2], grid_delta[0], grid_delta[1],
208 grid_delta[2] )
209 , _cell_stencil( neighborhood_radius, cell_size_ratio, grid_min,
210 grid_max )
211 , _sorted( false )
212 {
213 std::size_t np = size( positions );
214 allocate( totalBins(), np );
215 build( positions, 0, np );
216 }
217
236 template <class PositionType>
238 PositionType positions, const std::size_t begin, const std::size_t end,
239 const Scalar grid_delta[3], const Scalar grid_min[3],
240 const Scalar grid_max[3], const Scalar neighborhood_radius,
241 const Scalar cell_size_ratio = 1,
242 typename std::enable_if<( is_slice<PositionType>::value ||
243 Kokkos::is_view<PositionType>::value ),
244 int>::type* = 0 )
245 : _begin( begin )
246 , _end( end )
247 , _grid( grid_min[0], grid_min[1], grid_min[2], grid_max[0],
248 grid_max[1], grid_max[2], grid_delta[0], grid_delta[1],
249 grid_delta[2] )
250 , _cell_stencil( neighborhood_radius, cell_size_ratio, grid_min,
251 grid_max )
252 , _sorted( false )
253 {
254 allocate( totalBins(), end - begin );
255 build( positions, begin, end );
256 }
257
259 KOKKOS_INLINE_FUNCTION
260 int numParticles() const { return _permutes.extent( 0 ); }
261
263 KOKKOS_INLINE_FUNCTION
264 std::size_t getParticleBegin() const { return _begin; }
265
267 KOKKOS_INLINE_FUNCTION
268 std::size_t getParticleEnd() const { return _end; }
269
274 KOKKOS_INLINE_FUNCTION
275 int totalBins() const { return _grid.totalNumCells(); }
276
282 KOKKOS_INLINE_FUNCTION
283 int numBin( const int dim ) const { return _grid.numBin( dim ); }
284
295 KOKKOS_INLINE_FUNCTION
296 size_type cardinalBinIndex( const int i, const int j, const int k ) const
297 {
298 return _grid.cardinalCellIndex( i, j, k );
299 }
300
311 KOKKOS_INLINE_FUNCTION
312 void ijkBinIndex( const int cardinal, int& i, int& j, int& k ) const
313 {
314 _grid.ijkBinIndex( cardinal, i, j, k );
315 }
316
324 KOKKOS_INLINE_FUNCTION
325 int binSize( const int i, const int j, const int k ) const
326 {
327 return _bin_data.binSize( cardinalBinIndex( i, j, k ) );
328 }
329
337 KOKKOS_INLINE_FUNCTION
338 size_type binOffset( const int i, const int j, const int k ) const
339 {
340 return _bin_data.binOffset( cardinalBinIndex( i, j, k ) );
341 }
342
349 KOKKOS_INLINE_FUNCTION
350 size_type permutation( const int particle_id ) const
351 {
352 return _bin_data.permutation( particle_id );
353 }
354
358 KOKKOS_INLINE_FUNCTION
359 std::size_t rangeBegin() const { return _bin_data.rangeBegin(); }
360
364 KOKKOS_INLINE_FUNCTION
365 std::size_t rangeEnd() const { return _bin_data.rangeEnd(); }
366
371 KOKKOS_INLINE_FUNCTION
372 stencil_type cellStencil() const { return _cell_stencil; }
373
378 BinningData<MemorySpace> binningData() const { return _bin_data; }
379
394 template <class ExecutionSpace, class PositionType>
395 void build( ExecutionSpace, PositionType positions, const std::size_t begin,
396 const std::size_t end )
397 {
398 Kokkos::Profiling::ScopedRegion region(
399 "Cabana::LinkedCellList::build" );
400
402 assert( end >= begin );
403 assert( end <= size( positions ) );
404
405 // Resize the binning data. Note that the permutation vector spans
406 // only the length of begin-end;
407 std::size_t ncell = totalBins();
408 if ( _counts.extent( 0 ) != ncell )
409 {
410 Kokkos::resize( _counts, ncell );
411 Kokkos::resize( _offsets, ncell );
412 }
413 std::size_t nparticles = end - begin;
414 if ( _permutes.extent( 0 ) != nparticles )
415 {
416 Kokkos::resize( _permutes, nparticles );
417 }
418
419 // Get local copies of class data for lambda function capture.
420 auto grid = _grid;
421 auto counts = _counts;
422 auto offsets = _offsets;
423 auto permutes = _permutes;
424
425 // Count.
426 Kokkos::RangePolicy<ExecutionSpace> particle_range( begin, end );
427 Kokkos::deep_copy( _counts, 0 );
428 auto counts_sv = Kokkos::Experimental::create_scatter_view( _counts );
429 auto cell_count = KOKKOS_LAMBDA( const std::size_t p )
430 {
431 int i, j, k;
432 grid.locatePoint( positions( p, 0 ), positions( p, 1 ),
433 positions( p, 2 ), i, j, k );
434 auto counts_data = counts_sv.access();
435 counts_data( grid.cardinalCellIndex( i, j, k ) ) += 1;
436 };
437 Kokkos::parallel_for( "Cabana::LinkedCellList::build::cell_count",
438 particle_range, cell_count );
439 Kokkos::fence();
440 Kokkos::Experimental::contribute( _counts, counts_sv );
441
442 // Compute offsets.
443 Kokkos::RangePolicy<ExecutionSpace> cell_range( 0, ncell );
444 auto offset_scan = KOKKOS_LAMBDA( const std::size_t c, int& update,
445 const bool final_pass )
446 {
447 if ( final_pass )
448 offsets( c ) = update;
449 update += counts( c );
450 };
451 Kokkos::parallel_scan( "Cabana::LinkedCellList::build::offset_scan",
452 cell_range, offset_scan );
453 Kokkos::fence();
454
455 // Reset counts.
456 Kokkos::deep_copy( _counts, 0 );
457
458 // Compute the permutation vector.
459 auto create_permute = KOKKOS_LAMBDA( const std::size_t p )
460 {
461 int i, j, k;
462 grid.locatePoint( positions( p, 0 ), positions( p, 1 ),
463 positions( p, 2 ), i, j, k );
464 auto cell_id = grid.cardinalCellIndex( i, j, k );
465 int c = Kokkos::atomic_fetch_add( &counts( cell_id ), 1 );
466 permutes( offsets( cell_id ) + c ) = p;
467 };
468 Kokkos::parallel_for( "Cabana::LinkedCellList::build::create_permute",
469 particle_range, create_permute );
470 Kokkos::fence();
471
472 // Create the binning data.
473 _bin_data = BinningData<MemorySpace>( begin, end, _counts, _offsets,
474 _permutes );
475
476 // Store the bin per particle (for neighbor iteration).
478 }
479
493 template <class PositionType>
494 void build( PositionType positions, const std::size_t begin,
495 const std::size_t end )
496 {
497 // Use the default execution space.
498 build( execution_space{}, positions, begin, end );
499 }
500
508 template <class PositionType>
509 void build( PositionType positions )
510 {
511 build( positions, 0, size( positions ) );
512 }
513
518 {
519 Kokkos::parallel_for(
520 "Cabana::LinkedCellList::storeBinIndices",
521 Kokkos::RangePolicy<execution_space>( 0, totalBins() ), *this );
522 }
523
528 auto getParticleBins() const { return _particle_bins; }
529
533 KOKKOS_INLINE_FUNCTION
534 auto getParticleBin( const int particle_index ) const
535 {
536 assert( particle_index >= static_cast<int>( _begin ) );
537 assert( particle_index < static_cast<int>( _end ) );
538 return _particle_bins( particle_index - _begin );
539 }
540
545 KOKKOS_FUNCTION void operator()( const int i ) const
546 {
547 int bin_ijk[3];
548 ijkBinIndex( i, bin_ijk[0], bin_ijk[1], bin_ijk[2] );
549 auto offset = binOffset( bin_ijk[0], bin_ijk[1], bin_ijk[2] );
550 auto size = binSize( bin_ijk[0], bin_ijk[1], bin_ijk[2] );
551 for ( size_t p = offset; p < offset + size; ++p )
552 {
553 if ( _sorted )
554 {
555 _particle_bins( p ) = i;
556 }
557 else
558 {
559 _particle_bins( permutation( p ) - _begin ) = i;
560 }
561 }
562 }
563
568 void update( const bool sorted ) { _sorted = sorted; }
569
573 KOKKOS_INLINE_FUNCTION
574 auto sorted() const { return _sorted; }
575
579 KOKKOS_INLINE_FUNCTION
580 void getStencilCells( const int cell, int& imin, int& imax, int& jmin,
581 int& jmax, int& kmin, int& kmax ) const
582 {
583 _cell_stencil.getCells( cell, imin, imax, jmin, jmax, kmin, kmax );
584 }
585
590 KOKKOS_INLINE_FUNCTION
591 auto getParticle( const int offset ) const
592 {
593 std::size_t j;
594 if ( !sorted() )
595 j = permutation( offset );
596 else
597 j = offset + getParticleBegin();
598 return j;
599 }
600
601 private:
602 std::size_t _begin;
603 std::size_t _end;
604
605 // Building the linked cell.
606 BinningData<MemorySpace> _bin_data;
607 Impl::CartesianGrid<Scalar> _grid;
608
609 CountView _counts;
610 OffsetView _offsets;
611 OffsetView _permutes;
612
613 // Iterating over the linked cell.
614 stencil_type _cell_stencil;
615
616 bool _sorted;
617 CountView _particle_bins;
618
619 void allocate( const int ncell, const int nparticles )
620 {
621 _counts = CountView(
622 Kokkos::view_alloc( Kokkos::WithoutInitializing, "counts" ),
623 ncell );
624 _offsets = OffsetView(
625 Kokkos::view_alloc( Kokkos::WithoutInitializing, "offsets" ),
626 ncell );
627 _permutes = OffsetView(
628 Kokkos::view_alloc( Kokkos::WithoutInitializing, "permutes" ),
629 nparticles );
630 // This is only used for iterating over the particles (not building the
631 // permutaion vector).
632 _particle_bins = CountView(
633 Kokkos::view_alloc( Kokkos::WithoutInitializing, "counts" ),
634 nparticles );
635 }
636};
637
642template <class MemorySpace, class PositionType, class Scalar>
643auto createLinkedCellList( PositionType positions, const Scalar grid_delta[3],
644 const Scalar grid_min[3], const Scalar grid_max[3] )
645{
646 return LinkedCellList<MemorySpace, Scalar>( positions, grid_delta, grid_min,
647 grid_max );
648}
649
654template <class MemorySpace, class PositionType, class Scalar>
655auto createLinkedCellList( PositionType positions, const std::size_t begin,
656 const std::size_t end, const Scalar grid_delta[3],
657 const Scalar grid_min[3], const Scalar grid_max[3] )
658{
660 positions, begin, end, grid_delta, grid_min, grid_max );
661}
662
668template <class MemorySpace, class PositionType, class Scalar>
669auto createLinkedCellList( PositionType positions, const Scalar grid_delta[3],
670 const Scalar grid_min[3], const Scalar grid_max[3],
671 const Scalar neighborhood_radius,
672 const Scalar cell_size_ratio = 1.0 )
673{
674 return LinkedCellList<MemorySpace, Scalar>( positions, grid_delta, grid_min,
675 grid_max, neighborhood_radius,
676 cell_size_ratio );
677}
678
684template <class MemorySpace, class PositionType, class Scalar>
685auto createLinkedCellList( PositionType positions, const std::size_t begin,
686 const std::size_t end, const Scalar grid_delta[3],
687 const Scalar grid_min[3], const Scalar grid_max[3],
688 const Scalar neighborhood_radius,
689 const Scalar cell_size_ratio = 1.0 )
690{
692 positions, begin, end, grid_delta, grid_min, grid_max,
693 neighborhood_radius, cell_size_ratio );
694}
695
696//---------------------------------------------------------------------------//
698template <typename>
699struct is_linked_cell_list_impl : public std::false_type
700{
701};
702
703template <typename MemorySpace, typename Scalar>
704struct is_linked_cell_list_impl<LinkedCellList<MemorySpace, Scalar>>
705 : public std::true_type
706{
707};
709
711template <class T>
713 : public is_linked_cell_list_impl<typename std::remove_cv<T>::type>::type
714{
715};
716
717//---------------------------------------------------------------------------//
729template <class LinkedCellListType, class PositionType>
731 LinkedCellListType& linked_cell_list, PositionType& positions,
732 typename std::enable_if<( is_linked_cell_list<LinkedCellListType>::value &&
735 Kokkos::is_view<PositionType>::value ) ),
736 int>::type* = 0 )
737{
738 permute( linked_cell_list.binningData(), positions );
739
740 // Update internal state.
741 linked_cell_list.update( true );
742
743 linked_cell_list.storeParticleBins();
744}
745
746//---------------------------------------------------------------------------//
748template <class MemorySpace, typename Scalar>
749class NeighborList<LinkedCellList<MemorySpace, Scalar>>
750{
751 public:
753 using memory_space = MemorySpace;
756
758 KOKKOS_INLINE_FUNCTION static std::size_t
760 {
761 std::size_t total_n = 0;
762 // Sum neighbors across all particles in range.
763 for ( std::size_t p = list.getParticleBegin();
764 p < list.getParticleEnd(); p++ )
765 total_n += numNeighbor( list, p );
766 return total_n;
767 }
768
770 KOKKOS_INLINE_FUNCTION
771 static std::size_t maxNeighbor( const list_type& list )
772 {
773 std::size_t max_n = 0;
774 // Max neighbors across all particles in range.
775 for ( std::size_t p = list.getParticleBegin();
776 p < list.getParticleEnd(); p++ )
777 if ( numNeighbor( list, p ) > max_n )
778 max_n = numNeighbor( list, p );
779 return max_n;
780 }
781
783 KOKKOS_INLINE_FUNCTION static std::size_t
784 numNeighbor( const list_type& list, const std::size_t particle_index )
785 {
786 int total_count = 0;
787 int imin, imax, jmin, jmax, kmin, kmax;
788 list.getStencilCells( list.getParticleBin( particle_index ), imin, imax,
789 jmin, jmax, kmin, kmax );
790
791 // Loop over the cell stencil.
792 for ( int i = imin; i < imax; ++i )
793 for ( int j = jmin; j < jmax; ++j )
794 for ( int k = kmin; k < kmax; ++k )
795 {
796 total_count += list.binSize( i, j, k );
797 }
798 return total_count;
799 }
800
803 KOKKOS_INLINE_FUNCTION static std::size_t
804 getNeighbor( const list_type& list, const std::size_t particle_index,
805 const std::size_t neighbor_index )
806 {
807 std::size_t total_count = 0;
808 std::size_t previous_count = 0;
809 int imin, imax, jmin, jmax, kmin, kmax;
810 list.getStencilCells( list.getParticleBin( particle_index ), imin, imax,
811 jmin, jmax, kmin, kmax );
812
813 // Loop over the cell stencil.
814 for ( int i = imin; i < imax; ++i )
815 for ( int j = jmin; j < jmax; ++j )
816 for ( int k = kmin; k < kmax; ++k )
817 {
818 total_count += list.binSize( i, j, k );
819 // This neighbor is in this bin.
820 if ( total_count > neighbor_index )
821 {
822 int particle_id = list.binOffset( i, j, k ) +
823 ( neighbor_index - previous_count );
824 return list.getParticle( particle_id );
825 }
826 previous_count = total_count;
827 }
828
829 assert( total_count <= totalNeighbor( list ) );
830
831 // Should never make it to this point.
832 return 0;
833 }
834};
835
836} // end namespace Cabana
837
838#endif // end CABANA_SORT_HPP
Neighbor list interface.
Slice a single particle property from an AoSoA.
Sorting and binning built on Kokkos BinSort.
Cabana utilities.
Data describing the bin sizes and offsets resulting from a binning operation.
Definition Cabana_Sort.hpp:39
Data describing the bin sizes and offsets resulting from a binning operation on a 3d regular Cartesia...
Definition Cabana_LinkedCellList.hpp:95
Kokkos::View< size_type *, memory_space > OffsetView
Offset view type.
Definition Cabana_LinkedCellList.hpp:109
LinkedCellList(PositionType positions, const std::size_t begin, const std::size_t end, const Scalar grid_delta[3], const Scalar grid_min[3], const Scalar grid_max[3], typename std::enable_if<(is_slice< PositionType >::value||Kokkos::is_view< PositionType >::value), int >::type *=0)
Partial range constructor.
Definition Cabana_LinkedCellList.hpp:165
KOKKOS_INLINE_FUNCTION std::size_t getParticleBegin() const
Beginning of binned range.
Definition Cabana_LinkedCellList.hpp:264
void build(ExecutionSpace, PositionType positions, const std::size_t begin, const std::size_t end)
Build the linked cell list with a subset of particles.
Definition Cabana_LinkedCellList.hpp:395
void build(PositionType positions)
Build the linked cell list with all particles.
Definition Cabana_LinkedCellList.hpp:509
LinkedCellList(PositionType positions, const Scalar grid_delta[3], const Scalar grid_min[3], const Scalar grid_max[3], const Scalar neighborhood_radius, const Scalar cell_size_ratio=1, typename std::enable_if<(is_slice< PositionType >::value||Kokkos::is_view< PositionType >::value), int >::type *=0)
Explicit stencil constructor.
Definition Cabana_LinkedCellList.hpp:197
KOKKOS_INLINE_FUNCTION auto getParticleBin(const int particle_index) const
Get the bin cell index of the input particle.
Definition Cabana_LinkedCellList.hpp:534
LinkedCellList()=default
Default constructor.
KOKKOS_INLINE_FUNCTION int binSize(const int i, const int j, const int k) const
Given a bin get the number of particles it contains.
Definition Cabana_LinkedCellList.hpp:325
Kokkos::View< int *, memory_space > CountView
Binning view type.
Definition Cabana_LinkedCellList.hpp:107
KOKKOS_INLINE_FUNCTION int numParticles() const
Number of binned particles.
Definition Cabana_LinkedCellList.hpp:260
KOKKOS_INLINE_FUNCTION size_type cardinalBinIndex(const int i, const int j, const int k) const
Given the ijk index of a bin get its cardinal index.
Definition Cabana_LinkedCellList.hpp:296
KOKKOS_INLINE_FUNCTION void getStencilCells(const int cell, int &imin, int &imax, int &jmin, int &jmax, int &kmin, int &kmax) const
Get the cell indices for the stencil about cell.
Definition Cabana_LinkedCellList.hpp:580
KOKKOS_INLINE_FUNCTION stencil_type cellStencil() const
Get the linked cell stencil.
Definition Cabana_LinkedCellList.hpp:372
KOKKOS_INLINE_FUNCTION size_type binOffset(const int i, const int j, const int k) const
Given a bin get the particle index at which it sorts.
Definition Cabana_LinkedCellList.hpp:338
Cabana::LinkedCellStencil< Scalar > stencil_type
Stencil type.
Definition Cabana_LinkedCellList.hpp:111
MemorySpace memory_space
Kokkos memory space.
Definition Cabana_LinkedCellList.hpp:98
KOKKOS_INLINE_FUNCTION auto getParticle(const int offset) const
Get a candidate neighbor particle at a given binned offset.
Definition Cabana_LinkedCellList.hpp:591
KOKKOS_INLINE_FUNCTION size_type permutation(const int particle_id) const
Given a local particle id in the binned layout, get the id of the particle in the old (unbinned) layo...
Definition Cabana_LinkedCellList.hpp:350
LinkedCellList(PositionType positions, const Scalar grid_delta[3], const Scalar grid_min[3], const Scalar grid_max[3], typename std::enable_if<(is_slice< PositionType >::value||Kokkos::is_view< PositionType >::value), int >::type *=0)
Simple constructor.
Definition Cabana_LinkedCellList.hpp:129
typename memory_space::size_type size_type
Memory space size type.
Definition Cabana_LinkedCellList.hpp:104
KOKKOS_INLINE_FUNCTION std::size_t getParticleEnd() const
End of binned range.
Definition Cabana_LinkedCellList.hpp:268
KOKKOS_INLINE_FUNCTION auto sorted() const
Definition Cabana_LinkedCellList.hpp:574
auto getParticleBins() const
Get the bin cell index for each binned particle.
Definition Cabana_LinkedCellList.hpp:528
KOKKOS_INLINE_FUNCTION int totalBins() const
Get the total number of bins.
Definition Cabana_LinkedCellList.hpp:275
void update(const bool sorted)
Definition Cabana_LinkedCellList.hpp:568
KOKKOS_INLINE_FUNCTION void ijkBinIndex(const int cardinal, int &i, int &j, int &k) const
Given the cardinal index of a bin get its ijk indices.
Definition Cabana_LinkedCellList.hpp:312
void build(PositionType positions, const std::size_t begin, const std::size_t end)
Build the linked cell list with a subset of particles.
Definition Cabana_LinkedCellList.hpp:494
KOKKOS_FUNCTION void operator()(const int i) const
Determines which particles belong to bin i.
Definition Cabana_LinkedCellList.hpp:545
LinkedCellList(PositionType positions, const std::size_t begin, const std::size_t end, const Scalar grid_delta[3], const Scalar grid_min[3], const Scalar grid_max[3], const Scalar neighborhood_radius, const Scalar cell_size_ratio=1, typename std::enable_if<(is_slice< PositionType >::value||Kokkos::is_view< PositionType >::value), int >::type *=0)
Explicit stencil and partial range constructor.
Definition Cabana_LinkedCellList.hpp:237
typename memory_space::execution_space execution_space
Default execution space.
Definition Cabana_LinkedCellList.hpp:102
BinningData< MemorySpace > binningData() const
Get the 1d bin data.
Definition Cabana_LinkedCellList.hpp:378
KOKKOS_INLINE_FUNCTION std::size_t rangeBegin() const
The beginning particle index binned by the linked cell list.
Definition Cabana_LinkedCellList.hpp:359
void storeParticleBins()
Store the bin cell index for each binned particle.
Definition Cabana_LinkedCellList.hpp:517
KOKKOS_INLINE_FUNCTION std::size_t rangeEnd() const
The ending particle index binned by the linked cell list.
Definition Cabana_LinkedCellList.hpp:365
KOKKOS_INLINE_FUNCTION int numBin(const int dim) const
Get the number of bins in a given dimension.
Definition Cabana_LinkedCellList.hpp:283
MemorySpace memory_space
Kokkos memory space.
Definition Cabana_LinkedCellList.hpp:753
static KOKKOS_INLINE_FUNCTION std::size_t numNeighbor(const list_type &list, const std::size_t particle_index)
Get the number of neighbors for a given particle index.
Definition Cabana_LinkedCellList.hpp:784
LinkedCellList< MemorySpace, Scalar > list_type
Neighbor list type.
Definition Cabana_LinkedCellList.hpp:755
static KOKKOS_INLINE_FUNCTION std::size_t maxNeighbor(const list_type &list)
Get the maximum number of neighbors per particles.
Definition Cabana_LinkedCellList.hpp:771
static KOKKOS_INLINE_FUNCTION std::size_t getNeighbor(const list_type &list, const std::size_t particle_index, const std::size_t neighbor_index)
Definition Cabana_LinkedCellList.hpp:804
static KOKKOS_INLINE_FUNCTION std::size_t totalNeighbor(const list_type &list)
Get the total number of neighbors across all particles.
Definition Cabana_LinkedCellList.hpp:759
Neighbor list interface. Provides an interface callable at the functor level that gives access to nei...
Definition Cabana_NeighborList.hpp:114
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 totalNeighbor(const NeighborListType &list)
Get the total number of neighbors across all particles.
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36
auto size(SliceType slice, typename std::enable_if< is_slice< SliceType >::value, int >::type *=0)
Check slice size (differs from Kokkos View).
Definition Cabana_Slice.hpp:1019
void permute(LinkedCellListType &linked_cell_list, PositionType &positions, typename std::enable_if<(is_linked_cell_list< LinkedCellListType >::value &&(is_aosoa< PositionType >::value||is_slice< PositionType >::value||Kokkos::is_view< PositionType >::value)), int >::type *=0)
Given a linked cell list permute positions.
Definition Cabana_LinkedCellList.hpp:730
auto createLinkedCellList(PositionType positions, const Scalar grid_delta[3], const Scalar grid_min[3], const Scalar grid_max[3])
Creation function for linked cell list.
Definition Cabana_LinkedCellList.hpp:643
Stencil of cells surrounding each cell.
Definition Cabana_LinkedCellList.hpp:38
int cell_range
Range of cells to search based on cutoff.
Definition Cabana_LinkedCellList.hpp:46
LinkedCellStencil(const Scalar neighborhood_radius, const Scalar cell_size_ratio, const Scalar grid_min[3], const Scalar grid_max[3])
Constructor.
Definition Cabana_LinkedCellList.hpp:52
int max_cells
Maximum total cells.
Definition Cabana_LinkedCellList.hpp:44
int max_cells_dir
Maximum cells per dimension.
Definition Cabana_LinkedCellList.hpp:42
LinkedCellStencil()=default
Default Constructor.
Impl::CartesianGrid< Scalar > grid
Background grid.
Definition Cabana_LinkedCellList.hpp:40
KOKKOS_INLINE_FUNCTION void getCells(const int cell, int &imin, int &imax, int &jmin, int &jmax, int &kmin, int &kmax) const
Given a cell, get the index bounds of the cell stencil.
Definition Cabana_LinkedCellList.hpp:67
Definition Cabana_Types.hpp:88
AoSoA static type checker.
Definition Cabana_AoSoA.hpp:61
LinkedCellList static type checker.
Definition Cabana_LinkedCellList.hpp:714
Slice static type checker.
Definition Cabana_Slice.hpp:868