GEOS
KernelLaunchSelectors.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 TotalEnergies
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_PHYSICSSOLVERS_KERNELLAUNCHSELECTORS_HPP
21 #define GEOS_PHYSICSSOLVERS_KERNELLAUNCHSELECTORS_HPP
22 
23 namespace geos
24 {
25 namespace internal
26 {
27 
28 template< typename S, typename T, typename LAMBDA >
29 void invokePhaseDispatchLambda ( S val, T numPhases, LAMBDA && lambda )
30 {
31  if( numPhases == 1 )
32  {
33  lambda( val, std::integral_constant< T, 1 >());
34  return;
35  }
36  else if( numPhases == 2 )
37  {
38  lambda( val, std::integral_constant< T, 2 >());
39  return;
40  }
41  else if( numPhases == 3 )
42  {
43  lambda( val, std::integral_constant< T, 3 >());
44  return;
45  }
46  else
47  {
48  GEOS_ERROR( "Unsupported state: " << numPhases );
49  }
50 }
51 
52 template< typename S, typename T, typename LAMBDA >
53 void invokeThermalDispatchLambda ( S val, T isThermal, LAMBDA && lambda )
54 {
55  if( isThermal == 1 )
56  {
57  lambda( val, std::integral_constant< T, 1 >());
58  return;
59  }
60  else if( isThermal == 0 )
61  {
62  lambda( val, std::integral_constant< T, 0 >());
63  return;
64  }
65  else
66  {
67  GEOS_ERROR( "Unsupported state: " << isThermal );
68  }
69 }
70 
71 template< typename T, typename LAMBDA >
72 void kernelLaunchSelectorThermalSwitch( T value, LAMBDA && lambda )
73 {
74  static_assert( std::is_integral< T >::value, "kernelLaunchSelectorThermalSwitch: type should be integral" );
75 
76  switch( value )
77  {
78  case 0:
79  {
80  lambda( std::integral_constant< T, 0 >() );
81  return;
82  }
83  case 1:
84  {
85  lambda( std::integral_constant< T, 1 >() );
86  return;
87  }
88  default:
89  {
90  GEOS_ERROR( "Unsupported thermal state: " << value );
91  }
92  }
93 }
94 
95 template< typename T, typename LAMBDA >
96 void kernelLaunchSelectorCompThermSwitch( T value, bool const isThermal, LAMBDA && lambda )
97 {
98  static_assert( std::is_integral< T >::value, "kernelLaunchSelectorCompSwitch: value type should be integral" );
99 
100 
101  switch( value )
102  {
103  case 1:
104  {
105  invokeThermalDispatchLambda( std::integral_constant< T, 1 >(), isThermal, lambda ); return;
106  }
107  case 2:
108  {
109  invokeThermalDispatchLambda( std::integral_constant< T, 2 >(), isThermal, lambda );
110  return;
111  }
112  case 3:
113  {
114  invokeThermalDispatchLambda( std::integral_constant< T, 3 >(), isThermal, lambda );
115  return;
116  }
117  case 4:
118  {
119  invokeThermalDispatchLambda( std::integral_constant< T, 4 >(), isThermal, lambda );
120  return;
121  }
122  case 5:
123  {
124  invokeThermalDispatchLambda( std::integral_constant< T, 5 >(), isThermal, lambda );
125  return;
126  }
127  default:
128  {
129  GEOS_ERROR( "Unsupported number of components: " << value );
130  }
131  }
132 }
133 
134 template< typename T, typename LAMBDA >
135 void kernelLaunchSelectorCompPhaseSwitch( T value, T n_phase, LAMBDA && lambda )
136 {
137  static_assert( std::is_integral< T >::value, "kernelLaunchSelectorCompSwitch: value type should be integral" );
138  switch( value )
139  {
140  case 1:
141  {
142  invokePhaseDispatchLambda( std::integral_constant< T, 1 >(), n_phase, lambda );
143  return;
144  }
145  case 2:
146  {
147  invokePhaseDispatchLambda( std::integral_constant< T, 2 >(), n_phase, lambda );
148  return;
149  }
150  case 3:
151  {
152  invokePhaseDispatchLambda( std::integral_constant< T, 3 >(), n_phase, lambda );
153  return;
154  }
155  case 4:
156  {
157  invokePhaseDispatchLambda( std::integral_constant< T, 4 >(), n_phase, lambda );
158  return;
159  }
160  case 5:
161  {
162  invokePhaseDispatchLambda( std::integral_constant< T, 5 >(), n_phase, lambda );
163  return;
164  }
165  default:
166  { GEOS_ERROR( "Unsupported number of components: " << value ); }
167  }
168 }
169 
170 
171 } // end namspace internal
172 } // end namespace geos
173 
174 
175 #endif // GEOS_PHYSICSSOLVERS_KERNELLAUNCHSELECTORS_HPP
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:157