cgma
CubitFileSimModel.hpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002     COPYRIGHT 2010 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      : CubitFileSimModel.hpp
00016 
00017  Purpose       : Defines an interface for the reading and writing functionality
00018                  for a Simulation model section of a Cubit (*.cub) format file.
00019            
00020  Special Notes :
00021 
00022  Creator       : Andrew Rout
00023 
00024  Creation Date : 02/20/10
00025 
00026  Owner         : Andrew Rout
00027 
00028 *******************************************************************************/
00029 
00030 #ifndef CubitFileSimModel_HPP
00031 #define CubitFileSimModel_HPP
00032 
00033 #include "CubitFileMetaData.hpp"
00034 #include "CGMUtilConfigure.h"
00035 #include <vector>
00036 
00037 namespace NCubitFile {
00038 
00039 class CUBIT_UTIL_EXPORT CSimModel {
00040 public:
00041     CSimModel();
00042     virtual ~CSimModel();
00043     
00044     UnsignedInt32 InitWrite(FILE* xpFile,
00045         UnsignedInt32 xintBCCount, UnsignedInt32 xintICCount,
00046         UnsignedInt32 xintBCSetCount, UnsignedInt32 xintMaterialCount,
00047         UnsignedInt32 xintAmplitudeCount, UnsignedInt32 xintConstraintCount);
00048     void WriteBCSet(UnsignedInt32 xintIndex,
00049         UnsignedInt32 xintBCSetID, UnsignedInt32 xintBCSetUniqueID,
00050         UnsignedInt32 xintBCSetAnalysisType, UnsignedInt32 xintRestraintTypesCount,
00051         UnsignedInt32 xintLoadTypesCount, UnsignedInt32 xintContactPairTypesCount,
00052         SBCSetData* xpaBCSetRestraintData, SBCSetData* xpaBCSetLoadData,
00053         SBCSetData* xpaBCSetContactPairData);
00054     void WriteMaterial(UnsignedInt32 xintIndex,
00055         UnsignedInt32 xintMaterialID, UnsignedInt32 xintMaterialUniqueID,
00056         UnsignedInt32 xintPropertiesCount, SMaterialData* xpaMaterialData);
00057     void WriteConstraint(UnsignedInt32 xintIndex,
00058         UnsignedInt32 xintConstraintID, UnsignedInt32 xintConstraintUniqueID,
00059         UnsignedInt32 xintConstraintType,
00060         UnsignedInt32 xintIndependentTypeCount, SConstraintData* xpaIndependentData,
00061         UnsignedInt32 xintDependentTypeCount, SConstraintData* xpaDependentData);
00062     UnsignedInt32 EndWrite();
00063     
00064     void InitRead(FILE* xpFile, UnsignedInt32& xintAbsoluteOffset,
00065         UnsignedInt32& xintBCCount, UnsignedInt32& xintICCount,
00066         UnsignedInt32& xintBCSetCount, UnsignedInt32& xintMaterialCount,
00067         UnsignedInt32& xintAmplitudeCount, UnsignedInt32& xintConstraintCount);
00068     void ReadBCSet(UnsignedInt32 xintIndex,
00069         UnsignedInt32& xintBCSetID, UnsignedInt32& xintBCSetUniqueID,
00070         UnsignedInt32& xintBCSetAnalysisType, UnsignedInt32& xintRestraintTypesCount,
00071         UnsignedInt32& xintLoadTypesCount, UnsignedInt32& xintContactPairTypesCount,
00072         SBCSetData*& xpaBCSetRestraintData, SBCSetData*& xpaBCSetLoadData,
00073         SBCSetData*& xpaBCSetContactPairData);
00074     void ReadMaterial(UnsignedInt32 xintIndex,
00075         UnsignedInt32& xintMaterialID, UnsignedInt32& xintMaterialUniqueID,
00076         UnsignedInt32& xintPropertiesCount, SMaterialData*& xpaMaterialData);
00077     void ReadConstraint(UnsignedInt32 xintIndex,
00078         UnsignedInt32& xintConstraintID, UnsignedInt32& xintConstraintUniqueID,
00079         UnsignedInt32& xintConstraintType,
00080         UnsignedInt32& xintIndependentTypeCount, SConstraintData*& xpaIndependentData,
00081         UnsignedInt32& xintDependentTypeCount, SConstraintData*& xpaDependentData);
00082     void EndRead();
00083     
00084     CMetaData& GetBCMetaData();
00085     CMetaData& GetICMetaData();
00086     CMetaData& GetBCSetMetaData();
00087     CMetaData& GetMaterialMetaData();
00088     CMetaData& GetAmplitudeMetaData();
00089     CMetaData& GetConstraintMetaData();
00090     
00091 private:
00092     FILE* mpReadFile;
00093     FILE* mpWriteFile;
00094     UnsignedInt32 mintSimModelOffset;
00095     CMetaData mBCMetaData;
00096     CMetaData mICMetaData;
00097     CMetaData mBCSetMetaData;
00098     CMetaData mMaterialMetaData;
00099     CMetaData mAmplitudeMetaData;
00100     CMetaData mConstraintMetaData;
00101 
00102     // Data storage structures:
00103     // CAUTION: These structures must be 64 bit word aligned!!!
00104     struct SCubitFileSimModelHeader {
00105         UnsignedInt32 mintSimModelEndian;
00106         UnsignedInt32 mintSimModelSchema;
00107         UnsignedInt32 mintSimModelCompress;
00108         UnsignedInt32 mintSimModelLength;
00109         UnsignedInt32 mintBCCount;
00110         UnsignedInt32 mintBCTableOffset;
00111         UnsignedInt32 mintBCMetaDataOffset;
00112         UnsignedInt32 mintICCount;
00113         UnsignedInt32 mintICTableOffset;
00114         UnsignedInt32 mintICMetaDataOffset;
00115         UnsignedInt32 mintBCSetCount;
00116         UnsignedInt32 mintBCSetTableOffset;
00117         UnsignedInt32 mintBCSetMetaDataOffset;
00118         UnsignedInt32 mintMaterialCount;
00119         UnsignedInt32 mintMaterialTableOffset;
00120         UnsignedInt32 mintMaterialMetaDataOffset;
00121         UnsignedInt32 mintAmplitudeCount;
00122         UnsignedInt32 mintAmplitudeTableOffset;
00123         UnsignedInt32 mintAmplitudeMetaDataOffset;
00124         UnsignedInt32 mintFutureTableOffset; // for forwards compatibility
00125         //UnsignedInt32 mintPadFor64bitOS; // only if odd number of items in struct
00126     } mSimModel;
00127     static const UnsignedInt32 mintSizeOfSimModelHeader;
00128     //
00129     // Continuation from previous table
00130     // CAUTION: These structures must be 64 bit word aligned!!!
00131     struct SCubitFileSimModelHeader2 {
00132         UnsignedInt32 mintConstraintCount;
00133         UnsignedInt32 mintConstraintTableOffset;
00134         UnsignedInt32 mintConstraintMetaDataOffset;
00135         UnsignedInt32 mintFutureTableOffset; // for forwards compatibility
00136         //UnsignedInt32 mintPadFor64bitOS; // only if odd number of items in struct
00137     } mSimModel2;
00138     static const UnsignedInt32 mintSizeOfSimModelHeader2;
00139 
00140     struct SCubitFileBCSetEntry {
00141         UnsignedInt32 mintBCSetID;
00142         UnsignedInt32 mintBCSetUniqueID;
00143         UnsignedInt32 mintBCSetAnalysisType;
00144         UnsignedInt32 mintRestraintTypesCount;
00145         UnsignedInt32 mintRestraintMembersCount;
00146         UnsignedInt32 mintRestraintsOffset;
00147         UnsignedInt32 mintLoadTypesCount;
00148         UnsignedInt32 mintLoadMembersCount;
00149         UnsignedInt32 mintLoadsOffset;
00150         UnsignedInt32 mintContactPairTypesCount;
00151         UnsignedInt32 mintContactPairMembersCount;
00152         UnsignedInt32 mintContactPairsOffset;
00153         UnsignedInt32 mintBCSetLength;
00154         UnsignedInt32 mintPadFor64bitOS;
00155     } *mpaBCSets;
00156     static const UnsignedInt32 mintSizeOfBCSetEntry;
00157 
00158     struct SCubitFileMaterialEntry {
00159         UnsignedInt32 mintMaterialID;
00160         UnsignedInt32 mintMaterialUniqueID;
00161         UnsignedInt32 mintMaterialPropertiesOffset;
00162         UnsignedInt32 mintMaterialPropertiesCount;
00163         UnsignedInt32 mintPropertyDataCount; // total num of all property data
00164         UnsignedInt32 mintMaterialLength;
00165     } *mpaMaterials;
00166     static const UnsignedInt32 mintSizeOfMaterialEntry;
00167 
00168     struct SCubitFileConstraintEntry {
00169         UnsignedInt32 mintConstraintID;
00170         UnsignedInt32 mintConstraintUniqueID;
00171         UnsignedInt32 mintConstraintType;
00172         UnsignedInt32 mintIndependentTypeCount; // usually 1 independent node/vertex
00173         UnsignedInt32 mintIndependentDataOffset;
00174         UnsignedInt32 mintDependentTypeCount;
00175         UnsignedInt32 mintDependentDataOffset;
00176         UnsignedInt32 mintConstraintLength;
00177         //UnsignedInt32 mintPadFor64bitOS;
00178     } *mpaConstraints;
00179     static const UnsignedInt32 mintSizeOfConstraintEntry;
00180 
00181     // These structs aren't used yet (12.1), can modify them until they are first used.
00182     // Then, they must be locked in.
00183     struct SCubitFileBCEntry {
00184         UnsignedInt32 mintBCID;
00185         UnsignedInt32 mintBCUniqueID;
00186         UnsignedInt32 mintBCType;
00187         UnsignedInt32 mintDataLength;
00188         UnsignedInt32 mintDataOffset;
00189         UnsignedInt32 mintBCLength;
00190         //UnsignedInt32 mintPadFor64bitOS;
00191     } *mpaBCs;
00192     static const UnsignedInt32 mintSizeOfBCEntry;
00193 
00194     struct SCubitFileICEntry {
00195         UnsignedInt32 mintICID;
00196         UnsignedInt32 mintICUniqueID;
00197         UnsignedInt32 mintICType;
00198         UnsignedInt32 mintDataLength;
00199         UnsignedInt32 mintDataOffset;
00200         UnsignedInt32 mintICCLength;
00201         //UnsignedInt32 mintPadFor64bitOS;
00202     } *mpaICs;
00203     static const UnsignedInt32 mintSizeOfICEntry;
00204 
00205     struct SCubitFileAmplitudeEntry {
00206         UnsignedInt32 mintAmplitudeID;
00207         UnsignedInt32 mintAmplitudeUniqueID;
00208         UnsignedInt32 mintDataLength;
00209         UnsignedInt32 mintDataOffset;
00210         UnsignedInt32 mintAmplitudeLength;
00211         UnsignedInt32 mintPadFor64bitOS;
00212     } *mpaAmplitudes;
00213     static const UnsignedInt32 mintSizeOfAmplitudeEntry;
00214     
00215     // Buffers for read operations.
00216     struct SBCSetReturnBuffer {
00217         //restraints
00218         UnsignedInt32 mintNumRestraintTypes;
00219         UnsignedInt32 mintNumRestraintMembers;
00220         SBCSetData* mpaBCSetRestraintData;
00221         UnsignedInt32* mpaintRestraintMemberIDs;
00222         //loads
00223         UnsignedInt32 mintNumLoadTypes;
00224         UnsignedInt32 mintNumLoadMembers;
00225         SBCSetData* mpaBCSetLoadData;
00226         UnsignedInt32* mpaintLoadMemberIDs;
00227         //contact pairs
00228         UnsignedInt32 mintNumContactPairTypes;
00229         UnsignedInt32 mintNumContactPairMembers;
00230         SBCSetData* mpaBCSetContactPairData;
00231         UnsignedInt32* mpaintContactPairMemberIDs;
00232     } mBCSetBuff;
00233 
00234     struct SMaterialReturnBuffer {
00235         UnsignedInt32 mintNumDataTypes;
00236         UnsignedInt32 mintNumDataMembers; //i.e. current size of buffer
00237         SMaterialData* mpaMaterialData;
00238         double* mpadblData;
00239     } mMaterialBuff;
00240 
00241     struct SConstraintReturnBuffer {
00242         UnsignedInt32 mintNumIndependentTypes;
00243         UnsignedInt32 mintNumIndependentMembers;
00244         SConstraintData* mpaIndependentData;
00245         UnsignedInt32* mpaintIndependentIDs;
00246         //--
00247         UnsignedInt32 mintNumDependentTypes;
00248         UnsignedInt32 mintNumDependentMembers;
00249         SConstraintData* mpaDependentData;
00250         UnsignedInt32* mpaintDependentIDs;
00251     } mConstraintBuff;
00252 
00253 
00254     template <class TBuffer>
00255     TBuffer* AdjustBuffer(UnsignedInt32 xintRequiredSize,
00256         UnsignedInt32& xintActualSize, TBuffer*& xpaBuffer)
00257     {
00258         if(!xintRequiredSize)  return NULL;  // Nothing requested, return nothing.
00259 
00260         if(xintActualSize < xintRequiredSize) {
00261             if(xpaBuffer)
00262                 delete [] xpaBuffer;
00263             xintActualSize = xintRequiredSize;
00264             xpaBuffer = new TBuffer[xintActualSize];
00265             if(!xpaBuffer) {
00266                 xintActualSize = 0;
00267                 throw CCubitFile::eMemoryError;
00268             }
00269         }
00270         return xpaBuffer;
00271     }
00272 };
00273 
00274 } // namespace NCubitFile
00275 
00276 #endif
00277 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines