GEOS
LaplaceFEMKernels.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 
16 
21 #ifndef GEOS_PHYSICSSOLVERS_SIMPLEPDE_LAPLACEFEMKERNELS_HPP_
22 #define GEOS_PHYSICSSOLVERS_SIMPLEPDE_LAPLACEFEMKERNELS_HPP_
23 
24 #define GEOS_DISPATCH_VEM
25 
27 
28 namespace geos
29 {
30 
31 //*****************************************************************************
55 template< typename SUBREGION_TYPE,
56  typename CONSTITUTIVE_TYPE,
57  typename FE_TYPE >
59  public finiteElement::ImplicitKernelBase< SUBREGION_TYPE,
60  CONSTITUTIVE_TYPE,
61  FE_TYPE,
62  1,
63  1 >
64 {
65 public:
67  using Base = finiteElement::ImplicitKernelBase< SUBREGION_TYPE,
68  CONSTITUTIVE_TYPE,
69  FE_TYPE,
70  1,
71  1 >;
72 
76  using Base::m_dofNumber;
78  using Base::m_matrix;
79  using Base::m_rhs;
82  using Base::m_meshData;
83  using Base::m_dt;
84 
91  LaplaceFEMKernel( NodeManager const & nodeManager,
92  EdgeManager const & edgeManager,
93  FaceManager const & faceManager,
94  localIndex const targetRegionIndex,
95  SUBREGION_TYPE const & elementSubRegion,
96  FE_TYPE const & finiteElementSpace,
97  CONSTITUTIVE_TYPE & inputConstitutiveType,
98  arrayView1d< globalIndex const > const inputDofNumber,
99  globalIndex const rankOffset,
101  arrayView1d< real64 > const inputRhs,
102  real64 const inputDt,
103  string const fieldName ):
104  Base( nodeManager,
105  edgeManager,
106  faceManager,
107  targetRegionIndex,
108  elementSubRegion,
109  finiteElementSpace,
110  inputConstitutiveType,
111  inputDofNumber,
112  rankOffset,
113  inputMatrix,
114  inputRhs,
115  inputDt ),
116  m_X( nodeManager.referencePosition() ),
117  m_primaryField( nodeManager.template getReference< array1d< real64 > >( fieldName ))
118  {}
119 
120  //***************************************************************************
128  {
129 public:
130 
136  Base::StackVariables(),
137  xLocal(),
138  primaryField_local{ 0.0 }
139  {}
140 
141 #if !defined(CALC_FEM_SHAPE_IN_KERNEL)
143  int xLocal;
144 #else
147 #endif
148 
151  };
152 
153 
163  inline
164  void setup( localIndex const k,
165  StackVariables & stack ) const
166  {
167  m_finiteElementSpace.template setup< FE_TYPE >( k, m_meshData, stack.feStack );
168  stack.numRows = m_finiteElementSpace.template numSupportPoints< FE_TYPE >( stack.feStack );
169  stack.numCols = stack.numRows;
170  for( localIndex a = 0; a < stack.numRows; ++a )
171  {
172  localIndex const localNodeIndex = m_elemsToNodes( k, a );
173 
174 #if defined(CALC_FEM_SHAPE_IN_KERNEL)
175  for( int i=0; i<3; ++i )
176  {
177  stack.xLocal[ a ][ i ] = m_X[ localNodeIndex ][ i ];
178  }
179 #endif
180 
181  stack.primaryField_local[ a ] = m_primaryField[ localNodeIndex ];
182  stack.localRowDofIndex[a] = m_dofNumber[localNodeIndex];
183  stack.localColDofIndex[a] = m_dofNumber[localNodeIndex];
184  }
185  m_finiteElementSpace.template
186  addGradGradStabilizationMatrix< FE_TYPE, numDofPerTrialSupportPoint >( stack.feStack,
187  stack.localJacobian );
188  }
189 
194  inline
196  localIndex const q,
197  StackVariables & stack ) const
198  {
200  real64 const detJ = m_finiteElementSpace.template getGradN< FE_TYPE >( k, q, stack.xLocal,
201  stack.feStack, dNdX );
202  for( localIndex a = 0; a < stack.numRows; ++a )
203  {
204  for( localIndex b = 0; b < stack.numCols; ++b )
205  {
206  stack.localJacobian[ a ][ b ] += LvArray::tensorOps::AiBi< 3 >( dNdX[a], dNdX[b] ) * detJ;
207  }
208  }
209  }
210 
219  inline
221  StackVariables & stack ) const
222  {
223  GEOS_UNUSED_VAR( k );
224  real64 maxForce = 0;
225 
226  for( localIndex a = 0; a < stack.numRows; ++a )
227  {
228  for( localIndex b = 0; b < stack.numCols; ++b )
229  {
230  stack.localResidual[ a ] += stack.localJacobian[ a ][ b ] * stack.primaryField_local[ b ];
231  }
232  }
233 
234  for( int a = 0; a < stack.numRows; ++a )
235  {
236  localIndex const dof = LvArray::integerConversion< localIndex >( stack.localRowDofIndex[ a ] - m_dofRankOffset );
237  if( dof < 0 || dof >= m_matrix.numRows() ) continue;
238  m_matrix.template addToRowBinarySearchUnsorted< parallelDeviceAtomic >( dof,
239  stack.localColDofIndex,
240  stack.localJacobian[ a ],
241  stack.numCols );
242 
243  RAJA::atomicAdd< parallelDeviceAtomic >( &m_rhs[ dof ], stack.localResidual[ a ] );
244  maxForce = fmax( maxForce, fabs( stack.localResidual[ a ] ) );
245  }
246 
247  return maxForce;
248  }
249 
250 protected:
253 
256 
257 };
258 
262  globalIndex const,
264  arrayView1d< real64 > const,
265  real64 const,
266  string const >;
267 
268 } // namespace geos
269 
271 
272 #endif // GEOS_PHYSICSSOLVERS_SIMPLEPDE_LAPLACEFEMKERNELS_HPP_
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:84
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
Implements kernels for solving Laplace's equation.
GEOS_HOST_DEVICE real64 complete(localIndex const k, StackVariables &stack) const
Performs the complete phase for the kernel.
LaplaceFEMKernel(NodeManager const &nodeManager, EdgeManager const &edgeManager, FaceManager const &faceManager, localIndex const targetRegionIndex, SUBREGION_TYPE const &elementSubRegion, FE_TYPE const &finiteElementSpace, CONSTITUTIVE_TYPE &inputConstitutiveType, arrayView1d< globalIndex const > const inputDofNumber, globalIndex const rankOffset, CRSMatrixView< real64, globalIndex const > const inputMatrix, arrayView1d< real64 > const inputRhs, real64 const inputDt, string const fieldName)
Constructor.
GEOS_HOST_DEVICE void quadraturePointKernel(localIndex const k, localIndex const q, StackVariables &stack) const
Performs a state update at a quadrature point.
arrayView2d< real64 const, nodes::REFERENCE_POSITION_USD > const m_X
The array containing the nodal position array.
GEOS_HOST_DEVICE void setup(localIndex const k, StackVariables &stack) const
Copy global values from primary field to a local stack array.
arrayView1d< real64 const > const m_primaryField
The global primary field array.
The NodeManager class provides an interface to ObjectManagerBase in order to manage node data.
Definition: NodeManager.hpp:46
Define the base interface for implicit finite element kernels.
traits::ViewTypeConst< typename SUBREGION_TYPE::NodeMapType::base_type > const m_elemsToNodes
The element to nodes map.
Definition: KernelBase.hpp:257
CRSMatrixView< real64, globalIndex const > const m_matrix
The global Jacobian matrix.
FE_TYPE::template MeshData< SUBREGION_TYPE > m_meshData
Data structure containing mesh data used to setup the finite element.
arrayView1d< globalIndex const > const m_dofNumber
The global degree of freedom number.
Used to forward arguments to a class that implements the KernelBase interface.
Definition: KernelBase.hpp:282
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:180
LvArray::CRSMatrixView< T, COL_INDEX, localIndex const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
Definition: DataTypes.hpp:310
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:88
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
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:196
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:176
Kernel variables allocated on the stack.
GEOS_HOST_DEVICE StackVariables()
Constructor.
real64 primaryField_local[maxNumTestSupportPointsPerElem]
C-array storage for the element local primary field variable.
Kernel variables allocated on the stack.
Definition: KernelBase.hpp:137