21 #ifndef GEOS_FINITEELEMENT_KERNELBASE_HPP_
22 #define GEOS_FINITEELEMENT_KERNELBASE_HPP_
26 #include "constitutive/ConstitutivePassThru.hpp"
27 #include "finiteElement/FiniteElementDispatch.hpp"
28 #include "mesh/MeshLevel.hpp"
29 #include "common/GEOS_RAJA_Interface.hpp"
38 #ifndef SELECTED_FE_TYPES
39 #define SELECTED_FE_TYPES BASE_FE_TYPES
84 template<
typename SUBREGION_TYPE,
85 typename CONSTITUTIVE_TYPE,
87 int NUM_DOF_PER_TEST_SP,
88 int NUM_DOF_PER_TRIAL_SP >
120 FE_TYPE
const & finiteElementSpace,
121 CONSTITUTIVE_TYPE & inputConstitutiveType ):
229 template<
typename POLICY,
230 typename KERNEL_TYPE >
234 KERNEL_TYPE
const & kernelComponent )
239 RAJA::ReduceMax< ReducePolicy< POLICY >,
real64 > maxResidual( 0 );
241 forAll< POLICY >( numElems,
244 typename KERNEL_TYPE::StackVariables stack;
246 kernelComponent.setup( k, stack );
250 kernelComponent.quadraturePointKernel( k, q, stack );
252 maxResidual.max( kernelComponent.complete( k, stack ) );
254 return maxResidual.get();
263 using KernelWrapper = decltype( std::declval< CONSTITUTIVE_TYPE const & >().createKernelUpdates() );
266 traits::ViewTypeConst< typename SUBREGION_TYPE::NodeMapType::base_type >
const m_elemsToNodes;
286 template<
template<
typename SUBREGION_TYPE,
287 typename CONSTITUTIVE_TYPE,
288 typename FE_TYPE >
class KERNEL_TYPE,
316 template<
typename SUBREGION_TYPE,
typename CONSTITUTIVE_TYPE,
typename FE_TYPE >
317 KERNEL_TYPE< SUBREGION_TYPE, CONSTITUTIVE_TYPE, FE_TYPE >
createKernel(
322 SUBREGION_TYPE
const & elementSubRegion,
323 FE_TYPE
const & finiteElementSpace,
324 CONSTITUTIVE_TYPE & inputConstitutiveType )
330 SUBREGION_TYPE
const &,
332 CONSTITUTIVE_TYPE & > standardArgs { nodeManager,
338 inputConstitutiveType };
340 auto allArgs = camp::tuple_cat_pair( standardArgs, m_args );
341 return camp::make_from_tuple< KERNEL_TYPE< SUBREGION_TYPE, CONSTITUTIVE_TYPE, FE_TYPE > >( allArgs );
346 camp::tuple< ARGS ... > m_args;
376 template<
typename POLICY,
377 typename CONSTITUTIVE_BASE,
378 typename SUBREGION_TYPE,
379 typename KERNEL_FACTORY >
383 string const & finiteElementName,
384 string const & constitutiveStringName,
385 KERNEL_FACTORY & kernelFactory )
389 real64 maxResidualContribution = 0;
398 [&constitutiveStringName,
399 &maxResidualContribution,
405 (
localIndex const targetRegionIndex,
auto & elementSubRegion )
407 localIndex const numElems = elementSubRegion.size();
411 constitutive::ConstitutiveBase * constitutiveRelation =
nullptr;
412 constitutive::NullModel * nullConstitutiveModel =
nullptr;
413 if( elementSubRegion.template hasWrapper< string >( constitutiveStringName ) )
415 string const & constitutiveName = elementSubRegion.template getReference< string >( constitutiveStringName );
416 constitutiveRelation = &elementSubRegion.getConstitutiveModel( constitutiveName );
420 nullConstitutiveModel = &elementSubRegion.template registerGroup< constitutive::NullModel >(
"nullModelGroup" );
421 constitutiveRelation = nullConstitutiveModel;
425 constitutive::ConstitutivePassThru< CONSTITUTIVE_BASE >::execute( *constitutiveRelation,
426 [&maxResidualContribution,
435 (
auto & castedConstitutiveRelation )
438 subRegionFE = elementSubRegion.template getReference< FiniteElementBase >( finiteElementName );
440 finiteElement::FiniteElementDispatchHandler< SELECTED_FE_TYPES >::dispatch3D( subRegionFE,
441 [&maxResidualContribution,
451 auto kernel = kernelFactory.createKernel( nodeManager,
457 castedConstitutiveRelation );
459 using KERNEL_TYPE = decltype( kernel );
462 maxResidualContribution =
463 std::max( maxResidualContribution,
464 KERNEL_TYPE::template kernelLaunch< POLICY, KERNEL_TYPE >( numElems, kernel ) );
469 if( nullConstitutiveModel )
471 elementSubRegion.deregisterGroup(
"nullModelGroup" );
476 return maxResidualContribution;
497 template<
typename POLICY,
498 typename DISPATCH_TYPE_LIST,
499 typename KERNEL_FACTORY >
503 string const & finiteElementName,
504 string const & constitutiveStringName,
505 KERNEL_FACTORY & kernelFactory )
509 real64 maxResidualContribution = 0;
521 [&constitutiveStringName,
522 &maxResidualContribution,
530 localIndex const numElems = elementSubRegion.size();
533 constitutive::ConstitutiveBase * constitutiveRelation =
nullptr;
534 constitutive::NullModel * nullConstitutiveModel =
nullptr;
535 if( elementSubRegion.template hasWrapper< string >( constitutiveStringName ) )
537 string const & constitutiveName = elementSubRegion.template getReference< string >( constitutiveStringName );
538 constitutiveRelation = &elementSubRegion.template getConstitutiveModel< >( constitutiveName );
542 nullConstitutiveModel = &elementSubRegion.template registerGroup< constitutive::NullModel >(
"nullModelGroup" );
543 constitutiveRelation = nullConstitutiveModel;
546 FiniteElementBase & subRegionFE = elementSubRegion.template getReference< FiniteElementBase >( finiteElementName );
548 auto kernelLaunch = [&](
auto typeCombination )
550 using SUBREGION_TYPE = camp::at_v< decltype( typeCombination ), 0 >;
551 using CONSTITUTIVE_TYPE = camp::at_v< decltype( typeCombination ), 1 >;
552 using FE_TYPE = camp::at_v< decltype( typeCombination ), 2 >;
554 SUBREGION_TYPE & castedSubRegion = dynamicCast< SUBREGION_TYPE & >( elementSubRegion );
555 CONSTITUTIVE_TYPE & castedConstitutiveRelation = dynamicCast< CONSTITUTIVE_TYPE & >( *constitutiveRelation );
556 typename FE_TYPE::ImplType & castedFiniteElement = *(dynamicCast< FE_TYPE & >( subRegionFE ).getImpl());
558 auto kernel = kernelFactory.createKernel( nodeManager,
564 castedConstitutiveRelation );
566 using KERNEL_TYPE = decltype( kernel );
569 maxResidualContribution =
570 std::max( maxResidualContribution,
571 KERNEL_TYPE::template kernelLaunch< POLICY, KERNEL_TYPE >( numElems, kernel ) );
574 types::dispatch( DISPATCH_TYPE_LIST{}, kernelLaunch, elementSubRegion, *constitutiveRelation, subRegionFE );
577 if( nullConstitutiveModel )
579 elementSubRegion.deregisterGroup(
"nullModelGroup" );
584 return maxResidualContribution;
#define GEOS_HOST_DEVICE
Marks a host-device function.
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
#define GEOS_FORCE_INLINE
Marks a function or lambda for inlining.
static real64 regionBasedKernelApplication(MeshLevel &mesh, string_array const &targetRegions, string const &finiteElementName, string const &constitutiveStringName, KERNEL_FACTORY &kernelFactory)
Performs a loop over specific regions (by type and name) and calls a kernel launch on the subregions ...
#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.
The ElementRegionManager class provides an interface to ObjectManagerBase in order to manage ElementR...
void forElementSubRegions(LAMBDA &&lambda)
This function is used to launch kernel function over the element subregions of all the subregion type...
The FaceManager class provides an interface to ObjectManagerBase in order to manage face data.
Class facilitating the representation of a multi-level discretization of a MeshBody.
NodeManager const & getNodeManager() const
Get the node manager.
FaceManager const & getFaceManager() const
Get the face manager.
ElementRegionManager const & getElemManager() const
Get the element region manager.
EdgeManager const & getEdgeManager() const
Get the edge manager.
The NodeManager class provides an interface to ObjectManagerBase in order to manage node data.
Base class for FEM element implementations.
Define the base interface for finite element kernels.
traits::ViewTypeConst< typename SUBREGION_TYPE::NodeMapType::base_type > const m_elemsToNodes
The element to nodes map.
FE_TYPE const m_finiteElementSpace
GEOS_HOST_DEVICE void setup(localIndex const k, StackVariables &stack) const
Performs the setup phase for the kernel.
static constexpr int numQuadraturePointsPerElem
Compile time value for the number of quadrature points per element.
static constexpr int numDofPerTestSupportPoint
static constexpr int numDofPerTrialSupportPoint
GEOS_HOST_DEVICE GEOS_FORCE_INLINE void quadraturePointKernel(localIndex const k, localIndex const q, StackVariables &stack) const
Performs a state update at a quadrature point.
static real64 kernelLaunch(localIndex const numElems, KERNEL_TYPE const &kernelComponent)
Kernel Launcher.
GEOS_HOST_DEVICE real64 complete(localIndex const k, StackVariables &stack) const
Performs the complete phase for the kernel.
KernelWrapper const m_constitutiveUpdate
static constexpr int maxNumTrialSupportPointsPerElem
arrayView1d< integer const > const m_elemGhostRank
The element ghost rank array.
KernelBase(SUBREGION_TYPE const &elementSubRegion, FE_TYPE const &finiteElementSpace, CONSTITUTIVE_TYPE &inputConstitutiveType)
Constructor.
static constexpr int maxNumTestSupportPointsPerElem
Used to forward arguments to a class that implements the KernelBase interface.
KERNEL_TYPE< SUBREGION_TYPE, CONSTITUTIVE_TYPE, FE_TYPE > createKernel(NodeManager &nodeManager, EdgeManager const &edgeManager, FaceManager const &faceManager, localIndex const targetRegionIndex, SUBREGION_TYPE const &elementSubRegion, FE_TYPE const &finiteElementSpace, CONSTITUTIVE_TYPE &inputConstitutiveType)
Create a new kernel with the given standard arguments.
KernelFactory(ARGS ... args)
Initialize the factory.
camp::list< Ts... > TypeList
Construct a list of types.
bool dispatch(LIST const combinations, LAMBDA &&lambda, Ts &&... objects)
Dispatch a generic worker function lambda based on runtime type.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
stdVector< string > string_array
A 1-dimensional array of geos::string types.
double real64
64-bit floating point type.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
int integer
Signed integer type.
Kernel variables allocated on the stack.