19 #ifndef GEOSX_LINEARALGEBRA_DOFMANAGERHELPERS_HPP 20 #define GEOSX_LINEARALGEBRA_DOFMANAGERHELPERS_HPP 33 template< DofManager::Location LOC >
38 struct MeshHelper< DofManager::Location::Node >
40 using ManagerType = NodeManager;
43 static LocalIndexType constexpr invalid_local_index{ -1 };
45 static constexpr
auto managerGroupName = MeshLevel::groupStructKeys::nodeManagerString;
47 static constexpr
auto syncObjName =
"node";
49 template<
typename MANAGER >
50 using MapType =
typename MANAGER::NodeMapType;
54 struct MeshHelper< DofManager::Location::Edge >
56 using ManagerType = EdgeManager;
59 static LocalIndexType constexpr invalid_local_index{ -1 };
61 static constexpr
auto managerGroupName = MeshLevel::groupStructKeys::edgeManagerString;
63 static constexpr
auto syncObjName =
"edge";
65 template<
typename MANAGER >
66 using MapType =
typename MANAGER::EdgeMapType;
70 struct MeshHelper< DofManager::Location::Face >
72 using ManagerType = FaceManager;
75 static LocalIndexType constexpr invalid_local_index{ -1 };
77 static constexpr
auto managerGroupName = MeshLevel::groupStructKeys::faceManagerString;
79 static constexpr
auto syncObjName =
"face";
81 template<
typename MANAGER >
82 using MapType =
typename MANAGER::FaceMapType;
86 struct MeshHelper< DofManager::Location::Elem >
88 using ManagerType = ElementSubRegionBase;
89 using LocalIndexType = std::array< localIndex, 3 >;
91 static LocalIndexType constexpr invalid_local_index{ -1, -1, -1 };
93 static constexpr
auto managerGroupName = MeshLevel::groupStructKeys::elemManagerString;
94 static constexpr
auto syncObjName =
"elems";
96 template<
typename MANAGER >
97 using MapType =
typename MANAGER::ElemMapType;
112 template< DofManager::Location LOC, DofManager::Location LOC_ADJ >
113 struct MeshIncidence {};
116 template< DofManager::Location LOC >
117 struct MeshIncidence< LOC, LOC >
123 #define SET_MAX_MESH_INCIDENCE( LOC, LOC_ADJ, MAX ) \ 125 struct MeshIncidence< DofManager::Location::LOC, DofManager::Location::LOC_ADJ > \ 127 static localIndex constexpr max = MAX; \ 146 #undef SET_MAX_MESH_INCIDENCE 148 template< DofManager::Location LOC,
typename MANAGER >
151 using type =
typename MeshHelper< LOC >::template MapType< MANAGER >;
156 template< DofManager::Location LOC,
typename MANAGER >
157 using MapType =
typename MapTypeHelper< LOC, MANAGER >::type;
160 template<
typename T,
bool >
161 struct BaseTypeHelper
166 template<
typename T >
167 struct BaseTypeHelper< T, true >
169 using type =
typename T::base_type;
174 template<
typename MAP >
175 using BaseType =
typename BaseTypeHelper< MAP, HasMemberType_base_type< MAP > >::type;
181 template<
typename MAP >
185 template<
typename T,
typename PERMUTATION >
186 struct MapHelperImpl<
array2d< T, PERMUTATION > >
188 static localIndex size0( array2d< T, PERMUTATION >
const &
map )
190 return map.size( 0 );
195 return map.size( 1 );
198 static T
const & value( array2d< T, PERMUTATION >
const & map,
localIndex const i0,
localIndex const i1 )
200 return map( i0, i1 );
205 return map.size( 0 );
210 return map.size( 1 );
215 return map( i0, i1 );
220 template<
typename T >
230 return map[i0].size();
245 return map[i0].size();
255 template<
typename T >
258 static localIndex size0( ArrayOfArraysView< T const >
const & map )
265 return map.sizeOfArray( i0 );
268 static T
const & value( ArrayOfArraysView< T const >
const & map,
localIndex const i0,
localIndex const i1 )
270 return map( i0, i1 );
274 template<
typename T >
284 return map[i0].size();
293 template<
typename T >
296 static localIndex size0( ArrayOfSetsView< T const >
const & map )
303 return map.sizeOfSet( i0 );
306 static T
const & value( ArrayOfSetsView< T const >
const & map,
localIndex const i0,
localIndex const i1 )
308 return map( i0, i1 );
312 template<
typename BASETYPE >
313 struct MapHelperImpl< ToElementRelation< BASETYPE > >
315 using BaseHelper = MapHelperImpl< BASETYPE >;
317 static localIndex size0( ToElementRelation< BASETYPE >
const & map )
319 return BaseHelper::size0( map.m_toElementIndex );
324 return BaseHelper::size1( map.m_toElementIndex, i0 );
327 static auto value( ToElementRelation< BASETYPE >
const & map,
localIndex const i0,
localIndex const i1 )
329 return MeshHelper< DofManager::Location::Elem >::LocalIndexType{ BaseHelper::value( map.m_toElementRegion, i0, i1 ),
330 BaseHelper::value( map.m_toElementSubRegion, i0, i1 ),
331 BaseHelper::value( map.m_toElementIndex, i0, i1 ) };
341 template<
typename MAP >
342 using MapHelper = MapHelperImpl< BaseType< MAP > >;
350 template<
typename LAMBDA >
358 lambda( std::integral_constant< DofManager::Location, DofManager::Location::Node >() );
363 lambda( std::integral_constant< DofManager::Location, DofManager::Location::Edge >() );
368 lambda( std::integral_constant< DofManager::Location, DofManager::Location::Face >() );
373 lambda( std::integral_constant< DofManager::Location, DofManager::Location::Elem >() );
381 template<
typename LAMBDA >
388 LocationSwitch( loc1, [&](
auto const loc_type1 )
391 LocationSwitch( loc2, [&](
auto const loc_type2 )
393 lambda( loc_type1, loc_type2 );
399 template< DofManager::Location LOC >
400 typename MeshHelper< LOC >::ManagerType
const & getObjectManager( MeshLevel
const *
const mesh )
402 using ObjectManager =
typename MeshHelper< LOC >::ManagerType;
404 ObjectManager
const * manager = mesh->GetGroup< ObjectManager >( MeshHelper< LOC >::managerGroupName );
409 template< DofManager::Location LOC >
410 typename MeshHelper< LOC >::ManagerType & getObjectManager( MeshLevel *
const mesh )
412 using ObjectManager =
typename MeshHelper< LOC >::ManagerType;
413 return const_cast< ObjectManager &
>( getObjectManager< LOC >(
const_cast< MeshLevel
const *
>( mesh ) ) );
416 ObjectManagerBase
const & getObjectManager(
DofManager::Location const loc, MeshLevel
const *
const mesh )
418 ObjectManagerBase
const * manager =
nullptr;
419 LocationSwitch( loc, [&](
auto const LOC )
421 manager = &getObjectManager< decltype(LOC)::value >( mesh );
429 return const_cast< ObjectManagerBase &
>( getObjectManager( loc, const_cast< MeshLevel const * >( mesh ) ) );
439 template< DofManager::Location LOC, DofManager::Location CONN_LOC,
bool VISIT_GHOSTS >
440 struct MeshLoopHelper;
450 template< DofManager::Location LOC,
bool VISIT_GHOSTS >
451 struct MeshLoopHelper< LOC, LOC, VISIT_GHOSTS >
453 template<
typename ... SUBREGIONTYPES,
typename LAMBDA >
454 static void visit( MeshLevel *
const meshLevel,
455 std::vector< std::string >
const & regions,
459 using ObjectManagerLoc =
typename MeshHelper< LOC >::ManagerType;
462 ObjectManagerLoc
const & objectManager = getObjectManager< LOC >( meshLevel );
463 arrayView1d< integer const >
const & ghostRank = objectManager.ghostRank();
466 array1d< bool > locationsVisited( objectManager.size() );
467 locationsVisited.setValues< serialPolicy >( false );
470 array1d< localIndex > locationsToVisit{};
471 locationsToVisit.reserve( objectManager.size() );
473 meshLevel->getElemManager()->
474 forElementSubRegions< SUBREGIONTYPES... >( regions, [&](
localIndex const,
auto const & subRegion )
477 using ElementSubRegionType = std::remove_reference_t< decltype( subRegion ) >;
478 using ElemToLocMapType = MapType< LOC, ElementSubRegionType >;
481 auto const & elemToLocMap =
482 subRegion.template getReference< ElemToLocMapType >( MeshHelper< LOC >::mapViewKey );
485 for( localIndex ei = 0; ei < subRegion.size(); ++ei )
488 for( localIndex a = 0; a < MapHelper< ElemToLocMapType >::size1( elemToLocMap, ei ); ++a )
490 localIndex
const locIdx = MapHelper< ElemToLocMapType >::value( elemToLocMap, ei, a );
493 if( ( VISIT_GHOSTS || ghostRank[locIdx] < 0) && !std::exchange( locationsVisited[locIdx],
true ) )
495 locationsToVisit.emplace_back( locIdx );
502 if( locationsToVisit.size() == objectManager.size() )
504 for( localIndex locIdx = 0; locIdx < objectManager.size(); ++locIdx )
506 lambda( locIdx, locIdx, 0 );
512 std::sort( locationsToVisit.begin(), locationsToVisit.end() );
513 for( localIndex
const locIdx : locationsToVisit )
515 lambda( locIdx, locIdx, 0 );
527 template< DofManager::Location LOC, DofManager::Location CONN_LOC,
bool VISIT_GHOSTS >
528 struct MeshLoopHelper
530 template<
typename ... SUBREGIONTYPES,
typename LAMBDA >
531 static void visit( MeshLevel *
const meshLevel,
532 std::vector< std::string >
const & regions,
536 using ObjectManagerLoc =
typename MeshHelper< LOC >::ManagerType;
537 using LocToConnMapType = MapType< CONN_LOC, ObjectManagerLoc >;
539 ObjectManagerLoc
const & objectManager = getObjectManager< LOC >( meshLevel );
542 auto const & locToConnMap =
543 objectManager.template getReference< LocToConnMapType >( MeshHelper< CONN_LOC >::mapViewKey );
546 MeshLoopHelper< LOC, LOC, VISIT_GHOSTS >::template visit< SUBREGIONTYPES... >( meshLevel, regions,
547 [&]( localIndex
const locIdx,
552 for( localIndex b = 0; b < MapHelper< LocToConnMapType >::size1( locToConnMap, locIdx ); ++b )
554 auto const connIdx = MapHelper< LocToConnMapType >::value( locToConnMap, locIdx, b );
555 lambda( locIdx, connIdx, b );
569 template< DofManager::Location LOC,
bool VISIT_GHOSTS >
570 struct MeshLoopHelper< LOC, DofManager::Location::Elem, VISIT_GHOSTS >
572 template<
typename ... SUBREGIONTYPES,
typename LAMBDA >
573 static void visit( MeshLevel *
const meshLevel,
574 std::vector< std::string >
const & regions,
578 using ObjectManagerLoc =
typename MeshHelper< LOC >::ManagerType;
579 using ToElemMapType = BaseType< MapType< DofManager::Location::Elem, ObjectManagerLoc > >;
582 ObjectManagerLoc
const & objectManager = getObjectManager< LOC >( meshLevel );
585 auto const & elemRegionList =
586 objectManager.template getReference< ToElemMapType >( ObjectManagerLoc::viewKeyStruct::elementRegionListString );
587 auto const & elemSubRegionList =
588 objectManager.template getReference< ToElemMapType >( ObjectManagerLoc::viewKeyStruct::elementSubRegionListString );
589 auto const & elemIndexList =
590 objectManager.template getReference< ToElemMapType >( ObjectManagerLoc::viewKeyStruct::elementListString );
593 MeshLoopHelper< LOC, LOC, VISIT_GHOSTS >::template visit< SUBREGIONTYPES... >( meshLevel, regions,
594 [&]( localIndex
const locIdx,
599 for( localIndex b = 0; b < MapHelper< ToElemMapType >::size1( elemIndexList, locIdx ); ++b )
601 localIndex
const er = MapHelper< ToElemMapType >::value( elemRegionList, locIdx, b );
602 localIndex
const esr = MapHelper< ToElemMapType >::value( elemSubRegionList, locIdx, b );
603 localIndex
const ei = MapHelper< ToElemMapType >::value( elemIndexList, locIdx, b );
605 if( er >= 0 && esr >= 0 && ei >= 0 )
607 lambda( locIdx, MeshHelper< DofManager::Location::Elem >::LocalIndexType{ er, esr, ei }, b );
622 template< DofManager::Location CONN_LOC,
bool VISIT_GHOSTS >
623 struct MeshLoopHelper< DofManager::Location::Elem, CONN_LOC, VISIT_GHOSTS >
625 template<
typename ... SUBREGIONTYPES,
typename LAMBDA >
626 static void visit( MeshLevel *
const meshLevel,
627 std::vector< std::string >
const & regions,
630 meshLevel->getElemManager()->
631 forElementSubRegionsComplete< SUBREGIONTYPES... >( regions, [&]( localIndex
const,
633 localIndex
const esr,
634 ElementRegionBase
const &,
635 auto const & subRegion )
638 using ElemToConnMapType = MapType< CONN_LOC, TYPEOFREF( subRegion ) >;
641 auto const & elemToConnMap =
642 subRegion.template getReference< ElemToConnMapType >( MeshHelper< CONN_LOC >::mapViewKey );
644 arrayView1d< integer const >
const & elemGhostRank = subRegion.ghostRank();
646 for( localIndex ei = 0; ei < subRegion.size(); ++ei )
648 if( VISIT_GHOSTS || elemGhostRank[ei] < 0 )
650 auto const elemIdx = MeshHelper< DofManager::Location::Elem >::LocalIndexType{ er, esr, ei };
652 for( localIndex a = 0; a < MapHelper< ElemToConnMapType >::size1( elemToConnMap, ei ); ++a )
654 localIndex
const locIdx = MapHelper< ElemToConnMapType >::value( elemToConnMap, ei, a );
655 lambda( elemIdx, locIdx, a );
667 template<
bool VISIT_GHOSTS >
670 template<
typename ... SUBREGIONTYPES,
typename LAMBDA >
671 static void visit( MeshLevel *
const meshLevel,
672 std::vector< std::string >
const & regions,
675 meshLevel->getElemManager()->
676 forElementSubRegionsComplete< SUBREGIONTYPES... >( regions, [&]( localIndex
const,
678 localIndex
const esr,
679 ElementRegionBase
const &,
680 ElementSubRegionBase
const & subRegion )
682 arrayView1d< integer const >
const & elemGhostRank = subRegion.ghostRank();
683 localIndex
const numElems = subRegion.size();
685 for( localIndex ei = 0; ei < numElems; ++ei )
687 if( VISIT_GHOSTS || elemGhostRank[ei] < 0 )
689 auto const elemIdx = MeshHelper< DofManager::Location::Elem >::LocalIndexType{ er, esr, ei };
690 lambda( elemIdx, elemIdx, 0 );
720 typename ... SUBREGIONTYPES,
typename LAMBDA >
721 void forMeshLocation( MeshLevel *
const mesh,
722 std::vector< std::string >
const & regions,
725 MeshLoopHelper< LOC, CONN_LOC, VISIT_GHOSTS >::template visit< SUBREGIONTYPES... >( mesh,
727 std::forward< LAMBDA >( lambda ) );
734 typename ... SUBREGIONTYPES,
typename LAMBDA >
735 void forMeshLocation( MeshLevel *
const mesh,
736 std::vector< std::string >
const & regions,
739 forMeshLocation< LOC, LOC, VISIT_GHOSTS, SUBREGIONTYPES... >( mesh,
741 [&](
auto const locIdx,
759 localIndex countMeshObjects( MeshLevel *
const mesh,
760 std::vector< std::string >
const & regions )
762 localIndex count = 0;
763 forMeshLocation< LOC, VISIT_GHOSTS, SUBREGIONTYPES... >( mesh, regions,
776 template<
typename INDEX, DofManager::Location LOC >
777 struct IndexArrayHelper
780 using ArrayType = array1d< std::remove_const_t< INDEX > >;
781 using ViewType = arrayView1d< INDEX >;
783 using Mesh = add_const_if_t< MeshLevel, std::is_const< INDEX >::value >;
785 template<
typename ... SUBREGIONTYPES >
787 create( Mesh *
const mesh,
789 string const & description,
792 ObjectManagerBase & baseManager = getObjectManager< LOC >( mesh );
793 baseManager.registerWrapper< ArrayType >( key )->
794 setApplyDefaultValue( -1 )->
797 setDescription( description );
800 static Accessor
get( Mesh *
const mesh,
string const & key )
802 return getObjectManager< LOC >( mesh ).
template getReference< ArrayType >( key );
805 static inline INDEX value( Accessor & indexArray,
typename MeshHelper< LOC >::LocalIndexType
const i )
807 return indexArray[i];
810 static inline INDEX & reference( Accessor & indexArray,
typename MeshHelper< LOC >::LocalIndexType
const i )
812 return indexArray[i];
815 template<
typename ... SUBREGIONTYPES >
817 remove( Mesh *
const mesh,
821 getObjectManager< LOC >( mesh ).deregisterWrapper( key );
828 template<
typename INDEX >
829 struct IndexArrayHelper< INDEX, DofManager::Location::Elem >
831 using IndexType = INDEX;
832 using ArrayType = array1d< std::remove_const_t< INDEX > >;
833 using ViewType = arrayView1d< INDEX >;
834 using Accessor = ElementRegionManager::ElementViewAccessor< ViewType >
const;
835 using Mesh = add_const_if_t< MeshLevel, std::is_const< INDEX >::value >;
837 template<
typename ... SUBREGIONTYPES >
839 create( Mesh *
const mesh,
841 string const & description,
842 std::vector< std::string >
const & regions )
844 mesh->getElemManager()->template forElementSubRegions< SUBREGIONTYPES... >( regions,
845 [&]( localIndex
const,
848 subRegion.template registerWrapper< ArrayType >( key )->
849 setApplyDefaultValue( -1 )->
852 setDescription( description );
856 static Accessor
get( Mesh *
const mesh,
string const & key )
858 return mesh->getElemManager()->template ConstructViewAccessor< ArrayType, ViewType >( key );
861 static inline INDEX value( Accessor & indexArray,
862 MeshHelper< DofManager::Location::Elem >::LocalIndexType
const & e )
864 if( indexArray[std::get< 0 >( e )].empty() || indexArray[std::get< 0 >( e )][std::get< 1 >( e )].empty() )
868 return indexArray[std::get< 0 >( e )][std::get< 1 >( e )][std::get< 2 >( e )];
871 static inline INDEX & reference( Accessor & indexArray,
872 MeshHelper< DofManager::Location::Elem >::LocalIndexType
const & e )
874 return indexArray[std::get< 0 >( e )][std::get< 1 >( e )][std::get< 2 >( e )];
877 template<
typename ... SUBREGIONTYPES >
879 remove( Mesh *
const mesh,
881 std::vector< std::string >
const & regions )
883 mesh->getElemManager()->template forElementSubRegions< SUBREGIONTYPES... >( regions,
884 [&]( localIndex
const,
885 ElementSubRegionBase & subRegion )
887 subRegion.deregisterWrapper( key );
896 #endif //GEOSX_LINEARALGEBRA_DOFMANAGERHELPERS_HPP static constexpr auto nodeListString
String key for the element-to-node relation.
Array< T, 2, PERMUTATION > array2d
Alias for 2D array.
Doe no write into restart.
#define SET_MAX_MESH_INCIDENCE(LOC, LOC_ADJ, MAX)
Shortcut macro for declaring adjacency.
LvArray::ArrayOfSets< T, localIndex, LvArray::ChaiBuffer > ArrayOfSets
Array of variable-sized sets. See LvArray::ArrayOfSets for details.
location is face (like flux in mixed finite elements)
static constexpr auto faceListString
String key for the element-to-face relation.
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
location is element (like pressure in finite volumes)
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
static constexpr auto edgeListString
String key for the element-to-edge relation.
location is edge (like flux between fracture elements)
LvArray::SortedArray< T, localIndex, LvArray::ChaiBuffer > SortedArray
A sorted array of local indices.
Array< T, 1 > array1d
Alias for 1D array.
Write to plot when plotLevel>=1 is specified in input.
Location
Enumeration of geometric objects for support location. Note that this enum is nearly identical to Con...
#define HAS_MEMBER_TYPE(NAME)
Macro that expands to a static constexpr bool templated on a type that is only true when the type has...
LvArray::ArrayOfArrays< T, localIndex, LvArray::ChaiBuffer > ArrayOfArrays
Array of variable-sized arrays. See LvArray::ArrayOfArrays for details.
constexpr camp::idx_t getStrideOneDimension(camp::idx_seq< INDICES... >)
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
#define GEOSX_ASSERT(EXP)
Assert a condition in debug builds.
typename internal::GetViewType< T >::type ViewType
An alias for the view type of T.
location is node (like displacements in finite elements)
constexpr std::enable_if_t< std::is_arithmetic< T >::value, T > max(T const a, T const b)
mapBase< TKEY, TVAL, std::integral_constant< bool, true > > map
Ordered map type.
#define GEOSX_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.