GEOS
AverageOverQuadraturePointsKernel.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 Total, S.A
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_UTILITIES_AVERAGEOVERQUADRATUREPOINTSKERNEL_HPP_
21 #define GEOS_MESH_UTILITIES_AVERAGEOVERQUADRATUREPOINTSKERNEL_HPP_
22 
23 #include "common/DataTypes.hpp"
24 #include "common/GEOS_RAJA_Interface.hpp"
25 #include "finiteElement/FiniteElementDispatch.hpp"
26 #include "mesh/CellElementSubRegion.hpp"
27 
28 namespace geos
29 {
30 
36 template< typename SUBREGION_TYPE,
37  typename FE_TYPE >
39 {
40 public:
41 
51  EdgeManager const & edgeManager,
52  FaceManager const & faceManager,
53  SUBREGION_TYPE const & elementSubRegion,
54  FE_TYPE const & finiteElementSpace ):
55  m_finiteElementSpace( finiteElementSpace ),
56  m_elemsToNodes( elementSubRegion.nodeList().toViewConst() ),
57  m_X( nodeManager.referencePosition() ),
58  m_elementVolume( elementSubRegion.getElementVolume() )
59  {
60  finiteElement::FiniteElementBase::
61  initialize< FE_TYPE >( nodeManager,
62  edgeManager,
63  faceManager,
64  elementSubRegion,
65  m_meshData );
66  }
67 
68  //*****************************************************************************
73  {
74 public:
75 
81  xLocal()
82  {}
83 
85  real64 xLocal[ FE_TYPE::maxSupportPoints ][ 3 ];
86 
88  typename FE_TYPE::StackVariables feStack;
89  };
90  //***************************************************************************
91 
98  void setup( localIndex const k,
99  StackVariables & stack ) const
100  {
101  m_finiteElementSpace.template setup< FE_TYPE >( k, m_meshData, stack.feStack );
102 
103  for( localIndex a = 0; a < FE_TYPE::maxSupportPoints; ++a )
104  {
105  localIndex const localNodeIndex = m_elemsToNodes( k, a );
106 
107  for( integer i = 0; i < 3; ++i )
108  {
109  stack.xLocal[a][i] = m_X[localNodeIndex][i];
110  }
111  }
112  }
113 
114 protected:
115 
118  FE_TYPE const & m_finiteElementSpace;
119 
121  traits::ViewTypeConst< typename SUBREGION_TYPE::NodeMapType::base_type > const m_elemsToNodes;
122 
125 
128 
130  typename FE_TYPE::template MeshData< SUBREGION_TYPE > m_meshData;
131 };
132 
138 template< typename SUBREGION_TYPE,
139  typename FE_TYPE >
141  public AverageOverQuadraturePointsBase< SUBREGION_TYPE,
142  FE_TYPE >
143 {
144 public:
145 
147  using Base = AverageOverQuadraturePointsBase< SUBREGION_TYPE,
148  FE_TYPE >;
149 
150  using Base::m_elementVolume;
151 
163  EdgeManager const & edgeManager,
164  FaceManager const & faceManager,
165  SUBREGION_TYPE const & elementSubRegion,
166  FE_TYPE const & finiteElementSpace,
167  arrayView2d< real64 const > const property,
168  arrayView1d< real64 > const averageProperty ):
169  Base( nodeManager,
170  edgeManager,
171  faceManager,
172  elementSubRegion,
173  finiteElementSpace ),
174  m_property( property ),
175  m_averageProperty( averageProperty )
176  {}
177 
182  {};
183 
190  void setup( localIndex const k,
191  StackVariables & stack ) const
192  {
193  Base::setup( k, stack );
194  m_averageProperty[k] = 0.0;
195  }
196 
205  localIndex const q,
206  StackVariables & stack ) const
207  {
208  real64 const weight = FE_TYPE::transformedQuadratureWeight( q, stack.xLocal, stack.feStack ) / m_elementVolume[k];
209  m_averageProperty[k] += weight * m_property[k][q];
210  }
211 
219  template< typename POLICY,
220  typename KERNEL_TYPE >
221  static void
222  kernelLaunch( localIndex const numElems,
223  KERNEL_TYPE const & kernelComponent )
224  {
225  forAll< POLICY >( numElems,
226  [=] GEOS_HOST_DEVICE ( localIndex const k )
227  {
228  typename KERNEL_TYPE::StackVariables stack;
229 
230  kernelComponent.setup( k, stack );
231  for( integer q = 0; q < FE_TYPE::numQuadraturePoints; ++q )
232  {
233  kernelComponent.quadraturePointKernel( k, q, stack );
234  }
235  } );
236  }
237 
238 protected:
239 
242 
245 
246 };
247 
248 
254 {
255 public:
256 
270  template< typename SUBREGION_TYPE,
271  typename FE_TYPE,
272  typename POLICY >
273  static void
274  createAndLaunch( NodeManager & nodeManager,
275  EdgeManager const & edgeManager,
276  FaceManager const & faceManager,
277  SUBREGION_TYPE const & elementSubRegion,
278  FE_TYPE const & finiteElementSpace,
279  arrayView2d< real64 const > const property,
280  arrayView1d< real64 > const averageProperty )
281  {
283  kernel( nodeManager, edgeManager, faceManager, elementSubRegion, finiteElementSpace,
284  property, averageProperty );
285 
287  kernelLaunch< POLICY >( elementSubRegion.size(), kernel );
288  }
289 };
290 
291 }
292 
293 #endif /* GEOS_MESH_UTILITIES_AVERAGEOVERQUADRATUREPOINTSKERNEL_HPP_ */
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
arrayView2d< real64 const > const m_property
The property living on quadrature points.
AverageOverQuadraturePoints1D(NodeManager &nodeManager, EdgeManager const &edgeManager, FaceManager const &faceManager, SUBREGION_TYPE const &elementSubRegion, FE_TYPE const &finiteElementSpace, arrayView2d< real64 const > const property, arrayView1d< real64 > const averageProperty)
Constructor for the class.
GEOS_HOST_DEVICE void quadraturePointKernel(localIndex const k, localIndex const q, StackVariables &stack) const
Increment the average property with the contribution of the property at this quadrature point.
arrayView1d< real64 > const m_averageProperty
The average property.
static void kernelLaunch(localIndex const numElems, KERNEL_TYPE const &kernelComponent)
Launch the kernel over the elements in the subRegion.
arrayView1d< real64 const > const m_elementVolume
The volume of the elements.
GEOS_HOST_DEVICE void setup(localIndex const k, StackVariables &stack) const
Performs the setup phase for the kernel.
static void createAndLaunch(NodeManager &nodeManager, EdgeManager const &edgeManager, FaceManager const &faceManager, SUBREGION_TYPE const &elementSubRegion, FE_TYPE const &finiteElementSpace, arrayView2d< real64 const > const property, arrayView1d< real64 > const averageProperty)
Create a new kernel and launch.
GEOS_HOST_DEVICE void setup(localIndex const k, StackVariables &stack) const
Performs the setup phase for the kernel.
arrayView2d< real64 const, nodes::REFERENCE_POSITION_USD > const m_X
The reference position of the nodes.
arrayView1d< real64 const > const m_elementVolume
The volume of the elements.
FE_TYPE::template MeshData< SUBREGION_TYPE > m_meshData
Data structure containing mesh data used to setup the finite element.
traits::ViewTypeConst< typename SUBREGION_TYPE::NodeMapType::base_type > const m_elemsToNodes
The element to nodes map.
AverageOverQuadraturePointsBase(NodeManager &nodeManager, EdgeManager const &edgeManager, FaceManager const &faceManager, SUBREGION_TYPE const &elementSubRegion, FE_TYPE const &finiteElementSpace)
Constructor for the class.
This class provides an interface to ObjectManagerBase in order to manage edge data.
Definition: EdgeManager.hpp:43
The FaceManager class provides an interface to ObjectManagerBase in order to manage face data.
Definition: FaceManager.hpp:44
The NodeManager class provides an interface to ObjectManagerBase in order to manage node data.
Definition: NodeManager.hpp:46
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:180
double real64
64-bit floating point type.
Definition: DataTypes.hpp:99
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:82
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:196
FE_TYPE::StackVariables feStack
Stack variables needed for the underlying FEM type.
real64 xLocal[FE_TYPE::maxSupportPoints][3]
C-array stack storage for element local the nodal positions.