Cabana 0.8.0-dev
 
Loading...
Searching...
No Matches
Cabana_Grid_SparseArray.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_GRID_SPARSE_ARRAY_HPP
17#define CABANA_GRID_SPARSE_ARRAY_HPP
18
21#include <Cabana_Grid_Types.hpp>
22
23#include <Cabana_AoSoA.hpp>
24#include <Cabana_Utils.hpp> // FIXME: remove after next release.
25
26#include <Kokkos_Core.hpp>
27
28#include <cmath>
29#include <memory>
30#include <type_traits>
31#include <vector>
32
33#include <mpi.h>
34
35namespace Cabana
36{
37namespace Grid
38{
39
40namespace Experimental
41{
42//---------------------------------------------------------------------------//
51template <class DataTypes, class EntityType, class MeshType,
52 class SparseMapType>
54{
55 public:
57 using mesh_type = MeshType;
59 using scalar_type = typename mesh_type::scalar_type;
60 // check if mesh_type is SparseMesh
61 static_assert( isSparseMesh<MeshType>::value,
62 "[SparesArrayLayout] Support only SparseMesh" );
63
65 using entity_type = EntityType;
67 using member_types = DataTypes;
68
70 using sparse_map_type = SparseMapType;
72 using value_type = typename sparse_map_type::value_type;
74 using key_type = typename sparse_map_type::key_type;
77 static constexpr unsigned long long cell_bits_per_tile_dim =
78 sparse_map_type::cell_bits_per_tile_dim;
80 static constexpr unsigned long long cell_num_per_tile_dim =
81 sparse_map_type::cell_num_per_tile_dim;
83 static constexpr std::size_t num_space_dim = sparse_map_type::rank;
85 using memory_space = typename sparse_map_type::memory_space;
86
94 SparseArrayLayout( const std::shared_ptr<LocalGrid<MeshType>>& local_grid,
95 SparseMapType& sparse_map, const float over_allocation )
96 : _over_allocation( over_allocation )
97 , _local_grid( local_grid )
98 , _map( std::forward<sparse_map_type>( sparse_map ) )
99 {
100 auto sparse_mesh = _local_grid->globalGrid().globalMesh();
101 _cell_size[0] = sparse_mesh.cellSize( 0 );
102 _cell_size[1] = sparse_mesh.cellSize( 1 );
103 _cell_size[2] = sparse_mesh.cellSize( 2 );
104 _global_low_corner[0] = sparse_mesh.lowCorner( 0 );
105 _global_low_corner[1] = sparse_mesh.lowCorner( 1 );
106 _global_low_corner[2] = sparse_mesh.lowCorner( 2 );
107 }
108
110 SparseMapType& sparseMap() { return _map; }
111
113 const std::shared_ptr<LocalGrid<MeshType>> localGrid() const
114 {
115 return _local_grid;
116 }
117
119 inline uint64_t sizeCell() const { return _map.sizeCell(); }
120
122 inline uint64_t sizeTile() const { return _map.sizeTile(); }
123
128 inline uint64_t reservedCellSize( float factor ) const
129 {
130 return _map.reservedCellSize( factor );
131 }
132
134 inline uint64_t arraySize() const { return sizeCell(); }
135
137 inline void clear() { _map.clear(); }
138
147 template <class ExecSpace, class PositionSliceType>
148 void registerSparseMap( PositionSliceType& positions,
149 const int particle_num, const int p2g_radius = 1 )
150 {
151 // get references
152 Kokkos::Array<scalar_type, 3> dx_inv = {
153 (scalar_type)1.0 / _cell_size[0], (scalar_type)1.0 / _cell_size[1],
154 (scalar_type)1.0 / _cell_size[2] };
155 auto& map = _map;
156 auto& low_corner = _global_low_corner;
157 // register sparse map in sparse array layout
158 Kokkos::parallel_for(
159 "register sparse map in sparse array layout",
160 Kokkos::RangePolicy<ExecSpace>( 0, particle_num ),
161 KOKKOS_LAMBDA( const int pid ) {
162 scalar_type pos[3] = { positions( pid, 0 ) - low_corner[0],
163 positions( pid, 1 ) - low_corner[1],
164 positions( pid, 2 ) - low_corner[2] };
165 int grid_base[3] = {
166 static_cast<int>( std::lround( pos[0] * dx_inv[0] ) -
167 p2g_radius ),
168 static_cast<int>( std::lround( pos[1] * dx_inv[1] ) -
169 p2g_radius ),
170 static_cast<int>( std::lround( pos[2] * dx_inv[2] ) -
171 p2g_radius ) };
172 // register grids that will have data transfer with the particle
173 const int p2g_size = p2g_radius * 2;
174 for ( int i = 0; i <= p2g_size; ++i )
175 for ( int j = 0; j <= p2g_size; ++j )
176 for ( int k = 0; k <= p2g_size; ++k )
177 {
178 int cell_id[3] = { grid_base[0] + i,
179 grid_base[1] + j,
180 grid_base[2] + k };
181 map.insertCell( cell_id[0], cell_id[1],
182 cell_id[2] );
183 }
184 } );
185 }
186
191 KOKKOS_FORCEINLINE_FUNCTION
192 value_type queryCell( const int cell_i, const int cell_j,
193 const int cell_k ) const
194 {
195 return _map.queryCell( cell_i, cell_j, cell_k );
196 }
197
202 KOKKOS_FORCEINLINE_FUNCTION
203 value_type queryTile( const int cell_i, const int cell_j,
204 const int cell_k ) const
205 {
206 return _map.queryTile( cell_i, cell_j, cell_k );
207 }
208
213 KOKKOS_FORCEINLINE_FUNCTION
214 value_type queryTileFromTileId( const int tile_i, const int tile_j,
215 const int tile_k ) const
216 {
217 return _map.queryTileFromTileId( tile_i, tile_j, tile_k );
218 }
219
224 KOKKOS_FORCEINLINE_FUNCTION
226 {
227 return _map.queryTileFromTileKey( tile_key );
228 }
229
235 KOKKOS_FORCEINLINE_FUNCTION
236 value_type cellLocalId( const int cell_i, const int cell_j,
237 const int cell_k ) const
238 {
239 return _map.cell_local_id( cell_i, cell_j, cell_k );
240 }
241
242 private:
244 float _over_allocation;
246 Kokkos::Array<scalar_type, 3> _cell_size;
248 Kokkos::Array<scalar_type, 3> _global_low_corner;
250 std::shared_ptr<LocalGrid<MeshType>> _local_grid;
251 //! sparse map
252 sparse_map_type _map;
253}; // end class SparseArrayLayout
254
256template <class>
257struct is_sparse_array_layout : public std::false_type
258{
259};
260
262template <class DataTypes, class EntityType, class MeshType,
263 class SparseMapType>
265 SparseArrayLayout<DataTypes, EntityType, MeshType, SparseMapType>>
266 : public std::true_type
267{
268};
269
271template <class DataTypes, class EntityType, class MeshType,
272 class SparseMapType>
274 const SparseArrayLayout<DataTypes, EntityType, MeshType, SparseMapType>>
275 : public std::true_type
276{
277};
278
279//---------------------------------------------------------------------------//
280// Array layout creation.
281//---------------------------------------------------------------------------//
291template <class DataTypes, class EntityType, class MeshType,
292 class SparseMapType>
294 const std::shared_ptr<LocalGrid<MeshType>>& local_grid,
295 SparseMapType& sparse_map, EntityType, const float over_allocation = 1.01f )
296{
297 return std::make_shared<
299 local_grid, sparse_map, over_allocation );
300}
301
302//---------------------------------------------------------------------------//
313template <class DataTypes, class MemorySpace, class EntityType, class MeshType,
314 class SparseMapType>
316{
317 public:
319 using sparse_array_type = SparseArray<DataTypes, MemorySpace, EntityType,
320 MeshType, SparseMapType>;
321 // FIXME: extracting the self type for backwards compatibility with previous
322 // template on DeviceType. Should simply be MemorySpace after next release.
324 using memory_space = typename MemorySpace::memory_space;
325 // FIXME: replace warning with memory space assert after next release.
326 static_assert(
327 Cabana::Impl::deprecated( Kokkos::is_device<MemorySpace>() ) );
328
330 using device_type [[deprecated]] = typename memory_space::device_type;
332 using execution_space = typename memory_space::execution_space;
334 using size_type = typename memory_space::size_type;
336 using entity_type = EntityType;
338 using mesh_type = MeshType;
340 using sparse_map_type = SparseMapType;
342 static constexpr std::size_t num_space_dim = mesh_type::num_space_dim;
344 static constexpr unsigned long long cell_bits_per_tile =
345 sparse_map_type::cell_bits_per_tile;
347 static constexpr unsigned long long cell_mask_per_tile =
348 sparse_map_type::cell_mask_per_tile;
349
350 // AoSoA related types
352 using member_types = DataTypes;
354 static constexpr int vector_length = sparse_map_type::cell_num_per_tile;
361
370 SparseArray( const std::string label, array_layout layout )
371 : _layout( layout )
372 , _data( label )
373 {
374 }
375
376 // ------------------------------------------------------------------------
377 // AoSoA-related interfaces
379 aosoa_type& aosoa() { return _data; }
384 std::string label() const { return _data.label(); }
386 array_layout& layout() { return _layout; }
388 const array_layout& layout() const { return _layout; }
389
394 inline void resize( const size_type n ) { _data.resize( n ); }
395
399 inline void resize() { resize( _layout.sizeCell() ); }
400
405 inline void reserve( const size_type n ) { _data.reserve( n ); }
406
411 inline void reserveFromMap( const double factor = 1.2 )
412 {
413 reserve( _layout.reservedCellSize( factor ) );
414 }
415
417 inline void shrinkToFit() { _data.shrinkToFit(); }
420 inline void clear()
421 {
422 resize( 0 );
423 _layout.clear();
424 };
425
427 KOKKOS_FUNCTION
428 size_type capacity() { return _data.capacity(); }
430 KOKKOS_FUNCTION
431 size_type size() const { return _data.size(); }
433 KOKKOS_FUNCTION
434 bool empty() const { return ( size() == 0 ); }
436 KOKKOS_FORCEINLINE_FUNCTION
437 size_type numSoA() const { return _data.numSoA(); }
439 KOKKOS_FORCEINLINE_FUNCTION
441 {
442 return _data.arraySize( s );
443 }
444
453 template <class PositionSliceType>
454 void registerSparseGrid( PositionSliceType& positions, int particle_num,
455 const int p2g_radius = 1 )
456 {
457 _layout.template registerSparseMap<execution_space, PositionSliceType>(
458 positions, particle_num, p2g_radius );
459 this->resize( _layout.sparseMap().sizeCell() );
460 }
461
462 // ------------------------------------------------------------------------
467 KOKKOS_FORCEINLINE_FUNCTION
468 soa_type& accessTile( const int tile_i, const int tile_j,
469 const int tile_k ) const
470 {
471 auto tile_id = _layout.queryTileFromTileId( tile_i, tile_j, tile_k );
472 return _data.access( tile_id );
473 }
474
480 template <typename Value>
481 KOKKOS_FORCEINLINE_FUNCTION soa_type&
482 accessTile( const Value tile_id ) const
483 {
484 return _data.access( tile_id );
485 }
486
491 KOKKOS_FORCEINLINE_FUNCTION
492 soa_type& accessTileFromCell( const int cell_i, const int cell_j,
493 const int cell_k ) const
494 {
495 auto tile_id = _layout.queryTile( cell_i, cell_j, cell_k );
496 return _data.access( tile_id );
497 }
498
499 // ------------------------------------------------------------------------
505 template <typename Key>
506 KOKKOS_FORCEINLINE_FUNCTION tuple_type
507 getTuple( const Key tile_key, const int cell_local_id ) const
508 {
509 auto tile_id = _layout.queryTileFromTileKey( tile_key );
510 return _data.getTuple( ( tile_id << cell_bits_per_tile ) |
511 ( cell_local_id & cell_mask_per_tile ) );
512 }
513
514 // ------------------------------------------------------------------------
521 template <std::size_t M, typename... Indices>
522 KOKKOS_FORCEINLINE_FUNCTION
523 typename soa_type::template member_reference_type<M>
524 get( const Kokkos::Array<int, 3> cell_ijk, Indices&&... ids ) const
525 {
526 auto& soa = accessTileFromCell( cell_ijk[0], cell_ijk[1], cell_ijk[2] );
527 auto array_index =
528 _layout.cellLocalId( cell_ijk[0], cell_ijk[1], cell_ijk[2] );
529 return Cabana::get<M>( soa, array_index, ids... );
530 }
531
536 template <std::size_t M>
537 KOKKOS_FORCEINLINE_FUNCTION
538 typename soa_type::template member_reference_type<M>
539 get( const Kokkos::Array<int, 3> cell_ijk ) const
540 {
541 auto& soa = accessTileFromCell( cell_ijk[0], cell_ijk[1], cell_ijk[2] );
542 auto array_index =
543 _layout.cellLocalId( cell_ijk[0], cell_ijk[1], cell_ijk[2] );
544 return Cabana::get<M>( soa, array_index );
545 }
546
554 template <std::size_t M, typename... Indices>
555 KOKKOS_FORCEINLINE_FUNCTION
556 typename soa_type::template member_reference_type<M>
557 get( const Kokkos::Array<int, 3> tile_ijk,
558 const Kokkos::Array<int, 3> local_cell_ijk,
559 Indices&&... ids ) const
560 {
561 auto& soa = accessTile( tile_ijk[0], tile_ijk[1], tile_ijk[2] );
562 auto array_index = _layout.cellLocalId(
563 local_cell_ijk[0], local_cell_ijk[1], local_cell_ijk[2] );
564 return Cabana::get<M>( soa, array_index, ids... );
565 }
566
573 template <std::size_t M>
574 KOKKOS_FORCEINLINE_FUNCTION
575 typename soa_type::template member_reference_type<M>
576 get( const Kokkos::Array<int, 3> tile_ijk,
577 const Kokkos::Array<int, 3> local_cell_ijk ) const
578 {
579 auto& soa = accessTile( tile_ijk[0], tile_ijk[1], tile_ijk[2] );
580 auto array_index = _layout.cellLocalId(
581 local_cell_ijk[0], local_cell_ijk[1], local_cell_ijk[2] );
582 return Cabana::get<M>( soa, array_index );
583 }
584
592 template <std::size_t M, typename... Indices>
593 KOKKOS_FORCEINLINE_FUNCTION
594 typename soa_type::template member_reference_type<M>
595 get( const int tile_id, const Kokkos::Array<int, 3> local_cell_ijk,
596 Indices&&... ids ) const
597 {
598 auto& soa = _data.access( tile_id );
599 auto array_index = _layout.cellLocalId(
600 local_cell_ijk[0], local_cell_ijk[1], local_cell_ijk[2] );
601 return Cabana::get<M>( soa, array_index, ids... );
602 }
603
610 template <std::size_t M>
611 KOKKOS_FORCEINLINE_FUNCTION
612 typename soa_type::template member_reference_type<M>
613 get( const int tile_id,
614 const Kokkos::Array<int, 3> local_cell_ijk ) const
615 {
616 auto& soa = _data.access( tile_id );
617 auto array_index = _layout.cellLocalId(
618 local_cell_ijk[0], local_cell_ijk[1], local_cell_ijk[2] );
619 return Cabana::get<M>( soa, array_index );
620 }
621
630 template <std::size_t M, typename... Indices>
631 KOKKOS_FORCEINLINE_FUNCTION
632 typename soa_type::template member_reference_type<M>
633 get( const int tile_id, const int cell_id, Indices&&... ids ) const
634 {
635 auto& soa = _data.access( tile_id );
636 return Cabana::get<M>( soa, cell_id, ids... );
637 }
638
645 template <std::size_t M>
646 KOKKOS_FORCEINLINE_FUNCTION
647 typename soa_type::template member_reference_type<M>
648 get( const int tile_id, const int cell_id ) const
649 {
650 auto& soa = _data.access( tile_id );
651 return Cabana::get<M>( soa, cell_id );
652 }
653
654 private:
656 array_layout _layout;
658 aosoa_type _data;
659
660}; // end class SparseArray
661
662//---------------------------------------------------------------------------//
663// Scatic type checker.
664//---------------------------------------------------------------------------//
666template <class>
667struct is_sparse_array : public std::false_type
668{
669};
670
672template <class DataTypes, class MemorySpace, class EntityType, class MeshType,
673 class SparseMapType>
675 SparseArray<DataTypes, MemorySpace, EntityType, MeshType, SparseMapType>>
676 : public std::true_type
677{
678};
679
681template <class DataTypes, class MemorySpace, class EntityType, class MeshType,
682 class SparseMapType>
683struct is_sparse_array<const SparseArray<DataTypes, MemorySpace, EntityType,
684 MeshType, SparseMapType>>
685 : public std::true_type
686{
687};
688
689//---------------------------------------------------------------------------//
690// Array creation.
691//---------------------------------------------------------------------------//
698template <class MemorySpace, class DataTypes, class EntityType, class MeshType,
699 class SparseMapType>
701 const std::string label,
703{
704 return std::make_shared<SparseArray<DataTypes, MemorySpace, EntityType,
705 MeshType, SparseMapType>>( label,
706 layout );
707}
708
709} // namespace Experimental
710} // namespace Grid
711} // namespace Cabana
712
713#endif // CABANA_GRID_SPARSE_ARRAY_HPP
Array-of-Struct-of-Arrays particle data structure.
auto createSparseArrayLayout(const std::shared_ptr< LocalGrid< MeshType > > &local_grid, SparseMapType &sparse_map, EntityType, const float over_allocation=1.01f)
Create sparse array layout over the entities of a sparse local grid.
Definition Cabana_Grid_SparseArray.hpp:293
auto createSparseArray(const std::string label, SparseArrayLayout< DataTypes, EntityType, MeshType, SparseMapType > &layout)
Create sparse array based on the sparse array layout.
Definition Cabana_Grid_SparseArray.hpp:700
Sparse Local grid and related implementations.
Grid type tags.
Cabana utilities.
Array-of-Struct-of-Arrays.
Definition Cabana_AoSoA.hpp:121
Definition Cabana_Grid_SparseLocalGrid.hpp:35
Entity layout for sparse array data on the local sparse mesh.
Definition Cabana_Grid_SparseArray.hpp:54
DataTypes member_types
Array member types, such as Cabana::MemberTypes<double, float[3]>
Definition Cabana_Grid_SparseArray.hpp:67
uint64_t arraySize() const
Array size in cell (default size measurse: cell)
Definition Cabana_Grid_SparseArray.hpp:134
KOKKOS_FORCEINLINE_FUNCTION value_type queryCell(const int cell_i, const int cell_j, const int cell_k) const
(Device) Query the 1D cell ID from the 3D cell ijk
Definition Cabana_Grid_SparseArray.hpp:192
KOKKOS_FORCEINLINE_FUNCTION value_type queryTileFromTileKey(const key_type tile_key) const
(Device) Query the 1D tile key from the 1D tile key
Definition Cabana_Grid_SparseArray.hpp:225
EntityType entity_type
Entity Type.
Definition Cabana_Grid_SparseArray.hpp:65
static constexpr std::size_t num_space_dim
Definition Cabana_Grid_SparseArray.hpp:83
SparseMapType sparse_map_type
Abbreviation for Sparse Map Type.
Definition Cabana_Grid_SparseArray.hpp:70
SparseArrayLayout(const std::shared_ptr< LocalGrid< MeshType > > &local_grid, SparseMapType &sparse_map, const float over_allocation)
(Host) Constructor
Definition Cabana_Grid_SparseArray.hpp:94
MeshType mesh_type
Mesh Type, should be SparseMesh.
Definition Cabana_Grid_SparseArray.hpp:57
void clear()
clear valid info inside array layout; i.e. clear sparse map
Definition Cabana_Grid_SparseArray.hpp:137
static constexpr unsigned long long cell_bits_per_tile_dim
Definition Cabana_Grid_SparseArray.hpp:77
SparseMapType & sparseMap()
get reference of sparse map
Definition Cabana_Grid_SparseArray.hpp:110
typename sparse_map_type::key_type key_type
key type in sparse map, i.e., the tile key type
Definition Cabana_Grid_SparseArray.hpp:74
KOKKOS_FORCEINLINE_FUNCTION value_type queryTileFromTileId(const int tile_i, const int tile_j, const int tile_k) const
(Device) Query the 1D tile key from the 3D tile ijk
Definition Cabana_Grid_SparseArray.hpp:214
const std::shared_ptr< LocalGrid< MeshType > > localGrid() const
Get the local grid over which this layout is defined.
Definition Cabana_Grid_SparseArray.hpp:113
void registerSparseMap(PositionSliceType &positions, const int particle_num, const int p2g_radius=1)
Register valid grids in sparse map according to input particle positions.
Definition Cabana_Grid_SparseArray.hpp:148
static constexpr unsigned long long cell_num_per_tile_dim
Definition Cabana_Grid_SparseArray.hpp:80
KOKKOS_FORCEINLINE_FUNCTION value_type queryTile(const int cell_i, const int cell_j, const int cell_k) const
(Device) Query the 1D tile ID from the 3D tile ijk
Definition Cabana_Grid_SparseArray.hpp:203
uint64_t sizeTile() const
array size in tile
Definition Cabana_Grid_SparseArray.hpp:122
KOKKOS_FORCEINLINE_FUNCTION value_type cellLocalId(const int cell_i, const int cell_j, const int cell_k) const
(Device) Get local cell ID from cell IJK
Definition Cabana_Grid_SparseArray.hpp:236
uint64_t sizeCell() const
array size in cell
Definition Cabana_Grid_SparseArray.hpp:119
typename mesh_type::scalar_type scalar_type
Scalar Type.
Definition Cabana_Grid_SparseArray.hpp:59
typename sparse_map_type::value_type value_type
value type in sparse map, i.e., the tile ID (array ID) type
Definition Cabana_Grid_SparseArray.hpp:72
uint64_t reservedCellSize(float factor) const
array reservation size in cell
Definition Cabana_Grid_SparseArray.hpp:128
typename sparse_map_type::memory_space memory_space
Memory space, the same memory space in sparse map.
Definition Cabana_Grid_SparseArray.hpp:85
Sparse array of field data on the local sparse mesh; Array data is stored in AoSoA manner,...
Definition Cabana_Grid_SparseArray.hpp:316
static constexpr int vector_length
AoSoA vector length = cell number in each tile.
Definition Cabana_Grid_SparseArray.hpp:354
const array_layout & layout() const
Get const reference to the array layout (device accessible)
Definition Cabana_Grid_SparseArray.hpp:388
KOKKOS_FORCEINLINE_FUNCTION soa_type::template member_reference_type< M > get(const Kokkos::Array< int, 3 > cell_ijk) const
Access element from cell IJK.
Definition Cabana_Grid_SparseArray.hpp:539
SparseMapType sparse_map_type
Sparse map type.
Definition Cabana_Grid_SparseArray.hpp:340
EntityType entity_type
Array entity type (node, cell, face, edge).
Definition Cabana_Grid_SparseArray.hpp:336
KOKKOS_FORCEINLINE_FUNCTION soa_type::template member_reference_type< M > get(const Kokkos::Array< int, 3 > cell_ijk, Indices &&... ids) const
Access element from cell IJK, access corresponding element's channels with extra indices.
Definition Cabana_Grid_SparseArray.hpp:524
KOKKOS_FORCEINLINE_FUNCTION soa_type::template member_reference_type< M > get(const int tile_id, const int cell_id, Indices &&... ids) const
Access element in a hierarchical manner, from 1D tile ID and then 1D local cell ID,...
Definition Cabana_Grid_SparseArray.hpp:633
static constexpr unsigned long long cell_bits_per_tile
Least bits required to represent all cells inside a tile.
Definition Cabana_Grid_SparseArray.hpp:344
KOKKOS_FORCEINLINE_FUNCTION size_type arraySize(const size_type s) const
Get data array size at a given struct member index.
Definition Cabana_Grid_SparseArray.hpp:440
aosoa_type & aosoa()
Get AoSoA reference.
Definition Cabana_Grid_SparseArray.hpp:379
Cabana::Tuple< member_types > tuple_type
AoSoA tuple type.
Definition Cabana_Grid_SparseArray.hpp:360
MeshType mesh_type
Mesh type.
Definition Cabana_Grid_SparseArray.hpp:338
KOKKOS_FORCEINLINE_FUNCTION size_type numSoA() const
Get the number of SoA inside an AoSoA structure.
Definition Cabana_Grid_SparseArray.hpp:437
KOKKOS_FORCEINLINE_FUNCTION soa_type & accessTile(const Value tile_id) const
(Device) Access tile SoA from tile-related information
Definition Cabana_Grid_SparseArray.hpp:482
SparseArray(const std::string label, array_layout layout)
(Host) Constructor
Definition Cabana_Grid_SparseArray.hpp:370
KOKKOS_FUNCTION bool empty() const
Test if the AoSoA array is empty.
Definition Cabana_Grid_SparseArray.hpp:434
void shrinkToFit()
Shrink allocation to fit the valid size.
Definition Cabana_Grid_SparseArray.hpp:417
void reserve(const size_type n)
Reserve the AoSoA array according to the input.
Definition Cabana_Grid_SparseArray.hpp:405
std::string label() const
Get array label (description)
Definition Cabana_Grid_SparseArray.hpp:384
static constexpr std::size_t num_space_dim
Dimension number.
Definition Cabana_Grid_SparseArray.hpp:342
void reserveFromMap(const double factor=1.2)
Reserve the AoSoA array according to the sparse map info in layout.
Definition Cabana_Grid_SparseArray.hpp:411
KOKKOS_FORCEINLINE_FUNCTION soa_type::template member_reference_type< M > get(const int tile_id, const int cell_id) const
Access element in a hierarchical manner, from 1D tile ID and then 1D local cell ID.
Definition Cabana_Grid_SparseArray.hpp:648
array_layout & layout()
Get reference to the array layout (device accessible)
Definition Cabana_Grid_SparseArray.hpp:386
void resize(const size_type n)
Resize the AoSoA array according to the input.
Definition Cabana_Grid_SparseArray.hpp:394
KOKKOS_FUNCTION size_type capacity()
Get AoSoA capacity.
Definition Cabana_Grid_SparseArray.hpp:428
typename memory_space::execution_space execution_space
Default execution space.
Definition Cabana_Grid_SparseArray.hpp:332
KOKKOS_FORCEINLINE_FUNCTION soa_type::template member_reference_type< M > get(const int tile_id, const Kokkos::Array< int, 3 > local_cell_ijk, Indices &&... ids) const
Access element in a hierarchical manner, from 1D tile ID and then local cell IJK, access correspondin...
Definition Cabana_Grid_SparseArray.hpp:595
void clear()
Definition Cabana_Grid_SparseArray.hpp:420
KOKKOS_FORCEINLINE_FUNCTION soa_type::template member_reference_type< M > get(const Kokkos::Array< int, 3 > tile_ijk, const Kokkos::Array< int, 3 > local_cell_ijk, Indices &&... ids) const
Access element in a hierarchical manner, from tile IJK and then local cell IJK, access corresponding ...
Definition Cabana_Grid_SparseArray.hpp:557
Cabana::AoSoA< member_types, memory_space, vector_length > aosoa_type
AosoA type.
Definition Cabana_Grid_SparseArray.hpp:356
void resize()
Reserve the AoSoA array according to the sparse map info in layout.
Definition Cabana_Grid_SparseArray.hpp:399
KOKKOS_FORCEINLINE_FUNCTION soa_type::template member_reference_type< M > get(const int tile_id, const Kokkos::Array< int, 3 > local_cell_ijk) const
Access element in a hierarchical manner, from 1D tile ID and then local cell IJK.
Definition Cabana_Grid_SparseArray.hpp:613
static constexpr unsigned long long cell_mask_per_tile
Cell ID mask inside a tile.
Definition Cabana_Grid_SparseArray.hpp:347
KOKKOS_FORCEINLINE_FUNCTION soa_type::template member_reference_type< M > get(const Kokkos::Array< int, 3 > tile_ijk, const Kokkos::Array< int, 3 > local_cell_ijk) const
Access element in a hierarchical manner, from tile IJK and then local cell IJK.
Definition Cabana_Grid_SparseArray.hpp:576
KOKKOS_FORCEINLINE_FUNCTION soa_type & accessTile(const int tile_i, const int tile_j, const int tile_k) const
(Device) Access tile SoA from tile-related information
Definition Cabana_Grid_SparseArray.hpp:468
typename MemorySpace::memory_space memory_space
Memory space.
Definition Cabana_Grid_SparseArray.hpp:324
void registerSparseGrid(PositionSliceType &positions, int particle_num, const int p2g_radius=1)
Register valid grids in sparse map according to input particle positions.
Definition Cabana_Grid_SparseArray.hpp:454
KOKKOS_FORCEINLINE_FUNCTION soa_type & accessTileFromCell(const int cell_i, const int cell_j, const int cell_k) const
(Device) Access tile SoA from cell-related information
Definition Cabana_Grid_SparseArray.hpp:492
SparseArray< DataTypes, MemorySpace, EntityType, MeshType, SparseMapType > sparse_array_type
self type
Definition Cabana_Grid_SparseArray.hpp:319
DataTypes member_types
DataTypes Data types (Cabana::MemberTypes).
Definition Cabana_Grid_SparseArray.hpp:352
KOKKOS_FORCEINLINE_FUNCTION tuple_type getTuple(const Key tile_key, const int cell_local_id) const
Access AoSoA tuple from tile key and local cell id.
Definition Cabana_Grid_SparseArray.hpp:507
Cabana::SoA< member_types, vector_length > soa_type
SoA Type.
Definition Cabana_Grid_SparseArray.hpp:358
typename memory_space::size_type size_type
Memory space size type.
Definition Cabana_Grid_SparseArray.hpp:334
KOKKOS_FUNCTION size_type size() const
Get AoSoA size (valid number of elements)
Definition Cabana_Grid_SparseArray.hpp:431
SparseArrayLayout< member_types, entity_type, mesh_type, sparse_map_type > array_layout
Sparse array layout type.
Definition Cabana_Grid_SparseArray.hpp:363
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36
KOKKOS_FORCEINLINE_FUNCTION std::enable_if< is_parameter_pack< ParameterPack_t >::value, typenameParameterPack_t::templatevalue_type< N > & >::type get(ParameterPack_t &pp)
Get an element from a parameter pack.
Definition Cabana_ParameterPack.hpp:129
Sparse array layout static type checker.
Definition Cabana_Grid_SparseArray.hpp:258
Sparse array static type checker.
Definition Cabana_Grid_SparseArray.hpp:668
Definition Cabana_Grid_Types.hpp:337
Definition Cabana_SoA.hpp:32
Definition Cabana_Tuple.hpp:32