GEOS
SparsityKernelBase.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 #include "ImplicitKernelBase.hpp"
17 
22 #ifndef GEOS_FINITEELEMENT_SPARSITYKERNELBASE_HPP_
23 #define GEOS_FINITEELEMENT_SPARSITYKERNELBASE_HPP_
24 
25 
26 
27 namespace geos
28 {
29 
30 namespace finiteElement
31 {
32 
33 //*****************************************************************************
34 //*****************************************************************************
35 //*****************************************************************************
44 template< typename SUBREGION_TYPE,
45  typename CONSTITUTIVE_TYPE,
46  typename FE_TYPE,
47  int NUM_DOF_PER_TEST_SP,
48  int NUM_DOF_PER_TRIAL_SP >
49 class SparsityKernelBase : public ImplicitKernelBase< SUBREGION_TYPE,
50  CONSTITUTIVE_TYPE,
51  FE_TYPE,
52  NUM_DOF_PER_TEST_SP,
53  NUM_DOF_PER_TRIAL_SP >
54 {
55 public:
57  using Base = ImplicitKernelBase< SUBREGION_TYPE,
58  CONSTITUTIVE_TYPE,
59  FE_TYPE,
60  NUM_DOF_PER_TEST_SP,
61  NUM_DOF_PER_TRIAL_SP >;
62 
63 
64  using typename Base::StackVariables;
66  using Base::m_dt;
67 
68  using Base::setup;
69 
82  SparsityKernelBase( NodeManager const & nodeManager,
83  EdgeManager const & edgeManager,
84  FaceManager const & faceManager,
85  localIndex const targetRegionIndex,
86  SUBREGION_TYPE const & elementSubRegion,
87  FE_TYPE const & finiteElementSpace,
88  CONSTITUTIVE_TYPE & inputConstitutiveType,
89  arrayView1d< globalIndex const > const & inputDofNumber,
90  globalIndex const rankOffset,
91  real64 const inputDt,
92  SparsityPattern< globalIndex > & inputSparsity ):
93  Base( nodeManager,
94  edgeManager,
95  faceManager,
96  targetRegionIndex,
97  elementSubRegion,
98  finiteElementSpace,
99  inputConstitutiveType,
100  inputDofNumber,
101  rankOffset,
102  CRSMatrixView< real64, globalIndex const >(),
103  arrayView1d< real64 >(),
104  inputDt ),
105  m_sparsity( inputSparsity )
106  {}
107 
108 
115  inline
117  StackVariables & stack ) const
118  {
119  GEOS_UNUSED_VAR( k );
120 
121  for( localIndex r=0; r<stack.numRows; ++r )
122  {
123  localIndex const row = stack.localRowDofIndex[r] - m_dofRankOffset;
124  if( row < 0 || row >= m_sparsity.numRows() ) continue;
125  for( localIndex c=0; c<stack.numCols; ++c )
126  {
127  m_sparsity.insertNonZero( row,
128  stack.localColDofIndex[c] );
129  }
130  }
131  return 0;
132  }
133 
134 
135 
148  template< typename POLICY,
149  typename KERNEL_TYPE >
150  static
151  real64
152  kernelLaunch( localIndex const numElems,
153  KERNEL_TYPE const & kernelComponent )
154  {
156 
157  // launch the kernel
158  forAll< POLICY >( numElems,
159  [=] ( localIndex const k )
160  {
161  // allocate the stack variables
162  typename KERNEL_TYPE::StackVariables stack;
163 
164  kernelComponent.setup( k, stack );
165 
166  kernelComponent.complete( k, stack );
167 
168  } );
169  return 0;
170  }
171 private:
172  SparsityPattern< globalIndex > & m_sparsity;
173 };
174 
175 
176 //*****************************************************************************
177 //*****************************************************************************
178 //*****************************************************************************
185 template< template< typename,
186  typename,
187  typename > class KERNEL_TEMPLATE >
189 {
190 public:
191 
199  globalIndex const rankOffset,
200  SparsityPattern< globalIndex > & inputSparsityPattern ):
201  m_inputDofNumber( inputDofNumber ),
202  m_rankOffset( rankOffset ),
203  m_inputSparsityPattern( inputSparsityPattern )
204  {}
205 
220  template< typename SUBREGION_TYPE, typename CONSTITUTIVE_TYPE, typename FE_TYPE >
221  auto createKernel( NodeManager const & nodeManager,
222  EdgeManager const & edgeManager,
223  FaceManager const & faceManager,
224  localIndex const targetRegionIndex,
225  SUBREGION_TYPE const & elementSubRegion,
226  FE_TYPE const & finiteElementSpace,
227  CONSTITUTIVE_TYPE & inputConstitutiveType )
228  {
229  using Kernel = KERNEL_TEMPLATE< SUBREGION_TYPE, CONSTITUTIVE_TYPE, FE_TYPE >;
230 
231  return SparsityKernelBase< SUBREGION_TYPE,
232  CONSTITUTIVE_TYPE,
233  FE_TYPE,
234  Kernel::numDofPerTestSupportPoint,
235  Kernel::numDofPerTrialSupportPoint >( nodeManager,
236  edgeManager,
237  faceManager,
238  targetRegionIndex,
239  elementSubRegion,
240  finiteElementSpace,
241  inputConstitutiveType,
242  m_inputDofNumber,
243  m_rankOffset,
244  0.0, //dt but not needed
245  m_inputSparsityPattern );
246  }
247 
248 private:
250  arrayView1d< globalIndex const > const & m_inputDofNumber;
252  globalIndex const m_rankOffset;
254  SparsityPattern< globalIndex > & m_inputSparsityPattern;
255 };
256 
257 //*****************************************************************************
258 //*****************************************************************************
259 //*****************************************************************************
281 template< typename REGION_TYPE,
282  template< typename SUBREGION_TYPE,
283  typename CONSTITUTIVE_TYPE,
284  typename FE_TYPE > class KERNEL_TEMPLATE >
285 static
287  arrayView1d< string const > const & targetRegions,
288  string const & discretizationName,
289  arrayView1d< globalIndex const > const & inputDofNumber,
290  globalIndex const rankOffset,
291  SparsityPattern< globalIndex > & inputSparsityPattern )
292 {
294 
295  SparsityKernelFactory< KERNEL_TEMPLATE > KernelFactory( inputDofNumber, rankOffset, inputSparsityPattern );
296 
297  regionBasedKernelApplication< serialPolicy,
298  constitutive::NullModel,
299  REGION_TYPE >( mesh,
300  targetRegions,
301  discretizationName,
302  string(),
303  KernelFactory );
304 
305  return 0;
306 }
307 
308 }
309 }
310 
311 
312 
313 #endif /* GEOS_FINITEELEMENT_SPARSITYKERNELBASE_HPP_ */
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:84
static real64 fillSparsity(MeshLevel &mesh, arrayView1d< string const > const &targetRegions, string const &discretizationName, arrayView1d< globalIndex const > const &inputDofNumber, globalIndex const rankOffset, SparsityPattern< globalIndex > &inputSparsityPattern)
Fills matrix sparsity.
#define GEOS_MARK_FUNCTION
Mark function with both Caliper and NVTX if enabled.
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
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:42
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.
globalIndex const m_dofRankOffset
The global rank offset.
GEOS_HOST_DEVICE void setup(localIndex const k, StackVariables &stack) const
Performs the setup phase for the kernel.
Define the base interface for finite element kernels.
Definition: KernelBase.hpp:87
Used to forward arguments to a class that implements the KernelBase interface.
Definition: KernelBase.hpp:282
Define the base interface for implicit finite element kernels.
SparsityKernelBase(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, real64 const inputDt, SparsityPattern< globalIndex > &inputSparsity)
Constructor.
real64 complete(localIndex const k, StackVariables &stack) const
Performs the complete phase for the kernel.
static real64 kernelLaunch(localIndex const numElems, KERNEL_TYPE const &kernelComponent)
Kernel Launcher.
Helper struct to define a specialization of #geos::finiteElement::SparsityKernelBase that may be used...
SparsityKernelFactory(arrayView1d< globalIndex const > const &inputDofNumber, globalIndex const rankOffset, SparsityPattern< globalIndex > &inputSparsityPattern)
Constructor.
auto createKernel(NodeManager const &nodeManager, EdgeManager const &edgeManager, FaceManager const &faceManager, localIndex const targetRegionIndex, SUBREGION_TYPE const &elementSubRegion, FE_TYPE const &finiteElementSpace, CONSTITUTIVE_TYPE &inputConstitutiveType)
Return a new instance of SparsityKernelBase specialized for KERNEL_TEMPLATE.
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
std::string string
String type.
Definition: DataTypes.hpp:91
LvArray::SparsityPattern< COL_INDEX, INDEX_TYPE, LvArray::ChaiBuffer > SparsityPattern
Alias for Sparsity pattern class.
Definition: DataTypes.hpp:298
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
localIndex numCols
The actual number of columns in the element local jacobian matrix (<= maxNumCols).
globalIndex localRowDofIndex[maxNumRows]
C-array storage for the element local row degrees of freedom.
globalIndex localColDofIndex[maxNumCols]
C-array storage for the element local column degrees of freedom.
localIndex numRows
The actual number of rows in the element local jacobian matrix (<= maxNumRows).
Kernel variables allocated on the stack.
Definition: KernelBase.hpp:137