GEOSX
LaplaceFEMKernels.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 
15 
20 #ifndef GEOSX_PHYSICSSOLVERS_SIMPLEPDE_LAPLACEFEMKERNELS_HPP_
21 #define GEOSX_PHYSICSSOLVERS_SIMPLEPDE_LAPLACEFEMKERNELS_HPP_
22 
24 
25 namespace geosx
26 {
27 //*****************************************************************************
51 template< typename SUBREGION_TYPE,
52  typename CONSTITUTIVE_TYPE,
53  typename FE_TYPE >
55  public finiteElement::ImplicitKernelBase< SUBREGION_TYPE,
56  CONSTITUTIVE_TYPE,
57  FE_TYPE,
58  1,
59  1 >
60 {
61 public:
63  using Base = finiteElement::ImplicitKernelBase< SUBREGION_TYPE,
64  CONSTITUTIVE_TYPE,
65  FE_TYPE,
66  1,
67  1 >;
68 
71  using Base::m_dofNumber;
73  using Base::m_matrix;
74  using Base::m_rhs;
77 
80 
87  LaplaceFEMKernel( NodeManager const & nodeManager,
88  EdgeManager const & edgeManager,
89  FaceManager const & faceManager,
90  SUBREGION_TYPE const & elementSubRegion,
91  FE_TYPE const & finiteElementSpace,
92  CONSTITUTIVE_TYPE * const inputConstitutiveType,
93  arrayView1d< globalIndex const > const & inputDofNumber,
94  globalIndex const rankOffset,
96  arrayView1d< real64 > const & inputRhs,
97  string const & fieldName ):
98  Base( nodeManager,
99  edgeManager,
100  faceManager,
101  elementSubRegion,
102  finiteElementSpace,
103  inputConstitutiveType,
104  inputDofNumber,
105  rankOffset,
106  inputMatrix,
107  inputRhs ),
108  m_X( nodeManager.referencePosition() ),
109  m_primaryField( nodeManager.template getReference< array1d< real64 > >( fieldName )),
110  m_dNdX( elementSubRegion.dNdX() ),
111  m_detJ( elementSubRegion.detJ() )
112  {}
113 
114  //***************************************************************************
122  {
123 public:
124 
130  Base::StackVariables(),
131  xLocal(),
132  primaryField_local{ 0.0 }
133  {}
134 
135 #if !defined(CALC_FEM_SHAPE_IN_KERNEL)
136  int xLocal;
138 #else
139  real64 xLocal[ numNodesPerElem ][ 3 ];
141 #endif
142 
145  };
146 
147 
158  void setup( localIndex const k,
159  StackVariables & stack ) const
160  {
161  for( localIndex a=0; a<numNodesPerElem; ++a )
162  {
163  localIndex const localNodeIndex = m_elemsToNodes( k, a );
164 
165 #if defined(CALC_FEM_SHAPE_IN_KERNEL)
166  for( int i=0; i<3; ++i )
167  {
168  stack.xLocal[ a ][ i ] = m_X[ localNodeIndex ][ i ];
169  }
170 #endif
171 
172  stack.primaryField_local[ a ] = m_primaryField[ localNodeIndex ];
173  stack.localRowDofIndex[a] = m_dofNumber[localNodeIndex];
174  stack.localColDofIndex[a] = m_dofNumber[localNodeIndex];
175  }
176  }
177 
184  localIndex const q,
185  StackVariables & stack ) const
186  {
187  real64 dNdX[ numNodesPerElem ][ 3 ];
188  real64 const detJ = m_finiteElementSpace.template getGradN< FE_TYPE >( k, q, stack.xLocal, dNdX );
189 
190  for( localIndex a=0; a<numNodesPerElem; ++a )
191  {
192  for( localIndex b=0; b<numNodesPerElem; ++b )
193  {
194  stack.localJacobian[ a ][ b ] += LvArray::tensorOps::AiBi< 3 >( dNdX[a], dNdX[b] ) * detJ;
195  }
196  }
197  }
198 
209  StackVariables & stack ) const
210  {
211  GEOSX_UNUSED_VAR( k );
212  real64 maxForce = 0;
213 
214  for( localIndex a = 0; a < numNodesPerElem; ++a )
215  {
216  for( localIndex b = 0; b < numNodesPerElem; ++b )
217  {
218  stack.localResidual[ a ] += stack.localJacobian[ a ][ b ] * stack.primaryField_local[ b ];
219  }
220  }
221 
222  for( int a = 0; a < numNodesPerElem; ++a )
223  {
224  localIndex const dof = LvArray::integerConversion< localIndex >( stack.localRowDofIndex[ a ] - m_dofRankOffset );
225  if( dof < 0 || dof >= m_matrix.numRows() ) continue;
226  m_matrix.template addToRowBinarySearchUnsorted< parallelDeviceAtomic >( dof,
227  stack.localColDofIndex,
228  stack.localJacobian[ a ],
229  numNodesPerElem );
230 
231  RAJA::atomicAdd< parallelDeviceAtomic >( &m_rhs[ dof ], stack.localResidual[ a ] );
232  maxForce = fmax( maxForce, fabs( stack.localResidual[ a ] ) );
233  }
234 
235  return maxForce;
236  }
237 
238 
239 
240 protected:
243 
246 
249 
252 
253 };
254 
255 
256 } // namespace geosx
257 
259 
260 #endif // GEOSX_PHYSICSSOLVERS_SIMPLEPDE_LAPLACEFEMKERNELS_HPP_
#define GEOSX_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:48
Kernel variables allocated on the stack.
Define the base interface for implicit finite element kernels.
real64 localResidual[numRows]
C-array storage for the element local residual vector.
Kernel variables allocated on the stack.
Definition: KernelBase.hpp:182
long long int globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:128
The NodeManager class provides an interface to ObjectManagerBase in order to manage node data...
Definition: NodeManager.hpp:47
arrayView2d< real64 const, nodes::REFERENCE_POSITION_USD > const m_X
The array containing the nodal position array.
Implements kernels for solving Laplace&#39;s equation.
traits::ViewTypeConst< typename SUBREGION_TYPE::NodeMapType::base_type > const m_elemsToNodes
The element to nodes map.
Definition: KernelBase.hpp:302
This class serves to provide a "view" of a multidimensional array.
Definition: ArrayView.hpp:67
arrayView1d< globalIndex const > const m_dofNumber
The global degree of freedom number.
constexpr INDEX_TYPE_NC numRows() const
double real64
64-bit floating point type.
Definition: DataTypes.hpp:136
arrayView2d< real64 const > const m_detJ
The global determinant of the parent/physical Jacobian.
LaplaceFEMKernel(NodeManager const &nodeManager, EdgeManager const &edgeManager, FaceManager const &faceManager, SUBREGION_TYPE const &elementSubRegion, FE_TYPE const &finiteElementSpace, CONSTITUTIVE_TYPE *const inputConstitutiveType, arrayView1d< globalIndex const > const &inputDofNumber, globalIndex const rankOffset, CRSMatrixView< real64, globalIndex const > const &inputMatrix, arrayView1d< real64 > const &inputRhs, string const &fieldName)
Constructor.
globalIndex localColDofIndex[numCols]
C-array storage for the element local column degrees of freedom.
static constexpr int numTestSupportPointsPerElem
Definition: KernelBase.hpp:137
GEOSX_HOST_DEVICE GEOSX_FORCE_INLINE void setup(localIndex const k, StackVariables &stack) const
Copy global values from primary field to a local stack array.
FE_TYPE const & m_finiteElementSpace
Definition: KernelBase.hpp:313
static constexpr int numDofPerTestSupportPoint
Definition: KernelBase.hpp:145
arrayView1d< real64 const > const m_primaryField
The global primary field array.
This class provides an interface to ObjectManagerBase in order to manage edge data.
Definition: EdgeManager.hpp:42
real64 primaryField_local[numNodesPerElem]
C-array storage for the element local primary field variable.
#define GEOSX_FORCE_INLINE
Marks a function or lambda for inlining.
Definition: GeosxMacros.hpp:50
GEOSX_HOST_DEVICE GEOSX_FORCE_INLINE void quadraturePointKernel(localIndex const k, localIndex const q, StackVariables &stack) const
Performs a state update at a quadrature point.
#define GEOSX_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:78
static constexpr int numDofPerTrialSupportPoint
Definition: KernelBase.hpp:149
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
GEOSX_HOST_DEVICE GEOSX_FORCE_INLINE real64 complete(localIndex const k, StackVariables &stack) const
Performs the complete phase for the kernel.
arrayView4d< real64 const > const m_dNdX
The global shape function derivatives array.
CRSMatrixView< real64, globalIndex const > const m_matrix
The global Jacobian matrix.
The FaceManager class provides an interface to ObjectManagerBase in order to manage face data...
Definition: FaceManager.hpp:40
GEOSX_HOST_DEVICE StackVariables()
Constructor.
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
Definition: Array.hpp:55
globalIndex localRowDofIndex[numRows]
C-array storage for the element local row degrees of freedom.
real64 localJacobian[numRows][numCols]
C-array storage for the element local Jacobian matrix.
static constexpr int numNodesPerElem
The number of nodes per element.