SENSEI
A frame work for generic in situ analytics
DataAdaptor.h
1 #ifndef sensei_DataAdaptor_h
2 #define sensei_DataAdaptor_h
3 
4 #include "senseiConfig.h"
5 #include "MeshMetadata.h"
6 
7 #include <svtkObjectBase.h>
8 
9 #include <vector>
10 #include <string>
11 #include <mpi.h>
12 #include <memory>
13 
14 class svtkAbstractArray;
15 class svtkDataObject;
16 class svtkCompositeDataSet;
17 
18 namespace sensei
19 {
20 
21 /** Base class that defines the interface for fetching data from a simulation.
22  * Simulation codes provide an implementation of this interface which is used
23  * by data consumers to fetch simulation data for processing, movement, or I/O.
24  */
25 class SENSEI_EXPORT DataAdaptor : public svtkObjectBase
26 {
27 public:
28  senseiBaseTypeMacro(DataAdaptor, svtkObjectBase);
29 
30  /// Prints the current state of the adaptor.
31  void PrintSelf(ostream& os, svtkIndent indent) override;
32 
33  /** Set the communicator used by the adaptor. The default communicator is a
34  * duplicate of MPI_COMMM_WORLD, giving each adaptor a unique communication
35  * space. Users wishing to override this should set the communicator before
36  * doing anything else. Derived classes should use the communicator returned
37  * by GetCommunicator.
38  */
39  virtual int SetCommunicator(MPI_Comm comm);
40 
41  /// Get the communicator used by the adaptor.
42  MPI_Comm GetCommunicator() { return this->Comm; }
43 
44  /** Gets the number of meshes a simulation can provide. The caller passes a
45  * reference to an integer variable in the first argument upon return this
46  * variable contains the number of meshes the simulation can provide. If
47  * successfull the method returns 0, a non-zero return indicates an error
48  * occurred.
49  *
50  * @param[out] numMeshes an integer variable where number of meshes is stored
51  * @returns zero if successful, non zero if an error occurred
52  */
53  virtual int GetNumberOfMeshes(unsigned int &numMeshes) = 0;
54 
55  /** Get metadata of the i'th mesh. The caller passes the integer id of the
56  * mesh for which the metadata is desired, and a pointer to a MeshMetadata
57  * instance where the metadata is stored.
58  *
59  * @param[in] id index of the mesh to access
60  * @param[out] metadata a pointer to instance where metadata is stored
61  * @returns zero if successful, non zero if an error occurred
62  */
63  virtual int GetMeshMetadata(unsigned int id, sensei::MeshMetadataPtr &metadata) = 0;
64 
65  /** Fetches the requested data object from the simulation. This method will
66  * return a svtkDataObject containing the simulation state. Implementers
67  * should prefer svtkMultiBlockData over svtkDataSet types. However, both
68  * approaches are supported. Callers should typically pass \c structureOnly
69  * to false. Caller may set \c stuctureOnly to true when data arrays without
70  * mesh geometry and connectivity are sufficient for processing. If \c
71  * structureOnly is set to true, then implementers should not populate the
72  * mesh geometry and connectivity information. This can result in large
73  * savings in data transfer.
74  *
75  * @note Callers are to take ownership of the newly allocated mesh and must
76  * Delete the returned mesh when finished to prevent a memory leak.
77  *
78  * @param[in] meshName the name of the mesh to access (see GetMeshMetadata)
79  * @param[in] structureOnly When set to true the returned mesh
80  * may not have any geometry or topology information.
81  * @param[out] mesh a reference to a pointer where a new VTK object is stored
82  * @returns zero if successful, non zero if an error occurred
83  */
84  virtual int GetMesh(const std::string &meshName, bool structureOnly,
85  svtkDataObject *&mesh) = 0;
86 
87  /** Adds ghost nodes on the specified mesh. Implementers shouls set the name
88  * of the array to "svtkGhostType".
89  *
90  * @param[in] mesh the VTK object returned from GetMesh
91  * @param[in] meshName the name of the mesh to access (see GetMeshMetadata)
92  * @returns zero if successful, non zero if an error occurred
93  */
94  virtual int AddGhostNodesArray(svtkDataObject* mesh, const std::string &meshName);
95 
96  /** Adds ghost cells on the specified mesh. Implementers should set the array name to
97  * "svtkGhostType".
98  *
99  * @param[in] mesh the svtkDataObject returned from GetMesh
100  * @param[in] meshName the name of the mesh to access (see GetMeshMetadata)
101  * @returns zero if successful, non zero if an error occurred
102  */
103  virtual int AddGhostCellsArray(svtkDataObject* mesh, const std::string &meshName);
104 
105  /** Fetches the named array from the simulation and adds it to the passed
106  * mesh. Implementers should pass the data by zero copy when possible. See
107  * svtkAOSDataArrayTemplate and svtkSOADataArrayTemplate for details of passing
108  * data zero copy.
109  *
110  * @param[in] mesh the VTK object returned from GetMesh
111  * @param[in] meshName the name of the mesh on which the array is stored
112  * @param[in] association field association; one of
113  * svtkDataObject::FieldAssociations or svtkDataObject::AttributeTypes.
114  * @param[in] arrayName name of the array
115  * @returns zero if successful, non zero if an error occurred
116  */
117  virtual int AddArray(svtkDataObject* mesh, const std::string &meshName,
118  int association, const std::string &arrayName) = 0;
119 
120  /** Fetches multiple arrays from the simulation and adds them to the mesh.
121  * Implementers typically do not have to override this method.
122  *
123  * @param[in] mesh the VTK object returned from GetMesh
124  * @param[in] meshName the name of the mesh on which the array is stored
125  * @param[in] association field association; one of
126  * svtkDataObject::FieldAssociations or svtkDataObject::AttributeTypes.
127  * @param[in] arrayNames vector of array names to add
128  * @returns zero if successful, non zero if an error occurred
129  */
130  virtual int AddArrays(svtkDataObject* mesh, const std::string &meshName,
131  int association, const std::vector<std::string> &arrayNames);
132 
133  /** Release data allocated for the current timestep. This method allows implementers to
134  * free resources that were used in the conversion of the simulation data.
135  * However, note that callers of GetMesh must Delete the returned
136  * svtkDataObject which typically alleviates the need for the adaptor to hold
137  * references to the returned data. In most cases this method should not be overridden.
138  *
139  * @note The instrumentation (or bridge) code must call this method when
140  * done processing a time step to ensure that all resources are released.
141  * Analysis adaptors should not call this method.
142  *
143  * @returns zero if successful, non zero if an error occurred
144  */
145  virtual int ReleaseData() { return 0; }
146 
147  /// Get the current simulated time.
148  virtual double GetDataTime();
149 
150  /** Set the current simulated time. The default implementation stores the
151  * passed time. Implemetors typically call this method rather than
152  * overriding the method.
153  */
154  virtual void SetDataTime(double time);
155 
156  /// Get the current time step.
157  virtual long GetDataTimeStep();
158 
159  /** Set the current simulated time step. The default implementation stores the
160  * passed time step. Implemetors typically call this method rather than
161  * overriding the method.
162  */
163  virtual void SetDataTimeStep(long index);
164 
165 protected:
166  DataAdaptor();
167  ~DataAdaptor();
168 
169  DataAdaptor(const DataAdaptor&) = delete;
170  void operator=(const DataAdaptor&) = delete;
171 
172  struct InternalsType;
173  InternalsType *Internals;
174 
175  MPI_Comm Comm;
176 };
177 
178 }
179 #endif
virtual int ReleaseData()
Release data allocated for the current timestep.
Definition: DataAdaptor.h:145
SENSEI.
Definition: ADIOS2AnalysisAdaptor.h:27
Base class that defines the interface for fetching data from a simulation.
Definition: DataAdaptor.h:25
MPI_Comm GetCommunicator()
Get the communicator used by the adaptor.
Definition: DataAdaptor.h:42