VTK
dox/Parallel/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 "vtkWriter.h"
00074 #include "vtkSmartPointer.h" // For vtkSmartPointer
00075 
00076 #include <vector> // STL Header
00077 #include <map>    // STL Header
00078 #include <string> // STL Header
00079 
00080 class vtkModelMetadata;
00081 class vtkDoubleArray;
00082 class vtkIntArray;
00083 class vtkUnstructuredGrid;
00084 
00085 class VTK_PARALLEL_EXPORT vtkExodusIIWriter : public vtkWriter
00086 {
00087 public:
00088   static vtkExodusIIWriter *New ();
00089   vtkTypeMacro(vtkExodusIIWriter,vtkWriter);
00090   void PrintSelf (ostream& os, vtkIndent indent);
00091 
00100   void SetModelMetadata (vtkModelMetadata*);
00101   vtkGetObjectMacro(ModelMetadata, vtkModelMetadata);
00102 
00108   vtkSetStringMacro(FileName);
00109   vtkGetStringMacro(FileName);
00110 
00116   vtkSetMacro(StoreDoubles, int);
00117   vtkGetMacro(StoreDoubles, int);
00118 
00122   vtkSetMacro(GhostLevel, int);
00123   vtkGetMacro(GhostLevel, int);
00124 
00130   vtkSetMacro(WriteOutBlockIdArray, int);
00131   vtkGetMacro(WriteOutBlockIdArray, int);
00132   vtkBooleanMacro(WriteOutBlockIdArray, int);
00133 
00138   vtkSetMacro(WriteOutGlobalNodeIdArray, int);
00139   vtkGetMacro(WriteOutGlobalNodeIdArray, int);
00140   vtkBooleanMacro(WriteOutGlobalNodeIdArray, int);
00141 
00146   vtkSetMacro(WriteOutGlobalElementIdArray, int);
00147   vtkGetMacro(WriteOutGlobalElementIdArray, int);
00148   vtkBooleanMacro(WriteOutGlobalElementIdArray, int);
00149 
00153   vtkSetMacro(WriteAllTimeSteps, int);
00154   vtkGetMacro(WriteAllTimeSteps, int);
00155   vtkBooleanMacro(WriteAllTimeSteps, int);
00156 
00157   vtkSetStringMacro(BlockIdArrayName);
00158   vtkGetStringMacro(BlockIdArrayName);
00159 
00160 protected:
00161   vtkExodusIIWriter ();
00162   ~vtkExodusIIWriter ();
00163 
00164   vtkModelMetadata* ModelMetadata;
00165 
00166   char *BlockIdArrayName;
00167 
00168   char *FileName;
00169   int fid;
00170 
00171   int NumberOfProcesses;
00172   int MyRank;
00173 
00174   int PassDoubles;
00175 
00176   int StoreDoubles;
00177   int GhostLevel;
00178   int WriteOutBlockIdArray;
00179   int WriteOutGlobalNodeIdArray;
00180   int WriteOutGlobalElementIdArray;
00181   int WriteAllTimeSteps;
00182   int NumberOfTimeSteps;
00183 
00184   vtkDoubleArray* TimeValues;
00185   int CurrentTimeIndex;
00186   int FileTimeOffset;
00187 
00188 //BTX 
00189   vtkDataObject *OriginalInput;
00190   std::vector< vtkSmartPointer<vtkUnstructuredGrid> > FlattenedInput;
00191   std::vector< vtkSmartPointer<vtkUnstructuredGrid> > NewFlattenedInput;
00192 
00193   std::vector< vtkIntArray* > BlockIdList;
00194 
00195   struct Block
00196   {
00197     Block () 
00198       {
00199       this->Type = 0;
00200       this->NumElements = 0;
00201       this->ElementStartIndex = -1;
00202       this->NodesPerElement = 0;
00203       this->EntityCounts = std::vector<int>();
00204       this->EntityNodeOffsets = std::vector<int>();
00205       this->GridIndex = 0;
00206       this->OutputIndex = -1;
00207       this->NumAttributes = 0;
00208       this->BlockAttributes = 0;
00209       };
00210     int Type;
00211     int NumElements;
00212     int ElementStartIndex;
00213     int NodesPerElement;
00214     std::vector<int> EntityCounts;
00215     std::vector<int> EntityNodeOffsets;
00216     size_t GridIndex;
00217     // std::vector<int> CellIndex;
00218     int OutputIndex;
00219     int NumAttributes;
00220     float *BlockAttributes; // Owned by metamodel or null.  Don't delete.
00221   };
00222   std::map<int, Block> BlockInfoMap;
00223   int NumCells, NumPoints, MaxId;
00224 
00225   std::vector<vtkIdType*> GlobalElementIdList;
00226   std::vector<vtkIdType*> GlobalNodeIdList;
00227 //ETX
00228   int AtLeastOneGlobalElementIdList;
00229   int AtLeastOneGlobalNodeIdList;
00230 
00231 //BTX
00232   struct VariableInfo
00233   {
00234     int NumComponents;
00235     int InIndex;
00236     int ScalarOutOffset;
00237     std::vector<std::string> OutNames;
00238   };
00239   std::map<std::string, VariableInfo> GlobalVariableMap;
00240   std::map<std::string, VariableInfo> BlockVariableMap;
00241   std::map<std::string, VariableInfo> NodeVariableMap;
00242   int NumberOfScalarGlobalArrays;
00243   int NumberOfScalarElementArrays;
00244   int NumberOfScalarNodeArrays;
00245 //ETX
00246   
00247 //BTX
00248   std::vector< std::vector<int> > CellToElementOffset;
00249 //ETX
00250   // By BlockId, and within block ID by element variable, with variables
00251   // appearing in the same order in which they appear in OutputElementArrayNames
00252   
00253   int *BlockElementVariableTruthTable;
00254   int AllVariablesDefinedInAllBlocks;
00255 
00256   int BlockVariableTruthValue(int blockIdx, int varIdx);
00257   
00258 //BTX
00259   char *StrDupWithNew (const char *s);
00260   void StringUppercase (std::string& str);
00261 //ETX
00262 
00263   int ProcessRequest (vtkInformation* request,
00264                       vtkInformationVector** inputVector,
00265                       vtkInformationVector* outputVector);
00266 
00267   int RequestInformation (vtkInformation* request,
00268                           vtkInformationVector** inputVector,
00269                           vtkInformationVector* outputVector);
00270 
00271   int FillInputPortInformation (int port, vtkInformation* info);
00272 
00273   int RequestData (vtkInformation* request,
00274                    vtkInformationVector** inputVector,
00275                    vtkInformationVector* outputVector);
00276 
00277   void WriteData ();
00278   
00279   int FlattenHierarchy (vtkDataObject* input, bool& changed);
00280 
00281   int CreateNewExodusFile ();
00282   void CloseExodusFile ();
00283 
00284   int IsDouble ();
00285   void RemoveGhostCells ();
00286   int CheckParameters ();
00287   int CheckInputArrays ();
00288   int ConstructBlockInfoMap ();
00289   int ConstructVariableInfoMaps ();
00290   int ParseMetadata ();
00291   int CreateDefaultMetadata ();
00292   char *GetCellTypeName (int t);
00293   
00294   int CreateBlockIdMetadata(vtkModelMetadata *em);
00295   int CreateBlockVariableMetadata (vtkModelMetadata* em);
00296   
00297 //BTX
00298   void ConvertVariableNames (std::map<std::string, VariableInfo>& variableMap);
00299   char **FlattenOutVariableNames (
00300             int nScalarArrays, 
00301             const std::map<std::string, VariableInfo>& variableMap);
00302   std::string CreateNameForScalarArray (const char *root,
00303                                            int component,
00304                                            int numComponents);
00305 
00306   std::map<vtkIdType, vtkIdType> *LocalNodeIdMap;
00307   std::map<vtkIdType, vtkIdType> *LocalElementIdMap;
00308 //ETX
00309   vtkIdType GetNodeLocalId(vtkIdType id);
00310   vtkIdType GetElementLocalId(vtkIdType id);
00311 
00312   int WriteInitializationParameters ();
00313   int WriteQARecords ();
00314   int WriteInformationRecords ();
00315   int WritePoints ();
00316   int WriteCoordinateNames ();
00317   int WriteGlobalPointIds ();
00318   int WriteBlockInformation ();
00319   int WriteGlobalElementIds ();
00320   int WriteVariableArrayNames ();
00321   int WriteNodeSetInformation ();
00322   int WriteSideSetInformation ();
00323   int WriteProperties ();
00324   int WriteNextTimeStep ();
00325 
00326 //BTX
00327   double ExtractGlobalData (const char *name, int comp, int ts);
00328   int WriteGlobalData (int timestep, vtkDataArray *buffer);
00329   void ExtractCellData (const char *name, int comp, vtkDataArray *buffer);
00330   int WriteCellData (int timestep, vtkDataArray *buffer);
00331   void ExtractPointData (const char *name, int comp, vtkDataArray *buffer);
00332   int WritePointData (int timestep, vtkDataArray *buffer);
00333 //ETX
00334 
00335 
00336 private:
00337   vtkExodusIIWriter (const vtkExodusIIWriter&); // Not Implemented
00338   void operator= (const vtkExodusIIWriter&); // Not Implemented
00339 };
00340 
00341 #endif