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(const MagneticField<Device>& magnetic_field, 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  // Constructor from namelist
25  Grid(NLReader::NamelistReader& nlr, const GridFiles& grid_files);
27  // Default constructor
28  Grid(){}
30  KOKKOS_INLINE_FUNCTION void t_coeff(const SimdVector2D &x, const Simd<int>& itr, SimdGridVec &p) const;
32  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;
34  KOKKOS_INLINE_FUNCTION void search_tr2( const SimdVector2D &xy, Simd<int>& itr, SimdGridVec &pout ) const;
36  KOKKOS_INLINE_FUNCTION void search_tr_check_guess(const SimdVector2D &x, const Simd<int>& old_itr,Simd<int>& itr,SimdGridVec &p ) const;
38  KOKKOS_INLINE_FUNCTION void search_ptl_1d(double psi,double &wp,int &ip) const;
40  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  KOKKOS_INLINE_FUNCTION void charge_search_index(const MagneticField<Device> &magnetic_field, const SimdVector &v, Simd<int>& itr, SimdGridVec &p) const;
44  KOKKOS_INLINE_FUNCTION void charge_search_index(const MagneticField<Device> &magnetic_field, const SimdVector &v, const Simd<double>& psi, Simd<int>& itr, SimdGridVec &p) const;
46  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;
48  KOKKOS_INLINE_FUNCTION void wedge_modulo_phi(Simd<double>& phi_mod) const;
50  KOKKOS_INLINE_FUNCTION void check_triangle(const Simd<int>& itr,Simd<bool>& wasnt_in_triangle) const;
52  KOKKOS_INLINE_FUNCTION bool node_is_inside_psi_range(const MagneticField<Device> &magnetic_field, const int node) const;
54  void draw_ascii_grid(MagneticField<Device> magnetic_field, double rmin, double rmax, double dr, double zmin, double zmax, double dz){
55  printf("\n\n******** PLOT OF GRID ******* \n");
56  Kokkos::View<int*,HostType> save_vert("save_vert", 1+((rmax-rmin)/dr));
57  for (double zplot = zmax; zplot>=zmin; zplot-=dz){
58  printf("\n");
59  int save_num = 0;
60  int rsave_ind = -1;
61  for (double rplot = rmin; rplot<=rmax; rplot+=dr){
62  rsave_ind++;
63  SimdVector v;
64  v.r = rplot;
65  v.z = zplot;
66  v.phi = 0.001;
68  // Get itr (triangle index)
69  SimdGridVec p;
70  Simd<int> itr = -1;
71  charge_search_index(magnetic_field, v, itr, p);
72  if(itr[0]!=save_num || itr[0]!=save_vert[rsave_ind]){
73  if(itr[0]<10 && itr[0]>=0) printf("%d ",itr[0]);
74  else printf("%d ",itr[0]);
75  save_num = itr[0];
76  save_vert[rsave_ind] = itr[0];
77  } else {printf(" ");}
78  }
79  }
80  }
82  int ntriangle;
83  int nnode;
84  int nplanes;
85  double wedge_angle;
86  double delta_phi;
87  double inv_delta_phi;
89  Kokkos::View<double*,Kokkos::LayoutRight,Device> psi;
90  Kokkos::View<double*,Kokkos::LayoutRight,Device> bfield;
91  Kokkos::View<int*, Kokkos::LayoutRight,Device> basis;
92  Kokkos::View<Vertex*,Kokkos::LayoutRight,Device> nodes;
93  Kokkos::View<VertexMap*,Kokkos::LayoutRight,Device> mapping;
95  int nguess;
97  double guess_min1;
98  double guess_min2;
99  double guess_max1;
100  double guess_max2;
101  double inv_guess_d1;
102  double inv_guess_d2;
103  Kokkos::View<int*,Kokkos::LayoutRight,Device> guess_list;
104  Kokkos::View<int**,Kokkos::LayoutRight,Device> guess_xtable;
105  Kokkos::View<int**,Kokkos::LayoutRight,Device> guess_count;
106  Kokkos::View<int**,Kokkos::LayoutRight,Device> guess_list_1d;
111  Kokkos::View<double*,Kokkos::LayoutRight,Device> psi_surf2;
114  int npsi00;
115  double psi00min;
116  double psi00max;
117  double dpsi00;
119  Kokkos::View<int*,Kokkos::LayoutRight,Device> rgn;
120  Kokkos::View<RZPair*,Kokkos::LayoutRight,Device> gx;
122  int nwall;
123  Kokkos::View<int*,Kokkos::LayoutRight,Device> wall_nodes;
124  Kokkos::View<int*,Kokkos::LayoutRight,Device> node_to_wall;
128  // Gyroaverage grid information
129  int nrho;
130  double rhomax;
131  double drho;
132  double phimin;
133  double phimax;
134 };
136 #include "grid.tpp"
137 #endif
KOKKOS_INLINE_FUNCTION void t_coeff(const SimdVector2D &x, const Simd< int > &itr, SimdGridVec &p) const
Definition: grid.tpp:417
double inv_delta_phi
Definition: grid.hpp:87
Simd< double > r
Definition: simd.hpp:145
double guess_min1
Definition: grid.hpp:97
Definition: simd.hpp:144
Kokkos::View< int **, Kokkos::LayoutRight, Device > guess_xtable
Definition: grid.hpp:104
Definition: grid_structs.hpp:33
Definition: grid.hpp:28
Kokkos::View< double *, Kokkos::LayoutRight, Device > bfield
Magnetic field magnitude at nodes.
Definition: grid.hpp:90
int ntriangle
Number of grid triangles.
Definition: grid.hpp:82
double minval_psi_surf2
Definition: grid.hpp:109
Kokkos::View< int **, Kokkos::LayoutRight, Device > guess_count
Definition: grid.hpp:105
Definition: NamelistReader.hpp:163
Definition: magnetic_field.hpp:9
Kokkos::View< int *, Kokkos::LayoutRight, Device > guess_list
Definition: grid.hpp:103
Definition: grid_files.hpp:15
Definition: grid.hpp:10
int nrho
Definition: grid.hpp:129
int nplanes
Number of planes.
Definition: grid.hpp:84
KOKKOS_INLINE_FUNCTION void search_ptl_1d(double psi, double &wp, int &ip) const
Definition: grid.tpp:479
double phimin
Definition: grid.hpp:132
Kokkos::View< double *, Kokkos::LayoutRight, Device > psi_surf2
Definition: grid.hpp:111
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:85
int nwall
Definition: grid.hpp:122
Definition: grid_structs.hpp:28
int npsi00
Definition: grid.hpp:114
double guess_min2
Definition: grid.hpp:98
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:435
Kokkos::View< double *, Kokkos::LayoutRight, Device > psi
An array of psi coordinates.
Definition: grid.hpp:89
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:644
double guess_max2
Definition: grid.hpp:100
Kokkos::View< int *, Kokkos::LayoutRight, Device > rgn
Definition: grid.hpp:119
double psi00max
Definition: grid.hpp:116
Kokkos::View< int *, Kokkos::LayoutRight, Device > basis
A basis for the guesses?
Definition: grid.hpp:91
int npsi_surf2
Definition: grid.hpp:108
double inv_guess_d1
Definition: grid.hpp:101
KOKKOS_INLINE_FUNCTION bool node_is_inside_psi_range(const MagneticField< Device > &magnetic_field, const int node) const
Definition: grid.tpp:705
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:355
KOKKOS_INLINE_FUNCTION void wedge_modulo_phi(Simd< double > &phi_mod) const
Definition: grid.tpp:611
Simd< double > phi
Definition: simd.hpp:147
double phimax
Definition: grid.hpp:133
KOKKOS_INLINE_FUNCTION void search_tr2(const SimdVector2D &xy, Simd< int > &itr, SimdGridVec &pout) const
Definition: grid.tpp:281
int guess_list_len
Definition: grid.hpp:96
Simd< double > z
Definition: simd.hpp:146
Definition: grid_structs.hpp:24
Definition: grid_structs.hpp:7
double rhomax
Definition: grid.hpp:130
int nguess
Definition: grid.hpp:95
Kokkos::View< int *, Kokkos::LayoutRight, Device > node_to_wall
Definition: grid.hpp:124
Kokkos::View< int *, Kokkos::LayoutRight, Device > wall_nodes
Definition: grid.hpp:123
int iphi_offset
Definition: grid.hpp:113
Definition: magnetic_field.F90:1
double dpsi00
Definition: grid.hpp:117
void draw_ascii_grid(MagneticField< Device > magnetic_field, double rmin, double rmax, double dr, double zmin, double zmax, double dz)
Definition: grid.hpp:54
Definition: simd.hpp:18
Definition: simd.hpp:139
Kokkos::View< int **, Kokkos::LayoutRight, Device > guess_list_1d
Definition: grid.hpp:106
double psi00min
Definition: grid.hpp:115
double maxval_psi_surf2
Definition: grid.hpp:110
double inv_guess_d2
Definition: grid.hpp:102
int nnode
Number of grid nodes.
Definition: grid.hpp:83
double delta_phi
Distance between planes.
Definition: grid.hpp:86
double eps_flux_surface
The minimum difference in psi that counts as being on two different flux surfaces.
Definition: grid.hpp:126
Kokkos::View< VertexMap *, Kokkos::LayoutRight, Device > mapping
Definition: grid.hpp:93
double drho
Definition: grid.hpp:131
KOKKOS_INLINE_FUNCTION void check_triangle(const Simd< int > &itr, Simd< bool > &wasnt_in_triangle) const
Definition: grid.tpp:630
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:529
Kokkos::View< Vertex *, Kokkos::LayoutRight, Device > nodes
Definition: grid.hpp:92
double guess_max1
Definition: grid.hpp:99
Kokkos::View< RZPair *, Kokkos::LayoutRight, Device > gx
Definition: grid.hpp:120