XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends 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 "bounds.hpp"
6 #include "grid_structs.hpp"
7 #include "grid_weights.hpp"
8 #include "grid_files.hpp"
9 #include "guess_table.hpp"
10 #include "uniform_range.hpp"
11 #include "guess_list_1d.hpp"
12 #include "plane.hpp"
13 #include "ff_projection.hpp"
14 #include "domain_decomposition.hpp"
15 #include "volumes_and_areas.hpp"
16 #include "flux_surface_average.hpp"
17 
18 
19 // Grid class
20 template<class Device>
21 class Grid {
22  // This line enables private access between the host and device implementations of this class
23  // i.e. Makes the copy from host to device more straightforward
24  template<class Device2> friend class Grid;
25 
26  public:
27 
28  // Constructor from namelist
30 
31  // Default constructor
32  Grid(){}
33 
34  // Create a mirror with a different device type
35  template<class Device2>
36  inline Grid<Device2> mirror() const{
37  Grid<Device2> m;
38 
40 
41  m.ntriangle = ntriangle;
42  m.nnode = nnode;
43  m.nplanes = nplanes;
45  m.delta_phi = delta_phi;
47  m.nwall = nwall;
48 
52  m.psi00 = psi00;
53 
54  if(axisymmetric){
55  m.midplane = midplane.template mirror<Device2>();
56  m.rplane = m.midplane; // Shallow copy of midplane if axisymmetric
57  m.lplane = m.midplane;
58  }else{
59  m.midplane = midplane.template mirror<Device2>();
60  m.rplane = rplane.template mirror<Device2>();
61  m.lplane = lplane.template mirror<Device2>();
62  }
63 
64  // Set these views to be their midplane equivalents (shallow copy)
65  m.psi = m.midplane.psi;
66  m.bfield = m.midplane.bfield;
67  m.psi_surf2 = m.midplane.psi_surf2;
68  m.wall_nodes = m.midplane.wall_nodes;
69 
70  m.volumes_and_areas = volumes_and_areas; // Doesn't require mirror view since everything is on host
71 
76 
77 #ifdef NO_FORTRAN_MODULES
78  m.gradient_matrices_h = gradient_matrices_h;
79 #endif
80  //m.fsa_matrices_h = fsa_matrices_h;
81 
82  return m;
83  }
84 
85  void write_to_file() const;
86 
87  KOKKOS_INLINE_FUNCTION void psi_search(double psi,double &wp,int &ip) const;
88 
89  template<PhiInterpType PIT>
90  KOKKOS_INLINE_FUNCTION void nearest_node(const SimdGridWeights<Order::One, PIT>& grid_wts, SimdGridWeights<Order::Zero, PIT>& grid_wts0) const;
91 
92  template<PhiInterpType PIT>
93  KOKKOS_INLINE_FUNCTION void get_grid_weights(const MagneticField<Device> &magnetic_field, const SimdVector &v, const Simd<double>& psi, SimdVector2D &xff,SimdGridWeights<Order::One, PIT>& grid_wts) const;
94 
95  template<PhiInterpType PIT>
96  KOKKOS_INLINE_FUNCTION void get_grid_weights(const MagneticField<Device> &magnetic_field, const SimdVector &v, SimdVector2D &xff, SimdGridWeights<Order::One, PIT>& grid_wts) const;
97 
98  template<PhiInterpType PIT>
99  KOKKOS_INLINE_FUNCTION void get_grid_weights(const MagneticField<Device> &magnetic_field, const SimdVector &v, const Simd<double>& psi_in, SimdGridWeights<Order::Zero, PIT>& grid_wts) const;
100 
101  template<PhiInterpType PIT>
102  KOKKOS_INLINE_FUNCTION void get_grid_weights(const MagneticField<Device> &magnetic_field, const SimdVector &v, const Simd<double>& psi_in, SimdGridWeights<Order::One, PIT>& grid_wts) const;
103 
104  template<PhiInterpType PIT>
105  KOKKOS_INLINE_FUNCTION void get_grid_weights(const MagneticField<Device> &magnetic_field, const SimdVector &v, SimdGridWeights<Order::Zero, PIT>& grid_wts) const;
106 
107  template<PhiInterpType PIT>
108  KOKKOS_INLINE_FUNCTION void get_grid_weights(const MagneticField<Device> &magnetic_field, const SimdVector &v, SimdGridWeights<Order::One, PIT>& grid_wts) const;
109 
110  KOKKOS_INLINE_FUNCTION void get_wall_index(const Simd<bool>& just_left_the_grid,const SimdVector2D &x, const SimdGridWeights<Order::One, PIT_GLOBAL>& grid_wts, Simd<int>& widx) const;
111 
112  KOKKOS_INLINE_FUNCTION void wedge_modulo_phi(Simd<double>& phi_mod) const;
113 
114  KOKKOS_INLINE_FUNCTION double wedge_modulo_phi(double phi) const;
115 
116  KOKKOS_INLINE_FUNCTION bool node_is_inside_psi_range(const MagneticField<Device> &magnetic_field, const int node) const;
117 
118  KOKKOS_INLINE_FUNCTION int get_plane_index(double phi) const;
119 
120  Bounds get_local_wedge_bounds(int plane_index) const;
121 
122  KOKKOS_INLINE_FUNCTION int get_node_index(int triangle_index, int tri_vertex_index) const;
123 
124  KOKKOS_INLINE_FUNCTION double node_area_to_volume(const MagneticField<Device> &magnetic_field, double area, int node_index) const;
125 
126  KOKKOS_INLINE_FUNCTION void get_triangle_area_and_volume(const MagneticField<Device> &magnetic_field, int i, double& area, double& volume) const;
127 
128  KOKKOS_INLINE_FUNCTION bool node_is_in_region_1_or_2_no_wall(const int inode) const;
129 
130  KOKKOS_INLINE_FUNCTION bool node_is_in_private_region_no_wall(const int inode) const;
131 
132  KOKKOS_INLINE_FUNCTION bool node_is_in_included_region(const int inode, const bool exclude_private_region) const;
133 
134  KOKKOS_INLINE_FUNCTION bool node_is_in_region_1_or_2(const MagneticField<Device> &magnetic_field, const int inode) const;
135 
136  KOKKOS_INLINE_FUNCTION int uses_rz_basis(const int inode) const;
137 
138  KOKKOS_INLINE_FUNCTION double get_r(const int inode) const;
139 
140  KOKKOS_INLINE_FUNCTION void get_rz_coordinates(const int inode, double& r, double& z) const;
141 
142  KOKKOS_INLINE_FUNCTION void get_rz_coordinates(const Simd<int>& grid_inds, SimdVector2D& x) const;
143 
144  KOKKOS_INLINE_FUNCTION RZPair get_wall_rz(int i_wall) const;
145 
147 
148  // Planes
152 
153  int ntriangle;
154  int nnode;
155  int nplanes;
156  double wedge_angle;
157  double delta_phi;
158  double inv_delta_phi;
159  int nwall;
160 
165  Kokkos::View<double*,Kokkos::LayoutRight,Device> psi;
166  Kokkos::View<double*,Kokkos::LayoutRight,Device> bfield;
167  Kokkos::View<double*,Kokkos::LayoutRight,Device> psi_surf2;
168  Kokkos::View<int*,Kokkos::LayoutRight,Device> wall_nodes;
169 
170  // Volume- and Area-related Host Views. Should find a different location for these so that these unused views aren't sent to GPU
172 
173  // Projections - reside in host memory for now
178 
179 
180 #ifdef NO_FORTRAN_MODULES
181  GradientMatrices<HostType> gradient_matrices_h;
182 #endif
183  //FluxSurfaceAverage<HostType> fsa_matrices_h;
184 };
185 
186 #include "grid.tpp"
187 #endif
double inv_delta_phi
1/delta_phi
Definition: grid.hpp:158
VolumesAndAreas volumes_and_areas
Definition: grid.hpp:171
KOKKOS_INLINE_FUNCTION RZPair get_wall_rz(int i_wall) const
Definition: grid.tpp:291
Definition: simd.hpp:149
Grid()
Definition: grid.hpp:32
Definition: gradient_matrices.hpp:9
bool axisymmetric
Definition: grid.hpp:146
Definition: grid_weights.hpp:73
Kokkos::View< double *, Kokkos::LayoutRight, Device > bfield
Magnetic field magnitude at nodes.
Definition: grid.hpp:166
int ntriangle
Number of grid triangles.
Definition: grid.hpp:153
double minval_psi_surf2
Definition: grid.hpp:162
KOKKOS_INLINE_FUNCTION bool node_is_in_private_region_no_wall(const int inode) const
Definition: grid.tpp:209
Definition: bounds.hpp:4
Definition: grid_weights.hpp:47
Definition: NamelistReader.hpp:193
Definition: magnetic_field.hpp:13
Grid< Device2 > mirror() const
Definition: grid.hpp:36
KOKKOS_INLINE_FUNCTION bool node_is_in_included_region(const int inode, const bool exclude_private_region) const
Definition: grid.tpp:222
Definition: grid_files.hpp:721
Definition: grid.hpp:21
KOKKOS_INLINE_FUNCTION void get_triangle_area_and_volume(const MagneticField< Device > &magnetic_field, int i, double &area, double &volume) const
Definition: grid.tpp:191
int nplanes
Number of planes.
Definition: grid.hpp:155
Definition: plane.hpp:17
KOKKOS_INLINE_FUNCTION void get_wall_index(const Simd< bool > &just_left_the_grid, const SimdVector2D &x, const SimdGridWeights< Order::One, PIT_GLOBAL > &grid_wts, Simd< int > &widx) const
Definition: grid.tpp:106
Projection< HostType > half_plane_ff
Definition: grid.hpp:174
KOKKOS_INLINE_FUNCTION int uses_rz_basis(const int inode) const
Definition: grid.tpp:248
Kokkos::View< double *, Kokkos::LayoutRight, Device > psi_surf2
Definition: grid.hpp:167
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:156
int nwall
Definition: grid.hpp:159
Definition: grid_structs.hpp:28
Definition: volumes_and_areas.hpp:14
Kokkos::View< double *, Kokkos::LayoutRight, Device > psi
An array of psi coordinates.
Definition: grid.hpp:165
KOKKOS_INLINE_FUNCTION void get_rz_coordinates(const int inode, double &r, double &z) const
Definition: grid.tpp:281
void write_to_file() const
Projection< HostType > ff_to_midplane
Definition: grid.hpp:177
int npsi_surf2
Definition: grid.hpp:161
KOKKOS_INLINE_FUNCTION int get_node_index(int triangle_index, int tri_vertex_index) const
Definition: grid.tpp:160
KOKKOS_INLINE_FUNCTION double get_r(const int inode) const
Definition: grid.tpp:260
KOKKOS_INLINE_FUNCTION bool node_is_inside_psi_range(const MagneticField< Device > &magnetic_field, const int node) const
Definition: grid.tpp:120
Projection< HostType > ff_lplane_to_neighbors
Definition: grid.hpp:176
KOKKOS_INLINE_FUNCTION void nearest_node(const SimdGridWeights< Order::One, PIT > &grid_wts, SimdGridWeights< Order::Zero, PIT > &grid_wts0) const
Definition: grid.tpp:64
KOKKOS_INLINE_FUNCTION int get_plane_index(double phi) const
Definition: grid.tpp:133
KOKKOS_INLINE_FUNCTION void wedge_modulo_phi(Simd< double > &phi_mod) const
Definition: grid.tpp:86
Bounds get_local_wedge_bounds(int plane_index) const
Definition: grid.tpp:145
Projection< HostType > ff_rplane_to_neighbors
Definition: grid.hpp:175
KOKKOS_INLINE_FUNCTION double node_area_to_volume(const MagneticField< Device > &magnetic_field, double area, int node_index) const
Definition: grid.tpp:176
KOKKOS_INLINE_FUNCTION bool node_is_in_region_1_or_2_no_wall(const int inode) const
Definition: grid.tpp:204
Kokkos::View< int *, Kokkos::LayoutRight, Device > wall_nodes
Definition: grid.hpp:168
Definition: grid_weights.hpp:52
UniformRange psi00
Definition: grid.hpp:164
Definition: magnetic_field.F90:1
Definition: simd.hpp:139
Definition: uniform_range.hpp:6
KOKKOS_INLINE_FUNCTION void get_grid_weights(const MagneticField< Device > &magnetic_field, const SimdVector &v, const Simd< double > &psi, SimdVector2D &xff, SimdGridWeights< Order::One, PIT > &grid_wts) const
Definition: grid.tpp:32
double maxval_psi_surf2
Definition: grid.hpp:163
Plane< Device > midplane
Definition: grid.hpp:149
int nnode
Number of grid nodes.
Definition: grid.hpp:154
Plane< Device > lplane
Definition: grid.hpp:150
double delta_phi
Distance between planes.
Definition: grid.hpp:157
KOKKOS_INLINE_FUNCTION void psi_search(double psi, double &wp, int &ip) const
Definition: grid.tpp:17
Plane< Device > rplane
Definition: grid.hpp:151
KOKKOS_INLINE_FUNCTION bool node_is_in_region_1_or_2(const MagneticField< Device > &magnetic_field, const int inode) const
Definition: grid.tpp:236