XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
uniform_range.hpp
Go to the documentation of this file.
1 #ifndef UNIFORM_RANGE_HPP
2 #define UNIFORM_RANGE_HPP
3 
4 // This struct is where we need to work with a linear range of values, but think it's more efficient
5 // to recalculate values than to store them.
6 struct UniformRange{
7  int n;
8  double val_min;
9  double val_max;
10  double dval;
11 
13 
14  UniformRange(int n, double val_min, double val_max)
15  : n(n),
16  val_min(val_min),
17  val_max(val_max),
18  dval( (val_max-val_min)/(n-1) )
19  {}
20 
21  KOKKOS_INLINE_FUNCTION double get_val(int i) const{
22  return val_min + i*dval;
23  }
24 
25  KOKKOS_INLINE_FUNCTION bool is_in_bounds(double val) const{
26  return (val<=val_max && val>=val_min);
27  }
28 
29  KOKKOS_INLINE_FUNCTION int get_index(double val) const{
30  return (int)((val - val_min)/dval);
31  }
32 
33  // Generate view containing the linear grid
34  template<class Device>
35  View<double*,CLayout,Device> generate_view(const std::string& name) const{
36  // Make a local copy of *this to pass into lambda
37  auto uniform_range = *this;
38  View<double*,CLayout,Device> view(NoInit(name), n);
39 
40  Kokkos::parallel_for("generate_view", Kokkos::RangePolicy<typename Device::execution_space>( 0,n ), KOKKOS_LAMBDA( const int i){
41  view(i) = uniform_range.get_val(i);
42  });
43  Kokkos::fence();
44  return view;
45  }
46 };
47 
48 #endif
UniformRange()
Definition: uniform_range.hpp:12
KOKKOS_INLINE_FUNCTION double get_val(int i) const
Definition: uniform_range.hpp:21
KOKKOS_INLINE_FUNCTION bool is_in_bounds(double val) const
Definition: uniform_range.hpp:25
UniformRange(int n, double val_min, double val_max)
Definition: uniform_range.hpp:14
View< double *, CLayout, Device > generate_view(const std::string &name) const
Definition: uniform_range.hpp:35
double dval
Definition: uniform_range.hpp:10
double val_max
Definition: uniform_range.hpp:9
Definition: uniform_range.hpp:6
void parallel_for(const std::string name, int n_ptl, Function func, Option option, HostAoSoA aosoa_h, DeviceAoSoA aosoa_d)
Definition: streamed_parallel_for.hpp:252
double val_min
Definition: uniform_range.hpp:8
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:68
int n
Definition: uniform_range.hpp:7
KOKKOS_INLINE_FUNCTION int get_index(double val) const
Definition: uniform_range.hpp:29