ParaView
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  =========================================================================*/
37 #ifndef vtkPEnSightReader_h
38 #define vtkPEnSightReader_h
39 
41 #include "vtkPVVTKExtensionsDefaultModule.h" //needed for exports
42 
43 #include "vtkIdTypeArray.h" // For ivars
44 #include <algorithm> // For ivars
45 #include <map> // For ivars
46 #include <map> // For ivars
47 #include <string> // For ivars
48 #include <string> // For ivars
49 #include <vector> // For ivars
50 
51 class vtkDataSet;
52 class vtkIdList;
53 class vtkMultiBlockDataSet;
54 class vtkInformation;
55 class vtkInformationVector;
56 class vtkUnsignedCharArray;
57 class vtkUnstructuredGrid;
58 class vtkFloatArray;
59 class vtkPEnSightReaderCellIdsType;
60 
61 #define NEXTMODULO3(x) (x == 0) ? 1 : ((x == 1) ? 2 : 0)
62 
63 class VTKPVVTKEXTENSIONSDEFAULT_EXPORT vtkPEnSightReader : public vtkPGenericEnSightReader
64 {
65 public:
67  void PrintSelf(ostream& os, vtkIndent indent);
68 
69  //----------------------------------------------------------------------------
70  // PointIds and CellIds must be stored in a different way:
71  // std::vector in non distributed mode
72  // std::map in distributed mode
73  // note: Ensight Ids are INTEGERS, not longs
75  {
76 
77  public:
78  typedef std::map<int, int> IntIntMap;
79  typedef std::vector<int> IntVector;
80 
82  : cellMap(NULL)
83  , cellNumberOfIds(-1)
84  , cellLocalNumberOfIds(-1)
85  , cellVector(NULL)
86  , ImplicitDimensions(NULL)
87  , ImplicitLocalDimensions(NULL)
88  , ImplicitSplitDimension(-1)
89  , ImplicitSplitDimensionBeginIndex(-1)
90  , ImplicitSplitDimensionEndIndex(-1)
91  , mode(NON_SPARSE_MODE)
92  {
93  }
94 
95  vtkPEnSightReaderCellIds(EnsightReaderCellIdMode amode)
96  : cellMap(NULL)
97  , cellNumberOfIds(-1)
98  , cellLocalNumberOfIds(-1)
99  , cellVector(NULL)
100  , ImplicitDimensions(NULL)
101  , ImplicitLocalDimensions(NULL)
102  , ImplicitSplitDimension(-1)
103  , ImplicitSplitDimensionBeginIndex(-1)
104  , ImplicitSplitDimensionEndIndex(-1)
105  , mode(amode)
106  {
107  if (this->mode == SPARSE_MODE)
108  {
109  this->cellMap = new IntIntMap;
110  this->cellNumberOfIds = 0;
111  this->cellVector = NULL;
112  }
113  else if (this->mode == IMPLICIT_STRUCTURED_MODE)
114  {
115  this->ImplicitDimensions = new int[3];
116  this->ImplicitSplitDimension = -1;
117  this->ImplicitSplitDimensionBeginIndex = -1;
118  this->ImplicitSplitDimensionEndIndex = -1;
119  }
120  else
121  {
122  this->cellMap = NULL;
123  this->cellVector = new IntVector;
124  this->cellNumberOfIds = -1;
125  this->cellLocalNumberOfIds = -1;
126  }
127  }
128 
130  {
131  delete this->cellMap;
132  delete this->cellVector;
133  delete[] this->ImplicitDimensions;
134  }
135 
136  void SetMode(EnsightReaderCellIdMode amode)
137  {
138  this->mode = amode;
139  if (this->mode == SPARSE_MODE)
140  {
141  this->cellMap = new IntIntMap;
142  this->cellNumberOfIds = 0;
143  this->cellVector = NULL;
144  }
145  else if (this->mode == IMPLICIT_STRUCTURED_MODE)
146  {
147  this->ImplicitDimensions = new int[3];
148  this->ImplicitSplitDimension = -1;
149  this->ImplicitSplitDimensionBeginIndex = -1;
150  this->ImplicitSplitDimensionEndIndex = -1;
151  }
152  else
153  {
154  this->cellMap = NULL;
155  this->cellVector = new IntVector;
156  this->cellNumberOfIds = -1;
157  this->cellLocalNumberOfIds = -1;
158  }
159  }
160 
161  void SetImplicitDimensions(int dim1, int dim2, int dim3)
162  {
163  this->ImplicitDimensions[0] = dim1;
164  this->ImplicitDimensions[1] = dim2;
165  this->ImplicitDimensions[2] = dim3;
166  }
167 
168  void SetImplicitSplitDimension(int dim) { this->ImplicitSplitDimension = dim; }
169 
171  {
172  this->ImplicitSplitDimensionBeginIndex = begin;
173  }
174 
175  void SetImplicitSplitDimensionEndIndex(int end) { this->ImplicitSplitDimensionEndIndex = end; }
176 
177  // return -1 if not found
178  int GetId(int id)
179  {
180  switch (this->mode)
181  {
182  case SINGLE_PROCESS_MODE:
183  {
184  // Single Process compatibility
185  return id;
186  break;
187  }
188  case IMPLICIT_STRUCTURED_MODE:
189  {
190  if (this->ImplicitSplitDimension == -1)
191  return -1; // not initialized
192 
193  // Compute the global i j k index
194  // id = i + j * dim[0] + k * dim[1] * dim[0]
195  int index[3];
196  index[2] = id / (this->ImplicitDimensions[0] * this->ImplicitDimensions[1]); // k
197  index[1] = (id - (index[2] * this->ImplicitDimensions[0] * this->ImplicitDimensions[1])) /
198  this->ImplicitDimensions[0]; // j
199  index[0] = id - index[1] * this->ImplicitDimensions[0] -
200  index[2] * this->ImplicitDimensions[1] * this->ImplicitDimensions[0]; // i
201  if ((index[this->ImplicitSplitDimension] < this->ImplicitSplitDimensionBeginIndex) ||
202  (index[this->ImplicitSplitDimension] >= this->ImplicitSplitDimensionEndIndex))
203  {
204  // not for me
205  return -1;
206  }
207  else
208  {
209  // Compute the local id
210  int localIndex[3];
211  int localDim[3];
212  int dim = this->ImplicitSplitDimension;
213  localIndex[dim] = index[dim] - this->ImplicitSplitDimensionBeginIndex;
214  localDim[dim] =
215  this->ImplicitSplitDimensionEndIndex - this->ImplicitSplitDimensionBeginIndex;
216  dim = NEXTMODULO3(dim);
217  localIndex[dim] = index[dim];
218  localDim[dim] = this->ImplicitDimensions[dim];
219  dim = NEXTMODULO3(dim);
220  localDim[dim] = this->ImplicitDimensions[dim];
221  localIndex[dim] = index[dim];
222  return localIndex[0] + localDim[0] * localIndex[1] +
223  localDim[0] * localDim[1] * localIndex[2];
224  }
225  }
226  case SPARSE_MODE:
227  {
228  std::map<int, int>::iterator it = this->cellMap->find(id);
229  if (it == this->cellMap->end())
230  return -1;
231  else
232  return (*this->cellMap)[id];
233  break;
234  }
235  default:
236  {
237  if (this->cellVector->size() > (unsigned int)(id))
238  return (*this->cellVector)[id];
239  break;
240  }
241  }
242  return -1;
243  }
244 
245  void SetId(int id, int value)
246  {
247  switch (this->mode)
248  {
249  case SINGLE_PROCESS_MODE:
250  case IMPLICIT_STRUCTURED_MODE:
251  {
252  // Compatibility Only
253  // do noting
254  break;
255  }
256  case SPARSE_MODE:
257  {
258  std::map<int, int>::iterator it = this->cellMap->find(id);
259  if (it == this->cellMap->end())
260  this->cellNumberOfIds++;
261 
262  (*this->cellMap)[id] = value;
263  break;
264  }
265  default:
266  {
267  if (this->cellVector->size() < (unsigned int)(id + 1))
268  {
269  int k;
270  int currentSize = static_cast<int>(this->cellVector->size());
271  this->cellVector->resize(id + 1);
272  for (k = currentSize; k < id; k++)
273  {
274  (*this->cellVector)[k] = -1;
275  }
276  (*this->cellVector)[id] = value;
277  }
278  else
279  {
280  (*this->cellVector)[id] = value;
281  }
282  break;
283  }
284  }
285  }
286 
287  // In distributed mode, if id == -1, do not insert it in map
288  int InsertNextId(int id)
289  {
290  switch (this->mode)
291  {
292  case SINGLE_PROCESS_MODE:
293  case IMPLICIT_STRUCTURED_MODE:
294  {
295  // Single Process compatibility
296  // do noting
297  break;
298  }
299  case SPARSE_MODE:
300  {
301  if (id != -1)
302  {
303  (*this->cellMap)[this->cellNumberOfIds] = id;
304  }
305  // increment fake number of ids
306  this->cellNumberOfIds++;
307  return this->cellNumberOfIds - 1;
308  break;
309  }
310  default:
311  {
312  this->cellVector->push_back(id);
313  return static_cast<int>(this->cellVector->size() - 1);
314  break;
315  }
316  }
317  return static_cast<int>(this->cellVector->size() - 1);
318  }
319 
321  {
322  switch (this->mode)
323  {
324  case SINGLE_PROCESS_MODE:
325  {
326  // Single Process compatibility
327  return this->cellNumberOfIds;
328  break;
329  }
330  case IMPLICIT_STRUCTURED_MODE:
331  {
332  return this->cellNumberOfIds;
333  }
334  case SPARSE_MODE:
335  {
336  return this->cellNumberOfIds;
337  break;
338  }
339  default:
340  {
341  break;
342  }
343  }
344 
345  // Point Ids are directly injected in the vector,
346  // contrary to cell Ids which are "stacked" with
347  // InsertNextId. So the real total number of Ids
348  // for Points cannot be the size of the vector.
349  // So we must inject it manually
350  if (this->cellNumberOfIds >= 0)
351  {
352  return this->cellNumberOfIds;
353  }
354 
355  return static_cast<int>(this->cellVector->size());
356  }
357 
358  // Just inject the real total number of Ids
359  void SetNumberOfIds(int n)
360  {
361  if (this->mode == SPARSE_MODE)
362  {
363  // do nothing
364  }
365  else
366  {
367  // Non sparse Or Single Process
368  this->cellNumberOfIds = n;
369  }
370  }
371 
373  {
374  if (this->mode == SPARSE_MODE)
375  {
376  // do nothing
377  }
378  else
379  {
380  // Non sparse Or Single Process
381  // Used for Structured compatibility
382  this->cellLocalNumberOfIds = n;
383  }
384  }
385 
386  void Reset()
387  {
388  if (this->mode == SPARSE_MODE)
389  {
390  this->cellMap->clear();
391  this->cellNumberOfIds = 0;
392  }
393  else
394  {
395  if (this->mode == NON_SPARSE_MODE)
396  this->cellVector->clear();
397  if (this->cellNumberOfIds >= 0)
398  this->cellNumberOfIds = -1;
399  if (this->cellLocalNumberOfIds >= 0)
400  this->cellLocalNumberOfIds = -1;
401  }
402  }
403 
405  {
406  switch (this->mode)
407  {
408  case SINGLE_PROCESS_MODE:
409  {
410  // Single Process compatibility
411  return this->cellNumberOfIds;
412  break;
413  }
414  case IMPLICIT_STRUCTURED_MODE:
415  {
416  return this->cellLocalNumberOfIds;
417  }
418  case SPARSE_MODE:
419  {
420  return static_cast<int>(this->cellMap->size());
421  break;
422  }
423  default:
424  {
425  break;
426  }
427  }
428 
429  // Return cellLocalNumberOfIds if valid
430  if (this->cellLocalNumberOfIds >= 0)
431  {
432  return this->cellLocalNumberOfIds;
433  }
434 
435  // Else compute the real size
436  int result = 0;
437  for (unsigned int i = 0; i < this->cellVector->size(); i++)
438  {
439  if ((*this->cellVector)[i] != -1)
440  result++;
441  }
442  return result;
443  }
444 
445  vtkIdTypeArray* GenerateGlobalIdsArray(const char* name)
446  {
447  // Generate a sorted Array For Global Ids
448  // Your local Ids must be consistent !
449  if (this->mode == IMPLICIT_STRUCTURED_MODE)
450  {
451  vtkIdTypeArray* array = vtkIdTypeArray::New();
452  array->SetNumberOfComponents(1);
453  array->SetName(name);
454  int localDim[3];
455 
456  int dim = this->ImplicitSplitDimension;
457  localDim[dim] =
458  this->ImplicitSplitDimensionEndIndex - this->ImplicitSplitDimensionBeginIndex;
459  dim = NEXTMODULO3(dim);
460  localDim[dim] = this->ImplicitDimensions[dim];
461  dim = NEXTMODULO3(dim);
462  localDim[dim] = this->ImplicitDimensions[dim];
463  array->SetNumberOfTuples(localDim[0] * localDim[1] * localDim[2]);
464 
465  int index = 0;
466  for (int k = 0; k < this->ImplicitDimensions[2]; k++)
467  {
468  for (int j = 0; j < this->ImplicitDimensions[1]; j++)
469  {
470  for (int i = 0; i < this->ImplicitDimensions[0]; i++)
471  {
472  int n = (this->ImplicitSplitDimension == 0)
473  ? i
474  : ((this->ImplicitSplitDimension == 1) ? j : k);
475  if ((n >= this->ImplicitSplitDimensionBeginIndex) &&
476  (n < this->ImplicitSplitDimensionEndIndex))
477  {
478  vtkIdType nn = n;
479  array->SetTypedTuple(index, &nn);
480  index++;
481  }
482  }
483  }
484  }
485  return array;
486  }
487  else
488  {
489  int i;
490  vtkIdTypeArray* array = vtkIdTypeArray::New();
491  array->SetNumberOfComponents(1);
492  array->SetName(name);
493  array->SetNumberOfTuples(this->GetLocalNumberOfIds());
494  int min = 1000000000;
495  int max = -1;
496  for (i = 0; i < this->GetNumberOfIds(); i++)
497  {
498  int id = this->GetId(i);
499  if (id != -1)
500  {
501  vtkIdType ii = i;
502  if (ii < min)
503  min = ii;
504  if (ii > max)
505  max = ii;
506  array->SetTypedTuple(id, &ii);
507  }
508  }
509  return array;
510  }
511  }
512 
513  protected:
514  IntIntMap* cellMap;
517  IntVector* cellVector;
518  // Implicit Structured Real (global) dimensions
520  // Implicit Structured local dimensions
522  // Implicit Structured Split Dimension
524  // Implicit Structured Split Dimension Begin Index. Inclusive
526  // Implicit StructuredSplit Dimension End Index. Exclusive
528 
529  EnsightReaderCellIdMode mode;
530  };
531 
533  {
534  POINT = 0,
535  BAR2 = 1,
536  BAR3 = 2,
537  NSIDED = 3,
538  TRIA3 = 4,
539  TRIA6 = 5,
540  QUAD4 = 6,
541  QUAD8 = 7,
542  NFACED = 8,
543  TETRA4 = 9,
544  TETRA10 = 10,
545  PYRAMID5 = 11,
546  PYRAMID13 = 12,
547  HEXA8 = 13,
548  HEXA20 = 14,
549  PENTA6 = 15,
550  PENTA15 = 16,
551  NUMBER_OF_ELEMENT_TYPES = 17
552  };
553 
555  {
556  SCALAR_PER_NODE = 0,
557  VECTOR_PER_NODE = 1,
558  TENSOR_SYMM_PER_NODE = 2,
559  SCALAR_PER_ELEMENT = 3,
560  VECTOR_PER_ELEMENT = 4,
561  TENSOR_SYMM_PER_ELEMENT = 5,
562  SCALAR_PER_MEASURED_NODE = 6,
563  VECTOR_PER_MEASURED_NODE = 7,
564  COMPLEX_SCALAR_PER_NODE = 8,
565  COMPLEX_VECTOR_PER_NODE = 9,
566  COMPLEX_SCALAR_PER_ELEMENT = 10,
567  COMPLEX_VECTOR_PER_ELEMENT = 11
568  };
569 
571  {
572  COORDINATES = 0,
573  BLOCK = 1,
574  ELEMENT = 2
575  };
576 
578 
582  vtkGetStringMacro(MeasuredFileName);
584 
586 
590  vtkGetStringMacro(MatchFileName);
592 
594 
606  vtkSetMacro(ParticleCoordinatesByIndex, int);
607  vtkGetMacro(ParticleCoordinatesByIndex, int);
608  vtkBooleanMacro(ParticleCoordinatesByIndex, int);
610 
611 protected:
614 
615  virtual int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*);
616  virtual int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*);
617 
618  /*int RequestUpdateExtent(
619  vtkInformation *vtkNotUsed(request),
620  vtkInformationVector **inputVector,
621  vtkInformationVector *outputVector);
622  */
623 
625 
628  vtkSetStringMacro(MeasuredFileName);
630 
632 
635  vtkSetStringMacro(MatchFileName);
637 
639 
642  int ReadCaseFile();
643  int ReadCaseFileGeometry(char* line);
644  int ReadCaseFileVariable(char* line);
645  int ReadCaseFileTime(char* line);
646  int ReadCaseFileFile(char* line);
648 
649  // set in UpdateInformation to value returned from ReadCaseFile
651 
655  virtual int ReadGeometryFile(
656  const char* fileName, int timeStep, vtkMultiBlockDataSet* output) = 0;
657 
662  virtual int ReadMeasuredGeometryFile(
663  const char* fileName, int timeStep, vtkMultiBlockDataSet* output) = 0;
664 
668  int ReadVariableFiles(vtkMultiBlockDataSet* output);
669 
674  virtual int ReadScalarsPerNode(const char* fileName, const char* description, int timeStep,
675  vtkMultiBlockDataSet* output, int measured = 0, int numberOfComponents = 1,
676  int component = 0) = 0;
677 
682  virtual int ReadVectorsPerNode(const char* fileName, const char* description, int timeStep,
683  vtkMultiBlockDataSet* output, int measured = 0) = 0;
684 
689  virtual int ReadTensorsPerNode(
690  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
691 
696  virtual int ReadScalarsPerElement(const char* fileName, const char* description, int timeStep,
697  vtkMultiBlockDataSet* output, int numberOfComponents = 1, int component = 0) = 0;
698 
703  virtual int ReadVectorsPerElement(
704  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
705 
710  virtual int ReadTensorsPerElement(
711  const char* fileName, const char* description, int timeStep, vtkMultiBlockDataSet* output) = 0;
712 
717  virtual int CreateUnstructuredGridOutput(
718  int partId, char line[80], const char* name, vtkMultiBlockDataSet* output) = 0;
719 
724  virtual int CreateStructuredGridOutput(
725  int partId, char line[80], const char* name, vtkMultiBlockDataSet* output) = 0;
726 
730  void AddVariableFileName(const char* fileName1, const char* fileName2 = NULL);
731 
735  void AddVariableDescription(const char* description);
736 
740  void AddVariableType();
741 
746  int GetElementType(const char* line);
747 
752  int GetSectionType(const char* line);
753 
757  void ReplaceWildcards(char* filename, int num);
758 
762  void RemoveLeadingBlanks(char* line);
763 
767  vtkPEnSightReaderCellIds* GetCellIds(int index, int cellType);
768 
770 
774  vtkIdType GetTotalNumberOfCellIds(int index);
775  vtkIdType GetLocalTotalNumberOfCellIds(int index);
777 
782  vtkPEnSightReaderCellIds* GetPointIds(int index);
783 
788  void AddToBlock(vtkMultiBlockDataSet* output, unsigned int blockNo, vtkDataSet* dataset);
789 
794  vtkDataSet* GetDataSetFromBlock(vtkMultiBlockDataSet* output, unsigned int blockNo);
795 
799  void SetBlockName(vtkMultiBlockDataSet* output, unsigned int blockNo, const char* name);
800 
802 
806  void InsertNextCellAndId(vtkUnstructuredGrid*, int vtkCellType, vtkIdType numPoints,
807  vtkIdType* points, int partId, int ensightCellType, vtkIdType globalId, vtkIdType numElements);
808  void InsertVariableComponent(vtkFloatArray* array, int i, int component, float* content,
809  int partId, int ensightCellType, int insertionType);
811 
818  void PrepareStructuredDimensionsForDistribution(int partId, int* oldDimensions,
819  int* newDimensions, int* splitDimension, int* splitDimensionBeginIndex, int ghostLevel,
820  vtkUnsignedCharArray* pointGhostArray, vtkUnsignedCharArray* cellGhostArray);
821 
823  char* MatchFileName; // may not actually be necessary to read this file
824 
825  // pointer to lists of list (cell ids per element type per part)
826  vtkPEnSightReaderCellIdsType* CellIds;
827 
828  // pointer to lists of list (point ids per element type per part)
829  vtkPEnSightReaderCellIdsType* PointIds;
830 
831  // part ids of unstructured outputs
833  // part ids of structured outputs
834  vtkIdList* StructuredPartIds;
835 
840 
842 
843  // pointers to lists of filenames
844  char** VariableFileNames; // non-complex
846 
847  // array of time sets
848  vtkIdList* VariableTimeSetIds;
850 
851  // array of file sets
852  vtkIdList* VariableFileSetIds;
854 
855  // collection of filename numbers per time set
856  vtkIdListCollection* TimeSetFileNameNumbers;
858 
859  // collection of filename numbers per file set
860  vtkIdListCollection* FileSetFileNameNumbers;
862 
863  // collection of number of steps per file per file set
864  vtkIdListCollection* FileSetNumberOfSteps;
865 
866  // ids of the time and file sets
867  vtkIdList* TimeSetIds;
868  vtkIdList* FileSets;
869 
874 
877 
879  vtkSetMacro(UseTimeSets, int);
880  vtkGetMacro(UseTimeSets, int);
881  vtkBooleanMacro(UseTimeSets, int);
882 
883  int UseFileSets;
884  vtkSetMacro(UseFileSets, int);
885  vtkGetMacro(UseFileSets, int);
886  vtkBooleanMacro(UseFileSets, int);
887 
889 
890  // global list of points for measured geometry
892 
895 
896  int CheckOutputConsistency();
897 
899 
901 
903 
904  std::map<std::string, std::map<int, long> > FileOffsets;
905 
906 private:
907  vtkPEnSightReader(const vtkPEnSightReader&) VTK_DELETE_FUNCTION;
908  void operator=(const vtkPEnSightReader&) VTK_DELETE_FUNCTION;
909 };
910 
911 #endif
void SetMode(EnsightReaderCellIdMode amode)
vtkPEnSightReaderCellIds(EnsightReaderCellIdMode amode)
vtkIdList * VariableTimeSetIds
void PrintSelf(ostream &os, vtkIndent indent)
Superclass for EnSight file parallel readers.
vtkIdList * TimeSetsWithFilenameNumbers
vtkIdList * ComplexVariableFileSetIds
char ** ComplexVariableFileNames
vtkIdList * UnstructuredPartIds
class to read any type of EnSight files
vtkPEnSightReaderCellIdsType * CellIds
vtkIdTypeArray * GenerateGlobalIdsArray(const char *name)
vtkIdList * VariableFileSetIds
vtkIdListCollection * FileSetFileNameNumbers
void SetImplicitDimensions(int dim1, int dim2, int dim3)
#define NEXTMODULO3(x)
vtkIdListCollection * TimeSetFileNameNumbers
vtkIdList * ComplexVariableTimeSetIds
vtkIdListCollection * FileSetNumberOfSteps
vtkIdList * StructuredPartIds
std::map< std::string, std::map< int, long > > FileOffsets
vtkPEnSightReaderCellIdsType * PointIds
vtkIdList * FileSetsWithFilenameNumbers