vtkPEnSightReader.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkPEnSightReader.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  =========================================================================*/
32 #ifndef vtkPEnSightReader_h
33 #define vtkPEnSightReader_h
34 
36 #include "vtkPVVTKExtensionsIOEnSightModule.h" //needed for exports
37 
38 #include "vtkIdTypeArray.h" // For ivars
39 #include <algorithm> // For ivars
40 #include <map> // For ivars
41 #include <string> // For ivars
42 #include <vector> // For ivars
43 
44 class vtkDataSet;
45 class vtkIdList;
47 class vtkInformation;
51 class vtkFloatArray;
52 class vtkPEnSightReaderCellIdsType;
53 
54 #define NEXTMODULO3(x) (x == 0) ? 1 : ((x == 1) ? 2 : 0)
55 
57 {
58 public:
60  void PrintSelf(ostream& os, vtkIndent indent) override;
61 
62  //----------------------------------------------------------------------------
63  // PointIds and CellIds must be stored in a different way:
64  // std::vector in non distributed mode
65  // std::map in distributed mode
66  // note: Ensight Ids are INTEGERS, not longs
68  {
69 
70  public:
71  typedef std::map<int, int> IntIntMap;
72  typedef std::vector<int> IntVector;
73 
75  : cellMap(nullptr)
76  , cellNumberOfIds(-1)
77  , cellLocalNumberOfIds(-1)
78  , cellVector(nullptr)
79  , ImplicitDimensions(nullptr)
80  , ImplicitLocalDimensions(nullptr)
81  , ImplicitSplitDimension(-1)
82  , ImplicitSplitDimensionBeginIndex(-1)
83  , ImplicitSplitDimensionEndIndex(-1)
85  {
86  }
87 
89  : cellMap(nullptr)
90  , cellNumberOfIds(-1)
91  , cellLocalNumberOfIds(-1)
92  , cellVector(nullptr)
93  , ImplicitDimensions(nullptr)
94  , ImplicitLocalDimensions(nullptr)
95  , ImplicitSplitDimension(-1)
96  , ImplicitSplitDimensionBeginIndex(-1)
97  , ImplicitSplitDimensionEndIndex(-1)
98  , mode(amode)
99  {
100  if (this->mode == SPARSE_MODE)
101  {
102  this->cellMap = new IntIntMap;
103  this->cellNumberOfIds = 0;
104  this->cellVector = nullptr;
105  }
106  else if (this->mode == IMPLICIT_STRUCTURED_MODE)
107  {
108  this->ImplicitDimensions = new int[3];
109  this->ImplicitSplitDimension = -1;
110  this->ImplicitSplitDimensionBeginIndex = -1;
111  this->ImplicitSplitDimensionEndIndex = -1;
112  }
113  else
114  {
115  this->cellMap = nullptr;
116  this->cellVector = new IntVector;
117  this->cellNumberOfIds = -1;
118  this->cellLocalNumberOfIds = -1;
119  }
120  }
121 
123  {
124  delete this->cellMap;
125  delete this->cellVector;
126  delete[] this->ImplicitDimensions;
127  }
128 
130  {
131  this->mode = amode;
132  if (this->mode == SPARSE_MODE)
133  {
134  this->cellMap = new IntIntMap;
135  this->cellNumberOfIds = 0;
136  this->cellVector = nullptr;
137  }
138  else if (this->mode == IMPLICIT_STRUCTURED_MODE)
139  {
140  this->ImplicitDimensions = new int[3];
141  this->ImplicitSplitDimension = -1;
142  this->ImplicitSplitDimensionBeginIndex = -1;
143  this->ImplicitSplitDimensionEndIndex = -1;
144  }
145  else
146  {
147  this->cellMap = nullptr;
148  this->cellVector = new IntVector;
149  this->cellNumberOfIds = -1;
150  this->cellLocalNumberOfIds = -1;
151  }
152  }
153 
154  void SetImplicitDimensions(int dim1, int dim2, int dim3)
155  {
156  this->ImplicitDimensions[0] = dim1;
157  this->ImplicitDimensions[1] = dim2;
158  this->ImplicitDimensions[2] = dim3;
159  }
160 
161  void SetImplicitSplitDimension(int dim) { this->ImplicitSplitDimension = dim; }
162 
164  {
165  this->ImplicitSplitDimensionBeginIndex = begin;
166  }
167 
168  void SetImplicitSplitDimensionEndIndex(int end) { this->ImplicitSplitDimensionEndIndex = end; }
169 
170  // return -1 if not found
171  int GetId(int id)
172  {
173  switch (this->mode)
174  {
175  case SINGLE_PROCESS_MODE:
176  {
177  // Single Process compatibility
178  return id;
179  break;
180  }
182  {
183  if (this->ImplicitSplitDimension == -1)
184  return -1; // not initialized
185 
186  // Compute the global i j k index
187  // id = i + j * dim[0] + k * dim[1] * dim[0]
188  int index[3];
189  index[2] = id / (this->ImplicitDimensions[0] * this->ImplicitDimensions[1]); // k
190  index[1] = (id - (index[2] * this->ImplicitDimensions[0] * this->ImplicitDimensions[1])) /
191  this->ImplicitDimensions[0]; // j
192  index[0] = id - index[1] * this->ImplicitDimensions[0] -
193  index[2] * this->ImplicitDimensions[1] * this->ImplicitDimensions[0]; // i
194  if ((index[this->ImplicitSplitDimension] < this->ImplicitSplitDimensionBeginIndex) ||
195  (index[this->ImplicitSplitDimension] >= this->ImplicitSplitDimensionEndIndex))
196  {
197  // not for me
198  return -1;
199  }
200  else
201  {
202  // Compute the local id
203  int localIndex[3];
204  int localDim[3];
205  int dim = this->ImplicitSplitDimension;
206  localIndex[dim] = index[dim] - this->ImplicitSplitDimensionBeginIndex;
207  localDim[dim] =
208  this->ImplicitSplitDimensionEndIndex - this->ImplicitSplitDimensionBeginIndex;
209  dim = NEXTMODULO3(dim);
210  localIndex[dim] = index[dim];
211  localDim[dim] = this->ImplicitDimensions[dim];
212  dim = NEXTMODULO3(dim);
213  localDim[dim] = this->ImplicitDimensions[dim];
214  localIndex[dim] = index[dim];
215  return localIndex[0] + localDim[0] * localIndex[1] +
216  localDim[0] * localDim[1] * localIndex[2];
217  }
218  }
219  case SPARSE_MODE:
220  {
221  std::map<int, int>::iterator it = this->cellMap->find(id);
222  if (it == this->cellMap->end())
223  return -1;
224  else
225  return (*this->cellMap)[id];
226  break;
227  }
228  default:
229  {
230  if (this->cellVector->size() > (unsigned int)(id))
231  return (*this->cellVector)[id];
232  break;
233  }
234  }
235  return -1;
236  }
237 
238  void SetId(int id, int value)
239  {
240  switch (this->mode)
241  {
242  case SINGLE_PROCESS_MODE:
244  {
245  // Compatibility Only
246  // do noting
247  break;
248  }
249  case SPARSE_MODE:
250  {
251  std::map<int, int>::iterator it = this->cellMap->find(id);
252  if (it == this->cellMap->end())
253  this->cellNumberOfIds++;
254 
255  (*this->cellMap)[id] = value;
256  break;
257  }
258  default:
259  {
260  if (this->cellVector->size() < (unsigned int)(id + 1))
261  {
262  int k;
263  int currentSize = static_cast<int>(this->cellVector->size());
264  this->cellVector->resize(id + 1);
265  for (k = currentSize; k < id; k++)
266  {
267  (*this->cellVector)[k] = -1;
268  }
269  (*this->cellVector)[id] = value;
270  }
271  else
272  {
273  (*this->cellVector)[id] = value;
274  }
275  break;
276  }
277  }
278  }
279 
280  // In distributed mode, if id == -1, do not insert it in map
281  int InsertNextId(int id)
282  {
283  switch (this->mode)
284  {
285  case SINGLE_PROCESS_MODE:
287  {
288  // Single Process compatibility
289  // do noting
290  break;
291  }
292  case SPARSE_MODE:
293  {
294  if (id != -1)
295  {
296  (*this->cellMap)[this->cellNumberOfIds] = id;
297  }
298  // increment fake number of ids
299  this->cellNumberOfIds++;
300  return this->cellNumberOfIds - 1;
301  break;
302  }
303  default:
304  {
305  this->cellVector->push_back(id);
306  return static_cast<int>(this->cellVector->size() - 1);
307  break;
308  }
309  }
310  return static_cast<int>(this->cellVector->size() - 1);
311  }
312 
314  {
315  switch (this->mode)
316  {
317  case SINGLE_PROCESS_MODE:
318  {
319  // Single Process compatibility
320  return this->cellNumberOfIds;
321  break;
322  }
324  {
325  return this->cellNumberOfIds;
326  }
327  case SPARSE_MODE:
328  {
329  return this->cellNumberOfIds;
330  break;
331  }
332  default:
333  {
334  break;
335  }
336  }
337 
338  // Point Ids are directly injected in the vector,
339  // contrary to cell Ids which are "stacked" with
340  // InsertNextId. So the real total number of Ids
341  // for Points cannot be the size of the vector.
342  // So we must inject it manually
343  if (this->cellNumberOfIds >= 0)
344  {
345  return this->cellNumberOfIds;
346  }
347 
348  return static_cast<int>(this->cellVector->size());
349  }
350 
351  // Just inject the real total number of Ids
352  void SetNumberOfIds(int n)
353  {
354  if (this->mode == SPARSE_MODE)
355  {
356  // do nothing
357  }
358  else
359  {
360  // Non sparse Or Single Process
361  this->cellNumberOfIds = n;
362  }
363  }
364 
366  {
367  if (this->mode == SPARSE_MODE)
368  {
369  // do nothing
370  }
371  else
372  {
373  // Non sparse Or Single Process
374  // Used for Structured compatibility
375  this->cellLocalNumberOfIds = n;
376  }
377  }
378 
379  void Reset()
380  {
381  if (this->mode == SPARSE_MODE)
382  {
383  this->cellMap->clear();
384  this->cellNumberOfIds = 0;
385  }
386  else
387  {
388  if (this->mode == NON_SPARSE_MODE)
389  this->cellVector->clear();
390  if (this->cellNumberOfIds >= 0)
391  this->cellNumberOfIds = -1;
392  if (this->cellLocalNumberOfIds >= 0)
393  this->cellLocalNumberOfIds = -1;
394  }
395  }
396 
398  {
399  switch (this->mode)
400  {
401  case SINGLE_PROCESS_MODE:
402  {
403  // Single Process compatibility
404  return this->cellNumberOfIds;
405  break;
406  }
408  {
409  return this->cellLocalNumberOfIds;
410  }
411  case SPARSE_MODE:
412  {
413  return static_cast<int>(this->cellMap->size());
414  break;
415  }
416  default:
417  {
418  break;
419  }
420  }
421 
422  // Return cellLocalNumberOfIds if valid
423  if (this->cellLocalNumberOfIds >= 0)
424  {
425  return this->cellLocalNumberOfIds;
426  }
427 
428  // Else compute the real size
429  int result = 0;
430  for (unsigned int i = 0; i < this->cellVector->size(); i++)
431  {
432  if ((*this->cellVector)[i] != -1)
433  result++;
434  }
435  return result;
436  }
437 
438  protected:
439  IntIntMap* cellMap;
442  IntVector* cellVector;
443  // Implicit Structured Real (global) dimensions
445  // Implicit Structured local dimensions
447  // Implicit Structured Split Dimension
449  // Implicit Structured Split Dimension Begin Index. Inclusive
451  // Implicit StructuredSplit Dimension End Index. Exclusive
453 
455  };
456 
458  {
459  POINT = 0,
460  BAR2 = 1,
461  BAR3 = 2,
462  NSIDED = 3,
463  TRIA3 = 4,
464  TRIA6 = 5,
465  QUAD4 = 6,
466  QUAD8 = 7,
467  NFACED = 8,
468  TETRA4 = 9,
469  TETRA10 = 10,
470  PYRAMID5 = 11,
471  PYRAMID13 = 12,
472  HEXA8 = 13,
473  HEXA20 = 14,
474  PENTA6 = 15,
475  PENTA15 = 16,
476  NUMBER_OF_ELEMENT_TYPES = 17
477  };
478 
480  {
481  SCALAR_PER_NODE = 0,
482  VECTOR_PER_NODE = 1,
483  TENSOR_SYMM_PER_NODE = 2,
484  SCALAR_PER_ELEMENT = 3,
485  VECTOR_PER_ELEMENT = 4,
486  TENSOR_SYMM_PER_ELEMENT = 5,
487  SCALAR_PER_MEASURED_NODE = 6,
488  VECTOR_PER_MEASURED_NODE = 7,
489  COMPLEX_SCALAR_PER_NODE = 8,
490  COMPLEX_VECTOR_PER_NODE = 9,
491  COMPLEX_SCALAR_PER_ELEMENT = 10,
492  COMPLEX_VECTOR_PER_ELEMENT = 11
493  };
494 
496  {
497  COORDINATES = 0,
498  BLOCK = 1,
499  ELEMENT = 2
500  };
501 
503 
507  vtkGetStringMacro(MeasuredFileName);
509 
511 
515  vtkGetStringMacro(MatchFileName);
517 
518 protected:
520  ~vtkPEnSightReader() override;
521 
522  int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
523  int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
524 
525  /*int RequestUpdateExtent(
526  vtkInformation *vtkNotUsed(request),
527  vtkInformationVector **inputVector,
528  vtkInformationVector *outputVector);
529  */
530 
532 
535  vtkSetStringMacro(MeasuredFileName);
537 
539 
542  vtkSetStringMacro(MatchFileName);
544 
546 
549  int ReadCaseFile();
550  int ReadCaseFileGeometry(char* line);
551  int ReadCaseFileVariable(char* line);
552  int ReadCaseFileTime(char* line);
553  int ReadCaseFileFile(char* line);
555 
556  // set in UpdateInformation to value returned from ReadCaseFile
558 
562  virtual int ReadGeometryFile(
563  const char* fileName, int timeStep, vtkMultiBlockDataSet* output) = 0;
564 
569  virtual int ReadMeasuredGeometryFile(
570  const char* fileName, int timeStep, vtkMultiBlockDataSet* output) = 0;
571 
575  int ReadVariableFiles(vtkMultiBlockDataSet* output);
576 
581  virtual int ReadScalarsPerNode(const char* fileName, const char* description, int timeStep,
582  vtkMultiBlockDataSet* output, int measured = 0, int numberOfComponents = 1,
583  int component = 0) = 0;
584 
589  virtual int ReadVectorsPerNode(const char* fileName, const char* description, int timeStep,
590  vtkMultiBlockDataSet* output, int measured = 0) = 0;
591 
596  virtual int ReadTensorsPerNode(
597  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
598 
603  virtual int ReadScalarsPerElement(const char* fileName, const char* description, int timeStep,
604  vtkMultiBlockDataSet* output, int numberOfComponents = 1, int component = 0) = 0;
605 
610  virtual int ReadVectorsPerElement(
611  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
612 
617  virtual int ReadTensorsPerElement(
618  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
619 
624  virtual int CreateUnstructuredGridOutput(
625  int partId, char line[80], const char* name, vtkMultiBlockDataSet* output) = 0;
626 
631  virtual int CreateStructuredGridOutput(
632  int partId, char line[80], const char* name, vtkMultiBlockDataSet* output) = 0;
633 
637  void AddVariableFileName(const char* fileName1, const char* fileName2 = nullptr);
638 
642  void AddVariableDescription(const char* description);
643 
647  void AddVariableType();
648 
653  int GetElementType(const char* line);
654 
659  int GetSectionType(const char* line);
660 
664  void ReplaceWildcards(char* filename, int num);
665 
669  void RemoveLeadingBlanks(char* line);
670 
674  vtkPEnSightReaderCellIds* GetCellIds(int index, int cellType);
675 
677 
681  vtkIdType GetTotalNumberOfCellIds(int index);
682  vtkIdType GetLocalTotalNumberOfCellIds(int index);
684 
689  vtkPEnSightReaderCellIds* GetPointIds(int index);
690 
695  void AddToBlock(vtkMultiBlockDataSet* output, unsigned int blockNo, vtkDataSet* dataset);
696 
701  vtkDataSet* GetDataSetFromBlock(vtkMultiBlockDataSet* output, unsigned int blockNo);
702 
706  void SetBlockName(vtkMultiBlockDataSet* output, unsigned int blockNo, const char* name);
707 
709 
714  void InsertNextCellAndId(vtkUnstructuredGrid*, int vtkCellType, vtkIdType numPoints,
715  vtkIdType* points, int partId, int ensightCellType, vtkIdType globalId, vtkIdType numElements,
716  const std::vector<vtkIdType>& faces = {});
717  void InsertVariableComponent(vtkFloatArray* array, int i, int component, float* content,
718  int partId, int ensightCellType, int insertionType);
720 
724  void MapToGlobalIds(
725  const vtkIdType* inputIds, vtkIdType numPoints, int partId, vtkIdType* globalIds);
726 
733  void PrepareStructuredDimensionsForDistribution(int partId, int* oldDimensions,
734  int* newDimensions, int* splitDimension, int* splitDimensionBeginIndex, int ghostLevel,
735  vtkUnsignedCharArray* pointGhostArray, vtkUnsignedCharArray* cellGhostArray);
736 
738  char* MatchFileName; // may not actually be necessary to read this file
739 
740  // pointer to lists of list (cell ids per element type per part)
741  vtkPEnSightReaderCellIdsType* CellIds;
742 
743  // pointer to lists of list (point ids per element type per part)
744  vtkPEnSightReaderCellIdsType* PointIds;
745 
746  // part ids of unstructured outputs
748  // part ids of structured outputs
750 
755 
757 
758  // pointers to lists of filenames
759  char** VariableFileNames; // non-complex
761 
762  // array of time sets
765 
766  // array of file sets
769 
770  // collection of filename numbers per time set
773 
774  // collection of filename numbers per file set
777 
778  // collection of number of steps per file per file set
780 
781  // ids of the time and file sets
784 
789 
792 
794  vtkSetMacro(UseTimeSets, int);
795  vtkGetMacro(UseTimeSets, int);
796  vtkBooleanMacro(UseTimeSets, int);
797 
798  int UseFileSets;
799  vtkSetMacro(UseFileSets, int);
800  vtkGetMacro(UseFileSets, int);
801  vtkBooleanMacro(UseFileSets, int);
802 
804 
805  // global list of points for measured geometry
807 
810 
811  int CheckOutputConsistency();
812 
814 
816 
817  std::map<std::string, std::map<int, long>> FileOffsets;
818 
819 private:
820  vtkPEnSightReader(const vtkPEnSightReader&) = delete;
821  void operator=(const vtkPEnSightReader&) = delete;
822 };
823 
824 #endif
void SetMode(EnsightReaderCellIdMode amode)
int
vtkPEnSightReaderCellIds(EnsightReaderCellIdMode amode)
vtkIdList * VariableTimeSetIds
Superclass for EnSight file parallel readers.
vtkIdList * TimeSetsWithFilenameNumbers
vtkIdList * ComplexVariableFileSetIds
SPARSE_MODE
EnsightReaderCellIdMode
int vtkIdType
char ** ComplexVariableFileNames
vtkIdList * UnstructuredPartIds
class to read any type of EnSight files
vtkPEnSightReaderCellIdsType * CellIds
SINGLE_PROCESS_MODE
NON_SPARSE_MODE
void PrintSelf(ostream &os, vtkIndent indent) override
vtkIdList * VariableFileSetIds
mode
IMPLICIT_STRUCTURED_MODE
vtkIdListCollection * FileSetFileNameNumbers
void SetImplicitDimensions(int dim1, int dim2, int dim3)
#define NEXTMODULO3(x)
vtkIdListCollection * TimeSetFileNameNumbers
vtkIdList * ComplexVariableTimeSetIds
index
vtkIdListCollection * FileSetNumberOfSteps
#define VTKPVVTKEXTENSIONSIOENSIGHT_EXPORT
vtkIdList * StructuredPartIds
std::map< std::string, std::map< int, long > > FileOffsets
vtkPEnSightReaderCellIdsType * PointIds
vtkIdList * FileSetsWithFilenameNumbers