1 #ifndef MAGNETIC_EQUIL_FILES_HPP
2 #define MAGNETIC_EQUIL_FILES_HPP
11 extern "C" void xgc_read_eq_m3dc1_dims(
int* mpsi,
int* mr,
int* mz,
double* min_r,
double* max_r,
double* min_z,
double* max_z);
12 extern "C" void xgc_read_eq_m3dc1(
int mpsi,
int mr,
int mz,
double min_r,
double max_r,
double min_z,
double max_z,
13 double* axis_r,
double* axis_z,
double* axis_b,
double* x_psi,
double* x_r,
double* x_z,
14 double* psi_grid,
double* rgrid,
double* zgrid,
double* I,
double* psi_rz);
30 View<double*, CLayout, HostType>
I;
31 View<double**, CLayout, HostType>
psi_rz;
55 file_reader.
read(
I.data(),
I.size());
59 file_reader.
read(&end_flag, 1);
61 exit_XGC(
"\nError reading eqd file: Did not encounter end flag (-1) where expected. The file format may be incorrect.\n");
75 file_reader.
open(eq_filename);
91 psi_grid = View<double*, CLayout, HostType>(
"psi_grid",
mpsi);
92 I = View<double*, CLayout, HostType>(
"I",
mpsi);
93 psi_rz = View<double**, CLayout, HostType>(
"psi_rz",
mz,
mr);
102 xgc_read_eq_m3dc1(
mpsi,
mr, mz,
bounds.
min_r,
bounds.
max_r,
bounds.
min_z,
bounds.
max_z, &
axis_r, &
axis_z, &
axis_b, &
x_psi, &
x_r, &
x_z,
103 psi_grid.data(), rgrid.data(),
zgrid.data(), I.data(), psi_rz.data());
120 MPI_Bcast(I.data(), I.size(), MPI_DOUBLE, root_rank,
SML_COMM_WORLD);
121 MPI_Bcast(psi_rz.data(), psi_rz.size(), MPI_DOUBLE, root_rank,
SML_COMM_WORLD);
128 if(
is_rank_zero()) printf(
"\nCreating a circular analytic magnetic equilibrium.\n");
157 I = View<double*, CLayout, HostType>(
"I",
mpsi);
158 Kokkos::deep_copy(
I, 10000.0);
161 psi_rz = View<double**, CLayout, HostType>(
"psi_rz",
mz,
mr);
162 for (
int j=0; j<
zgrid.size(); j++){
163 for (
int i=0; i<
rgrid.size(); i++){
166 psi_rz(j,i) = sqrt(rp*rp + zp*zp);
180 bool bt_sign = nlr.
get<
double>(
"sml_bt_sign", -1.0);
181 bool bp_sign = nlr.
get<
double>(
"sml_bp_sign", 1.0);
184 bool read_eqd = nlr.
get<
bool>(
"sml_read_eq",
true);
185 bool read_m3dc1 = nlr.
get<
bool>(
"sml_read_eq_m3dc1",
false);
188 if(!(read_eqd || read_m3dc1))
exit_XGC(
"Error: must use either sml_read_eq or sml_read_eq_m3dc1");
190 std::string input_file_dir = nlr.
get<std::string>(
"sml_input_file_dir",
"./");
193 std::string eq_filename = nlr.
get<std::string>(
"eq_filename",
"example_file.eqd");
196 eq_filename = input_file_dir +
"/" + eq_filename;
201 eq_file.x_psi *= bp_sign;
202 eq_file.axis_b *= bt_sign;
204 for(
int i=0; i<eq_file.psi_grid.size(); i++) eq_file.psi_grid(i) *= bp_sign;
205 for(
int i=0; i<eq_file.I.size(); i++) eq_file.I(i) *= bt_sign;
206 for(
int i=0; i<eq_file.psi_rz.extent(0); i++)
207 for(
int j=0; j<eq_file.psi_rz.extent(1); j++)
208 eq_file.psi_rz(i,j) *= bp_sign;
View< double *, HostType > rgrid
Definition: magnetic_equil_files.hpp:28
double axis_b
Definition: magnetic_equil_files.hpp:23
Definition: magnetic_equil_files.hpp:16
bool is_rank_zero()
Definition: globals.hpp:27
MPI_Comm SML_COMM_WORLD
Definition: my_mpi.cpp:4
double x_psi
Definition: magnetic_equil_files.hpp:24
T get(const string ¶m, const T default_val, int val_ind=0)
Definition: NamelistReader.hpp:373
double x_z
Definition: magnetic_equil_files.hpp:26
Definition: rz_bounds.hpp:4
View< double *, HostType > create_range_view(std::string name, double x_min, double x_max, int n)
Definition: range_view.hpp:6
Definition: NamelistReader.hpp:193
void read_eq_dims(FileReader &file_reader)
Definition: magnetic_equil_files.hpp:34
void read(T *var, int n)
Definition: file_reader.hpp:28
double axis_z
Definition: magnetic_equil_files.hpp:22
View< double *, HostType > zgrid
Definition: magnetic_equil_files.hpp:29
MagneticEquilFiles(NLReader::NamelistReader &nlr)
Definition: magnetic_equil_files.hpp:126
double x_r
Definition: magnetic_equil_files.hpp:25
int mr
Definition: magnetic_equil_files.hpp:18
void use_namelist(const string &namelist)
Definition: NamelistReader.hpp:355
double max_z
Definition: rz_bounds.hpp:8
View< double **, CLayout, HostType > psi_rz
Definition: magnetic_equil_files.hpp:31
subroutine xgc_read_eq_m3dc1_dims(mpsi, mr, mz, min_r, max_r, min_z, max_z)
Definition: read.F90:22
double axis_r
Definition: magnetic_equil_files.hpp:21
MagneticEquilFiles(bool read_m3dc1, const std::string &eq_filename)
Definition: magnetic_equil_files.hpp:66
double min_r
Definition: rz_bounds.hpp:5
int mpsi
Definition: magnetic_equil_files.hpp:17
void read_eq(FileReader &file_reader)
Definition: magnetic_equil_files.hpp:46
Definition: file_reader.hpp:6
static MagneticEquilFiles eq_files_from_namelist(NLReader::NamelistReader &nlr)
Definition: magnetic_equil_files.hpp:174
subroutine xgc_read_eq_m3dc1(mpsi, mr, mz, min_r, max_r, min_z, max_z, axis_r, axis_z, axis_b, x_psi, x_r, x_z, psi_grid, rgrid, zgrid, eq_I, psi_rz)
Definition: read.F90:54
bool namelist_present(const string &namelist)
Definition: NamelistReader.hpp:351
View< double *, CLayout, HostType > I
Definition: magnetic_equil_files.hpp:30
void exit_XGC(std::string msg)
Definition: globals.hpp:37
View< double *, CLayout, HostType > psi_grid
Definition: magnetic_equil_files.hpp:27
RZBounds bounds
Definition: magnetic_equil_files.hpp:20
double min_z
Definition: rz_bounds.hpp:7
void skip_line()
Definition: file_reader.hpp:62
int mz
Definition: magnetic_equil_files.hpp:19
void open(const std::string &input)
Definition: file_reader.hpp:13
double max_r
Definition: rz_bounds.hpp:6