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 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_MESH_MESHFORLOOPINTERFACE_HPP
20 #define GEOSX_MESH_MESHFORLOOPINTERFACE_HPP
21 
22 #include "finiteElement/FiniteElementDiscretization.hpp"
23 #include "finiteElement/FiniteElementDiscretizationManager.hpp"
24 #include "rajaInterface/GEOS_RAJA_Interface.hpp"
25 
26 #include "common/DataTypes.hpp"
27 #include "mesh/MeshLevel.hpp"
28 #include "constitutive/ConstitutiveManager.hpp"
29 
30 namespace geosx
31 {
32 
40 template< class POLICY=serialPolicy, typename LAMBDA=void >
41 void forAllElemsInMesh( MeshLevel const * const mesh, LAMBDA && lambda )
42 {
43 
44  ElementRegionManager const * 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 * 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 * const elemManager = mesh->getElemManager();
70 
71  for( localIndex er=0; er<elemManager->numRegions(); ++er )
72  {
73  ElementRegionBase const * 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 geosx
96 
97 #endif // GEOSX_MESH_MESHFORLOOPINTERFACE_HPP
auto minLocOverElemsInMesh(MeshLevel const *const mesh, LAMBDA &&lambda)
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:38
void forElementSubRegionsComplete(LAMBDA &&lambda) const
This const function is used to launch kernel function over the element subregions of all subregion ty...
void forElementSubRegionsIndex(LAMBDA &&lambda) const
Apply LAMBDA to the subregions, loop using subregion indices.
ElementRegionManager const * getElemManager() const
Get the element region manager.
Definition: MeshLevel.hpp:139
T const * GetRegion(string const &regionName) const
Get a element region.
The ElementRegionBase is the base class to manage the data stored at the element level.
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
The ElementRegionManager class provides an interface to ObjectManagerBase in order to manage ElementR...
void forAllElemsInMesh(MeshLevel const *const mesh, LAMBDA &&lambda)
Loop over all elements in a geosx::MeshLevel.
constexpr std::enable_if_t< std::is_arithmetic< T >::value, T > max(T const a, T const b)
Definition: math.hpp:46
localIndex numRegions() const
Get number of the regions.