GEOSX
PrismUtilities.hpp
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 TotalEnergies
8  * Copyright (c) 2020- 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 GEOS_MESH_GENERATORS_PRISMUTILITIES_HPP_
16 #define GEOS_MESH_GENERATORS_PRISMUTILITIES_HPP_
17 
18 #include "common/DataTypes.hpp"
19 #include "common/Span.hpp"
20 
21 namespace geos
22 {
23 
35 template< localIndex N >
38  Span< localIndex > const faceNodes )
39 {
40  static_assert( N > 4,
41  "Function getFaceNodePrism can be called for a prism with N-sided polygon base where N > 5." );
42  static constexpr auto nodeCountError = "Not enough nodes for {} element (face index = {}).\n";
43 
44  if( faceNum == 0 )
45  {
46  GEOS_ERROR_IF_LT_MSG( faceNodes.size(), 4, GEOS_FMT( nodeCountError, N, faceNum ) << generalMeshErrorAdvice );
47  faceNodes[0] = elemNodes[0];
48  faceNodes[1] = elemNodes[1];
49  faceNodes[2] = elemNodes[N+1];
50  faceNodes[3] = elemNodes[N];
51  return 4;
52  }
53  else if( faceNum == 1 )
54  {
55  GEOS_ERROR_IF_LT_MSG( faceNodes.size(), N, GEOS_FMT( nodeCountError, N, faceNum ) << generalMeshErrorAdvice );
56  faceNodes[0] = elemNodes[0];
57  for( localIndex i = 1; i < N; ++i )
58  {
59  faceNodes[i] = elemNodes[N-i];
60  }
61  return N;
62  }
63  else if( faceNum == 2 )
64  {
65  GEOS_ERROR_IF_LT_MSG( faceNodes.size(), 4, GEOS_FMT( nodeCountError, N, faceNum ) << generalMeshErrorAdvice );
66  faceNodes[0] = elemNodes[0];
67  faceNodes[1] = elemNodes[N];
68  faceNodes[2] = elemNodes[N*2-1];
69  faceNodes[3] = elemNodes[N-1];
70  return 4;
71  }
72  else if( faceNum >= 3 && faceNum <= N )
73  {
74  GEOS_ERROR_IF_LT_MSG( faceNodes.size(), 4, GEOS_FMT( nodeCountError, N, faceNum ) << generalMeshErrorAdvice );
75  faceNodes[0] = elemNodes[faceNum-2];
76  faceNodes[1] = elemNodes[faceNum-1];
77  faceNodes[2] = elemNodes[N+faceNum-1];
78  faceNodes[3] = elemNodes[N+faceNum-2];
79  return 4;
80  }
81  else if( faceNum == N + 1 )
82  {
83  GEOS_ERROR_IF_LT_MSG( faceNodes.size(), N, GEOS_FMT( nodeCountError, N, faceNum ) << generalMeshErrorAdvice );
84  for( localIndex i = 0; i < N; ++i )
85  {
86  faceNodes[i] = elemNodes[i+N];
87  }
88  return N;
89  }
90  else
91  {
92  GEOS_ERROR( GEOS_FMT( "Local face index out of range for Prism{} element: face index = {}.\n{}",
93  N, faceNum, generalMeshErrorAdvice ) );
94  return 0;
95  }
96 
97 }
98 
99 }
100 
101 #endif // GEOS_MESH_GENERATORS_PRISMUTILITIES_HPP_
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:122
#define GEOS_ERROR_IF_LT_MSG(lhs, rhs, msg)
Raise a hard error if one value compares less than the other.
Definition: Logger.hpp:304
Lightweight non-owning wrapper over a contiguous range of elements.
Definition: Span.hpp:41
constexpr size_type size() const noexcept
Definition: Span.hpp:106
ArraySlice< T, 1, USD > arraySlice1d
Alias for 1D array slice.
Definition: DataTypes.hpp:224
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.
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
constexpr auto generalMeshErrorAdvice
String available for mesh errors.