VTK
dox/IO/AMR/vtkAMRFlashReaderInternal.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkAMRFlashReaderInternal.hpp
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00024 #ifndef VTKAMRFLASHREADERINTERNAL_HPP_
00025 #define VTKAMRFLASHREADERINTERNAL_HPP_
00026 
00027 #include <cassert>
00028 #include <vector>
00029 #include <map>
00030 #include <cstring>
00031 #include <string>
00032 
00033 #include "vtkSetGet.h"
00034 #include "vtkDataSet.h"
00035 #include "vtkObject.h"
00036 #include "vtkDataArray.h"
00037 #include "vtkDoubleArray.h"
00038 #include "vtkIntArray.h"
00039 #include "vtkCellData.h"
00040 #include "vtkByteSwap.h"
00041 
00042 #define H5_USE_16_API
00043 #include "vtk_hdf5.h"
00044 
00045 //==============================================================================
00046 //            I N T E R N A L   F L A S H     R E A D E R
00047 //==============================================================================
00048 
00049 #define  FLASH_READER_MAX_DIMS     3
00050 #define  FLASH_READER_LEAF_BLOCK   1
00051 #define  FLASH_READER_FLASH3_FFV8  8
00052 #define  FLASH_READER_FLASH3_FFV9  9
00053 
00054 typedef  struct tagFlashReaderIntegerScalar
00055 {
00056   char   Name[20];                // name  of the integer scalar
00057   int    Value;                   // value of the integer scalar
00058 } FlashReaderIntegerScalar;
00059 
00060 typedef  struct tagFlashReaderDoubleScalar
00061 {
00062   char   Name[20];                // name  of the real scalar
00063   double Value;                   // value of the real scalar
00064 } FlashReaderDoubleScalar;
00065 
00066 typedef  struct tagFlashReaderSimulationParameters
00067 {
00068   int    NumberOfBlocks;          // number of all blocks
00069   int    NumberOfTimeSteps;       // number of time steps
00070   int    NumberOfXDivisions;      // number of divisions per block along x axis
00071   int    NumberOfYDivisions;      // number of divisions per block along y axis
00072   int    NumberOfZDivisions;      // number of divisions per block along z axis
00073   double Time;                    // the time of this step
00074   double TimeStep;                // time interval
00075   double RedShift;
00076 } FlashReaderSimulationParameters;
00077 
00078 typedef  struct tagBlock
00079 {
00080   int    Index;                   // Id of the block
00081   int    Level;                   // LOD level
00082   int    Type;                    // a leaf block?
00083   int    ParentId;                // Id  of the parent block
00084   int    ChildrenIds[8];          // Ids of the children    blocks
00085   int    NeighborIds[6];          // Ids of the neighboring blocks
00086   int    ProcessorId;             // Id  of the processor
00087   int    MinGlobalDivisionIds[3]; // first (global) division index
00088   int    MaxGlobalDivisionIds[3]; // last  (global) division index
00089   double Center[3];               // center of the block
00090   double MinBounds[3];            // lower left  of the bounding box
00091   double MaxBounds[3];            // upper right of the bounding box
00092 } Block;
00093 
00094 typedef  struct tagFlashReaderSimulationInformation
00095 {
00096   int    FileFormatVersion;
00097   char   SetupCall[400];
00098   char   FileCreationTime[80];
00099   char   FlashVersion[80];
00100   char   BuildData[80];
00101   char   BuildDirectory[80];
00102   char   build_machine[80];
00103   char   CFlags[400];
00104   char   FFlags[400];
00105   char   SetupTimeStamp[80];
00106   char   BuildTimeStamp[80];
00107 } FlashReaderSimulationInformation;
00108 
00109 static std::string GetSeparatedParticleName( const std::string & variable )
00110 {
00111   std::string sepaName = variable;
00112 
00113   if ( sepaName.length() > 9 && sepaName.substr(0,9) == "particle_" )
00114     {
00115     sepaName = std::string( "Particles/" ) + sepaName.substr( 9 );
00116     }
00117   else
00118     {
00119     sepaName = std::string( "Particles/" ) + sepaName;
00120     }
00121 
00122   return sepaName;
00123 }
00124 
00125 
00126 // ----------------------------------------------------------------------------
00127 //                     Class  vtkFlashReaderInternal (begin)
00128 // ----------------------------------------------------------------------------
00129 
00130 
00131 class vtkFlashReaderInternal
00132 {
00133 public:
00134   vtkFlashReaderInternal()  { this->Init(); }
00135   ~vtkFlashReaderInternal() { this->Init(); }
00136 
00137   int      NumberOfBlocks;            // number of ALL blocks
00138   int      NumberOfLevels;            // number of levels
00139   int      FileFormatVersion;         // version of file format
00140   int      NumberOfParticles;         // number of particles
00141   int      NumberOfLeafBlocks;        // number of leaf blocks
00142   int      NumberOfDimensions;        // number of dimensions
00143   int      NumberOfProcessors;        // number of processors
00144   int      HaveProcessorsInfo;        // processor Ids available?
00145   int      BlockGridDimensions[3];    // number of grid points
00146   int      BlockCellDimensions[3];    // number of divisions
00147   int      NumberOfChildrenPerBlock;  // number of children  per block
00148   int      NumberOfNeighborsPerBlock; // number of neighbors per block
00149 
00150   char *   FileName;                  // Flash data file name
00151   hid_t    FileIndex;                 // file handle
00152   double   MinBounds[3];              // lower left  of the bounding-box
00153   double   MaxBounds[3];              // upper right of the bounding box
00154   FlashReaderSimulationParameters     SimulationParameters;   // CFD simulation
00155   FlashReaderSimulationInformation    SimulationInformation;  // CFD simulation
00156 
00157   // blocks
00158   std::vector< Block >             Blocks;
00159   std::vector<  int  >             LeafBlocks;
00160   std::vector< std::string >    AttributeNames;
00161 
00162   // particles
00163   std::string                      ParticleName;
00164   std::vector< hid_t >             ParticleAttributeTypes;
00165   std::vector< std::string >    ParticleAttributeNames;
00166   std::map< std::string, int >  ParticleAttributeNamesToIds;
00167 
00168 
00169   int      GetCycle();
00170   double   GetTime();
00171 
00172   void     Init();
00173   void     SetFileName( char * fileName ) { this->FileName = fileName; }
00174   const char* GetParticleName(char* variableName)
00175    {
00176    return( GetSeparatedParticleName(std::string(variableName)).c_str() );
00177    }
00178 
00179   void     ReadMetaData();
00180   void     ReadProcessorIds();
00181   void     ReadDoubleScalars( hid_t fileIndx );
00182   void     ReadIntegerScalars( hid_t fileIndx );
00183   void     ReadVersionInformation( hid_t fileIndx );
00184   void     ReadSimulationParameters
00185            ( hid_t fileIndx, bool bTmCycle = false ); // time and cycle only
00186   void     GetBlockMinMaxGlobalDivisionIds();
00187 
00188   void     ReadBlockTypes();
00189   void     ReadBlockBounds();
00190   void     ReadBlockCenters();
00191   void     ReadBlockStructures();
00192   void     ReadRefinementLevels();
00193   void     ReadDataAttributeNames();
00194 
00195   void     ReadParticlesComponent
00196            ( hid_t dataIndx, const char * compName, double * dataBuff );
00197   void     ReadParticleAttributes();
00198   void     ReadParticleAttributesFLASH3();
00199   void     GetBlockAttribute( const char *atribute, int blockIdx,
00200                               vtkDataSet *pDataSet );
00201 };
00202 
00203 
00204 
00205 
00206 // ----------------------------------------------------------------------------
00207 //                     Class  vtkFlashReaderInternal ( end )
00208 // ----------------------------------------------------------------------------
00209 #endif /* VTKAMRFLASHREADERINTERNAL_HPP_ */
00210 // VTK-HeaderTest-Exclude: vtkAMRFlashReaderInternal.h