GEOSX
SparsityKernelBase.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 
15 #include "ImplicitKernelBase.hpp"
16 
21 #ifndef GEOS_FINITEELEMENT_SPARSITYKERNELBASE_HPP_
22 #define GEOS_FINITEELEMENT_SPARSITYKERNELBASE_HPP_
23 
24 
25 
26 namespace geos
27 {
28 
29 namespace finiteElement
30 {
31 
32 //*****************************************************************************
33 //*****************************************************************************
34 //*****************************************************************************
43 template< typename SUBREGION_TYPE,
44  typename CONSTITUTIVE_TYPE,
45  typename FE_TYPE,
46  int NUM_DOF_PER_TEST_SP,
47  int NUM_DOF_PER_TRIAL_SP >
48 class SparsityKernelBase : public ImplicitKernelBase< SUBREGION_TYPE,
49  CONSTITUTIVE_TYPE,
50  FE_TYPE,
51  NUM_DOF_PER_TEST_SP,
52  NUM_DOF_PER_TRIAL_SP >
53 {
54 public:
56  using Base = ImplicitKernelBase< SUBREGION_TYPE,
57  CONSTITUTIVE_TYPE,
58  FE_TYPE,
59  NUM_DOF_PER_TEST_SP,
60  NUM_DOF_PER_TRIAL_SP >;
61 
62 
63  using typename Base::StackVariables;
65  using Base::m_dt;
66 
67  using Base::setup;
68 
81  SparsityKernelBase( NodeManager const & nodeManager,
82  EdgeManager const & edgeManager,
83  FaceManager const & faceManager,
84  localIndex const targetRegionIndex,
85  SUBREGION_TYPE const & elementSubRegion,
86  FE_TYPE const & finiteElementSpace,
87  CONSTITUTIVE_TYPE & inputConstitutiveType,
88  arrayView1d< globalIndex const > const & inputDofNumber,
89  globalIndex const rankOffset,
90  real64 const inputDt,
91  SparsityPattern< globalIndex > & inputSparsity ):
92  Base( nodeManager,
93  edgeManager,
94  faceManager,
95  targetRegionIndex,
96  elementSubRegion,
97  finiteElementSpace,
98  inputConstitutiveType,
99  inputDofNumber,
100  rankOffset,
101  CRSMatrixView< real64, globalIndex const >(),
102  arrayView1d< real64 >(),
103  inputDt ),
104  m_sparsity( inputSparsity )
105  {}
106 
107 
114  inline
116  StackVariables & stack ) const
117  {
118  GEOS_UNUSED_VAR( k );
119 
120  for( localIndex r=0; r<stack.numRows; ++r )
121  {
122  localIndex const row = stack.localRowDofIndex[r] - m_dofRankOffset;
123  if( row < 0 || row >= m_sparsity.numRows() ) continue;
124  for( localIndex c=0; c<stack.numCols; ++c )
125  {
126  m_sparsity.insertNonZero( row,
127  stack.localColDofIndex[c] );
128  }
129  }
130  return 0;
131  }
132 
133 
134 
147  template< typename POLICY,
148  typename KERNEL_TYPE >
149  static
150  real64
151  kernelLaunch( localIndex const numElems,
152  KERNEL_TYPE const & kernelComponent )
153  {
155 
156  // launch the kernel
157  forAll< POLICY >( numElems,
158  [=] ( localIndex const k )
159  {
160  // allocate the stack variables
161  typename KERNEL_TYPE::StackVariables stack;
162 
163  kernelComponent.setup( k, stack );
164 
165  kernelComponent.complete( k, stack );
166 
167  } );
168  return 0;
169  }
170 private:
171  SparsityPattern< globalIndex > & m_sparsity;
172 };
173 
174 
175 //*****************************************************************************
176 //*****************************************************************************
177 //*****************************************************************************
184 template< template< typename,
185  typename,
186  typename > class KERNEL_TEMPLATE >
188 {
189 public:
190 
198  globalIndex const rankOffset,
199  SparsityPattern< globalIndex > & inputSparsityPattern ):
200  m_inputDofNumber( inputDofNumber ),
201  m_rankOffset( rankOffset ),
202  m_inputSparsityPattern( inputSparsityPattern )
203  {}
204 
219  template< typename SUBREGION_TYPE, typename CONSTITUTIVE_TYPE, typename FE_TYPE >
220  auto createKernel( NodeManager const & nodeManager,
221  EdgeManager const & edgeManager,
222  FaceManager const & faceManager,
223  localIndex const targetRegionIndex,
224  SUBREGION_TYPE const & elementSubRegion,
225  FE_TYPE const & finiteElementSpace,
226  CONSTITUTIVE_TYPE & inputConstitutiveType )
227  {
228  using Kernel = KERNEL_TEMPLATE< SUBREGION_TYPE, CONSTITUTIVE_TYPE, FE_TYPE >;
229 
230  return SparsityKernelBase< SUBREGION_TYPE,
231  CONSTITUTIVE_TYPE,
232  FE_TYPE,
233  Kernel::numDofPerTestSupportPoint,
234  Kernel::numDofPerTrialSupportPoint >( nodeManager,
235  edgeManager,
236  faceManager,
237  targetRegionIndex,
238  elementSubRegion,
239  finiteElementSpace,
240  inputConstitutiveType,
241  m_inputDofNumber,
242  m_rankOffset,
243  0.0, //dt but not needed
244  m_inputSparsityPattern );
245  }
246 
247 private:
249  arrayView1d< globalIndex const > const & m_inputDofNumber;
251  globalIndex const m_rankOffset;
253  SparsityPattern< globalIndex > & m_inputSparsityPattern;
254 };
255 
256 //*****************************************************************************
257 //*****************************************************************************
258 //*****************************************************************************
280 template< typename REGION_TYPE,
281  template< typename SUBREGION_TYPE,
282  typename CONSTITUTIVE_TYPE,
283  typename FE_TYPE > class KERNEL_TEMPLATE >
284 static
286  arrayView1d< string const > const & targetRegions,
287  string const & discretizationName,
288  arrayView1d< globalIndex const > const & inputDofNumber,
289  globalIndex const rankOffset,
290  SparsityPattern< globalIndex > & inputSparsityPattern )
291 {
293 
294  SparsityKernelFactory< KERNEL_TEMPLATE > KernelFactory( inputDofNumber, rankOffset, inputSparsityPattern );
295 
296  regionBasedKernelApplication< serialPolicy,
297  constitutive::NullModel,
298  REGION_TYPE >( mesh,
299  targetRegions,
300  discretizationName,
301  string(),
302  KernelFactory );
303 
304  return 0;
305 }
306 
307 }
308 }
309 
310 
311 
312 #endif /* GEOS_FINITEELEMENT_SPARSITYKERNELBASE_HPP_ */
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:83
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:42
The FaceManager class provides an interface to ObjectManagerBase in order to manage face data.
Definition: FaceManager.hpp:43
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:41
The NodeManager class provides an interface to ObjectManagerBase in order to manage node data.
Definition: NodeManager.hpp:45
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:86
Used to forward arguments to a class that implements the KernelBase interface.
Definition: KernelBase.hpp:281
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:220
LvArray::CRSMatrixView< T, COL_INDEX, localIndex const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
Definition: DataTypes.hpp:350
std::string string
String type.
Definition: DataTypes.hpp:131
LvArray::SparsityPattern< COL_INDEX, INDEX_TYPE, LvArray::ChaiBuffer > SparsityPattern
Alias for Sparsity pattern class.
Definition: DataTypes.hpp:338
double real64
64-bit floating point type.
Definition: DataTypes.hpp:139
GEOSX_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:128
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
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:136