1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkOpenFOAMReader.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 // .NAME vtkOpenFOAMReader - reads a dataset in OpenFOAM format
16 // .SECTION Description
17 // vtkOpenFOAMReader creates a multiblock dataset. It reads mesh
18 // information and time dependent data.  The polyMesh folders contain
19 // mesh information. The time folders contain transient data for the
20 // cells. Each folder can contain any number of data files.
21 
22 // .SECTION Thanks
23 // Thanks to Terry Jordan of SAIC at the National Energy
24 // Technology Laboratory who developed this class.
25 // Please address all comments to Terry Jordan (terry.jordan@sa.netl.doe.gov).
26 // GUI Based selection of mesh regions and fields available in the case,
27 // minor bug fixes, strict memory allocation checks,
28 // minor performance enhancements by Philippose Rajan (sarith@rocketmail.com).
29 // Token-based FoamFile format lexer/parser,
30 // performance/stability/compatibility enhancements, gzipped file
31 // support, lagrangian field support, variable timestep support,
32 // builtin cell-to-point filter, pointField support, polyhedron
33 // decomposition support, OF 1.5 extended format support, multiregion
34 // support, old mesh format support, parallelization support for
35 // decomposed cases in conjunction with vtkPOpenFOAMReader, et. al. by
36 // Takuya Oshima of Niigata University, Japan (oshima@eng.niigata-u.ac.jp).
37 
38 #ifndef vtkOpenFOAMReader_h
39 #define vtkOpenFOAMReader_h
40 
41 #include "vtkIOGeometryModule.h" // For export macro
42 #include "vtkMultiBlockDataSetAlgorithm.h"
43 
44 class vtkCollection;
45 class vtkCharArray;
46 class vtkDataArraySelection;
47 class vtkDoubleArray;
48 class vtkStdString;
49 class vtkStringArray;
50 
51 class vtkOpenFOAMReaderPrivate;
52 
53 class VTKIOGEOMETRY_EXPORT vtkOpenFOAMReader : public vtkMultiBlockDataSetAlgorithm
54 {
55 public:
56   static vtkOpenFOAMReader *New();
57   vtkTypeMacro(vtkOpenFOAMReader, vtkMultiBlockDataSetAlgorithm);
58   void PrintSelf(ostream &, vtkIndent);
59 
60   // Description:
61   // Determine if the file can be readed with this reader.
62   int CanReadFile(const char *);
63 
64   // Description:
65   // Set/Get the filename.
66   vtkSetStringMacro(FileName);
67   vtkGetStringMacro(FileName);
68 
69   // Description:
70   // Get the number of cell arrays available in the input.
GetNumberOfCellArrays(void)71   int GetNumberOfCellArrays(void)
72   { return this->GetNumberOfSelectionArrays(this->CellDataArraySelection); }
73 
74   // Description:
75   // Get/Set whether the cell array with the given name is to
76   // be read.
GetCellArrayStatus(const char * name)77   int GetCellArrayStatus(const char *name)
78   { return this->GetSelectionArrayStatus(this->CellDataArraySelection, name); }
SetCellArrayStatus(const char * name,int status)79   void SetCellArrayStatus(const char *name, int status)
80   { this->SetSelectionArrayStatus(this->CellDataArraySelection, name, status); }
81 
82   // Description:
83   // Get the name of the  cell array with the given index in
84   // the input.
GetCellArrayName(int index)85   const char *GetCellArrayName(int index)
86   { return this->GetSelectionArrayName(this->CellDataArraySelection, index); }
87 
88   // Description:
89   // Turn on/off all cell arrays.
DisableAllCellArrays()90   void DisableAllCellArrays()
91   { this->DisableAllSelectionArrays(this->CellDataArraySelection); }
EnableAllCellArrays()92   void EnableAllCellArrays()
93   { this->EnableAllSelectionArrays(this->CellDataArraySelection); }
94 
95   // Description:
96   // Get the number of point arrays available in the input.
GetNumberOfPointArrays(void)97   int GetNumberOfPointArrays(void)
98   { return this->GetNumberOfSelectionArrays(this->PointDataArraySelection); }
99 
100   // Description:
101   // Get/Set whether the point array with the given name is to
102   // be read.
GetPointArrayStatus(const char * name)103   int GetPointArrayStatus(const char *name)
104   { return this->GetSelectionArrayStatus(this->PointDataArraySelection, name); }
SetPointArrayStatus(const char * name,int status)105   void SetPointArrayStatus(const char *name, int status)
106   { this->SetSelectionArrayStatus(this->PointDataArraySelection,
107     name, status); }
108 
109   // Description:
110   // Get the name of the  point array with the given index in
111   // the input.
GetPointArrayName(int index)112   const char *GetPointArrayName(int index)
113   { return this->GetSelectionArrayName(this->PointDataArraySelection, index); }
114 
115   // Description:
116   // Turn on/off all point arrays.
DisableAllPointArrays()117   void DisableAllPointArrays()
118   { this->DisableAllSelectionArrays(this->PointDataArraySelection); }
EnableAllPointArrays()119   void EnableAllPointArrays()
120   { this->EnableAllSelectionArrays(this->PointDataArraySelection); }
121 
122   // Description:
123   // Get the number of Lagrangian arrays available in the input.
GetNumberOfLagrangianArrays(void)124   int GetNumberOfLagrangianArrays(void)
125   { return this->GetNumberOfSelectionArrays(
126     this->LagrangianDataArraySelection); }
127 
128   // Description:
129   // Get/Set whether the Lagrangian array with the given name is to
130   // be read.
GetLagrangianArrayStatus(const char * name)131   int GetLagrangianArrayStatus(const char *name)
132   { return this->GetSelectionArrayStatus(this->LagrangianDataArraySelection,
133     name); }
SetLagrangianArrayStatus(const char * name,int status)134   void SetLagrangianArrayStatus(const char *name, int status)
135   { this->SetSelectionArrayStatus(this->LagrangianDataArraySelection, name,
136     status); }
137 
138   // Description:
139   // Get the name of the  Lagrangian array with the given index in
140   // the input.
GetLagrangianArrayName(int index)141   const char* GetLagrangianArrayName(int index)
142   { return this->GetSelectionArrayName(this->LagrangianDataArraySelection,
143     index); }
144 
145   // Description:
146   // Turn on/off all Lagrangian arrays.
DisableAllLagrangianArrays()147   void DisableAllLagrangianArrays()
148   { this->DisableAllSelectionArrays(this->LagrangianDataArraySelection); }
EnableAllLagrangianArrays()149   void EnableAllLagrangianArrays()
150   { this->EnableAllSelectionArrays(this->LagrangianDataArraySelection); }
151 
152   // Description:
153   // Get the number of Patches (including Internal Mesh) available in the input.
GetNumberOfPatchArrays(void)154   int GetNumberOfPatchArrays(void)
155   { return this->GetNumberOfSelectionArrays(this->PatchDataArraySelection); }
156 
157   // Description:
158   // Get/Set whether the Patch with the given name is to
159   // be read.
GetPatchArrayStatus(const char * name)160   int GetPatchArrayStatus(const char *name)
161   { return this->GetSelectionArrayStatus(this->PatchDataArraySelection, name); }
SetPatchArrayStatus(const char * name,int status)162   void SetPatchArrayStatus(const char *name, int status)
163   { this->SetSelectionArrayStatus(this->PatchDataArraySelection, name,
164     status); }
165 
166   // Description:
167   // Get the name of the Patch with the given index in
168   // the input.
GetPatchArrayName(int index)169   const char *GetPatchArrayName(int index)
170   { return this->GetSelectionArrayName(this->PatchDataArraySelection, index); }
171 
172   // Description:
173   // Turn on/off all Patches including the Internal Mesh.
DisableAllPatchArrays()174   void DisableAllPatchArrays()
175   { this->DisableAllSelectionArrays(this->PatchDataArraySelection); }
EnableAllPatchArrays()176   void EnableAllPatchArrays()
177   { this->EnableAllSelectionArrays(this->PatchDataArraySelection); }
178 
179   // Description:
180   // Set/Get whether to create cell-to-point translated data for cell-type data
181   vtkSetMacro(CreateCellToPoint,int);
182   vtkGetMacro(CreateCellToPoint,int);
183   vtkBooleanMacro(CreateCellToPoint, int);
184 
185   // Description:
186   // Set/Get whether mesh is to be cached.
187   vtkSetMacro(CacheMesh, int);
188   vtkGetMacro(CacheMesh, int);
189   vtkBooleanMacro(CacheMesh, int);
190 
191   // Description:
192   // Set/Get whether polyhedra are to be decomposed.
193   vtkSetMacro(DecomposePolyhedra, int);
194   vtkGetMacro(DecomposePolyhedra, int);
195   vtkBooleanMacro(DecomposePolyhedra, int);
196 
197   // Option for reading old binary lagrangian/positions format
198   // Description:
199   // Set/Get whether the lagrangian/positions is in OF 1.3 format
200   vtkSetMacro(PositionsIsIn13Format, int);
201   vtkGetMacro(PositionsIsIn13Format, int);
202   vtkBooleanMacro(PositionsIsIn13Format, int);
203 
204   // Description:
205   // Determine if time directories are to be listed according to controlDict
206   vtkSetMacro(ListTimeStepsByControlDict, int);
207   vtkGetMacro(ListTimeStepsByControlDict, int);
208   vtkBooleanMacro(ListTimeStepsByControlDict, int);
209 
210   // Description:
211   // Add dimensions to array names
212   vtkSetMacro(AddDimensionsToArrayNames, int);
213   vtkGetMacro(AddDimensionsToArrayNames, int);
214   vtkBooleanMacro(AddDimensionsToArrayNames, int);
215 
216   // Description:
217   // Set/Get whether zones will be read.
218   vtkSetMacro(ReadZones, int);
219   vtkGetMacro(ReadZones, int);
220   vtkBooleanMacro(ReadZones, int);
221 
SetRefresh()222   void SetRefresh() { this->Refresh = true; this->Modified(); }
223 
SetParent(vtkOpenFOAMReader * parent)224   void SetParent(vtkOpenFOAMReader *parent) { this->Parent = parent; }
225   int MakeInformationVector(vtkInformationVector *, const vtkStdString &);
226   bool SetTimeValue(const double);
227   vtkDoubleArray *GetTimeValues();
228   int MakeMetaDataAtTimeStep(const bool);
229 
230   //BTX
231   friend class vtkOpenFOAMReaderPrivate;
232   //ETX
233 
234 protected:
235   // refresh flag
236   bool Refresh;
237 
238   // for creating cell-to-point translated data
239   int CreateCellToPoint;
240 
241   // for caching mesh
242   int CacheMesh;
243 
244   // for decomposing polyhedra on-the-fly
245   int DecomposePolyhedra;
246 
247   // for reading old binary lagrangian/positions format
248   int PositionsIsIn13Format;
249 
250   // for reading point/face/cell-Zones
251   int ReadZones;
252 
253   // determine if time directories are listed according to controlDict
254   int ListTimeStepsByControlDict;
255 
256   // add dimensions to array names
257   int AddDimensionsToArrayNames;
258 
259   char *FileName;
260   vtkCharArray *CasePath;
261   vtkCollection *Readers;
262 
263   // DataArraySelection for Patch / Region Data
264   vtkDataArraySelection *PatchDataArraySelection;
265   vtkDataArraySelection *CellDataArraySelection;
266   vtkDataArraySelection *PointDataArraySelection;
267   vtkDataArraySelection *LagrangianDataArraySelection;
268 
269   // old selection status
270   unsigned long int PatchSelectionMTimeOld;
271   unsigned long int CellSelectionMTimeOld;
272   unsigned long int PointSelectionMTimeOld;
273   unsigned long int LagrangianSelectionMTimeOld;
274 
275   // preserved old information
276   vtkStdString *FileNameOld;
277   int ListTimeStepsByControlDictOld;
278   int CreateCellToPointOld;
279   int DecomposePolyhedraOld;
280   int PositionsIsIn13FormatOld;
281   int AddDimensionsToArrayNamesOld;
282   int ReadZonesOld;
283 
284   // paths to Lagrangians
285   vtkStringArray *LagrangianPaths;
286 
287   // number of reader instances
288   int NumberOfReaders;
289   // index of the active reader
290   int CurrentReaderIndex;
291 
292   vtkOpenFOAMReader();
293   ~vtkOpenFOAMReader();
294   int RequestInformation(vtkInformation *, vtkInformationVector **,
295     vtkInformationVector *);
296   int RequestData(vtkInformation *, vtkInformationVector **,
297     vtkInformationVector *);
298 
299   void CreateCasePath(vtkStdString &, vtkStdString &);
300   void SetTimeInformation(vtkInformationVector *, vtkDoubleArray *);
301   void CreateCharArrayFromString(vtkCharArray *, const char *, vtkStdString &);
302   void UpdateStatus();
303   void UpdateProgress(double);
304 
305 private:
306   vtkOpenFOAMReader *Parent;
307 
308   vtkOpenFOAMReader(const vtkOpenFOAMReader&);  // Not implemented.
309   void operator=(const vtkOpenFOAMReader&);  // Not implemented.
310 
311   int GetNumberOfSelectionArrays(vtkDataArraySelection *);
312   int GetSelectionArrayStatus(vtkDataArraySelection *, const char *);
313   void SetSelectionArrayStatus(vtkDataArraySelection *, const char *, int);
314   const char *GetSelectionArrayName(vtkDataArraySelection *, int);
315   void DisableAllSelectionArrays(vtkDataArraySelection *);
316   void EnableAllSelectionArrays(vtkDataArraySelection *);
317 
318   void AddSelectionNames(vtkDataArraySelection *, vtkStringArray *);
319 };
320 
321 #endif
322