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 
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< ElementSubRegionBase >( [&]( localIndex const esr, ElementSubRegionBase 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 
101 template< typename LAMBDA >
102 auto
103 minLocOverElemsInRegion( ElementRegionBase const & region, LAMBDA && lambda )
104 {
105  using NUMBER = decltype( lambda( 0, 0 ) );
106 
107  NUMBER minVal = std::numeric_limits< NUMBER >::max();
108  localIndex minSubreg = -1, minIndex = -1;
109 
110  region.forElementSubRegionsIndex< ElementSubRegionBase >( [&]( localIndex const esr, ElementSubRegionBase const & subRegion )
111  {
112  localIndex const size = subRegion.size();
113  for( localIndex k = 0; k < size; ++k )
114  {
115  NUMBER const val = lambda( esr, k );
116  if( val < minVal )
117  {
118  minVal = val;
119  minSubreg = esr;
120  minIndex = k;
121  }
122  }
123  } );
124 
125  return std::make_pair( minVal, std::make_tuple( minSubreg, minIndex ));
126 }
127 
134 template< typename LAMBDA >
135 auto
136 minLocOverElemsInSubRegion( ElementSubRegionBase const & subRegion, LAMBDA && lambda )
137 {
138  using NUMBER = decltype( lambda( 0 ) );
139 
140  NUMBER minVal = std::numeric_limits< NUMBER >::max();
141  localIndex minIndex = -1;
142 
143  localIndex const size = subRegion.size();
144  for( localIndex k = 0; k < size; ++k )
145  {
146  NUMBER const val = lambda( k );
147  if( val < minVal )
148  {
149  minVal = val;
150  minIndex = k;
151  }
152  }
153 
154  return std::make_pair( minVal, minIndex );
155 }
156 
157 } // namespace geos
158 
159 #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
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers.
Definition: Group.hpp:1317
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 minLocOverElemsInRegion(ElementRegionBase const &region, LAMBDA &&lambda)
auto minLocOverElemsInSubRegion(ElementSubRegionBase const &subRegion, LAMBDA &&lambda)
auto minLocOverElemsInMesh(MeshLevel const &mesh, LAMBDA &&lambda)