20 #ifndef GEOS_LINEARALGEBRA_DOFMANAGERHELPERS_HPP
21 #define GEOS_LINEARALGEBRA_DOFMANAGERHELPERS_HPP
36 template< FieldLocation LOC >
42 using ManagerType = NodeManager;
45 static LocalIndexType constexpr invalid_local_index{ -1 };
47 static constexpr
char const * managerGroupName() {
return MeshLevel::groupStructKeys::nodeManagerString(); }
49 static constexpr
char const * syncObjName =
"node";
51 template<
typename MANAGER >
52 using MapType =
typename MANAGER::NodeMapType;
58 using ManagerType = EdgeManager;
61 static LocalIndexType constexpr invalid_local_index{ -1 };
63 static constexpr
char const * managerGroupName() {
return MeshLevel::groupStructKeys::edgeManagerString(); }
65 static constexpr
char const * syncObjName =
"edge";
67 template<
typename MANAGER >
68 using MapType =
typename MANAGER::EdgeMapType;
74 using ManagerType = FaceManager;
77 static LocalIndexType constexpr invalid_local_index{ -1 };
79 static constexpr
char const * managerGroupName() {
return MeshLevel::groupStructKeys::faceManagerString(); }
81 static constexpr
char const * syncObjName =
"face";
83 template<
typename MANAGER >
84 using MapType =
typename MANAGER::FaceMapType;
90 using ManagerType = ElementSubRegionBase;
91 using LocalIndexType = std::array< localIndex, 3 >;
93 static LocalIndexType constexpr invalid_local_index{ -1, -1, -1 };
95 static constexpr
auto managerGroupName() {
return MeshLevel::groupStructKeys::elemManagerString(); }
96 static constexpr
auto syncObjName =
"elems";
98 template<
typename MANAGER >
99 using MapType =
typename MANAGER::ElemMapType;
113 template< FieldLocation LOC, FieldLocation LOC_ADJ >
114 struct MeshIncidence {};
117 template< FieldLocation LOC >
118 struct MeshIncidence< LOC, LOC >
124 #define SET_MAX_MESH_INCIDENCE( LOC, LOC_ADJ, MAX ) \
126 struct MeshIncidence< FieldLocation::LOC, FieldLocation::LOC_ADJ > \
128 static localIndex constexpr max = MAX; \
147 #undef SET_MAX_MESH_INCIDENCE
155 template<
typename LAMBDA >
163 lambda( std::integral_constant< FieldLocation, FieldLocation::Node >() );
168 lambda( std::integral_constant< FieldLocation, FieldLocation::Edge >() );
173 lambda( std::integral_constant< FieldLocation, FieldLocation::Face >() );
178 lambda( std::integral_constant< FieldLocation, FieldLocation::Elem >() );
186 template<
typename LAMBDA >
193 LocationSwitch( loc1, [&](
auto const loc_type1 )
196 LocationSwitch( loc2, [&](
auto const loc_type2 )
198 lambda( loc_type1, loc_type2 );
204 template< FieldLocation LOC >
205 typename MeshHelper< LOC >::ManagerType
const & getObjectManager( MeshLevel
const & mesh )
207 using ObjectManager =
typename MeshHelper< LOC >::ManagerType;
208 return mesh.getGroup< ObjectManager >( MeshHelper< LOC >::managerGroupName() );
211 template< FieldLocation LOC >
212 typename MeshHelper< LOC >::ManagerType & getObjectManager( MeshLevel & mesh )
214 using ObjectManager =
typename MeshHelper< LOC >::ManagerType;
215 return mesh.getGroup< ObjectManager >( MeshHelper< LOC >::managerGroupName() );
218 ObjectManagerBase
const & getObjectManager(
FieldLocation const loc,
219 MeshLevel
const & mesh )
221 ObjectManagerBase
const * manager =
nullptr;
222 LocationSwitch( loc, [&](
auto const LOC )
224 manager = &getObjectManager< decltype(LOC)::value >( mesh );
230 ObjectManagerBase & getObjectManager(
FieldLocation const loc,
233 return const_cast< ObjectManagerBase &
>( getObjectManager( loc,
const_cast< MeshLevel
const &
>( mesh ) ) );
241 template< FieldLocation LOC,
typename MANAGER >
242 using MapType =
typename MeshHelper< LOC >::template MapType< MANAGER >;
251 template< FieldLocation LOC, FieldLocation CONN_LOC,
bool VISIT_GHOSTS >
262 template< FieldLocation LOC,
bool VISIT_GHOSTS >
263 struct MeshVisitor< LOC, LOC, VISIT_GHOSTS >
265 template<
typename POLICY,
typename ... SUBREGIONTYPES,
typename REGIONS_CONTAINER,
typename LAMBDA >
266 static void visit( MeshLevel
const & meshLevel,
267 REGIONS_CONTAINER
const & regions,
271 using ObjectManagerLoc =
typename MeshHelper< LOC >::ManagerType;
274 ObjectManagerLoc
const & objectManager = getObjectManager< LOC >( meshLevel );
275 arrayView1d< integer const >
const & ghostRank = objectManager.ghostRank();
278 array1d< integer > visited( objectManager.size() );
280 meshLevel.getElemManager().
281 forElementSubRegions< SUBREGIONTYPES... >( regions, [&](
localIndex const,
auto const & subRegion )
284 using ElemToLocMapType = MapType< LOC, TYPEOFREF( subRegion ) >;
287 auto const & elemToLocMap =
288 subRegion.template getReference< ElemToLocMapType >( MeshHelper< LOC >::mapViewKey() ).toViewConst();
291 forAll< parallelHostPolicy >( subRegion.size(), [=, visited = visited.toView()](
localIndex const ei )
294 auto const locList = elemToLocMap[ei];
295 for( localIndex a = 0; a < locList.size(); ++a )
297 localIndex const locIdx = locList[a];
298 if( VISIT_GHOSTS || ghostRank[locIdx] < 0 )
300 RAJA::atomicInc< parallelHostAtomic >( &visited[locIdx] );
307 array1d< localIndex > locations;
308 locations.reserve( objectManager.size() );
309 for(
localIndex i = 0; i < visited.size(); ++i )
313 locations.emplace_back( i );
318 if( locations.size() == objectManager.size() )
320 forAll< POLICY >( objectManager.size(), [=](
localIndex const locIdx )
322 lambda( locIdx, locIdx, 0 );
327 forAll< POLICY >( locations.size(), [=, locations = locations.toViewConst()](
localIndex const i )
329 localIndex const locIdx = locations[i];
330 lambda( locIdx, locIdx, 0 );
342 template< FieldLocation LOC, FieldLocation CONN_LOC,
bool VISIT_GHOSTS >
345 template<
typename POLICY,
typename ... SUBREGIONTYPES,
typename REGIONS_CONTAINER,
typename LAMBDA >
346 static void visit( MeshLevel
const & meshLevel,
347 REGIONS_CONTAINER
const & regions,
351 using ObjectManagerLoc =
typename MeshHelper< LOC >::ManagerType;
352 using LocToConnMapType = MapType< CONN_LOC, ObjectManagerLoc >;
354 ObjectManagerLoc
const & objectManager = getObjectManager< LOC >( meshLevel );
357 auto const & locToConnMap =
358 objectManager.template getReference< LocToConnMapType >( MeshHelper< CONN_LOC >::mapViewKey() ).toViewConst();
361 MeshVisitor< LOC, LOC, VISIT_GHOSTS >::
362 template visit< POLICY, SUBREGIONTYPES... >( meshLevel, regions,
368 auto const connList = locToConnMap[locIdx];
369 for(
localIndex b = 0; b < connList.size(); ++b )
371 lambda( locIdx, connList[b], b );
385 template< FieldLocation LOC,
bool VISIT_GHOSTS >
388 template<
typename POLICY,
typename ... SUBREGIONTYPES,
typename REGIONS_CONTAINER,
typename LAMBDA >
389 static void visit( MeshLevel
const & meshLevel,
390 REGIONS_CONTAINER
const & regions,
394 using ObjectManagerLoc =
typename MeshHelper< LOC >::ManagerType;
395 using ToElemMapType =
typename MapType< FieldLocation::Elem, ObjectManagerLoc >::base_type;
398 ObjectManagerLoc
const & objectManager = getObjectManager< LOC >( meshLevel );
401 using keys =
typename ObjectManagerLoc::viewKeyStruct;
402 auto const & elemRegionList =
403 objectManager.template getReference< ToElemMapType >( keys::elementRegionListString() ).toViewConst();
404 auto const & elemSubRegionList =
405 objectManager.template getReference< ToElemMapType >( keys::elementSubRegionListString() ).toViewConst();
406 auto const & elemIndexList =
407 objectManager.template getReference< ToElemMapType >( keys::elementListString() ).toViewConst();
410 MeshVisitor< LOC, LOC, VISIT_GHOSTS >::
411 template visit< POLICY, SUBREGIONTYPES... >( meshLevel, regions,
417 auto const elemRegions = elemRegionList[ locIdx ];
418 auto const elemSubRegions = elemSubRegionList[ locIdx ];
419 auto const elemIndices = elemIndexList[ locIdx ];
420 for(
localIndex b = 0; b < elemIndices.size(); ++b )
422 MeshHelper< FieldLocation::Elem >::LocalIndexType
const elemIdx =
423 { elemRegions[b], elemSubRegions[b], elemIndices[b] };
425 if( elemIdx[0] >= 0 && elemIdx[1] >= 0 && elemIdx[2] >= 0 )
427 lambda( locIdx, elemIdx, b );
442 template< FieldLocation CONN_LOC,
bool VISIT_GHOSTS >
445 template<
typename POLICY,
typename ... SUBREGIONTYPES,
typename REGIONS_CONTAINER,
typename LAMBDA >
446 static void visit( MeshLevel
const & meshLevel,
447 REGIONS_CONTAINER
const & regions,
450 meshLevel.getElemManager().
451 forElementSubRegionsComplete< SUBREGIONTYPES... >( regions, [&](
localIndex const,
454 ElementRegionBase
const &,
455 auto const & subRegion )
458 using ElemToConnMapType = MapType< CONN_LOC, TYPEOFREF( subRegion ) >;
461 auto const & elemToConnMap =
462 subRegion.template getReference< ElemToConnMapType >( MeshHelper< CONN_LOC >::mapViewKey() ).toViewConst();
464 arrayView1d< integer const >
const & ghostRank = subRegion.ghostRank();
466 forAll< POLICY >( subRegion.size(), [=](
localIndex const ei )
468 if( VISIT_GHOSTS || ghostRank[ei] < 0 )
470 auto const elemIdx = MeshHelper< FieldLocation::Elem >::LocalIndexType{ er, esr, ei };
471 auto const connList = elemToConnMap[ei];
473 for( localIndex a = 0; a < connList.size(); ++a )
475 lambda( elemIdx, connList[a], a );
487 template<
bool VISIT_GHOSTS >
490 template<
typename POLICY,
typename ... SUBREGIONTYPES,
typename REGIONS_CONTAINER,
typename LAMBDA >
491 static void visit( MeshLevel
const & meshLevel,
492 REGIONS_CONTAINER
const & regions,
495 meshLevel.getElemManager().
496 forElementSubRegionsComplete< SUBREGIONTYPES... >( regions, [&](
localIndex const,
499 ElementRegionBase
const &,
500 ElementSubRegionBase
const & subRegion )
502 arrayView1d< integer const >
const & ghostRank = subRegion.ghostRank();
504 forAll< POLICY >( subRegion.size(), [=](
localIndex const ei )
506 if( VISIT_GHOSTS || ghostRank[ei] < 0 )
508 MeshHelper< FieldLocation::Elem >::LocalIndexType elemIdx{ er, esr, ei };
509 lambda( elemIdx, elemIdx, 0 );
540 typename POLICY,
typename ... SUBREGIONTYPES,
typename REGIONS_CONTAINER,
typename LAMBDA >
541 void forMeshLocation( MeshLevel
const & mesh,
542 REGIONS_CONTAINER
const & regions,
545 MeshVisitor< LOC, CONN_LOC, VISIT_GHOSTS >::
546 template visit< POLICY, SUBREGIONTYPES... >( mesh,
548 std::forward< LAMBDA >( lambda ) );
555 typename POLICY,
typename ... SUBREGIONTYPES,
typename REGIONS_CONTAINER,
typename LAMBDA >
556 void forMeshLocation( MeshLevel
const & mesh,
557 REGIONS_CONTAINER
const & regions,
560 forMeshLocation< LOC, LOC, VISIT_GHOSTS, POLICY, SUBREGIONTYPES... >( mesh,
562 [=](
auto const locIdx,
auto, auto )
578 template<
FieldLocation LOC,
bool VISIT_GHOSTS,
typename ... SUBREGIONTYPES,
typename REGIONS_CONTAINER >
579 localIndex countMeshObjects( MeshLevel
const & mesh,
580 REGIONS_CONTAINER
const & regions )
582 using countPolicy = parallelHostPolicy;
583 RAJA::ReduceSum< ReducePolicy< countPolicy >,
localIndex > count( 0 );
584 forMeshLocation< LOC, VISIT_GHOSTS, countPolicy, SUBREGIONTYPES... >( mesh, regions, [=]( auto )
601 template<
bool VISIT_GHOSTS,
typename ... SUBREGIONTYPES,
typename REGIONS_CONTAINER >
603 MeshLevel
const & mesh,
604 REGIONS_CONTAINER
const & regions )
607 bool const success = LocationSwitch( location, [&](
auto const loc )
610 count = countMeshObjects< LOC, VISIT_GHOSTS, SUBREGIONTYPES... >( mesh, regions );
612 GEOS_ERROR_IF( !success,
"Invalid location type: " <<
static_cast< int >( location ) );
622 template<
typename T, FieldLocation LOC >
625 using ArrayType = array1d< std::remove_const_t< T > >;
626 using ViewType = arrayView1d< T >;
627 using Accessor = ViewType;
629 template<
typename ... SUBREGIONTYPES,
typename REGIONS_CONTAINER >
631 create( MeshLevel & mesh,
633 string const & description,
636 ObjectManagerBase & baseManager = getObjectManager< LOC >( mesh );
637 baseManager.registerWrapper< ArrayType >( key ).
638 setApplyDefaultValue( -1 ).
639 setPlotLevel( dataRepository::PlotLevel::LEVEL_1 ).
640 setRestartFlags( dataRepository::RestartFlags::NO_WRITE ).
641 setDescription( description );
644 static Accessor get( add_const_if_t< MeshLevel, std::is_const< T >::value > & mesh,
string const & key )
646 return getObjectManager< LOC >( mesh ).template getReference< ArrayType >( key );
649 static inline T value( Accessor
const & indexArray,
typename MeshHelper< LOC >::LocalIndexType
const i )
651 return indexArray[i];
654 static inline T & reference( Accessor
const & indexArray,
typename MeshHelper< LOC >::LocalIndexType
const i )
656 return indexArray[i];
659 template<
typename ... SUBREGIONTYPES,
typename REGIONS_CONTAINER >
661 remove( MeshLevel & mesh,
665 getObjectManager< LOC >( mesh ).deregisterWrapper( key );
673 template<
typename T >
676 using ArrayType = array1d< std::remove_const_t< T > >;
677 using ViewType = arrayView1d< T >;
678 using Accessor = ElementRegionManager::ElementViewAccessor< ViewType >;
680 template<
typename ... SUBREGIONTYPES,
typename REGIONS_CONTAINER >
682 create( MeshLevel & mesh,
684 string const & description,
685 REGIONS_CONTAINER
const & regions )
687 mesh.getElemManager().template forElementSubRegions< SUBREGIONTYPES... >( regions,
688 [&](
localIndex const, ElementSubRegionBase & subRegion )
690 subRegion.registerWrapper< ArrayType >( key ).
691 setApplyDefaultValue( -1 ).
692 setPlotLevel( dataRepository::PlotLevel::LEVEL_1 ).
693 setRestartFlags( dataRepository::RestartFlags::NO_WRITE ).
694 setDescription( description );
698 static Accessor get( add_const_if_t< MeshLevel, std::is_const< T >::value > & mesh,
string const & key )
700 return mesh.getElemManager().template constructViewAccessor< ArrayType, ViewType >( key );
703 static inline T value( Accessor
const & indexArray,
704 MeshHelper< FieldLocation::Elem >::LocalIndexType
const & e )
706 if( indexArray[std::get< 0 >( e )].empty() || indexArray[std::get< 0 >( e )][std::get< 1 >( e )].empty() )
710 return indexArray[std::get< 0 >( e )][std::get< 1 >( e )][std::get< 2 >( e )];
713 static inline T & reference( Accessor
const & indexArray,
714 MeshHelper< FieldLocation::Elem >::LocalIndexType
const & e )
716 return indexArray[std::get< 0 >( e )][std::get< 1 >( e )][std::get< 2 >( e )];
719 template<
typename ... SUBREGIONTYPES,
typename REGIONS_CONTAINER >
721 remove( MeshLevel & mesh,
723 REGIONS_CONTAINER
const & regions )
725 mesh.getElemManager().template forElementSubRegions< SUBREGIONTYPES... >( regions,
726 [&](
localIndex const, ElementSubRegionBase & subRegion )
728 subRegion.deregisterWrapper( key );
#define SET_MAX_MESH_INCIDENCE(LOC, LOC_ADJ, MAX)
Shortcut macro for declaring adjacency.
#define GEOS_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
#define GEOS_ASSERT(EXP)
Assert a condition in debug builds.
#define GEOS_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
FieldLocation
Enum defining the possible location of a field on the mesh.
@ Node
location is node (like displacements in finite elements)
@ Face
location is face (like flux in mixed finite elements)
@ Elem
location is element (like pressure in finite volumes)
@ Edge
location is edge (like flux between fracture elements)
static constexpr char const * nodeListString()
static constexpr char const * edgeListString()
static constexpr char const * faceListString()