GEOS
KernelLaunchSelectors.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 TotalEnergies
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOS_PHYSICSSOLVERS_KERNELLAUNCHSELECTORS_HPP
20 #define GEOS_PHYSICSSOLVERS_KERNELLAUNCHSELECTORS_HPP
21 
22 namespace geos
23 {
24 namespace internal
25 {
26 
27 template< typename S, typename T, typename LAMBDA >
28 void invokePhaseDispatchLambda ( S val, T numPhases, LAMBDA && lambda )
29 {
30  if( numPhases == 1 )
31  {
32  lambda( val, std::integral_constant< T, 1 >());
33  return;
34  }
35  else if( numPhases == 2 )
36  {
37  lambda( val, std::integral_constant< T, 2 >());
38  return;
39  }
40  else if( numPhases == 3 )
41  {
42  lambda( val, std::integral_constant< T, 3 >());
43  return;
44  }
45  else
46  {
47  GEOS_ERROR( "Unsupported state: " << numPhases );
48  }
49 }
50 
51 template< typename S, typename T, typename LAMBDA >
52 void invokeThermalDispatchLambda ( S val, T isThermal, LAMBDA && lambda )
53 {
54  if( isThermal == 1 )
55  {
56  lambda( val, std::integral_constant< T, 1 >());
57  return;
58  }
59  else if( isThermal == 0 )
60  {
61  lambda( val, std::integral_constant< T, 0 >());
62  return;
63  }
64  else
65  {
66  GEOS_ERROR( "Unsupported state: " << isThermal );
67  }
68 }
69 
70 template< typename T, typename LAMBDA >
71 void kernelLaunchSelectorThermalSwitch( T value, LAMBDA && lambda )
72 {
73  static_assert( std::is_integral< T >::value, "kernelLaunchSelectorThermalSwitch: type should be integral" );
74 
75  switch( value )
76  {
77  case 0:
78  {
79  lambda( std::integral_constant< T, 0 >() );
80  return;
81  }
82  case 1:
83  {
84  lambda( std::integral_constant< T, 1 >() );
85  return;
86  }
87  default:
88  {
89  GEOS_ERROR( "Unsupported thermal state: " << value );
90  }
91  }
92 }
93 
94 template< typename T, typename LAMBDA >
95 void kernelLaunchSelectorCompThermSwitch( T value, bool const isThermal, LAMBDA && lambda )
96 {
97  static_assert( std::is_integral< T >::value, "kernelLaunchSelectorCompSwitch: value type should be integral" );
98 
99 
100  switch( value )
101  {
102  case 1:
103  {
104  invokeThermalDispatchLambda( std::integral_constant< T, 1 >(), isThermal, lambda ); return;
105  }
106  case 2:
107  {
108  invokeThermalDispatchLambda( std::integral_constant< T, 2 >(), isThermal, lambda );
109  return;
110  }
111  case 3:
112  {
113  invokeThermalDispatchLambda( std::integral_constant< T, 3 >(), isThermal, lambda );
114  return;
115  }
116  case 4:
117  {
118  invokeThermalDispatchLambda( std::integral_constant< T, 4 >(), isThermal, lambda );
119  return;
120  }
121  case 5:
122  {
123  invokeThermalDispatchLambda( std::integral_constant< T, 5 >(), isThermal, lambda );
124  return;
125  }
126  default:
127  {
128  GEOS_ERROR( "Unsupported number of components: " << value );
129  }
130  }
131 }
132 
133 template< typename T, typename LAMBDA >
134 void kernelLaunchSelectorCompPhaseSwitch( T value, T n_phase, LAMBDA && lambda )
135 {
136  static_assert( std::is_integral< T >::value, "kernelLaunchSelectorCompSwitch: value type should be integral" );
137  switch( value )
138  {
139  case 1:
140  {
141  invokePhaseDispatchLambda( std::integral_constant< T, 1 >(), n_phase, lambda );
142  return;
143  }
144  case 2:
145  {
146  invokePhaseDispatchLambda( std::integral_constant< T, 2 >(), n_phase, lambda );
147  return;
148  }
149  case 3:
150  {
151  invokePhaseDispatchLambda( std::integral_constant< T, 3 >(), n_phase, lambda );
152  return;
153  }
154  case 4:
155  {
156  invokePhaseDispatchLambda( std::integral_constant< T, 4 >(), n_phase, lambda );
157  return;
158  }
159  case 5:
160  {
161  invokePhaseDispatchLambda( std::integral_constant< T, 5 >(), n_phase, lambda );
162  return;
163  }
164  default:
165  { GEOS_ERROR( "Unsupported number of components: " << value ); }
166  }
167 }
168 
169 
170 } // end namspace internal
171 } // end namespace geos
172 
173 
174 #endif // GEOS_PHYSICSSOLVERS_KERNELLAUNCHSELECTORS_HPP
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:157