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 
32 
35  const DomainDecomposition<DeviceType>& pol_decomp,
36  const Grid<DeviceType>& grid, const VelocityGrid& vgrid, int f_source_period,
37  bool overwrite_existing){
38 
39  nlr.use_namelist("diag_param");
40  int diag_1d_period = nlr.get<int>("diag_1d_period",10);
41  int diag_3d_on = nlr.get<bool>("diag_3d_on",true);
42 
43  bool heat_diag_is_on = nlr.get<bool>("diag_heat_on", false);
44 
45  // Construct each diagnostic
46  if(heat_diag_is_on){
47  heat_diag.init(nlr, magnetic_field, grid, plasma.nspecies);
48  }
49 
50  // Check if some species are deltaf
51  bool use_deltaf_diag = plasma.true_for_some_species([&](const Species<DeviceType>& species){return (species.f_analytic_shape!=FAnalyticShape::None && !species.is_adiabatic);});
52  push_diag = PushDiagnostic<DeviceType>(nlr, use_deltaf_diag, grid.npsi_surf2, plasma.n_nonadiabatic_species, sml.nthreads);
53 
54  diag_f0_df.init(nlr, sml, grid, plasma, f_source_period);
55 
56  diag_f0.init(nlr, f_source_period, sml.is_XGCa);
57 
58  diag_3d_f0_f.init(nlr, f_source_period);
59 
60 #ifdef GB2024
61  particle_stream = ParticleStream(nlr, magnetic_field);
62 #endif
63 #ifndef NO_PETSC
64  if (vgrid.pseudo_inv_on){
65  pseudo_inv_diag.init(nlr, f_source_period, "pseudo_inv_diag");
66  }
67  if (sml.current_drive_on){
68  loop_vol_diag.init(nlr, f_source_period,"loop_vol_diag");
69  }
70 #endif
71 #ifdef ESC_PTL
72  tracer_diag.init("tracer_diag");
73 #endif
74 
75 
76  diag_1d.init(nlr, pol_decomp, grid, magnetic_field, plasma, use_deltaf_diag);
77 
78  if(diag_3d_on){
79  diag_3d.init(nlr, grid, diag_1d_period);
80  }
81 
82  // Open file streams for diagnostics
83  open_streams(overwrite_existing);
84  }
85 
86  void open_streams(bool overwrite_existing){
87  XGC_IO_Mode mode = (overwrite_existing ? XGC_IO_Mode::Write : XGC_IO_Mode::Append);
88  if(heat_diag.is_on){
89  if(heat_diag.mode==1) heat_diag.open_stream("xgc.heatdiag.bp", mode);
90  else heat_diag.open_stream("xgc.heatdiag2.bp", mode);
91  }
92 #ifdef XGCA
93  // XGC1 uses a different file for each step. This is kept for back compatibility, but should be consolidated.
94  if(diag_f0_df.is_on){
95  diag_f0_df.open_stream("xgc.fsourcediag.bp", mode);
96  }
97 #endif
99  pseudo_inv_diag.open_stream("xgc.pseudo_inv.bp", mode);
100  }
101  if(loop_vol_diag.is_on){
102 #ifdef USE_MPI
103  loop_vol_diag.open_stream("xgc.loop_vol.bp", mode, MPI_COMM_SELF);
104 #endif
105  }
106  if(tracer_diag.is_on){
107  tracer_diag.open_stream("xgc.particle_stream.bp", XGC_IO_Mode::Write);
108  }
109  if(diag_1d.is_on){
110  diag_1d.open_stream("xgc.oneddiag.bp", mode);
111  }
112 #ifdef XGC1
113  // Steps within the same file are only used if XGC1 and adios_stage_3d
114  // This is kept for back compatibility, but should be consolidated
116  diag_3d.open_stream("xgc.3d.bp", mode);
117  }
118 
120  diag_f0.open_stream("xgc.f0.bp", mode);
121  }
122 
124  diag_3d_f0_f.open_stream("xgc.f3d.bp", mode);
125  }
126 #endif
127  }
128 
130 #ifdef XGCA
132 #endif
138 #ifdef XGC1
142 #endif
143  }
144 };
145 
146 #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:33
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:12
DiagF0 diag_f0
Definition: diagnostics.hpp:26
Diagnostics()
Definition: diagnostics.hpp:31
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:65
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: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:166
Definition: tracer_diag.hpp:12
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:86
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 close_streams()
Definition: diagnostics.hpp:129
void init(NLReader::NamelistReader &nlr, int default_period)
Definition: diag_3d_f0_f.cpp:8
HeatDiagnostics< DeviceType > heat_diag
Definition: diagnostics.hpp:20
bool current_drive_on
Definition: sml.hpp:244
Definition: plasma.hpp:13
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