cgma
CubitFileFEModel.hpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002     COPYRIGHT 2002 CATERPILLAR INC.  ALL RIGHTS RESERVED
00003 
00004     This program is the property of Caterpillar Inc., includes Caterpillar's
00005     confidential and trade secret information, and is maintained as an
00006     unpublished copyrighted work.  It is not to be copied or used by others
00007     except under license from Caterpillar.  This program is also protected as an
00008     unpublished work in accordance with the copyright act of 1976.  In the event
00009     of either inadvertent or deliberate publication, Caterpillar Inc. intends to
00010     maintain copyright protection for this work under the relevant copyright
00011     laws pertaining to published works.  The inclusion of a copyright notice
00012     hereon is precautionary only, and does not imply publication or disclosure.
00013 
00014  
00015  Filename      : CubitFileFEModel.hpp
00016 
00017  Purpose       : Defines an interface for the reading and writing functionality
00018                  for a FE model section of a Cubit (*.cub) format file.
00019            
00020  Special Notes :
00021 
00022  Creator       : Will A. Helden
00023 
00024  Creation Date : 02/15/02
00025 
00026  Owner         : Will A. Helden
00027 
00028 *******************************************************************************/
00029 
00030 #ifndef CubitFileFEModel_HPP
00031 #define CubitFileFEModel_HPP
00032 
00033 #include "CubitFileMetaData.hpp"
00034 #include "CGMUtilConfigure.h"
00035 #include <vector>
00036 
00037 namespace NCubitFile {
00038 
00039 class CUBIT_UTIL_EXPORT CFEModel {
00040 public:
00041     CFEModel();
00042     virtual ~CFEModel();
00043     
00044     UnsignedInt32 InitWrite(FILE* xpFile,
00045         UnsignedInt32 xintGeomCount, UnsignedInt32 xintGroupCount,
00046         UnsignedInt32 xintBlockCount, UnsignedInt32 xintNodeSetCount,
00047         UnsignedInt32 xintSideSetCount);
00048     void WriteNodes(UnsignedInt32 xintIndex, UnsignedInt32 xintGeomID,
00049         UnsignedInt32 xintNodeCount, UnsignedInt32 *xpaintNodeIDs,
00050         double *xpadblX, double *xpadblY, double *xpadblZ);
00051     void WriteElems(UnsignedInt32 xintIndex,
00052         UnsignedInt32 xintNumTypes, SElemData* xpaElemData);
00053     void WriteGroup(UnsignedInt32 xintIndex, UnsignedInt32 xintGroupID,
00054         UnsignedInt32 xintGroupType, const char* xpachrGroupName,
00055         UnsignedInt32 xintNumTypes, SGroupData* xpaGroupData);
00056     void WriteBlock(UnsignedInt32 xintIndex,
00057         UnsignedInt32 xintBlockID, int unique_id, UnsignedInt32 xintBlockType,
00058         UnsignedInt32 xintBlockColor, UnsignedInt32 xintMixedElemType,
00059         UnsignedInt32 xintDefPyramidType, UnsignedInt32 xintMaterialID,
00060         UnsignedInt32 xintBlockDimension,
00061         UnsignedInt32 xintNumTypes, SBlockData* xpaBlockData,
00062         UnsignedInt32 xintAttributeOrder, double* xpadblAttributes);
00063     void WriteNodeSet(UnsignedInt32 xintIndex,
00064         UnsignedInt32 xintNodeSetID, int unique_id, UnsignedInt32 xintColor,
00065         UnsignedInt32 xintPointSymbol,
00066         UnsignedInt32 xintNumTypes, SNodeSetData* xpaNodeSetData,
00067         const std::vector<char>& bcdata);
00068     void WriteSideSet_11(UnsignedInt32 xintIndex,
00069         UnsignedInt32 xintSideSetID, int unique_id, UnsignedInt32 xintColor,
00070         UnsignedInt32 xintUseShells,
00071         UnsignedInt32 xintNumTypes, SSideSetData_11* xpaSideSetData,
00072         UnsignedInt32 xintNumDistFact, double* xpadblDistribution,
00073         const std::vector<char>& bcdata);
00074     UnsignedInt32 EndWrite();
00075     
00076     void InitRead(FILE* xpFile, UnsignedInt32 xintAbsoluteOffset,
00077         UnsignedInt32& xintGeomCount, UnsignedInt32& xintGroupCount,
00078         UnsignedInt32& xintBlockCount, UnsignedInt32& xintNodeSetCount,
00079         UnsignedInt32& xintSideSetCount); 
00080     void ReadNodes(UnsignedInt32 xintIndex, UnsignedInt32& xintGeomID,
00081         UnsignedInt32& xintNodeCount, UnsignedInt32*& xpaintNodeIDs,
00082         double*& xpadblX, double*& xpadblY, double*& xpadblZ);
00083     void ReadElems(double data_version,
00084         UnsignedInt32 xintIndex, UnsignedInt32& xintGeomID,
00085         UnsignedInt32& xintNumTypes, SElemData*& xpaElemData);
00086     void ReadGroupIdentity(UnsignedInt32 xintIndex, UnsignedInt32& xintGroupID,
00087         UnsignedInt32& xintGroupType, const char*& xpachrGroupName);
00088     void ReadGroupMembers(UnsignedInt32 xintIndex,
00089         UnsignedInt32& xintNumTypes, SGroupData*& xpaGroupData);
00090     void ReadBlock(UnsignedInt32 xintIndex,
00091         UnsignedInt32& xintBlockID, int& unique_id, UnsignedInt32& xintBlockType,
00092         UnsignedInt32& xintBlockColor, UnsignedInt32& xintMixedElemType,
00093         UnsignedInt32& xintDefPyramidType, UnsignedInt32& xintMaterialID,
00094         UnsignedInt32& xintBlockDimension,
00095         UnsignedInt32& xintNumTypes, SBlockData*& xpaBlockData,
00096         UnsignedInt32& xintAttributeOrder, double*& xpadblAttributes);
00097     void ReadNodeSet(UnsignedInt32 xintIndex,
00098         UnsignedInt32& xintNodeSetID, int& unique_id, UnsignedInt32& xintColor,
00099         UnsignedInt32& xintPointSymbol,
00100         UnsignedInt32& xintNumTypes, SNodeSetData*& xpaNodeSetData,
00101         std::vector<char>& bcdata);
00102     void ReadSideSet_10(UnsignedInt32 xintIndex,
00103         UnsignedInt32& xintSideSetID, UnsignedInt32& xintColor,
00104         UnsignedInt32& xintUseShells,
00105         UnsignedInt32& xintNumTypes, SSideSetData_10*& xpaSideSetData,
00106         UnsignedInt32& xintNumDistFact, double*& xpadblDistribution);
00107     void ReadSideSet_11(UnsignedInt32 xintIndex,
00108         UnsignedInt32& xintSideSetID, int& unique_id, UnsignedInt32& xintColor,
00109         UnsignedInt32& xintUseShells,
00110         UnsignedInt32& xintNumTypes, SSideSetData_11*& xpaSideSetData,
00111         UnsignedInt32& xintNumDistFact, double*& xpadblDistribution,
00112         std::vector<char>& bcdata);
00113     void EndRead();
00114     
00115     CMetaData& GetGeomMetaData();
00116     CMetaData& GetNodeMetaData();
00117     CMetaData& GetElemMetaData();
00118     CMetaData& GetGroupMetaData();
00119     CMetaData& GetBlockMetaData();
00120     CMetaData& GetNodeSetMetaData();
00121     CMetaData& GetSideSetMetaData();
00122     
00123 private:
00124     FILE* mpReadFile;
00125     FILE* mpWriteFile;
00126     UnsignedInt32 mintFEModelOffset;
00127     CMetaData mGeomMetaData;
00128     CMetaData mNodeMetaData;
00129     CMetaData mElemMetaData;
00130     CMetaData mGroupMetaData;
00131     CMetaData mBlockMetaData;
00132     CMetaData mNodeSetMetaData;
00133     CMetaData mSideSetMetaData;
00134 
00135     // Data storage structures:
00136     // CAUTION: These structures must be 64 bit word aligned!!!
00137     struct SCubitFileFEModelHeader {
00138         UnsignedInt32 mintFEModelEndian;
00139         UnsignedInt32 mintFEModelSchema;
00140         UnsignedInt32 mintFEModelCompress;
00141         UnsignedInt32 mintFEModelLength;
00142         UnsignedInt32 mintGeometryCount;
00143         UnsignedInt32 mintGeomTableOffset;
00144         UnsignedInt32 mintGeomMetaDataOffset;
00145         UnsignedInt32 mintNodeMetaDataOffset;
00146         UnsignedInt32 mintElemMetaDataOffset;
00147         UnsignedInt32 mintGroupCount;
00148         UnsignedInt32 mintGroupTableOffset;
00149         UnsignedInt32 mintGroupMetaDataOffset;
00150         UnsignedInt32 mintBlockCount;
00151         UnsignedInt32 mintBlockTableOffset;
00152         UnsignedInt32 mintBlockMetaDataOffset;
00153         UnsignedInt32 mintNodeSetCount;
00154         UnsignedInt32 mintNodeSetTableOffset;
00155         UnsignedInt32 mintNodeSetMetaDataOffset;
00156         UnsignedInt32 mintSideSetCount;
00157         UnsignedInt32 mintSideSetTableOffset;
00158         UnsignedInt32 mintSideSetMetaDataOffset;
00159         UnsignedInt32 mintPadFor64bitOS;
00160     } mFEModel;
00161     static const UnsignedInt32 mintSizeOfFEModelHeader;
00162     struct SCubitFileGeomEntry {
00163         UnsignedInt32 mintNodeCount;
00164         UnsignedInt32 mintNodeOffset;
00165         UnsignedInt32 mintElemCount;
00166         UnsignedInt32 mintElemOffset;
00167         UnsignedInt32 mintElemTypeCount;
00168         UnsignedInt32 mintElemLength;
00169         UnsignedInt32 mintGeomID;
00170         UnsignedInt32 mintPadFor64bitOS;
00171     } *mpaGeoms;
00172     static const UnsignedInt32 mintSizeOfGeomEntry;
00173     struct SCubitFileGroupEntry {
00174         UnsignedInt32 mintGroupID;
00175         UnsignedInt32 mintGroupType;
00176         UnsignedInt32 mintMemberCount;
00177         UnsignedInt32 mintMemberOffset;
00178         UnsignedInt32 mintMemberTypeCount;
00179         UnsignedInt32 mintGroupLength;
00180     } *mpaGroups;
00181     static const UnsignedInt32 mintSizeOfGroupEntry;
00182     struct SCubitFileBlockEntry {
00183         UnsignedInt32 mintBlockID;
00184         UnsignedInt32 mintBlockElementType;
00185         UnsignedInt32 mintMemberCount;
00186         UnsignedInt32 mintMemberOffset;
00187         UnsignedInt32 mintMemberTypeCount;
00188         UnsignedInt32 mintAttributeOrder;
00189         UnsignedInt32 mintBlockColor;
00190         UnsignedInt32 mintBlockMixedElemType;
00191         UnsignedInt32 mintBlockDefPyramidType;
00192         UnsignedInt32 mintBlockMaterial;
00193         UnsignedInt32 mintBlockLength;
00194         UnsignedInt32 mintBlockDimension;
00195     } *mpaBlocks;
00196     static const UnsignedInt32 mintSizeOfBlockEntry;
00197     struct SCubitFileNodeSetEntry {
00198         UnsignedInt32 mintNodeSetID;
00199         UnsignedInt32 mintMemberCount;
00200         UnsignedInt32 mintMemberOffset;
00201         UnsignedInt32 mintMemberTypeCount;
00202         UnsignedInt32 mintNodeSetPointSym;
00203         UnsignedInt32 mintNodeSetColor;
00204         UnsignedInt32 mintNodeSetLength;
00205         UnsignedInt32 mintPadFor64bitOS;
00206     } *mpaNodeSets;
00207     static const UnsignedInt32 mintSizeOfNodeSetEntry;
00208     struct SCubitFileSideSetEntry {
00209         UnsignedInt32 mintSideSetID;
00210         UnsignedInt32 mintMemberCount;
00211         UnsignedInt32 mintMemberOffset;
00212         UnsignedInt32 mintMemberTypeCount;
00213         UnsignedInt32 mintNumDistFact;
00214         UnsignedInt32 mintSideSetColor;
00215         UnsignedInt32 mintUseShells;
00216         UnsignedInt32 mintSideSetLength;
00217     } *mpaSideSets;
00218     static const UnsignedInt32 mintSizeOfSideSetEntry;
00219     
00220     // Buffers for read operations.
00221     struct SNodeReturnBuffer {
00222         UnsignedInt32 mintNumNodes;
00223         UnsignedInt32* mpaNodeIDs;
00224         double* mpadblX;
00225         double* mpadblY;
00226         double* mpadblZ;
00227     } mNodeBuff;
00228     struct SElemReturnBuffer {
00229         UnsignedInt32 mintNumTypes;
00230         UnsignedInt32 mintNumElemIds;
00231         UnsignedInt32 mintNumElemGids;
00232         UnsignedInt32 mintNumConnect;
00233         SElemData* mpaElemData;
00234         UnsignedInt32* mpaElemIDs;
00235         UnsignedInt32* mpaElemGlobalIDs;
00236         UnsignedInt32* mpaElemConnect;
00237     } mElemBuff;
00238     struct SGroupReturnBuffer {
00239         UnsignedInt32 mintNumTypes;
00240         UnsignedInt32 mintNumMembers;
00241         SGroupData* mpaGroupData;
00242         UnsignedInt32* mpaintMemberIDs;
00243     } mGroupBuff;
00244     struct SBlockReturnBuffer {
00245         UnsignedInt32 mintNumTypes;
00246         UnsignedInt32 mintNumMembers;
00247         UnsignedInt32 mintAttributeOrder;
00248         SBlockData* mpaBlockData;
00249         UnsignedInt32* mpaintMemberIDs;
00250         double* mpadblAttributes;
00251     } mBlockBuff;
00252     struct SNodeSetReturnBuffer {
00253         UnsignedInt32 mintNumTypes;
00254         UnsignedInt32 mintNumMembers;
00255         SNodeSetData* mpaNodeSetData;
00256         UnsignedInt32* mpaintMemberIDs;
00257     } mNodeSetBuff;
00258 
00259     // these sideset buffers are big arrays and the mpaSideSetData can reference parts of these buffers
00260     // I guess the reason for that is memory ownership is a bit more clear when passing data around
00261     struct SSideSetReturnBuffer_10 {
00262         UnsignedInt32 mintNumTypes;
00263         UnsignedInt32 mintNumMembersIDs;
00264         UnsignedInt32 mintNumMembersSense8;
00265         UnsignedInt32 mintNumMembersSense32;
00266         UnsignedInt32 mintNumMembersSideNum;
00267         UnsignedInt32 mintNumDistFact;
00268         SSideSetData_10* mpaSideSetData;
00269         UnsignedInt32* mpaintMemberIDs;
00270         char* mpachrMemberSense;
00271         UnsignedInt32* mpaintMemberSense;
00272         char* mpachrMemberSideNum;
00273         double* mpadblDistribution;
00274     } mSideSetBuff_10;
00275     struct SSideSetReturnBuffer_11 {
00276         UnsignedInt32 mintNumTypes;
00277         UnsignedInt32 mintNumMembersIDs;
00278         UnsignedInt32 mintNumMembersSense;
00279         UnsignedInt32 mintNumMembersSideNum;
00280         UnsignedInt32 mintNumDistFact;
00281         SSideSetData_11* mpaSideSetData;
00282         UnsignedInt32* mpaintMemberTypes;
00283         UnsignedInt32* mpaintMemberIDs;
00284         char* mpachrMemberSense;
00285         UnsignedInt32 mintNumWRTEntities;
00286         UnsignedInt32* mpaintMemberWRTEntities;
00287         double* mpadblDistribution;
00288     } mSideSetBuff_11;
00289 
00290     template <class TBuffer>
00291     TBuffer* AdjustBuffer(UnsignedInt32 xintRequiredSize,
00292         UnsignedInt32& xintActualSize, TBuffer*& xpaBuffer)
00293     {
00294         if(!xintRequiredSize)  return NULL;  // Nothing requested, return nothing.
00295 
00296         if(xintActualSize < xintRequiredSize) {
00297             if(xpaBuffer)
00298                 delete [] xpaBuffer;
00299             xintActualSize = xintRequiredSize;
00300             xpaBuffer = new TBuffer[xintActualSize];
00301             if(!xpaBuffer) {
00302                 xintActualSize = 0;
00303                 throw CCubitFile::eMemoryError;
00304             }
00305         }
00306         return xpaBuffer;
00307     }
00308 };
00309 
00310 } // namespace NCubitFile
00311 
00312 #endif
00313 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines