XGC1
 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 #include "magnetic_equil_files.hpp"
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  // Except plane_phi
59  m.rplane.plane_phi = rplane.plane_phi;
60  m.lplane.plane_phi = lplane.plane_phi;
61  }else{
62  m.midplane = midplane.template mirror<Device2>();
63  m.rplane = rplane.template mirror<Device2>();
64  m.lplane = lplane.template mirror<Device2>();
65  }
66 
67  // Set these views to be their midplane equivalents (shallow copy)
68  m.psi = m.midplane.psi;
69  m.bfield = m.midplane.bfield;
70  m.psi_surf2 = m.midplane.psi_surf2;
71  m.wall_nodes = m.midplane.wall_nodes;
72 
73  m.volumes_and_areas = volumes_and_areas; // Doesn't require mirror view since everything is on host
74 
79 
80 #ifdef NO_FORTRAN_MODULES
81  m.gradient_matrices_h = gradient_matrices_h;
82 #endif
83  m.fsa_matrices = fsa_matrices.template mirror<Device2>();
84 
85  return m;
86  }
87 
88  void write_to_file(const DomainDecomposition<DeviceType>& pol_decomp, MagneticEquilFiles::Ptr equil_files_ptr, bool is_stellarator) const;
89 
90  KOKKOS_INLINE_FUNCTION void psi_search(double psi,double &wp,int &ip) const;
91 
92  template<PhiInterpType PIT>
93  KOKKOS_INLINE_FUNCTION void nearest_node(const SimdGridWeights<Order::One, PIT>& grid_wts, SimdGridWeights<Order::Zero, PIT>& grid_wts0) const;
94 
95  template<PhiInterpType PIT>
96  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;
97 
98  template<PhiInterpType PIT>
99  KOKKOS_INLINE_FUNCTION void get_grid_weights(const MagneticField<Device> &magnetic_field, const SimdVector &v, SimdVector2D &xff, SimdGridWeights<Order::One, 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::Zero, 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, const Simd<double>& psi_in, SimdGridWeights<Order::One, 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::Zero, PIT>& grid_wts) const;
109 
110  template<PhiInterpType PIT>
111  KOKKOS_INLINE_FUNCTION void get_grid_weights(const MagneticField<Device> &magnetic_field, const SimdVector &v, SimdGridWeights<Order::One, PIT>& grid_wts) const;
112 
113  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;
114 
115  KOKKOS_INLINE_FUNCTION void wedge_modulo_phi(Simd<double>& phi_mod) const;
116 
117  KOKKOS_INLINE_FUNCTION double wedge_modulo_phi(double phi) const;
118 
119  KOKKOS_INLINE_FUNCTION bool node_is_inside_psi_range(const MagneticField<Device> &magnetic_field, const int node) const;
120 
121  KOKKOS_INLINE_FUNCTION int get_plane_index(double phi) const;
122 
124 
125  KOKKOS_INLINE_FUNCTION int get_node_index(int triangle_index, int tri_vertex_index) const;
126 
127  KOKKOS_INLINE_FUNCTION double node_area_to_volume(const MagneticField<Device> &magnetic_field, double area, int node_index) const;
128 
129  KOKKOS_INLINE_FUNCTION void get_triangle_area_and_volume(const MagneticField<Device> &magnetic_field, int i, double& area, double& volume) const;
130 
131  KOKKOS_INLINE_FUNCTION bool node_is_in_region_1_or_2_no_wall(const int inode) const;
132 
133  KOKKOS_INLINE_FUNCTION bool node_is_in_region_2_or_3_no_wall(const int inode) const;
134 
135  KOKKOS_INLINE_FUNCTION bool node_is_in_private_region_no_wall(const int inode) const;
136 
137  KOKKOS_INLINE_FUNCTION bool node_is_in_included_region(const int inode, const bool exclude_private_region) const;
138 
139  KOKKOS_INLINE_FUNCTION bool node_is_in_region_1_or_2(const MagneticField<Device> &magnetic_field, const int inode) const;
140 
141  KOKKOS_INLINE_FUNCTION int uses_rz_basis(const int inode) const;
142 
143  KOKKOS_INLINE_FUNCTION double get_r(const int inode) const;
144 
145  KOKKOS_INLINE_FUNCTION void get_rz_coordinates(const int inode, double& r, double& z) const;
146 
147  KOKKOS_INLINE_FUNCTION void get_rz_coordinates(const Simd<int>& grid_inds, SimdVector2D& x) const;
148 
149  KOKKOS_INLINE_FUNCTION RZPair get_wall_rz(int i_wall) const;
150 
152 
153  // Planes
157 
158  int ntriangle;
159  int nnode;
160  int nplanes;
161  double wedge_angle;
162  double delta_phi;
163  double inv_delta_phi;
164  int nwall;
165 
170  Kokkos::View<double*,Kokkos::LayoutRight,Device> psi;
171  Kokkos::View<double*,Kokkos::LayoutRight,Device> bfield;
172  Kokkos::View<double*,Kokkos::LayoutRight,Device> psi_surf2;
173  Kokkos::View<int*,Kokkos::LayoutRight,Device> wall_nodes;
174 
175  // Volume- and Area-related Host Views. Should find a different location for these so that these unused views aren't sent to GPU
177 
178  // Projections - reside in host memory for now
183 
184 
185 #ifdef NO_FORTRAN_MODULES
186  GradientMatrices<HostType> gradient_matrices_h;
187 #endif
189 };
190 
191 #include "grid.tpp"
192 #endif
double inv_delta_phi
1/delta_phi
Definition: grid.hpp:163
VolumesAndAreas volumes_and_areas
Definition: grid.hpp:176
KOKKOS_INLINE_FUNCTION RZPair get_wall_rz(int i_wall) const
Definition: grid.tpp:294
Definition: simd.hpp:149
Grid()
Definition: grid.hpp:32
Definition: gradient_matrices.hpp:9
bool axisymmetric
Definition: grid.hpp:151
Definition: grid_weights.hpp:73
Kokkos::View< double *, Kokkos::LayoutRight, Device > bfield
Magnetic field magnitude at nodes.
Definition: grid.hpp:171
int ntriangle
Number of grid triangles.
Definition: grid.hpp:158
double minval_psi_surf2
Definition: grid.hpp:167
KOKKOS_INLINE_FUNCTION bool node_is_in_private_region_no_wall(const int inode) const
Definition: grid.tpp:212
Definition: bounds.hpp:4
Definition: grid_weights.hpp:47
Definition: NamelistReader.hpp:193
Definition: magnetic_field.hpp:12
Grid< Device2 > mirror() const
Definition: grid.hpp:36
void write_to_file(const DomainDecomposition< DeviceType > &pol_decomp, MagneticEquilFiles::Ptr equil_files_ptr, bool is_stellarator) const
KOKKOS_INLINE_FUNCTION bool node_is_in_included_region(const int inode, const bool exclude_private_region) const
Definition: grid.tpp:225
Definition: grid_files.hpp:736
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:189
int nplanes
Number of planes.
Definition: grid.hpp:160
Definition: flux_surface_average.hpp:8
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:179
KOKKOS_INLINE_FUNCTION int uses_rz_basis(const int inode) const
Definition: grid.tpp:251
Kokkos::View< double *, Kokkos::LayoutRight, Device > psi_surf2
Definition: grid.hpp:172
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:161
int nwall
Definition: grid.hpp:164
Definition: grid_structs.hpp:28
Definition: volumes_and_areas.hpp:8
Kokkos::View< double *, Kokkos::LayoutRight, Device > psi
An array of psi coordinates.
Definition: grid.hpp:170
KOKKOS_INLINE_FUNCTION void get_rz_coordinates(const int inode, double &r, double &z) const
Definition: grid.tpp:284
Projection< HostType > ff_to_midplane
Definition: grid.hpp:182
int npsi_surf2
Definition: grid.hpp:166
KOKKOS_INLINE_FUNCTION int get_node_index(int triangle_index, int tri_vertex_index) const
Definition: grid.tpp:158
KOKKOS_INLINE_FUNCTION double get_r(const int inode) const
Definition: grid.tpp:263
Bounds get_local_wedge_bounds() const
Definition: grid.tpp:145
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:181
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
Projection< HostType > ff_rplane_to_neighbors
Definition: grid.hpp:180
KOKKOS_INLINE_FUNCTION double node_area_to_volume(const MagneticField< Device > &magnetic_field, double area, int node_index) const
Definition: grid.tpp:174
FluxSurfaceAverage< Device > fsa_matrices
Definition: grid.hpp:188
KOKKOS_INLINE_FUNCTION bool node_is_in_region_1_or_2_no_wall(const int inode) const
Definition: grid.tpp:202
Kokkos::View< int *, Kokkos::LayoutRight, Device > wall_nodes
Definition: grid.hpp:173
Definition: grid_weights.hpp:52
UniformRange psi00
Definition: grid.hpp:169
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:168
Plane< Device > midplane
Definition: grid.hpp:154
int nnode
Number of grid nodes.
Definition: grid.hpp:159
Plane< Device > lplane
Definition: grid.hpp:155
double delta_phi
Distance between planes.
Definition: grid.hpp:162
KOKKOS_INLINE_FUNCTION void psi_search(double psi, double &wp, int &ip) const
Definition: grid.tpp:17
Plane< Device > rplane
Definition: grid.hpp:156
KOKKOS_INLINE_FUNCTION bool node_is_in_region_1_or_2(const MagneticField< Device > &magnetic_field, const int inode) const
Definition: grid.tpp:239
std::shared_ptr< MagneticEquilFiles > Ptr
Definition: magnetic_equil_files.hpp:11
KOKKOS_INLINE_FUNCTION bool node_is_in_region_2_or_3_no_wall(const int inode) const
Definition: grid.tpp:207