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 "particle_stream.hpp"
15 #include <mpi.h>
16 
17 /* Contains all the diagnostics */
18 struct Diagnostics{
30 
31  // Make these use Diagnostic class
33 
35 
38  const DomainDecomposition<DeviceType>& pol_decomp,
39  const Grid<DeviceType>& grid, const VelocityGrid& vgrid, int f_source_period,
40  bool overwrite_existing){
41 
42  nlr.use_namelist("diag_param");
43  int diag_1d_period = nlr.get<int>("diag_1d_period",10);
44  int diag_3d_on = nlr.get<bool>("diag_3d_on",true);
45 
46  bool heat_diag_is_on = nlr.get<bool>("diag_heat_on", false);
47 
48  nlr.use_namelist("sml_param");
49  int special = nlr.get<int>("sml_special",0);
50  diag_poincare = (special==4);
51 
52 
53  // Construct each diagnostic
54  if(heat_diag_is_on){
55  heat_diag.init(nlr, magnetic_field, grid, plasma.nspecies);
56  }
57 
58  // Check if some species are deltaf
59  bool use_deltaf_diag = plasma.true_for_some_species([&](const Species<DeviceType>& species){return species.marker_type!=MarkerType::FullF;});
60  push_diag = PushDiagnostic<DeviceType>(nlr, use_deltaf_diag, grid.npsi_surf2, plasma.n_nonadiabatic_species, sml.nthreads);
61 
62  diag_f0_df.init(nlr, sml, grid, plasma, f_source_period);
63 
64  diag_f0.init(nlr, f_source_period, sml.is_XGCa);
65 
66  diag_3d_f0_f.init(nlr, f_source_period);
67 
68 #ifdef GB2024
69  particle_stream = ParticleStream(nlr, magnetic_field);
70 #endif
71 #ifndef NO_PETSC
72  if (vgrid.pseudo_inv_on){
73  pseudo_inv_diag.init(nlr, f_source_period, "pseudo_inv_diag");
74  }
75  if (sml.current_drive_on){
76  loop_vol_diag.init(nlr, f_source_period,"loop_vol_diag");
77  }
78 #endif
79 #ifdef ESC_PTL
80  tracer_diag.init("tracer_diag");
81 #endif
82 
83 
84  diag_1d.init(nlr, pol_decomp, grid, magnetic_field, plasma, use_deltaf_diag);
85 
86  if(diag_3d_on){
87  diag_3d.init(nlr, grid, diag_1d_period);
88  }
89 
90  // Open file streams for diagnostics
91  open_streams(overwrite_existing);
92  }
93 
94  void open_streams(bool overwrite_existing){
95  XGC_IO_Mode mode = (overwrite_existing ? XGC_IO_Mode::Write : XGC_IO_Mode::Append);
96  if(heat_diag.is_on){
97  if(heat_diag.mode==1) heat_diag.open_stream("xgc.heatdiag.bp", mode);
98  else heat_diag.open_stream("xgc.heatdiag2.bp", mode);
99  }
100 #ifdef XGCA
101  // XGC1 uses a different file for each step. This is kept for back compatibility, but should be consolidated.
102  if(diag_f0_df.is_on){
103  diag_f0_df.open_stream("xgc.fsourcediag.bp", mode);
104  }
105 #endif
107  pseudo_inv_diag.open_stream("xgc.pseudo_inv.bp", mode);
108  }
109  if(loop_vol_diag.is_on){
110 #ifdef USE_MPI
111  loop_vol_diag.open_stream("xgc.loop_vol.bp", mode, MPI_COMM_SELF);
112 #endif
113  }
114  if(tracer_diag.is_on){
115  tracer_diag.open_stream("xgc.particle_stream.bp", XGC_IO_Mode::Write);
116  }
117  if(diag_1d.is_on){
118  diag_1d.open_stream("xgc.oneddiag.bp", mode);
119  }
120 #ifdef XGC1
121  // Steps within the same file are only used if XGC1 and adios_stage_3d
122  // This is kept for back compatibility, but should be consolidated
124  diag_3d.open_stream("xgc.3d.bp", mode);
125  }
126 
128  diag_f0.open_stream("xgc.f0.bp", mode);
129  }
130 
132  diag_3d_f0_f.open_stream("xgc.f3d.bp", mode);
133  }
134 #endif
135  }
136 
138 #ifdef XGCA
140 #endif
146 #ifdef XGC1
150 #endif
151  }
152 };
153 
154 #endif
void init(NLReader::NamelistReader &nlr, const Grid< DeviceType > &grid, int default_period)
Definition: diag_3d.cpp:100
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:36
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:12
bool pseudo_inv_on
whether pseudo-inverse interpolation is used in velocity space
Definition: velocity_grid.hpp:24
TracerDiagnostics tracer_diag
Definition: diagnostics.hpp:22
Definition: velocity_grid.hpp:8
Definition: diagnostics.hpp:18
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:1224
bool adios_stage
Definition: diag_3d.hpp:18
Definition: NamelistReader.hpp:193
Definition: magnetic_field.hpp:13
DiagF0 diag_f0
Definition: diagnostics.hpp:26
Diagnostics()
Definition: diagnostics.hpp:34
LoopVolDiagnostics loop_vol_diag
Definition: diagnostics.hpp:23
void init(NLReader::NamelistReader &nlr, int default_period, bool is_XGCa_in)
Definition: diag_f0.cpp:3
PseudoInvDiagnostics pseudo_inv_diag
Definition: diagnostics.hpp:21
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:28
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:29
PushDiagnostic< DeviceType > push_diag
Definition: diagnostics.hpp:19
Diag3DF0F diag_3d_f0_f
Definition: diagnostics.hpp:27
int nthreads
Number of OMP threads on the host.
Definition: sml.hpp:67
Definition: diag_1d.hpp:9
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:182
Definition: diag_f0.hpp:10
void close_stream()
Definition: diagnostic.hpp:90
bool true_for_some_species(F func) const
Definition: plasma.hpp:188
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:161
MarkerType marker_type
Marker type: reduced delta-f, total-f, full-f, or none (placeholder for adiabatic species) ...
Definition: species.hpp:89
Definition: tracer_diag.hpp:12
int nspecies
Number of species including electrons.
Definition: plasma.hpp:94
int n_nonadiabatic_species
Number of nonadiabatic species.
Definition: plasma.hpp:95
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:94
Definition: magnetic_field.F90:1
void close_streams()
Definition: diagnostics.hpp:137
bool diag_poincare
Whether to do poincare output.
Definition: diagnostics.hpp:32
void init(NLReader::NamelistReader &nlr, int default_period)
Definition: diag_3d_f0_f.cpp:9
HeatDiagnostics< DeviceType > heat_diag
Definition: diagnostics.hpp:20
bool current_drive_on
Definition: sml.hpp:216
Definition: plasma.hpp:14
ParticleStream particle_stream
Definition: diagnostics.hpp:24
Definition: particle_stream.hpp:6
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
DiagF0DF diag_f0_df
Definition: diagnostics.hpp:25
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:56