Cabana 0.8.0-dev
 
Loading...
Searching...
No Matches
Cabana_Grid_SparseLocalGrid.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_LOCALGRID_SPARSE_HPP
17#define CABANA_GRID_LOCALGRID_SPARSE_HPP
18
22#include <Cabana_Grid_Types.hpp>
23
24#include <array>
25#include <vector>
26
27namespace Cabana
28{
29namespace Grid
30{
31namespace Experimental
32{
33//---------------------------------------------------------------------------//
34template <class MeshType>
36
37//---------------------------------------------------------------------------//
43template <class Scalar, std::size_t NumSpaceDim>
44class LocalGrid<SparseMesh<Scalar, NumSpaceDim>>
45{
46 public:
49
51 static constexpr std::size_t num_space_dim = mesh_type::num_space_dim;
52
62 LocalGrid( const std::shared_ptr<GlobalGrid<mesh_type>>& global_grid,
63 const int halo_cell_width, const long cell_num_per_tile_dim );
64
66 const GlobalGrid<mesh_type>& globalGrid() const;
69
71 int haloCellWidth() const;
72
74 int haloTileWidth() const;
75
78 int totalNumCell( const int d ) const;
79
82 int totalNumCell() const;
83
94 int neighborRank( const std::array<int, num_space_dim>& off_ijk ) const;
95
106 int neighborRank( const int off_i, const int off_j, const int off_k ) const;
107
117 template <class DecompositionTag, class EntityType, class IndexType>
118 IndexSpace<num_space_dim> indexSpace( DecompositionTag t1, EntityType t2,
119 IndexType t3 ) const;
120
133 template <unsigned long long cellBitsPerTileDim, class DecompositionTag,
134 class EntityType>
136 sharedTileIndexSpace( DecompositionTag t1, EntityType t2,
137 const std::array<int, num_space_dim>& off_ijk,
138 const int halo_width = -1 ) const;
139
155 template <unsigned long long cellBitsPerTileDim, class DecompositionTag,
156 class EntityType, std::size_t NSD = num_space_dim>
157 std::enable_if_t<3 == NSD, TileIndexSpace<3, cellBitsPerTileDim>>
158 sharedTileIndexSpace( DecompositionTag t1, EntityType t2, const int off_i,
159 const int off_j, const int off_k,
160 const int halo_width = -1 ) const;
161
162 private:
163 // Node related index space implementations
164 template <class DecompositionTag, class IndexType>
165 IndexSpace<num_space_dim> indexSpaceImpl( DecompositionTag t1, Node,
166 IndexType t3 ) const;
167
168 template <unsigned long long cellBitsPerTileDim, class DecompositionTag>
170 sharedTileIndexSpaceImpl( DecompositionTag t1, Node,
171 const std::array<int, num_space_dim>& off_ijk,
172 const int halo_width ) const;
173
174 // Cell related index space implementations
175 template <class DecompositionTag, class IndexType>
176 IndexSpace<num_space_dim> indexSpaceImpl( DecompositionTag t1, Cell,
177 IndexType t3 ) const;
178
179 template <unsigned long long cellBitsPerTileDim, class DecompositionTag>
181 sharedTileIndexSpaceImpl( DecompositionTag t1, Cell,
182 const std::array<int, num_space_dim>& off_ijk,
183 const int halo_width ) const;
184
185 // Face related index space implementations
186 template <class DecompositionTag, class IndexType>
187 IndexSpace<num_space_dim> indexSpaceImpl( DecompositionTag t1, Face<Dim::I>,
188 IndexType t3 ) const;
189 template <class DecompositionTag, class IndexType>
190 IndexSpace<num_space_dim> indexSpaceImpl( DecompositionTag t1, Face<Dim::J>,
191 IndexType t3 ) const;
192 template <class DecompositionTag, class IndexType>
193 IndexSpace<num_space_dim> indexSpaceImpl( DecompositionTag t1, Face<Dim::K>,
194 IndexType t3 ) const;
195
196 template <unsigned long long cellBitsPerTileDim, class DecompositionTag>
198 sharedTileIndexSpaceImpl( DecompositionTag t1, Face<Dim::I>,
199 const std::array<int, num_space_dim>& off_ijk,
200 const int halo_width ) const;
201 template <unsigned long long cellBitsPerTileDim, class DecompositionTag>
203 sharedTileIndexSpaceImpl( DecompositionTag t1, Face<Dim::J>,
204 const std::array<int, num_space_dim>& off_ijk,
205 const int halo_width ) const;
206 template <unsigned long long cellBitsPerTileDim, class DecompositionTag>
208 sharedTileIndexSpaceImpl( DecompositionTag t1, Face<Dim::K>,
209 const std::array<int, num_space_dim>& off_ijk,
210 const int halo_width ) const;
211 // Edge related index space implementations1
212
213 template <class DecompositionTag, class IndexType>
214 IndexSpace<num_space_dim> indexSpaceImpl( DecompositionTag t1, Edge<Dim::I>,
215 IndexType t3 ) const;
216 template <class DecompositionTag, class IndexType>
217 IndexSpace<num_space_dim> indexSpaceImpl( DecompositionTag t1, Edge<Dim::J>,
218 IndexType t3 ) const;
219 template <class DecompositionTag, class IndexType>
220 IndexSpace<num_space_dim> indexSpaceImpl( DecompositionTag t1, Edge<Dim::K>,
221 IndexType t3 ) const;
222
223 template <unsigned long long cellBitsPerTileDim, class DecompositionTag>
225 sharedTileIndexSpaceImpl( DecompositionTag t1, Edge<Dim::I>,
226 const std::array<int, num_space_dim>& off_ijk,
227 const int halo_width ) const;
228 template <unsigned long long cellBitsPerTileDim, class DecompositionTag>
230 sharedTileIndexSpaceImpl( DecompositionTag t1, Edge<Dim::J>,
231 const std::array<int, num_space_dim>& off_ijk,
232 const int halo_width ) const;
233 template <unsigned long long cellBitsPerTileDim, class DecompositionTag>
235 sharedTileIndexSpaceImpl( DecompositionTag t1, Edge<Dim::K>,
236 const std::array<int, num_space_dim>& off_ijk,
237 const int halo_width ) const;
238
239 // More general implementations for node and cell center indices
240 // Note: In Sparse grid, each cell considers the left-most node and its cell
241 // center as belongings, i.e., Node and Cell share the same element-to-cell
242 // mapping, thus sharse the same interface.
243 IndexSpace<num_space_dim> indexSpaceImpl( Own, Local ) const;
244 IndexSpace<num_space_dim> indexSpaceImpl( Ghost, Local ) const;
245 IndexSpace<num_space_dim> indexSpaceImpl( Own, Global ) const;
246
247 template <unsigned long long cellBitsPerTileDim>
249 sharedTileIndexSpaceImpl( Own,
250 const std::array<int, num_space_dim>& off_ijk,
251 const int halo_width ) const;
252 template <unsigned long long cellBitsPerTileDim>
254 sharedTileIndexSpaceImpl( Ghost,
255 const std::array<int, num_space_dim>& off_ijk,
256 const int halo_width ) const;
257
258 private:
259 std::shared_ptr<GlobalGrid<mesh_type>> _global_grid;
260 int _halo_cell_width;
261 const long _cell_num_per_tile_dim;
262
263}; // end LocalGrid<SparseMesh<Scalar, NumSpaceDim>>
264
265//---------------------------------------------------------------------------//
266// Creation function.
267//---------------------------------------------------------------------------//
278template <class MeshType>
279std::shared_ptr<LocalGrid<MeshType>>
280createSparseLocalGrid( const std::shared_ptr<GlobalGrid<MeshType>>& global_grid,
281 const int halo_cell_width,
282 const int cell_num_per_tile_dim )
283{
284 static_assert( isSparseMesh<MeshType>::value,
285 "createSparseLocalGrid supports only SparseMesh" );
286 return std::make_shared<LocalGrid<MeshType>>( global_grid, halo_cell_width,
287 cell_num_per_tile_dim );
288}
289
290} // namespace Experimental
291} // namespace Grid
292} // namespace Cabana
293//---------------------------------------------------------------------------//
294
295//---------------------------------------------------------------------------//
296// Template implementations
297//---------------------------------------------------------------------------//
298
299#include <Cabana_Grid_SparseLocalGrid_impl.hpp>
300
301//---------------------------------------------------------------------------//
302#endif // end CABANA_GRID_LOCALGRID_SPARSE_HPP
Logical grid indexing.
std::shared_ptr< LocalGrid< MeshType > > createSparseLocalGrid(const std::shared_ptr< GlobalGrid< MeshType > > &global_grid, const int halo_cell_width, const int cell_num_per_tile_dim)
Create a local grid.
Definition Cabana_Grid_SparseLocalGrid.hpp:280
Grid type tags.
std::enable_if_t< 3==NSD, TileIndexSpace< 3, cellBitsPerTileDim > > sharedTileIndexSpace(DecompositionTag t1, EntityType t2, const int off_i, const int off_j, const int off_k, const int halo_width=-1) const
Given the relative offsets of a neighbor rank, get the set of global entity indices shared with that ...
TileIndexSpace< num_space_dim, cellBitsPerTileDim > sharedTileIndexSpace(DecompositionTag t1, EntityType t2, const std::array< int, num_space_dim > &off_ijk, const int halo_width=-1) const
Given the relative offsets of a neighbor rank, get the set of global entity indices shared with that ...
LocalGrid(const std::shared_ptr< GlobalGrid< mesh_type > > &global_grid, const int halo_cell_width, const long cell_num_per_tile_dim)
Constructor.
Definition Cabana_Grid_SparseLocalGrid_impl.hpp:25
int neighborRank(const std::array< int, num_space_dim > &off_ijk) const
Get the global index of a neighbor given neighbor rank offsets relative to this local grid.
Definition Cabana_Grid_SparseLocalGrid_impl.hpp:98
const GlobalGrid< mesh_type > & globalGrid() const
Get the global grid that owns the local grid.
Definition Cabana_Grid_SparseLocalGrid_impl.hpp:43
int totalNumCell(const int d) const
Get the total number of local cells per dimension (owned + halo).
Definition Cabana_Grid_SparseLocalGrid_impl.hpp:76
int haloCellWidth() const
Get the number of cells in the halo.
Definition Cabana_Grid_SparseLocalGrid_impl.hpp:60
IndexSpace< num_space_dim > indexSpace(DecompositionTag t1, EntityType t2, IndexType t3) const
Given a decomposition type, entity type, and index type, get the contiguous set of indices that span ...
int haloTileWidth() const
Get the number of tiles in the halo.
Definition Cabana_Grid_SparseLocalGrid_impl.hpp:68
SparseMesh< Scalar, NumSpaceDim > mesh_type
Mesh type.
Definition Cabana_Grid_SparseLocalGrid.hpp:48
static constexpr std::size_t num_space_dim
Spatial dimension.
Definition Cabana_Grid_SparseLocalGrid.hpp:51
Definition Cabana_Grid_SparseLocalGrid.hpp:35
Global logical grid.
Definition Cabana_Grid_GlobalGrid.hpp:39
Structured index space.
Definition Cabana_Grid_IndexSpace.hpp:37
Index space with tile as unit; _min and _max forms the tile range. Note this is for sparse grid only,...
Definition Cabana_Grid_SparseIndexSpace.hpp:1137
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36
Mesh cell tag.
Definition Cabana_Grid_Types.hpp:49
Mesh edge tag.
Definition Cabana_Grid_Types.hpp:95
Mesh face tag.
Definition Cabana_Grid_Types.hpp:64
Ghosted decomposition tag.
Definition Cabana_Grid_Types.hpp:197
Global index tag.
Definition Cabana_Grid_Types.hpp:215
Local index tag.
Definition Cabana_Grid_Types.hpp:208
Mesh node tag.
Definition Cabana_Grid_Types.hpp:56
Owned decomposition tag.
Definition Cabana_Grid_Types.hpp:190
Sparse mesh tag.
Definition Cabana_Grid_Types.hpp:253
static constexpr std::size_t num_space_dim
Definition Cabana_Grid_Types.hpp:258
Definition Cabana_Grid_Types.hpp:337