GEOS
CellBlockUtilities.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 Total, S.A
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_CELLBLOCKUTILITIES_HPP_
17 #define GEOS_MESH_GENERATORS_CELLBLOCKUTILITIES_HPP_
18 
19 #include "mesh/ElementType.hpp"
20 #include "common/DataTypes.hpp"
21 #include "common/Span.hpp"
22 #include "common/GEOS_RAJA_Interface.hpp"
23 
24 namespace geos
25 {
26 
31 template< typename T >
33 {
36 
42  ToCellRelation( T const & toBlockIndex_,
43  T const & toCellIndex_ )
44  : toBlockIndex( toBlockIndex_ ),
45  toCellIndex( toCellIndex_ )
46  { }
47 
53  ToCellRelation( T && toBlockIndex_,
54  T && toCellIndex_ )
55  : toBlockIndex( toBlockIndex_ ),
56  toCellIndex( toCellIndex_ )
57  { }
58 
59  ToCellRelation() = default;
60 };
61 
72  ArrayOfArraysView< localIndex const > const & faceToNodeMap,
73  ArrayOfArrays< localIndex > & faceToEdgeMap,
74  ArrayOfArrays< localIndex > & edgeToFaceMap,
75  array2d< localIndex > & edgeToNodeMap );
76 
86 localIndex getFaceNodes( ElementType const elementType,
87  localIndex const elemIdx,
88  localIndex const faceNumber,
90  Span< localIndex > const faceNodes );
91 
103 template< typename POLICY, typename T, typename COMP = std::equal_to<> >
105 computeUniqueValueOffsets( ArrayOfArraysView< T const > const & sortedLists, COMP && comp = {} )
106 {
107  localIndex const numNodes = sortedLists.size();
108  array1d< localIndex > uniqueValueOffsets( numNodes + 1 );
109 
110  // For each node, count number of unique edges that have the node as its lowest
111  arrayView1d< localIndex > const numUniqueValuesView = uniqueValueOffsets.toView();
112  forAll< POLICY >( numNodes, [sortedLists, numUniqueValuesView, comp=std::forward< COMP >( comp )]( localIndex const i )
113  {
114  arraySlice1d< T const > const list = sortedLists[ i ];
115  forEqualRanges( list.begin(), list.end(), [&]( auto, auto )
116  {
117  ++numUniqueValuesView[ i + 1 ];
118  }, comp );
119  } );
120 
121  // Perform an inplace prefix-sum to get the unique edge offset.
122  RAJA::inclusive_scan_inplace< POLICY >( RAJA::make_span( uniqueValueOffsets.data(), uniqueValueOffsets.size() ) );
123  return uniqueValueOffsets;
124 }
125 
126 }
127 
128 #endif // GEOS_MESH_GENERATORS_CELLBLOCKUTILITIES_HPP_
Lightweight non-owning wrapper over a contiguous range of elements.
Definition: Span.hpp:42
Array< T, 2, PERMUTATION > array2d
Alias for 2D array.
Definition: DataTypes.hpp:192
LvArray::ArrayOfArraysView< T, INDEX_TYPE const, CONST_SIZES, LvArray::ChaiBuffer > ArrayOfArraysView
View of array of variable-sized arrays. See LvArray::ArrayOfArraysView for details.
Definition: DataTypes.hpp:286
array1d< localIndex > computeUniqueValueOffsets(ArrayOfArraysView< T const > const &sortedLists, COMP &&comp={})
Find and count ranges of repeated values in an array of sorted arrays and compute offsets.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85
localIndex getFaceNodes(ElementType const elementType, localIndex const elemIdx, localIndex const faceNumber, arrayView2d< localIndex const, cells::NODE_MAP_USD > const &elementToNodes, Span< localIndex > const faceNodes)
Get the local indices of the nodes in a face of the element.
localIndex buildEdgeMaps(localIndex numNodes, ArrayOfArraysView< localIndex const > const &faceToNodeMap, ArrayOfArrays< localIndex > &faceToEdgeMap, ArrayOfArrays< localIndex > &edgeToFaceMap, array2d< localIndex > &edgeToNodeMap)
Free function that generates face to edges, edge to faces and edge to nodes mappings.
ElementType
Denotes type of cell/element shape.
Definition: ElementType.hpp:32
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:196
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:176
LvArray::ArrayOfArrays< T, INDEX_TYPE, LvArray::ChaiBuffer > ArrayOfArrays
Array of variable-sized arrays. See LvArray::ArrayOfArrays for details.
Definition: DataTypes.hpp:282
Container for maps from a mesh object (node, edge or face) to cells.
ToCellRelation(T &&toBlockIndex_, T &&toCellIndex_)
Constructor from moved values.
T toCellIndex
Map containing cell indices, same shape as above.
ToCellRelation(T const &toBlockIndex_, T const &toCellIndex_)
Constructor by values.
T toBlockIndex
Map containing a list of cell block indices for each object.