GEOS
MeshForLoopInterface.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_MESH_MESHFORLOOPINTERFACE_HPP
21 #define GEOS_MESH_MESHFORLOOPINTERFACE_HPP
22 
23 #include "finiteElement/FiniteElementDiscretization.hpp"
24 #include "finiteElement/FiniteElementDiscretizationManager.hpp"
25 #include "common/GEOS_RAJA_Interface.hpp"
26 
27 #include "common/DataTypes.hpp"
28 #include "mesh/MeshLevel.hpp"
29 #include "constitutive/ConstitutiveManager.hpp"
30 
31 namespace geos
32 {
33 
41 template< class POLICY=serialPolicy, typename LAMBDA=void >
42 void forAllElemsInMesh( MeshLevel const & mesh, LAMBDA && lambda )
43 {
44 
45  ElementRegionManager const & elemManager = mesh.getElemManager();
46  elemManager.forElementSubRegionsComplete< ElementSubRegionBase >( [&] ( localIndex const er,
47  localIndex const esr,
48  ElementRegionBase const &,
49  ElementSubRegionBase const & subRegion )
50  {
51  forAll< POLICY >( subRegion.size(), [&]( localIndex const k ) { lambda( er, esr, k ); } );
52  } );
53 }
54 
61 template< typename LAMBDA >
62 auto
63 minLocOverElemsInMesh( MeshLevel const & mesh, LAMBDA && lambda )
64 {
65  using NUMBER = decltype( lambda( 0, 0, 0 ) );
66 
67  NUMBER minVal = std::numeric_limits< NUMBER >::max();
68  localIndex minReg = -1, minSubreg = -1, minIndex = -1;
69 
70  ElementRegionManager const & elemManager = mesh.getElemManager();
71 
72  for( localIndex er=0; er<elemManager.numRegions(); ++er )
73  {
74  ElementRegionBase const & elemRegion = elemManager.getRegion( er );
75 
76  elemRegion.forElementSubRegionsIndex< CellElementSubRegion >( [&]( localIndex const esr, CellElementSubRegion const & subRegion )
77  {
78  localIndex const size = subRegion.size();
79  for( localIndex k = 0; k < size; ++k )
80  {
81  NUMBER const val = lambda( er, esr, k );
82  if( val < minVal )
83  {
84  minVal = val;
85  minReg = er;
86  minSubreg = esr;
87  minIndex = k;
88  }
89  }
90  } );
91  }
92 
93  return std::make_pair( minVal, std::make_tuple( minReg, minSubreg, minIndex ));
94 }
95 
96 } // namespace geos
97 
98 #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:42
ElementRegionManager const & getElemManager() const
Get the element region manager.
Definition: MeshLevel.hpp:207
void forAllElemsInMesh(MeshLevel const &mesh, LAMBDA &&lambda)
Loop over all elements in a geos::MeshLevel.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85
auto minLocOverElemsInMesh(MeshLevel const &mesh, LAMBDA &&lambda)