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 "Cabana::Grid::Experimental::SparseArrayLayout::registerSparseMap",
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>;
322 using memory_space = MemorySpace;
323 static_assert( Kokkos::is_memory_space<MemorySpace>() );
325 using execution_space = typename memory_space::execution_space;
327 using size_type = typename memory_space::size_type;
329 using entity_type = EntityType;
331 using mesh_type = MeshType;
333 using sparse_map_type = SparseMapType;
335 static constexpr std::size_t num_space_dim = mesh_type::num_space_dim;
337 static constexpr unsigned long long cell_bits_per_tile =
338 sparse_map_type::cell_bits_per_tile;
340 static constexpr unsigned long long cell_mask_per_tile =
341 sparse_map_type::cell_mask_per_tile;
342
343 // AoSoA related types
345 using member_types = DataTypes;
347 static constexpr int vector_length = sparse_map_type::cell_num_per_tile;
354
363 SparseArray( const std::string label, array_layout layout )
364 : _layout( layout )
365 , _data( label )
366 {
367 }
368
369 // ------------------------------------------------------------------------
370 // AoSoA-related interfaces
372 aosoa_type& aosoa() { return _data; }
377 std::string label() const { return _data.label(); }
379 array_layout& layout() { return _layout; }
381 const array_layout& layout() const { return _layout; }
382
387 inline void resize( const size_type n ) { _data.resize( n ); }
388
392 inline void resize() { resize( _layout.sizeCell() ); }
393
398 inline void reserve( const size_type n ) { _data.reserve( n ); }
399
404 inline void reserveFromMap( const double factor = 1.2 )
405 {
406 reserve( _layout.reservedCellSize( factor ) );
407 }
408
410 inline void shrinkToFit() { _data.shrinkToFit(); }
413 inline void clear()
414 {
415 resize( 0 );
416 _layout.clear();
417 };
418
420 KOKKOS_FUNCTION
421 size_type capacity() { return _data.capacity(); }
423 KOKKOS_FUNCTION
424 size_type size() const { return _data.size(); }
426 KOKKOS_FUNCTION
427 bool empty() const { return ( size() == 0 ); }
429 KOKKOS_FORCEINLINE_FUNCTION
430 size_type numSoA() const { return _data.numSoA(); }
432 KOKKOS_FORCEINLINE_FUNCTION
434 {
435 return _data.arraySize( s );
436 }
437
446 template <class PositionSliceType>
447 void registerSparseGrid( PositionSliceType& positions, int particle_num,
448 const int p2g_radius = 1 )
449 {
450 _layout.template registerSparseMap<execution_space, PositionSliceType>(
451 positions, particle_num, p2g_radius );
452 this->resize( _layout.sparseMap().sizeCell() );
453 }
454
455 // ------------------------------------------------------------------------
460 KOKKOS_FORCEINLINE_FUNCTION
461 soa_type& accessTile( const int tile_i, const int tile_j,
462 const int tile_k ) const
463 {
464 auto tile_id = _layout.queryTileFromTileId( tile_i, tile_j, tile_k );
465 return _data.access( tile_id );
466 }
467
473 template <typename Value>
474 KOKKOS_FORCEINLINE_FUNCTION soa_type&
475 accessTile( const Value tile_id ) const
476 {
477 return _data.access( tile_id );
478 }
479
484 KOKKOS_FORCEINLINE_FUNCTION
485 soa_type& accessTileFromCell( const int cell_i, const int cell_j,
486 const int cell_k ) const
487 {
488 auto tile_id = _layout.queryTile( cell_i, cell_j, cell_k );
489 return _data.access( tile_id );
490 }
491
492 // ------------------------------------------------------------------------
498 template <typename Key>
499 KOKKOS_FORCEINLINE_FUNCTION tuple_type
500 getTuple( const Key tile_key, const int cell_local_id ) const
501 {
502 auto tile_id = _layout.queryTileFromTileKey( tile_key );
503 return _data.getTuple( ( tile_id << cell_bits_per_tile ) |
504 ( cell_local_id & cell_mask_per_tile ) );
505 }
506
507 // ------------------------------------------------------------------------
514 template <std::size_t M, typename... Indices>
515 KOKKOS_FORCEINLINE_FUNCTION
516 typename soa_type::template member_reference_type<M>
517 get( const Kokkos::Array<int, 3> cell_ijk, Indices&&... ids ) const
518 {
519 auto& soa = accessTileFromCell( cell_ijk[0], cell_ijk[1], cell_ijk[2] );
520 auto array_index =
521 _layout.cellLocalId( cell_ijk[0], cell_ijk[1], cell_ijk[2] );
522 return Cabana::get<M>( soa, array_index, ids... );
523 }
524
529 template <std::size_t M>
530 KOKKOS_FORCEINLINE_FUNCTION
531 typename soa_type::template member_reference_type<M>
532 get( const Kokkos::Array<int, 3> cell_ijk ) const
533 {
534 auto& soa = accessTileFromCell( cell_ijk[0], cell_ijk[1], cell_ijk[2] );
535 auto array_index =
536 _layout.cellLocalId( cell_ijk[0], cell_ijk[1], cell_ijk[2] );
537 return Cabana::get<M>( soa, array_index );
538 }
539
547 template <std::size_t M, typename... Indices>
548 KOKKOS_FORCEINLINE_FUNCTION
549 typename soa_type::template member_reference_type<M>
550 get( const Kokkos::Array<int, 3> tile_ijk,
551 const Kokkos::Array<int, 3> local_cell_ijk,
552 Indices&&... ids ) const
553 {
554 auto& soa = accessTile( tile_ijk[0], tile_ijk[1], tile_ijk[2] );
555 auto array_index = _layout.cellLocalId(
556 local_cell_ijk[0], local_cell_ijk[1], local_cell_ijk[2] );
557 return Cabana::get<M>( soa, array_index, ids... );
558 }
559
566 template <std::size_t M>
567 KOKKOS_FORCEINLINE_FUNCTION
568 typename soa_type::template member_reference_type<M>
569 get( const Kokkos::Array<int, 3> tile_ijk,
570 const Kokkos::Array<int, 3> local_cell_ijk ) const
571 {
572 auto& soa = accessTile( tile_ijk[0], tile_ijk[1], tile_ijk[2] );
573 auto array_index = _layout.cellLocalId(
574 local_cell_ijk[0], local_cell_ijk[1], local_cell_ijk[2] );
575 return Cabana::get<M>( soa, array_index );
576 }
577
585 template <std::size_t M, typename... Indices>
586 KOKKOS_FORCEINLINE_FUNCTION
587 typename soa_type::template member_reference_type<M>
588 get( const int tile_id, const Kokkos::Array<int, 3> local_cell_ijk,
589 Indices&&... ids ) const
590 {
591 auto& soa = _data.access( tile_id );
592 auto array_index = _layout.cellLocalId(
593 local_cell_ijk[0], local_cell_ijk[1], local_cell_ijk[2] );
594 return Cabana::get<M>( soa, array_index, ids... );
595 }
596
603 template <std::size_t M>
604 KOKKOS_FORCEINLINE_FUNCTION
605 typename soa_type::template member_reference_type<M>
606 get( const int tile_id,
607 const Kokkos::Array<int, 3> local_cell_ijk ) const
608 {
609 auto& soa = _data.access( tile_id );
610 auto array_index = _layout.cellLocalId(
611 local_cell_ijk[0], local_cell_ijk[1], local_cell_ijk[2] );
612 return Cabana::get<M>( soa, array_index );
613 }
614
623 template <std::size_t M, typename... Indices>
624 KOKKOS_FORCEINLINE_FUNCTION
625 typename soa_type::template member_reference_type<M>
626 get( const int tile_id, const int cell_id, Indices&&... ids ) const
627 {
628 auto& soa = _data.access( tile_id );
629 return Cabana::get<M>( soa, cell_id, ids... );
630 }
631
638 template <std::size_t M>
639 KOKKOS_FORCEINLINE_FUNCTION
640 typename soa_type::template member_reference_type<M>
641 get( const int tile_id, const int cell_id ) const
642 {
643 auto& soa = _data.access( tile_id );
644 return Cabana::get<M>( soa, cell_id );
645 }
646
647 private:
649 array_layout _layout;
651 aosoa_type _data;
652
653}; // end class SparseArray
654
655//---------------------------------------------------------------------------//
656// Scatic type checker.
657//---------------------------------------------------------------------------//
659template <class>
660struct is_sparse_array : public std::false_type
661{
662};
663
665template <class DataTypes, class MemorySpace, class EntityType, class MeshType,
666 class SparseMapType>
668 SparseArray<DataTypes, MemorySpace, EntityType, MeshType, SparseMapType>>
669 : public std::true_type
670{
671};
672
674template <class DataTypes, class MemorySpace, class EntityType, class MeshType,
675 class SparseMapType>
676struct is_sparse_array<const SparseArray<DataTypes, MemorySpace, EntityType,
677 MeshType, SparseMapType>>
678 : public std::true_type
679{
680};
681
682//---------------------------------------------------------------------------//
683// Array creation.
684//---------------------------------------------------------------------------//
691template <class MemorySpace, class DataTypes, class EntityType, class MeshType,
692 class SparseMapType>
694 const std::string label,
696{
697 return std::make_shared<SparseArray<DataTypes, MemorySpace, EntityType,
698 MeshType, SparseMapType>>( label,
699 layout );
700}
701
702} // namespace Experimental
703} // namespace Grid
704} // namespace Cabana
705
706#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:693
Sparse Local grid and related implementations.
Grid type tags.
Cabana utilities.
Array-of-Struct-of-Arrays.
Definition Cabana_AoSoA.hpp:123
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:347
const array_layout & layout() const
Get const reference to the array layout (device accessible)
Definition Cabana_Grid_SparseArray.hpp:381
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:532
SparseMapType sparse_map_type
Sparse map type.
Definition Cabana_Grid_SparseArray.hpp:333
EntityType entity_type
Array entity type (node, cell, face, edge).
Definition Cabana_Grid_SparseArray.hpp:329
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:517
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:626
static constexpr unsigned long long cell_bits_per_tile
Least bits required to represent all cells inside a tile.
Definition Cabana_Grid_SparseArray.hpp:337
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:433
aosoa_type & aosoa()
Get AoSoA reference.
Definition Cabana_Grid_SparseArray.hpp:372
Cabana::Tuple< member_types > tuple_type
AoSoA tuple type.
Definition Cabana_Grid_SparseArray.hpp:353
MeshType mesh_type
Mesh type.
Definition Cabana_Grid_SparseArray.hpp:331
KOKKOS_FORCEINLINE_FUNCTION size_type numSoA() const
Get the number of SoA inside an AoSoA structure.
Definition Cabana_Grid_SparseArray.hpp:430
KOKKOS_FORCEINLINE_FUNCTION soa_type & accessTile(const Value tile_id) const
(Device) Access tile SoA from tile-related information
Definition Cabana_Grid_SparseArray.hpp:475
SparseArray(const std::string label, array_layout layout)
(Host) Constructor
Definition Cabana_Grid_SparseArray.hpp:363
KOKKOS_FUNCTION bool empty() const
Test if the AoSoA array is empty.
Definition Cabana_Grid_SparseArray.hpp:427
MemorySpace memory_space
Kokkos memory space.
Definition Cabana_Grid_SparseArray.hpp:322
void shrinkToFit()
Shrink allocation to fit the valid size.
Definition Cabana_Grid_SparseArray.hpp:410
void reserve(const size_type n)
Reserve the AoSoA array according to the input.
Definition Cabana_Grid_SparseArray.hpp:398
std::string label() const
Get array label (description)
Definition Cabana_Grid_SparseArray.hpp:377
static constexpr std::size_t num_space_dim
Dimension number.
Definition Cabana_Grid_SparseArray.hpp:335
void reserveFromMap(const double factor=1.2)
Reserve the AoSoA array according to the sparse map info in layout.
Definition Cabana_Grid_SparseArray.hpp:404
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:641
array_layout & layout()
Get reference to the array layout (device accessible)
Definition Cabana_Grid_SparseArray.hpp:379
void resize(const size_type n)
Resize the AoSoA array according to the input.
Definition Cabana_Grid_SparseArray.hpp:387
KOKKOS_FUNCTION size_type capacity()
Get AoSoA capacity.
Definition Cabana_Grid_SparseArray.hpp:421
typename memory_space::execution_space execution_space
Default execution space.
Definition Cabana_Grid_SparseArray.hpp:325
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:588
void clear()
Definition Cabana_Grid_SparseArray.hpp:413
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:550
Cabana::AoSoA< member_types, memory_space, vector_length > aosoa_type
AosoA type.
Definition Cabana_Grid_SparseArray.hpp:349
void resize()
Reserve the AoSoA array according to the sparse map info in layout.
Definition Cabana_Grid_SparseArray.hpp:392
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:606
static constexpr unsigned long long cell_mask_per_tile
Cell ID mask inside a tile.
Definition Cabana_Grid_SparseArray.hpp:340
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:569
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:461
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:447
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:485
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:345
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:500
Cabana::SoA< member_types, vector_length > soa_type
SoA Type.
Definition Cabana_Grid_SparseArray.hpp:351
typename memory_space::size_type size_type
Memory space size type.
Definition Cabana_Grid_SparseArray.hpp:327
KOKKOS_FUNCTION size_type size() const
Get AoSoA size (valid number of elements)
Definition Cabana_Grid_SparseArray.hpp:424
SparseArrayLayout< member_types, entity_type, mesh_type, sparse_map_type > array_layout
Sparse array layout type.
Definition Cabana_Grid_SparseArray.hpp:356
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:661
Definition Cabana_Grid_Types.hpp:337
Definition Cabana_SoA.hpp:32
Definition Cabana_Tuple.hpp:32