GEOS
StructuredGridUtilities.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
16 #ifndef GEOS_MESH_UTILITIES_STRUCTUREDGRIDUTILITIES_HPP
17 #define GEOS_MESH_UTILITIES_STRUCTUREDGRIDUTILITIES_HPP
18 
23 namespace structuredGrid
24 {
25 
31 template< int dim >
32 int dimpower( int n );
33 
35 
36 template<> inline int dimpower< 1 >( int n ) { return n; }
37 template<> inline int dimpower< 2 >( int n ) { return n*n; }
38 template<> inline int dimpower< 3 >( int n ) { return n*n*n; }
39 
41 
51 template< int dim >
52 void map_index( const int index,
53  const int nnx,
54  std::vector< int > & indices );
55 
57 
58 template<>
59 inline
60 void map_index< 1 >( const int index,
61  const int nnx,
62  std::vector< int > & indices )
63 {
64  GEOS_ASSERT_GT( nnx, index );
65  GEOS_DEBUG_VAR( nnx );
66  indices[0] = index;
67 }
68 
69 template<>
70 inline
71 void map_index< 2 >( const int index,
72  const int nnx,
73  std::vector< int > & indices )
74 {
75  GEOS_ASSERT_GT( nnx*nnx, index );
76  indices[0] = index % nnx;
77  indices[1] = index / nnx;
78 }
79 
80 template<>
81 inline
82 void map_index< 3 >( const int index,
83  const int nnx,
84  std::vector< int > & indices )
85 {
86  GEOS_ASSERT_GT( nnx*nnx*nnx, index );
87  indices[0] = index % nnx;
88  indices[1] = (index / nnx) % nnx;
89  indices[2] = index / (nnx*nnx);
90 }
91 
93 
94 } /* namespace structuredGrid */
95 
96 #endif /* GEOS_MESH_UTILITIES_STRUCTUREDGRIDUTILITIES_HPP */
#define GEOS_DEBUG_VAR(...)
Mark a debug variable and silence compiler warnings.
Definition: GeosxMacros.hpp:87
#define GEOS_ASSERT_GT(lhs, rhs)
Assert that one value compares greater than the other in debug builds.
Definition: Logger.hpp:440
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....
int dimpower(int n)
Given n, compute n^dim, where dim is the spatial dimension.