18 #ifndef GEOS_MESH_UTILITIES_MESHMAPUTILITIES_HPP
19 #define GEOS_MESH_UTILITIES_MESHMAPUTILITIES_HPP
33 namespace meshMapUtilities
44 template<
typename T,
int USD >
56 template<
typename T >
68 template<
typename T >
86 template<
typename POLICY,
typename VIEW_TYPE >
94 counts.setValues< POLICY >( overAlloc );
95 forAll< POLICY >(
size0( srcMap ), [srcMap, counts = counts.toView()] (
localIndex const srcIndex )
97 for( localIndex const dstIndex : srcMap[ srcIndex ] )
99 RAJA::atomicInc< AtomicPolicy< POLICY > >( &counts[ dstIndex ] );
105 dstMap.resizeFromCapacities< parallelHostPolicy >( dstSize, counts.data() );
108 forAll< POLICY >(
size0( srcMap ), [srcMap, dstMap = dstMap.toView()] (
localIndex const srcIndex )
110 for( localIndex const dstIndex : srcMap[ srcIndex ] )
112 dstMap.emplaceBackAtomic< AtomicPolicy< POLICY > >( dstIndex, srcIndex );
126 template<
typename POLICY >
132 localIndex const numObjects = srcMap.toCellIndex.size();
134 localIndex const * offsets = srcMap.toCellIndex.toViewConst().getOffsets();
135 dstMap.m_toElementRegion.resizeFromOffsets( numObjects, offsets );
136 dstMap.m_toElementSubRegion.resizeFromOffsets( numObjects, offsets );
137 dstMap.m_toElementIndex.resizeFromOffsets( numObjects, offsets );
139 forAll< POLICY >( numObjects, [toCell = srcMap.toCellIndex.toViewConst(),
140 toBlock = srcMap.toBlockIndex.toViewConst(),
141 toRegion = dstMap.m_toElementRegion.toView(),
142 toSubRegion = dstMap.m_toElementSubRegion.toView(),
143 toElement = dstMap.m_toElementIndex.toView(),
144 blockToSubRegion](
localIndex const objIndex )
146 arraySlice1d< localIndex const > const cells = toCell[objIndex];
147 for( localIndex i = 0; i < cells.size(); ++i )
149 localIndex const blockIndex = toBlock( objIndex, i );
150 localIndex const er = blockToSubRegion( blockIndex, 0 );
151 localIndex const esr = blockToSubRegion( blockIndex, 1 );
154 if( er >= 0 && esr >= 0 )
156 toRegion.emplaceBack( objIndex, er );
157 toSubRegion.emplaceBack( objIndex, esr );
158 toElement.emplaceBack( objIndex, cells[i] );
171 template<
typename POLICY,
typename PERM1,
typename PERM2 >
177 localIndex const numObjects = srcMap.toCellIndex.size( 0 );
178 localIndex const maxCellsPerObject = srcMap.toCellIndex.size( 1 );
180 dstMap.m_toElementRegion.resize( numObjects, maxCellsPerObject );
181 dstMap.m_toElementSubRegion.resize( numObjects, maxCellsPerObject );
182 dstMap.m_toElementIndex.resize( numObjects, maxCellsPerObject );
184 forAll< POLICY >( numObjects, [toCell = srcMap.toCellIndex.toViewConst(),
185 toBlock = srcMap.toBlockIndex.toViewConst(),
186 toRegion = dstMap.m_toElementRegion.toView(),
187 toSubRegion = dstMap.m_toElementSubRegion.toView(),
188 toElement = dstMap.m_toElementIndex.toView(),
190 maxCellsPerObject](
localIndex const objIndex )
192 arraySlice1d< localIndex const > const cells = toCell[objIndex];
193 localIndex cellCount = 0;
194 for( localIndex i = 0; i < maxCellsPerObject && cells[i] >= 0; ++i )
196 localIndex const blockIndex = toBlock( objIndex, i );
197 localIndex const er = blockToSubRegion( blockIndex, 0 );
198 localIndex const esr = blockToSubRegion( blockIndex, 1 );
201 if( er >= 0 && esr >= 0 )
203 toRegion( objIndex, cellCount ) = er;
204 toSubRegion( objIndex, cellCount ) = esr;
205 toElement( objIndex, cellCount ) = cells[i];
218 template<
typename T >
231 hash ^= std::hash< T >{} ( v ) + 0x9e3779b9 + ( hash << 6 ) + ( hash >> 2 );
242 template<
typename T >
245 return std::array< T, 6 > { v, -1, -1, -1, -1, -1 };
256 template<
typename T >
265 return std::array< T, 6 > { v1, v2, -1, -1, a, -1 };
269 return std::array< T, 6 > { v2, v1, -1, -1, order - a, -1 };
284 template<
typename T >
285 static std::array< T, 6 >
createNodeKey( T v1, T v2, T v3, T v4,
int a,
int b,
int order )
297 while( v1 > v2 || v1 > v3 || v1 > v4 || v2 > v3 )
324 return std::array< T, 6 > { v1, v2, v3, v4, a, b };
336 template<
typename T >
337 static std::array< T, 6 >
createNodeKey( T
const (&elemNodes)[ 8 ],
int q1,
int q2,
int q3,
int order )
339 bool extremal1 = q1 == 0 || q1 == order;
340 bool extremal2 = q2 == 0 || q2 == order;
341 bool extremal3 = q3 == 0 || q3 == order;
345 if( extremal1 && extremal2 && extremal3 )
350 else if( extremal1 && extremal2 )
353 return createNodeKey( elemNodes[ v1 + 2*v2 ], elemNodes[ v1 + 2*v2 + 4 ], q3, order );
355 else if( extremal1 && extremal3 )
358 return createNodeKey( elemNodes[ v1 + 4*v3 ], elemNodes[ v1 + 2 + 4*v3 ], q2, order );
360 else if( extremal2 && extremal3 )
363 return createNodeKey( elemNodes[ 2*v2 + 4*v3 ], elemNodes[ 1 + 2*v2 + 4*v3 ], q1, order );
368 return createNodeKey( elemNodes[ v1 ], elemNodes[ v1 + 2 ], elemNodes[ v1 + 4 ], elemNodes[ v1 + 2 + 4 ], q2, q3, order );
373 return createNodeKey( elemNodes[ 2*v2 ], elemNodes[ 1 + 2*v2 ], elemNodes[ 2*v2 + 4 ], elemNodes[ 1 + 2*v2 + 4 ], q1, q3, order );
378 return createNodeKey( elemNodes[ 4*v3 ], elemNodes[ 1 + 4*v3 ], elemNodes[ 2 + 4*v3 ], elemNodes[ 1 + 2 + 4*v3 ], q1, q2, order );
#define GEOS_HOST_DEVICE
Marks a host-device function.
#define GEOS_ASSERT_EQ(lhs, rhs)
Assert that two values compare equal in debug builds.
A relationship to an element.
Base template for ordered and unordered maps.
ArrayOfArrays< std::remove_const_t< typename VIEW_TYPE::ValueType > > transposeIndexMap(VIEW_TYPE const &srcMap, localIndex const dstSize, localIndex const overAlloc=0)
Transposes an input map (array2d, ArrayOfArrays or ArrayOfSets)
void transformCellBlockToRegionMap(arrayView2d< localIndex const > const &blockToSubRegion, ToCellRelation< array2d< localIndex, PERM1 > > const &srcMap, ToElementRelation< array2d< localIndex, PERM2 > > &dstMap)
Convert ToCellRelation into ToElementRelation.
GEOS_HOST_DEVICE localIndex size0(arrayView2d< T, USD > const &map)
Array< T, 2, PERMUTATION > array2d
Alias for 2D array.
LvArray::ArrayOfSetsView< T, INDEX_TYPE const, LvArray::ChaiBuffer > ArrayOfSetsView
View of array of variable-sized sets. See LvArray::ArrayOfSetsView for details.
LvArray::ArrayOfArraysView< T, INDEX_TYPE const, CONST_SIZES, LvArray::ChaiBuffer > ArrayOfArraysView
View of array of variable-sized arrays. See LvArray::ArrayOfArraysView for details.
std::size_t size_t
Unsigned size type.
static std::array< T, 6 > createNodeKey(T const (&elemNodes)[8], int q1, int q2, int q3, int order)
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Array< T, 1 > array1d
Alias for 1D array.
LvArray::ArrayOfArrays< T, INDEX_TYPE, LvArray::ChaiBuffer > ArrayOfArrays
Array of variable-sized arrays. See LvArray::ArrayOfArrays for details.
Strucure used to hash interpolation arrays representing high-order nodes.
std::size_t operator()(const std::array< T, 6 > &arr) const
Container for maps from a mesh object (node, edge or face) to cells.