GEOS
PrismUtilities.hpp
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_GENERATORS_PRISMUTILITIES_HPP_
17 #define GEOS_MESH_GENERATORS_PRISMUTILITIES_HPP_
18 
19 #include "common/DataTypes.hpp"
20 #include "common/Span.hpp"
21 
22 namespace geos
23 {
24 
36 template< localIndex N >
39  Span< localIndex > const faceNodes )
40 {
41  static_assert( N > 4,
42  "Function getFaceNodePrism can be called for a prism with N-sided polygon base where N > 5." );
43  static constexpr auto nodeCountError = "Not enough nodes for {} element (face index = {}).\n";
44  GEOS_UNUSED_VAR( nodeCountError ); // Not used in GPU builds.
45 
46  if( faceNum == 0 )
47  {
48  GEOS_ERROR_IF_LT_MSG( faceNodes.size(), 4,
49  GEOS_FMT( "{}{}",
50  GEOS_FMT( nodeCountError, N, faceNum ),
52  faceNodes[0] = elemNodes[0];
53  faceNodes[1] = elemNodes[1];
54  faceNodes[2] = elemNodes[N+1];
55  faceNodes[3] = elemNodes[N];
56  return 4;
57  }
58  else if( faceNum == 1 )
59  {
60  GEOS_ERROR_IF_LT_MSG( faceNodes.size(), N,
61  GEOS_FMT( "{}{}",
62  GEOS_FMT( nodeCountError, N, faceNum ),
64  faceNodes[0] = elemNodes[0];
65  for( localIndex i = 1; i < N; ++i )
66  {
67  faceNodes[i] = elemNodes[N-i];
68  }
69  return N;
70  }
71  else if( faceNum == 2 )
72  {
73  GEOS_ERROR_IF_LT_MSG( faceNodes.size(), 4,
74  GEOS_FMT( "{}{}",
75  GEOS_FMT( nodeCountError, N, faceNum ),
77  faceNodes[0] = elemNodes[0];
78  faceNodes[1] = elemNodes[N];
79  faceNodes[2] = elemNodes[N*2-1];
80  faceNodes[3] = elemNodes[N-1];
81  return 4;
82  }
83  else if( faceNum >= 3 && faceNum <= N )
84  {
85  GEOS_ERROR_IF_LT_MSG( faceNodes.size(), 4,
86  GEOS_FMT( "{}{}",
87  GEOS_FMT( nodeCountError, N, faceNum ),
89  faceNodes[0] = elemNodes[faceNum-2];
90  faceNodes[1] = elemNodes[faceNum-1];
91  faceNodes[2] = elemNodes[N+faceNum-1];
92  faceNodes[3] = elemNodes[N+faceNum-2];
93  return 4;
94  }
95  else if( faceNum == N + 1 )
96  {
97  GEOS_ERROR_IF_LT_MSG( faceNodes.size(), N,
98  GEOS_FMT( "{}{}",
99  GEOS_FMT( nodeCountError, N, faceNum ),
101  for( localIndex i = 0; i < N; ++i )
102  {
103  faceNodes[i] = elemNodes[i+N];
104  }
105  return N;
106  }
107  else
108  {
109  GEOS_ERROR( GEOS_FMT( "Local face index out of range for Prism{} element: face index = {}.\n{}",
110  N, faceNum, generalMeshErrorAdvice ) );
111  return 0;
112  }
113 
114 }
115 
116 }
117 
118 #endif // GEOS_MESH_GENERATORS_PRISMUTILITIES_HPP_
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:84
#define GEOS_ERROR(...)
Raise a hard error and terminate the program.
Definition: Logger.hpp:226
#define GEOS_ERROR_IF_LT_MSG(lhs, rhs,...)
Raise a hard error if one value compares less than the other.
Definition: Logger.hpp:523
Lightweight non-owning wrapper over a contiguous range of elements.
Definition: Span.hpp:42
constexpr size_type size() const noexcept
Definition: Span.hpp:107
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:84
ArraySlice< T, 1, USD > arraySlice1d
Alias for 1D array slice.
Definition: DataTypes.hpp:183
localIndex getFaceNodesPrism(localIndex const faceNum, arraySlice1d< localIndex const, cells::NODE_MAP_USD - 1 > const &elemNodes, Span< localIndex > const faceNodes)
Get the local indices of the nodes in a face of the prism with N-sided polygon base.
constexpr auto generalMeshErrorAdvice
String available for mesh errors.