SENSEI
A frame work for generic in situ analytics
MeshMetadata.h
1 #ifndef MeshMetadata_h
2 #define MeshMetadata_h
3 
4 #include "senseiConfig.h"
5 #include "BinaryStream.h"
6 
7 #include <mpi.h>
8 #include <ostream>
9 #include <vector>
10 #include <vector>
11 #include <string>
12 #include <memory>
13 
14 namespace sensei
15 {
16 /** a set of flags describing which optional fields in the MeshMetadata
17  * structure should be generated.
18  */
19 class SENSEI_EXPORT MeshMetadataFlags
20 {
21 public:
22  MeshMetadataFlags() : Flags(0) {}
23  MeshMetadataFlags(long long flags) : Flags(flags) {}
24 
25  void SetAll(){ Flags = 0xffffffffffffffff; }
26  void ClearAll(){ Flags = 0; }
27 
28  // The following API is used to enable optional metadata. This
29  // metadata is crucial for some appilications but can be expensive
30  // to generate, thus it is only provided when requested.
31 
32  /** set, clear, or check flag to generate arrays describing
33  * the domain decomposition. This incudles MPI rank block ownership
34  * arrays (MeshMetadata.BlockOwner and MeshMetadata.BlockIds)
35  */
36  void SetBlockDecomp(){ Flags |= DECOMP; }
37  /// @copydoc SetBlockDecomp
38  void ClearBlockDecomp(){ Flags &= ~DECOMP; }
39  /// @copydoc SetBlockDecomp
40  bool BlockDecompSet() const { return Flags & DECOMP; }
41 
42  /** set, clear, or check flag to generate global and block size arrays
43  * MeshMetadata.BlockNumPoints, MeshMetadata.BlockNumCells, and
44  * MeshMetadata.BlockCellArraySize)
45  */
46  void SetBlockSize(){ Flags |= SIZE; }
47  /// @copydoc SetBlockSize
48  void ClearBlockSize(){ Flags &= ~SIZE; }
49  /// @copydoc SetBlockSize
50  bool BlockSizeSet() const { return Flags & SIZE; }
51 
52  /** set, clear, or check flag to generate block extent arrays
53  * MeshMetadata.BlockExtents
54  */
55  void SetBlockExtents(){ Flags |= EXTENTS; }
56  /// @copydoc SetBlockExtents
57  void ClearBlockExtents(){ Flags &= ~EXTENTS; }
58  /// @copydoc SetBlockExtents
59  bool BlockExtentsSet() const { return Flags & EXTENTS; }
60 
61  /** set, clear, or check flag to generate block bounds arrays
62  * MeshMetaData.BlockBounds
63  */
64  void SetBlockBounds(){ Flags |= BOUNDS; }
65  /// @copydoc SetBlockBounds
66  void ClearBlockBounds(){ Flags &= ~BOUNDS; }
67  /// @copydoc SetBlockBounds
68  bool BlockBoundsSet() const { return Flags & BOUNDS; }
69 
70  /** set, clear, or check flag to generate block array ranges
71  * (MeshMetadata.BlockArrayRange)
72  */
73  void SetBlockArrayRange(){ Flags |= RANGE; }
74  /// @copydoc SetBlockArrayRange
75  void ClearBlockArrayRange(){ Flags &= ~RANGE; }
76  /// @copydoc SetBlockArrayRange
77  bool BlockArrayRangeSet() const { return Flags & RANGE; }
78 
79 
80  /// serialize for communication and/or I/O
81  int ToStream(sensei::BinaryStream &str) const;
82 
83  /// deserialize for communication and/or I/O
84  int FromStream(sensei::BinaryStream &str);
85 
86  /// serialize for human readable I/O
87  int ToStream(ostream &str) const;
88 
89 private:
90 
91  /** flags indicate which optional fields are needed some feilds are optional
92  * because they are costly to generate and not universally used on the
93  * analysis side. see Set/Clear methods above.
94  */
95  long long Flags;
96 
97  /// flag values
98  enum { DECOMP = 0x1, SIZE = 0x2, EXTENTS = 0x4,
99  BOUNDS = 0x8, RANGE = 0x10 };
100 };
101 
102 
103 
104 struct MeshMetadata;
105 using MeshMetadataPtr = std::shared_ptr<sensei::MeshMetadata>;
106 
107 /// A container for capturing metadata describing a mesh.
108 struct SENSEI_EXPORT MeshMetadata
109 {
110  /// allocate a new instance
111  static
112  sensei::MeshMetadataPtr New() { return MeshMetadataPtr(new MeshMetadata); }
113 
114  /// allocate a new instance intialize the flags
115  static
116  sensei::MeshMetadataPtr New(const MeshMetadataFlags flags)
117  {
118  MeshMetadataPtr mdp = MeshMetadataPtr(new MeshMetadata);
119  mdp->Flags = flags;
120  return mdp;
121  }
122 
123  /// copy the meatdata in a new instance
124  sensei::MeshMetadataPtr NewCopy()
125  {
126  MeshMetadataPtr md = MeshMetadata::New();
127  *md = *this;
128  return md;
129  }
130 
131  /// serialize/deserialize for communication and/or I/O
132  int ToStream(sensei::BinaryStream &str) const;
133 
134  /// serialize/deserialize for communication and/or I/O
135  int FromStream(sensei::BinaryStream &str);
136 
137  /// serialize/deserialize for communication and/or I/O
138  int ToStream(ostream &str) const;
139 
140  /** return true if the Flags match the arrays. will return false
141  * if the a flag is set and a coresponding array is empty. an
142  * error message will be printed naming the missing the array
143  * this method tries to be context sensative. for instance if
144  * the extents flag was set but the simulation reports unstructured
145  * data no error will be issued. Optionally a set of required flags
146  * may be specified. Only errors in fields with corresponding bits set are
147  * reported. This lets you have optional fields and handle the error on
148  * your own. Finally some convenience functionality is packaged here
149  * for instance global extents and bounds are automatically generated
150  * if requested but not provided.
151  */
152  int Validate(MPI_Comm comm,
153  const sensei::MeshMetadataFlags &requiredFlags = 0xffffffffffffffff);
154 
155  /** construct a global view of the metadata. return 0 if successful.
156  * this call uses MPI collectives
157  */
158  int GlobalizeView(MPI_Comm);
159 
160  /** removes all block level information from the instance. initialize
161  * the related dataset level information.
162  */
163  int ClearBlockInfo();
164 
165  /// appends block level information of block bid from other.
166  int CopyBlockInfo(const sensei::MeshMetadataPtr &other, int bid);
167 
168  /// removes all array metadata from the instance
169  int ClearArrayInfo();
170 
171  /// appends metadata for the named array to the instance
172  int CopyArrayInfo(const sensei::MeshMetadataPtr &other,
173  const std::string &arrayName);
174 
175  // metadata: the following metadata fields are available. fields marked
176  // "all" are required for all mesh types. other fields may be required for
177  // specific mesh types as indicated and/or be optional. optional fields are
178  // expensive to generate and only generated when their corresponding flag is
179  // see. See MeshMetadataFlags. AMR metadata is stored in flat arrays, first
180  // level 0, then level 1 and so on until the finest level. The index of the
181  // array will give you the SVTK composite dataset index,
182 
183  bool GlobalView; //< tells if the information describes data on this rank or all ranks.
184  // Passed into Set methods, Get methods generate the desired view.
185 
186  std::string MeshName; ///< name of mesh (all)
187  int MeshType; ///< container mesh type. see svtkType.h (all)
188  int BlockType; ///< block mesh type. see svtkType.h (all)
189  int NumBlocks; ///< global number of blocks (all)
190  std::vector<int> NumBlocksLocal; ///< number of blocks on each rank (all)
191  std::array<int,6> Extent; ///< global cell index space extent (Cartesian, AMR, optional)
192  std::array<double,6> Bounds; ///< global bounding box (all, optional)
193  int CoordinateType; ///< type enum of point data (unstructured, optional)
194  long NumPoints; ///< total number of points in all blocks (all, optional)
195  long NumCells; ///< total number of cells in all blocks (all, optional)
196  long CellArraySize; ///< total cell array size in all blocks (unstructured, optional)
197  int CellArrayType; ///< element type of the cell array (unstructured, optional)
198  int NumArrays; ///< number of arrays (all)
199  int NumGhostCells; ///< number of ghost cell layers (all)
200  int NumGhostNodes; ///< number of ghost node layers (all)
201  int NumLevels; ///< number of AMR levels (AMR)
202  int StaticMesh; ///< non zero if the mesh does not change in time (all)
203 
204  std::vector<std::string> ArrayName; ///< name of each data array (all)
205  std::vector<int> ArrayCentering; ///< centering of each data array (all)
206  std::vector<int> ArrayComponents; ///< number of components of each array (all)
207  std::vector<int> ArrayType; ///< type enum of each data array (all)
208  std::vector<std::array<double,2>> ArrayRange; ///< global min,max of each array (all, optional)
209 
210  std::vector<int> BlockOwner; ///< rank where each block resides (all, optional)
211  std::vector<int> BlockIds; ///< global id of each block (all, optional)
212 
213  ///< note: for AMR BlockNumPoints and BlockNumCells are always global
214  std::vector<long> BlockNumPoints; ///< number of points for each block (all, optional)
215  std::vector<long> BlockNumCells; ///< number of cells for each block (all, optional)
216  std::vector<long> BlockCellArraySize; ///< cell array size for each block (unstructured, optional)
217 
218  // note: for AMR BlockExtents and BlockBounds are always global
219  std::vector<std::array<int,6>> BlockExtents; //< index space extent of each block [i0,i1, j0,j1, k0,k1] (Cartesian, AMR, optional)
220  std::vector<std::array<double,6>> BlockBounds; //< bounds of each block [x0,x1, y0,y1, z0,z1] (all, optional)
221 
222  std::vector<std::vector<std::array<double,2>>> BlockArrayRange; //< min max of each array on each block.
223  // indexed by block then array. (all, optional)
224 
225  std::vector<std::array<int,3>> RefRatio; //< refinement ratio in i,j, and k directions for each level (AMR)
226  std::vector<int> BlocksPerLevel; //< number of blocks in each level (AMR)
227  std::vector<int> BlockLevel; //< AMR level of each block (AMR)
228  std::array<int,3> PeriodicBoundary; //< flag indicating presence of a periodic boundary in the i,j,k direction (all)
229 
230 
231  sensei::MeshMetadataFlags Flags; //< flags indicate which optional fields are needed
232  // some feilds are optional because they are costly
233  // to generate and not universally used on the analysis
234  // side.
235 
236 protected:
237  MeshMetadata() : GlobalView(false), MeshName(),
238  MeshType(SVTK_MULTIBLOCK_DATA_SET), BlockType(SVTK_DATA_SET), NumBlocks(0),
239  NumBlocksLocal(), Extent(), Bounds(), CoordinateType(SVTK_DOUBLE),
240  NumPoints(0), NumCells(0), CellArraySize(0), CellArrayType(SVTK_TYPE_INT64),
241  NumArrays(0), NumGhostCells(0), NumGhostNodes(0), NumLevels(0),
242  StaticMesh(0), ArrayName(), ArrayCentering(), ArrayType(),
243  ArrayRange(),BlockOwner(), BlockIds(), BlockNumPoints(), BlockNumCells(),
244  BlockCellArraySize(), BlockExtents(), BlockBounds(), BlockArrayRange(),
245  RefRatio(), BlocksPerLevel(), BlockLevel(), PeriodicBoundary(), Flags()
246  {}
247 };
248 
249 };
250 
251 #endif
a set of flags describing which optional fields in the MeshMetadata structure should be generated...
Definition: MeshMetadata.h:19
Definition: BinaryStream.h:19
std::vector< int > ArrayType
type enum of each data array (all)
Definition: MeshMetadata.h:207
int StaticMesh
non zero if the mesh does not change in time (all)
Definition: MeshMetadata.h:202
std::vector< int > BlockIds
global id of each block (all, optional)
Definition: MeshMetadata.h:211
A container for capturing metadata describing a mesh.
Definition: MeshMetadata.h:108
bool BlockArrayRangeSet() const
set, clear, or check flag to generate block array ranges (MeshMetadata.BlockArrayRange) ...
Definition: MeshMetadata.h:77
void SetBlockArrayRange()
set, clear, or check flag to generate block array ranges (MeshMetadata.BlockArrayRange) ...
Definition: MeshMetadata.h:73
void SetBlockSize()
set, clear, or check flag to generate global and block size arrays MeshMetadata.BlockNumPoints, MeshMetadata.BlockNumCells, and MeshMetadata.BlockCellArraySize)
Definition: MeshMetadata.h:46
std::vector< int > NumBlocksLocal
number of blocks on each rank (all)
Definition: MeshMetadata.h:190
int NumBlocks
global number of blocks (all)
Definition: MeshMetadata.h:189
int NumLevels
number of AMR levels (AMR)
Definition: MeshMetadata.h:201
void SetBlockBounds()
set, clear, or check flag to generate block bounds arrays MeshMetaData.BlockBounds ...
Definition: MeshMetadata.h:64
void ClearBlockExtents()
set, clear, or check flag to generate block extent arrays MeshMetadata.BlockExtents ...
Definition: MeshMetadata.h:57
long NumPoints
total number of points in all blocks (all, optional)
Definition: MeshMetadata.h:194
void ClearBlockSize()
set, clear, or check flag to generate global and block size arrays MeshMetadata.BlockNumPoints, MeshMetadata.BlockNumCells, and MeshMetadata.BlockCellArraySize)
Definition: MeshMetadata.h:48
std::vector< long > BlockNumCells
number of cells for each block (all, optional)
Definition: MeshMetadata.h:215
std::vector< int > ArrayComponents
number of components of each array (all)
Definition: MeshMetadata.h:206
std::array< double, 6 > Bounds
global bounding box (all, optional)
Definition: MeshMetadata.h:192
std::vector< std::array< double, 2 > > ArrayRange
global min,max of each array (all, optional)
Definition: MeshMetadata.h:208
void ClearBlockBounds()
set, clear, or check flag to generate block bounds arrays MeshMetaData.BlockBounds ...
Definition: MeshMetadata.h:66
bool BlockBoundsSet() const
set, clear, or check flag to generate block bounds arrays MeshMetaData.BlockBounds ...
Definition: MeshMetadata.h:68
long CellArraySize
total cell array size in all blocks (unstructured, optional)
Definition: MeshMetadata.h:196
std::array< int, 6 > Extent
global cell index space extent (Cartesian, AMR, optional)
Definition: MeshMetadata.h:191
void SetBlockDecomp()
set, clear, or check flag to generate arrays describing the domain decomposition. ...
Definition: MeshMetadata.h:36
sensei::MeshMetadataPtr NewCopy()
copy the meatdata in a new instance
Definition: MeshMetadata.h:124
int CellArrayType
element type of the cell array (unstructured, optional)
Definition: MeshMetadata.h:197
void SetBlockExtents()
set, clear, or check flag to generate block extent arrays MeshMetadata.BlockExtents ...
Definition: MeshMetadata.h:55
std::vector< long > BlockNumPoints
number of points for each block (all, optional)
Definition: MeshMetadata.h:214
bool BlockSizeSet() const
set, clear, or check flag to generate global and block size arrays MeshMetadata.BlockNumPoints, MeshMetadata.BlockNumCells, and MeshMetadata.BlockCellArraySize)
Definition: MeshMetadata.h:50
static sensei::MeshMetadataPtr New(const MeshMetadataFlags flags)
allocate a new instance intialize the flags
Definition: MeshMetadata.h:116
void ClearBlockDecomp()
set, clear, or check flag to generate arrays describing the domain decomposition. ...
Definition: MeshMetadata.h:38
std::vector< long > BlockCellArraySize
cell array size for each block (unstructured, optional)
Definition: MeshMetadata.h:216
std::string MeshName
name of mesh (all)
Definition: MeshMetadata.h:186
bool BlockExtentsSet() const
set, clear, or check flag to generate block extent arrays MeshMetadata.BlockExtents ...
Definition: MeshMetadata.h:59
SENSEI.
Definition: ADIOS2AnalysisAdaptor.h:27
int CoordinateType
type enum of point data (unstructured, optional)
Definition: MeshMetadata.h:193
static sensei::MeshMetadataPtr New()
allocate a new instance
Definition: MeshMetadata.h:112
long NumCells
total number of cells in all blocks (all, optional)
Definition: MeshMetadata.h:195
std::vector< int > ArrayCentering
centering of each data array (all)
Definition: MeshMetadata.h:205
std::vector< std::string > ArrayName
name of each data array (all)
Definition: MeshMetadata.h:204
bool BlockDecompSet() const
set, clear, or check flag to generate arrays describing the domain decomposition. ...
Definition: MeshMetadata.h:40
int MeshType
container mesh type. see svtkType.h (all)
Definition: MeshMetadata.h:187
std::vector< int > BlockOwner
rank where each block resides (all, optional)
Definition: MeshMetadata.h:210
int NumGhostNodes
number of ghost node layers (all)
Definition: MeshMetadata.h:200
int NumArrays
number of arrays (all)
Definition: MeshMetadata.h:198
int NumGhostCells
number of ghost cell layers (all)
Definition: MeshMetadata.h:199
void ClearBlockArrayRange()
set, clear, or check flag to generate block array ranges (MeshMetadata.BlockArrayRange) ...
Definition: MeshMetadata.h:75
int BlockType
block mesh type. see svtkType.h (all)
Definition: MeshMetadata.h:188