XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
guess_table.hpp
Go to the documentation of this file.
1 #ifndef GUESS_TABLE_HPP
2 #define GUESS_TABLE_HPP
3 
4 extern "C" void init_guess_table_from_cpp(int n, int list_len, int* nguess_2, double* grid_guess_min, double* grid_guess_max, double* grid_inv_guess_d, int* list, int* xtable, int* count);
5 
6 // Guess table
7 template<class Device>
8 struct GuessTable{
9  int n;
11  double inv_d1;
12  double inv_d2;
13  View<int*,CLayout,Device> list;
14  View<int**,CLayout,Device> xtable;
15  View<int**,CLayout,Device> count;
16 
18 
19  // Create a mirror with a different device type
20  template<class Device2>
21  inline GuessTable<Device2> mirror() const{
23 
24  m.n = n;
25  m.bounds = bounds;
26  m.inv_d1 = inv_d1;
27  m.inv_d2 = inv_d2;
28 
29  m.list = my_mirror_view(list, Device2());
30  mirror_copy(m.list, list);
31 
32  m.xtable = my_mirror_view(xtable, Device2());
34 
35  m.count = my_mirror_view(count, Device2());
37 
38  return m;
39  }
40 
41  GuessTable(const RZBounds& bounds_in, const View<RZPair*,CLayout,Device>& gx, const View<Vertex*,CLayout,Device>& nodes, int guess_table_size)
42  : n(guess_table_size),
43  bounds(bounds_in),
44  inv_d1(n/bounds.get_r_width()),
45  inv_d2(n/bounds.get_z_width()),
46  xtable( "guess_xtable", n,n),
47  count( "guess_count", n,n)
48  {
49 
50  if(is_rank_zero()){
51  printf("\ninit_grid: Guess min %1.15e %1.15e", bounds.min_r, bounds.min_z);
52  printf("\ninit_grid: Guess max %1.15e %1.15e", bounds.max_r, bounds.max_z);
53  }
54 
55  int ntriangle = nodes.size();
56  int nnode = gx.size();
57 
58  // Set up guess_xtable
59  int nguess_2[2];
60  nguess_2[0] = n;
61  nguess_2[1] = n;
62 
63  double grid_guess_max[2];
64  grid_guess_max[0] = bounds.max_r; grid_guess_max[1] = bounds.max_z;
65  double grid_guess_min[2];
66  grid_guess_min[0] = bounds.min_r; grid_guess_min[1] = bounds.min_z;
67 
68  // Calculated
69  double grid_guess_d = (bounds.max_r - bounds.min_r)/n;
70  double grid_inv_guess_d[2];
71  grid_inv_guess_d[0] = inv_d1; grid_inv_guess_d[1] = inv_d2;
72 
73  View<int**, HostType> guess_xtable_tmp(NoInit("guess_xtable_tmp"),n,n);
74  View<int**, HostType> guess_count_tmp(NoInit("guess_count_tmp"),n,n);
75 
76  int list_len;
77  init_guess_xtable_fort( nguess_2, grid_guess_max, grid_guess_min, grid_inv_guess_d, &ntriangle, &nnode, gx.data(),
78  nodes.data(), guess_xtable_tmp.data(), guess_count_tmp.data(), &list_len);
79 
80  // Allocate guess_list_tmp after getting length from init_guess_xtable_fort
81  View<int*, HostType> guess_list_tmp(NoInit("guess_list_tmp"),list_len);
82 
83  init_guess_list_fort( nguess_2, grid_guess_max, grid_guess_min, grid_inv_guess_d, &ntriangle, &nnode, gx.data(),
84  nodes.data(), guess_list_tmp.data(), guess_xtable_tmp.data(), guess_count_tmp.data(),&list_len);
85 
86  // Initialize list here because the list length is determined in init_guess_xtable_fort
87  list = View<int*,CLayout,Device>( "guess_list", list_len);
88 
89  Kokkos::deep_copy(xtable, guess_xtable_tmp);
90  Kokkos::deep_copy(count, guess_count_tmp);
91  Kokkos::deep_copy(list, guess_list_tmp);
92 
93 
94 #ifndef NO_FORTRAN_MODULES
95  init_guess_table_from_cpp(n, list_len, nguess_2, grid_guess_min, grid_guess_max, grid_inv_guess_d, list.data(), xtable.data(), count.data());
96 #endif
97  }
98 };
99 
100 #endif
void init_guess_table_from_cpp(int n, int list_len, int *nguess_2, double *grid_guess_min, double *grid_guess_max, double *grid_inv_guess_d, int *list, int *xtable, int *count)
bool is_rank_zero()
Definition: globals.hpp:27
double inv_d1
Definition: guess_table.hpp:11
void mirror_copy(T1 &view_dest, const T2 &view_src)
Definition: my_mirror_view.hpp:122
Definition: rz_bounds.hpp:4
void init_guess_xtable_fort(int *nguess_2, double *grid_guess_max, double *grid_guess_min, double *grid_inv_guess_d, int *ntriangle, int *nnodes, const RZPair *grid_x, Vertex *grid_nd, int *guess_xtable, int *guess_count, int *guess_list_len_in)
View< int **, CLayout, Device > count
Definition: guess_table.hpp:15
GuessTable()
Definition: guess_table.hpp:17
RZBounds bounds
Definition: guess_table.hpp:10
GuessTable(const RZBounds &bounds_in, const View< RZPair *, CLayout, Device > &gx, const View< Vertex *, CLayout, Device > &nodes, int guess_table_size)
Definition: guess_table.hpp:41
Definition: guess_table.hpp:8
int n
Definition: guess_table.hpp:9
double max_z
Definition: rz_bounds.hpp:8
double min_r
Definition: rz_bounds.hpp:5
double inv_d2
Definition: guess_table.hpp:12
void init_guess_list_fort(int *nguess_2, double *grid_guess_max, double *grid_guess_min, double *grid_inv_guess_d, int *ntriangle, int *nnodes, const RZPair *grid_x, Vertex *grid_nd, int *guess_list, int *guess_xtable, int *guess_count, int *guess_list_len_in)
View< T *, CLayout, Device > my_mirror_view(const View< T *, CLayout, Device > &view, Device nd)
Definition: my_mirror_view.hpp:14
GuessTable< Device2 > mirror() const
Definition: guess_table.hpp:21
View< int *, CLayout, Device > list
Definition: guess_table.hpp:13
double min_z
Definition: rz_bounds.hpp:7
View< int **, CLayout, Device > xtable
Definition: guess_table.hpp:14
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:69
double max_r
Definition: rz_bounds.hpp:6