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 #include "host_array.hpp"
8 
9 /* Base class for diagnostics */
10 class Diagnostic{
11  HostArray<XGC_IO_Stream> stream; // Make this a HostArray so that Diagnostics can be sent to device and not invoke the stream destructor
12 
13  protected:
14 
15  // These can be set by a derived class
16  StepTrigger step_trigger; // Triggers when it is time to call this diagnostic
17 
18  public:
19 
20  bool is_on;
21 
22  /* Returns whether this diagnostic should be executed on this step
23  * */
24  bool is_triggered(int step){
25  return step_trigger.is_triggered(step);
26  }
27 
28  /* Returns whether or not we have passed the first trigger yet
29  * */
30  bool has_been_triggered(int step){
31  return step_trigger.has_been_triggered(step);
32  }
33 
34  /* Returns period in steps
35  * */
36  int get_period() const{
37  return step_trigger.get_period();
38  }
39 
40  // Default constructor for use if diagnostic is not used
42  : stream(1),
43  is_on(false){}
44 
45  // Constructor if used: Set up stream and trigger
46  void init(const std::string& name, int period, int first_step=-1){
47  stream(0).Init(name);
48 
49  is_on = true;
50  if(first_step==-1){
51  // Use default if no first step provided
52  step_trigger = StepTrigger(period);
53  }else{
54  step_trigger = StepTrigger(period, first_step);
55  }
56  }
57 
66  void open_stream(const std::string& filename, const XGC_IO_Mode& mode){
67  stream(0).Open(filename, mode);
68  }
69 
70 #ifdef USE_MPI
71 
80  void open_stream(const std::string& filename, const XGC_IO_Mode& mode, const MPI_Comm& comm){
81  stream(0).Open(filename, mode, comm);
82  }
83 #endif
84 
90  void close_stream(){
91  stream(0).Close();
92  }
93 
94  // Every diagnostic will have its own custom write since they will vary significantly in structure
95  void write(const XGC_IO& xgc_io){
96  xgc_io.write(stream(0));
97  }
98 
100 #ifdef ADIOS2
101  stream(0).engine->BeginStep();
102 #endif
103  }
104 
106 #ifdef ADIOS2
107  return (stream(0).engine->CurrentStep() == 0);
108 #else
109  return true;
110 #endif
111  }
112 
114 #ifdef ADIOS2
115  stream(0).engine->EndStep();
116 #endif
117  }
118 };
119 
120 #endif
void write(const XGC_IO_Stream &stream) const
Definition: xgc_io.hpp:211
Definition: xgc_io.hpp:192
bool has_been_triggered(int step) const
Definition: step_trigger.hpp:35
void init(const std::string &name, int period, int first_step=-1)
Definition: diagnostic.hpp:46
bool is_on
Definition: diagnostic.hpp:20
HostArray< XGC_IO_Stream > stream
Definition: diagnostic.hpp:11
void start_write_step()
Definition: diagnostic.hpp:99
void close_stream()
Definition: diagnostic.hpp:90
void open_stream(const std::string &filename, const XGC_IO_Mode &mode)
Definition: diagnostic.hpp:66
bool is_triggered(int step) const
Definition: step_trigger.hpp:25
void end_write_step()
Definition: diagnostic.hpp:113
bool is_triggered(int step)
Definition: diagnostic.hpp:24
int get_period() const
Definition: diagnostic.hpp:36
void write(const XGC_IO &xgc_io)
Definition: diagnostic.hpp:95
int get_period() const
Definition: step_trigger.hpp:41
XGC_IO_Mode
Definition: xgc_io.hpp:17
bool has_been_triggered(int step)
Definition: diagnostic.hpp:30
Diagnostic()
Definition: diagnostic.hpp:41
Definition: diagnostic.hpp:10
Definition: step_trigger.hpp:4
bool is_first_step()
Definition: diagnostic.hpp:105
StepTrigger step_trigger
Definition: diagnostic.hpp:16