GEOSX
DofManagerHelpers.hpp
Go to the documentation of this file.
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 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOSX_LINEARALGEBRA_DOFMANAGERHELPERS_HPP
20 #define GEOSX_LINEARALGEBRA_DOFMANAGERHELPERS_HPP
21 
22 namespace geosx
23 {
24 
25 // unnamed namespace to avoid needless external linkage
26 namespace
27 {
28 
33 template< DofManager::Location LOC >
34 struct MeshHelper
35 {};
36 
37 template<>
38 struct MeshHelper< DofManager::Location::Node >
39 {
40  using ManagerType = NodeManager;
41  using LocalIndexType = localIndex;
42 
43  static LocalIndexType constexpr invalid_local_index{ -1 };
44 
45  static constexpr auto managerGroupName = MeshLevel::groupStructKeys::nodeManagerString;
46  static constexpr auto mapViewKey = ElementSubRegionBase::viewKeyStruct::nodeListString;
47  static constexpr auto syncObjName = "node";
48 
49  template< typename MANAGER >
50  using MapType = typename MANAGER::NodeMapType;
51 };
52 
53 template<>
54 struct MeshHelper< DofManager::Location::Edge >
55 {
56  using ManagerType = EdgeManager;
57  using LocalIndexType = localIndex;
58 
59  static LocalIndexType constexpr invalid_local_index{ -1 };
60 
61  static constexpr auto managerGroupName = MeshLevel::groupStructKeys::edgeManagerString;
62  static constexpr auto mapViewKey = ElementSubRegionBase::viewKeyStruct::edgeListString;
63  static constexpr auto syncObjName = "edge";
64 
65  template< typename MANAGER >
66  using MapType = typename MANAGER::EdgeMapType;
67 };
68 
69 template<>
70 struct MeshHelper< DofManager::Location::Face >
71 {
72  using ManagerType = FaceManager;
73  using LocalIndexType = localIndex;
74 
75  static LocalIndexType constexpr invalid_local_index{ -1 };
76 
77  static constexpr auto managerGroupName = MeshLevel::groupStructKeys::faceManagerString;
78  static constexpr auto mapViewKey = ElementSubRegionBase::viewKeyStruct::faceListString;
79  static constexpr auto syncObjName = "face";
80 
81  template< typename MANAGER >
82  using MapType = typename MANAGER::FaceMapType;
83 };
84 
85 template<>
86 struct MeshHelper< DofManager::Location::Elem >
87 {
88  using ManagerType = ElementSubRegionBase;
89  using LocalIndexType = std::array< localIndex, 3 >;
90 
91  static LocalIndexType constexpr invalid_local_index{ -1, -1, -1 };
92 
93  static constexpr auto managerGroupName = MeshLevel::groupStructKeys::elemManagerString;
94  static constexpr auto syncObjName = "elems";
95 
96  template< typename MANAGER >
97  using MapType = typename MANAGER::ElemMapType;
98 };
99 
100 
112 template< DofManager::Location LOC, DofManager::Location LOC_ADJ >
113 struct MeshIncidence {};
114 
116 template< DofManager::Location LOC >
117 struct MeshIncidence< LOC, LOC >
118 {
119  static localIndex constexpr max = 1;
120 };
121 
123 #define SET_MAX_MESH_INCIDENCE( LOC, LOC_ADJ, MAX ) \
124  template<> \
125  struct MeshIncidence< DofManager::Location::LOC, DofManager::Location::LOC_ADJ > \
126  { \
127  static localIndex constexpr max = MAX; \
128  }
129 
130 SET_MAX_MESH_INCIDENCE( Node, Edge, 10 );
131 SET_MAX_MESH_INCIDENCE( Node, Face, 10 );
132 SET_MAX_MESH_INCIDENCE( Node, Elem, 12 );
133 
134 SET_MAX_MESH_INCIDENCE( Edge, Node, 2 );
135 SET_MAX_MESH_INCIDENCE( Edge, Face, 8 );
136 SET_MAX_MESH_INCIDENCE( Edge, Elem, 8 );
137 
138 SET_MAX_MESH_INCIDENCE( Face, Node, 8 );
139 SET_MAX_MESH_INCIDENCE( Face, Edge, 4 );
140 SET_MAX_MESH_INCIDENCE( Face, Elem, 2 );
141 
142 SET_MAX_MESH_INCIDENCE( Elem, Node, 8 );
143 SET_MAX_MESH_INCIDENCE( Elem, Edge, 12 );
144 SET_MAX_MESH_INCIDENCE( Elem, Face, 6 );
145 
146 #undef SET_MAX_MESH_INCIDENCE
147 
148 template< DofManager::Location LOC, typename MANAGER >
149 struct MapTypeHelper
150 {
151  using type = typename MeshHelper< LOC >::template MapType< MANAGER >;
152 };
153 
154 // return dummy type if target manager type does not declare a type alias to map to LOC objects
155 // this allows all switchyards to compile, but one shouldn't attempt to access a non-existent map
156 template< DofManager::Location LOC, typename MANAGER >
157 using MapType = typename MapTypeHelper< LOC, MANAGER >::type;
158 
159 // some helper crust to extract underlying type from InterObjectRelation and the likes
160 template< typename T, bool >
161 struct BaseTypeHelper
162 {
163  using type = T;
164 };
165 
166 template< typename T >
167 struct BaseTypeHelper< T, true >
168 {
169  using type = typename T::base_type;
170 };
171 
172 HAS_MEMBER_TYPE( base_type );
173 
174 template< typename MAP >
175 using BaseType = typename BaseTypeHelper< MAP, HasMemberType_base_type< MAP > >::type;
176 
181 template< typename MAP >
182 struct MapHelperImpl
183 {};
184 
185 template< typename T, typename PERMUTATION >
186 struct MapHelperImpl< array2d< T, PERMUTATION > >
187 {
188  static localIndex size0( array2d< T, PERMUTATION > const & map )
189  {
190  return map.size( 0 );
191  }
192 
193  static localIndex size1( array2d< T, PERMUTATION > const & map, localIndex const GEOSX_UNUSED_PARAM( i0 ) )
194  {
195  return map.size( 1 );
196  }
197 
198  static T const & value( array2d< T, PERMUTATION > const & map, localIndex const i0, localIndex const i1 )
199  {
200  return map( i0, i1 );
201  }
202 
203  static localIndex size0( arrayView2d<T const, LvArray::typeManipulation::getStrideOneDimension( PERMUTATION {} ) > const & map )
204  {
205  return map.size( 0 );
206  }
207 
208  static localIndex size1( arrayView2d<T const, LvArray::typeManipulation::getStrideOneDimension( PERMUTATION {} ) > const & map, localIndex const GEOSX_UNUSED_PARAM( i0 ) )
209  {
210  return map.size( 1 );
211  }
212 
213  static T const & value( arrayView2d<T const, LvArray::typeManipulation::getStrideOneDimension( PERMUTATION {} ) > const & map, localIndex const i0, localIndex const i1 )
214  {
215  return map( i0, i1 );
216  }
217 
218 };
219 
220 template< typename T >
221 struct MapHelperImpl< array1d< array1d< T > > >
222 {
223  static localIndex size0( array1d< array1d< T > > const & map )
224  {
225  return map.size();
226  }
227 
228  static localIndex size1( array1d< array1d< T > > const & map, localIndex const i0 )
229  {
230  return map[i0].size();
231  }
232 
233  static T const & value( array1d< array1d< T > > const & map, localIndex const i0, localIndex const i1 )
234  {
235  return map[i0][i1];
236  }
237 
238  static localIndex size0( arrayView1d< arrayView1d< T const > const > const & map )
239  {
240  return map.size();
241  }
242 
243  static localIndex size1( arrayView1d< arrayView1d< T const > const > const & map, localIndex const i0 )
244  {
245  return map[i0].size();
246  }
247 
248  static T const & value( arrayView1d< arrayView1d< T const > const > const & map, localIndex const i0, localIndex const i1 )
249  {
250  return map[i0][i1];
251  }
252 
253 };
254 
255 template< typename T >
256 struct MapHelperImpl< ArrayOfArrays< T > >
257 {
258  static localIndex size0( ArrayOfArraysView< T const > const & map )
259  {
260  return map.size();
261  }
262 
263  static localIndex size1( ArrayOfArraysView< T const > const & map, localIndex const i0 )
264  {
265  return map.sizeOfArray( i0 );
266  }
267 
268  static T const & value( ArrayOfArraysView< T const > const & map, localIndex const i0, localIndex const i1 )
269  {
270  return map( i0, i1 );
271  }
272 };
273 
274 template< typename T >
275 struct MapHelperImpl< array1d< SortedArray< T > > >
276 {
277  static localIndex size0( array1d< SortedArray< T > > const & map )
278  {
279  return map.size();
280  }
281 
282  static localIndex size1( array1d< SortedArray< T > > const & map, localIndex const i0 )
283  {
284  return map[i0].size();
285  }
286 
287  static T const & value( array1d< SortedArray< T > > const & map, localIndex const i0, localIndex const i1 )
288  {
289  return map[i0][i1];
290  }
291 };
292 
293 template< typename T >
294 struct MapHelperImpl< ArrayOfSets< T > >
295 {
296  static localIndex size0( ArrayOfSetsView< T const > const & map )
297  {
298  return map.size();
299  }
300 
301  static localIndex size1( ArrayOfSetsView< T const > const & map, localIndex const i0 )
302  {
303  return map.sizeOfSet( i0 );
304  }
305 
306  static T const & value( ArrayOfSetsView< T const > const & map, localIndex const i0, localIndex const i1 )
307  {
308  return map( i0, i1 );
309  }
310 };
311 
312 template< typename BASETYPE >
313 struct MapHelperImpl< ToElementRelation< BASETYPE > >
314 {
315  using BaseHelper = MapHelperImpl< BASETYPE >;
316 
317  static localIndex size0( ToElementRelation< BASETYPE > const & map )
318  {
319  return BaseHelper::size0( map.m_toElementIndex );
320  }
321 
322  static localIndex size1( ToElementRelation< BASETYPE > const & map, localIndex const i0 )
323  {
324  return BaseHelper::size1( map.m_toElementIndex, i0 );
325  }
326 
327  static auto value( ToElementRelation< BASETYPE > const & map, localIndex const i0, localIndex const i1 )
328  {
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 ) };
332  }
333 };
334 
341 template< typename MAP >
342 using MapHelper = MapHelperImpl< BaseType< MAP > >;
343 
350 template< typename LAMBDA >
351 bool LocationSwitch( DofManager::Location const loc,
352  LAMBDA lambda )
353 {
354  switch( loc )
355  {
357  {
358  lambda( std::integral_constant< DofManager::Location, DofManager::Location::Node >() );
359  return true;
360  }
362  {
363  lambda( std::integral_constant< DofManager::Location, DofManager::Location::Edge >() );
364  return true;
365  }
367  {
368  lambda( std::integral_constant< DofManager::Location, DofManager::Location::Face >() );
369  return true;
370  }
372  {
373  lambda( std::integral_constant< DofManager::Location, DofManager::Location::Elem >() );
374  return true;
375  }
376  default:
377  return false;
378  }
379 }
380 
381 template< typename LAMBDA >
382 bool LocationSwitch( DofManager::Location const loc1,
383  DofManager::Location const loc2,
384  LAMBDA lambda )
385 {
386  bool ret2;
387  bool const ret1 =
388  LocationSwitch( loc1, [&]( auto const loc_type1 )
389  {
390  ret2 =
391  LocationSwitch( loc2, [&]( auto const loc_type2 )
392  {
393  lambda( loc_type1, loc_type2 );
394  } );
395  } );
396  return ret1 && ret2;
397 }
398 
399 template< DofManager::Location LOC >
400 typename MeshHelper< LOC >::ManagerType const & getObjectManager( MeshLevel const * const mesh )
401 {
402  using ObjectManager = typename MeshHelper< LOC >::ManagerType;
403  GEOSX_ASSERT( mesh != nullptr );
404  ObjectManager const * manager = mesh->GetGroup< ObjectManager >( MeshHelper< LOC >::managerGroupName );
405  GEOSX_ASSERT( manager != nullptr );
406  return *manager;
407 }
408 
409 template< DofManager::Location LOC >
410 typename MeshHelper< LOC >::ManagerType & getObjectManager( MeshLevel * const mesh )
411 {
412  using ObjectManager = typename MeshHelper< LOC >::ManagerType;
413  return const_cast< ObjectManager & >( getObjectManager< LOC >( const_cast< MeshLevel const * >( mesh ) ) );
414 }
415 
416 ObjectManagerBase const & getObjectManager( DofManager::Location const loc, MeshLevel const * const mesh )
417 {
418  ObjectManagerBase const * manager = nullptr;
419  LocationSwitch( loc, [&]( auto const LOC )
420  {
421  manager = &getObjectManager< decltype(LOC)::value >( mesh );
422  } );
423  GEOSX_ASSERT( manager != nullptr );
424  return *manager;
425 }
426 
427 ObjectManagerBase & getObjectManager( DofManager::Location const loc, MeshLevel * const mesh )
428 {
429  return const_cast< ObjectManagerBase & >( getObjectManager( loc, const_cast< MeshLevel const * >( mesh ) ) );
430 }
431 
439 template< DofManager::Location LOC, DofManager::Location CONN_LOC, bool VISIT_GHOSTS >
440 struct MeshLoopHelper;
441 
450 template< DofManager::Location LOC, bool VISIT_GHOSTS >
451 struct MeshLoopHelper< LOC, LOC, VISIT_GHOSTS >
452 {
453  template< typename ... SUBREGIONTYPES, typename LAMBDA >
454  static void visit( MeshLevel * const meshLevel,
455  std::vector< std::string > const & regions,
456  LAMBDA lambda )
457  {
458  // derive some useful type aliases
459  using ObjectManagerLoc = typename MeshHelper< LOC >::ManagerType;
460 
461  // get access to location ghost rank (we don't want to visit ghosted locations
462  ObjectManagerLoc const & objectManager = getObjectManager< LOC >( meshLevel );
463  arrayView1d< integer const > const & ghostRank = objectManager.ghostRank();
464 
465  // create an array to track previously visited locations (to avoid multiple visits)
466  array1d< bool > locationsVisited( objectManager.size() );
467  locationsVisited.setValues< serialPolicy >( false );
468 
469  // create (and overallocate) an array to collect indicies to visit
470  array1d< localIndex > locationsToVisit{};
471  locationsToVisit.reserve( objectManager.size() );
472 
473  meshLevel->getElemManager()->
474  forElementSubRegions< SUBREGIONTYPES... >( regions, [&]( localIndex const, auto const & subRegion )
475  {
476  // derive some more useful, subregion-dependent type aliases
477  using ElementSubRegionType = std::remove_reference_t< decltype( subRegion ) >;
478  using ElemToLocMapType = MapType< LOC, ElementSubRegionType >;
479 
480  // get access to element-to-location map
481  auto const & elemToLocMap =
482  subRegion.template getReference< ElemToLocMapType >( MeshHelper< LOC >::mapViewKey );
483 
484  // loop over all elements (including ghosts, which may be necessary to access some locally owned locations)
485  for( localIndex ei = 0; ei < subRegion.size(); ++ei )
486  {
487  // loop over all locations incident on an element
488  for( localIndex a = 0; a < MapHelper< ElemToLocMapType >::size1( elemToLocMap, ei ); ++a )
489  {
490  localIndex const locIdx = MapHelper< ElemToLocMapType >::value( elemToLocMap, ei, a );
491 
492  // check if we should visit this location
493  if( ( VISIT_GHOSTS || ghostRank[locIdx] < 0) && !std::exchange( locationsVisited[locIdx], true ) )
494  {
495  locationsToVisit.emplace_back( locIdx );
496  }
497  }
498  }
499  } );
500 
501  // optimize for the common case (e.g. all nodes of the mesh)
502  if( locationsToVisit.size() == objectManager.size() )
503  {
504  for( localIndex locIdx = 0; locIdx < objectManager.size(); ++locIdx )
505  {
506  lambda( locIdx, locIdx, 0 );
507  }
508  }
509  else
510  {
511  // I think this is faster than alternatives, but need to profile
512  std::sort( locationsToVisit.begin(), locationsToVisit.end() );
513  for( localIndex const locIdx : locationsToVisit )
514  {
515  lambda( locIdx, locIdx, 0 );
516  }
517  }
518  }
519 };
520 
527 template< DofManager::Location LOC, DofManager::Location CONN_LOC, bool VISIT_GHOSTS >
528 struct MeshLoopHelper
529 {
530  template< typename ... SUBREGIONTYPES, typename LAMBDA >
531  static void visit( MeshLevel * const meshLevel,
532  std::vector< std::string > const & regions,
533  LAMBDA lambda )
534  {
535  // derive some useful type aliases
536  using ObjectManagerLoc = typename MeshHelper< LOC >::ManagerType;
537  using LocToConnMapType = MapType< CONN_LOC, ObjectManagerLoc >;
538 
539  ObjectManagerLoc const & objectManager = getObjectManager< LOC >( meshLevel );
540 
541  // get access to location-to-connected map
542  auto const & locToConnMap =
543  objectManager.template getReference< LocToConnMapType >( MeshHelper< CONN_LOC >::mapViewKey );
544 
545  // call the specialized version first, then add an extra loop over connected objects
546  MeshLoopHelper< LOC, LOC, VISIT_GHOSTS >::template visit< SUBREGIONTYPES... >( meshLevel, regions,
547  [&]( localIndex const locIdx,
548  localIndex const,
549  localIndex const )
550  {
551  // loop over all connected locations
552  for( localIndex b = 0; b < MapHelper< LocToConnMapType >::size1( locToConnMap, locIdx ); ++b )
553  {
554  auto const connIdx = MapHelper< LocToConnMapType >::value( locToConnMap, locIdx, b );
555  lambda( locIdx, connIdx, b );
556  }
557  } );
558  }
559 };
560 
569 template< DofManager::Location LOC, bool VISIT_GHOSTS >
570 struct MeshLoopHelper< LOC, DofManager::Location::Elem, VISIT_GHOSTS >
571 {
572  template< typename ... SUBREGIONTYPES, typename LAMBDA >
573  static void visit( MeshLevel * const meshLevel,
574  std::vector< std::string > const & regions,
575  LAMBDA lambda )
576  {
577  // derive some useful type aliases
578  using ObjectManagerLoc = typename MeshHelper< LOC >::ManagerType;
579  using ToElemMapType = BaseType< MapType< DofManager::Location::Elem, ObjectManagerLoc > >;
580 
581  // get mesh object manager for LOC to access maps
582  ObjectManagerLoc const & objectManager = getObjectManager< LOC >( meshLevel );
583 
584  // access to location-to-element map
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 );
591 
592  // call the specialized version first, then add an extra loop over connected elements
593  MeshLoopHelper< LOC, LOC, VISIT_GHOSTS >::template visit< SUBREGIONTYPES... >( meshLevel, regions,
594  [&]( localIndex const locIdx,
595  localIndex const,
596  localIndex const )
597  {
598  // loop over all connected locations
599  for( localIndex b = 0; b < MapHelper< ToElemMapType >::size1( elemIndexList, locIdx ); ++b )
600  {
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 );
604 
605  if( er >= 0 && esr >= 0 && ei >= 0 )
606  {
607  lambda( locIdx, MeshHelper< DofManager::Location::Elem >::LocalIndexType{ er, esr, ei }, b );
608  }
609  }
610  } );
611  }
612 };
613 
622 template< DofManager::Location CONN_LOC, bool VISIT_GHOSTS >
623 struct MeshLoopHelper< DofManager::Location::Elem, CONN_LOC, VISIT_GHOSTS >
624 {
625  template< typename ... SUBREGIONTYPES, typename LAMBDA >
626  static void visit( MeshLevel * const meshLevel,
627  std::vector< std::string > const & regions,
628  LAMBDA lambda )
629  {
630  meshLevel->getElemManager()->
631  forElementSubRegionsComplete< SUBREGIONTYPES... >( regions, [&]( localIndex const,
632  localIndex const er,
633  localIndex const esr,
634  ElementRegionBase const &,
635  auto const & subRegion )
636  {
637  // derive subregion-dependent map type
638  using ElemToConnMapType = MapType< CONN_LOC, TYPEOFREF( subRegion ) >;
639 
640  // get access to element-to-location map
641  auto const & elemToConnMap =
642  subRegion.template getReference< ElemToConnMapType >( MeshHelper< CONN_LOC >::mapViewKey );
643 
644  arrayView1d< integer const > const & elemGhostRank = subRegion.ghostRank();
645 
646  for( localIndex ei = 0; ei < subRegion.size(); ++ei )
647  {
648  if( VISIT_GHOSTS || elemGhostRank[ei] < 0 )
649  {
650  auto const elemIdx = MeshHelper< DofManager::Location::Elem >::LocalIndexType{ er, esr, ei };
651 
652  for( localIndex a = 0; a < MapHelper< ElemToConnMapType >::size1( elemToConnMap, ei ); ++a )
653  {
654  localIndex const locIdx = MapHelper< ElemToConnMapType >::value( elemToConnMap, ei, a );
655  lambda( elemIdx, locIdx, a );
656  }
657  }
658  }
659  } );
660  }
661 };
662 
667 template< bool VISIT_GHOSTS >
668 struct MeshLoopHelper< DofManager::Location::Elem, DofManager::Location::Elem, VISIT_GHOSTS >
669 {
670  template< typename ... SUBREGIONTYPES, typename LAMBDA >
671  static void visit( MeshLevel * const meshLevel,
672  std::vector< std::string > const & regions,
673  LAMBDA && lambda )
674  {
675  meshLevel->getElemManager()->
676  forElementSubRegionsComplete< SUBREGIONTYPES... >( regions, [&]( localIndex const,
677  localIndex const er,
678  localIndex const esr,
679  ElementRegionBase const &,
680  ElementSubRegionBase const & subRegion )
681  {
682  arrayView1d< integer const > const & elemGhostRank = subRegion.ghostRank();
683  localIndex const numElems = subRegion.size();
684 
685  for( localIndex ei = 0; ei < numElems; ++ei )
686  {
687  if( VISIT_GHOSTS || elemGhostRank[ei] < 0 )
688  {
689  auto const elemIdx = MeshHelper< DofManager::Location::Elem >::LocalIndexType{ er, esr, ei };
690  lambda( elemIdx, elemIdx, 0 );
691  }
692  }
693  } );
694  }
695 };
696 
719 template< DofManager::Location LOC, DofManager::Location CONN_LOC, bool VISIT_GHOSTS,
720  typename ... SUBREGIONTYPES, typename LAMBDA >
721 void forMeshLocation( MeshLevel * const mesh,
722  std::vector< std::string > const & regions,
723  LAMBDA && lambda )
724 {
725  MeshLoopHelper< LOC, CONN_LOC, VISIT_GHOSTS >::template visit< SUBREGIONTYPES... >( mesh,
726  regions,
727  std::forward< LAMBDA >( lambda ) );
728 }
729 
733 template< DofManager::Location LOC, bool VISIT_GHOSTS,
734  typename ... SUBREGIONTYPES, typename LAMBDA >
735 void forMeshLocation( MeshLevel * const mesh,
736  std::vector< std::string > const & regions,
737  LAMBDA && lambda )
738 {
739  forMeshLocation< LOC, LOC, VISIT_GHOSTS, SUBREGIONTYPES... >( mesh,
740  regions,
741  [&]( auto const locIdx,
742  auto const,
743  auto const )
744  {
745  lambda( locIdx );
746  } );
747 }
748 
758 template< DofManager::Location LOC, bool VISIT_GHOSTS, typename ... SUBREGIONTYPES >
759 localIndex countMeshObjects( MeshLevel * const mesh,
760  std::vector< std::string > const & regions )
761 {
762  localIndex count = 0;
763  forMeshLocation< LOC, VISIT_GHOSTS, SUBREGIONTYPES... >( mesh, regions,
764  [&]( auto const GEOSX_UNUSED_PARAM( connIdx ) )
765  {
766  ++count;
767  } );
768  return count;
769 }
770 
776 template< typename INDEX, DofManager::Location LOC >
777 struct IndexArrayHelper
778 {
779  using IndexType = localIndex;
780  using ArrayType = array1d< std::remove_const_t< INDEX > >;
781  using ViewType = arrayView1d< INDEX >;
782  using Accessor = ViewType const;
783  using Mesh = add_const_if_t< MeshLevel, std::is_const< INDEX >::value >;
784 
785  template< typename ... SUBREGIONTYPES >
786  static void
787  create( Mesh * const mesh,
788  string const & key,
789  string const & description,
790  std::vector< std::string > const & GEOSX_UNUSED_PARAM( regions ) )
791  {
792  ObjectManagerBase & baseManager = getObjectManager< LOC >( mesh );
793  baseManager.registerWrapper< ArrayType >( key )->
794  setApplyDefaultValue( -1 )->
795  setPlotLevel( dataRepository::PlotLevel::LEVEL_1 )->
796  setRestartFlags( dataRepository::RestartFlags::NO_WRITE )->
797  setDescription( description );
798  }
799 
800  static Accessor get( Mesh * const mesh, string const & key )
801  {
802  return getObjectManager< LOC >( mesh ).template getReference< ArrayType >( key );
803  }
804 
805  static inline INDEX value( Accessor & indexArray, typename MeshHelper< LOC >::LocalIndexType const i )
806  {
807  return indexArray[i];
808  }
809 
810  static inline INDEX & reference( Accessor & indexArray, typename MeshHelper< LOC >::LocalIndexType const i )
811  {
812  return indexArray[i];
813  }
814 
815  template< typename ... SUBREGIONTYPES >
816  static void
817  remove( Mesh * const mesh,
818  string const & key,
819  std::vector< std::string > const & GEOSX_UNUSED_PARAM( regions ) )
820  {
821  getObjectManager< LOC >( mesh ).deregisterWrapper( key );
822  }
823 };
824 
828 template< typename INDEX >
829 struct IndexArrayHelper< INDEX, DofManager::Location::Elem >
830 {
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 >;
836 
837  template< typename ... SUBREGIONTYPES >
838  static void
839  create( Mesh * const mesh,
840  string const & key,
841  string const & description,
842  std::vector< std::string > const & regions )
843  {
844  mesh->getElemManager()->template forElementSubRegions< SUBREGIONTYPES... >( regions,
845  [&]( localIndex const,
846  auto & subRegion )
847  {
848  subRegion.template registerWrapper< ArrayType >( key )->
849  setApplyDefaultValue( -1 )->
850  setPlotLevel( dataRepository::PlotLevel::LEVEL_1 )->
851  setRestartFlags( dataRepository::RestartFlags::NO_WRITE )->
852  setDescription( description );
853  } );
854  }
855 
856  static Accessor get( Mesh * const mesh, string const & key )
857  {
858  return mesh->getElemManager()->template ConstructViewAccessor< ArrayType, ViewType >( key );
859  }
860 
861  static inline INDEX value( Accessor & indexArray,
862  MeshHelper< DofManager::Location::Elem >::LocalIndexType const & e )
863  {
864  if( indexArray[std::get< 0 >( e )].empty() || indexArray[std::get< 0 >( e )][std::get< 1 >( e )].empty() )
865  {
866  return -1;
867  }
868  return indexArray[std::get< 0 >( e )][std::get< 1 >( e )][std::get< 2 >( e )];
869  }
870 
871  static inline INDEX & reference( Accessor & indexArray,
872  MeshHelper< DofManager::Location::Elem >::LocalIndexType const & e )
873  {
874  return indexArray[std::get< 0 >( e )][std::get< 1 >( e )][std::get< 2 >( e )];
875  }
876 
877  template< typename ... SUBREGIONTYPES >
878  static void
879  remove( Mesh * const mesh,
880  string const & key,
881  std::vector< std::string > const & regions )
882  {
883  mesh->getElemManager()->template forElementSubRegions< SUBREGIONTYPES... >( regions,
884  [&]( localIndex const,
885  ElementSubRegionBase & subRegion )
886  {
887  subRegion.deregisterWrapper( key );
888  } );
889  }
890 };
891 
892 } // namespace
893 
894 } // namespace geosx
895 
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.
Definition: DataTypes.hpp:213
#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.
Definition: DataTypes.hpp:311
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.
Definition: DataTypes.hpp:217
location is element (like pressure in finite volumes)
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:201
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.
Definition: DataTypes.hpp:288
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:197
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...
Definition: DofManager.hpp:51
#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.
Definition: DataTypes.hpp:303
constexpr camp::idx_t getStrideOneDimension(camp::idx_seq< INDICES... >)
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
#define GEOSX_ASSERT(EXP)
Assert a condition in debug builds.
Definition: Logger.hpp:123
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)
Definition: math.hpp:46
mapBase< TKEY, TVAL, std::integral_constant< bool, true > > map
Ordered map type.
Definition: DataTypes.hpp:386
#define GEOSX_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
Definition: GeosxMacros.hpp:66