20 View<RZPair*, HostType>
x;
21 View<int*, HostType>
rgn;
28 View<int*, HostType>
i_x;
42 Kokkos::parallel_for(
"transpose_x_and_rgn", Kokkos::RangePolicy<HostExSpace>(0,tmp_nodes.extent(0)), KOKKOS_LAMBDA(
const int i ){
44 x(i).r = tmp_nodes(i,1);
45 x(i).z = tmp_nodes(i,2);
46 rgn(i) = tmp_nodes(i,3);
51 Kokkos::parallel_for(
"transpose_x_and_rgn", Kokkos::RangePolicy<HostExSpace>(0,tmp_ele.extent(0)), KOKKOS_LAMBDA(
const int i ){
53 nodes(i).vertex[0] = tmp_ele(i,1);
54 nodes(i).vertex[1] = tmp_ele(i,2);
55 nodes(i).vertex[2] = tmp_ele(i,3);
63 GridFiles(
const std::string& node_file,
const std::string& element_file,
const std::string& flx_aif_file){
64 int max_nodes_on_surface;
73 file_reader.
open(node_file);
78 View<double**, CLayout, HostType> tmp_nodes(
NoInit(
"tmp_nodes"),
nnodes,4);
79 file_reader.
read(tmp_nodes.data(), tmp_nodes.size());
87 file_reader.
open(element_file);
93 file_reader.
read(tmp_ele.data(), tmp_ele.size());
104 file_reader.
open(flx_aif_file);
106 if(old_flx_aif_format){
110 i_x = View<int*, HostType>(
"i_x",0);
119 file_reader.
read(&n_xpts, 1);
120 i_x = View<int*, HostType>(
"i_x", n_xpts);
124 file_reader.
read(&i_xpt1, 1);
125 file_reader.
read(&i_xpt2, 1);
128 if(n_xpts==1 && i_xpt2 != -1)
exit_XGC(
"Error in flx.aif file: n_xpts=1, but i_xpt2 is specified.\n");
129 if(n_xpts==2 && i_xpt2 <= 0)
exit_XGC(
"Error in flx.aif file: n_xpts=2, but i_xpt2 is not specified.\n");
131 if(n_xpts>=1)
i_x(0) = i_xpt1 - 1;
132 if(n_xpts>=2)
i_x(1) = i_xpt2 - 1;
156 max_nodes_on_surface = 0;
160 surf_idx = View<int**, CLayout, HostType>(
"surf_idx",
nsurfaces, max_nodes_on_surface);
168 int should_be_negative_one;
169 file_reader.
read(&should_be_negative_one, 1);
170 if(should_be_negative_one != -1){
171 printf(
"\nExpected -1 at end of section in surface file, encountered %d instead\n", should_be_negative_one);
172 exit_XGC(
"Error reading surface file.\n");
185 if(old_flx_aif_format){
195 file_reader.
read(&should_be_negative_one, 1);
196 if(should_be_negative_one != -1){
197 printf(
"\nExpected -1 at end of the surface file, encountered %d instead\n", should_be_negative_one);
198 exit_XGC(
"Error reading surface file.\n");
206 View<int*, HostType> scalars(
"scalars", n_scalars);
210 scalars(3) = max_nodes_on_surface;
213 scalars(6) = n_separatrices;
222 MPI_Bcast(scalars.data(), scalars.size(), MPI_INT, root_rank,
SML_COMM_WORLD);
230 max_nodes_on_surface = scalars(3);
233 n_separatrices = scalars(6);
246 i_x = View<int*, HostType>(
"i_x", n_xpts);
293 enum { NE = 0,
N, NW, SW, S, SE };
296 int max_nodes_on_surface = 6*nshells;
307 for(
int ish = 1; ish<=nshells; ish++){
308 int nodes_in_shell = 6*ish;
309 int first_inner_shell_node = ish==1 ? 0 : inode - 6*(ish-1);
310 int first_node = inode;
311 int inner_shell_node = first_inner_shell_node;
313 double r_track = raxis + rscale*ish;
314 double z_track = zaxis;
315 for (
int inodesh = 0; inodesh < nodes_in_shell; inodesh++){
316 x(inode).r = r_track;
317 x(inode).z = z_track;
318 rgn(inode) = (ish==nshells? OnWall : Inside);
323 nodes(itri).vertex[0] = inner_shell_node;
324 nodes(itri).vertex[1] = inode-1;
325 nodes(itri).vertex[2] = inode;
328 nodes(itri).vertex[0] = inner_shell_node;
329 nodes(itri).vertex[1] = (inodesh == nodes_in_shell - 1) ? first_inner_shell_node : (inner_shell_node+1);
330 nodes(itri).vertex[2] = inode;
337 int hex_region = inodesh/ish;
338 double r_move, z_move;
340 {r_move = -0.5; z_move = 1.0;}
341 else if (hex_region ==
N)
342 {r_move = -1.0; z_move = 0.0;}
343 else if (hex_region == NW)
344 {r_move = -0.5; z_move = -1.0;}
345 else if (hex_region == SW)
346 {r_move = 0.5; z_move = -1.0;}
347 else if (hex_region == S)
348 {r_move = 1.0; z_move = 0.0;}
349 else if (hex_region == SE)
350 {r_move = 0.5; z_move = 1.0;}
351 r_track += rscale*r_move;
352 z_track += zscale*z_move;
357 nodes(itri).vertex[0] = first_inner_shell_node;
358 nodes(itri).vertex[1] = inode-1;
359 nodes(itri).vertex[2] = first_node;
367 nodes(i).vertex[0]++;
368 nodes(i).vertex[1]++;
369 nodes(i).vertex[2]++;
374 int n_separatrices = 0;
375 i_x = View<int*, HostType>(
"i_x", n_xpts);
390 return sqrt((a.
r-b.
r)*(a.
r-b.
r) + (a.
z-b.
z)*(a.
z-b.
z));
414 int max_nodes_on_surface = 6*nshells;
421 for(
int ish = 1; ish<=nshells; ish++){
422 int nodes_in_shell = 6*ish;
423 int nodes_in_inner_shell = ish==1 ? 1 : 6*(ish-1);
424 int first_inner_shell_node = ish==1 ? 0 : inode - 6*(ish-1);
425 int first_node = inode;
426 int inner_shell_node = first_inner_shell_node;
428 for (
int inodesh = 0; inodesh <= nodes_in_shell; inodesh++){
430 if(inodesh<nodes_in_shell){
431 double angle =
TWOPI*double(inodesh)/double(nodes_in_shell);
432 x(inode).r = raxis + ish*rscale*cos(angle);
433 x(inode).z = zaxis + ish*zscale*sin(angle);
434 rgn(inode) = (ish==nshells? OnWall : Inside);
441 int outer_node = (inodesh < nodes_in_shell) ? inode : first_node;
442 int prev_outer_node = inode-1;
445 int next_inner_shell_node = inner_shell_node+1;
446 if(next_inner_shell_node-first_inner_shell_node==nodes_in_inner_shell) next_inner_shell_node = first_inner_shell_node;
451 if(distance1>distance2 && next_inner_shell_node!=inner_shell_node){
452 if(itri>=
nodes.size()) {printf(
"\nMore elements than expected in circular grid generation. Dynamically resize?"); exit(1); }
453 nodes(itri).vertex[0] = inner_shell_node;
454 nodes(itri).vertex[1] = next_inner_shell_node;
455 nodes(itri).vertex[2] = prev_outer_node;
456 inner_shell_node = next_inner_shell_node;
460 if(itri>=
nodes.size()) {printf(
"\nMore elements than expected in circular grid generation. Dynamically resize?"); exit(1); }
461 nodes(itri).vertex[0] = inner_shell_node;
462 nodes(itri).vertex[1] = prev_outer_node;
463 nodes(itri).vertex[2] = outer_node;
467 if(inodesh<nodes_in_shell){
475 if(itri!=
nodes.size()) {printf(
"\nFewer elements than expected in circular grid generation. Dynamically resize?"); exit(1); }
479 nodes(i).vertex[0]++;
480 nodes(i).vertex[1]++;
481 nodes(i).vertex[2]++;
486 int n_separatrices = 0;
487 i_x = View<int*, HostType>(
"i_x", n_xpts);
502 if(nnodes<1)
return 0;
503 else return std::ceil(sqrt(12*nnodes - 3)/6 - 0.5);
517 :
nnodes(1 + 3*(nshells+1)*nshells),
541 :
nnodes(1 + 3*(nshells+1)*nshells),
567 double triangle_width = width/(2*nshells);
568 double triangle_height = height/(2*nshells);
572 double scale = std::min(width,height)/(2*nshells);
582 View<Equil::XPoint*, HostType> xpts(
NoInit(
"xpts"),
i_x.size());
583 for(
int i = 0; i<
i_x.size(); i++){
584 xpts(i).r =
x(
i_x(i)).r;
585 xpts(i).z =
x(
i_x(i)).z;
596 std::string node_file = nlr.
get<std::string>(
"sml_node_file",
"example_file.node");
597 std::string ele_file = nlr.
get<std::string>(
"sml_ele_file",
"example_file.ele");
598 std::string surf_file = nlr.
get<std::string>(
"sml_surf_file",
"example_file.flx.aif");
599 std::string input_file_dir = nlr.
get<std::string>(
"sml_input_file_dir",
"./");
602 node_file = input_file_dir +
"/" + node_file;
603 ele_file = input_file_dir +
"/" + ele_file;
604 surf_file = input_file_dir +
"/" + surf_file;
607 return GridFiles(node_file, ele_file, surf_file);
int nsurfaces3b
Definition: grid_files.hpp:31
int nsurfaces2
Definition: grid_files.hpp:31
void convert_to_x_rgn_format(const View< double **, CLayout, HostType > &tmp_nodes, View< RZPair *, HostType > &x, View< int *, HostType > &rgn)
Definition: grid_files.hpp:41
bool is_rank_zero()
Definition: globals.hpp:27
View< int *, HostType > non_aligned_vert
Definition: grid_files.hpp:36
MPI_Comm SML_COMM_WORLD
Definition: my_mpi.cpp:4
int num_non_aligned
Definition: grid_files.hpp:35
T get(const string ¶m, const T default_val, int val_ind=0)
Definition: NamelistReader.hpp:373
View< Vertex *, HostType > nodes
Definition: grid_files.hpp:25
void set_fortran_flx_aif_format(int is_flx_aif_format_int)
int nsurfaces
Definition: grid_files.hpp:30
Definition: NamelistReader.hpp:193
int nsurfaces1
Definition: grid_files.hpp:31
Definition: magnetic_field.hpp:12
View< int **, CLayout, HostType > surf_idx
Definition: grid_files.hpp:39
RZBounds bounds
Simulation boundary.
Definition: magnetic_field.hpp:23
Definition: grid_files.hpp:17
Equilibrium equil
The object containing information about the magnetic equilibrium.
Definition: magnetic_field.hpp:32
View< int *, HostType > non_aligned_nsurf
Definition: grid_files.hpp:37
static GridFiles grid_files_from_namelist(NLReader::NamelistReader &nlr)
Definition: grid_files.hpp:593
void read(T *var, int n)
Definition: file_reader.hpp:28
View< int *, HostType > nnodes_on_surface
Definition: grid_files.hpp:33
void construct_circular_grid(int nshells, double raxis, double zaxis, double rscale, double zscale)
Definition: grid_files.hpp:402
View< int *, HostType > rgn
Definition: grid_files.hpp:21
View< int *, HostType > i_x
Definition: grid_files.hpp:28
GridFiles(int nshells, double raxis, double zaxis, double rscale, double zscale, GridCreateOpt grid_opt=Hexagonal)
Definition: grid_files.hpp:516
double z
Definition: grid_structs.hpp:30
GridFiles()
Definition: grid_files.hpp:60
double axis_z
z coordinate of axis
Definition: equil.hpp:95
Definition: grid_structs.hpp:28
int nsurfaces3a
Definition: grid_files.hpp:31
View< RZPair *, HostType > x
Definition: grid_files.hpp:20
Definition: grid_files.hpp:274
GridFiles(MagneticField< HostType > &magnetic_field, int nshells, GridCreateOpt grid_opt=Hexagonal)
Definition: grid_files.hpp:540
View< Equil::XPoint *, HostType > get_xpts()
Definition: grid_files.hpp:581
View< int *, HostType > i_surf_separatrices
Definition: grid_files.hpp:32
int ntriangles
Definition: grid_files.hpp:24
void use_namelist(const string &namelist)
Definition: NamelistReader.hpp:355
double max_z
Definition: rz_bounds.hpp:8
Definition: grid_files.hpp:273
void convert_to_node_format(const View< int **, CLayout, HostType > &tmp_ele, View< Vertex *, HostType > &nodes)
Definition: grid_files.hpp:50
double axis_r
r coordinate of axis
Definition: equil.hpp:94
double min_r
Definition: rz_bounds.hpp:5
Definition: col_grid.hpp:35
Definition: file_reader.hpp:6
void construct_hex_grid(int nshells, double raxis, double zaxis, double rscale, double zscale)
Definition: grid_files.hpp:286
double r
Definition: grid_structs.hpp:29
void exit_XGC(std::string msg)
Definition: globals.hpp:37
Definition: magnetic_field.F90:1
int sum_nnodes_on_surfaces
Definition: grid_files.hpp:34
static int nshells_from_nnodes(int nnodes)
Definition: grid_files.hpp:497
GridCreateOpt
Definition: grid_files.hpp:272
GridFiles(const std::string &node_file, const std::string &element_file, const std::string &flx_aif_file)
Definition: grid_files.hpp:63
void parallel_for(const std::string name, int n_ptl, Function func, Option option, HostAoSoA aosoa_h, DeviceAoSoA aosoa_d)
Definition: streamed_parallel_for.hpp:252
double min_z
Definition: rz_bounds.hpp:7
int nnodes
Definition: grid_files.hpp:19
void skip(int n)
Definition: file_reader.hpp:45
View< int **, CLayout, HostType > non_aligned_surf_idx
Definition: grid_files.hpp:38
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:68
constexpr double TWOPI
Definition: constants.hpp:9
double node_to_node_dist(RZPair a, RZPair b)
Definition: grid_files.hpp:389
void open(const std::string &input)
Definition: file_reader.hpp:13
int n_specified_xpts()
Definition: grid_files.hpp:577
double max_r
Definition: rz_bounds.hpp:6