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 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 #include "ImplicitKernelBase.hpp"
16 
21 #ifndef GEOSX_FINITEELEMENT_SPARSITYKERNELBASE_HPP_
22 #define GEOSX_FINITEELEMENT_SPARSITYKERNELBASE_HPP_
23 
24 
25 
26 namespace geosx
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 
66  using Base::setup;
67 
78  SparsityKernelBase( NodeManager const & nodeManager,
79  EdgeManager const & edgeManager,
80  FaceManager const & faceManager,
81  SUBREGION_TYPE const & elementSubRegion,
82  FE_TYPE const & finiteElementSpace,
83  CONSTITUTIVE_TYPE * const inputConstitutiveType,
84  arrayView1d< globalIndex const > const & inputDofNumber,
85  globalIndex const rankOffset,
86  SparsityPattern< globalIndex > & inputSparsity ):
87  Base( nodeManager,
88  edgeManager,
89  faceManager,
90  elementSubRegion,
91  finiteElementSpace,
92  inputConstitutiveType,
93  inputDofNumber,
94  rankOffset,
95  CRSMatrixView< real64, globalIndex const >(),
96  arrayView1d< real64 >() ),
97  m_sparsity( inputSparsity )
98  {}
99 
100 
109  StackVariables & stack ) const
110  {
111  GEOSX_UNUSED_VAR( k );
112 
113  for( localIndex r=0; r<stack.numRows; ++r )
114  {
115  localIndex const row = stack.localRowDofIndex[r] - m_dofRankOffset;
116  if( row < 0 || row >= m_sparsity.numRows() ) continue;
117  for( localIndex c=0; c<stack.numCols; ++c )
118  {
119  m_sparsity.insertNonZero( row,
120  stack.localColDofIndex[c] );
121  }
122  }
123  return 0;
124  }
125 
126 
127 
140  template< typename POLICY,
141  typename KERNEL_TYPE >
142  static
143  real64
144  kernelLaunch( localIndex const numElems,
145  KERNEL_TYPE const & kernelComponent )
146  {
147  GEOSX_MARK_FUNCTION;
148 
149  // launch the kernel
150  forAll< POLICY >( numElems,
151  [=] ( localIndex const k )
152  {
153  // allocate the stack variables
154  typename KERNEL_TYPE::StackVariables stack;
155 
156  kernelComponent.setup( k, stack );
157 
158  kernelComponent.complete( k, stack );
159 
160  } );
161  return 0;
162  }
163 private:
164  SparsityPattern< globalIndex > & m_sparsity;
165 };
166 
167 
168 //*****************************************************************************
169 //*****************************************************************************
170 //*****************************************************************************
177 template< template< typename,
178  typename,
179  typename > class KERNEL_TEMPLATE >
181 {
182 
190  template< typename SUBREGION_TYPE,
191  typename CONSTITUTIVE_TYPE,
192  typename FE_TYPE >
193  using Kernel = SparsityKernelBase< SUBREGION_TYPE,
194  CONSTITUTIVE_TYPE,
195  FE_TYPE,
196  KERNEL_TEMPLATE< SUBREGION_TYPE,
197  CONSTITUTIVE_TYPE,
199  KERNEL_TEMPLATE< SUBREGION_TYPE,
200  CONSTITUTIVE_TYPE,
202  >;
203 };
204 
205 
206 //*****************************************************************************
207 //*****************************************************************************
208 //*****************************************************************************
230 template< typename REGION_TYPE,
231  template< typename SUBREGION_TYPE,
232  typename CONSTITUTIVE_TYPE,
233  typename FE_TYPE > class KERNEL_TEMPLATE >
234 static
236  arrayView1d< string const > const & targetRegions,
237  string const & discretizationName,
238  arrayView1d< globalIndex const > const & inputDofNumber,
239  globalIndex const rankOffset,
240  SparsityPattern< globalIndex > & inputSparsityPattern )
241 {
242  GEOSX_MARK_FUNCTION;
243  regionBasedKernelApplication< serialPolicy,
244  constitutive::NullModel,
245  REGION_TYPE,
247  >( mesh,
248  targetRegions,
249  discretizationName,
251  inputDofNumber,
252  rankOffset,
253  inputSparsityPattern );
254 
255  return 0;
256 }
257 
258 }
259 }
260 
261 
262 
263 #endif /* GEOSX_FINITEELEMENT_SPARSITYKERNELBASE_HPP_ */
Define the base interface for implicit finite element kernels.
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
SparsityKernelBase(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, SparsityPattern< globalIndex > &inputSparsity)
Constructor.
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:38
The NodeManager class provides an interface to ObjectManagerBase in order to manage node data...
Definition: NodeManager.hpp:47
static real64 kernelLaunch(localIndex const numElems, KERNEL_TYPE const &kernelComponent)
Kernel Launcher.
GEOSX_FORCE_INLINE real64 complete(localIndex const k, StackVariables &stack) const
Performs the complete phase for the kernel.
GEOSX_HOST_DEVICE GEOSX_FORCE_INLINE void setup(localIndex const k, StackVariables &stack) const
Performs the setup phase for the kernel.
This class serves to provide a "view" of a multidimensional array.
Definition: ArrayView.hpp:67
static constexpr int numRows
The number of rows in the element local jacobian matrix.
constexpr INDEX_TYPE_NC numRows() const
globalIndex const m_dofRankOffset
The global rank offset.
double real64
64-bit floating point type.
Definition: DataTypes.hpp:136
globalIndex localColDofIndex[numCols]
C-array storage for the element local column degrees of freedom.
static constexpr int numDofPerTestSupportPoint
Definition: KernelBase.hpp:145
This class provides an interface to ObjectManagerBase in order to manage edge data.
Definition: EdgeManager.hpp:42
Helper struct to define a specialization of #geosx::finiteElement::SparsityKernelBase that may be use...
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 GEOSX_FORCE_INLINE
Marks a function or lambda for inlining.
Definition: GeosxMacros.hpp:50
static constexpr int numCols
The number of columns in the element local jacobian matrix.
#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
bool insertNonZero(INDEX_TYPE const row, COL_TYPE const col)
Insert a non zero entry in the entry (row, col).
The FaceManager class provides an interface to ObjectManagerBase in order to manage face data...
Definition: FaceManager.hpp:40
Define the base interface for implicit finite element kernels.
globalIndex localRowDofIndex[numRows]
C-array storage for the element local row degrees of freedom.
This class provides a view into a compressed row storage matrix.