XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
guess_list_1d.hpp
Go to the documentation of this file.
1 #ifndef GUESS_LIST_1D_HPP
2 #define GUESS_LIST_1D_HPP
3 
4 #include "my_mirror_view.hpp"
5 
6 template<class Device>
7 struct GuessList1D{
8  View<int**,CLayout,Device> list;
9 
11 
12  GuessList1D(const UniformRange& range, const View<double*, Device>& view)
13  : list("guess_list_1D", 2, range.n)
14  {
15  // Run a binary search for each value of
16  // the uniform grid --> upper and lower
17  // index on the non-uniform mesh
18  for(int i=0; i<range.n; i++){
19  double val = range.get_val(i);
20  int down=1;
21  int up=view.size();
22  int middle=down + (up-down)/2;
23  while(up-down > 1){
24  if (val >= view(middle-1)){
25  down = middle;
26  }else{
27  up = middle;
28  }
29  middle = down + (up-down)/2;
30  }
31 
32  list(0,i)=down;
33  list(1,i)=up;
34 
35  if (val < view(down-1) || val > view(up-1)){
36  list(0,i) = -1;
37  list(1,i) = -1;
38  }
39  }
40 
41  for(int i=0; i<(range.n-1); i++){
42  // Correct the upper bound to make sure that
43  // upper and lower bound enclose the interval
44  // range.val_min+i*range.dval to range.val_min+(i+1)*range.dval
45  list(1, i) = list(1, i+1);
46  }
47  }
48 
49  // Create a mirror with a different device type
50  template<class Device2>
51  inline GuessList1D<Device2> mirror() const{
53 
54  m.list = my_mirror_view(list, Device2());
55  mirror_copy(m.list, list);
56 
57  return m;
58  }
59 };
60 
61 #endif
Definition: guess_list_1d.hpp:7
View< int **, CLayout, Device > list
Definition: guess_list_1d.hpp:8
void mirror_copy(T1 &view_dest, const T2 &view_src)
Definition: my_mirror_view.hpp:122
GuessList1D()
Definition: guess_list_1d.hpp:10
KOKKOS_INLINE_FUNCTION double get_val(int i) const
Definition: uniform_range.hpp:21
GuessList1D< Device2 > mirror() const
Definition: guess_list_1d.hpp:51
View< T *, CLayout, Device > my_mirror_view(const View< T *, CLayout, Device > &view, Device nd)
Definition: my_mirror_view.hpp:14
Definition: uniform_range.hpp:6
GuessList1D(const UniformRange &range, const View< double *, Device > &view)
Definition: guess_list_1d.hpp:12
int n
Definition: uniform_range.hpp:7