GEOSX
MeshForLoopInterface.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 TotalEnergies
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 GEOS_MESH_MESHFORLOOPINTERFACE_HPP
20 #define GEOS_MESH_MESHFORLOOPINTERFACE_HPP
21 
22 #include "finiteElement/FiniteElementDiscretization.hpp"
23 #include "finiteElement/FiniteElementDiscretizationManager.hpp"
24 #include "common/GEOS_RAJA_Interface.hpp"
25 
26 #include "common/DataTypes.hpp"
27 #include "mesh/MeshLevel.hpp"
28 #include "constitutive/ConstitutiveManager.hpp"
29 
30 namespace geos
31 {
32 
40 template< class POLICY=serialPolicy, typename LAMBDA=void >
41 void forAllElemsInMesh( MeshLevel const & mesh, LAMBDA && lambda )
42 {
43 
44  ElementRegionManager const & elemManager = mesh.getElemManager();
45  elemManager.forElementSubRegionsComplete< ElementSubRegionBase >( [&] ( localIndex const er,
46  localIndex const esr,
47  ElementRegionBase const &,
48  ElementSubRegionBase const & subRegion )
49  {
50  forAll< POLICY >( subRegion.size(), [&]( localIndex const k ) { lambda( er, esr, k ); } );
51  } );
52 }
53 
60 template< typename LAMBDA >
61 auto
62 minLocOverElemsInMesh( MeshLevel const & mesh, LAMBDA && lambda )
63 {
64  using NUMBER = decltype( lambda( 0, 0, 0 ) );
65 
66  NUMBER minVal = std::numeric_limits< NUMBER >::max();
67  localIndex minReg = -1, minSubreg = -1, minIndex = -1;
68 
69  ElementRegionManager const & elemManager = mesh.getElemManager();
70 
71  for( localIndex er=0; er<elemManager.numRegions(); ++er )
72  {
73  ElementRegionBase const & elemRegion = elemManager.getRegion( er );
74 
75  elemRegion.forElementSubRegionsIndex< CellElementSubRegion >( [&]( localIndex const esr, CellElementSubRegion const & subRegion )
76  {
77  localIndex const size = subRegion.size();
78  for( localIndex k = 0; k < size; ++k )
79  {
80  NUMBER const val = lambda( er, esr, k );
81  if( val < minVal )
82  {
83  minVal = val;
84  minReg = er;
85  minSubreg = esr;
86  minIndex = k;
87  }
88  }
89  } );
90  }
91 
92  return std::make_pair( minVal, std::make_tuple( minReg, minSubreg, minIndex ));
93 }
94 
95 } // namespace geos
96 
97 #endif // GEOS_MESH_MESHFORLOOPINTERFACE_HPP
The ElementRegionBase is the base class to manage the data stored at the element level.
void forElementSubRegionsIndex(LAMBDA &&lambda) const
Apply LAMBDA to the subregions, loop using subregion indices.
The ElementRegionManager class provides an interface to ObjectManagerBase in order to manage ElementR...
localIndex numRegions() const
Get number of the regions.
void forElementSubRegionsComplete(LAMBDA &&lambda) const
This const function is used to launch kernel function over the element subregions of all subregion ty...
T const & getRegion(KEY_TYPE const &key) const
Get a element region.
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:41
ElementRegionManager const & getElemManager() const
Get the element region manager.
Definition: MeshLevel.hpp:206
void forAllElemsInMesh(MeshLevel const &mesh, LAMBDA &&lambda)
Loop over all elements in a geos::MeshLevel.
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
auto minLocOverElemsInMesh(MeshLevel const &mesh, LAMBDA &&lambda)