All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Go to the documentation of this file.
1 #ifndef GRID_HPP
2 #define GRID_HPP
4 #include "magnetic_field.hpp"
5 #include "grid_structs.hpp"
6 #include "grid_files.hpp"
8 // Grid class
9 template<class Device>
10 class Grid {
11  public:
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  int* guess_list_1d, double* psi_surf2,double minval_psi_surf2, double maxval_psi_surf2,
19  int* wall_nodes, int* node_to_wall, int* rgn, RZPair* gx, int nrho, double rhomax, double phimax);
21  // Constructor from file inputs
22  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);
24  // Default constructor
25  Grid(){}
27  KOKKOS_INLINE_FUNCTION void t_coeff(const SimdVector2D &x, const Simd<int>& itr, SimdGridVec &p) const;
29  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;
31  KOKKOS_INLINE_FUNCTION void search_tr2( const SimdVector2D &xy, Simd<int>& itr, SimdGridVec &pout ) const;
33  KOKKOS_INLINE_FUNCTION void search_tr_check_guess(const SimdVector2D &x, const Simd<int>& old_itr,Simd<int>& itr,SimdGridVec &p ) const;
35  KOKKOS_INLINE_FUNCTION void search_ptl_1d(double psi,double &wp,int &ip) const;
37  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;
39  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;
41  KOKKOS_INLINE_FUNCTION void wedge_modulo_phi(Simd<double>& phi_mod) const;
43  KOKKOS_INLINE_FUNCTION void check_triangle(const Simd<int>& itr,Simd<bool>& wasnt_in_triangle) const;
45  KOKKOS_INLINE_FUNCTION bool node_is_inside_psi_range(const MagneticField<Device> &magnetic_field, const int node) const;
47  void draw_ascii_grid(MagneticField<Device> magnetic_field, double rmin, double rmax, double dr, double zmin, double zmax, double dz){
48  printf("\n\n******** PLOT OF GRID ******* \n");
49  Kokkos::View<int*,HostType> save_vert("save_vert", 1+((rmax-rmin)/dr));
50  for (double zplot = zmax; zplot>=zmin; zplot-=dz){
51  printf("\n");
52  int save_num = 0;
53  int rsave_ind = -1;
54  for (double rplot = rmin; rplot<=rmax; rplot+=dr){
55  rsave_ind++;
56  SimdVector2D x;
57  x.r = rplot;
58  x.z = zplot;
59  Simd<int> itr = -1;
61  Simd<double> phi = 0.001;
63  //magnetic_field.psi_bicub.interpol(x.r,x.z,0,0,psi);
65  // Get itr (triangle index)
66  SimdVector2D xff; // Unused
67  SimdGridVec p; // Unused
68  charge_search_index(magnetic_field, x, phi, psi,xff,itr, p);
69  if(itr[0]!=save_num || itr[0]!=save_vert[rsave_ind]){
70  if(itr[0]<10 && itr[0]>=0) printf("%d ",itr[0]);
71  else printf("%d ",itr[0]);
72  save_num = itr[0];
73  save_vert[rsave_ind] = itr[0];
74  } else {printf(" ");}
75  }
76  }
77  }
79  int ntriangle;
80  int nnode;
81  int nplanes;
82  double wedge_angle;
83  double delta_phi;
84  double inv_delta_phi;
86  Kokkos::View<double*,Kokkos::LayoutRight,Device> psi;
87  Kokkos::View<int*, Kokkos::LayoutRight,Device> basis;
88  Kokkos::View<Vertex*,Kokkos::LayoutRight,Device> nodes;
89  Kokkos::View<VertexMap*,Kokkos::LayoutRight,Device> mapping;
91  int nguess;
93  double guess_min1;
94  double guess_min2;
95  double guess_max1;
96  double guess_max2;
97  double inv_guess_d1;
98  double inv_guess_d2;
99  Kokkos::View<int*,Kokkos::LayoutRight,Device> guess_list;
100  Kokkos::View<int**,Kokkos::LayoutRight,Device> guess_xtable;
101  Kokkos::View<int**,Kokkos::LayoutRight,Device> guess_count;
102  Kokkos::View<int**,Kokkos::LayoutRight,Device> guess_list_1d;
107  Kokkos::View<double*,Kokkos::LayoutRight,Device> psi_surf2;
110  int npsi00;
111  double psi00min;
112  double psi00max;
113  double dpsi00;
115  Kokkos::View<int*,Kokkos::LayoutRight,Device> rgn;
116  Kokkos::View<RZPair*,Kokkos::LayoutRight,Device> gx;
118  int nwall;
119  Kokkos::View<int*,Kokkos::LayoutRight,Device> wall_nodes;
120  Kokkos::View<int*,Kokkos::LayoutRight,Device> node_to_wall;
124  // Gyroaverage grid information
125  int nrho;
126  double rhomax;
127  double drho;
128  double phimin;
129  double phimax;
130 };
132 #include "grid.tpp"
133 #endif
KOKKOS_INLINE_FUNCTION void t_coeff(const SimdVector2D &x, const Simd< int > &itr, SimdGridVec &p) const
Definition: grid.tpp:375
double inv_delta_phi
Definition: grid.hpp:84
double guess_min1
Definition: grid.hpp:93
Kokkos::View< int **, Kokkos::LayoutRight, Device > guess_xtable
Definition: grid.hpp:100
Definition: grid_structs.hpp:33
Definition: grid.hpp:25
int ntriangle
Number of grid triangles.
Definition: grid.hpp:79
double minval_psi_surf2
Definition: grid.hpp:105
Kokkos::View< int **, Kokkos::LayoutRight, Device > guess_count
Definition: grid.hpp:101
Definition: magnetic_field.hpp:9
Kokkos::View< int *, Kokkos::LayoutRight, Device > guess_list
Definition: grid.hpp:99
Definition: grid_files.hpp:14
Definition: grid.hpp:10
int nrho
Definition: grid.hpp:125
int nplanes
Number of planes.
Definition: grid.hpp:81
KOKKOS_INLINE_FUNCTION void search_ptl_1d(double psi, double &wp, int &ip) const
Definition: grid.tpp:437
double phimin
Definition: grid.hpp:128
Kokkos::View< double *, Kokkos::LayoutRight, Device > psi_surf2
Definition: grid.hpp:107
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:82
int nwall
Definition: grid.hpp:118
Definition: grid_structs.hpp:28
int npsi00
Definition: grid.hpp:110
double guess_min2
Definition: grid.hpp:94
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:393
Kokkos::View< double *, Kokkos::LayoutRight, Device > psi
An array of psi coordinates.
Definition: grid.hpp:86
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:569
double guess_max2
Definition: grid.hpp:96
Kokkos::View< int *, Kokkos::LayoutRight, Device > rgn
Definition: grid.hpp:115
double psi00max
Definition: grid.hpp:112
Kokkos::View< int *, Kokkos::LayoutRight, Device > basis
A basis for the guesses?
Definition: grid.hpp:87
int npsi_surf2
Definition: grid.hpp:104
double inv_guess_d1
Definition: grid.hpp:97
Simd< double > z
Definition: globals.hpp:110
KOKKOS_INLINE_FUNCTION bool node_is_inside_psi_range(const MagneticField< Device > &magnetic_field, const int node) const
Definition: grid.tpp:630
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:317
KOKKOS_INLINE_FUNCTION void wedge_modulo_phi(Simd< double > &phi_mod) const
Definition: grid.tpp:536
double phimax
Definition: grid.hpp:129
KOKKOS_INLINE_FUNCTION void search_tr2(const SimdVector2D &xy, Simd< int > &itr, SimdGridVec &pout) const
Definition: grid.tpp:243
int guess_list_len
Definition: grid.hpp:92
Definition: grid_structs.hpp:24
Definition: grid_structs.hpp:7
double rhomax
Definition: grid.hpp:126
int nguess
Definition: grid.hpp:91
Kokkos::View< int *, Kokkos::LayoutRight, Device > node_to_wall
Definition: grid.hpp:120
Simd< double > r
Definition: globals.hpp:109
Kokkos::View< int *, Kokkos::LayoutRight, Device > wall_nodes
Definition: grid.hpp:119
int iphi_offset
Definition: grid.hpp:109
Definition: magnetic_field.F90:1
double dpsi00
Definition: grid.hpp:113
void draw_ascii_grid(MagneticField< Device > magnetic_field, double rmin, double rmax, double dr, double zmin, double zmax, double dz)
Definition: grid.hpp:47
Definition: simd.hpp:18
Definition: globals.hpp:108
Kokkos::View< int **, Kokkos::LayoutRight, Device > guess_list_1d
Definition: grid.hpp:102
double psi00min
Definition: grid.hpp:111
double maxval_psi_surf2
Definition: grid.hpp:106
double inv_guess_d2
Definition: grid.hpp:98
int nnode
Number of grid nodes.
Definition: grid.hpp:80
double delta_phi
Distance between planes.
Definition: grid.hpp:83
double eps_flux_surface
The minimum difference in psi that counts as being on two different flux surfaces.
Definition: grid.hpp:122
Kokkos::View< VertexMap *, Kokkos::LayoutRight, Device > mapping
Definition: grid.hpp:89
double drho
Definition: grid.hpp:127
KOKKOS_INLINE_FUNCTION void check_triangle(const Simd< int > &itr, Simd< bool > &wasnt_in_triangle) const
Definition: grid.tpp:555
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:487
Kokkos::View< Vertex *, Kokkos::LayoutRight, Device > nodes
Definition: grid.hpp:88
double guess_max1
Definition: grid.hpp:95
Kokkos::View< RZPair *, Kokkos::LayoutRight, Device > gx
Definition: grid.hpp:116