XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <mpi.h>
18 
19 /* Contains all the diagnostics */
20 struct Diagnostics{
34 
35 
37 
40  const DomainDecomposition<DeviceType>& pol_decomp,
41  const Grid<DeviceType>& grid, const VelocityGrid& vgrid, int f_source_period,
42  bool overwrite_existing){
43 
44  nlr.use_namelist("diag_param");
45  int diag_1d_period = nlr.get<int>("diag_1d_period",10);
46  int diag_3d_on = nlr.get<bool>("diag_3d_on",true);
47 
48  bool heat_diag_is_on = nlr.get<bool>("diag_heat_on", false); // Whether to write heat diagnostic.
49 
50  // Construct each diagnostic
51  if(heat_diag_is_on){
52  heat_diag.init(nlr, magnetic_field, grid, plasma.nspecies);
53  }
54 
55  // Check if some species are deltaf
56  bool use_deltaf_diag = plasma.true_for_some_species([&](const Species<DeviceType>& species){return (species.f_analytic_shape!=FAnalyticShape::None && !species.is_adiabatic);});
57  push_diag = PushDiagnostic<DeviceType>(nlr, use_deltaf_diag, grid.npsi_surf2, plasma.n_nonadiabatic_species, sml.nthreads);
58 
59  diag_f0_df.init(nlr, sml, grid, plasma, f_source_period);
60 
61  diag_f0.init(nlr, f_source_period, sml.is_XGCa);
62 
63  diag_3d_f0_f.init(nlr, magnetic_field, grid, f_source_period);
64 
65 #ifdef GB2024
66  particle_stream = ParticleStream(nlr, magnetic_field);
67 #endif
68 #ifndef NO_PETSC
69  if (vgrid.pseudo_inv_on){
70  pseudo_inv_diag.init(nlr, f_source_period, "pseudo_inv_diag");
71  }
72  if (sml.current_drive_on){
73  loop_vol_diag.init(nlr, f_source_period,"loop_vol_diag");
74  }
75 #endif
76 #ifdef ESC_PTL
77  tracer_diag.init("tracer_diag");
78 #endif
79 
80 
81  diag_1d.init(nlr, pol_decomp, grid, magnetic_field, plasma, use_deltaf_diag);
82 
83  if(diag_3d_on){
84  diag_3d.init(nlr, grid, diag_1d_period);
85  }
86 
87  diag_particle.init(nlr);
88 
89  nlr.use_namelist("diag_param");
90  bool diag_diff_prof_on = nlr.get<bool>("diag_diff_profiles_on",false);
91  if (diag_diff_prof_on){
92  diag_diff_prof.init(nlr, sml, grid, plasma, f_source_period);
93  }
94 
95  // Open file streams for diagnostics
96  open_streams(overwrite_existing);
97  }
98 
99  void open_streams(bool overwrite_existing){
100  XGC_IO_Mode mode = (overwrite_existing ? XGC_IO_Mode::Write : XGC_IO_Mode::Append);
101  if(heat_diag.is_on){
102  if(heat_diag.mode==1) heat_diag.open_stream("xgc.heatdiag.bp", mode);
103  else heat_diag.open_stream("xgc.heatdiag2.bp", mode);
104  }
105 #ifdef XGCA
106  // XGC1 uses a different file for each step. This is kept for back compatibility, but should be consolidated.
107  if(diag_f0_df.is_on){
108  diag_f0_df.open_stream("xgc.fsourcediag.bp", mode);
109  }
110 #endif
112  pseudo_inv_diag.open_stream("xgc.pseudo_inv.bp", mode);
113  }
114  if(loop_vol_diag.is_on){
115 #ifdef USE_MPI
116  loop_vol_diag.open_stream("xgc.loop_vol.bp", mode, MPI_COMM_SELF);
117 #else
118  loop_vol_diag.open_stream("xgc.loop_vol.bp", mode);
119 #endif
120  }
121  if(tracer_diag.is_on){
122  tracer_diag.open_stream("xgc.particle_stream.bp", XGC_IO_Mode::Write);
123  }
124  if(diag_1d.is_on){
125  diag_1d.open_stream("xgc.oneddiag.bp", mode);
126  }
127  if(diag_diff_prof.is_on){
128 #ifdef USE_MPI
129  if (is_rank_zero()){
130  diag_diff_prof.open_stream("xgc.diffusion_profiles.bp", mode, MPI_COMM_SELF);
131  }
132 #else
133  diag_diff_prof.open_stream("xgc.diffusion_profiles.bp", mode);
134 #endif
135  }
136 #ifdef XGC1
137  // Steps within the same file are only used if XGC1 and adios_stage_3d
138  // This is kept for back compatibility, but should be consolidated
140  diag_3d.open_stream("xgc.3d.bp", mode);
141  }
142 
144  diag_particle.open_stream("xgc.particle.bp", mode);
145  }
146 
148  diag_f0.open_stream("xgc.f0.bp", mode);
149  }
150 
152  diag_3d_f0_f.open_stream("xgc.f3d.bp", mode);
153  }
154 #endif
155  }
156 
158 #ifdef XGCA
160 #endif
166 #ifdef XGC1
171 #endif
173  }
174 };
175 
176 #endif
bool is_on
Flag to indicate if this diagnostic is active.
Definition: diag_diffusion_profiles.hpp:40
void init(NLReader::NamelistReader &nlr, const Grid< DeviceType > &grid, int default_period)
Definition: diag_3d.cpp:100
bool is_rank_zero()
Definition: globals.hpp:27
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:38
T get(const string &param, const T default_val, int val_ind=0)
Definition: NamelistReader.hpp:373
Definition: diag_f0_df.hpp:9
Definition: diag_3d_f0_f.hpp:13
bool pseudo_inv_on
whether pseudo-inverse interpolation is used in velocity space
Definition: velocity_grid.hpp:24
TracerDiagnostics tracer_diag
Definition: diagnostics.hpp:24
Definition: velocity_grid.hpp:8
Definition: diagnostics.hpp:20
Definition: sml.hpp:8
static constexpr bool is_XGCa
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:19
void init(NLReader::NamelistReader &nlr, const MagneticField< Device > &magnetic_field, const Grid< Device > &grid, int nspecies)
subroutine plasma(grid, itr, p, dene_out, deni_out, Te_out, Ti_out, Vparai_out)
Calculate the plasma density, temperature, and parallel velocity for a point in triangle itr using pl...
Definition: neutral_totalf.F90:1248
bool adios_stage
Definition: diag_particle.hpp:12
bool adios_stage
Definition: diag_3d.hpp:18
Definition: NamelistReader.hpp:193
Definition: magnetic_field.hpp:12
DiagF0 diag_f0
Definition: diagnostics.hpp:28
Diagnostics()
Definition: diagnostics.hpp:36
LoopVolDiagnostics loop_vol_diag
Definition: diagnostics.hpp:25
void init(NLReader::NamelistReader &nlr, int default_period, bool is_XGCa_in)
Definition: diag_f0.cpp:3
PseudoInvDiagnostics pseudo_inv_diag
Definition: diagnostics.hpp:23
DiffusionProfilesDiag diag_diff_prof
Definition: diagnostics.hpp:33
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:45
Diag1D diag_1d
Definition: diagnostics.hpp:30
bool is_on
Definition: diagnostic.hpp:20
bool adios_stage
Definition: diag_f0.hpp:14
Definition: diag_3d.hpp:12
Diag3D diag_3d
Definition: diagnostics.hpp:31
PushDiagnostic< DeviceType > push_diag
Definition: diagnostics.hpp:21
Diag3DF0F diag_3d_f0_f
Definition: diagnostics.hpp:29
int nthreads
Number of OMP threads on the host.
Definition: sml.hpp:65
Definition: diag_particle.hpp:8
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:323
Definition: diag_f0.hpp:10
void close_stream()
Definition: diagnostic.hpp:90
bool true_for_some_species(F func) const
Definition: plasma.hpp:182
void use_namelist(const string &namelist)
Definition: NamelistReader.hpp:355
Definition: pseudo_inverse_diag.hpp:26
void open_stream(const std::string &filename, const XGC_IO_Mode &mode)
Definition: diagnostic.hpp:66
int npsi_surf2
Definition: grid.hpp:172
Definition: tracer_diag.hpp:12
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
int nspecies
Number of species including electrons.
Definition: plasma.hpp:89
int n_nonadiabatic_species
Number of nonadiabatic species.
Definition: plasma.hpp:90
XGC_IO_Mode
Definition: xgc_io.hpp:17
void init(NLReader::NamelistReader &nlr, int f_source_period, const std::string &name)
Definition: loop_voltage_diag.hpp:26
void open_streams(bool overwrite_existing)
Definition: diagnostics.hpp:99
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: magnetic_field.F90:1
void init(NLReader::NamelistReader &nlr, const MagneticField< DeviceType > &magnetic_field, const Grid< DeviceType > &grid, int default_period)
Definition: diag_3d_f0_f.cpp:7
void close_streams()
Definition: diagnostics.hpp:157
Diagnostic for writing diffusion profile data using ADIOS2.
Definition: diag_diffusion_profiles.hpp:29
HeatDiagnostics< DeviceType > heat_diag
Definition: diagnostics.hpp:22
bool current_drive_on
Definition: sml.hpp:228
Definition: plasma.hpp:13
ParticleStream particle_stream
Definition: diagnostics.hpp:26
Definition: particle_stream.hpp:6
Headers for the DiffusionProfilesDiag diagnostic for writing plasma profile data for automatic adjust...
Definition: species.hpp:75
void init(NLReader::NamelistReader &nlr, int f_source_period, const std::string &name)
Definition: pseudo_inverse_diag.hpp:32
Definition: loop_voltage_diag.hpp:20
DiagParticle diag_particle
Definition: diagnostics.hpp:32
DiagF0DF diag_f0_df
Definition: diagnostics.hpp:27
int mode
Using mode 1 or mode 2.
Definition: heat_diagnostics.hpp:32
void init(const std::string &name)
Definition: tracer_diag.hpp:18
bool adios_stage
Definition: diag_3d_f0_f.hpp:64
void init(NLReader::NamelistReader &nlr)
Definition: diag_particle.cpp:29