SENSEI
A frame work for generic in situ analytics
DataBinning.h
1 #ifndef DataBinning_h
2 #define DataBinning_h
3 
4 #include "AnalysisAdaptor.h"
5 #include <mpi.h>
6 #include <vector>
7 #include <thread>
8 #include <future>
9 #include <list>
10 
11 /// @cond
12 namespace pugi { class xml_node; }
13 /// @endcond
14 
15 namespace sensei
16 {
17 /** Bins a set of arrays onto a user defined uniform Cartesian mesh. The
18  * binning operations supported are: min, max, and sum. A count is always
19  * computed. From count and sum bin averages can be obtained. At each time
20  * step the results are stored on disk in VTK format. Binning can be used to
21  * compute phase space plots or visualize particle data using mesh based
22  * visualization techniques.
23  */
24 class SENSEI_EXPORT DataBinning : public AnalysisAdaptor
25 {
26 public:
27  /// allocates a new instance
28  static DataBinning* New();
29  senseiTypeMacro(DataBinning, AnalysisAdaptor);
30 
31  /// When set binning runs in a thread and ::Execute returns immediately
32  void SetAsynchronous(int val) override;
33 
34  /** set the name of the mesh and arrays to request from the simulation.
35  * Sets the output image resolution and the name of a file to write them in.
36  * the substring %t% is replaced with the current simulation time step. if
37  * one of resx or resy is -1 it is calculated from the data's aspect ratio
38  * so that image pixels are square.
39  */
40  int Initialize(const std::string &meshName,
41  const std::string &xAxisArray,
42  const std::string &yAxisArray,
43  const std::vector<std::string> &binnedArray,
44  const std::vector<std::string> &operation,
45  long xres, long yres, const std::string &outDir,
46  int returnData, int maxThreads);
47 
48  /** Initialize from XML
49  * Input mesh, coordinate axis arrays, grid resolution, and output path are
50  * specified as attributes.
51  *
52  * The supported attributes are:
53  * | attribute | description |
54  * | --------- | ----------- |
55  * | mesh | names the mesh to process |
56  * | x_axis | names the array to use as x-axis coordinates |
57  * | y_axis | names the array to use as y-axis coordinates |
58  * | out_dir | the path to write results to |
59  * | x_res | the grid resolution to bin to in the x-direction |
60  * | y_res | the grid resolution to bin to in the y-direction |
61  * | return_data | set to 1 to return a data adaptor w/ the results |
62  * | max_threads | the max number of threads to use |
63  *
64  * Nested elements:
65  * | element | description |
66  * | arrays | a list of comma or space delimited array names to bin |
67  * | operations | a list of comma or space delimited binning operations |
68  *
69  * The arrays to bin and binning operations are specified in a nested
70  * elements with a space or comma delimited lists. There must be an operation
71  * specified for each array.
72  */
73  int Initialize(pugi::xml_node node);
74 
75  /// compute the histogram for this time step
76  bool Execute(DataAdaptor* data, DataAdaptor**) override;
77 
78  /// finalize the run
79  int Finalize() override;
80 
81  /// The supported binning operations
82  enum {INVALID_OP, BIN_SUM, BIN_AVG, BIN_MIN, BIN_MAX};
83 
84  /** converts the string to the corresponding enumeration.
85  * @param[in] opName string naming the operation(one of: "sum", "avg", "min", "max")
86  * @param[out] opCode the enumerated value
87  * @returns zero if successful
88  */
89  static int GetOperation(const std::string &opName, int &opCode);
90 
91  /** converts the enumeration to a string
92  * @param[in] opCode the enumerated value(one of: BIN_SUM, BIN_AVG, BIN_MIN, BIN_MAX)
93  * @param[out] opName string naming the operation
94  * @returns zero if successful
95  */
96  static int GetOperation(int opCode, std::string &opName);
97 
98 protected:
99  DataBinning();
100  ~DataBinning();
101 
102  DataBinning(const DataBinning&) = delete;
103  void operator=(const DataBinning&) = delete;
104 
105  void InitializeThreads();
106  int WaitThreads();
107 
108  long XRes;
109  long YRes;
110  std::string OutDir;
111  unsigned long Iteration;
112  double AxisFactor;
113  std::string MeshName;
114  std::string XAxisArray;
115  std::string YAxisArray;
116  std::vector<std::string> BinnedArray;
117  std::vector<int> Operation;
118  int ReturnData;
119  int MaxThreads;
120  std::vector<std::future<int>> Threads;
121  std::vector<MPI_Comm> ThreadComm;
122 };
123 
124 }
125 
126 #endif
int Initialize(MPI_Comm comm, const std::string &fileName, InTransitDataAdaptor *&dataAdaptor)
Creates a sensei::ConfigurableAnalysis adaptor and sensei::InTransitDataAdaptor based on a SENSEI XML...
The base class for data consumers.
Definition: AnalysisAdaptor.h:24
Bins a set of arrays onto a user defined uniform Cartesian mesh.
Definition: DataBinning.h:24
SENSEI.
Definition: ADIOS2AnalysisAdaptor.h:27
Definition: ADIOS2DataAdaptor.h:10
Base class that defines the interface for fetching data from a simulation.
Definition: DataAdaptor.h:25