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 <map> // For ivars
42 #include <string> // For ivars
43 #include <string> // For ivars
44 #include <vector> // For ivars
45 
46 class vtkDataSet;
47 class vtkIdList;
49 class vtkInformation;
53 class vtkFloatArray;
54 class vtkPEnSightReaderCellIdsType;
55 
56 #define NEXTMODULO3(x) (x == 0) ? 1 : ((x == 1) ? 2 : 0)
57 
59 {
60 public:
62  void PrintSelf(ostream& os, vtkIndent indent) override;
63 
64  //----------------------------------------------------------------------------
65  // PointIds and CellIds must be stored in a different way:
66  // std::vector in non distributed mode
67  // std::map in distributed mode
68  // note: Ensight Ids are INTEGERS, not longs
70  {
71 
72  public:
73  typedef std::map<int, int> IntIntMap;
74  typedef std::vector<int> IntVector;
75 
77  : cellMap(NULL)
78  , cellNumberOfIds(-1)
79  , cellLocalNumberOfIds(-1)
80  , cellVector(NULL)
81  , ImplicitDimensions(NULL)
82  , ImplicitLocalDimensions(NULL)
83  , ImplicitSplitDimension(-1)
84  , ImplicitSplitDimensionBeginIndex(-1)
85  , ImplicitSplitDimensionEndIndex(-1)
87  {
88  }
89 
91  : cellMap(NULL)
92  , cellNumberOfIds(-1)
93  , cellLocalNumberOfIds(-1)
94  , cellVector(NULL)
95  , ImplicitDimensions(NULL)
96  , ImplicitLocalDimensions(NULL)
97  , ImplicitSplitDimension(-1)
98  , ImplicitSplitDimensionBeginIndex(-1)
99  , ImplicitSplitDimensionEndIndex(-1)
100  , mode(amode)
101  {
102  if (this->mode == SPARSE_MODE)
103  {
104  this->cellMap = new IntIntMap;
105  this->cellNumberOfIds = 0;
106  this->cellVector = NULL;
107  }
108  else if (this->mode == IMPLICIT_STRUCTURED_MODE)
109  {
110  this->ImplicitDimensions = new int[3];
111  this->ImplicitSplitDimension = -1;
112  this->ImplicitSplitDimensionBeginIndex = -1;
113  this->ImplicitSplitDimensionEndIndex = -1;
114  }
115  else
116  {
117  this->cellMap = NULL;
118  this->cellVector = new IntVector;
119  this->cellNumberOfIds = -1;
120  this->cellLocalNumberOfIds = -1;
121  }
122  }
123 
125  {
126  delete this->cellMap;
127  delete this->cellVector;
128  delete[] this->ImplicitDimensions;
129  }
130 
132  {
133  this->mode = amode;
134  if (this->mode == SPARSE_MODE)
135  {
136  this->cellMap = new IntIntMap;
137  this->cellNumberOfIds = 0;
138  this->cellVector = NULL;
139  }
140  else if (this->mode == IMPLICIT_STRUCTURED_MODE)
141  {
142  this->ImplicitDimensions = new int[3];
143  this->ImplicitSplitDimension = -1;
144  this->ImplicitSplitDimensionBeginIndex = -1;
145  this->ImplicitSplitDimensionEndIndex = -1;
146  }
147  else
148  {
149  this->cellMap = NULL;
150  this->cellVector = new IntVector;
151  this->cellNumberOfIds = -1;
152  this->cellLocalNumberOfIds = -1;
153  }
154  }
155 
156  void SetImplicitDimensions(int dim1, int dim2, int dim3)
157  {
158  this->ImplicitDimensions[0] = dim1;
159  this->ImplicitDimensions[1] = dim2;
160  this->ImplicitDimensions[2] = dim3;
161  }
162 
163  void SetImplicitSplitDimension(int dim) { this->ImplicitSplitDimension = dim; }
164 
166  {
167  this->ImplicitSplitDimensionBeginIndex = begin;
168  }
169 
170  void SetImplicitSplitDimensionEndIndex(int end) { this->ImplicitSplitDimensionEndIndex = end; }
171 
172  // return -1 if not found
173  int GetId(int id)
174  {
175  switch (this->mode)
176  {
177  case SINGLE_PROCESS_MODE:
178  {
179  // Single Process compatibility
180  return id;
181  break;
182  }
184  {
185  if (this->ImplicitSplitDimension == -1)
186  return -1; // not initialized
187 
188  // Compute the global i j k index
189  // id = i + j * dim[0] + k * dim[1] * dim[0]
190  int index[3];
191  index[2] = id / (this->ImplicitDimensions[0] * this->ImplicitDimensions[1]); // k
192  index[1] = (id - (index[2] * this->ImplicitDimensions[0] * this->ImplicitDimensions[1])) /
193  this->ImplicitDimensions[0]; // j
194  index[0] = id - index[1] * this->ImplicitDimensions[0] -
195  index[2] * this->ImplicitDimensions[1] * this->ImplicitDimensions[0]; // i
196  if ((index[this->ImplicitSplitDimension] < this->ImplicitSplitDimensionBeginIndex) ||
197  (index[this->ImplicitSplitDimension] >= this->ImplicitSplitDimensionEndIndex))
198  {
199  // not for me
200  return -1;
201  }
202  else
203  {
204  // Compute the local id
205  int localIndex[3];
206  int localDim[3];
207  int dim = this->ImplicitSplitDimension;
208  localIndex[dim] = index[dim] - this->ImplicitSplitDimensionBeginIndex;
209  localDim[dim] =
210  this->ImplicitSplitDimensionEndIndex - this->ImplicitSplitDimensionBeginIndex;
211  dim = NEXTMODULO3(dim);
212  localIndex[dim] = index[dim];
213  localDim[dim] = this->ImplicitDimensions[dim];
214  dim = NEXTMODULO3(dim);
215  localDim[dim] = this->ImplicitDimensions[dim];
216  localIndex[dim] = index[dim];
217  return localIndex[0] + localDim[0] * localIndex[1] +
218  localDim[0] * localDim[1] * localIndex[2];
219  }
220  }
221  case SPARSE_MODE:
222  {
223  std::map<int, int>::iterator it = this->cellMap->find(id);
224  if (it == this->cellMap->end())
225  return -1;
226  else
227  return (*this->cellMap)[id];
228  break;
229  }
230  default:
231  {
232  if (this->cellVector->size() > (unsigned int)(id))
233  return (*this->cellVector)[id];
234  break;
235  }
236  }
237  return -1;
238  }
239 
240  void SetId(int id, int value)
241  {
242  switch (this->mode)
243  {
244  case SINGLE_PROCESS_MODE:
246  {
247  // Compatibility Only
248  // do noting
249  break;
250  }
251  case SPARSE_MODE:
252  {
253  std::map<int, int>::iterator it = this->cellMap->find(id);
254  if (it == this->cellMap->end())
255  this->cellNumberOfIds++;
256 
257  (*this->cellMap)[id] = value;
258  break;
259  }
260  default:
261  {
262  if (this->cellVector->size() < (unsigned int)(id + 1))
263  {
264  int k;
265  int currentSize = static_cast<int>(this->cellVector->size());
266  this->cellVector->resize(id + 1);
267  for (k = currentSize; k < id; k++)
268  {
269  (*this->cellVector)[k] = -1;
270  }
271  (*this->cellVector)[id] = value;
272  }
273  else
274  {
275  (*this->cellVector)[id] = value;
276  }
277  break;
278  }
279  }
280  }
281 
282  // In distributed mode, if id == -1, do not insert it in map
283  int InsertNextId(int id)
284  {
285  switch (this->mode)
286  {
287  case SINGLE_PROCESS_MODE:
289  {
290  // Single Process compatibility
291  // do noting
292  break;
293  }
294  case SPARSE_MODE:
295  {
296  if (id != -1)
297  {
298  (*this->cellMap)[this->cellNumberOfIds] = id;
299  }
300  // increment fake number of ids
301  this->cellNumberOfIds++;
302  return this->cellNumberOfIds - 1;
303  break;
304  }
305  default:
306  {
307  this->cellVector->push_back(id);
308  return static_cast<int>(this->cellVector->size() - 1);
309  break;
310  }
311  }
312  return static_cast<int>(this->cellVector->size() - 1);
313  }
314 
316  {
317  switch (this->mode)
318  {
319  case SINGLE_PROCESS_MODE:
320  {
321  // Single Process compatibility
322  return this->cellNumberOfIds;
323  break;
324  }
326  {
327  return this->cellNumberOfIds;
328  }
329  case SPARSE_MODE:
330  {
331  return this->cellNumberOfIds;
332  break;
333  }
334  default:
335  {
336  break;
337  }
338  }
339 
340  // Point Ids are directly injected in the vector,
341  // contrary to cell Ids which are "stacked" with
342  // InsertNextId. So the real total number of Ids
343  // for Points cannot be the size of the vector.
344  // So we must inject it manually
345  if (this->cellNumberOfIds >= 0)
346  {
347  return this->cellNumberOfIds;
348  }
349 
350  return static_cast<int>(this->cellVector->size());
351  }
352 
353  // Just inject the real total number of Ids
354  void SetNumberOfIds(int n)
355  {
356  if (this->mode == SPARSE_MODE)
357  {
358  // do nothing
359  }
360  else
361  {
362  // Non sparse Or Single Process
363  this->cellNumberOfIds = n;
364  }
365  }
366 
368  {
369  if (this->mode == SPARSE_MODE)
370  {
371  // do nothing
372  }
373  else
374  {
375  // Non sparse Or Single Process
376  // Used for Structured compatibility
377  this->cellLocalNumberOfIds = n;
378  }
379  }
380 
381  void Reset()
382  {
383  if (this->mode == SPARSE_MODE)
384  {
385  this->cellMap->clear();
386  this->cellNumberOfIds = 0;
387  }
388  else
389  {
390  if (this->mode == NON_SPARSE_MODE)
391  this->cellVector->clear();
392  if (this->cellNumberOfIds >= 0)
393  this->cellNumberOfIds = -1;
394  if (this->cellLocalNumberOfIds >= 0)
395  this->cellLocalNumberOfIds = -1;
396  }
397  }
398 
400  {
401  switch (this->mode)
402  {
403  case SINGLE_PROCESS_MODE:
404  {
405  // Single Process compatibility
406  return this->cellNumberOfIds;
407  break;
408  }
410  {
411  return this->cellLocalNumberOfIds;
412  }
413  case SPARSE_MODE:
414  {
415  return static_cast<int>(this->cellMap->size());
416  break;
417  }
418  default:
419  {
420  break;
421  }
422  }
423 
424  // Return cellLocalNumberOfIds if valid
425  if (this->cellLocalNumberOfIds >= 0)
426  {
427  return this->cellLocalNumberOfIds;
428  }
429 
430  // Else compute the real size
431  int result = 0;
432  for (unsigned int i = 0; i < this->cellVector->size(); i++)
433  {
434  if ((*this->cellVector)[i] != -1)
435  result++;
436  }
437  return result;
438  }
439 
441  {
442  // Generate a sorted Array For Global Ids
443  // Your local Ids must be consistent !
444  if (this->mode == IMPLICIT_STRUCTURED_MODE)
445  {
447  array->SetNumberOfComponents(1);
448  array->SetName(name);
449  int localDim[3];
450 
451  int dim = this->ImplicitSplitDimension;
452  localDim[dim] =
453  this->ImplicitSplitDimensionEndIndex - this->ImplicitSplitDimensionBeginIndex;
454  dim = NEXTMODULO3(dim);
455  localDim[dim] = this->ImplicitDimensions[dim];
456  dim = NEXTMODULO3(dim);
457  localDim[dim] = this->ImplicitDimensions[dim];
458  array->SetNumberOfTuples(localDim[0] * localDim[1] * localDim[2]);
459 
460  int index = 0;
461  for (int k = 0; k < this->ImplicitDimensions[2]; k++)
462  {
463  for (int j = 0; j < this->ImplicitDimensions[1]; j++)
464  {
465  for (int i = 0; i < this->ImplicitDimensions[0]; i++)
466  {
467  int n = (this->ImplicitSplitDimension == 0)
468  ? i
469  : ((this->ImplicitSplitDimension == 1) ? j : k);
470  if ((n >= this->ImplicitSplitDimensionBeginIndex) &&
471  (n < this->ImplicitSplitDimensionEndIndex))
472  {
473  vtkIdType nn = n;
474  array->SetTypedTuple(index, &nn);
475  index++;
476  }
477  }
478  }
479  }
480  return array;
481  }
482  else
483  {
484  int i;
486  array->SetNumberOfComponents(1);
487  array->SetName(name);
488  array->SetNumberOfTuples(this->GetLocalNumberOfIds());
489  int min = 1000000000;
490  int max = -1;
491  for (i = 0; i < this->GetNumberOfIds(); i++)
492  {
493  int id = this->GetId(i);
494  if (id != -1)
495  {
496  vtkIdType ii = i;
497  if (ii < min)
498  min = ii;
499  if (ii > max)
500  max = ii;
501  array->SetTypedTuple(id, &ii);
502  }
503  }
504  return array;
505  }
506  }
507 
508  protected:
509  IntIntMap* cellMap;
512  IntVector* cellVector;
513  // Implicit Structured Real (global) dimensions
515  // Implicit Structured local dimensions
517  // Implicit Structured Split Dimension
519  // Implicit Structured Split Dimension Begin Index. Inclusive
521  // Implicit StructuredSplit Dimension End Index. Exclusive
523 
525  };
526 
528  {
529  POINT = 0,
530  BAR2 = 1,
531  BAR3 = 2,
532  NSIDED = 3,
533  TRIA3 = 4,
534  TRIA6 = 5,
535  QUAD4 = 6,
536  QUAD8 = 7,
537  NFACED = 8,
538  TETRA4 = 9,
539  TETRA10 = 10,
540  PYRAMID5 = 11,
541  PYRAMID13 = 12,
542  HEXA8 = 13,
543  HEXA20 = 14,
544  PENTA6 = 15,
545  PENTA15 = 16,
546  NUMBER_OF_ELEMENT_TYPES = 17
547  };
548 
550  {
551  SCALAR_PER_NODE = 0,
552  VECTOR_PER_NODE = 1,
553  TENSOR_SYMM_PER_NODE = 2,
554  SCALAR_PER_ELEMENT = 3,
555  VECTOR_PER_ELEMENT = 4,
556  TENSOR_SYMM_PER_ELEMENT = 5,
557  SCALAR_PER_MEASURED_NODE = 6,
558  VECTOR_PER_MEASURED_NODE = 7,
559  COMPLEX_SCALAR_PER_NODE = 8,
560  COMPLEX_VECTOR_PER_NODE = 9,
561  COMPLEX_SCALAR_PER_ELEMENT = 10,
562  COMPLEX_VECTOR_PER_ELEMENT = 11
563  };
564 
566  {
567  COORDINATES = 0,
568  BLOCK = 1,
569  ELEMENT = 2
570  };
571 
573 
577  vtkGetStringMacro(MeasuredFileName);
579 
581 
585  vtkGetStringMacro(MatchFileName);
587 
588 protected:
590  ~vtkPEnSightReader() override;
591 
592  int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
593  int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
594 
595  /*int RequestUpdateExtent(
596  vtkInformation *vtkNotUsed(request),
597  vtkInformationVector **inputVector,
598  vtkInformationVector *outputVector);
599  */
600 
602 
605  vtkSetStringMacro(MeasuredFileName);
607 
609 
612  vtkSetStringMacro(MatchFileName);
614 
616 
619  int ReadCaseFile();
620  int ReadCaseFileGeometry(char* line);
621  int ReadCaseFileVariable(char* line);
622  int ReadCaseFileTime(char* line);
623  int ReadCaseFileFile(char* line);
625 
626  // set in UpdateInformation to value returned from ReadCaseFile
628 
632  virtual int ReadGeometryFile(
633  const char* fileName, int timeStep, vtkMultiBlockDataSet* output) = 0;
634 
639  virtual int ReadMeasuredGeometryFile(
640  const char* fileName, int timeStep, vtkMultiBlockDataSet* output) = 0;
641 
645  int ReadVariableFiles(vtkMultiBlockDataSet* output);
646 
651  virtual int ReadScalarsPerNode(const char* fileName, const char* description, int timeStep,
652  vtkMultiBlockDataSet* output, int measured = 0, int numberOfComponents = 1,
653  int component = 0) = 0;
654 
659  virtual int ReadVectorsPerNode(const char* fileName, const char* description, int timeStep,
660  vtkMultiBlockDataSet* output, int measured = 0) = 0;
661 
666  virtual int ReadTensorsPerNode(
667  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
668 
673  virtual int ReadScalarsPerElement(const char* fileName, const char* description, int timeStep,
674  vtkMultiBlockDataSet* output, int numberOfComponents = 1, int component = 0) = 0;
675 
680  virtual int ReadVectorsPerElement(
681  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
682 
687  virtual int ReadTensorsPerElement(
688  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
689 
694  virtual int CreateUnstructuredGridOutput(
695  int partId, char line[80], const char* name, vtkMultiBlockDataSet* output) = 0;
696 
701  virtual int CreateStructuredGridOutput(
702  int partId, char line[80], const char* name, vtkMultiBlockDataSet* output) = 0;
703 
707  void AddVariableFileName(const char* fileName1, const char* fileName2 = NULL);
708 
712  void AddVariableDescription(const char* description);
713 
717  void AddVariableType();
718 
723  int GetElementType(const char* line);
724 
729  int GetSectionType(const char* line);
730 
734  void ReplaceWildcards(char* filename, int num);
735 
739  void RemoveLeadingBlanks(char* line);
740 
744  vtkPEnSightReaderCellIds* GetCellIds(int index, int cellType);
745 
747 
751  vtkIdType GetTotalNumberOfCellIds(int index);
752  vtkIdType GetLocalTotalNumberOfCellIds(int index);
754 
759  vtkPEnSightReaderCellIds* GetPointIds(int index);
760 
765  void AddToBlock(vtkMultiBlockDataSet* output, unsigned int blockNo, vtkDataSet* dataset);
766 
771  vtkDataSet* GetDataSetFromBlock(vtkMultiBlockDataSet* output, unsigned int blockNo);
772 
776  void SetBlockName(vtkMultiBlockDataSet* output, unsigned int blockNo, const char* name);
777 
779 
784  void InsertNextCellAndId(vtkUnstructuredGrid*, int vtkCellType, vtkIdType numPoints,
785  vtkIdType* points, int partId, int ensightCellType, vtkIdType globalId, vtkIdType numElements,
786  const std::vector<vtkIdType>& faces = {});
787  void InsertVariableComponent(vtkFloatArray* array, int i, int component, float* content,
788  int partId, int ensightCellType, int insertionType);
790 
794  void MapToGlobalIds(
795  const vtkIdType* inputIds, vtkIdType numPoints, int partId, vtkIdType* globalIds);
796 
803  void PrepareStructuredDimensionsForDistribution(int partId, int* oldDimensions,
804  int* newDimensions, int* splitDimension, int* splitDimensionBeginIndex, int ghostLevel,
805  vtkUnsignedCharArray* pointGhostArray, vtkUnsignedCharArray* cellGhostArray);
806 
808  char* MatchFileName; // may not actually be necessary to read this file
809 
810  // pointer to lists of list (cell ids per element type per part)
811  vtkPEnSightReaderCellIdsType* CellIds;
812 
813  // pointer to lists of list (point ids per element type per part)
814  vtkPEnSightReaderCellIdsType* PointIds;
815 
816  // part ids of unstructured outputs
818  // part ids of structured outputs
820 
825 
827 
828  // pointers to lists of filenames
829  char** VariableFileNames; // non-complex
831 
832  // array of time sets
835 
836  // array of file sets
839 
840  // collection of filename numbers per time set
843 
844  // collection of filename numbers per file set
847 
848  // collection of number of steps per file per file set
850 
851  // ids of the time and file sets
854 
859 
862 
864  vtkSetMacro(UseTimeSets, int);
865  vtkGetMacro(UseTimeSets, int);
866  vtkBooleanMacro(UseTimeSets, int);
867 
868  int UseFileSets;
869  vtkSetMacro(UseFileSets, int);
870  vtkGetMacro(UseFileSets, int);
871  vtkBooleanMacro(UseFileSets, int);
872 
874 
875  // global list of points for measured geometry
877 
880 
881  int CheckOutputConsistency();
882 
884 
886 
887  std::map<std::string, std::map<int, long> > FileOffsets;
888 
889 private:
890  vtkPEnSightReader(const vtkPEnSightReader&) = delete;
891  void operator=(const vtkPEnSightReader&) = delete;
892 };
893 
894 #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
virtual void SetName(const char *)
SINGLE_PROCESS_MODE
NON_SPARSE_MODE
void PrintSelf(ostream &os, vtkIndent indent) override
vtkIdTypeArray * GenerateGlobalIdsArray(const char *name)
static vtkIdTypeArray * New()
vtkIdList * VariableFileSetIds
mode
IMPLICIT_STRUCTURED_MODE
virtual void SetNumberOfComponents(int)
vtkIdListCollection * FileSetFileNameNumbers
void SetImplicitDimensions(int dim1, int dim2, int dim3)
#define NEXTMODULO3(x)
vtkIdListCollection * TimeSetFileNameNumbers
vtkIdList * ComplexVariableTimeSetIds
virtual void SetNumberOfTuples(vtkIdType numTuples)=0
index
vtkIdListCollection * FileSetNumberOfSteps
#define VTKPVVTKEXTENSIONSIOENSIGHT_EXPORT
vtkIdList * StructuredPartIds
#define max(a, b)
std::map< std::string, std::map< int, long > > FileOffsets
vtkPEnSightReaderCellIdsType * PointIds
vtkIdList * FileSetsWithFilenameNumbers