XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
diagnostic.hpp
Go to the documentation of this file.
1 #ifndef DIAGNOSTIC_HPP
2 #define DIAGNOSTIC_HPP
3 
4 #include "xgc_io.hpp"
5 #include "space_settings.hpp"
6 #include "step_trigger.hpp"
7 
8 /* Base class for diagnostics */
9 class Diagnostic{
11 
12  protected:
13 
14  // These can be set by a derived class
15  StepTrigger step_trigger; // Triggers when it is time to call this diagnostic
16 
17  public:
18 
19  bool is_on;
20 
21  /* Returns whether this diagnostic should be executed on this step
22  * */
23  bool is_triggered(int step){
24  return step_trigger.is_triggered(step);
25  }
26 
27  /* Returns whether or not we have passed the first trigger yet
28  * */
29  bool has_been_triggered(int step){
30  return step_trigger.has_been_triggered(step);
31  }
32 
33  // Default constructor for use if diagnostic is not used
35  : is_on(false){}
36  // Constructor if used: Set up stream and trigger
37  void init(const std::string& name, int period, int first_step=-1){
38  stream.Init(name);
39 
40  is_on = true;
41  if(first_step==-1){
42  // Use default if no first step provided
43  step_trigger = StepTrigger(period);
44  }else{
45  step_trigger = StepTrigger(period, first_step);
46  }
47  }
48 
57  void open_stream(const std::string& filename, const XGC_IO_Mode& mode){
58  stream.Open(filename, mode);
59  }
60 
61 #ifdef USE_MPI
62 
71  void open_stream(const std::string& filename, const XGC_IO_Mode& mode, const MPI_Comm& comm){
72  stream.Open(filename, mode, comm);
73  }
74 #endif
75 
81  void close_stream(){
82  stream.Close();
83  }
84 
85  // Every diagnostic will have its own custom write since they will vary significantly in structure
86  void write(const XGC_IO& xgc_io){
87  xgc_io.write(stream);
88  }
89 
91 #ifdef ADIOS2
92  stream.engine->BeginStep();
93 #endif
94  }
95 
96  bool is_first_step(){
97 #ifdef ADIOS2
98  return (stream.engine->CurrentStep() == 0);
99 #else
100  return true;
101 #endif
102  }
103 
105 #ifdef ADIOS2
106  stream.engine->EndStep();
107 #endif
108  }
109 };
110 
111 #endif
void write(const XGC_IO_Stream &stream) const
Definition: xgc_io.hpp:206
void Open(const std::string &StreamName, const XGC_IO_Mode mode)
Definition: xgc_io.hpp:25
Definition: xgc_io.hpp:187
bool has_been_triggered(int step)
Definition: step_trigger.hpp:30
void init(const std::string &name, int period, int first_step=-1)
Definition: diagnostic.hpp:37
bool is_on
Definition: diagnostic.hpp:19
void start_write_step()
Definition: diagnostic.hpp:90
void close_stream()
Definition: diagnostic.hpp:81
void open_stream(const std::string &filename, const XGC_IO_Mode &mode)
Definition: diagnostic.hpp:57
void end_write_step()
Definition: diagnostic.hpp:104
bool is_triggered(int step)
Definition: step_trigger.hpp:23
bool is_triggered(int step)
Definition: diagnostic.hpp:23
Definition: xgc_io.hpp:19
void write(const XGC_IO &xgc_io)
Definition: diagnostic.hpp:86
XGC_IO_Mode
Definition: xgc_io.hpp:12
bool has_been_triggered(int step)
Definition: diagnostic.hpp:29
void Close()
Definition: xgc_io.hpp:29
Diagnostic()
Definition: diagnostic.hpp:34
Definition: diagnostic.hpp:9
void Init(const std::string &IOName)
Definition: xgc_io.hpp:24
Definition: step_trigger.hpp:4
XGC_IO_Stream stream
Definition: diagnostic.hpp:10
bool is_first_step()
Definition: diagnostic.hpp:96
StepTrigger step_trigger
Definition: diagnostic.hpp:15