vtkPEnSightReader.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
3 // SPDX-FileCopyrightText: Copyright (c) CEA
4 // SPDX-License-Identifier: BSD-3-Clause
21 #ifndef vtkPEnSightReader_h
22 #define vtkPEnSightReader_h
23 
25 #include "vtkPVVTKExtensionsIOEnSightModule.h" //needed for exports
26 
27 #include "vtkIdTypeArray.h" // For ivars
28 #include <algorithm> // For ivars
29 #include <map> // For ivars
30 #include <string> // For ivars
31 #include <vector> // For ivars
32 
33 class vtkCellArray;
34 class vtkDataSet;
35 class vtkIdList;
37 class vtkInformation;
41 class vtkFloatArray;
42 class vtkPEnSightReaderCellIdsType;
43 
44 #define NEXTMODULO3(x) (x == 0) ? 1 : ((x == 1) ? 2 : 0)
45 
47 {
48 public:
50  void PrintSelf(ostream& os, vtkIndent indent) override;
51 
52  //----------------------------------------------------------------------------
53  // PointIds and CellIds must be stored in a different way:
54  // std::vector in non distributed mode
55  // std::map in distributed mode
56  // note: Ensight Ids are INTEGERS, not longs
58  {
59 
60  public:
61  typedef std::map<int, int> IntIntMap;
62  typedef std::vector<int> IntVector;
63 
65  : cellMap(nullptr)
66  , cellNumberOfIds(-1)
67  , cellLocalNumberOfIds(-1)
68  , cellVector(nullptr)
69  , ImplicitDimensions(nullptr)
70  , ImplicitLocalDimensions(nullptr)
71  , ImplicitSplitDimension(-1)
72  , ImplicitSplitDimensionBeginIndex(-1)
73  , ImplicitSplitDimensionEndIndex(-1)
75  {
76  }
77 
79  : cellMap(nullptr)
80  , cellNumberOfIds(-1)
81  , cellLocalNumberOfIds(-1)
82  , cellVector(nullptr)
83  , ImplicitDimensions(nullptr)
84  , ImplicitLocalDimensions(nullptr)
85  , ImplicitSplitDimension(-1)
86  , ImplicitSplitDimensionBeginIndex(-1)
87  , ImplicitSplitDimensionEndIndex(-1)
88  , mode(amode)
89  {
90  if (this->mode == SPARSE_MODE)
91  {
92  this->cellMap = new IntIntMap;
93  this->cellNumberOfIds = 0;
94  this->cellVector = nullptr;
95  }
96  else if (this->mode == IMPLICIT_STRUCTURED_MODE)
97  {
98  this->ImplicitDimensions = new int[3];
99  this->ImplicitSplitDimension = -1;
100  this->ImplicitSplitDimensionBeginIndex = -1;
101  this->ImplicitSplitDimensionEndIndex = -1;
102  }
103  else
104  {
105  this->cellMap = nullptr;
106  this->cellVector = new IntVector;
107  this->cellNumberOfIds = -1;
108  this->cellLocalNumberOfIds = -1;
109  }
110  }
111 
113  {
114  delete this->cellMap;
115  delete this->cellVector;
116  delete[] this->ImplicitDimensions;
117  }
118 
120  {
121  this->mode = amode;
122  if (this->mode == SPARSE_MODE)
123  {
124  this->cellMap = new IntIntMap;
125  this->cellNumberOfIds = 0;
126  this->cellVector = nullptr;
127  }
128  else if (this->mode == IMPLICIT_STRUCTURED_MODE)
129  {
130  this->ImplicitDimensions = new int[3];
131  this->ImplicitSplitDimension = -1;
132  this->ImplicitSplitDimensionBeginIndex = -1;
133  this->ImplicitSplitDimensionEndIndex = -1;
134  }
135  else
136  {
137  this->cellMap = nullptr;
138  this->cellVector = new IntVector;
139  this->cellNumberOfIds = -1;
140  this->cellLocalNumberOfIds = -1;
141  }
142  }
143 
144  void SetImplicitDimensions(int dim1, int dim2, int dim3)
145  {
146  this->ImplicitDimensions[0] = dim1;
147  this->ImplicitDimensions[1] = dim2;
148  this->ImplicitDimensions[2] = dim3;
149  }
150 
151  void SetImplicitSplitDimension(int dim) { this->ImplicitSplitDimension = dim; }
152 
154  {
155  this->ImplicitSplitDimensionBeginIndex = begin;
156  }
157 
158  void SetImplicitSplitDimensionEndIndex(int end) { this->ImplicitSplitDimensionEndIndex = end; }
159 
160  // return -1 if not found
161  int GetId(int id)
162  {
163  switch (this->mode)
164  {
165  case SINGLE_PROCESS_MODE:
166  {
167  // Single Process compatibility
168  return id;
169  break;
170  }
172  {
173  if (this->ImplicitSplitDimension == -1)
174  return -1; // not initialized
175 
176  // Compute the global i j k index
177  // id = i + j * dim[0] + k * dim[1] * dim[0]
178  int index[3];
179  index[2] = id / (this->ImplicitDimensions[0] * this->ImplicitDimensions[1]); // k
180  index[1] = (id - (index[2] * this->ImplicitDimensions[0] * this->ImplicitDimensions[1])) /
181  this->ImplicitDimensions[0]; // j
182  index[0] = id - index[1] * this->ImplicitDimensions[0] -
183  index[2] * this->ImplicitDimensions[1] * this->ImplicitDimensions[0]; // i
184  if ((index[this->ImplicitSplitDimension] < this->ImplicitSplitDimensionBeginIndex) ||
185  (index[this->ImplicitSplitDimension] >= this->ImplicitSplitDimensionEndIndex))
186  {
187  // not for me
188  return -1;
189  }
190  else
191  {
192  // Compute the local id
193  int localIndex[3];
194  int localDim[3];
195  int dim = this->ImplicitSplitDimension;
196  localIndex[dim] = index[dim] - this->ImplicitSplitDimensionBeginIndex;
197  localDim[dim] =
198  this->ImplicitSplitDimensionEndIndex - this->ImplicitSplitDimensionBeginIndex;
199  dim = NEXTMODULO3(dim);
200  localIndex[dim] = index[dim];
201  localDim[dim] = this->ImplicitDimensions[dim];
202  dim = NEXTMODULO3(dim);
203  localDim[dim] = this->ImplicitDimensions[dim];
204  localIndex[dim] = index[dim];
205  return localIndex[0] + localDim[0] * localIndex[1] +
206  localDim[0] * localDim[1] * localIndex[2];
207  }
208  }
209  case SPARSE_MODE:
210  {
211  std::map<int, int>::iterator it = this->cellMap->find(id);
212  if (it == this->cellMap->end())
213  return -1;
214  else
215  return (*this->cellMap)[id];
216  break;
217  }
218  default:
219  {
220  if (this->cellVector->size() > (unsigned int)(id))
221  return (*this->cellVector)[id];
222  break;
223  }
224  }
225  return -1;
226  }
227 
228  void SetId(int id, int value)
229  {
230  switch (this->mode)
231  {
232  case SINGLE_PROCESS_MODE:
234  {
235  // Compatibility Only
236  // do noting
237  break;
238  }
239  case SPARSE_MODE:
240  {
241  std::map<int, int>::iterator it = this->cellMap->find(id);
242  if (it == this->cellMap->end())
243  this->cellNumberOfIds++;
244 
245  (*this->cellMap)[id] = value;
246  break;
247  }
248  default:
249  {
250  if (this->cellVector->size() < (unsigned int)(id + 1))
251  {
252  int k;
253  int currentSize = static_cast<int>(this->cellVector->size());
254  this->cellVector->resize(id + 1);
255  for (k = currentSize; k < id; k++)
256  {
257  (*this->cellVector)[k] = -1;
258  }
259  (*this->cellVector)[id] = value;
260  }
261  else
262  {
263  (*this->cellVector)[id] = value;
264  }
265  break;
266  }
267  }
268  }
269 
270  // In distributed mode, if id == -1, do not insert it in map
271  int InsertNextId(int id)
272  {
273  switch (this->mode)
274  {
275  case SINGLE_PROCESS_MODE:
277  {
278  // Single Process compatibility
279  // do noting
280  break;
281  }
282  case SPARSE_MODE:
283  {
284  if (id != -1)
285  {
286  (*this->cellMap)[this->cellNumberOfIds] = id;
287  }
288  // increment fake number of ids
289  this->cellNumberOfIds++;
290  return this->cellNumberOfIds - 1;
291  break;
292  }
293  default:
294  {
295  this->cellVector->push_back(id);
296  return static_cast<int>(this->cellVector->size() - 1);
297  break;
298  }
299  }
300  return static_cast<int>(this->cellVector->size() - 1);
301  }
302 
304  {
305  switch (this->mode)
306  {
307  case SINGLE_PROCESS_MODE:
308  {
309  // Single Process compatibility
310  return this->cellNumberOfIds;
311  break;
312  }
314  {
315  return this->cellNumberOfIds;
316  }
317  case SPARSE_MODE:
318  {
319  return this->cellNumberOfIds;
320  break;
321  }
322  default:
323  {
324  break;
325  }
326  }
327 
328  // Point Ids are directly injected in the vector,
329  // contrary to cell Ids which are "stacked" with
330  // InsertNextId. So the real total number of Ids
331  // for Points cannot be the size of the vector.
332  // So we must inject it manually
333  if (this->cellNumberOfIds >= 0)
334  {
335  return this->cellNumberOfIds;
336  }
337 
338  return static_cast<int>(this->cellVector->size());
339  }
340 
341  // Just inject the real total number of Ids
342  void SetNumberOfIds(int n)
343  {
344  if (this->mode == SPARSE_MODE)
345  {
346  // do nothing
347  }
348  else
349  {
350  // Non sparse Or Single Process
351  this->cellNumberOfIds = n;
352  }
353  }
354 
356  {
357  if (this->mode == SPARSE_MODE)
358  {
359  // do nothing
360  }
361  else
362  {
363  // Non sparse Or Single Process
364  // Used for Structured compatibility
365  this->cellLocalNumberOfIds = n;
366  }
367  }
368 
369  void Reset()
370  {
371  if (this->mode == SPARSE_MODE)
372  {
373  this->cellMap->clear();
374  this->cellNumberOfIds = 0;
375  }
376  else
377  {
378  if (this->mode == NON_SPARSE_MODE)
379  this->cellVector->clear();
380  if (this->cellNumberOfIds >= 0)
381  this->cellNumberOfIds = -1;
382  if (this->cellLocalNumberOfIds >= 0)
383  this->cellLocalNumberOfIds = -1;
384  }
385  }
386 
388  {
389  switch (this->mode)
390  {
391  case SINGLE_PROCESS_MODE:
392  {
393  // Single Process compatibility
394  return this->cellNumberOfIds;
395  break;
396  }
398  {
399  return this->cellLocalNumberOfIds;
400  }
401  case SPARSE_MODE:
402  {
403  return static_cast<int>(this->cellMap->size());
404  break;
405  }
406  default:
407  {
408  break;
409  }
410  }
411 
412  // Return cellLocalNumberOfIds if valid
413  if (this->cellLocalNumberOfIds >= 0)
414  {
415  return this->cellLocalNumberOfIds;
416  }
417 
418  // Else compute the real size
419  int result = 0;
420  for (unsigned int i = 0; i < this->cellVector->size(); i++)
421  {
422  if ((*this->cellVector)[i] != -1)
423  result++;
424  }
425  return result;
426  }
427 
428  protected:
429  IntIntMap* cellMap;
432  IntVector* cellVector;
433  // Implicit Structured Real (global) dimensions
435  // Implicit Structured local dimensions
437  // Implicit Structured Split Dimension
439  // Implicit Structured Split Dimension Begin Index. Inclusive
441  // Implicit StructuredSplit Dimension End Index. Exclusive
443 
445  };
446 
448  {
449  POINT = 0,
450  BAR2 = 1,
451  BAR3 = 2,
452  NSIDED = 3,
453  TRIA3 = 4,
454  TRIA6 = 5,
455  QUAD4 = 6,
456  QUAD8 = 7,
457  NFACED = 8,
458  TETRA4 = 9,
459  TETRA10 = 10,
460  PYRAMID5 = 11,
461  PYRAMID13 = 12,
462  HEXA8 = 13,
463  HEXA20 = 14,
464  PENTA6 = 15,
465  PENTA15 = 16,
466  NUMBER_OF_ELEMENT_TYPES = 17
467  };
468 
470  {
471  SCALAR_PER_NODE = 0,
472  VECTOR_PER_NODE = 1,
473  TENSOR_SYMM_PER_NODE = 2,
474  SCALAR_PER_ELEMENT = 3,
475  VECTOR_PER_ELEMENT = 4,
476  TENSOR_SYMM_PER_ELEMENT = 5,
477  SCALAR_PER_MEASURED_NODE = 6,
478  VECTOR_PER_MEASURED_NODE = 7,
479  COMPLEX_SCALAR_PER_NODE = 8,
480  COMPLEX_VECTOR_PER_NODE = 9,
481  COMPLEX_SCALAR_PER_ELEMENT = 10,
482  COMPLEX_VECTOR_PER_ELEMENT = 11
483  };
484 
486  {
487  COORDINATES = 0,
488  BLOCK = 1,
489  ELEMENT = 2
490  };
491 
493 
497  vtkGetStringMacro(MeasuredFileName);
499 
501 
505  vtkGetStringMacro(MatchFileName);
507 
508 protected:
510  ~vtkPEnSightReader() override;
511 
512  int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
513  int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
514 
515  /*int RequestUpdateExtent(
516  vtkInformation *vtkNotUsed(request),
517  vtkInformationVector **inputVector,
518  vtkInformationVector *outputVector);
519  */
520 
522 
525  vtkSetStringMacro(MeasuredFileName);
527 
529 
532  vtkSetStringMacro(MatchFileName);
534 
536 
539  int ReadCaseFile();
540  int ReadCaseFileGeometry(char* line);
541  int ReadCaseFileVariable(char* line);
542  int ReadCaseFileTime(char* line);
543  int ReadCaseFileFile(char* line);
545 
546  // set in UpdateInformation to value returned from ReadCaseFile
548 
552  virtual int ReadGeometryFile(
553  const char* fileName, int timeStep, vtkMultiBlockDataSet* output) = 0;
554 
559  virtual int ReadMeasuredGeometryFile(
560  const char* fileName, int timeStep, vtkMultiBlockDataSet* output) = 0;
561 
565  int ReadVariableFiles(vtkMultiBlockDataSet* output);
566 
571  virtual int ReadScalarsPerNode(const char* fileName, const char* description, int timeStep,
572  vtkMultiBlockDataSet* output, int measured = 0, int numberOfComponents = 1,
573  int component = 0) = 0;
574 
579  virtual int ReadVectorsPerNode(const char* fileName, const char* description, int timeStep,
580  vtkMultiBlockDataSet* output, int measured = 0) = 0;
581 
586  virtual int ReadTensorsPerNode(
587  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
588 
593  virtual int ReadScalarsPerElement(const char* fileName, const char* description, int timeStep,
594  vtkMultiBlockDataSet* output, int numberOfComponents = 1, int component = 0) = 0;
595 
600  virtual int ReadVectorsPerElement(
601  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
602 
607  virtual int ReadTensorsPerElement(
608  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
609 
614  virtual int CreateUnstructuredGridOutput(
615  int partId, char line[80], const char* name, vtkMultiBlockDataSet* output) = 0;
616 
621  virtual int CreateStructuredGridOutput(
622  int partId, char line[80], const char* name, vtkMultiBlockDataSet* output) = 0;
623 
627  void AddVariableFileName(const char* fileName1, const char* fileName2 = nullptr);
628 
632  void AddVariableDescription(const char* description);
633 
637  void AddVariableType();
638 
643  int GetElementType(const char* line);
644 
649  int GetSectionType(const char* line);
650 
654  void ReplaceWildcards(char* filename, int num);
655 
659  void RemoveLeadingBlanks(char* line);
660 
664  vtkPEnSightReaderCellIds* GetCellIds(int index, int cellType);
665 
667 
671  vtkIdType GetTotalNumberOfCellIds(int index);
672  vtkIdType GetLocalTotalNumberOfCellIds(int index);
674 
679  vtkPEnSightReaderCellIds* GetPointIds(int index);
680 
685  void AddToBlock(vtkMultiBlockDataSet* output, unsigned int blockNo, vtkDataSet* dataset);
686 
691  vtkDataSet* GetDataSetFromBlock(vtkMultiBlockDataSet* output, unsigned int blockNo);
692 
696  void SetBlockName(vtkMultiBlockDataSet* output, unsigned int blockNo, const char* name);
697 
699 
704  void InsertNextCellAndId(vtkUnstructuredGrid*, int vtkCellType, vtkIdType numPoints,
705  vtkIdType* points, int partId, int ensightCellType, vtkIdType globalId, vtkIdType numElements,
706  vtkCellArray* faces = nullptr);
707  void InsertVariableComponent(vtkFloatArray* array, int i, int component, float* content,
708  int partId, int ensightCellType, int insertionType);
710 
714  void MapToGlobalIds(
715  const vtkIdType* inputIds, vtkIdType numPoints, int partId, vtkIdType* globalIds);
716 
723  void PrepareStructuredDimensionsForDistribution(int partId, int* oldDimensions,
724  int* newDimensions, int* splitDimension, int* splitDimensionBeginIndex, int ghostLevel,
725  vtkUnsignedCharArray* pointGhostArray, vtkUnsignedCharArray* cellGhostArray);
726 
728  char* MatchFileName; // may not actually be necessary to read this file
729 
730  // pointer to lists of list (cell ids per element type per part)
731  vtkPEnSightReaderCellIdsType* CellIds;
732 
733  // pointer to lists of list (point ids per element type per part)
734  vtkPEnSightReaderCellIdsType* PointIds;
735 
736  // part ids of unstructured outputs
738  // part ids of structured outputs
740 
745 
747 
748  // pointers to lists of filenames
749  char** VariableFileNames; // non-complex
751 
752  // array of time sets
755 
756  // array of file sets
759 
760  // collection of filename numbers per time set
763 
764  // collection of filename numbers per file set
767 
768  // collection of number of steps per file per file set
770 
771  // ids of the time and file sets
774 
779 
782 
784  vtkSetMacro(UseTimeSets, int);
785  vtkGetMacro(UseTimeSets, int);
786  vtkBooleanMacro(UseTimeSets, int);
787 
788  int UseFileSets;
789  vtkSetMacro(UseFileSets, int);
790  vtkGetMacro(UseFileSets, int);
791  vtkBooleanMacro(UseFileSets, int);
792 
794 
795  // global list of points for measured geometry
797 
800 
801  int CheckOutputConsistency();
802 
804 
806 
807  std::map<std::string, std::map<int, long>> FileOffsets;
808 
809 private:
810  vtkPEnSightReader(const vtkPEnSightReader&) = delete;
811  void operator=(const vtkPEnSightReader&) = delete;
812 };
813 
814 #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