1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkXdmfWriter.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 16 /** 17 * @class vtkXdmfWriter 18 * @brief write eXtensible Data Model and Format files 19 * 20 * vtkXdmfWriter converts vtkDataObjects to XDMF format. This is intended to 21 * replace vtkXdmfWriter, which is not up to date with the capabilities of the 22 * newer XDMF2 library. This writer understands VTK's composite data types and 23 * produces full trees in the output XDMF files. 24 */ 25 26 #ifndef vtkXdmfWriter_h 27 #define vtkXdmfWriter_h 28 29 #include "vtkIOXdmf2Module.h" // For export macro 30 31 #include "vtkDataObjectAlgorithm.h" 32 33 #include <string> // Needed for private members 34 #include <vector> // 35 36 class vtkExecutive; 37 38 class vtkCompositeDataSet; 39 class vtkDataArray; 40 class vtkDataSet; 41 class vtkDataObject; 42 class vtkFieldData; 43 class vtkInformation; 44 class vtkInformationVector; 45 class vtkXdmfWriterDomainMemoryHandler; 46 47 namespace xdmf2 48 { 49 class XdmfArray; 50 class XdmfDOM; 51 class XdmfElement; 52 class XdmfGrid; 53 class XdmfGeometry; 54 class XdmfTopology; 55 } 56 57 class VTKIOXDMF2_EXPORT vtkXdmfWriter : public vtkDataObjectAlgorithm 58 { 59 public: 60 static vtkXdmfWriter* New(); 61 vtkTypeMacro(vtkXdmfWriter, vtkDataObjectAlgorithm); 62 void PrintSelf(ostream& os, vtkIndent indent) override; 63 64 /** 65 * Set the input data set. 66 */ 67 virtual void SetInputData(vtkDataObject* dobj); 68 69 ///@{ 70 /** 71 * Set or get the file name of the xdmf file. 72 */ 73 vtkSetFilePathMacro(FileName); 74 vtkGetFilePathMacro(FileName); 75 ///@} 76 77 ///@{ 78 /** 79 * Set or get the file name of the hdf5 file. 80 * Note that if the File name is not specified, then the group name is ignore 81 */ 82 vtkSetFilePathMacro(HeavyDataFileName); 83 vtkGetFilePathMacro(HeavyDataFileName); 84 ///@} 85 86 ///@{ 87 /** 88 * Set or get the group name into which data will be written 89 * it may contain nested groups as in "/Proc0/Block0" 90 */ 91 vtkSetStringMacro(HeavyDataGroupName); 92 vtkGetStringMacro(HeavyDataGroupName); 93 ///@} 94 95 /** 96 * Write data to output. Method executes subclasses WriteData() method, as 97 * well as StartMethod() and EndMethod() methods. 98 * Returns 1 on success and 0 on failure. 99 */ 100 virtual int Write(); 101 102 ///@{ 103 /** 104 * Topology Geometry and Attribute arrays smaller than this are written in line into the XML. 105 * Default is 100. 106 * Node: LightDataLimit is forced to 1 when MeshStaticOverTime is TRUE. 107 */ 108 vtkSetMacro(LightDataLimit, int); 109 vtkGetMacro(LightDataLimit, int); 110 ///@} 111 112 ///@{ 113 /** 114 * Controls whether writer automatically writes all input time steps, or 115 * just the timestep that is currently on the input. 116 * Default is OFF. 117 */ 118 vtkSetMacro(WriteAllTimeSteps, int); 119 vtkGetMacro(WriteAllTimeSteps, int); 120 vtkBooleanMacro(WriteAllTimeSteps, int); 121 ///@} 122 123 ///@{ 124 /** 125 * Set of get the flag that specify if input mesh is static over time. 126 * If so, the mesh topology and geometry heavy data will be written only once. 127 * Default if FALSE. 128 * Note: this mode requires that all data is dumped in the heavy data file. 129 */ 130 vtkSetMacro(MeshStaticOverTime, bool); 131 vtkGetMacro(MeshStaticOverTime, bool); 132 vtkBooleanMacro(MeshStaticOverTime, bool); 133 ///@} 134 135 ///@{ 136 /** 137 * Called in parallel runs to identify the portion this process is responsible for 138 * TODO: respect this 139 */ 140 vtkSetMacro(Piece, int); 141 vtkSetMacro(NumberOfPieces, int); 142 ///@} 143 144 // TODO: control choice of heavy data format (xml, hdf5, sql, raw) 145 146 // TODO: These controls are available in vtkXdmfWriter, but are not used here. 147 // GridsOnly 148 // Append to Domain 149 150 protected: 151 vtkXdmfWriter(); 152 ~vtkXdmfWriter() override; 153 154 // Choose composite executive by default for time. 155 vtkExecutive* CreateDefaultExecutive() override; 156 157 // Can take any one data object 158 int FillInputPortInformation(int port, vtkInformation* info) override; 159 160 // Overridden to ... 161 int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; 162 // Overridden to ... 163 int RequestUpdateExtent(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; 164 // Overridden to ... 165 int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; 166 167 // These do the work: recursively parse down input's structure all the way to arrays, 168 // use XDMF lib to dump everything to file. 169 170 virtual int CreateTopology(vtkDataSet* ds, xdmf2::XdmfGrid* grid, vtkIdType PDims[3], 171 vtkIdType CDims[3], vtkIdType& PRank, vtkIdType& CRank, void* staticdata); 172 virtual int CreateGeometry(vtkDataSet* ds, xdmf2::XdmfGrid* grid, void* staticdata); 173 174 virtual int WriteDataSet(vtkDataObject* dobj, xdmf2::XdmfGrid* grid); 175 virtual int WriteCompositeDataSet(vtkCompositeDataSet* dobj, xdmf2::XdmfGrid* grid); 176 virtual int WriteAtomicDataSet(vtkDataObject* dobj, xdmf2::XdmfGrid* grid); 177 virtual int WriteArrays(vtkFieldData* dsa, xdmf2::XdmfGrid* grid, int association, vtkIdType rank, 178 vtkIdType* dims, const char* name); 179 virtual void ConvertVToXArray(vtkDataArray* vda, xdmf2::XdmfArray* xda, vtkIdType rank, 180 vtkIdType* dims, int AllocStrategy, const char* heavyprefix); 181 182 virtual void SetupDataArrayXML(xdmf2::XdmfElement*, xdmf2::XdmfArray*) const; 183 184 char* FileName; 185 char* HeavyDataFileName; 186 char* HeavyDataGroupName; 187 std::string WorkingDirectory; 188 std::string BaseFileName; 189 190 int LightDataLimit; 191 192 int WriteAllTimeSteps; 193 int NumberOfTimeSteps; 194 double CurrentTime; 195 int CurrentTimeIndex; 196 int CurrentBlockIndex; 197 int UnlabelledDataArrayId; 198 199 int Piece; 200 int NumberOfPieces; 201 202 bool MeshStaticOverTime; 203 204 xdmf2::XdmfDOM* DOM; 205 xdmf2::XdmfGrid* TopTemporalGrid; 206 207 vtkXdmfWriterDomainMemoryHandler* DomainMemoryHandler; 208 209 std::vector<xdmf2::XdmfTopology*> TopologyAtT0; 210 std::vector<xdmf2::XdmfGeometry*> GeometryAtT0; 211 212 private: 213 vtkXdmfWriter(const vtkXdmfWriter&) = delete; 214 void operator=(const vtkXdmfWriter&) = delete; 215 }; 216 217 #endif /* vtkXdmfWriter_h */ 218