XGC1
diagnostics.hpp
Go to the documentation of this file.
1 #ifndef DIAGNOSTICS_HPP
2 #define DIAGNOSTICS_HPP
3 
4 #include "push_diagnostic.hpp"
5 #include "heat_diagnostics.hpp"
7 #include "tracer_diag.hpp"
8 #include "loop_voltage_diag.hpp"
9 #include "diag_f0_df.hpp"
10 #include "diag_3d_f0_f.hpp"
11 #include "diag_f0.hpp"
12 #include "diag_1d.hpp"
13 #include "diag_3d.hpp"
14 #include "diag_particle.hpp"
15 #include "particle_stream.hpp"
17 #include "sheath_diag.hpp"
18 #include <mpi.h>
19 
20 /* Contains all the diagnostics */
21 struct Diagnostics{
36 
37 
39 
42  const DomainDecomposition<DeviceType>& pol_decomp,
43  const Grid<DeviceType>& grid, const VelocityGrid& vgrid, int f_source_period,
44  bool overwrite_existing){
45 
46  nlr.use_namelist("diag_param");
47  int diag_1d_period = nlr.get<int>("diag_1d_period",10);
48  int diag_3d_on = nlr.get<bool>("diag_3d_on",true);
49 
50  bool heat_diag_is_on = nlr.get<bool>("diag_heat_on", false); // Whether to write heat diagnostic.
51 
52  // Construct each diagnostic
53  if(heat_diag_is_on){
54  heat_diag.init(nlr, magnetic_field, grid, plasma.nspecies);
55  }
56 
57  // Check if some species are deltaf
58  bool use_deltaf_diag = plasma.true_for_some_species([&](const Species<DeviceType>& species){return (species.f_analytic_shape!=FAnalyticShape::None && !species.is_adiabatic);});
59  push_diag = PushDiagnostic<DeviceType>(nlr, use_deltaf_diag, grid.npsi_surf2, plasma.n_nonadiabatic_species, sml.nthreads);
60 
61  diag_f0_df.init(nlr, sml, grid, plasma, f_source_period);
62 
63  diag_f0.init(nlr, f_source_period, sml.is_XGCa);
64 
65  diag_3d_f0_f.init(nlr, magnetic_field, grid, f_source_period);
66 
67 #ifdef GB2024
69 #endif
70 #ifndef NO_PETSC
71  if (vgrid.pseudo_inv_on){
72  pseudo_inv_diag.init(nlr, f_source_period, "pseudo_inv_diag");
73  }
74  if (sml.current_drive_on){
75  loop_vol_diag.init(nlr, f_source_period,"loop_vol_diag");
76  }
77 #endif
78 #ifdef ESC_PTL
79  tracer_diag.init("tracer_diag");
80 #endif
81 
82  if(sml.sheath_mode>0){
83  sheath_diag.init(nlr, "sheath_diag");
84  }
85 
86  diag_1d.init(nlr, pol_decomp, grid, magnetic_field, plasma, use_deltaf_diag);
87 
88  if(diag_3d_on){
89  diag_3d.init(nlr, grid, plasma, diag_1d_period);
90  }
91 
92  diag_particle.init(nlr);
93 
94  nlr.use_namelist("diag_param");
95  bool diag_diff_prof_on = nlr.get<bool>("diag_diff_profiles_on",false);
96  if (diag_diff_prof_on){
97  diag_diff_prof.init(nlr, sml, grid, plasma, f_source_period);
98  }
99 
100  // Open file streams for diagnostics
101  open_streams(overwrite_existing);
102  }
103 
104  void open_streams(bool overwrite_existing){
105  XGC_IO_Mode mode = (overwrite_existing ? XGC_IO_Mode::Write : XGC_IO_Mode::Append);
106  if(heat_diag.is_on){
107  if(heat_diag.mode==1) heat_diag.open_stream("xgc.heatdiag.bp", mode);
108  else heat_diag.open_stream("xgc.heatdiag2.bp", mode);
109  }
111  diag_f0_df.open_stream("xgc.fsourcediag.bp", mode);
112  }
114  pseudo_inv_diag.open_stream("xgc.pseudo_inv.bp", mode);
115  }
116  if(loop_vol_diag.is_on){
117 #ifdef USE_MPI
118  if (is_rank_zero()){
119  loop_vol_diag.open_stream("xgc.loop_vol.bp", mode, MPI_COMM_SELF);
120  }
121 #else
122  loop_vol_diag.open_stream("xgc.loop_vol.bp", mode);
123 #endif
124  }
125  if(sheath_diag.is_on){
126 #ifdef USE_MPI
127  if (is_rank_zero()){
128  sheath_diag.open_stream("xgc.sheathdiag.bp", mode, MPI_COMM_SELF);
129  }
130 #else
131  sheath_diag.open_stream("xgc.sheathdiag.bp", mode);
132 #endif
133  }
134  if(tracer_diag.is_on){
135  tracer_diag.open_stream("xgc.particle_stream.bp", XGC_IO_Mode::Write);
136  }
137  if(diag_1d.is_on){
138  diag_1d.open_stream("xgc.oneddiag.bp", mode);
139  }
140  if(diag_diff_prof.is_on){
141 #ifdef USE_MPI
142  if (is_rank_zero()){
143  diag_diff_prof.open_stream("xgc.diffusion_profiles.bp", mode, MPI_COMM_SELF);
144  }
145 #else
146  diag_diff_prof.open_stream("xgc.diffusion_profiles.bp", mode);
147 #endif
148  }
150  diag_3d.open_stream("xgc.3d.bp", mode);
151  }
152 
154  diag_particle.open_stream("xgc.particle.bp", mode);
155  }
156 
158  diag_f0.open_stream("xgc.f0.bp", mode);
159  }
160 
162  diag_3d_f0_f.open_stream("xgc.f3d.bp", mode);
163  }
164  }
165 
179  }
180 };
181 
182 #endif
Definition: diag_1d.hpp:10
void init(NLReader::NamelistReader &nlr, const DomainDecomposition< DeviceType > &pol_decomp, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, const Plasma &plasma, bool allocate_df_diagnostic)
Definition: diag_1d.cpp:324
Definition: diag_3d_f0_f.hpp:13
void init(NLReader::NamelistReader &nlr, const MagneticField< DeviceType > &magnetic_field, const Grid< DeviceType > &grid, int default_period)
Definition: diag_3d_f0_f.cpp:7
bool adios_stage
Definition: diag_3d_f0_f.hpp:67
Definition: diag_3d.hpp:12
bool adios_stage
Definition: diag_3d.hpp:24
void init(NLReader::NamelistReader &nlr, const Grid< DeviceType > &grid, const Plasma &plasma, int default_period)
Definition: diag_3d.cpp:98
Definition: diag_f0_df.hpp:9
bool adios_stage
Definition: diag_f0_df.hpp:34
void init(NLReader::NamelistReader &nlr, const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const Plasma &plasma, int f_source_period)
Definition: diag_f0_df.hpp:47
Definition: diag_f0.hpp:10
bool adios_stage
Definition: diag_f0.hpp:14
void init(NLReader::NamelistReader &nlr, int default_period, bool is_XGCa_in)
Definition: diag_f0.cpp:3
Definition: diag_particle.hpp:8
void init(NLReader::NamelistReader &nlr)
Definition: diag_particle.cpp:29
bool adios_stage
Definition: diag_particle.hpp:12
void open_stream(const std::string &filename, const XGC_IO_Mode &mode)
Definition: diagnostic.hpp:66
bool is_on
Definition: diagnostic.hpp:20
void close_stream()
Definition: diagnostic.hpp:90
Diagnostic for writing diffusion profile data using ADIOS2.
Definition: diag_diffusion_profiles.hpp:29
void init(NLReader::NamelistReader &nlr, const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const Plasma &plasma, int f_source_period)
Initialize the DiffusionProfilesDiag diagnostic.
Definition: diag_diffusion_profiles.cpp:33
bool is_on
Flag to indicate if this diagnostic is active.
Definition: diag_diffusion_profiles.hpp:40
int npsi_surf2
Definition: grid.hpp:181
int mode
Using mode 1 or mode 2.
Definition: heat_diagnostics.hpp:32
void init(NLReader::NamelistReader &nlr, const MagneticField< Device > &magnetic_field, const Grid< Device > &grid, int nspecies)
Definition: loop_voltage_diag.hpp:18
void init(NLReader::NamelistReader &nlr, int f_source_period, const std::string &name)
Definition: loop_voltage_diag.hpp:24
Definition: magnetic_field.hpp:12
Definition: NamelistReader.hpp:193
T get(const string &param, const T default_val, int val_ind=0)
Definition: NamelistReader.hpp:386
void use_namelist(const string &namelist, Options required=Required)
Definition: NamelistReader.hpp:360
Definition: particle_stream.hpp:6
Definition: plasma.hpp:13
Definition: pseudo_inverse_diag.hpp:26
void init(NLReader::NamelistReader &nlr, int f_source_period, const std::string &name)
Definition: pseudo_inverse_diag.hpp:32
Definition: sheath_diag.hpp:8
void init(NLReader::NamelistReader &nlr, const std::string &name)
Definition: sheath_diag.hpp:14
Definition: sml.hpp:9
int sheath_mode
Type of sheath (0 is none)
Definition: sml.hpp:46
int nthreads
Number of OMP threads on the host.
Definition: sml.hpp:55
static constexpr bool is_XGCa
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:20
bool current_drive_on
Definition: sml.hpp:185
Definition: species.hpp:75
bool is_adiabatic
Whether this species is adiabatic.
Definition: species.hpp:80
FAnalyticShape f_analytic_shape
f_analytic_shape shape: Maxwellian, SlowingDown or None
Definition: species.hpp:90
Definition: tracer_diag.hpp:12
void init(const std::string &name)
Definition: tracer_diag.hpp:18
Headers for the DiffusionProfilesDiag diagnostic for writing plasma profile data for automatic adjust...
bool is_rank_zero()
Definition: globals.hpp:27
Definition: magnetic_field.F90:1
subroutine plasma(grid, itr, p, dene_out, deni_out, Te_out, Ti_out, Vparai_out, ignore_vacuum)
Calculate the plasma density, temperature, and parallel velocity for a point in triangle itr using pl...
Definition: neutral_totalf.F90:1541
Definition: diagnostics.hpp:21
Diag3D diag_3d
Definition: diagnostics.hpp:32
void close_streams()
Definition: diagnostics.hpp:166
Diagnostics()
Definition: diagnostics.hpp:38
void open_streams(bool overwrite_existing)
Definition: diagnostics.hpp:104
LoopVolDiagnostics loop_vol_diag
Definition: diagnostics.hpp:26
DiffusionProfilesDiag diag_diff_prof
Definition: diagnostics.hpp:34
DiagF0DF diag_f0_df
Definition: diagnostics.hpp:28
Diag3DF0F diag_3d_f0_f
Definition: diagnostics.hpp:30
DiagParticle diag_particle
Definition: diagnostics.hpp:33
ParticleStream particle_stream
Definition: diagnostics.hpp:27
DiagF0 diag_f0
Definition: diagnostics.hpp:29
Diag1D diag_1d
Definition: diagnostics.hpp:31
PushDiagnostic< DeviceType > push_diag
Definition: diagnostics.hpp:22
Diagnostics(NLReader::NamelistReader &nlr, const Simulation< DeviceType > &sml, const MagneticField< DeviceType > &magnetic_field, const Plasma &plasma, const DomainDecomposition< DeviceType > &pol_decomp, const Grid< DeviceType > &grid, const VelocityGrid &vgrid, int f_source_period, bool overwrite_existing)
Definition: diagnostics.hpp:40
PseudoInvDiagnostics pseudo_inv_diag
Definition: diagnostics.hpp:24
SheathDiag sheath_diag
Definition: diagnostics.hpp:35
HeatDiagnostics< DeviceType > heat_diag
Definition: diagnostics.hpp:23
TracerDiagnostics tracer_diag
Definition: diagnostics.hpp:25
Definition: velocity_grid.hpp:8
bool pseudo_inv_on
whether pseudo-inverse interpolation is used in velocity space
Definition: velocity_grid.hpp:24
XGC_IO_Mode
Definition: xgc_io.hpp:17