GEOS
InterfaceKernelBase.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 
20 #ifndef GEOS_FINITEELEMENT_INTERFACEKERNELBASE_HPP_
21 #define GEOS_FINITEELEMENT_INTERFACEKERNELBASE_HPP_
22 
23 #include "ImplicitKernelBase.hpp"
24 
29 #ifndef SELECTED_FE_TYPES_2D
30 #define SELECTED_FE_TYPES_2D BASE_FE_TYPES_2D
31 #endif
32 
33 namespace geos
34 {
35 
39 namespace finiteElement
40 {
41 
54 template< typename CONSTITUTIVE_TYPE,
55  typename FE_TYPE,
56  int NUM_DOF_PER_TEST_SP,
57  int NUM_DOF_PER_TRIAL_SP >
58 class InterfaceKernelBase : public ImplicitKernelBase< FaceElementSubRegion,
59  CONSTITUTIVE_TYPE,
60  FE_TYPE,
61  NUM_DOF_PER_TEST_SP,
62  NUM_DOF_PER_TRIAL_SP >
63 {
64 public:
65 
68  CONSTITUTIVE_TYPE,
69  FE_TYPE,
70  NUM_DOF_PER_TEST_SP,
71  NUM_DOF_PER_TRIAL_SP >;
72 
73  using Base::m_dofNumber;
75  using Base::m_matrix;
76 
81  InterfaceKernelBase( NodeManager const & nodeManager,
82  EdgeManager const & edgeManager,
83  FaceManager const & faceManager,
84  localIndex const targetRegionIndex,
85  FaceElementSubRegion & elementSubRegion,
86  FE_TYPE const & finiteElementSpace,
87  CONSTITUTIVE_TYPE & inputConstitutiveType,
88  arrayView1d< globalIndex const > const inputDofNumber,
89  globalIndex const rankOffset,
91  arrayView1d< real64 > const inputRhs,
92  real64 const inputDt ):
93  Base( nodeManager,
94  edgeManager,
95  faceManager,
96  targetRegionIndex,
97  elementSubRegion,
98  finiteElementSpace,
99  inputConstitutiveType,
100  inputDofNumber,
101  rankOffset,
102  inputMatrix,
103  inputRhs,
104  inputDt )
105  {}
106 
107  //***************************************************************************
112  {};
113 
114 };
115 
122 template< template< typename CONSTITUTIVE_TYPE,
123  typename FE_TYPE > class KERNEL_TYPE,
124  typename ... ARGS >
126 {
127 public:
128 
133  InterfaceKernelFactory( ARGS ... args ):
134  m_args( args ... )
135  {}
136 
150  template< typename CONSTITUTIVE_TYPE, typename FE_TYPE >
151  KERNEL_TYPE< CONSTITUTIVE_TYPE, FE_TYPE > createKernel(
152  NodeManager & nodeManager,
153  EdgeManager const & edgeManager,
154  FaceManager const & faceManager,
155  localIndex const targetRegionIndex,
156  FaceElementSubRegion & elementSubRegion,
157  FE_TYPE const & finiteElementSpace,
158  CONSTITUTIVE_TYPE & inputConstitutiveType )
159  {
160  camp::tuple< NodeManager &,
161  EdgeManager const &,
162  FaceManager const &,
163  localIndex const,
165  FE_TYPE const &,
166  CONSTITUTIVE_TYPE & > standardArgs { nodeManager,
167  edgeManager,
168  faceManager,
169  targetRegionIndex,
170  elementSubRegion,
171  finiteElementSpace,
172  inputConstitutiveType };
173 
174  auto allArgs = camp::tuple_cat_pair( standardArgs, m_args );
175  return camp::make_from_tuple< KERNEL_TYPE< CONSTITUTIVE_TYPE, FE_TYPE > >( allArgs );
176 
177  }
178 
179 private:
181  camp::tuple< ARGS ... > m_args;
182 };
183 
184 //*****************************************************************************
185 
186 //START_interfaceBasedKernelApplication
207 template< typename POLICY,
208  typename CONSTITUTIVE_BASE,
209  typename KERNEL_FACTORY >
210 static
212  string const & targetRegionName,
213  arrayView1d< localIndex const > const & faceElementList,
214  FiniteElementBase const & subRegionFE,
215  string const & constitutiveStringName,
216  KERNEL_FACTORY & interfaceKernelFactory )
217 {
219 
220 
221  // save the maximum residual contribution for scaling residuals for convergence criteria.
222  real64 maxResidualContribution = 0;
223 
224  NodeManager & nodeManager = mesh.getNodeManager();
225  EdgeManager & edgeManager = mesh.getEdgeManager();
226  FaceManager & faceManager = mesh.getFaceManager();
227  ElementRegionManager & elementManager = mesh.getElemManager();
228 
229  SurfaceElementRegion & region = elementManager.getRegion< SurfaceElementRegion >( targetRegionName );
231  localIndex const targetRegionIndex = 0;
232 
233  // Get the constitutive model...and allocate a null constitutive model if required.
234  constitutive::ConstitutiveBase * constitutiveRelation = nullptr;
235  constitutive::NullModel * nullConstitutiveModel = nullptr;
236  if( subRegion.template hasWrapper< string >( constitutiveStringName ) )
237  {
238  string const & constitutiveName = subRegion.template getReference< string >( constitutiveStringName );
239  constitutiveRelation = &subRegion.template getConstitutiveModel( constitutiveName );
240  }
241  else
242  {
243  nullConstitutiveModel = &subRegion.template registerGroup< constitutive::NullModel >( "nullModelGroup" );
244  constitutiveRelation = nullConstitutiveModel;
245  }
246 
247  localIndex const numElems = faceElementList.size();
248 
249  // Call the constitutive dispatch which converts the type of constitutive model into a compile time constant.
250  constitutive::ConstitutivePassThru< CONSTITUTIVE_BASE >::execute( *constitutiveRelation,
251  [&maxResidualContribution,
252  &nodeManager,
253  &edgeManager,
254  &faceManager,
255  targetRegionIndex,
256  &interfaceKernelFactory,
257  &subRegion,
258  &subRegionFE,
259  numElems]
260  ( auto & castedConstitutiveRelation )
261  {
262 
263  finiteElement::FiniteElementDispatchHandler< SELECTED_FE_TYPES_2D >::dispatch2D( subRegionFE,
264  [&maxResidualContribution,
265  &nodeManager,
266  &edgeManager,
267  &faceManager,
268  targetRegionIndex,
269  &interfaceKernelFactory,
270  &subRegion,
271  numElems,
272  &castedConstitutiveRelation] ( auto const finiteElement )
273 
274  {
275  auto kernel = interfaceKernelFactory.createKernel( nodeManager,
276  edgeManager,
277  faceManager,
278  targetRegionIndex,
279  subRegion,
281  castedConstitutiveRelation );
282 
283  using KERNEL_TYPE = decltype( kernel );
284 
285  // Call the kernelLaunch function, and store the maximum contribution to the residual.
286  maxResidualContribution =
287  std::max( maxResidualContribution,
288  KERNEL_TYPE::template kernelLaunch< POLICY, KERNEL_TYPE >( numElems, kernel ) );
289 
290  } );
291  } );
292 
293  // Remove the null constitutive model (not required, but cleaner)
294  if( nullConstitutiveModel )
295  {
296  subRegion.deregisterGroup( "nullModelGroup" );
297  }
298 
299  return maxResidualContribution;
300 }
301 //END_interfaceBasedKernelApplication
302 
303 } // namespace finiteElement
304 } // namespace geos
305 
306 #endif /* GEOS_FINITEELEMENT_INTERFACEKERNELBASE_HPP_ */
static real64 interfaceBasedKernelApplication(MeshLevel &mesh, string const &targetRegionName, arrayView1d< localIndex const > const &faceElementList, FiniteElementBase const &subRegionFE, string const &constitutiveStringName, KERNEL_FACTORY &interfaceKernelFactory)
Performs a loop over FaceElementSubRegion and calls a kernel launch with compile time knowledge of su...
#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 ElementRegionManager class provides an interface to ObjectManagerBase in order to manage ElementR...
T const & getRegion(KEY_TYPE const &key) const
Get a element region.
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
NodeManager const & getNodeManager() const
Get the node manager.
Definition: MeshLevel.hpp:155
FaceManager const & getFaceManager() const
Get the face manager.
Definition: MeshLevel.hpp:194
ElementRegionManager const & getElemManager() const
Get the element region manager.
Definition: MeshLevel.hpp:207
EdgeManager const & getEdgeManager() const
Get the edge manager.
Definition: MeshLevel.hpp:181
The NodeManager class provides an interface to ObjectManagerBase in order to manage node data.
Definition: NodeManager.hpp:46
SUBREGION_TYPE & getUniqueSubRegion()
Returns the unique sub-region of type SUBREGION_TYPE for the current SurfaceElementRegion.
Base class for FEM element implementations.
Define the base interface for implicit finite element kernels.
Define the base class for interface finite element kernels. (2D finite elements belong to FaceElement...
InterfaceKernelBase(NodeManager const &nodeManager, EdgeManager const &edgeManager, FaceManager const &faceManager, localIndex const targetRegionIndex, FaceElementSubRegion &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)
Constructor.
Used to forward arguments to a class that implements the InterfaceKernelBase interface.
KERNEL_TYPE< CONSTITUTIVE_TYPE, FE_TYPE > createKernel(NodeManager &nodeManager, EdgeManager const &edgeManager, FaceManager const &faceManager, localIndex const targetRegionIndex, FaceElementSubRegion &elementSubRegion, FE_TYPE const &finiteElementSpace, CONSTITUTIVE_TYPE &inputConstitutiveType)
Create a new kernel with the given standard arguments.
InterfaceKernelFactory(ARGS ... args)
Initialize the factory.
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