GEOSX
StructuredGridUtilities.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
15 #ifndef GEOSX_MESHUTILITIES_STRUCTUREDGRIDUTILITIES_HPP
16 #define GEOSX_MESHUTILITIES_STRUCTUREDGRIDUTILITIES_HPP
17 
22 namespace StructuredGrid
23 {
24 
30 template< int dim >
31 int dimpower( int n );
32 
34 
35 template<> inline int dimpower< 1 >( int n ) { return n; }
36 template<> inline int dimpower< 2 >( int n ) { return n*n; }
37 template<> inline int dimpower< 3 >( int n ) { return n*n*n; }
38 
40 
50 template< int dim >
51 void map_index( const int index,
52  const int nnx,
53  std::vector< int > & indices );
54 
56 
57 template<>
58 inline
59 void map_index< 1 >( const int index,
60  const int nnx,
61  std::vector< int > & indices )
62 {
63  GEOSX_ASSERT_GT( nnx, index );
64  GEOSX_DEBUG_VAR( nnx );
65  indices[0] = index;
66 }
67 
68 template<>
69 inline
70 void map_index< 2 >( const int index,
71  const int nnx,
72  std::vector< int > & indices )
73 {
74  GEOSX_ASSERT_GT( nnx*nnx, index );
75  indices[0] = index % nnx;
76  indices[1] = index / nnx;
77 }
78 
79 template<>
80 inline
81 void map_index< 3 >( const int index,
82  const int nnx,
83  std::vector< int > & indices )
84 {
85  GEOSX_ASSERT_GT( nnx*nnx*nnx, index );
86  indices[0] = index % nnx;
87  indices[1] = (index / nnx) % nnx;
88  indices[2] = index / (nnx*nnx);
89 }
90 
92 
93 } // end namespace
94 
95 #endif
#define GEOSX_ASSERT_GT(lhs, rhs)
Assert that one value compares greater than the other in debug builds.
Definition: Logger.hpp:284
void map_index(const int index, const int nnx, std::vector< int > &indices)
Given a lexicographical index, map back to the original i,j,k indices of the point. The first variation here assumes a uniform number of points nnx in all coordinate directions.
#define GEOSX_DEBUG_VAR(...)
Mark a debug variable and silence compiler warnings.
Definition: GeosxMacros.hpp:81
int dimpower(int n)
Given n, compute n^d, where d is the spatial dimension.