XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
grid.hpp
Go to the documentation of this file.
1 #ifndef GRID_HPP
2 #define GRID_HPP
3 
4 #include "magnetic_field.hpp"
5 #include "grid_structs.hpp"
6 #include "grid_files.hpp"
7 
8 // Grid class
9 template<class Device>
10 class Grid {
11  public:
12 
13  // Constructor from inputs sent through fortran interface
14  Grid(int ntriangle, int nnode, int nplanes, double delta_phi, int nguess, int guess_list_len, double guess_min1, double guess_min2, double guess_max1,
15  double guess_max2, double inv_guess_d1, double inv_guess_d2, int npsi_surf2, int iphi_offset, int npsi00, double psi00min, double psi00max,
16  double dpsi00, int nwall, double wedge_angle, double eq_x_psi,
17  double* psi, int* basis, Vertex* nodes, VertexMap* mapping, int* guess_list, int* guess_xtable, int* guess_count,
18 #ifdef CONVERT_GRID2
19  int* guess_list_1d, double* psi_surf2,double minval_psi_surf2, double maxval_psi_surf2,
20 #endif
21  int* wall_nodes, int* node_to_wall, int* rgn, RZPair* gx, int nrho, double rhomax, double phimax);
22 
23  // Constructor from file inputs
24  Grid(GridFiles& grid_files, const MagneticField<Device>& magnetic_field, int nplanes_in, int wedge_n_in, int iphi_offset_in, int guess_table_size, int npsi00_in, int nrho_in, double rhomax_in);
25 
26  // Default constructor
27  Grid(){}
28 
29  KOKKOS_INLINE_FUNCTION void t_coeff(const SimdVector2D &x, const Simd<int>& itr, SimdGridVec &p) const;
30 
31  KOKKOS_INLINE_FUNCTION void t_coeff_mod(const MagneticField<Device> &magnetic_field, const SimdVector2D &xy, const Simd<double>& psiin, const Simd<int>& itr, SimdGridVec &p ) const;
32 
33  KOKKOS_INLINE_FUNCTION void search_tr2( const SimdVector2D &xy, Simd<int>& itr, SimdGridVec &pout ) const;
34 
35  KOKKOS_INLINE_FUNCTION void search_tr_check_guess(const SimdVector2D &x, const Simd<int>& old_itr,Simd<int>& itr,SimdGridVec &p ) const;
36 
37 #ifdef CONVERT_GRID2
38  KOKKOS_INLINE_FUNCTION void search_ptl_1d(double psi,double &wp,int &ip) const;
39 #endif
40 
41  KOKKOS_INLINE_FUNCTION void charge_search_index(const MagneticField<Device> &magnetic_field, const SimdVector2D &x, const Simd<double>& phi, const Simd<double>& psi, SimdVector2D &xff,Simd<int>& itr, SimdGridVec &p) const;
42 
43  KOKKOS_INLINE_FUNCTION void get_wall_index(const Simd<bool>& just_left_the_grid,const SimdVector2D &x,const Simd<int>& itr, const SimdGridVec &p, Simd<int>& widx) const;
44 
45  KOKKOS_INLINE_FUNCTION void wedge_modulo_phi(Simd<double>& phi_mod) const;
46 
47  KOKKOS_INLINE_FUNCTION void check_triangle(const Simd<int>& itr,Simd<bool>& wasnt_in_triangle) const;
48 
49  void draw_ascii_grid(MagneticField<Device> magnetic_field, double rmin, double rmax, double dr, double zmin, double zmax, double dz){
50  printf("\n\n******** PLOT OF GRID ******* \n");
51  Kokkos::View<int*,HostType> save_vert("save_vert", 1+((rmax-rmin)/dr));
52  for (double zplot = zmax; zplot>=zmin; zplot-=dz){
53  printf("\n");
54  int save_num = 0;
55  int rsave_ind = -1;
56  for (double rplot = rmin; rplot<=rmax; rplot+=dr){
57  rsave_ind++;
58  SimdVector2D x;
59  x.r = rplot;
60  x.z = zplot;
61  Simd<int> itr = -1;
62 
63  Simd<double> phi = 0.001;
65  //magnetic_field.psi_bicub.interpol(x.r,x.z,0,0,psi);
66 
67  // Get itr (triangle index)
68  SimdVector2D xff; // Unused
69  SimdGridVec p; // Unused
70  charge_search_index(magnetic_field, x, phi, psi,xff,itr, p);
71  if(itr[0]!=save_num || itr[0]!=save_vert[rsave_ind]){
72  if(itr[0]<10 && itr[0]>=0) printf("%d ",itr[0]);
73  else printf("%d ",itr[0]);
74  save_num = itr[0];
75  save_vert[rsave_ind] = itr[0];
76  } else {printf(" ");}
77  }
78  }
79  }
80 
81  int ntriangle;
82  int nnode;
83  int nplanes;
84  double wedge_angle;
85  double delta_phi;
86  double inv_delta_phi;
87 
88  Kokkos::View<double*,Kokkos::LayoutRight,Device> psi;
89  Kokkos::View<int*, Kokkos::LayoutRight,Device> basis;
90  Kokkos::View<Vertex*,Kokkos::LayoutRight,Device> nodes;
91  Kokkos::View<VertexMap*,Kokkos::LayoutRight,Device> mapping;
92 
93  int nguess;
95  double guess_min1;
96  double guess_min2;
97  double guess_max1;
98  double guess_max2;
99  double inv_guess_d1;
100  double inv_guess_d2;
101  Kokkos::View<int*,Kokkos::LayoutRight,Device> guess_list;
102  Kokkos::View<int**,Kokkos::LayoutRight,Device> guess_xtable;
103  Kokkos::View<int**,Kokkos::LayoutRight,Device> guess_count;
104  Kokkos::View<int**,Kokkos::LayoutRight,Device> guess_list_1d;
105 
109  Kokkos::View<double*,Kokkos::LayoutRight,Device> psi_surf2;
110 
112  int npsi00;
113  double psi00min;
114  double psi00max;
115  double dpsi00;
116 
117  Kokkos::View<int*,Kokkos::LayoutRight,Device> rgn;
118  Kokkos::View<RZPair*,Kokkos::LayoutRight,Device> gx;
119 
120  int nwall;
121  Kokkos::View<int*,Kokkos::LayoutRight,Device> wall_nodes;
122  Kokkos::View<int*,Kokkos::LayoutRight,Device> node_to_wall;
123 
125 
126  // Gyroaverage grid information
127  int nrho;
128  double rhomax;
129  double drho;
130  double phimin;
131  double phimax;
132 };
133 
134 #include "grid.tpp"
135 #endif
KOKKOS_INLINE_FUNCTION void t_coeff(const SimdVector2D &x, const Simd< int > &itr, SimdGridVec &p) const
Definition: grid.tpp:391
double inv_delta_phi
1/delta_phi
Definition: grid.hpp:86
double guess_min1
Definition: grid.hpp:95
Kokkos::View< int **, Kokkos::LayoutRight, Device > guess_xtable
Definition: grid.hpp:102
Definition: grid_structs.hpp:33
Grid()
Definition: grid.hpp:27
int ntriangle
Number of grid triangles.
Definition: grid.hpp:81
double minval_psi_surf2
Definition: grid.hpp:107
Kokkos::View< int **, Kokkos::LayoutRight, Device > guess_count
Definition: grid.hpp:103
Definition: magnetic_field.hpp:9
Kokkos::View< int *, Kokkos::LayoutRight, Device > guess_list
Definition: grid.hpp:101
Definition: grid_files.hpp:9
Definition: grid.hpp:10
int nrho
Definition: grid.hpp:127
int nplanes
Number of planes.
Definition: grid.hpp:83
KOKKOS_INLINE_FUNCTION void search_ptl_1d(double psi, double &wp, int &ip) const
Definition: grid.tpp:454
double phimin
Definition: grid.hpp:130
Kokkos::View< double *, Kokkos::LayoutRight, Device > psi_surf2
Definition: grid.hpp:109
double wedge_angle
The size of the wedge (the model is periodic in phi, a angle of e.g. pi means half the tokamak is mod...
Definition: grid.hpp:84
int nwall
Definition: grid.hpp:120
Definition: grid_structs.hpp:28
int npsi00
Definition: grid.hpp:112
double guess_min2
Definition: grid.hpp:96
KOKKOS_INLINE_FUNCTION void search_tr_check_guess(const SimdVector2D &x, const Simd< int > &old_itr, Simd< int > &itr, SimdGridVec &p) const
Definition: grid.tpp:409
Kokkos::View< double *, Kokkos::LayoutRight, Device > psi
An array of psi coordinates.
Definition: grid.hpp:88
KOKKOS_INLINE_FUNCTION void get_wall_index(const Simd< bool > &just_left_the_grid, const SimdVector2D &x, const Simd< int > &itr, const SimdGridVec &p, Simd< int > &widx) const
Definition: grid.tpp:587
double guess_max2
Definition: grid.hpp:98
Kokkos::View< int *, Kokkos::LayoutRight, Device > rgn
Definition: grid.hpp:117
double psi00max
Definition: grid.hpp:114
Kokkos::View< int *, Kokkos::LayoutRight, Device > basis
A basis for the guesses?
Definition: grid.hpp:89
int npsi_surf2
Definition: grid.hpp:106
double inv_guess_d1
Definition: grid.hpp:99
Simd< double > z
Definition: globals.hpp:56
KOKKOS_INLINE_FUNCTION void t_coeff_mod(const MagneticField< Device > &magnetic_field, const SimdVector2D &xy, const Simd< double > &psiin, const Simd< int > &itr, SimdGridVec &p) const
Definition: grid.tpp:333
KOKKOS_INLINE_FUNCTION void wedge_modulo_phi(Simd< double > &phi_mod) const
Definition: grid.tpp:554
double phimax
Definition: grid.hpp:131
KOKKOS_INLINE_FUNCTION void search_tr2(const SimdVector2D &xy, Simd< int > &itr, SimdGridVec &pout) const
Definition: grid.tpp:259
int guess_list_len
Definition: grid.hpp:94
Definition: grid_structs.hpp:24
Definition: grid_structs.hpp:7
double rhomax
Definition: grid.hpp:128
int nguess
Definition: grid.hpp:93
Kokkos::View< int *, Kokkos::LayoutRight, Device > node_to_wall
Definition: grid.hpp:122
Simd< double > r
Definition: globals.hpp:55
Kokkos::View< int *, Kokkos::LayoutRight, Device > wall_nodes
Definition: grid.hpp:121
int iphi_offset
Definition: grid.hpp:111
Definition: magnetic_field.F90:1
double dpsi00
Definition: grid.hpp:115
void draw_ascii_grid(MagneticField< Device > magnetic_field, double rmin, double rmax, double dr, double zmin, double zmax, double dz)
Definition: grid.hpp:49
Definition: simd.hpp:18
Definition: globals.hpp:54
Kokkos::View< int **, Kokkos::LayoutRight, Device > guess_list_1d
Definition: grid.hpp:104
double psi00min
Definition: grid.hpp:113
double maxval_psi_surf2
Definition: grid.hpp:108
double inv_guess_d2
Definition: grid.hpp:100
int nnode
Number of grid nodes.
Definition: grid.hpp:82
double delta_phi
Distance between planes.
Definition: grid.hpp:85
double eps_flux_surface
The minimum difference in psi that counts as being on two different flux surfaces.
Definition: grid.hpp:124
Kokkos::View< VertexMap *, Kokkos::LayoutRight, Device > mapping
Definition: grid.hpp:91
double drho
Definition: grid.hpp:129
KOKKOS_INLINE_FUNCTION void check_triangle(const Simd< int > &itr, Simd< bool > &wasnt_in_triangle) const
Definition: grid.tpp:573
KOKKOS_INLINE_FUNCTION void charge_search_index(const MagneticField< Device > &magnetic_field, const SimdVector2D &x, const Simd< double > &phi, const Simd< double > &psi, SimdVector2D &xff, Simd< int > &itr, SimdGridVec &p) const
Definition: grid.tpp:505
Kokkos::View< Vertex *, Kokkos::LayoutRight, Device > nodes
Definition: grid.hpp:90
double guess_max1
Definition: grid.hpp:97
Kokkos::View< RZPair *, Kokkos::LayoutRight, Device > gx
Definition: grid.hpp:118