XGC1
 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 #ifdef ADIOS2
5 #include "adios2.hpp"
6 #include "adios2_io.hpp"
7 #endif
8 #include "space_settings.hpp"
9 #include "step_trigger.hpp"
10 
11 /* Base class for diagnostics */
12 class Diagnostic{
13 #ifdef ADIOS2
14  ADIOS2Stream stream;
15 #endif
16 
17  protected:
18 
19  // These can be set by a derived class
20  StepTrigger step_trigger; // Triggers when it is time to call this diagnostic
21 
22  public:
23 
24  bool is_on;
25 
26  /* Returns whether this diagnostic should be executed on this step
27  * */
28  bool is_triggered(int step){
29  return step_trigger.is_triggered(step);
30  }
31 
32  /* Returns whether or not we have passed the first trigger yet
33  * */
34  bool has_been_triggered(int step){
35  return step_trigger.has_been_triggered(step);
36  }
37 
38  // Default constructor for use if diagnostic is not used
40  : is_on(false){}
41  // Constructor if used: Set up stream and trigger
42  void init(const std::string& name, int period, int first_step=-1){
43 #ifdef ADIOS2
44  stream.Init(name);
45 #endif
46  is_on = true;
47  if(first_step==-1){
48  // Use default if no first step provided
49  step_trigger = StepTrigger(period);
50  }else{
51  step_trigger = StepTrigger(period, first_step);
52  }
53  }
54 #ifdef ADIOS2
55 
63  void open_stream(const std::string& filename, const adios2::Mode& mode){
64  stream.Open(filename, mode);
65  }
66 
76  void open_stream(const std::string& filename, const adios2::Mode& mode, const MPI_Comm& comm){
77  stream.Open(filename, mode, comm);
78  }
79 
85  void close_stream(){
86  stream.Close();
87  }
88 
89  // Every diagnostic will have its own custom write since they will vary significantly in structure
90  void write(const ADIOS2_IO& adios2_io){
91  adios2_io.write(stream);
92  }
93 
94  void start_write_step(){
95  stream.engine->BeginStep();
96  }
97 
98  bool is_first_step(){
99  return (stream.engine->CurrentStep() == 0);
100  }
101 
102  void end_write_step(){
103  stream.engine->EndStep();
104  }
105 #endif
106 };
107 
108 #endif
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:42
bool is_on
Definition: diagnostic.hpp:24
Definition: adios2.hpp:26
bool is_triggered(int step)
Definition: step_trigger.hpp:23
bool is_triggered(int step)
Definition: diagnostic.hpp:28
bool has_been_triggered(int step)
Definition: diagnostic.hpp:34
Diagnostic()
Definition: diagnostic.hpp:39
Definition: diagnostic.hpp:12
Definition: step_trigger.hpp:4
StepTrigger step_trigger
Definition: diagnostic.hpp:20