GEOSX
CellBlockUtilities.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_CELLBLOCKUTILITIES_HPP_
16 #define GEOS_MESH_GENERATORS_CELLBLOCKUTILITIES_HPP_
17 
18 #include "mesh/ElementType.hpp"
19 #include "common/DataTypes.hpp"
20 #include "common/Span.hpp"
21 #include "common/GEOS_RAJA_Interface.hpp"
22 
23 namespace geos
24 {
25 
30 template< typename T >
32 {
35 
41  ToCellRelation( T const & toBlockIndex_,
42  T const & toCellIndex_ )
43  : toBlockIndex( toBlockIndex_ ),
44  toCellIndex( toCellIndex_ )
45  { }
46 
52  ToCellRelation( T && toBlockIndex_,
53  T && toCellIndex_ )
54  : toBlockIndex( toBlockIndex_ ),
55  toCellIndex( toCellIndex_ )
56  { }
57 
58  ToCellRelation() = default;
59 };
60 
71  ArrayOfArraysView< localIndex const > const & faceToNodeMap,
72  ArrayOfArrays< localIndex > & faceToEdgeMap,
73  ArrayOfArrays< localIndex > & edgeToFaceMap,
74  array2d< localIndex > & edgeToNodeMap );
75 
85 localIndex getFaceNodes( ElementType const elementType,
86  localIndex const elemIdx,
87  localIndex const faceNumber,
89  Span< localIndex > const faceNodes );
90 
102 template< typename POLICY, typename T, typename COMP = std::equal_to<> >
104 computeUniqueValueOffsets( ArrayOfArraysView< T const > const & sortedLists, COMP && comp = {} )
105 {
106  localIndex const numNodes = sortedLists.size();
107  array1d< localIndex > uniqueValueOffsets( numNodes + 1 );
108 
109  // For each node, count number of unique edges that have the node as its lowest
110  arrayView1d< localIndex > const numUniqueValuesView = uniqueValueOffsets.toView();
111  forAll< POLICY >( numNodes, [sortedLists, numUniqueValuesView, comp=std::forward< COMP >( comp )]( localIndex const i )
112  {
113  arraySlice1d< T const > const list = sortedLists[ i ];
114  forEqualRanges( list.begin(), list.end(), [&]( auto, auto )
115  {
116  ++numUniqueValuesView[ i + 1 ];
117  }, comp );
118  } );
119 
120  // Perform an inplace prefix-sum to get the unique edge offset.
121  RAJA::inclusive_scan_inplace< POLICY >( RAJA::make_span( uniqueValueOffsets.data(), uniqueValueOffsets.size() ) );
122  return uniqueValueOffsets;
123 }
124 
125 }
126 
127 #endif // GEOS_MESH_GENERATORS_CELLBLOCKUTILITIES_HPP_
Lightweight non-owning wrapper over a contiguous range of elements.
Definition: Span.hpp:41
Array< T, 2, PERMUTATION > array2d
Alias for 2D array.
Definition: DataTypes.hpp:232
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:326
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.
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:31
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:236
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:216
LvArray::ArrayOfArrays< T, INDEX_TYPE, LvArray::ChaiBuffer > ArrayOfArrays
Array of variable-sized arrays. See LvArray::ArrayOfArrays for details.
Definition: DataTypes.hpp:322
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.