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
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:
97 // FIXME: add static_assert that this is a valid MemorySpace.
98
99 // FIXME: extracting the self type for backwards compatibility with previous
100 // template on DeviceType. Should simply be MemorySpace after next release.
102 using memory_space = typename MemorySpace::memory_space;
103 // FIXME: replace warning with memory space assert after next release.
104 static_assert( Impl::deprecated( Kokkos::is_device<MemorySpace>() ) );
105
107 using device_type [[deprecated]] = typename memory_space::device_type;
109 using execution_space = typename memory_space::execution_space;
111 using size_type = typename memory_space::size_type;
112
114 using CountView = Kokkos::View<int*, memory_space>;
116 using OffsetView = Kokkos::View<size_type*, memory_space>;
119
124
135 template <class PositionType>
137 PositionType positions, const Scalar grid_delta[3],
138 const Scalar grid_min[3], const Scalar grid_max[3],
139 typename std::enable_if<( is_slice<PositionType>::value ||
140 Kokkos::is_view<PositionType>::value ),
141 int>::type* = 0 )
142 : _begin( 0 )
143 , _end( size( positions ) )
144 , _grid( grid_min[0], grid_min[1], grid_min[2], grid_max[0],
145 grid_max[1], grid_max[2], grid_delta[0], grid_delta[1],
146 grid_delta[2] )
147 , _cell_stencil( grid_delta[0], 1.0, grid_min, grid_max )
148 , _sorted( false )
149 {
150 std::size_t np = size( positions );
151 allocate( totalBins(), np );
152 build( positions, 0, np );
153 }
154
171 template <class PositionType>
173 PositionType positions, const std::size_t begin, const std::size_t end,
174 const Scalar grid_delta[3], const Scalar grid_min[3],
175 const Scalar grid_max[3],
176 typename std::enable_if<( is_slice<PositionType>::value ||
177 Kokkos::is_view<PositionType>::value ),
178 int>::type* = 0 )
179 : _begin( begin )
180 , _end( end )
181 , _grid( grid_min[0], grid_min[1], grid_min[2], grid_max[0],
182 grid_max[1], grid_max[2], grid_delta[0], grid_delta[1],
183 grid_delta[2] )
184 , _cell_stencil( grid_delta[0], 1.0, grid_min, grid_max )
185 , _sorted( false )
186 {
187 allocate( totalBins(), end - begin );
188 build( positions, begin, end );
189 }
190
203 template <class PositionType>
205 PositionType positions, const Scalar grid_delta[3],
206 const Scalar grid_min[3], const Scalar grid_max[3],
207 const Scalar neighborhood_radius, const Scalar cell_size_ratio = 1,
208 typename std::enable_if<( is_slice<PositionType>::value ||
209 Kokkos::is_view<PositionType>::value ),
210 int>::type* = 0 )
211 : _begin( 0 )
212 , _end( size( positions ) )
213 , _grid( grid_min[0], grid_min[1], grid_min[2], grid_max[0],
214 grid_max[1], grid_max[2], grid_delta[0], grid_delta[1],
215 grid_delta[2] )
216 , _cell_stencil( neighborhood_radius, cell_size_ratio, grid_min,
217 grid_max )
218 , _sorted( false )
219 {
220 std::size_t np = size( positions );
221 allocate( totalBins(), np );
222 build( positions, 0, np );
223 }
224
243 template <class PositionType>
245 PositionType positions, const std::size_t begin, const std::size_t end,
246 const Scalar grid_delta[3], const Scalar grid_min[3],
247 const Scalar grid_max[3], const Scalar neighborhood_radius,
248 const Scalar cell_size_ratio = 1,
249 typename std::enable_if<( is_slice<PositionType>::value ||
250 Kokkos::is_view<PositionType>::value ),
251 int>::type* = 0 )
252 : _begin( begin )
253 , _end( end )
254 , _grid( grid_min[0], grid_min[1], grid_min[2], grid_max[0],
255 grid_max[1], grid_max[2], grid_delta[0], grid_delta[1],
256 grid_delta[2] )
257 , _cell_stencil( neighborhood_radius, cell_size_ratio, grid_min,
258 grid_max )
259 , _sorted( false )
260 {
261 allocate( totalBins(), end - begin );
262 build( positions, begin, end );
263 }
264
266 KOKKOS_INLINE_FUNCTION
267 int numParticles() const { return _permutes.extent( 0 ); }
268
270 KOKKOS_INLINE_FUNCTION
271 std::size_t getParticleBegin() const { return _begin; }
272
274 KOKKOS_INLINE_FUNCTION
275 std::size_t getParticleEnd() const { return _end; }
276
281 KOKKOS_INLINE_FUNCTION
282 int totalBins() const { return _grid.totalNumCells(); }
283
289 KOKKOS_INLINE_FUNCTION
290 int numBin( const int dim ) const { return _grid.numBin( dim ); }
291
302 KOKKOS_INLINE_FUNCTION
303 size_type cardinalBinIndex( const int i, const int j, const int k ) const
304 {
305 return _grid.cardinalCellIndex( i, j, k );
306 }
307
318 KOKKOS_INLINE_FUNCTION
319 void ijkBinIndex( const int cardinal, int& i, int& j, int& k ) const
320 {
321 _grid.ijkBinIndex( cardinal, i, j, k );
322 }
323
331 KOKKOS_INLINE_FUNCTION
332 int binSize( const int i, const int j, const int k ) const
333 {
334 return _bin_data.binSize( cardinalBinIndex( i, j, k ) );
335 }
336
344 KOKKOS_INLINE_FUNCTION
345 size_type binOffset( const int i, const int j, const int k ) const
346 {
347 return _bin_data.binOffset( cardinalBinIndex( i, j, k ) );
348 }
349
356 KOKKOS_INLINE_FUNCTION
357 size_type permutation( const int particle_id ) const
358 {
359 return _bin_data.permutation( particle_id );
360 }
361
365 KOKKOS_INLINE_FUNCTION
366 std::size_t rangeBegin() const { return _bin_data.rangeBegin(); }
367
371 KOKKOS_INLINE_FUNCTION
372 std::size_t rangeEnd() const { return _bin_data.rangeEnd(); }
373
378 KOKKOS_INLINE_FUNCTION
379 stencil_type cellStencil() const { return _cell_stencil; }
380
385 BinningData<MemorySpace> binningData() const { return _bin_data; }
386
401 template <class ExecutionSpace, class PositionType>
402 void build( ExecutionSpace, PositionType positions, const std::size_t begin,
403 const std::size_t end )
404 {
405 Kokkos::Profiling::ScopedRegion region(
406 "Cabana::LinkedCellList::build" );
407
409 assert( end >= begin );
410 assert( end <= size( positions ) );
411
412 // Resize the binning data. Note that the permutation vector spans
413 // only the length of begin-end;
414 std::size_t ncell = totalBins();
415 if ( _counts.extent( 0 ) != ncell )
416 {
417 Kokkos::resize( _counts, ncell );
418 Kokkos::resize( _offsets, ncell );
419 }
420 std::size_t nparticles = end - begin;
421 if ( _permutes.extent( 0 ) != nparticles )
422 {
423 Kokkos::resize( _permutes, nparticles );
424 }
425
426 // Get local copies of class data for lambda function capture.
427 auto grid = _grid;
428 auto counts = _counts;
429 auto offsets = _offsets;
430 auto permutes = _permutes;
431
432 // Count.
433 Kokkos::RangePolicy<ExecutionSpace> particle_range( begin, end );
434 Kokkos::deep_copy( _counts, 0 );
435 auto counts_sv = Kokkos::Experimental::create_scatter_view( _counts );
436 auto cell_count = KOKKOS_LAMBDA( const std::size_t p )
437 {
438 int i, j, k;
439 grid.locatePoint( positions( p, 0 ), positions( p, 1 ),
440 positions( p, 2 ), i, j, k );
441 auto counts_data = counts_sv.access();
442 counts_data( grid.cardinalCellIndex( i, j, k ) ) += 1;
443 };
444 Kokkos::parallel_for( "Cabana::LinkedCellList::build::cell_count",
445 particle_range, cell_count );
446 Kokkos::fence();
447 Kokkos::Experimental::contribute( _counts, counts_sv );
448
449 // Compute offsets.
450 Kokkos::RangePolicy<ExecutionSpace> cell_range( 0, ncell );
451 auto offset_scan = KOKKOS_LAMBDA( const std::size_t c, int& update,
452 const bool final_pass )
453 {
454 if ( final_pass )
455 offsets( c ) = update;
456 update += counts( c );
457 };
458 Kokkos::parallel_scan( "Cabana::LinkedCellList::build::offset_scan",
459 cell_range, offset_scan );
460 Kokkos::fence();
461
462 // Reset counts.
463 Kokkos::deep_copy( _counts, 0 );
464
465 // Compute the permutation vector.
466 auto create_permute = KOKKOS_LAMBDA( const std::size_t p )
467 {
468 int i, j, k;
469 grid.locatePoint( positions( p, 0 ), positions( p, 1 ),
470 positions( p, 2 ), i, j, k );
471 auto cell_id = grid.cardinalCellIndex( i, j, k );
472 int c = Kokkos::atomic_fetch_add( &counts( cell_id ), 1 );
473 permutes( offsets( cell_id ) + c ) = p;
474 };
475 Kokkos::parallel_for( "Cabana::LinkedCellList::build::create_permute",
476 particle_range, create_permute );
477 Kokkos::fence();
478
479 // Create the binning data.
480 _bin_data = BinningData<MemorySpace>( begin, end, _counts, _offsets,
481 _permutes );
482
483 // Store the bin per particle (for neighbor iteration).
485 }
486
500 template <class PositionType>
501 void build( PositionType positions, const std::size_t begin,
502 const std::size_t end )
503 {
504 // Use the default execution space.
505 build( execution_space{}, positions, begin, end );
506 }
507
515 template <class PositionType>
516 void build( PositionType positions )
517 {
518 build( positions, 0, size( positions ) );
519 }
520
525 {
526 Kokkos::parallel_for(
527 "Cabana::LinkedCellList::storeBinIndices",
528 Kokkos::RangePolicy<execution_space>( 0, totalBins() ), *this );
529 }
530
535 auto getParticleBins() const { return _particle_bins; }
536
540 KOKKOS_INLINE_FUNCTION
541 auto getParticleBin( const int particle_index ) const
542 {
543 assert( particle_index >= static_cast<int>( _begin ) );
544 assert( particle_index < static_cast<int>( _end ) );
545 return _particle_bins( particle_index - _begin );
546 }
547
552 KOKKOS_FUNCTION void operator()( const int i ) const
553 {
554 int bin_ijk[3];
555 ijkBinIndex( i, bin_ijk[0], bin_ijk[1], bin_ijk[2] );
556 auto offset = binOffset( bin_ijk[0], bin_ijk[1], bin_ijk[2] );
557 auto size = binSize( bin_ijk[0], bin_ijk[1], bin_ijk[2] );
558 for ( size_t p = offset; p < offset + size; ++p )
559 {
560 if ( _sorted )
561 {
562 _particle_bins( p ) = i;
563 }
564 else
565 {
566 _particle_bins( permutation( p ) - _begin ) = i;
567 }
568 }
569 }
570
575 void update( const bool sorted ) { _sorted = sorted; }
576
580 KOKKOS_INLINE_FUNCTION
581 auto sorted() const { return _sorted; }
582
586 KOKKOS_INLINE_FUNCTION
587 void getStencilCells( const int cell, int& imin, int& imax, int& jmin,
588 int& jmax, int& kmin, int& kmax ) const
589 {
590 _cell_stencil.getCells( cell, imin, imax, jmin, jmax, kmin, kmax );
591 }
592
597 KOKKOS_INLINE_FUNCTION
598 auto getParticle( const int offset ) const
599 {
600 std::size_t j;
601 if ( !sorted() )
602 j = permutation( offset );
603 else
604 j = offset + getParticleBegin();
605 return j;
606 }
607
608 private:
609 std::size_t _begin;
610 std::size_t _end;
611
612 // Building the linked cell.
613 BinningData<MemorySpace> _bin_data;
614 Impl::CartesianGrid<Scalar> _grid;
615
616 CountView _counts;
617 OffsetView _offsets;
618 OffsetView _permutes;
619
620 // Iterating over the linked cell.
621 stencil_type _cell_stencil;
622
623 bool _sorted;
624 CountView _particle_bins;
625
626 void allocate( const int ncell, const int nparticles )
627 {
628 _counts = CountView(
629 Kokkos::view_alloc( Kokkos::WithoutInitializing, "counts" ),
630 ncell );
631 _offsets = OffsetView(
632 Kokkos::view_alloc( Kokkos::WithoutInitializing, "offsets" ),
633 ncell );
634 _permutes = OffsetView(
635 Kokkos::view_alloc( Kokkos::WithoutInitializing, "permutes" ),
636 nparticles );
637 // This is only used for iterating over the particles (not building the
638 // permutaion vector).
639 _particle_bins = CountView(
640 Kokkos::view_alloc( Kokkos::WithoutInitializing, "counts" ),
641 nparticles );
642 }
643};
644
649template <class MemorySpace, class PositionType, class Scalar>
650auto createLinkedCellList( PositionType positions, const Scalar grid_delta[3],
651 const Scalar grid_min[3], const Scalar grid_max[3] )
652{
653 return LinkedCellList<MemorySpace, Scalar>( positions, grid_delta, grid_min,
654 grid_max );
655}
656
661template <class MemorySpace, class PositionType, class Scalar>
662auto createLinkedCellList( PositionType positions, const std::size_t begin,
663 const std::size_t end, const Scalar grid_delta[3],
664 const Scalar grid_min[3], const Scalar grid_max[3] )
665{
667 positions, begin, end, grid_delta, grid_min, grid_max );
668}
669
675template <class MemorySpace, class PositionType, class Scalar>
676auto createLinkedCellList( PositionType positions, const Scalar grid_delta[3],
677 const Scalar grid_min[3], const Scalar grid_max[3],
678 const Scalar neighborhood_radius,
679 const Scalar cell_size_ratio = 1.0 )
680{
681 return LinkedCellList<MemorySpace, Scalar>( positions, grid_delta, grid_min,
682 grid_max, neighborhood_radius,
683 cell_size_ratio );
684}
685
691template <class MemorySpace, class PositionType, class Scalar>
692auto createLinkedCellList( PositionType positions, const std::size_t begin,
693 const std::size_t end, const Scalar grid_delta[3],
694 const Scalar grid_min[3], const Scalar grid_max[3],
695 const Scalar neighborhood_radius,
696 const Scalar cell_size_ratio = 1.0 )
697{
699 positions, begin, end, grid_delta, grid_min, grid_max,
700 neighborhood_radius, cell_size_ratio );
701}
702
703//---------------------------------------------------------------------------//
705template <typename>
706struct is_linked_cell_list_impl : public std::false_type
707{
708};
709
710template <typename MemorySpace, typename Scalar>
711struct is_linked_cell_list_impl<LinkedCellList<MemorySpace, Scalar>>
712 : public std::true_type
713{
714};
716
718template <class T>
720 : public is_linked_cell_list_impl<typename std::remove_cv<T>::type>::type
721{
722};
723
724//---------------------------------------------------------------------------//
736template <class LinkedCellListType, class PositionType>
738 LinkedCellListType& linked_cell_list, PositionType& positions,
739 typename std::enable_if<( is_linked_cell_list<LinkedCellListType>::value &&
742 Kokkos::is_view<PositionType>::value ) ),
743 int>::type* = 0 )
744{
745 permute( linked_cell_list.binningData(), positions );
746
747 // Update internal state.
748 linked_cell_list.update( true );
749
750 linked_cell_list.storeParticleBins();
751}
752
753//---------------------------------------------------------------------------//
755template <class MemorySpace, typename Scalar>
756class NeighborList<LinkedCellList<MemorySpace, Scalar>>
757{
758 public:
760 using memory_space = MemorySpace;
763
765 KOKKOS_INLINE_FUNCTION static std::size_t
767 {
768 std::size_t total_n = 0;
769 // Sum neighbors across all particles in range.
770 for ( std::size_t p = list.getParticleBegin();
771 p < list.getParticleEnd(); p++ )
772 total_n += numNeighbor( list, p );
773 return total_n;
774 }
775
777 KOKKOS_INLINE_FUNCTION
778 static std::size_t maxNeighbor( const list_type& list )
779 {
780 std::size_t max_n = 0;
781 // Max neighbors across all particles in range.
782 for ( std::size_t p = list.getParticleBegin();
783 p < list.getParticleEnd(); p++ )
784 if ( numNeighbor( list, p ) > max_n )
785 max_n = numNeighbor( list, p );
786 return max_n;
787 }
788
790 KOKKOS_INLINE_FUNCTION static std::size_t
791 numNeighbor( const list_type& list, const std::size_t particle_index )
792 {
793 int total_count = 0;
794 int imin, imax, jmin, jmax, kmin, kmax;
795 list.getStencilCells( list.getParticleBin( particle_index ), imin, imax,
796 jmin, jmax, kmin, kmax );
797
798 // Loop over the cell stencil.
799 for ( int i = imin; i < imax; ++i )
800 for ( int j = jmin; j < jmax; ++j )
801 for ( int k = kmin; k < kmax; ++k )
802 {
803 total_count += list.binSize( i, j, k );
804 }
805 return total_count;
806 }
807
810 KOKKOS_INLINE_FUNCTION static std::size_t
811 getNeighbor( const list_type& list, const std::size_t particle_index,
812 const std::size_t neighbor_index )
813 {
814 std::size_t total_count = 0;
815 std::size_t previous_count = 0;
816 int imin, imax, jmin, jmax, kmin, kmax;
817 list.getStencilCells( list.getParticleBin( particle_index ), imin, imax,
818 jmin, jmax, kmin, kmax );
819
820 // Loop over the cell stencil.
821 for ( int i = imin; i < imax; ++i )
822 for ( int j = jmin; j < jmax; ++j )
823 for ( int k = kmin; k < kmax; ++k )
824 {
825 total_count += list.binSize( i, j, k );
826 // This neighbor is in this bin.
827 if ( total_count > neighbor_index )
828 {
829 int particle_id = list.binOffset( i, j, k ) +
830 ( neighbor_index - previous_count );
831 return list.getParticle( particle_id );
832 }
833 previous_count = total_count;
834 }
835
836 assert( total_count <= totalNeighbor( list ) );
837
838 // Should never make it to this point.
839 return 0;
840 }
841};
842
843} // end namespace Cabana
844
845#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:116
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:172
KOKKOS_INLINE_FUNCTION std::size_t getParticleBegin() const
Beginning of binned range.
Definition Cabana_LinkedCellList.hpp:271
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:402
void build(PositionType positions)
Build the linked cell list with all particles.
Definition Cabana_LinkedCellList.hpp:516
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:204
KOKKOS_INLINE_FUNCTION auto getParticleBin(const int particle_index) const
Get the bin cell index of the input particle.
Definition Cabana_LinkedCellList.hpp:541
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:332
Kokkos::View< int *, memory_space > CountView
Binning view type.
Definition Cabana_LinkedCellList.hpp:114
KOKKOS_INLINE_FUNCTION int numParticles() const
Number of binned particles.
Definition Cabana_LinkedCellList.hpp:267
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:303
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:587
KOKKOS_INLINE_FUNCTION stencil_type cellStencil() const
Get the linked cell stencil.
Definition Cabana_LinkedCellList.hpp:379
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:345
Cabana::LinkedCellStencil< Scalar > stencil_type
Stencil type.
Definition Cabana_LinkedCellList.hpp:118
typename MemorySpace::memory_space memory_space
Memory space.
Definition Cabana_LinkedCellList.hpp:102
KOKKOS_INLINE_FUNCTION auto getParticle(const int offset) const
Get a candidate neighbor particle at a given binned offset.
Definition Cabana_LinkedCellList.hpp:598
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:357
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:136
typename memory_space::size_type size_type
Memory space size type.
Definition Cabana_LinkedCellList.hpp:111
KOKKOS_INLINE_FUNCTION std::size_t getParticleEnd() const
End of binned range.
Definition Cabana_LinkedCellList.hpp:275
KOKKOS_INLINE_FUNCTION auto sorted() const
Definition Cabana_LinkedCellList.hpp:581
LinkedCellList()
Default constructor.
Definition Cabana_LinkedCellList.hpp:123
auto getParticleBins() const
Get the bin cell index for each binned particle.
Definition Cabana_LinkedCellList.hpp:535
KOKKOS_INLINE_FUNCTION int totalBins() const
Get the total number of bins.
Definition Cabana_LinkedCellList.hpp:282
void update(const bool sorted)
Definition Cabana_LinkedCellList.hpp:575
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:319
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:501
KOKKOS_FUNCTION void operator()(const int i) const
Determines which particles belong to bin i.
Definition Cabana_LinkedCellList.hpp:552
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:244
typename memory_space::execution_space execution_space
Default execution space.
Definition Cabana_LinkedCellList.hpp:109
BinningData< MemorySpace > binningData() const
Get the 1d bin data.
Definition Cabana_LinkedCellList.hpp:385
KOKKOS_INLINE_FUNCTION std::size_t rangeBegin() const
The beginning particle index binned by the linked cell list.
Definition Cabana_LinkedCellList.hpp:366
void storeParticleBins()
Store the bin cell index for each binned particle.
Definition Cabana_LinkedCellList.hpp:524
KOKKOS_INLINE_FUNCTION std::size_t rangeEnd() const
The ending particle index binned by the linked cell list.
Definition Cabana_LinkedCellList.hpp:372
KOKKOS_INLINE_FUNCTION int numBin(const int dim) const
Get the number of bins in a given dimension.
Definition Cabana_LinkedCellList.hpp:290
MemorySpace memory_space
Kokkos memory space.
Definition Cabana_LinkedCellList.hpp:760
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:791
LinkedCellList< MemorySpace, Scalar > list_type
Neighbor list type.
Definition Cabana_LinkedCellList.hpp:762
static KOKKOS_INLINE_FUNCTION std::size_t maxNeighbor(const list_type &list)
Get the maximum number of neighbors per particles.
Definition Cabana_LinkedCellList.hpp:778
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:811
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:766
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:1012
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:737
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:650
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 Constructor.
Definition Cabana_LinkedCellList.hpp:49
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:721
Slice static type checker.
Definition Cabana_Slice.hpp:861