VTK
dox/IO/Exodus/vtkModelMetadata.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   ParaView
00004   Module:    vtkModelMetadata.h
00005 
00006   Copyright (c) Kitware, Inc.
00007   All rights reserved.
00008   See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 
00074 #ifndef __vtkModelMetadata_h
00075 #define __vtkModelMetadata_h
00076 
00077 #include "vtkIOExodusModule.h" // For export macro
00078 #include "vtkObject.h"
00079 
00080 class vtkDataSet;
00081 class vtkCharArray;
00082 class vtkIdTypeArray;
00083 class vtkIntArray;
00084 class vtkFloatArray;
00085 class vtkIntArray;
00086 class vtkModelMetadataSTLCloak;
00087 
00088 class VTKIOEXODUS_EXPORT vtkModelMetadata : public vtkObject
00089 {
00090 public:
00091   vtkTypeMacro(vtkModelMetadata, vtkObject);
00092   virtual void PrintSelf(ostream &os, vtkIndent indent);
00093   static vtkModelMetadata *New();
00094 
00099   virtual void PrintGlobalInformation();
00100 
00111   virtual void PrintLocalInformation();
00112 
00114 
00115   vtkSetStringMacro(Title);
00116   const char *GetTitle() const {return this->Title;}
00118 
00120   void SetInformationLines(int numLines, char **lines);
00121 
00123   void AddInformationLine(char *info);
00124 
00127   int GetInformationLines(char ***lines) const;
00128 
00130 
00131   int GetNumberOfInformationLines() const {
00132     return this->NumberOfInformationLines;}
00134 
00138   void SetQARecords(int numberOfRecords, char *QARecords[][4]);
00139 
00143   void AddQARecord(char *name, char *version, char *date, char *time);
00144 
00146 
00147   void GetQARecord(int which, char **name, char **version,
00148                    char **date, char **time) const;
00150 
00152   int GetNumberOfQARecords() const {return this->NumberOfQARecords;}
00153 
00155 
00158   vtkSetMacro(TimeStepIndex, int);
00159   int GetTimeStepIndex() const {return this->TimeStepIndex;}
00161 
00163 
00166   void SetTimeSteps(int numberOfTimeSteps, float *timeStepValues);
00167   int GetNumberOfTimeSteps() const {return this->NumberOfTimeSteps;}
00169 
00171   float *GetTimeStepValues() const {return this->TimeStepValues;}
00172 
00174 
00175   void SetCoordinateNames(int dimension, char **);
00176   char **GetCoordinateNames() const {return this->CoordinateNames;}
00178 
00181   int GetDimension() const {return this->Dimension;}
00182 
00184 
00186   vtkSetMacro(NumberOfBlocks, int);
00187   int GetNumberOfBlocks() const {return this->NumberOfBlocks;}
00189 
00191 
00193   void SetBlockIds(int *);
00194   int *GetBlockIds() const {return this->BlockIds;}
00196 
00198 
00201   void SetBlockElementType(char **);
00202   char **GetBlockElementType() const {return this->BlockElementType;}
00204 
00206 
00209   int SetBlockNumberOfElements(int *nelts);
00210   int *GetBlockNumberOfElements()const{return this->BlockNumberOfElements;}
00212 
00214 
00217   void SetBlockNodesPerElement(int *);
00218   int *GetBlockNodesPerElement()const{return this->BlockNodesPerElement;}
00220 
00222 
00225   void SetBlockElementIdList(int *);
00226   int *GetBlockElementIdList() const {return this->BlockElementIdList;}
00228 
00230   int GetSumElementsPerBlock() const {return this->SumElementsPerBlock;}
00231 
00234   int *GetBlockElementIdListIndex()const {return this->BlockElementIdListIndex;}
00235 
00237 
00240   int SetBlockNumberOfAttributesPerElement(int *natts);
00241   int *GetBlockNumberOfAttributesPerElement()const {return this->BlockNumberOfAttributesPerElement;}
00243 
00245 
00248   void SetBlockAttributes(float *);
00249   float *GetBlockAttributes()const {return this->BlockAttributes;}
00251 
00253 
00254   int GetSizeBlockAttributeArray() const {
00255     return this->SizeBlockAttributeArray;}
00257 
00260   int *GetBlockAttributesIndex() const {return this->BlockAttributesIndex;}
00261 
00263 
00265   vtkSetMacro(NumberOfNodeSets, int);
00266   int GetNumberOfNodeSets() const {return this->NumberOfNodeSets;}
00268 
00270 
00273   void SetNodeSetIds(int *);
00274   int *GetNodeSetIds() const {return this->NodeSetIds;}
00276 
00278 
00281   int SetNodeSetSize(int *);
00282   int *GetNodeSetSize() const {return this->NodeSetSize;}
00284 
00286 
00290   void SetNodeSetNodeIdList(int *);
00291   int *GetNodeSetNodeIdList() const {return this->NodeSetNodeIdList;}
00293 
00295 
00299   int SetNodeSetNumberOfDistributionFactors(int *);
00300   int *GetNodeSetNumberOfDistributionFactors() const
00301     {return this->NodeSetNumberOfDistributionFactors;}
00303 
00305 
00308   void SetNodeSetDistributionFactors(float *);
00309   float *GetNodeSetDistributionFactors() const {
00310     return this->NodeSetDistributionFactors;}
00312 
00314   int GetSumNodesPerNodeSet() const {return this->SumNodesPerNodeSet;}
00315 
00317   int GetSumDistFactPerNodeSet() const {return this->SumDistFactPerNodeSet;}
00318 
00320 
00322   int *GetNodeSetNodeIdListIndex() const {
00323     return this->NodeSetNodeIdListIndex;}
00325 
00327 
00329   int *GetNodeSetDistributionFactorIndex() const {
00330     return this->NodeSetDistributionFactorIndex;}
00332 
00334 
00336   vtkSetMacro(NumberOfSideSets, int);
00337   int GetNumberOfSideSets() const {return this->NumberOfSideSets;}
00339 
00341 
00343   void SetSideSetIds(int *);
00344   int *GetSideSetIds() const {return this->SideSetIds;}
00346 
00348 
00351   int SetSideSetSize(int *sizes);
00352   int *GetSideSetSize() const {return this->SideSetSize;}
00354 
00356 
00360   int SetSideSetNumberOfDistributionFactors(int *df);
00361   int *GetSideSetNumberOfDistributionFactors() const {
00362     return this->SideSetNumberOfDistributionFactors;}
00364 
00366 
00370   void SetSideSetElementList(int *);
00371   int *GetSideSetElementList() const {return this->SideSetElementList;}
00373 
00375 
00380   void SetSideSetSideList(int *);
00381   int *GetSideSetSideList() const {return this->SideSetSideList;}
00383 
00385 
00389   void SetSideSetNumDFPerSide(int *numNodes);
00390   int *GetSideSetNumDFPerSide() const {return this->SideSetNumDFPerSide;}
00392 
00394 
00402   void SetSideSetDistributionFactors(float *);
00403   float *GetSideSetDistributionFactors() const {
00404     return this->SideSetDistributionFactors;}
00406 
00408   int GetSumSidesPerSideSet() const {return this->SumSidesPerSideSet;}
00409 
00411   int GetSumDistFactPerSideSet() const {return this->SumDistFactPerSideSet;}
00412 
00415   int *GetSideSetListIndex() const {return this->SideSetListIndex;}
00416 
00418 
00420   int *GetSideSetDistributionFactorIndex() const {
00421     return this->SideSetDistributionFactorIndex;}
00423 
00425 
00426   int GetNumberOfBlockProperties() const {
00427     return this->NumberOfBlockProperties;}
00429 
00431 
00432   void SetBlockPropertyNames(int numProp, char **names);
00433   char **GetBlockPropertyNames() const {return this->BlockPropertyNames;}
00435 
00437 
00439   void SetBlockPropertyValue(int *);
00440   int *GetBlockPropertyValue() const {return this->BlockPropertyValue;}
00442 
00444 
00445   int GetNumberOfNodeSetProperties() const {
00446     return this->NumberOfNodeSetProperties;}
00448 
00450 
00451   void SetNodeSetPropertyNames(int numProp, char **names);
00452   char **GetNodeSetPropertyNames() const {return this->NodeSetPropertyNames;}
00454 
00456 
00458   void SetNodeSetPropertyValue(int *);
00459   int *GetNodeSetPropertyValue() const {return this->NodeSetPropertyValue;}
00461 
00463 
00464   int GetNumberOfSideSetProperties() const {
00465     return this->NumberOfSideSetProperties;}
00467 
00469 
00470   void SetSideSetPropertyNames(int numProp, char **names);
00471   char **GetSideSetPropertyNames() const {return this->SideSetPropertyNames;}
00473 
00475 
00477   void SetSideSetPropertyValue(int *);
00478   int *GetSideSetPropertyValue() const {return this->SideSetPropertyValue;}
00480 
00482 
00483   int GetNumberOfGlobalVariables() const {
00484     return this->NumberOfGlobalVariables;}
00486 
00488 
00489   void SetGlobalVariableNames(int numVarNames, char **n);
00490   char **GetGlobalVariableNames() const {return this->GlobalVariableNames;}
00492 
00494 
00496   void SetGlobalVariableValue(float *f);
00497   float *GetGlobalVariableValue() const {return this->GlobalVariableValue;}
00499 
00501 
00510   void SetElementVariableInfo(int numOrigNames, char **origNames,
00511                               int numNames, char **names, int *numComp,
00512                               int *map);
00514 
00516 
00525   void SetNodeVariableInfo(int numOrigNames, char **origNames,
00526                            int numNames, char **names,  int *numComp,
00527                            int *map);
00529 
00531 
00535   void SetElementVariableTruthTable(int *);
00536   int *GetElementVariableTruthTable() const {
00537     return this->ElementVariableTruthTable;}
00539 
00541 
00543   vtkSetMacro(AllVariablesDefinedInAllBlocks, int);
00544   vtkBooleanMacro(AllVariablesDefinedInAllBlocks, int);
00545   int GetAllVariablesDefinedInAllBlocks() const {
00546     return this->AllVariablesDefinedInAllBlocks;}
00548 
00555   int ElementVariableIsDefinedInBlock(char *varname, int blockId);
00556 
00558 
00570   int GetOriginalNumberOfElementVariables() const {
00571     return this->OriginalNumberOfElementVariables;}
00572   char **GetOriginalElementVariableNames() const {
00573     return this->OriginalElementVariableNames;}
00574   int GetNumberOfElementVariables() const {
00575     return this->NumberOfElementVariables;}
00576   char **GetElementVariableNames() const {
00577     return this->ElementVariableNames;}
00578   int *GetElementVariableNumberOfComponents() const {
00579     return this->ElementVariableNumberOfComponents;}
00580   int *GetMapToOriginalElementVariableNames() const {
00581     return this->MapToOriginalElementVariableNames;}
00583 
00584   int GetOriginalNumberOfNodeVariables() const {
00585     return this->OriginalNumberOfNodeVariables;}
00586   char **GetOriginalNodeVariableNames() const {
00587     return this->OriginalNodeVariableNames;}
00588   int GetNumberOfNodeVariables() const {
00589     return this->NumberOfNodeVariables;}
00590   char **GetNodeVariableNames() const {
00591     return this->NodeVariableNames;}
00592   int *GetNodeVariableNumberOfComponents() const {
00593     return this->NodeVariableNumberOfComponents;}
00594   int *GetMapToOriginalNodeVariableNames() const {
00595     return this->MapToOriginalNodeVariableNames;}
00596 
00601   char *FindOriginalElementVariableName(const char *name, int component);
00602 
00607   char *FindOriginalNodeVariableName(const char *name, int component);
00608 
00611   static int HasMetadata(vtkDataSet *grid);
00612 
00615   static void RemoveMetadata(vtkDataSet *grid);
00616 
00618   void Pack(vtkDataSet *ugrid);
00619 
00624   int Unpack(vtkDataSet *ugrid, int deleteIt);
00625 
00627 
00638   int AddUGridElementVariable(char *ugridVarName, char *origName, int numComponents);
00639   int RemoveUGridElementVariable(char *ugridVarName);
00641 
00642   int AddUGridNodeVariable(char *ugridVarName, char *origName, int numComponents);
00643   int RemoveUGridNodeVariable(char *ugridVarName);
00644 
00653   int MergeModelMetadata(const vtkModelMetadata *em);
00654 
00658   int MergeGlobalInformation(const vtkModelMetadata *em);
00659 
00661 
00666   vtkModelMetadata *ExtractModelMetadata(vtkIdTypeArray *globalCellIdList,
00667                                          vtkDataSet *grid);
00669 
00672   vtkModelMetadata *ExtractGlobalMetadata();
00673 
00675 
00684   void FreeAllGlobalData();
00685   void FreeAllLocalData();
00686   void FreeBlockDependentData();
00687   void FreeOriginalElementVariableNames();
00688   void FreeOriginalNodeVariableNames();
00689   void FreeUsedElementVariableNames();
00690   void FreeUsedNodeVariableNames();
00691   void FreeUsedElementVariables();
00692   void FreeUsedNodeVariables();
00694 
00696   void Reset();
00697 
00700   int GetBlockLocalIndex(int id);
00701 
00702 protected:
00703   vtkModelMetadata();
00704   ~vtkModelMetadata();
00705 
00706 private:
00707   void InitializeAllMetadata();
00708   void InitializeAllIvars();
00709 
00710   void FreeAllMetadata();
00711   void FreeAllIvars();
00712 
00713   void FreeQARecords();
00714 
00715   int BuildBlockElementIdListIndex();
00716   int BuildBlockAttributesIndex();
00717   int BuildNodeSetNodeIdListIndex();
00718   int BuildNodeSetDistributionFactorIndex();
00719   int BuildSideSetListIndex();
00720   int BuildSideSetDistributionFactorIndex();
00721 
00722   int InitializeFromSizeArray(vtkIntArray *ia, int &maxStr, int &maxLine);
00723   vtkIntArray *PackSizeArray(int maxStr, int maxLine);
00724   int InitializeFromIntArray(vtkModelMetadata *sizes, vtkIntArray *ia);
00725   vtkIntArray *PackIntArray();
00726   int InitializeFromCharArray(vtkModelMetadata *sizes,
00727                    vtkCharArray *uca, int maxStr, int maxLine);
00728   vtkCharArray *PackCharArray(int maxStr, int maxLine);
00729   int InitializeFromFloatArray(vtkFloatArray *fa);
00730   vtkFloatArray *PackFloatArray();
00731 
00732   static char *StrDupWithNew(const char *s);
00733 
00734   static char *WriteLines(char *p, int maxLines, int maxLen, char **lines);
00735   static char *ReadLines(char ***to, int maxLines,
00736                             int maxLen, char *from);
00737   static char **CopyLines(char **lines, int num);
00738   static int *CopyInts(int *vals, int num);
00739 
00740   static int FindNameOnList(char *name, char **list, int listLen);
00741 
00742   int MergeIdLists(int numSubLists,
00743     int *id1, int *id1Idx, int id1Len,
00744       float *dist1, int *dist1Idx, int dist1Len,
00745     int *id2, int *id2Idx, int id2Len,
00746       float *dist2, int *dist2Idx, int dist2Len,
00747     int **idNew, int **idNewIdx, int *idNewLen,
00748       float **distNew, int **distNewIdx, int *distNewLen);
00749 
00750   int AppendFloatLists(int numSubLists,
00751     float *id1, int *id1Idx, int id1Len,
00752     float *id2, int *id2Idx, int id2Len,
00753     float **idNew, int **idNewIdx, int *idNewLen);
00754 
00755   int AppendIntegerLists(int numSubLists,
00756     int *id1, int *id1Idx, int id1Len,
00757     int *id2, int *id2Idx, int id2Len,
00758     int **idNew, int **idNewIdx, int *idNewLen);
00759 
00760   void ExtractCellsFromBlockData(vtkModelMetadataSTLCloak *idset,
00761                                  vtkModelMetadata *mmd);
00762   void ExtractNodesFromNodeSetData(vtkModelMetadataSTLCloak *idset,
00763                                    vtkModelMetadata *mmd);
00764   void ExtractSidesFromSideSetData(vtkModelMetadataSTLCloak *idset,
00765                                    vtkModelMetadata *mmd);
00766 
00767   void ShowFloats(const char *what, int num, float *f);
00768   void ShowLines(const char *what, int num, char **l);
00769   void ShowIntArray(const char *what, int numx, int numy, int *id);
00770   void ShowInts(const char *what, int num, int *id);
00771   void ShowListsOfInts(const char *what, int *list,
00772                        int nlists, int *idx, int len, int verbose);
00773   void ShowListsOfFloats(const char *what, float *list,
00774                          int nlists, int *idx, int len, int verbose);
00775 
00776   void SetOriginalElementVariableNames(int nvars, char **names);
00777   void SetElementVariableNames(int nvars, char **names);
00778   void SetElementVariableNumberOfComponents(int *comp);
00779   void SetMapToOriginalElementVariableNames(int *map);
00780 
00781   void SetOriginalNodeVariableNames(int nvars, char **names);
00782   void SetNodeVariableNames(int nvars, char **names);
00783   void SetNodeVariableNumberOfComponents(int *comp);
00784   void SetMapToOriginalNodeVariableNames(int *map);
00785 
00786   int CalculateMaximumLengths(int &maxString, int &maxLine);
00787 
00788   // Fields in Exodus II file and their size (defined in exodusII.h)
00789   //   (G - global fields, relevant to entire file or file set)
00790   //   (L - local fields, they differ depending on which cells and nodes are
00791   //        in a file of a partitioned set, or are read in from file)
00792 
00793   char *Title;                 // (G)
00794 
00795   int NumberOfQARecords;       // (G)
00796 //BTX
00797   char *(*QARecord)[4];        // NumberOfQARecords * 4 (G)
00798 //ETX
00799 
00800   int NumberOfInformationLines; // (G)
00801   char **InformationLine;       // (G)
00802 
00803   int Dimension;            // (G)
00804   char **CoordinateNames;   // (at most 3 of these) (G)
00805 
00806   // Time steps
00807 
00808   int TimeStepIndex;     // starting at 0 (Exodus file starts at 1)
00809   int NumberOfTimeSteps; // (G)
00810   float *TimeStepValues; // (G)
00811 
00812   // Block information - arrays that are input with Set*
00813 
00814   int NumberOfBlocks;       // (G)
00815 
00816   int *BlockIds;               // NumberOfBlocks (G) (start at 1)
00817   char **BlockElementType;     // NumberOfBlocks (G)
00818   int *BlockNumberOfElements;  // NumberOfBlocks (L)
00819   int *BlockNodesPerElement;   // NumberOfBlocks (G)
00820   int *BlockNumberOfAttributesPerElement;// NumberOfBlocks (G)
00821   int *BlockElementIdList;     // SumElementsPerBlock     (L)
00822   float *BlockAttributes;      // SizeBlockAttributeArray (L)
00823 
00824   // Block information - values that we calculate
00825 
00826   int SumElementsPerBlock;
00827   int SizeBlockAttributeArray;
00828 
00829   int *BlockElementIdListIndex;          // NumberOfBlocks
00830   int *BlockAttributesIndex;             // NumberOfBlocks
00831 
00832   vtkModelMetadataSTLCloak *BlockIdIndex;    // computed map
00833 
00834   // Node Sets - arrays that are input to the class with Set*
00835 
00836   int NumberOfNodeSets; // (G)
00837 
00838   int *NodeSetIds;             // NumberOfNodeSets (G)
00839   int *NodeSetSize;            // NumberOfNodeSets (L)
00840   int *NodeSetNumberOfDistributionFactors;  // NNS (L) (NSNDF[i] is 0 or NSS[i])
00841   int *NodeSetNodeIdList;   // SumNodesPerNodeSet (L)
00842   float *NodeSetDistributionFactors; // SumDistFactPerNodeSet (L)
00843 
00844   // Node Sets - values or arrays that the class computes
00845 
00846   int SumNodesPerNodeSet;
00847   int SumDistFactPerNodeSet;
00848 
00849   int *NodeSetNodeIdListIndex;           // NumberOfNodeSets
00850   int *NodeSetDistributionFactorIndex;   // NumberOfNodeSets
00851 
00852   // Side Sets - input to class with Set*
00853 
00854   int NumberOfSideSets; // (G)
00855 
00856   int *SideSetIds;                          // NumberOfSideSets (G)
00857   int *SideSetSize;                         // NumberOfSideSets (L)
00858   int *SideSetNumberOfDistributionFactors;  // NSS (L) (SSNDF[i] = 0 or NumNodesInSide)
00859   int *SideSetElementList;               // SumSidesPerSideSet (L)
00860   int *SideSetSideList;                  // SumSidesPerSideSet (L)
00861   int *SideSetNumDFPerSide;              // SumSidesPerSideSet (L)
00862   float *SideSetDistributionFactors;     // SumDistFactPerSideSet (L)
00863 
00864   // Side Sets - calculated by class
00865 
00866   int SumSidesPerSideSet;
00867   int SumDistFactPerSideSet;
00868 
00869   int *SideSetListIndex;                 // NumberOfSideSets
00870   int *SideSetDistributionFactorIndex;   // NumberOfSideSets
00871 
00872   // Other properties, provided as input with Set*
00873 
00874   int NumberOfBlockProperties; // (G)
00875   char **BlockPropertyNames;   // one per property (G)
00876   int *BlockPropertyValue;     // NumBlocks * NumBlockProperties (G)
00877 
00878   int NumberOfNodeSetProperties; // (G)
00879   char **NodeSetPropertyNames;   // one per property (G)
00880   int *NodeSetPropertyValue;     // NumNodeSets * NumNodeSetProperties (G)
00881 
00882   int NumberOfSideSetProperties; // (G)
00883   char **SideSetPropertyNames;   // one per property (G)
00884   int *SideSetPropertyValue;     // NumSideSets * NumSideSetProperties (G)
00885 
00886   // Global variables, 1 value per time step per variable.  We store
00887   // these as floats, even if they are doubles in the file.  The values
00888   // are global in the sense that they apply to the whole data set, but
00889   // the are local in the sense that they can change with each time step.
00890   // For the purpose of this object, which represents a particular
00891   // time step, they are therefore considered "local".  (Since they need
00892   // to be updated every time another read is done from the file.)
00893 
00894   int NumberOfGlobalVariables;   // (G)
00895   char **GlobalVariableNames;    // (G) NumberOfGlobalVariables
00896   float *GlobalVariableValue;   // (G) NumberOfGlobalVariables
00897 
00898   // The element and node arrays in the file were all scalar arrays.
00899   // Those with similar names were combined into vectors in VTK.  Here
00900   // are all the original names from the Exodus file, the names given
00901   // the variables in the VTK ugrid, and a mapping from the VTK names
00902   // to the Exodus names.
00903 
00904   int OriginalNumberOfElementVariables;    // (G)
00905   char **OriginalElementVariableNames;     // (G) OriginalNumberOfElementVariables
00906   int NumberOfElementVariables;            // (G)
00907   int MaxNumberOfElementVariables;         // (G)
00908   char **ElementVariableNames;             // (G) MaxNumberOfElementVariables
00909   int *ElementVariableNumberOfComponents;  // (G) MaxNumberOfElementVariables
00910   int *MapToOriginalElementVariableNames;  // (G) MaxNumberOfElementVariables
00911 
00912   int OriginalNumberOfNodeVariables;       // (G)
00913   char **OriginalNodeVariableNames;        // (G) OriginalNumberOfNodeVariables
00914   int NumberOfNodeVariables;               // (G)
00915   int MaxNumberOfNodeVariables;            // (G)
00916   char **NodeVariableNames;                // (G) NumberOfNodeVariables
00917   int *NodeVariableNumberOfComponents;     // (G) NumberOfNodeVariables
00918   int *MapToOriginalNodeVariableNames;     // (G) NumberOfNodeVariables
00919 
00920   int *ElementVariableTruthTable;  // (G) NumBlocks*OrigNumberOfElementVariables
00921   int AllVariablesDefinedInAllBlocks;
00922 
00923 private:
00924   vtkModelMetadata(const vtkModelMetadata&); // Not implemented
00925   void operator=(const vtkModelMetadata&); // Not implemented
00926 };
00927 #endif