XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
grid_files.hpp
Go to the documentation of this file.
1 #ifndef GRID_FILES_HPP
2 #define GRID_FILES_HPP
3 
4 #ifdef USE_MPI
5 #include "my_mpi.hpp"
6 #endif
7 #include "file_reader.hpp"
8 #include "magnetic_field.hpp"
9 #include "grid_structs.hpp"
10 #include "space_settings.hpp"
11 #include "NamelistReader.hpp"
12 
13 struct PlaneFiles{
14  // These are the regions designated in the .node file
15  enum FileRegion{
16  Inside=0,
18  };
19 
20  // Contents of .node
21  int nnodes;
22  View<RZPair*, HostType> x;
23  View<int*, HostType> rgn;
24 
25  // Contents of .ele
27  View<Vertex*, HostType> nodes;
28 
29  // Contents of .flx.aif
30  View<int*, HostType> i_x;
31 
32  int nsurfaces;
34  View<int*, HostType> i_surf_separatrices;
35  View<int*, HostType> nnodes_on_surface;
38  View<int*, HostType> non_aligned_vert;
39  View<int*, HostType> non_aligned_nsurf;
40  View<int**, CLayout, HostType> non_aligned_surf_idx;
41  View<int**, CLayout, HostType> surf_idx;
42 
43  View<double*, HostType> psiN;
44 
45  void convert_to_x_rgn_format(const View<double**, CLayout, HostType>& tmp_nodes, View<RZPair*, HostType>& x, View<int*, HostType>& rgn, bool is_stellarator);
46 
47  void convert_to_node_format(const View<int**, CLayout, HostType>& tmp_ele, View<Vertex*, HostType>& nodes);
48 
49  View<int*, HostType> pack_scalars(int max_nodes_on_surface, int n_xpts, int n_separatrices) const;
50  void unpack_scalars(const View<int*, HostType>& scalars, int& max_nodes_on_surface, int& n_xpts, int& n_separatrices);
51 
52  // Default constructor, to use to deallocate the file arrays after use
54 
55 // Should remove this USE_MPI at some point
56 #ifdef USE_MPI
57 
58  // Copy data from a PlaneFiles object on a neighboring rank
59  PlaneFiles(const MyMPI& my_mpi, const PlaneFiles& plane_files);
60 
61  // Read the files
62  PlaneFiles(const std::string& node_file, const std::string& element_file, const std::string& flx_aif_file, bool is_stellarator, const MPI_Comm& comm);
63 #endif
64 
65  // Options: hex vs circular
69  };
70 
71  void construct_hex_grid(int nshells, double raxis, double zaxis, double rscale, double zscale);
72 
73  double node_to_node_dist(RZPair a, RZPair b);
74 
75  void construct_circular_grid(int nshells, double raxis, double zaxis, double rscale, double zscale);
76 
77  static int nshells_from_nnodes(int nnodes);
78 
79  PlaneFiles(int nshells, double raxis, double zaxis, double rscale, double zscale, GridCreateOpt grid_opt=Hexagonal);
80 
82 
83  int n_specified_xpts() const;
84 
85  View<Equil::XPoint*, HostType> get_xpts() const;
86 
87  RZPair get_axis() const;
88 
90 
91  View<double*, HostType> get_psiN() const;
92 };
93 
94 struct GridFiles{
98 
99  std::vector<PlaneFiles> plane_files_vec;
100 
101  // For test grids
102  GridFiles(int nshells, double raxis, double zaxis, double rscale, double zscale, GridCreateOpt grid_opt=Hexagonal);
103 
105 
106  std::string ifile_int2str(int ifile) const;
107 
108 #ifdef USE_MPI
109  GridFiles(NLReader::NamelistReader& nlr, bool is_stellarator, const MyMPI& my_mpi);
110 #endif
111 
112  const PlaneFiles& lplane() const;
113 
114  const PlaneFiles& midplane() const;
115 
116  const PlaneFiles& rplane() const;
117 
118  int n_planes() const;
119 
120  void clear();
121 
122  static int nshells_from_nnodes(int nnodes);
123 };
124 
125 #endif
RZPair get_reference_point() const
Definition: grid_files.cpp:678
Definition: grid_files.hpp:68
FileRegion
Definition: grid_files.hpp:15
static constexpr GridCreateOpt Hexagonal
Definition: grid_files.hpp:96
View< int **, CLayout, HostType > surf_idx
Definition: grid_files.hpp:41
static constexpr GridCreateOpt Circular
Definition: grid_files.hpp:97
View< Equil::XPoint *, HostType > get_xpts() const
Definition: grid_files.cpp:663
int n_planes() const
Definition: grid_files.cpp:827
Definition: my_mpi.F90:1
PlaneFiles()
Definition: grid_files.hpp:53
View< int *, HostType > non_aligned_vert
Definition: grid_files.hpp:38
RZPair get_axis() const
Definition: grid_files.cpp:673
Definition: NamelistReader.hpp:193
Definition: magnetic_field.hpp:12
View< int *, HostType > non_aligned_nsurf
Definition: grid_files.hpp:39
int ntriangles
Definition: grid_files.hpp:26
Definition: grid_files.hpp:94
int num_non_aligned
Definition: grid_files.hpp:37
void construct_circular_grid(int nshells, double raxis, double zaxis, double rscale, double zscale)
Definition: grid_files.cpp:478
const PlaneFiles & lplane() const
Definition: grid_files.cpp:815
int nsurfaces3a
Definition: grid_files.hpp:33
View< int *, HostType > nnodes_on_surface
Definition: grid_files.hpp:35
int n_specified_xpts() const
Definition: grid_files.cpp:659
View< int *, HostType > pack_scalars(int max_nodes_on_surface, int n_xpts, int n_separatrices) const
Definition: grid_files.cpp:33
Definition: grid_files.hpp:67
GridFiles(int nshells, double raxis, double zaxis, double rscale, double zscale, GridCreateOpt grid_opt=Hexagonal)
Definition: grid_files.cpp:689
Definition: grid_structs.hpp:28
int nsurfaces2
Definition: grid_files.hpp:33
std::vector< PlaneFiles > plane_files_vec
Definition: grid_files.hpp:99
const PlaneFiles & rplane() const
Definition: grid_files.cpp:823
const PlaneFiles & midplane() const
Definition: grid_files.cpp:819
Definition: my_mpi.hpp:19
View< int *, HostType > i_x
Definition: grid_files.hpp:30
Definition: grid_files.hpp:17
std::string ifile_int2str(int ifile) const
Definition: grid_files.cpp:697
int nsurfaces1
Definition: grid_files.hpp:33
static int nshells_from_nnodes(int nnodes)
Definition: grid_files.cpp:579
void convert_to_node_format(const View< int **, CLayout, HostType > &tmp_ele, View< Vertex *, HostType > &nodes)
Definition: grid_files.cpp:24
View< double *, HostType > psiN
An array of normalized psi coordinates temporarily needed for the stellarator version.
Definition: grid_files.hpp:43
void unpack_scalars(const View< int *, HostType > &scalars, int &max_nodes_on_surface, int &n_xpts, int &n_separatrices)
Definition: grid_files.cpp:50
GridCreateOpt
Definition: grid_files.hpp:66
View< double *, HostType > get_psiN() const
Definition: grid_files.cpp:683
View< int **, CLayout, HostType > non_aligned_surf_idx
Definition: grid_files.hpp:40
int nnodes
Definition: grid_files.hpp:21
void construct_hex_grid(int nshells, double raxis, double zaxis, double rscale, double zscale)
Definition: grid_files.cpp:362
int nsurfaces3b
Definition: grid_files.hpp:33
Definition: magnetic_field.F90:1
void convert_to_x_rgn_format(const View< double **, CLayout, HostType > &tmp_nodes, View< RZPair *, HostType > &x, View< int *, HostType > &rgn, bool is_stellarator)
Definition: grid_files.cpp:15
Definition: grid_files.hpp:13
double node_to_node_dist(RZPair a, RZPair b)
Definition: grid_files.cpp:465
void clear()
Definition: grid_files.cpp:831
View< int *, HostType > rgn
Definition: grid_files.hpp:23
int nsurfaces
Definition: grid_files.hpp:32
View< RZPair *, HostType > x
Definition: grid_files.hpp:22
static int nshells_from_nnodes(int nnodes)
Definition: grid_files.cpp:836
Definition: grid_files.hpp:16
View< int *, HostType > i_surf_separatrices
Definition: grid_files.hpp:34
View< Vertex *, HostType > nodes
Definition: grid_files.hpp:27
int sum_nnodes_on_surfaces
Definition: grid_files.hpp:36