19 #ifndef GEOS_LINEARALGEBRA_MULTISCALE_MESHUTILS_HPP
20 #define GEOS_LINEARALGEBRA_MULTISCALE_MESHUTILS_HPP
29 class DomainPartition;
55 template<
typename T >
57 : m_manager( manager ),
58 m_key( std::move( key ) )
97 template<
typename T,
typename U = T >
103 dst.reserve( src.size() );
104 for( T
const & val : src )
106 U
const newVal =
map[val];
109 dst.emplace_back( newVal );
126 template<
typename T,
typename U = T >
132 values.reserve( src.size() );
133 for( T
const & val : src )
135 U
const newVal =
map[val];
138 values.insert( newVal );
142 dst.reserve( values.size() );
143 for( U
const & val : values )
145 dst.emplace_back( val );
157 template<
typename T,
typename U = T >
162 dst.reserve( src.size() );
163 for( T
const & val : src )
165 U
const newVal =
map[val];
168 dst.insert( newVal );
187 template<
typename POLICY,
typename T,
int NDIM,
int USD,
typename INDEX,
typename FUNC >
192 forAll< POLICY >(
map.size(), [=]( INDEX
const srcIdx )
194 INDEX const dstIdx = map[srcIdx];
197 LvArray::forValuesInSliceWithIndices( dst[dstIdx], [&]( T & dstValue, auto ... indices )
199 dstValue = src( srcIdx, indices ... );
219 template<
typename POLICY,
typename T,
int NDIM,
int USD,
typename INDEX,
typename FUNC >
225 forAll< POLICY >(
map.size(), [=]( INDEX
const dstIndex )
227 INDEX const srcIndex = map[dstIndex];
230 LvArray::forValuesInSliceWithIndices( dst[dstIndex], [&]( T & dstValue, auto ... indices )
232 dstValue = src( srcIndex, indices ... );
247 template<
typename FUNC >
249 string const & mapKey,
250 std::vector< integer >
const & ranks,
255 for(
integer const rank : ranks )
259 copyFunc( srcData.ghostsToSend(),
map, dstData.ghostsToSend() );
260 copyFunc( srcData.ghostsToReceive(),
map, dstData.ghostsToReceive() );
261 copyFunc( srcData.adjacencyList(),
map, dstData.adjacencyList() );
262 copyFunc( srcData.matchedPartitionBoundary(),
map, dstData.matchedPartitionBoundary() );
273 string const & mapKey,
282 IS_VALID_EXPRESSION( isCallableWithoutArgs, T, std::declval< T >()() );
283 IS_VALID_EXPRESSION_2( isCallableWithArg, T, U, std::declval< T >()( std::declval< U >() ) );
284 IS_VALID_EXPRESSION_2( isCallableWithArgAndCount, T, U, std::declval< T >()( std::declval< U >(), std::ptrdiff_t{} ) );
286 template<
typename T,
typename FUNC >
287 std::enable_if_t< isCallableWithoutArgs< FUNC > >
288 callWithArgs( T
const & val, std::ptrdiff_t
const count, FUNC && func )
294 template<
typename T,
typename FUNC >
295 std::enable_if_t< isCallableWithArg< FUNC, T > >
296 callWithArgs( T
const & val, std::ptrdiff_t
const count, FUNC && func )
302 template<
typename T,
typename FUNC >
303 std::enable_if_t< isCallableWithArgAndCount< FUNC, T > >
304 callWithArgs( T
const & val, std::ptrdiff_t
const count, FUNC && func )
320 template<
typename ITER,
typename FUNC >
325 LvArray::sortedArrayManipulation::makeSorted( first, last );
326 using T =
typename std::iterator_traits< ITER >::value_type;
327 while( first != last )
329 T
const & curr = *first;
330 ITER
const it = std::find_if( first, last, [&curr]( T
const & v ) {
return v != curr; } );
331 internal::callWithArgs( curr, std::distance( first, it ), std::forward< FUNC >( func ) );
349 template<
integer MAX_NEIGHBORS,
typename L2C_MAP,
typename C2L_MAP,
typename PRED,
typename FUNC >
351 L2C_MAP
const & locToConn,
352 C2L_MAP
const & connToLoc,
358 for(
localIndex const connIdx : locToConn[locIdx] )
360 if( connIdx >= 0 && connPred( connIdx ) )
362 for(
localIndex const nbrIdx : connToLoc[connIdx] )
364 GEOS_ERROR_IF_GE_MSG( numNeighbors, MAX_NEIGHBORS,
"Too many neighbors, need to increase stack limit" );
365 neighbors[numNeighbors++] = nbrIdx;
369 forUniqueValues( neighbors, neighbors + numNeighbors, std::forward< FUNC >( func ) );
385 template<
integer MAX_NEIGHBORS,
typename L2C_MAP,
typename C2L_MAP,
typename FUNC >
387 L2C_MAP
const & locToConn,
388 C2L_MAP
const & connToLoc,
391 forUniqueNeighbors< MAX_NEIGHBORS >( locIdx,
394 [](
auto ){
return true; },
395 std::forward< FUNC >( func ) );
411 template<
integer MAX_NEIGHBORS,
typename NBR_MAP,
typename VAL_FUNC,
typename VAL_PRED,
typename FUNC >
413 NBR_MAP
const & neighbors,
414 VAL_FUNC && valueFunc,
418 using T = std::remove_cv_t< std::remove_reference_t< decltype( valueFunc(
localIndex {} ) ) >>;
419 T nbrValues[MAX_NEIGHBORS];
421 for(
localIndex const nbrIdx : neighbors[locIdx] )
423 GEOS_ERROR_IF_GE_MSG( numValues, MAX_NEIGHBORS,
"Too many neighbors, need to increase stack limit" );
424 T
const value = valueFunc( nbrIdx );
427 nbrValues[numValues++] = value;
430 forUniqueValues( nbrValues, nbrValues + numValues, std::forward< FUNC >( func ) );
446 template<
integer MAX_NEIGHBORS,
typename NBR_MAP,
typename VAL_FUNC,
typename FUNC >
448 NBR_MAP
const & neighbors,
449 VAL_FUNC && valueFunc,
452 forUniqueNeighborValues< MAX_NEIGHBORS >( locIdx,
454 std::forward< VAL_FUNC >( valueFunc ),
455 [](
auto ){
return true; },
456 std::forward< FUNC >( func ) );
471 template<
typename INDEX_TYPE >
483 forAll< parallelHostPolicy >( fineObjectManager.
size(), [=, rowCounts = rowCounts.toView()](
localIndex const objIdx )
485 localIndex count = 0;
486 forUniqueNeighborValues< 256 >( objIdx, dualMap, subdomains, [&count]
490 rowCounts[objIdx] = count;
492 for(
string const & setName : boundaryObjectSets )
495 forAll< parallelHostPolicy >(
set.size(), [=, rowCounts = rowCounts.toView()](
localIndex const i )
503 objectToSubdomain.template resizeFromCapacities< parallelHostPolicy >( rowCounts.size(), rowCounts.data() );
506 INDEX_TYPE numBoundaries = 0;
507 for(
string const & setName : boundaryObjectSets )
511 forAll< parallelHostPolicy >(
set.size(), [=, objToSub = objectToSubdomain.toView()](
localIndex const i )
513 objToSub.insertIntoSet( set[i], -numBoundaries );
516 forAll< parallelHostPolicy >( fineObjectManager.size(), [=, objToSub = objectToSubdomain.toView()](
localIndex const objIdx )
518 for( localIndex const dualIdx : dualMap[objIdx] )
520 objToSub.insertIntoSet( objIdx, subdomains[dualIdx] );
524 return objectToSubdomain;
539 template<
typename INDEX_TYPE >
540 ArrayOfSets< INDEX_TYPE >
548 forAll< parallelHostPolicy >( manager.
size(), [=, rowCounts = rowCounts.toView()](
localIndex const objIdx )
550 rowCounts[objIdx] = inputMap.sizeOfSet( objIdx );
552 for(
string const & setName: boundaryObjectSets )
555 forAll< parallelHostPolicy >(
set.size(), [=, rowCounts = rowCounts.toView()](
localIndex const i )
563 outputMap.template resizeFromCapacities< parallelHostPolicy >( rowCounts.size(), rowCounts.data() );
566 INDEX_TYPE numBoundaries = 0;
567 for(
string const & setName: boundaryObjectSets )
571 forAll< parallelHostPolicy >(
set.size(), [=, outputMap = outputMap.toView()](
localIndex const i )
573 outputMap.insertIntoSet( set[i], -numBoundaries );
576 forAll< parallelHostPolicy >( manager.
size(), [=, outputMap = outputMap.toView()](
localIndex const objIdx )
578 outputMap.insertIntoSet( objIdx, inputMap[objIdx].begin(), inputMap[objIdx].end() );
610 bool allowMultiNodes =
true );
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
#define GEOS_ASSERT_EQ(lhs, rhs)
Assert that two values compare equal in debug builds.
#define GEOS_ERROR_IF_GE_MSG(lhs, rhs, msg)
Raise a hard error if one value compares greater than or equal to the other.
void mapIndexSet(SortedArrayView< T const > const &src, arrayView1d< U const > const &map, SortedArray< U > &dst)
Transform a set of mesh indices using a map.
void mapIndexArrayUnique(arrayView1d< T const > const &src, arrayView1d< U const > const &map, array1d< U > &dst)
Transform an array of mesh indices using a map, removing duplicates.
void fillArrayBySrcIndex(arrayView1d< INDEX const > const &map, ArrayView< T, NDIM, USD > const &dst, FUNC &&src)
Populate an array using a function source and an index map.
void fillArrayByDstIndex(arrayView1d< INDEX const > const &map, ArrayView< T, NDIM, USD > const &dst, FUNC &&src)
Populate an array using a function source and an index map.
void forUniqueNeighbors(localIndex const locIdx, L2C_MAP const &locToConn, C2L_MAP const &connToLoc, PRED &&connPred, FUNC &&func)
Call a function on unique indices of topological neighbors visited through location-connector adjacen...
void forUniqueNeighborValues(localIndex const locIdx, NBR_MAP const &neighbors, VAL_FUNC &&valueFunc, VAL_PRED &&pred, FUNC &&func)
Call a function on unique values of topological neighbors visited through location-connector adjacenc...
ArrayOfSets< INDEX_TYPE > addBoundarySubdomains(MeshObjectManager const &manager, ArrayOfSetsView< INDEX_TYPE const > const &inputMap, string_array const &boundaryObjectSets)
Insert virtual boundary subdomains into an adjacency map.
array1d< localIndex > findCoarseNodesByDualPartition(MeshObjectManager::MapViewConst const &nodeToDual, MeshObjectManager::MapViewConst const &dualToNode, ArrayOfSetsView< globalIndex const > const &nodeToSubdomain, integer const minSubdomains, bool allowMultiNodes=true)
Find "coarse" nodes in a mesh in which dual objects have been partitioned into subdomains.
void mapIndexArray(arrayView1d< T const > const &src, arrayView1d< U const > const &map, array1d< U > &dst)
Transform an array of mesh indices using a map.
void copyNeighborData(ObjectManagerBase const &srcManager, string const &mapKey, std::vector< integer > const &ranks, ObjectManagerBase &dstManager, FUNC &©Func)
Sets up NeighborData of a new object manager mapped from existing one.
void forUniqueValues(ITER first, ITER const last, FUNC &&func)
Call a function on unique values from a previously collected range.
ArrayOfSets< INDEX_TYPE > buildFineObjectToSubdomainMap(MeshObjectManager const &fineObjectManager, arrayView1d< INDEX_TYPE const > const &subdomains, string_array const &boundaryObjectSets)
Build a map from mesh objects (nodes/cells) to subdomains defined by a partitioning of dual objects (...
void copySets(ObjectManagerBase const &srcManager, string const &mapKey, ObjectManagerBase &dstManager)
Copy and update sets from an existing to a new object manager.
#define GEOS_MARK_FUNCTION
Mark function with both Caliper and NVTX if enabled.
Partition of the decomposed physical domain. It also manages the connexion information to its neighbo...
The ObjectManagerBase is the base object of all object managers in the mesh data hierachy.
NeighborData & getNeighborData(int const rank)
Get neighbor data for given rank.
SortedArray< localIndex > & getSet(string const &setName)
Get a set by name.
Wrapper< TBASE > & registerWrapper(string const &name, wrapperMap::KeyIndex::index_type *const rkey=nullptr)
Create and register a Wrapper around a new object.
GEOS_DECLTYPE_AUTO_RETURN getReference(LOOKUP_TYPE const &lookup) const
Look up a wrapper and get reference to wrapped object.
void deregisterWrapper(string const &name)
Removes a Wrapper from this group.
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers.
Base template for ordered and unordered maps.
Mesh object manager used in multiscale preconditioners to keep a simplified (node/cell only) represen...
decltype(std::declval< MapType >().base().toViewConst()) MapViewConst
Alias for relation map const view type.
MapType & toDualRelation()
Utility class to manage registration of temporary scope-bound data in the data repository.
ScopedDataRegistrar(ObjectManagerBase &manager, string key, T &data)
Constructor.
~ScopedDataRegistrar()
Destructor.
void sync(DomainPartition &domain) const
Synchronize data across ranks.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
stdVector< string > string_array
A 1-dimensional array of geos::string types.
LvArray::ArrayOfSetsView< T, INDEX_TYPE const, LvArray::ChaiBuffer > ArrayOfSetsView
View of array of variable-sized sets. See LvArray::ArrayOfSetsView for details.
std::set< T > set
A set of local indices.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
LvArray::SortedArray< T, localIndex, LvArray::ChaiBuffer > SortedArray
A sorted array of local indices.
LvArray::ArrayOfSets< T, INDEX_TYPE, LvArray::ChaiBuffer > ArrayOfSets
Array of variable-sized sets. See LvArray::ArrayOfSets for details.
LvArray::SortedArrayView< T, localIndex, LvArray::ChaiBuffer > SortedArrayView
A sorted array view of local indices.
int integer
Signed integer type.
Array< T, 1 > array1d
Alias for 1D array.
LvArray::ArrayView< T, NDIM, USD, localIndex, LvArray::ChaiBuffer > ArrayView
Multidimensional array view type. See LvArray:ArrayView for details.