GEOSX
AverageOverQuadraturePointsKernel.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_UTILITIES_AVERAGEOVERQUADRATUREPOINTSKERNEL_HPP_
20 #define GEOS_MESH_UTILITIES_AVERAGEOVERQUADRATUREPOINTSKERNEL_HPP_
21 
22 #include "common/DataTypes.hpp"
23 #include "common/GEOS_RAJA_Interface.hpp"
24 #include "finiteElement/FiniteElementDispatch.hpp"
25 #include "mesh/CellElementSubRegion.hpp"
26 
27 namespace geos
28 {
29 
35 template< typename SUBREGION_TYPE,
36  typename FE_TYPE >
38 {
39 public:
40 
50  EdgeManager const & edgeManager,
51  FaceManager const & faceManager,
52  SUBREGION_TYPE const & elementSubRegion,
53  FE_TYPE const & finiteElementSpace ):
54  m_finiteElementSpace( finiteElementSpace ),
55  m_elemsToNodes( elementSubRegion.nodeList().toViewConst() ),
56  m_X( nodeManager.referencePosition() ),
57  m_elementVolume( elementSubRegion.getElementVolume() )
58  {
59  finiteElement::FiniteElementBase::
60  initialize< FE_TYPE >( nodeManager,
61  edgeManager,
62  faceManager,
63  elementSubRegion,
64  m_meshData );
65  }
66 
67  //*****************************************************************************
72  {
73 public:
74 
80  xLocal()
81  {}
82 
84  real64 xLocal[ FE_TYPE::maxSupportPoints ][ 3 ];
85 
87  typename FE_TYPE::StackVariables feStack;
88  };
89  //***************************************************************************
90 
97  void setup( localIndex const k,
98  StackVariables & stack ) const
99  {
100  m_finiteElementSpace.template setup< FE_TYPE >( k, m_meshData, stack.feStack );
101 
102  for( localIndex a = 0; a < FE_TYPE::maxSupportPoints; ++a )
103  {
104  localIndex const localNodeIndex = m_elemsToNodes( k, a );
105 
106  for( integer i = 0; i < 3; ++i )
107  {
108  stack.xLocal[a][i] = m_X[localNodeIndex][i];
109  }
110  }
111  }
112 
113 protected:
114 
117  FE_TYPE const & m_finiteElementSpace;
118 
120  traits::ViewTypeConst< typename SUBREGION_TYPE::NodeMapType::base_type > const m_elemsToNodes;
121 
124 
127 
129  typename FE_TYPE::template MeshData< SUBREGION_TYPE > m_meshData;
130 };
131 
137 template< typename SUBREGION_TYPE,
138  typename FE_TYPE >
140  public AverageOverQuadraturePointsBase< SUBREGION_TYPE,
141  FE_TYPE >
142 {
143 public:
144 
146  using Base = AverageOverQuadraturePointsBase< SUBREGION_TYPE,
147  FE_TYPE >;
148 
149  using Base::m_elementVolume;
150 
162  EdgeManager const & edgeManager,
163  FaceManager const & faceManager,
164  SUBREGION_TYPE const & elementSubRegion,
165  FE_TYPE const & finiteElementSpace,
166  arrayView2d< real64 const > const property,
167  arrayView1d< real64 > const averageProperty ):
168  Base( nodeManager,
169  edgeManager,
170  faceManager,
171  elementSubRegion,
172  finiteElementSpace ),
173  m_property( property ),
174  m_averageProperty( averageProperty )
175  {}
176 
181  {};
182 
189  void setup( localIndex const k,
190  StackVariables & stack ) const
191  {
192  Base::setup( k, stack );
193  m_averageProperty[k] = 0.0;
194  }
195 
204  localIndex const q,
205  StackVariables & stack ) const
206  {
207  real64 const weight = FE_TYPE::transformedQuadratureWeight( q, stack.xLocal, stack.feStack ) / m_elementVolume[k];
208  m_averageProperty[k] += weight * m_property[k][q];
209  }
210 
218  template< typename POLICY,
219  typename KERNEL_TYPE >
220  static void
221  kernelLaunch( localIndex const numElems,
222  KERNEL_TYPE const & kernelComponent )
223  {
224  forAll< POLICY >( numElems,
225  [=] GEOS_HOST_DEVICE ( localIndex const k )
226  {
227  typename KERNEL_TYPE::StackVariables stack;
228 
229  kernelComponent.setup( k, stack );
230  for( integer q = 0; q < FE_TYPE::numQuadraturePoints; ++q )
231  {
232  kernelComponent.quadraturePointKernel( k, q, stack );
233  }
234  } );
235  }
236 
237 protected:
238 
241 
244 
245 };
246 
247 
253 {
254 public:
255 
269  template< typename SUBREGION_TYPE,
270  typename FE_TYPE,
271  typename POLICY >
272  static void
273  createAndLaunch( NodeManager & nodeManager,
274  EdgeManager const & edgeManager,
275  FaceManager const & faceManager,
276  SUBREGION_TYPE const & elementSubRegion,
277  FE_TYPE const & finiteElementSpace,
278  arrayView2d< real64 const > const property,
279  arrayView1d< real64 > const averageProperty )
280  {
282  kernel( nodeManager, edgeManager, faceManager, elementSubRegion, finiteElementSpace,
283  property, averageProperty );
284 
286  kernelLaunch< POLICY >( elementSubRegion.size(), kernel );
287  }
288 };
289 
290 }
291 
292 #endif /* GEOS_MESH_UTILITIES_AVERAGEOVERQUADRATUREPOINTSKERNEL_HPP_ */
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:48
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:42
The FaceManager class provides an interface to ObjectManagerBase in order to manage face data.
Definition: FaceManager.hpp:43
The NodeManager class provides an interface to ObjectManagerBase in order to manage node data.
Definition: NodeManager.hpp:45
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:220
double real64
64-bit floating point type.
Definition: DataTypes.hpp:139
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:122
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:236
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
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.