Cabana 0.8.0-dev
 
Loading...
Searching...
No Matches
Cabana_Grid_IndexConversion.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_INDEXCONVERSION_HPP
17#define CABANA_GRID_INDEXCONVERSION_HPP
18
20#include <Cabana_Grid_Types.hpp>
21
22#include <Kokkos_Core.hpp>
23
24#include <type_traits>
25
26namespace Cabana
27{
28namespace Grid
29{
30namespace IndexConversion
31{
32//---------------------------------------------------------------------------//
34template <class MeshType, class EntityType>
35struct L2G
36{
38 using mesh_type = MeshType;
39
41 static constexpr std::size_t num_space_dim = mesh_type::num_space_dim;
42
44 using entity_type = EntityType;
45
47 Kokkos::Array<int, num_space_dim> local_own_min;
48
50 Kokkos::Array<int, num_space_dim> local_own_max;
51
53 Kokkos::Array<int, num_space_dim> global_own_min;
54
56 Kokkos::Array<int, num_space_dim> global_num_entity;
57
59 Kokkos::Array<bool, num_space_dim> periodic;
60
62 Kokkos::Array<bool, num_space_dim> boundary_lo;
63
65 Kokkos::Array<bool, num_space_dim> boundary_hi;
66
68 L2G( const LocalGrid<MeshType>& local_grid )
69 {
70 // Local index set of owned entities.
71 auto local_own_space =
72 local_grid.indexSpace( Own(), EntityType(), Local() );
73
74 // Get the local owned min.
75 for ( std::size_t d = 0; d < num_space_dim; ++d )
76 local_own_min[d] = local_own_space.min( d );
77
78 // Get the local owned max.
79 for ( std::size_t d = 0; d < num_space_dim; ++d )
80 local_own_max[d] = local_own_space.max( d );
81
82 // Global index set of owned entities.
83 auto global_own_space =
84 local_grid.indexSpace( Own(), EntityType(), Global() );
85
86 // Get the global owned min.
87 for ( std::size_t d = 0; d < num_space_dim; ++d )
88 global_own_min[d] = global_own_space.min( d );
89
90 // Get the global grid.
91 const auto& global_grid = local_grid.globalGrid();
92
93 // Global number of entities.
94 for ( std::size_t d = 0; d < num_space_dim; ++d )
96 global_grid.globalNumEntity( EntityType(), d );
97
98 // Periodicity
99 for ( std::size_t d = 0; d < num_space_dim; ++d )
100 periodic[d] = global_grid.isPeriodic( d );
101
102 // Determine if a block is on the low or high boundaries.
103 for ( std::size_t d = 0; d < num_space_dim; ++d )
104 {
105 boundary_lo[d] = global_grid.onLowBoundary( d );
106 boundary_hi[d] = global_grid.onHighBoundary( d );
107 }
108 }
109
111 KOKKOS_INLINE_FUNCTION
112 void operator()( const int lijk[num_space_dim],
113 int gijk[num_space_dim] ) const
114 {
115 for ( std::size_t d = 0; d < num_space_dim; ++d )
116 {
117 // Compute periodic wrap-around on low boundary.
118 if ( periodic[d] && lijk[d] < local_own_min[d] && boundary_lo[d] )
119 {
120 gijk[d] = global_num_entity[d] - local_own_min[d] + lijk[d];
121 }
122
123 // Compute periodic wrap-around on high boundary.
124 else if ( periodic[d] && local_own_max[d] <= lijk[d] &&
125 boundary_hi[d] )
126 {
127 gijk[d] = lijk[d] - local_own_max[d];
128 }
129
130 // Otherwise compute I indices as normal.
131 else
132 {
133 gijk[d] = lijk[d] - local_own_min[d] + global_own_min[d];
134 }
135 }
136 }
137
139 template <std::size_t NSD = num_space_dim>
140 KOKKOS_INLINE_FUNCTION std::enable_if_t<3 == NSD, void>
141 operator()( const int li, const int lj, const int lk, int& gi, int& gj,
142 int& gk ) const
143 {
144 int lijk[num_space_dim] = { li, lj, lk };
145 int gijk[num_space_dim];
146 this->operator()( lijk, gijk );
147 gi = gijk[0];
148 gj = gijk[1];
149 gk = gijk[2];
150 }
151
153 template <std::size_t NSD = num_space_dim>
154 KOKKOS_INLINE_FUNCTION std::enable_if_t<2 == NSD, void>
155 operator()( const int li, const int lj, int& gi, int& gj ) const
156 {
157 int lijk[num_space_dim] = { li, lj };
158 int gijk[num_space_dim];
159 this->operator()( lijk, gijk );
160 gi = gijk[0];
161 gj = gijk[1];
162 }
163};
164
165//---------------------------------------------------------------------------//
168template <class MeshType, class EntityType>
170 EntityType )
171{
172 return L2G<MeshType, EntityType>( local_grid );
173}
174
175//---------------------------------------------------------------------------//
176
177} // end namespace IndexConversion
178} // namespace Grid
179} // namespace Cabana
180
181#endif // end CABANA_GRID_INDEXCONVERSION_HPP
L2G< MeshType, EntityType > createL2G(const LocalGrid< MeshType > &local_grid, EntityType)
Definition Cabana_Grid_IndexConversion.hpp:169
Logical grid indexing.
Grid type tags.
Local logical grid.
Definition Cabana_Grid_LocalGrid.hpp:39
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 ...
const GlobalGrid< MeshType > & globalGrid() const
Get the global grid that owns the local grid.
Definition Cabana_Grid_LocalGrid_impl.hpp:33
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36
Global index tag.
Definition Cabana_Grid_Types.hpp:215
Local-to-global indexer.
Definition Cabana_Grid_IndexConversion.hpp:36
Kokkos::Array< bool, num_space_dim > boundary_lo
True if block is on low boundary.
Definition Cabana_Grid_IndexConversion.hpp:62
Kokkos::Array< int, num_space_dim > local_own_min
Owned local indices minimum.
Definition Cabana_Grid_IndexConversion.hpp:47
static constexpr std::size_t num_space_dim
Spatial dimension.
Definition Cabana_Grid_IndexConversion.hpp:41
L2G(const LocalGrid< MeshType > &local_grid)
Constructor.
Definition Cabana_Grid_IndexConversion.hpp:68
KOKKOS_INLINE_FUNCTION std::enable_if_t< 2==NSD, void > operator()(const int li, const int lj, int &gi, int &gj) const
Convert local indices to global indices - 3D.
Definition Cabana_Grid_IndexConversion.hpp:155
KOKKOS_INLINE_FUNCTION void operator()(const int lijk[num_space_dim], int gijk[num_space_dim]) const
Convert local indices to global indices - general form.
Definition Cabana_Grid_IndexConversion.hpp:112
EntityType entity_type
Entity type.
Definition Cabana_Grid_IndexConversion.hpp:44
Kokkos::Array< bool, num_space_dim > boundary_hi
True if block is on high boundary.
Definition Cabana_Grid_IndexConversion.hpp:65
MeshType mesh_type
Mesh type.
Definition Cabana_Grid_IndexConversion.hpp:38
Kokkos::Array< bool, num_space_dim > periodic
Periodicity.
Definition Cabana_Grid_IndexConversion.hpp:59
Kokkos::Array< int, num_space_dim > local_own_max
Owned local indices maximum.
Definition Cabana_Grid_IndexConversion.hpp:50
Kokkos::Array< int, num_space_dim > global_own_min
Owned global indices minimum.
Definition Cabana_Grid_IndexConversion.hpp:53
KOKKOS_INLINE_FUNCTION std::enable_if_t< 3==NSD, void > operator()(const int li, const int lj, const int lk, int &gi, int &gj, int &gk) const
Convert local indices to global indices - 3D.
Definition Cabana_Grid_IndexConversion.hpp:141
Kokkos::Array< int, num_space_dim > global_num_entity
Global number of entities.
Definition Cabana_Grid_IndexConversion.hpp:56
Local index tag.
Definition Cabana_Grid_Types.hpp:208
Owned decomposition tag.
Definition Cabana_Grid_Types.hpp:190