VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/IO/Exodus/vtkExodusIIWriter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkExodusIIWriter.h
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 =========================================================================*/
00015 /*----------------------------------------------------------------------------
00016  Copyright (c) Sandia Corporation
00017  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
00018 ----------------------------------------------------------------------------*/
00019 
00070 #ifndef vtkExodusIIWriter_h
00071 #define vtkExodusIIWriter_h
00072 
00073 #include "vtkIOExodusModule.h" // For export macro
00074 #include "vtkWriter.h"
00075 #include "vtkSmartPointer.h" // For vtkSmartPointer
00076 
00077 #include <vector> // STL Header
00078 #include <map>    // STL Header
00079 #include <string> // STL Header
00080 
00081 class vtkModelMetadata;
00082 class vtkDoubleArray;
00083 class vtkIntArray;
00084 class vtkUnstructuredGrid;
00085 
00086 class VTKIOEXODUS_EXPORT vtkExodusIIWriter : public vtkWriter
00087 {
00088 public:
00089   static vtkExodusIIWriter *New ();
00090   vtkTypeMacro(vtkExodusIIWriter,vtkWriter);
00091   void PrintSelf (ostream& os, vtkIndent indent);
00092 
00101   void SetModelMetadata (vtkModelMetadata*);
00102   vtkGetObjectMacro(ModelMetadata, vtkModelMetadata);
00103 
00109   vtkSetStringMacro(FileName);
00110   vtkGetStringMacro(FileName);
00111 
00117   vtkSetMacro(StoreDoubles, int);
00118   vtkGetMacro(StoreDoubles, int);
00119 
00123   vtkSetMacro(GhostLevel, int);
00124   vtkGetMacro(GhostLevel, int);
00125 
00131   vtkSetMacro(WriteOutBlockIdArray, int);
00132   vtkGetMacro(WriteOutBlockIdArray, int);
00133   vtkBooleanMacro(WriteOutBlockIdArray, int);
00134 
00139   vtkSetMacro(WriteOutGlobalNodeIdArray, int);
00140   vtkGetMacro(WriteOutGlobalNodeIdArray, int);
00141   vtkBooleanMacro(WriteOutGlobalNodeIdArray, int);
00142 
00147   vtkSetMacro(WriteOutGlobalElementIdArray, int);
00148   vtkGetMacro(WriteOutGlobalElementIdArray, int);
00149   vtkBooleanMacro(WriteOutGlobalElementIdArray, int);
00150 
00154   vtkSetMacro(WriteAllTimeSteps, int);
00155   vtkGetMacro(WriteAllTimeSteps, int);
00156   vtkBooleanMacro(WriteAllTimeSteps, int);
00157 
00158   vtkSetStringMacro(BlockIdArrayName);
00159   vtkGetStringMacro(BlockIdArrayName);
00160 
00161 protected:
00162   vtkExodusIIWriter ();
00163   ~vtkExodusIIWriter ();
00164 
00165   vtkModelMetadata* ModelMetadata;
00166 
00167   char *BlockIdArrayName;
00168 
00169   char *FileName;
00170   int fid;
00171 
00172   int NumberOfProcesses;
00173   int MyRank;
00174 
00175   int PassDoubles;
00176 
00177   int StoreDoubles;
00178   int GhostLevel;
00179   int WriteOutBlockIdArray;
00180   int WriteOutGlobalNodeIdArray;
00181   int WriteOutGlobalElementIdArray;
00182   int WriteAllTimeSteps;
00183   int NumberOfTimeSteps;
00184 
00185   vtkDoubleArray* TimeValues;
00186   int CurrentTimeIndex;
00187   int FileTimeOffset;
00188   bool TopologyChanged;
00189 
00190 //BTX
00191   vtkDataObject *OriginalInput;
00192   std::vector< vtkSmartPointer<vtkUnstructuredGrid> > FlattenedInput;
00193   std::vector< vtkSmartPointer<vtkUnstructuredGrid> > NewFlattenedInput;
00194 
00195   std::vector< vtkIntArray* > BlockIdList;
00196 
00197   struct Block
00198   {
00199     Block ()
00200       {
00201       this->Type = 0;
00202       this->NumElements = 0;
00203       this->ElementStartIndex = -1;
00204       this->NodesPerElement = 0;
00205       this->EntityCounts = std::vector<int>();
00206       this->EntityNodeOffsets = std::vector<int>();
00207       this->GridIndex = 0;
00208       this->OutputIndex = -1;
00209       this->NumAttributes = 0;
00210       this->BlockAttributes = 0;
00211       };
00212     int Type;
00213     int NumElements;
00214     int ElementStartIndex;
00215     int NodesPerElement;
00216     std::vector<int> EntityCounts;
00217     std::vector<int> EntityNodeOffsets;
00218     size_t GridIndex;
00219     // std::vector<int> CellIndex;
00220     int OutputIndex;
00221     int NumAttributes;
00222     float *BlockAttributes; // Owned by metamodel or null.  Don't delete.
00223   };
00224   std::map<int, Block> BlockInfoMap;
00225   int NumCells, NumPoints, MaxId;
00226 
00227   std::vector<vtkIdType*> GlobalElementIdList;
00228   std::vector<vtkIdType*> GlobalNodeIdList;
00229 //ETX
00230   int AtLeastOneGlobalElementIdList;
00231   int AtLeastOneGlobalNodeIdList;
00232 
00233 //BTX
00234   struct VariableInfo
00235   {
00236     int NumComponents;
00237     int InIndex;
00238     int ScalarOutOffset;
00239     std::vector<std::string> OutNames;
00240   };
00241   std::map<std::string, VariableInfo> GlobalVariableMap;
00242   std::map<std::string, VariableInfo> BlockVariableMap;
00243   std::map<std::string, VariableInfo> NodeVariableMap;
00244   int NumberOfScalarGlobalArrays;
00245   int NumberOfScalarElementArrays;
00246   int NumberOfScalarNodeArrays;
00247 //ETX
00248 
00249 //BTX
00250   std::vector< std::vector<int> > CellToElementOffset;
00251 //ETX
00252   // By BlockId, and within block ID by element variable, with variables
00253   // appearing in the same order in which they appear in OutputElementArrayNames
00254 
00255   int *BlockElementVariableTruthTable;
00256   int AllVariablesDefinedInAllBlocks;
00257 
00258   int BlockVariableTruthValue(int blockIdx, int varIdx);
00259 
00260 //BTX
00261   char *StrDupWithNew (const char *s);
00262   void StringUppercase (std::string& str);
00263 //ETX
00264 
00265   int ProcessRequest (vtkInformation* request,
00266                       vtkInformationVector** inputVector,
00267                       vtkInformationVector* outputVector);
00268 
00269   int RequestInformation (vtkInformation* request,
00270                           vtkInformationVector** inputVector,
00271                           vtkInformationVector* outputVector);
00272 
00273   virtual int RequestUpdateExtent (vtkInformation* request,
00274                                    vtkInformationVector** inputVector,
00275                                    vtkInformationVector* outputVector);
00276 
00277   int FillInputPortInformation (int port, vtkInformation* info);
00278 
00279   int RequestData (vtkInformation* request,
00280                    vtkInformationVector** inputVector,
00281                    vtkInformationVector* outputVector);
00282 
00283   void WriteData ();
00284 
00285   int FlattenHierarchy (vtkDataObject* input, bool& changed);
00286 
00287   int CreateNewExodusFile ();
00288   void CloseExodusFile ();
00289 
00290   int IsDouble ();
00291   void RemoveGhostCells ();
00292   int CheckParametersInternal (int NumberOfProcesses, int MyRank);
00293   virtual int CheckParameters ();
00294   // If writing in parallel multiple time steps exchange after each time step
00295   // if we should continue the execution. Pass local continueExecution as a
00296   // parameter and return the global continueExecution.
00297   virtual int GlobalContinueExecuting(int localContinueExecution);
00298   int CheckInputArrays ();
00299   virtual void CheckBlockInfoMap();
00300   int ConstructBlockInfoMap ();
00301   int ConstructVariableInfoMaps ();
00302   int ParseMetadata ();
00303   int CreateDefaultMetadata ();
00304   char *GetCellTypeName (int t);
00305 
00306   int CreateBlockIdMetadata(vtkModelMetadata *em);
00307   int CreateBlockVariableMetadata (vtkModelMetadata* em);
00308 
00309 //BTX
00310   void ConvertVariableNames (std::map<std::string, VariableInfo>& variableMap);
00311   char **FlattenOutVariableNames (
00312             int nScalarArrays,
00313             const std::map<std::string, VariableInfo>& variableMap);
00314   std::string CreateNameForScalarArray (const char *root,
00315                                            int component,
00316                                            int numComponents);
00317 
00318   std::map<vtkIdType, vtkIdType> *LocalNodeIdMap;
00319   std::map<vtkIdType, vtkIdType> *LocalElementIdMap;
00320 //ETX
00321   vtkIdType GetNodeLocalId(vtkIdType id);
00322   vtkIdType GetElementLocalId(vtkIdType id);
00323 
00324   int WriteInitializationParameters ();
00325   int WriteInformationRecords ();
00326   int WritePoints ();
00327   int WriteCoordinateNames ();
00328   int WriteGlobalPointIds ();
00329   int WriteBlockInformation ();
00330   int WriteGlobalElementIds ();
00331   int WriteVariableArrayNames ();
00332   int WriteNodeSetInformation ();
00333   int WriteSideSetInformation ();
00334   int WriteProperties ();
00335   int WriteNextTimeStep ();
00336   vtkIntArray* GetBlockIdArray (
00337     const char* BlockIdArrayName, vtkUnstructuredGrid* input);
00338   static bool SameTypeOfCells (vtkIntArray* cellToBlockId,
00339                                vtkUnstructuredGrid* input);
00340 
00341 //BTX
00342   double ExtractGlobalData (const char *name, int comp, int ts);
00343   int WriteGlobalData (int timestep, vtkDataArray *buffer);
00344   void ExtractCellData (const char *name, int comp, vtkDataArray *buffer);
00345   int WriteCellData (int timestep, vtkDataArray *buffer);
00346   void ExtractPointData (const char *name, int comp, vtkDataArray *buffer);
00347   int WritePointData (int timestep, vtkDataArray *buffer);
00348 //ETX
00349 
00350 
00351 private:
00352   vtkExodusIIWriter (const vtkExodusIIWriter&); // Not Implemented
00353   void operator= (const vtkExodusIIWriter&); // Not Implemented
00354 };
00355 
00356 #endif