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 vtkDataSet;
34 class vtkIdList;
36 class vtkInformation;
40 class vtkFloatArray;
41 class vtkPEnSightReaderCellIdsType;
42 
43 #define NEXTMODULO3(x) (x == 0) ? 1 : ((x == 1) ? 2 : 0)
44 
46 {
47 public:
49  void PrintSelf(ostream& os, vtkIndent indent) override;
50 
51  //----------------------------------------------------------------------------
52  // PointIds and CellIds must be stored in a different way:
53  // std::vector in non distributed mode
54  // std::map in distributed mode
55  // note: Ensight Ids are INTEGERS, not longs
57  {
58 
59  public:
60  typedef std::map<int, int> IntIntMap;
61  typedef std::vector<int> IntVector;
62 
64  : cellMap(nullptr)
65  , cellNumberOfIds(-1)
66  , cellLocalNumberOfIds(-1)
67  , cellVector(nullptr)
68  , ImplicitDimensions(nullptr)
69  , ImplicitLocalDimensions(nullptr)
70  , ImplicitSplitDimension(-1)
71  , ImplicitSplitDimensionBeginIndex(-1)
72  , ImplicitSplitDimensionEndIndex(-1)
74  {
75  }
76 
78  : cellMap(nullptr)
79  , cellNumberOfIds(-1)
80  , cellLocalNumberOfIds(-1)
81  , cellVector(nullptr)
82  , ImplicitDimensions(nullptr)
83  , ImplicitLocalDimensions(nullptr)
84  , ImplicitSplitDimension(-1)
85  , ImplicitSplitDimensionBeginIndex(-1)
86  , ImplicitSplitDimensionEndIndex(-1)
87  , mode(amode)
88  {
89  if (this->mode == SPARSE_MODE)
90  {
91  this->cellMap = new IntIntMap;
92  this->cellNumberOfIds = 0;
93  this->cellVector = nullptr;
94  }
95  else if (this->mode == IMPLICIT_STRUCTURED_MODE)
96  {
97  this->ImplicitDimensions = new int[3];
98  this->ImplicitSplitDimension = -1;
99  this->ImplicitSplitDimensionBeginIndex = -1;
100  this->ImplicitSplitDimensionEndIndex = -1;
101  }
102  else
103  {
104  this->cellMap = nullptr;
105  this->cellVector = new IntVector;
106  this->cellNumberOfIds = -1;
107  this->cellLocalNumberOfIds = -1;
108  }
109  }
110 
112  {
113  delete this->cellMap;
114  delete this->cellVector;
115  delete[] this->ImplicitDimensions;
116  }
117 
119  {
120  this->mode = amode;
121  if (this->mode == SPARSE_MODE)
122  {
123  this->cellMap = new IntIntMap;
124  this->cellNumberOfIds = 0;
125  this->cellVector = nullptr;
126  }
127  else if (this->mode == IMPLICIT_STRUCTURED_MODE)
128  {
129  this->ImplicitDimensions = new int[3];
130  this->ImplicitSplitDimension = -1;
131  this->ImplicitSplitDimensionBeginIndex = -1;
132  this->ImplicitSplitDimensionEndIndex = -1;
133  }
134  else
135  {
136  this->cellMap = nullptr;
137  this->cellVector = new IntVector;
138  this->cellNumberOfIds = -1;
139  this->cellLocalNumberOfIds = -1;
140  }
141  }
142 
143  void SetImplicitDimensions(int dim1, int dim2, int dim3)
144  {
145  this->ImplicitDimensions[0] = dim1;
146  this->ImplicitDimensions[1] = dim2;
147  this->ImplicitDimensions[2] = dim3;
148  }
149 
150  void SetImplicitSplitDimension(int dim) { this->ImplicitSplitDimension = dim; }
151 
153  {
154  this->ImplicitSplitDimensionBeginIndex = begin;
155  }
156 
157  void SetImplicitSplitDimensionEndIndex(int end) { this->ImplicitSplitDimensionEndIndex = end; }
158 
159  // return -1 if not found
160  int GetId(int id)
161  {
162  switch (this->mode)
163  {
164  case SINGLE_PROCESS_MODE:
165  {
166  // Single Process compatibility
167  return id;
168  break;
169  }
171  {
172  if (this->ImplicitSplitDimension == -1)
173  return -1; // not initialized
174 
175  // Compute the global i j k index
176  // id = i + j * dim[0] + k * dim[1] * dim[0]
177  int index[3];
178  index[2] = id / (this->ImplicitDimensions[0] * this->ImplicitDimensions[1]); // k
179  index[1] = (id - (index[2] * this->ImplicitDimensions[0] * this->ImplicitDimensions[1])) /
180  this->ImplicitDimensions[0]; // j
181  index[0] = id - index[1] * this->ImplicitDimensions[0] -
182  index[2] * this->ImplicitDimensions[1] * this->ImplicitDimensions[0]; // i
183  if ((index[this->ImplicitSplitDimension] < this->ImplicitSplitDimensionBeginIndex) ||
184  (index[this->ImplicitSplitDimension] >= this->ImplicitSplitDimensionEndIndex))
185  {
186  // not for me
187  return -1;
188  }
189  else
190  {
191  // Compute the local id
192  int localIndex[3];
193  int localDim[3];
194  int dim = this->ImplicitSplitDimension;
195  localIndex[dim] = index[dim] - this->ImplicitSplitDimensionBeginIndex;
196  localDim[dim] =
197  this->ImplicitSplitDimensionEndIndex - this->ImplicitSplitDimensionBeginIndex;
198  dim = NEXTMODULO3(dim);
199  localIndex[dim] = index[dim];
200  localDim[dim] = this->ImplicitDimensions[dim];
201  dim = NEXTMODULO3(dim);
202  localDim[dim] = this->ImplicitDimensions[dim];
203  localIndex[dim] = index[dim];
204  return localIndex[0] + localDim[0] * localIndex[1] +
205  localDim[0] * localDim[1] * localIndex[2];
206  }
207  }
208  case SPARSE_MODE:
209  {
210  std::map<int, int>::iterator it = this->cellMap->find(id);
211  if (it == this->cellMap->end())
212  return -1;
213  else
214  return (*this->cellMap)[id];
215  break;
216  }
217  default:
218  {
219  if (this->cellVector->size() > (unsigned int)(id))
220  return (*this->cellVector)[id];
221  break;
222  }
223  }
224  return -1;
225  }
226 
227  void SetId(int id, int value)
228  {
229  switch (this->mode)
230  {
231  case SINGLE_PROCESS_MODE:
233  {
234  // Compatibility Only
235  // do noting
236  break;
237  }
238  case SPARSE_MODE:
239  {
240  std::map<int, int>::iterator it = this->cellMap->find(id);
241  if (it == this->cellMap->end())
242  this->cellNumberOfIds++;
243 
244  (*this->cellMap)[id] = value;
245  break;
246  }
247  default:
248  {
249  if (this->cellVector->size() < (unsigned int)(id + 1))
250  {
251  int k;
252  int currentSize = static_cast<int>(this->cellVector->size());
253  this->cellVector->resize(id + 1);
254  for (k = currentSize; k < id; k++)
255  {
256  (*this->cellVector)[k] = -1;
257  }
258  (*this->cellVector)[id] = value;
259  }
260  else
261  {
262  (*this->cellVector)[id] = value;
263  }
264  break;
265  }
266  }
267  }
268 
269  // In distributed mode, if id == -1, do not insert it in map
270  int InsertNextId(int id)
271  {
272  switch (this->mode)
273  {
274  case SINGLE_PROCESS_MODE:
276  {
277  // Single Process compatibility
278  // do noting
279  break;
280  }
281  case SPARSE_MODE:
282  {
283  if (id != -1)
284  {
285  (*this->cellMap)[this->cellNumberOfIds] = id;
286  }
287  // increment fake number of ids
288  this->cellNumberOfIds++;
289  return this->cellNumberOfIds - 1;
290  break;
291  }
292  default:
293  {
294  this->cellVector->push_back(id);
295  return static_cast<int>(this->cellVector->size() - 1);
296  break;
297  }
298  }
299  return static_cast<int>(this->cellVector->size() - 1);
300  }
301 
303  {
304  switch (this->mode)
305  {
306  case SINGLE_PROCESS_MODE:
307  {
308  // Single Process compatibility
309  return this->cellNumberOfIds;
310  break;
311  }
313  {
314  return this->cellNumberOfIds;
315  }
316  case SPARSE_MODE:
317  {
318  return this->cellNumberOfIds;
319  break;
320  }
321  default:
322  {
323  break;
324  }
325  }
326 
327  // Point Ids are directly injected in the vector,
328  // contrary to cell Ids which are "stacked" with
329  // InsertNextId. So the real total number of Ids
330  // for Points cannot be the size of the vector.
331  // So we must inject it manually
332  if (this->cellNumberOfIds >= 0)
333  {
334  return this->cellNumberOfIds;
335  }
336 
337  return static_cast<int>(this->cellVector->size());
338  }
339 
340  // Just inject the real total number of Ids
341  void SetNumberOfIds(int n)
342  {
343  if (this->mode == SPARSE_MODE)
344  {
345  // do nothing
346  }
347  else
348  {
349  // Non sparse Or Single Process
350  this->cellNumberOfIds = n;
351  }
352  }
353 
355  {
356  if (this->mode == SPARSE_MODE)
357  {
358  // do nothing
359  }
360  else
361  {
362  // Non sparse Or Single Process
363  // Used for Structured compatibility
364  this->cellLocalNumberOfIds = n;
365  }
366  }
367 
368  void Reset()
369  {
370  if (this->mode == SPARSE_MODE)
371  {
372  this->cellMap->clear();
373  this->cellNumberOfIds = 0;
374  }
375  else
376  {
377  if (this->mode == NON_SPARSE_MODE)
378  this->cellVector->clear();
379  if (this->cellNumberOfIds >= 0)
380  this->cellNumberOfIds = -1;
381  if (this->cellLocalNumberOfIds >= 0)
382  this->cellLocalNumberOfIds = -1;
383  }
384  }
385 
387  {
388  switch (this->mode)
389  {
390  case SINGLE_PROCESS_MODE:
391  {
392  // Single Process compatibility
393  return this->cellNumberOfIds;
394  break;
395  }
397  {
398  return this->cellLocalNumberOfIds;
399  }
400  case SPARSE_MODE:
401  {
402  return static_cast<int>(this->cellMap->size());
403  break;
404  }
405  default:
406  {
407  break;
408  }
409  }
410 
411  // Return cellLocalNumberOfIds if valid
412  if (this->cellLocalNumberOfIds >= 0)
413  {
414  return this->cellLocalNumberOfIds;
415  }
416 
417  // Else compute the real size
418  int result = 0;
419  for (unsigned int i = 0; i < this->cellVector->size(); i++)
420  {
421  if ((*this->cellVector)[i] != -1)
422  result++;
423  }
424  return result;
425  }
426 
427  protected:
428  IntIntMap* cellMap;
431  IntVector* cellVector;
432  // Implicit Structured Real (global) dimensions
434  // Implicit Structured local dimensions
436  // Implicit Structured Split Dimension
438  // Implicit Structured Split Dimension Begin Index. Inclusive
440  // Implicit StructuredSplit Dimension End Index. Exclusive
442 
444  };
445 
447  {
448  POINT = 0,
449  BAR2 = 1,
450  BAR3 = 2,
451  NSIDED = 3,
452  TRIA3 = 4,
453  TRIA6 = 5,
454  QUAD4 = 6,
455  QUAD8 = 7,
456  NFACED = 8,
457  TETRA4 = 9,
458  TETRA10 = 10,
459  PYRAMID5 = 11,
460  PYRAMID13 = 12,
461  HEXA8 = 13,
462  HEXA20 = 14,
463  PENTA6 = 15,
464  PENTA15 = 16,
465  NUMBER_OF_ELEMENT_TYPES = 17
466  };
467 
469  {
470  SCALAR_PER_NODE = 0,
471  VECTOR_PER_NODE = 1,
472  TENSOR_SYMM_PER_NODE = 2,
473  SCALAR_PER_ELEMENT = 3,
474  VECTOR_PER_ELEMENT = 4,
475  TENSOR_SYMM_PER_ELEMENT = 5,
476  SCALAR_PER_MEASURED_NODE = 6,
477  VECTOR_PER_MEASURED_NODE = 7,
478  COMPLEX_SCALAR_PER_NODE = 8,
479  COMPLEX_VECTOR_PER_NODE = 9,
480  COMPLEX_SCALAR_PER_ELEMENT = 10,
481  COMPLEX_VECTOR_PER_ELEMENT = 11
482  };
483 
485  {
486  COORDINATES = 0,
487  BLOCK = 1,
488  ELEMENT = 2
489  };
490 
492 
496  vtkGetStringMacro(MeasuredFileName);
498 
500 
504  vtkGetStringMacro(MatchFileName);
506 
507 protected:
509  ~vtkPEnSightReader() override;
510 
511  int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
512  int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
513 
514  /*int RequestUpdateExtent(
515  vtkInformation *vtkNotUsed(request),
516  vtkInformationVector **inputVector,
517  vtkInformationVector *outputVector);
518  */
519 
521 
524  vtkSetStringMacro(MeasuredFileName);
526 
528 
531  vtkSetStringMacro(MatchFileName);
533 
535 
538  int ReadCaseFile();
539  int ReadCaseFileGeometry(char* line);
540  int ReadCaseFileVariable(char* line);
541  int ReadCaseFileTime(char* line);
542  int ReadCaseFileFile(char* line);
544 
545  // set in UpdateInformation to value returned from ReadCaseFile
547 
551  virtual int ReadGeometryFile(
552  const char* fileName, int timeStep, vtkMultiBlockDataSet* output) = 0;
553 
558  virtual int ReadMeasuredGeometryFile(
559  const char* fileName, int timeStep, vtkMultiBlockDataSet* output) = 0;
560 
564  int ReadVariableFiles(vtkMultiBlockDataSet* output);
565 
570  virtual int ReadScalarsPerNode(const char* fileName, const char* description, int timeStep,
571  vtkMultiBlockDataSet* output, int measured = 0, int numberOfComponents = 1,
572  int component = 0) = 0;
573 
578  virtual int ReadVectorsPerNode(const char* fileName, const char* description, int timeStep,
579  vtkMultiBlockDataSet* output, int measured = 0) = 0;
580 
585  virtual int ReadTensorsPerNode(
586  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
587 
592  virtual int ReadScalarsPerElement(const char* fileName, const char* description, int timeStep,
593  vtkMultiBlockDataSet* output, int numberOfComponents = 1, int component = 0) = 0;
594 
599  virtual int ReadVectorsPerElement(
600  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
601 
606  virtual int ReadTensorsPerElement(
607  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
608 
613  virtual int CreateUnstructuredGridOutput(
614  int partId, char line[80], const char* name, vtkMultiBlockDataSet* output) = 0;
615 
620  virtual int CreateStructuredGridOutput(
621  int partId, char line[80], const char* name, vtkMultiBlockDataSet* output) = 0;
622 
626  void AddVariableFileName(const char* fileName1, const char* fileName2 = nullptr);
627 
631  void AddVariableDescription(const char* description);
632 
636  void AddVariableType();
637 
642  int GetElementType(const char* line);
643 
648  int GetSectionType(const char* line);
649 
653  void ReplaceWildcards(char* filename, int num);
654 
658  void RemoveLeadingBlanks(char* line);
659 
663  vtkPEnSightReaderCellIds* GetCellIds(int index, int cellType);
664 
666 
670  vtkIdType GetTotalNumberOfCellIds(int index);
671  vtkIdType GetLocalTotalNumberOfCellIds(int index);
673 
678  vtkPEnSightReaderCellIds* GetPointIds(int index);
679 
684  void AddToBlock(vtkMultiBlockDataSet* output, unsigned int blockNo, vtkDataSet* dataset);
685 
690  vtkDataSet* GetDataSetFromBlock(vtkMultiBlockDataSet* output, unsigned int blockNo);
691 
695  void SetBlockName(vtkMultiBlockDataSet* output, unsigned int blockNo, const char* name);
696 
698 
703  void InsertNextCellAndId(vtkUnstructuredGrid*, int vtkCellType, vtkIdType numPoints,
704  vtkIdType* points, int partId, int ensightCellType, vtkIdType globalId, vtkIdType numElements,
705  const std::vector<vtkIdType>& faces = {});
706  void InsertVariableComponent(vtkFloatArray* array, int i, int component, float* content,
707  int partId, int ensightCellType, int insertionType);
709 
713  void MapToGlobalIds(
714  const vtkIdType* inputIds, vtkIdType numPoints, int partId, vtkIdType* globalIds);
715 
722  void PrepareStructuredDimensionsForDistribution(int partId, int* oldDimensions,
723  int* newDimensions, int* splitDimension, int* splitDimensionBeginIndex, int ghostLevel,
724  vtkUnsignedCharArray* pointGhostArray, vtkUnsignedCharArray* cellGhostArray);
725 
727  char* MatchFileName; // may not actually be necessary to read this file
728 
729  // pointer to lists of list (cell ids per element type per part)
730  vtkPEnSightReaderCellIdsType* CellIds;
731 
732  // pointer to lists of list (point ids per element type per part)
733  vtkPEnSightReaderCellIdsType* PointIds;
734 
735  // part ids of unstructured outputs
737  // part ids of structured outputs
739 
744 
746 
747  // pointers to lists of filenames
748  char** VariableFileNames; // non-complex
750 
751  // array of time sets
754 
755  // array of file sets
758 
759  // collection of filename numbers per time set
762 
763  // collection of filename numbers per file set
766 
767  // collection of number of steps per file per file set
769 
770  // ids of the time and file sets
773 
778 
781 
783  vtkSetMacro(UseTimeSets, int);
784  vtkGetMacro(UseTimeSets, int);
785  vtkBooleanMacro(UseTimeSets, int);
786 
787  int UseFileSets;
788  vtkSetMacro(UseFileSets, int);
789  vtkGetMacro(UseFileSets, int);
790  vtkBooleanMacro(UseFileSets, int);
791 
793 
794  // global list of points for measured geometry
796 
799 
800  int CheckOutputConsistency();
801 
803 
805 
806  std::map<std::string, std::map<int, long>> FileOffsets;
807 
808 private:
809  vtkPEnSightReader(const vtkPEnSightReader&) = delete;
810  void operator=(const vtkPEnSightReader&) = delete;
811 };
812 
813 #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