Loading...
Searching...
No Matches
grid_types.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include "../kokkos/kokkos_wrapper.hpp"
5#include "../types.hpp"
6#include "dense/mat.hpp"
7
8namespace terra::grid {
9
10using Layout = Kokkos::LayoutRight;
11
12template < typename ScalarType >
13using Grid0DDataScalar = Kokkos::View< ScalarType, Layout >;
14
15template < typename ScalarType >
16using Grid1DDataScalar = Kokkos::View< ScalarType*, Layout >;
17
18template < typename ScalarType >
19using Grid2DDataScalar = Kokkos::View< ScalarType**, Layout >;
20
21template < typename ScalarType >
22using Grid3DDataScalar = Kokkos::View< ScalarType***, Layout >;
23
24template < typename ScalarType >
25using Grid4DDataScalar = Kokkos::View< ScalarType****, Layout >;
26
27template < typename ScalarType >
28using Grid5DDataScalar = Kokkos::View< ScalarType*****, Layout >;
29
30template < typename ScalarType, int VecDim >
31using Grid0DDataVec = Kokkos::View< ScalarType[VecDim], Layout >;
32
33template < typename ScalarType, int VecDim >
34using Grid1DDataVec = Kokkos::View< ScalarType* [VecDim], Layout >;
35
36template < typename ScalarType, int VecDim >
37using Grid2DDataVec = Kokkos::View< ScalarType** [VecDim], Layout >;
38
39template < typename ScalarType, int VecDim >
40using Grid3DDataVec = Kokkos::View< ScalarType*** [VecDim], Layout >;
41
42template < typename ScalarType, int VecDim >
43using Grid4DDataVec = Kokkos::View< ScalarType**** [VecDim], Layout >;
44
45template < typename ScalarType, int Rows, int Cols, int NumMatrices >
46using Grid4DDataMatrices = Kokkos::View< dense::Mat< ScalarType, Rows, Cols >****[NumMatrices], Layout >;
47
48template < typename GridDataType >
49constexpr int grid_data_vec_dim()
50{
51 if constexpr (
52 std::is_same_v< GridDataType, Grid0DDataScalar< typename GridDataType::value_type > > ||
53 std::is_same_v< GridDataType, Grid1DDataScalar< typename GridDataType::value_type > > ||
54 std::is_same_v< GridDataType, Grid2DDataScalar< typename GridDataType::value_type > > ||
55 std::is_same_v< GridDataType, Grid3DDataScalar< typename GridDataType::value_type > > ||
56 std::is_same_v< GridDataType, Grid4DDataScalar< typename GridDataType::value_type > > )
57 {
58 return 1;
59 }
60
61 else if constexpr (
62 std::is_same_v< GridDataType, Grid0DDataVec< typename GridDataType::value_type, 1 > > ||
63 std::is_same_v< GridDataType, Grid1DDataVec< typename GridDataType::value_type, 1 > > ||
64 std::is_same_v< GridDataType, Grid2DDataVec< typename GridDataType::value_type, 1 > > ||
65 std::is_same_v< GridDataType, Grid3DDataVec< typename GridDataType::value_type, 1 > > ||
66 std::is_same_v< GridDataType, Grid4DDataVec< typename GridDataType::value_type, 1 > > )
67 {
68 return 1;
69 }
70
71 else if constexpr (
72 std::is_same_v< GridDataType, Grid0DDataVec< typename GridDataType::value_type, 2 > > ||
73 std::is_same_v< GridDataType, Grid1DDataVec< typename GridDataType::value_type, 2 > > ||
74 std::is_same_v< GridDataType, Grid2DDataVec< typename GridDataType::value_type, 2 > > ||
75 std::is_same_v< GridDataType, Grid3DDataVec< typename GridDataType::value_type, 2 > > ||
76 std::is_same_v< GridDataType, Grid4DDataVec< typename GridDataType::value_type, 2 > > )
77 {
78 return 2;
79 }
80
81 else if constexpr (
82 std::is_same_v< GridDataType, Grid0DDataVec< typename GridDataType::value_type, 3 > > ||
83 std::is_same_v< GridDataType, Grid1DDataVec< typename GridDataType::value_type, 3 > > ||
84 std::is_same_v< GridDataType, Grid2DDataVec< typename GridDataType::value_type, 3 > > ||
85 std::is_same_v< GridDataType, Grid3DDataVec< typename GridDataType::value_type, 3 > > ||
86 std::is_same_v< GridDataType, Grid4DDataVec< typename GridDataType::value_type, 3 > > )
87 {
88 return 3;
89 }
90
91 return -1;
92}
93
94/// @brief Enum for encoding the boundary type tuples (in \ref BoundaryVertex, \ref BoundaryEdge, \ref BoundaryFace).
95enum class BoundaryPosition : int
96{
97 /// start (`== 0`)
98 P0 = 0,
99
100 /// end (`== size - 1`)
101 P1 = 1,
102
103 /// variable
104 PV = 2
105};
106
108{
109 return ( static_cast< int >( x ) << 4 ) | ( static_cast< int >( y ) << 2 ) | ( static_cast< int >( r ) << 0 );
110}
111
112/// @brief Enum for identification of the 8 boundary vertices of a subdomain.
113///
114/// @code
115/// V_011
116/// => x = 0,
117/// y = size - 1,
118/// r = size - 1
119/// @endcode
132
133/// @brief Enum for identification of the 12 boundary edges of a subdomain.
134///
135/// @code
136/// E_1Y0
137/// => x = size - 1,
138/// y = variable,
139/// r = 0
140/// @endcode
141enum class BoundaryEdge : int
142{
143 // edge along x, y=0, r=0, (:,BoundaryPosition::START,BoundaryPosition::START) in slice notation
148
149 // (0, :,BoundaryPosition::START) in slice notation
154
159};
160
161/// @brief Enum for identification of the 6 boundary faces of a subdomain.
162///
163/// @code
164/// F_X1R
165/// => x = variable,
166/// y = size - 1,
167/// r = variable
168/// @endcode
181
182/// @brief Enum for the iteration direction at a boundary.
183enum class BoundaryDirection : int
184{
185 FORWARD = 0,
187};
188
189template < typename BoundaryType >
190constexpr BoundaryPosition boundary_position_from_boundary_type_x( const BoundaryType& boundary_type )
191{
192 static_assert(
193 std::is_same_v< BoundaryType, BoundaryVertex > || std::is_same_v< BoundaryType, BoundaryEdge > ||
194 std::is_same_v< BoundaryType, BoundaryFace > );
195
196 return static_cast< BoundaryPosition >( ( static_cast< int >( boundary_type ) & 0b110000 ) >> 4 );
197}
198
199template < typename BoundaryType >
200constexpr BoundaryPosition boundary_position_from_boundary_type_y( const BoundaryType& boundary_type )
201{
202 static_assert(
203 std::is_same_v< BoundaryType, BoundaryVertex > || std::is_same_v< BoundaryType, BoundaryEdge > ||
204 std::is_same_v< BoundaryType, BoundaryFace > );
205
206 return static_cast< BoundaryPosition >( ( static_cast< int >( boundary_type ) & 0b001100 ) >> 2 );
207}
208
209template < typename BoundaryType >
210constexpr BoundaryPosition boundary_position_from_boundary_type_r( const BoundaryType& boundary_type )
211{
212 static_assert(
213 std::is_same_v< BoundaryType, BoundaryVertex > || std::is_same_v< BoundaryType, BoundaryEdge > ||
214 std::is_same_v< BoundaryType, BoundaryFace > );
215
216 return static_cast< BoundaryPosition >( ( static_cast< int >( boundary_type ) & 0b000011 ) >> 0 );
217}
218
219constexpr bool is_edge_boundary_radial( const BoundaryEdge id )
220{
221 return id == BoundaryEdge::E_00R || id == BoundaryEdge::E_10R || id == BoundaryEdge::E_01R ||
223}
224
226{
227 return id == BoundaryFace::F_XY0 || id == BoundaryFace::F_XY1;
228}
229
238
248
265
274
275// String conversion functions
276inline std::string to_string( BoundaryVertex v )
277{
278 switch ( v )
279 {
281 return "V_000";
283 return "V_100";
285 return "V_010";
287 return "V_110";
289 return "V_001";
291 return "V_101";
293 return "V_011";
295 return "V_111";
296 default:
297 return "<unknown LocalBoundaryVertex>";
298 }
299}
300
301inline std::string to_string( BoundaryEdge e )
302{
303 switch ( e )
304 {
306 return "E_X00";
308 return "E_X10";
310 return "E_X01";
312 return "E_X11";
314 return "E_0Y0";
316 return "E_1Y0";
318 return "E_0Y1";
320 return "E_1Y1";
322 return "E_00R";
324 return "E_10R";
326 return "E_01R";
328 return "E_11R";
329 default:
330 return "<unknown LocalBoundaryEdge>";
331 }
332}
333
334inline std::string to_string( BoundaryFace f )
335{
336 switch ( f )
337 {
339 return "F_XY0";
341 return "F_XY1";
343 return "F_X0R";
345 return "F_X1R";
347 return "F_0YR";
349 return "F_1YR";
350 default:
351 return "<unknown LocalBoundaryFace>";
352 }
353}
354
355inline std::ostream& operator<<( std::ostream& os, BoundaryVertex v )
356{
357 return os << to_string( v );
358}
359
360inline std::ostream& operator<<( std::ostream& os, BoundaryEdge e )
361{
362 return os << to_string( e );
363}
364
365inline std::ostream& operator<<( std::ostream& os, BoundaryFace f )
366{
367 return os << to_string( f );
368}
369
370} // namespace terra::grid
Definition bit_masks.hpp:8
Kokkos::View< ScalarType, Layout > Grid0DDataScalar
Definition grid_types.hpp:13
Kokkos::View< ScalarType *****, Layout > Grid5DDataScalar
Definition grid_types.hpp:28
constexpr bool is_edge_boundary_radial(const BoundaryEdge id)
Definition grid_types.hpp:219
Kokkos::View< dense::Mat< ScalarType, Rows, Cols > ****[NumMatrices], Layout > Grid4DDataMatrices
Definition grid_types.hpp:46
Kokkos::View< ScalarType ***[VecDim], Layout > Grid3DDataVec
Definition grid_types.hpp:40
BoundaryPosition
Enum for encoding the boundary type tuples (in BoundaryVertex, BoundaryEdge, BoundaryFace).
Definition grid_types.hpp:96
Kokkos::View< ScalarType ***, Layout > Grid3DDataScalar
Definition grid_types.hpp:22
BoundaryVertex
Enum for identification of the 8 boundary vertices of a subdomain.
Definition grid_types.hpp:121
constexpr std::array all_boundary_faces
Definition grid_types.hpp:266
BoundaryDirection
Enum for the iteration direction at a boundary.
Definition grid_types.hpp:184
constexpr std::array all_boundary_vertices
Definition grid_types.hpp:239
std::ostream & operator<<(std::ostream &os, BoundaryVertex v)
Definition grid_types.hpp:355
constexpr std::array all_boundary_edges
Definition grid_types.hpp:249
Kokkos::LayoutRight Layout
Definition grid_types.hpp:10
Kokkos::View< ScalarType ****[VecDim], Layout > Grid4DDataVec
Definition grid_types.hpp:43
Kokkos::View< ScalarType **[VecDim], Layout > Grid2DDataVec
Definition grid_types.hpp:37
constexpr int grid_data_vec_dim()
Definition grid_types.hpp:49
Kokkos::View< ScalarType *[VecDim], Layout > Grid1DDataVec
Definition grid_types.hpp:34
constexpr int boundary_position_encoding(const BoundaryPosition x, const BoundaryPosition y, const BoundaryPosition r)
Definition grid_types.hpp:107
constexpr BoundaryPosition boundary_position_from_boundary_type_y(const BoundaryType &boundary_type)
Definition grid_types.hpp:200
constexpr bool is_face_boundary_normal_to_radial_direction(const BoundaryFace id)
Definition grid_types.hpp:225
std::string to_string(BoundaryVertex v)
Definition grid_types.hpp:276
constexpr BoundaryPosition boundary_position_from_boundary_type_r(const BoundaryType &boundary_type)
Definition grid_types.hpp:210
Kokkos::View< ScalarType[VecDim], Layout > Grid0DDataVec
Definition grid_types.hpp:31
constexpr BoundaryVertex other_side_r(BoundaryVertex boundary_vertex)
Definition grid_types.hpp:230
BoundaryFace
Enum for identification of the 6 boundary faces of a subdomain.
Definition grid_types.hpp:170
Kokkos::View< ScalarType ****, Layout > Grid4DDataScalar
Definition grid_types.hpp:25
constexpr BoundaryPosition boundary_position_from_boundary_type_x(const BoundaryType &boundary_type)
Definition grid_types.hpp:190
Kokkos::View< ScalarType *, Layout > Grid1DDataScalar
Definition grid_types.hpp:16
Kokkos::View< ScalarType **, Layout > Grid2DDataScalar
Definition grid_types.hpp:19
BoundaryEdge
Enum for identification of the 12 boundary edges of a subdomain.
Definition grid_types.hpp:142