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 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 
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 
143 
146  };
147 
148 
158  inline
159  void setup( localIndex const k,
160  StackVariables & stack ) const
161  {
162  m_finiteElementSpace.template setup< FE_TYPE >( k, m_meshData, stack.feStack );
163  stack.numRows = m_finiteElementSpace.getNumSupportPoints( stack.feStack );
164  stack.numCols = stack.numRows;
165  for( localIndex a = 0; a < stack.numRows; ++a )
166  {
167  localIndex const localNodeIndex = m_elemsToNodes( k, a );
168 
169  for( int i=0; i<3; ++i )
170  {
171  stack.xLocal[ a ][ i ] = m_X[ localNodeIndex ][ i ];
172  }
173 
174  stack.primaryField_local[ a ] = m_primaryField[ localNodeIndex ];
175  stack.localRowDofIndex[a] = m_dofNumber[localNodeIndex];
176  stack.localColDofIndex[a] = m_dofNumber[localNodeIndex];
177  }
178  m_finiteElementSpace.template
179  addGradGradStabilizationMatrix< FE_TYPE, numDofPerTrialSupportPoint >( stack.feStack,
180  stack.localJacobian );
181  }
182 
187  inline
189  localIndex const q,
190  StackVariables & stack ) const
191  {
192  GEOS_UNUSED_VAR( k );
194  real64 const detJ = FE_TYPE::calcGradN( q, stack.xLocal, stack.feStack, dNdX );
195  for( localIndex a = 0; a < stack.numRows; ++a )
196  {
197  for( localIndex b = 0; b < stack.numCols; ++b )
198  {
199  stack.localJacobian[ a ][ b ] += LvArray::tensorOps::AiBi< 3 >( dNdX[a], dNdX[b] ) * detJ;
200  }
201  }
202  }
203 
212  inline
214  StackVariables & stack ) const
215  {
216  GEOS_UNUSED_VAR( k );
217  real64 maxForce = 0;
218 
219  for( localIndex a = 0; a < stack.numRows; ++a )
220  {
221  for( localIndex b = 0; b < stack.numCols; ++b )
222  {
223  stack.localResidual[ a ] += stack.localJacobian[ a ][ b ] * stack.primaryField_local[ b ];
224  }
225  }
226 
227  for( int a = 0; a < stack.numRows; ++a )
228  {
229  localIndex const dof = LvArray::integerConversion< localIndex >( stack.localRowDofIndex[ a ] - m_dofRankOffset );
230  if( dof < 0 || dof >= m_matrix.numRows() ) continue;
231  m_matrix.template addToRowBinarySearchUnsorted< parallelDeviceAtomic >( dof,
232  stack.localColDofIndex,
233  stack.localJacobian[ a ],
234  stack.numCols );
235 
236  RAJA::atomicAdd< parallelDeviceAtomic >( &m_rhs[ dof ], stack.localResidual[ a ] );
237  maxForce = fmax( maxForce, fabs( stack.localResidual[ a ] ) );
238  }
239 
240  return maxForce;
241  }
242 
243 protected:
246 
249 
250 };
251 
255  globalIndex const,
257  arrayView1d< real64 > const,
258  real64 const,
259  string const >;
260 
261 } // namespace geos
262 
264 
265 #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:258
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:283
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:179
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:87
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:84
LvArray::CRSMatrixView< T, COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
Definition: DataTypes.hpp:309
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:195
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:175
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.
real64 xLocal[maxNumTestSupportPointsPerElem][3]
C-array stack storage for element local the nodal positions.
Kernel variables allocated on the stack.
Definition: KernelBase.hpp:138