20 #ifndef GEOS_PHYSICSSOLVERS_KERNELLAUNCHSELECTORS_HPP
21 #define GEOS_PHYSICSSOLVERS_KERNELLAUNCHSELECTORS_HPP
26 #include <type_traits>
34 template<
typename S,
typename T,
typename LAMBDA >
35 void invokePhaseDispatchLambda ( S val, T numPhases, LAMBDA && lambda )
39 lambda( val, std::integral_constant< T, 1 >());
42 else if( numPhases == 2 )
44 lambda( val, std::integral_constant< T, 2 >());
47 else if( numPhases == 3 )
49 lambda( val, std::integral_constant< T, 3 >());
54 GEOS_ERROR( GEOS_FMT(
"Unsupported state: {}", numPhases ) );
58 template<
typename S,
typename T,
typename LAMBDA >
59 void invokeThermalDispatchLambda ( S val, T isThermal, LAMBDA && lambda )
63 lambda( val, std::integral_constant< T, 1 >());
66 else if( isThermal == 0 )
68 lambda( val, std::integral_constant< T, 0 >());
73 GEOS_ERROR( GEOS_FMT(
"Unsupported state: {}", isThermal ) );
77 template<
typename T,
typename LAMBDA >
78 void kernelLaunchSelectorThermalSwitch( T value, LAMBDA && lambda )
80 static_assert( std::is_integral< T >::value,
"kernelLaunchSelectorThermalSwitch: type should be integral" );
86 lambda( std::integral_constant< T, 0 >() );
91 lambda( std::integral_constant< T, 1 >() );
96 GEOS_ERROR( GEOS_FMT(
"Unsupported thermal state: {}", value ) );
105 template<
typename T,
typename LAMBDA >
106 void kernelLaunchSelectorCompSwitch( T value, LAMBDA && lambda )
108 static_assert( std::is_integral< T >::value,
"kernelLaunchSelectorCompSwitch: type should be integral" );
111 #define GEOS_DISPATCH_COMPONENT( NC ) \
113 { lambda( std::integral_constant< T, NC >() ); return; \
115 GEOS_FOR_EACH_COMPONENT( GEOS_DISPATCH_COMPONENT )
116 #undef GEOS_DISPATCH_COMPONENT
119 GEOS_ERROR( GEOS_FMT(
"Unsupported number of components: {}. This build instantiates 1 through {} (GEOS_MAX_FLUID_COMPONENTS).",
120 value, GEOS_MAX_FLUID_COMPONENTS ) );
125 template<
typename T,
typename LAMBDA >
126 void kernelLaunchSelectorCompThermSwitch( T value,
bool const isThermal, LAMBDA && lambda )
128 kernelLaunchSelectorCompSwitch( value, [&] (
auto NC )
130 invokeThermalDispatchLambda( NC, isThermal, lambda );
134 template<
typename T,
typename LAMBDA >
135 void kernelLaunchSelectorCompPhaseSwitch( T value, T n_phase, LAMBDA && lambda )
137 kernelLaunchSelectorCompSwitch( value, [&] (
auto NC )
139 invokePhaseDispatchLambda( NC, n_phase, lambda );
#define GEOS_ERROR(...)
Raise a hard error and terminate the program.