21 #ifndef GEOS_FINITEELEMENT_KERNELBASE_HPP_
22 #define GEOS_FINITEELEMENT_KERNELBASE_HPP_
26 #include "constitutive/ConstitutivePassThru.hpp"
27 #include "finiteElement/FiniteElementDispatch.hpp"
29 #include "common/GEOS_RAJA_Interface.hpp"
36 #ifndef SELECTED_FE_TYPES
37 #define SELECTED_FE_TYPES BASE_FE_TYPES
82 template<
typename SUBREGION_TYPE,
83 typename CONSTITUTIVE_TYPE,
85 int NUM_DOF_PER_TEST_SP,
86 int NUM_DOF_PER_TRIAL_SP >
118 FE_TYPE
const & finiteElementSpace,
119 CONSTITUTIVE_TYPE & inputConstitutiveType ):
227 template<
typename POLICY,
228 typename KERNEL_TYPE >
232 KERNEL_TYPE
const & kernelComponent )
237 RAJA::ReduceMax< ReducePolicy< POLICY >,
real64 > maxResidual( 0 );
239 forAll< POLICY >( numElems,
242 typename KERNEL_TYPE::StackVariables stack;
244 kernelComponent.setup( k, stack );
248 kernelComponent.quadraturePointKernel( k, q, stack );
250 maxResidual.max( kernelComponent.complete( k, stack ) );
252 return maxResidual.get();
258 traits::ViewTypeConst< typename SUBREGION_TYPE::NodeMapType::base_type >
const m_elemsToNodes;
278 template<
template<
typename SUBREGION_TYPE,
279 typename CONSTITUTIVE_TYPE,
280 typename FE_TYPE >
class KERNEL_TYPE,
308 template<
typename SUBREGION_TYPE,
typename CONSTITUTIVE_TYPE,
typename FE_TYPE >
309 KERNEL_TYPE< SUBREGION_TYPE, CONSTITUTIVE_TYPE, FE_TYPE >
createKernel(
314 SUBREGION_TYPE
const & elementSubRegion,
315 FE_TYPE
const & finiteElementSpace,
316 CONSTITUTIVE_TYPE & inputConstitutiveType )
322 SUBREGION_TYPE
const &,
324 CONSTITUTIVE_TYPE & > standardArgs { nodeManager,
330 inputConstitutiveType };
332 auto allArgs = camp::tuple_cat_pair( standardArgs, m_args );
333 return camp::make_from_tuple< KERNEL_TYPE< SUBREGION_TYPE, CONSTITUTIVE_TYPE, FE_TYPE > >( allArgs );
338 camp::tuple< ARGS ... > m_args;
368 template<
typename POLICY,
369 typename CONSTITUTIVE_BASE,
370 typename SUBREGION_TYPE,
371 typename KERNEL_FACTORY >
375 string const & finiteElementName,
376 string const & constitutiveStringName,
377 KERNEL_FACTORY & kernelFactory )
381 real64 maxResidualContribution = 0;
390 [&constitutiveStringName,
391 &maxResidualContribution,
397 (
localIndex const targetRegionIndex,
auto & elementSubRegion )
399 localIndex const numElems = elementSubRegion.size();
403 constitutive::ConstitutiveBase * constitutiveRelation =
nullptr;
404 constitutive::NullModel * nullConstitutiveModel =
nullptr;
405 if( elementSubRegion.template hasWrapper< string >( constitutiveStringName ) )
407 string const & constitutiveName = elementSubRegion.template getReference< string >( constitutiveStringName );
408 constitutiveRelation = &elementSubRegion.getConstitutiveModel( constitutiveName );
412 nullConstitutiveModel = &elementSubRegion.template registerGroup< constitutive::NullModel >(
"nullModelGroup" );
413 constitutiveRelation = nullConstitutiveModel;
417 constitutive::ConstitutivePassThru< CONSTITUTIVE_BASE >::execute( *constitutiveRelation,
418 [&maxResidualContribution,
427 (
auto & castedConstitutiveRelation )
430 subRegionFE = elementSubRegion.template getReference< FiniteElementBase >( finiteElementName );
432 finiteElement::FiniteElementDispatchHandler< SELECTED_FE_TYPES >::dispatch3D( subRegionFE,
433 [&maxResidualContribution,
443 auto kernel = kernelFactory.createKernel( nodeManager,
449 castedConstitutiveRelation );
451 using KERNEL_TYPE = decltype( kernel );
454 maxResidualContribution =
455 std::max( maxResidualContribution,
456 KERNEL_TYPE::template kernelLaunch< POLICY, KERNEL_TYPE >( numElems, kernel ) );
461 if( nullConstitutiveModel )
463 elementSubRegion.deregisterGroup(
"nullModelGroup" );
468 return maxResidualContribution;
489 template<
typename POLICY,
490 typename DISPATCH_TYPE_LIST,
491 typename KERNEL_FACTORY >
495 string const & finiteElementName,
496 string const & constitutiveStringName,
497 KERNEL_FACTORY & kernelFactory )
501 real64 maxResidualContribution = 0;
513 [&constitutiveStringName,
514 &maxResidualContribution,
522 localIndex const numElems = elementSubRegion.size();
525 constitutive::ConstitutiveBase * constitutiveRelation =
nullptr;
526 constitutive::NullModel * nullConstitutiveModel =
nullptr;
527 if( elementSubRegion.template hasWrapper< string >( constitutiveStringName ) )
529 string const & constitutiveName = elementSubRegion.template getReference< string >( constitutiveStringName );
530 constitutiveRelation = &elementSubRegion.template getConstitutiveModel< >( constitutiveName );
534 nullConstitutiveModel = &elementSubRegion.template registerGroup< constitutive::NullModel >(
"nullModelGroup" );
535 constitutiveRelation = nullConstitutiveModel;
538 FiniteElementBase & subRegionFE = elementSubRegion.template getReference< FiniteElementBase >( finiteElementName );
540 auto kernelLaunch = [&](
auto typeCombination )
542 using SUBREGION_TYPE = camp::at_v< decltype( typeCombination ), 0 >;
543 using CONSTITUTIVE_TYPE = camp::at_v< decltype( typeCombination ), 1 >;
544 using FE_TYPE = camp::at_v< decltype( typeCombination ), 2 >;
546 SUBREGION_TYPE & castedSubRegion = dynamicCast< SUBREGION_TYPE & >( elementSubRegion );
547 CONSTITUTIVE_TYPE & castedConstitutiveRelation = dynamicCast< CONSTITUTIVE_TYPE & >( *constitutiveRelation );
548 FE_TYPE & castedFiniteElement = dynamicCast< FE_TYPE & >( subRegionFE );
550 auto kernel = kernelFactory.createKernel( nodeManager,
556 castedConstitutiveRelation );
558 using KERNEL_TYPE = decltype( kernel );
561 maxResidualContribution =
562 std::max( maxResidualContribution,
563 KERNEL_TYPE::template kernelLaunch< POLICY, KERNEL_TYPE >( numElems, kernel ) );
566 types::dispatch( DISPATCH_TYPE_LIST{}, kernelLaunch, elementSubRegion, *constitutiveRelation, subRegionFE );
569 if( nullConstitutiveModel )
571 elementSubRegion.deregisterGroup(
"nullModelGroup" );
576 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.
static constexpr int maxNumTrialSupportPointsPerElem
arrayView1d< integer const > const m_elemGhostRank
The element ghost rank array.
CONSTITUTIVE_TYPE::KernelWrapper const m_constitutiveUpdate
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).
std::int32_t integer
Signed integer type.
Kernel variables allocated on the stack.