cgma
CubitFileSimModel.cpp
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      : CubitFileSimModel.cpp
00016 
00017  Purpose       : Implements the reading and writing functionality for a Simulation
00018                  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 #include "CubitFileSimModel.hpp"
00031 #include "CubitFileIOWrapper.hpp"
00032 #include "CCubitFile.hpp"
00033 
00034 using namespace NCubitFile;
00035 
00037 // CSimModel
00039 
00040 // The number of 32 bit words contained int each of the stored structures.
00041 const UnsignedInt32 CSimModel::mintSizeOfSimModelHeader =
00042     sizeof(SCubitFileSimModelHeader) / sizeof(UnsignedInt32);
00043 const UnsignedInt32 CSimModel::mintSizeOfSimModelHeader2 =
00044     sizeof(SCubitFileSimModelHeader2) / sizeof(UnsignedInt32);
00045 const UnsignedInt32 CSimModel::mintSizeOfBCEntry =
00046     sizeof(SCubitFileBCEntry) / sizeof(UnsignedInt32);
00047 const UnsignedInt32 CSimModel::mintSizeOfICEntry =
00048     sizeof(SCubitFileICEntry) / sizeof(UnsignedInt32);
00049 const UnsignedInt32 CSimModel::mintSizeOfBCSetEntry =
00050     sizeof(SCubitFileBCSetEntry) / sizeof(UnsignedInt32);
00051 const UnsignedInt32 CSimModel::mintSizeOfMaterialEntry =
00052     sizeof(SCubitFileMaterialEntry) / sizeof(UnsignedInt32);
00053 const UnsignedInt32 CSimModel::mintSizeOfAmplitudeEntry =
00054     sizeof(SCubitFileAmplitudeEntry) / sizeof(UnsignedInt32);
00055 const UnsignedInt32 CSimModel::mintSizeOfConstraintEntry =
00056     sizeof(SCubitFileConstraintEntry) / sizeof(UnsignedInt32);
00057 
00058 CSimModel::CSimModel()
00059 {
00060     mpReadFile = mpWriteFile = NULL;
00061     mpaBCs = NULL;
00062     mpaICs = NULL;
00063     mpaBCSets = NULL;
00064     mpaMaterials = NULL;
00065     mpaAmplitudes = NULL;
00066     mpaConstraints = NULL;
00067 
00068     mintSimModelOffset = 0;
00069 
00070     memset(&mSimModel, 0, sizeof(SCubitFileSimModelHeader));
00071     mSimModel.mintSimModelEndian = CCubitFile::mintNativeEndian;
00072 
00073     memset(&mSimModel2, 0, sizeof(SCubitFileSimModelHeader2));
00074 
00075     memset(&mBCSetBuff, 0, sizeof(SBCSetReturnBuffer));
00076     memset(&mMaterialBuff, 0, sizeof(SMaterialReturnBuffer));
00077     memset(&mConstraintBuff, 0, sizeof(SConstraintReturnBuffer));
00078 
00079 }
00080 
00081 CSimModel::~CSimModel()
00082 {
00083     if(mpaBCs)
00084         delete [] mpaBCs;
00085     if(mpaICs)
00086         delete [] mpaICs;
00087     if(mpaBCSets)
00088         delete [] mpaBCSets;
00089     if(mpaMaterials)
00090         delete [] mpaMaterials;
00091     if(mpaAmplitudes)
00092         delete [] mpaAmplitudes;
00093     if(mpaConstraints)
00094         delete [] mpaConstraints;
00095 
00096     if(mBCSetBuff.mpaBCSetRestraintData)
00097         delete [] mBCSetBuff.mpaBCSetRestraintData;
00098     if(mBCSetBuff.mpaintRestraintMemberIDs)
00099         delete [] mBCSetBuff.mpaintRestraintMemberIDs;
00100 
00101     if(mBCSetBuff.mpaBCSetLoadData)
00102         delete [] mBCSetBuff.mpaBCSetLoadData;
00103     if(mBCSetBuff.mpaintLoadMemberIDs)
00104         delete [] mBCSetBuff.mpaintLoadMemberIDs;
00105 
00106     if(mBCSetBuff.mpaBCSetContactPairData)
00107         delete [] mBCSetBuff.mpaBCSetContactPairData;
00108     if(mBCSetBuff.mpaintContactPairMemberIDs)
00109         delete [] mBCSetBuff.mpaintContactPairMemberIDs;
00110 
00111     if(mMaterialBuff.mpaMaterialData)
00112         delete [] mMaterialBuff.mpaMaterialData;
00113     if(mMaterialBuff.mpadblData)
00114         delete [] mMaterialBuff.mpadblData;
00115     
00116     if(mConstraintBuff.mpaintIndependentIDs)
00117         delete [] mConstraintBuff.mpaintIndependentIDs;
00118     if(mConstraintBuff.mpaintDependentIDs)
00119         delete [] mConstraintBuff.mpaintDependentIDs;
00120     if(mConstraintBuff.mpaIndependentData)
00121         delete [] mConstraintBuff.mpaIndependentData;
00122     if(mConstraintBuff.mpaDependentData)
00123         delete [] mConstraintBuff.mpaDependentData;
00124 
00125 }
00126 
00127 
00129 // Write Functions
00131 
00132 UnsignedInt32 CSimModel::InitWrite(FILE* xpFile,
00133                                    UnsignedInt32 xintBCCount,
00134                                    UnsignedInt32 xintICCount,
00135                                    UnsignedInt32 xintBCSetCount,
00136                                    UnsignedInt32 xintMaterialCount,
00137                                    UnsignedInt32 xintAmplitudeCount,
00138                                    UnsignedInt32 xintConstraintCount)
00139 {
00140     if(mpWriteFile)  throw CCubitFile::eFileWriteError;
00141 
00142     mpWriteFile = xpFile;
00143     CIOWrapper lIO(mpWriteFile);
00144 
00145     // Write out the Sim model header to reserve its position and size in the
00146     // file.
00147     mintSimModelOffset = lIO.BeginWriteBlock();
00148     lIO.Write((UnsignedInt32*)&mSimModel, mintSizeOfSimModelHeader);
00149     mSimModel.mintSimModelLength = lIO.EndWriteBlock();
00150 
00151     mSimModel.mintFutureTableOffset = lIO.BeginWriteBlock(mintSimModelOffset);
00152     lIO.Write((UnsignedInt32*)&mSimModel2, mintSizeOfSimModelHeader2);
00153     mSimModel.mintSimModelLength += lIO.EndWriteBlock();
00154 
00155     mSimModel.mintBCCount = xintBCCount;
00156     if(xintBCCount) {
00157         // Create a geometry entity array for storing ownership statistics and
00158         // initially blank it.
00159         mpaBCs = new SCubitFileBCEntry[xintBCCount];
00160         memset(mpaBCs, 0, sizeof(SCubitFileBCEntry) * xintBCCount);
00161 
00162         // Write the blank geometry table to the file to reserve its position
00163         // and size in the file.
00164         mSimModel.mintBCTableOffset = lIO.BeginWriteBlock(mintSimModelOffset);
00165         lIO.Write((UnsignedInt32*)mpaBCs,
00166             xintBCCount * mintSizeOfBCEntry);
00167         mSimModel.mintSimModelLength += lIO.EndWriteBlock();
00168     }
00169 
00170     mSimModel.mintICCount = xintICCount;
00171     if(xintICCount) {
00172         // Create a group array for storing ownership statistics and
00173         // initially blank it.
00174         mpaICs = new SCubitFileICEntry[xintICCount];
00175         memset(mpaICs, 0, sizeof(SCubitFileICEntry) * xintICCount);
00176 
00177         // Write the blank group table to the file to reserve its position
00178         // and size in the file.
00179         mSimModel.mintICTableOffset = lIO.BeginWriteBlock(mintSimModelOffset);
00180         lIO.Write((UnsignedInt32*)mpaICs,
00181             xintICCount * mintSizeOfICEntry);
00182         mSimModel.mintSimModelLength += lIO.EndWriteBlock();
00183     }
00184 
00185     mSimModel.mintBCSetCount = xintBCSetCount;
00186     if(xintBCSetCount) {
00187         // Create a block array for storing ownership statistics and
00188         // initially blank it.
00189         mpaBCSets = new SCubitFileBCSetEntry[xintBCSetCount];
00190         memset(mpaBCSets, 0, sizeof(SCubitFileBCSetEntry) * xintBCSetCount);
00191 
00192         // Write the blank block table to the file to reserve its position
00193         // and size in the file.
00194         mSimModel.mintBCSetTableOffset = lIO.BeginWriteBlock(mintSimModelOffset);
00195         lIO.Write((UnsignedInt32*)mpaBCSets,
00196             xintBCSetCount * mintSizeOfBCSetEntry);
00197         mSimModel.mintSimModelLength += lIO.EndWriteBlock();
00198     }
00199 
00200     mSimModel.mintMaterialCount = xintMaterialCount;
00201     if(xintMaterialCount) {
00202         // Create a node set array for storing ownership statistics and
00203         // initially blank it.
00204         mpaMaterials = new SCubitFileMaterialEntry[xintMaterialCount];
00205         memset(mpaMaterials, 0, sizeof(SCubitFileMaterialEntry) * xintMaterialCount);
00206 
00207         // Write the blank geometry table to the file to reserve its position
00208         // and size in the file.
00209         mSimModel.mintMaterialTableOffset = lIO.BeginWriteBlock(mintSimModelOffset);
00210         lIO.Write((UnsignedInt32*)mpaMaterials,
00211             xintMaterialCount * mintSizeOfMaterialEntry);
00212         mSimModel.mintSimModelLength += lIO.EndWriteBlock();
00213     }
00214 
00215     mSimModel.mintAmplitudeCount = xintAmplitudeCount;
00216     if(xintAmplitudeCount) {
00217         // Create a SideSet array for storing ownership statistics and
00218         // initially blank it.
00219         mpaAmplitudes = new SCubitFileAmplitudeEntry[xintAmplitudeCount];
00220         memset(mpaAmplitudes, 0, sizeof(SCubitFileAmplitudeEntry) * xintAmplitudeCount);
00221 
00222         // Write the blank geometry table to the file to reserve its position
00223         // and size in the file.
00224         mSimModel.mintAmplitudeTableOffset = lIO.BeginWriteBlock(mintSimModelOffset);
00225         lIO.Write((UnsignedInt32*)mpaAmplitudes,
00226             xintAmplitudeCount * mintSizeOfAmplitudeEntry);
00227         mSimModel.mintSimModelLength += lIO.EndWriteBlock();
00228     }
00229 
00230     mSimModel2.mintConstraintCount = xintConstraintCount;
00231     if(xintConstraintCount) {
00232         // Create a SideSet array for storing ownership statistics and
00233         // initially blank it.
00234         mpaConstraints = new SCubitFileConstraintEntry[xintConstraintCount];
00235         memset(mpaConstraints, 0, sizeof(SCubitFileConstraintEntry) * xintConstraintCount);
00236 
00237         // Write the blank geometry table to the file to reserve its position
00238         // and size in the file.
00239         mSimModel2.mintConstraintTableOffset = lIO.BeginWriteBlock(mintSimModelOffset);
00240         lIO.Write((UnsignedInt32*)mpaConstraints,
00241             xintConstraintCount * mintSizeOfConstraintEntry);
00242         mSimModel.mintSimModelLength += lIO.EndWriteBlock();
00243     }
00244 
00245     return mintSimModelOffset;
00246 }
00247 
00248 void CSimModel::WriteBCSet(UnsignedInt32 xintIndex,
00249                           UnsignedInt32 xintBCSetID,
00250                           UnsignedInt32 xintBCSetUniqueID,
00251                           UnsignedInt32 xintBCSetAnalysisType,
00252                           UnsignedInt32 xintRestraintTypesCount,
00253                           UnsignedInt32 xintLoadTypesCount,
00254                           UnsignedInt32 xintContactPairTypesCount,
00255                           SBCSetData* xpaBCSetRestraintData,
00256                           SBCSetData* xpaBCSetLoadData,
00257                           SBCSetData* xpaBCSetContactPairData)
00258 {
00259     if(!mpWriteFile)
00260         throw CCubitFile::eFileWriteError;
00261     if(xintIndex >= mSimModel.mintBCSetCount)
00262         throw CCubitFile::eNotFound;
00263     if(!mpaBCSets)
00264         throw CCubitFile::eOrderError;
00265     if(mpaBCSets[xintIndex].mintBCSetLength) // something that won't be zero
00266         throw CCubitFile::eDuplicateWrite;
00267 
00268     if(xintRestraintTypesCount)
00269     {  
00270         // An empty bcset is valid, but an incompletely defined one is not.
00271         if(!xpaBCSetRestraintData)
00272             throw CCubitFile::ePassedNullPointer;
00273         for(UnsignedInt32 lintRestraints = 0; lintRestraints < xintRestraintTypesCount; lintRestraints++) {
00274             if(xpaBCSetRestraintData[lintRestraints].mintMemberCount &&
00275                 !xpaBCSetRestraintData[lintRestraints].mpaMemberIDs)
00276                 throw CCubitFile::ePassedNullPointer;
00277         }
00278     }
00279     if(xintLoadTypesCount)
00280     {  
00281         // An empty bcset is valid, but an incompletely defined one is not.
00282         if(!xpaBCSetRestraintData)
00283             throw CCubitFile::ePassedNullPointer;
00284         for(UnsignedInt32 lintLoads = 0; lintLoads < xintLoadTypesCount; lintLoads++) {
00285             if(xpaBCSetLoadData[lintLoads].mintMemberCount &&
00286                 !xpaBCSetLoadData[lintLoads].mpaMemberIDs)
00287                 throw CCubitFile::ePassedNullPointer;
00288         }
00289     }
00290     if(xintContactPairTypesCount)
00291     {  
00292         // An empty bcset is valid, but an incompletely defined one is not.
00293         if(!xpaBCSetContactPairData)
00294             throw CCubitFile::ePassedNullPointer;
00295         for(UnsignedInt32 lintContactPairs = 0; lintContactPairs < xintContactPairTypesCount; lintContactPairs++) {
00296             if(xpaBCSetContactPairData[lintContactPairs].mintMemberCount &&
00297                 !xpaBCSetContactPairData[lintContactPairs].mpaMemberIDs)
00298                 throw CCubitFile::ePassedNullPointer;
00299         }
00300     }
00301 
00302     // BCSet header written out elsewhere.  Here, just populate the header struct
00303     mpaBCSets[xintIndex].mintBCSetID = xintBCSetID;
00304     mpaBCSets[xintIndex].mintBCSetUniqueID = xintBCSetUniqueID;
00305     mpaBCSets[xintIndex].mintBCSetAnalysisType = xintBCSetAnalysisType;
00306     mpaBCSets[xintIndex].mintRestraintTypesCount = xintRestraintTypesCount;
00307     mpaBCSets[xintIndex].mintLoadTypesCount = xintLoadTypesCount;
00308     mpaBCSets[xintIndex].mintContactPairTypesCount = xintContactPairTypesCount;
00309     
00310     CIOWrapper* lpIO = new CIOWrapper(mpWriteFile);
00311 
00312     // write restraints
00313     if(xintRestraintTypesCount)
00314     {        
00315         mpaBCSets[xintIndex].mintRestraintsOffset =
00316             lpIO->BeginWriteBlock(mintSimModelOffset);
00317 
00318         for(UnsignedInt32 lintBCSet = 0; lintBCSet < xintRestraintTypesCount; lintBCSet++)
00319         {
00320             if(!xpaBCSetRestraintData[lintBCSet].mintMemberCount)
00321             {
00322                 mpaBCSets[xintIndex].mintRestraintTypesCount--;
00323                 continue;
00324             }
00325             mpaBCSets[xintIndex].mintRestraintMembersCount +=
00326                 xpaBCSetRestraintData[lintBCSet].mintMemberCount;
00327             
00328             lpIO->Write(&xpaBCSetRestraintData[lintBCSet].mintMemberType, 1);
00329             lpIO->Write(&xpaBCSetRestraintData[lintBCSet].mintMemberCount, 1);
00330             lpIO->Write(xpaBCSetRestraintData[lintBCSet].mpaMemberIDs,
00331                 xpaBCSetRestraintData[lintBCSet].mintMemberCount);
00332         }
00333 
00334         mpaBCSets[xintIndex].mintBCSetLength += lpIO->EndWriteBlock();
00335     }
00336     else
00337     {
00338         // BCSet has no restraints in the file.
00339         mpaBCSets[xintIndex].mintRestraintsOffset = 0;
00340     }
00341 
00342     //write loads
00343     if(xintLoadTypesCount)
00344     {        
00345         mpaBCSets[xintIndex].mintLoadsOffset =
00346             lpIO->BeginWriteBlock(mintSimModelOffset);
00347 
00348         for(UnsignedInt32 lintBCSet = 0; lintBCSet < xintLoadTypesCount; lintBCSet++)
00349         {
00350             if(!xpaBCSetLoadData[lintBCSet].mintMemberCount)
00351             {
00352                 mpaBCSets[xintIndex].mintLoadTypesCount--;
00353                 continue;
00354             }
00355             mpaBCSets[xintIndex].mintLoadMembersCount +=
00356                 xpaBCSetLoadData[lintBCSet].mintMemberCount;
00357             
00358             lpIO->Write(&xpaBCSetLoadData[lintBCSet].mintMemberType, 1);
00359             lpIO->Write(&xpaBCSetLoadData[lintBCSet].mintMemberCount, 1);
00360             lpIO->Write(xpaBCSetLoadData[lintBCSet].mpaMemberIDs,
00361                 xpaBCSetLoadData[lintBCSet].mintMemberCount);
00362         }
00363 
00364         mpaBCSets[xintIndex].mintBCSetLength += lpIO->EndWriteBlock();
00365     }
00366     else
00367     {
00368         // BCSet has no Loads in the file.
00369         mpaBCSets[xintIndex].mintLoadsOffset = 0;
00370     }
00371 
00372     // write contact pairs
00373     if(xintContactPairTypesCount)
00374     {        
00375         mpaBCSets[xintIndex].mintContactPairsOffset =
00376             lpIO->BeginWriteBlock(mintSimModelOffset);
00377 
00378         for(UnsignedInt32 lintBCSet = 0; lintBCSet < xintContactPairTypesCount; lintBCSet++)
00379         {
00380             if(!xpaBCSetContactPairData[lintBCSet].mintMemberCount)
00381             {
00382                 mpaBCSets[xintIndex].mintContactPairTypesCount--;
00383                 continue;
00384             }
00385             mpaBCSets[xintIndex].mintContactPairMembersCount +=
00386                 xpaBCSetContactPairData[lintBCSet].mintMemberCount;
00387             
00388             lpIO->Write(&xpaBCSetContactPairData[lintBCSet].mintMemberType, 1);
00389             lpIO->Write(&xpaBCSetContactPairData[lintBCSet].mintMemberCount, 1);
00390             lpIO->Write(xpaBCSetContactPairData[lintBCSet].mpaMemberIDs,
00391                 xpaBCSetContactPairData[lintBCSet].mintMemberCount);
00392         }
00393 
00394         mpaBCSets[xintIndex].mintBCSetLength += lpIO->EndWriteBlock();
00395         
00396     }
00397     else
00398     {
00399         // BCSet has no ContactPairs in the file.
00400         mpaBCSets[xintIndex].mintContactPairsOffset = 0;
00401     }
00402     
00403     mSimModel.mintSimModelLength += mpaBCSets[xintIndex].mintBCSetLength;
00404     delete lpIO;
00405 }
00406 
00407 void CSimModel::WriteMaterial(UnsignedInt32 xintIndex,
00408                               UnsignedInt32 xintMaterialID,
00409                               UnsignedInt32 xintMaterialUniqueID,
00410                               UnsignedInt32 xintPropertiesCount,
00411                               SMaterialData* xpaMaterialData)
00412 {
00413     if(!mpWriteFile)
00414         throw CCubitFile::eFileWriteError;
00415     if(xintIndex >= mSimModel.mintMaterialCount)
00416         throw CCubitFile::eNotFound;
00417     if(!mpaBCSets)
00418         throw CCubitFile::eOrderError;
00419     if(mpaMaterials[xintIndex].mintMaterialLength) // something that won't be zero
00420         throw CCubitFile::eDuplicateWrite;
00421 
00422     if(xintPropertiesCount)
00423     {  
00424         // An empty material is valid, but an incompletely defined one is not.
00425         if(!xpaMaterialData)
00426             throw CCubitFile::ePassedNullPointer;
00427         for(UnsignedInt32 lintMaterialData = 0; lintMaterialData < xintPropertiesCount; lintMaterialData++) {
00428             if(xpaMaterialData[lintMaterialData].mintMemberRows &&
00429                 !xpaMaterialData[lintMaterialData].mpadblMemberData)
00430                 throw CCubitFile::ePassedNullPointer;
00431         }
00432     }
00433 
00434     // Material header written out elsewhere.  Here, just populate the header struct
00435     mpaMaterials[xintIndex].mintMaterialID = xintMaterialID;
00436     mpaMaterials[xintIndex].mintMaterialUniqueID = xintMaterialUniqueID;
00437     mpaMaterials[xintIndex].mintMaterialPropertiesCount = xintPropertiesCount;
00438     
00439     CIOWrapper* lpIO = new CIOWrapper(mpWriteFile);
00440 
00441     // write material data
00442     if(xintPropertiesCount)
00443     {        
00444         mpaMaterials[xintIndex].mintMaterialPropertiesOffset =
00445             lpIO->BeginWriteBlock(mintSimModelOffset);
00446 
00447         for(UnsignedInt32 lintMaterial = 0; lintMaterial < xintPropertiesCount; lintMaterial++)
00448         {
00449             if(!xpaMaterialData[lintMaterial].mintMemberRows)
00450             {
00451                 mpaMaterials[xintIndex].mintMaterialPropertiesCount--;
00452                 continue;
00453             }
00454              mpaMaterials[xintIndex].mintPropertyDataCount +=
00455                 (xpaMaterialData[lintMaterial].mintMemberRows *
00456                  xpaMaterialData[lintMaterial].mintMemberColumns);
00457             
00458             lpIO->Write(&xpaMaterialData[lintMaterial].mintMemberType, 1);
00459             lpIO->Write(&xpaMaterialData[lintMaterial].mintMemberRows, 1);
00460             lpIO->Write(&xpaMaterialData[lintMaterial].mintMemberColumns, 1);
00461             lpIO->Write(xpaMaterialData[lintMaterial].mpadblMemberData,
00462                         xpaMaterialData[lintMaterial].mintMemberRows *
00463                             xpaMaterialData[lintMaterial].mintMemberColumns);
00464             
00465         }
00466 
00467         mpaMaterials[xintIndex].mintMaterialLength += lpIO->EndWriteBlock();
00468     }
00469     else
00470     {
00471         // Material has no data in the file.
00472         mpaMaterials[xintIndex].mintMaterialPropertiesOffset = 0;
00473     }
00474     
00475     mSimModel.mintSimModelLength += mpaMaterials[xintIndex].mintMaterialLength;
00476     delete lpIO;
00477 }
00478 
00479 void CSimModel::WriteConstraint(UnsignedInt32 xintIndex,
00480         UnsignedInt32 xintConstraintID, UnsignedInt32 xintConstraintUniqueID,
00481         UnsignedInt32 xintConstraintType,
00482         UnsignedInt32 xintIndependentTypeCount, SConstraintData* xpaIndependentData,
00483         UnsignedInt32 xintDependentTypeCount, SConstraintData* xpaDependentData)
00484 {
00485     if(!mpWriteFile)
00486         throw CCubitFile::eFileWriteError;
00487     if(xintIndex >= mSimModel2.mintConstraintCount)
00488         throw CCubitFile::eNotFound;
00489     if(!mpaBCSets)
00490         throw CCubitFile::eOrderError;
00491     if(mpaConstraints[xintIndex].mintConstraintLength) // something that won't be zero
00492         throw CCubitFile::eDuplicateWrite;
00493 
00494     if(xintDependentTypeCount)
00495     {  
00496         // An empty Constraint is valid, but an incompletely defined one is not.
00497         if(!xpaDependentData)
00498             throw CCubitFile::ePassedNullPointer;
00499         for(int lintConstraintData = 0; lintConstraintData < (int)xintDependentTypeCount; lintConstraintData++) {
00500             if(xpaDependentData[lintConstraintData].mintMemberCount &&
00501                 !xpaDependentData[lintConstraintData].mpaMemberIDs)
00502                 throw CCubitFile::ePassedNullPointer;
00503         }
00504     }
00505     if(xintIndependentTypeCount)
00506     {  
00507         // An empty Constraint is valid, but an incompletely defined one is not.
00508         if(!xpaIndependentData)
00509             throw CCubitFile::ePassedNullPointer;
00510         for(int lintConstraintData = 0; lintConstraintData < (int)xintIndependentTypeCount; lintConstraintData++) {
00511             if(xpaIndependentData[lintConstraintData].mintMemberCount &&
00512                 !xpaIndependentData[lintConstraintData].mpaMemberIDs)
00513                 throw CCubitFile::ePassedNullPointer;
00514         }
00515     }
00516 
00517     // Constraint header written out elsewhere.  Here, just populate the header struct
00518     mpaConstraints[xintIndex].mintConstraintID = xintConstraintID;
00519     mpaConstraints[xintIndex].mintConstraintUniqueID = xintConstraintUniqueID;
00520     mpaConstraints[xintIndex].mintConstraintType = xintConstraintType;
00521     mpaConstraints[xintIndex].mintIndependentTypeCount = xintIndependentTypeCount;
00522     mpaConstraints[xintIndex].mintDependentTypeCount = xintDependentTypeCount;
00523     
00524     CIOWrapper* lpIO = new CIOWrapper(mpWriteFile);
00525 
00526     // write Independent Constraint data
00527     if(xintIndependentTypeCount)
00528     {        
00529         mpaConstraints[xintIndex].mintIndependentDataOffset =
00530             lpIO->BeginWriteBlock(mintSimModelOffset);
00531 
00532         for(int lintConstraint = 0; lintConstraint < (int)xintIndependentTypeCount; lintConstraint++)
00533         {
00534             if(!xpaIndependentData[lintConstraint].mintMemberCount)
00535             {
00536                 mpaConstraints[xintIndex].mintIndependentTypeCount--;
00537                 continue;
00538             }
00539 
00540             lpIO->Write(&xpaIndependentData[lintConstraint].mintMemberType, 1);
00541             lpIO->Write(&xpaIndependentData[lintConstraint].mintMemberCount, 1);
00542             lpIO->Write(xpaIndependentData[lintConstraint].mpaMemberIDs,
00543                         xpaIndependentData[lintConstraint].mintMemberCount);
00544         }
00545 
00546         mpaConstraints[xintIndex].mintConstraintLength += lpIO->EndWriteBlock();
00547     }
00548     else
00549     {
00550         // Constraint has no data in the file.
00551         mpaConstraints[xintIndex].mintIndependentDataOffset = 0;
00552     }
00553     
00554     // write Dependent Constraint data
00555     if(xintDependentTypeCount)
00556     {        
00557         mpaConstraints[xintIndex].mintDependentDataOffset =
00558             lpIO->BeginWriteBlock(mintSimModelOffset);
00559 
00560         for(int lintConstraint = 0; lintConstraint < (int)xintDependentTypeCount; lintConstraint++)
00561         {
00562             if(!xpaDependentData[lintConstraint].mintMemberCount)
00563             {
00564                 mpaConstraints[xintIndex].mintIndependentTypeCount--;
00565                 continue;
00566             }
00567 
00568             lpIO->Write(&xpaDependentData[lintConstraint].mintMemberType, 1);
00569             lpIO->Write(&xpaDependentData[lintConstraint].mintMemberCount, 1);
00570             lpIO->Write(xpaDependentData[lintConstraint].mpaMemberIDs,
00571                         xpaDependentData[lintConstraint].mintMemberCount);
00572         }
00573 
00574         mpaConstraints[xintIndex].mintConstraintLength += lpIO->EndWriteBlock();
00575     }
00576     else
00577     {
00578         // Constraint has no data in the file.
00579         mpaConstraints[xintIndex].mintDependentDataOffset = 0;
00580     }
00581     
00582     mSimModel.mintSimModelLength += mpaConstraints[xintIndex].mintConstraintLength;
00583 
00584     delete lpIO;
00585 }
00586 
00587 UnsignedInt32 CSimModel::EndWrite()
00588 {
00589     CIOWrapper lIO(mpWriteFile);
00590 
00591     if(mSimModel.mintBCCount) {
00592         lIO.BeginRewriteBlock(mintSimModelOffset, mSimModel.mintBCTableOffset);
00593         lIO.Write((UnsignedInt32*)mpaBCs,
00594             mSimModel.mintBCCount * mintSizeOfBCEntry);
00595         lIO.EndWriteBlock();
00596     }
00597 
00598     if(mSimModel.mintICCount) {
00599         lIO.BeginRewriteBlock(mintSimModelOffset, mSimModel.mintICTableOffset);
00600         lIO.Write((UnsignedInt32*)mpaICs,
00601             mSimModel.mintICCount * mintSizeOfICEntry);
00602         lIO.EndWriteBlock();
00603     }
00604 
00605     if(mSimModel.mintBCSetCount) {
00606         lIO.BeginRewriteBlock(mintSimModelOffset, mSimModel.mintBCSetTableOffset);
00607         lIO.Write((UnsignedInt32*)mpaBCSets,
00608             mSimModel.mintBCSetCount * mintSizeOfBCSetEntry);
00609         lIO.EndWriteBlock();
00610     }
00611 
00612     if(mSimModel.mintMaterialCount) {
00613         lIO.BeginRewriteBlock(mintSimModelOffset, mSimModel.mintMaterialTableOffset);
00614         lIO.Write((UnsignedInt32*)mpaMaterials,
00615             mSimModel.mintMaterialCount * mintSizeOfMaterialEntry);
00616         lIO.EndWriteBlock();
00617     }
00618 
00619     if(mSimModel.mintAmplitudeCount) {
00620         lIO.BeginRewriteBlock(mintSimModelOffset, mSimModel.mintAmplitudeTableOffset);
00621         lIO.Write((UnsignedInt32*)mpaAmplitudes,
00622             mSimModel.mintAmplitudeCount * mintSizeOfAmplitudeEntry);
00623         lIO.EndWriteBlock();
00624     }
00625 
00626     if(mSimModel2.mintConstraintCount) {
00627         lIO.BeginRewriteBlock(mintSimModelOffset, mSimModel2.mintConstraintTableOffset);
00628         lIO.Write((UnsignedInt32*)mpaConstraints,
00629             mSimModel2.mintConstraintCount * mintSizeOfConstraintEntry);
00630         lIO.EndWriteBlock();
00631     }
00632 
00633     UnsignedInt32 lintMetaDataLength;
00634     mBCMetaData.WriteMetaData(mpWriteFile, mSimModel.mintBCMetaDataOffset,
00635         lintMetaDataLength, mintSimModelOffset);
00636     mSimModel.mintSimModelLength += lintMetaDataLength;
00637     mICMetaData.WriteMetaData(mpWriteFile, mSimModel.mintICMetaDataOffset,
00638         lintMetaDataLength, mintSimModelOffset);
00639     mSimModel.mintSimModelLength += lintMetaDataLength;
00640     mBCSetMetaData.WriteMetaData(mpWriteFile, mSimModel.mintBCSetMetaDataOffset,
00641         lintMetaDataLength, mintSimModelOffset);
00642     mSimModel.mintSimModelLength += lintMetaDataLength;
00643     mMaterialMetaData.WriteMetaData(mpWriteFile, mSimModel.mintMaterialMetaDataOffset,
00644         lintMetaDataLength, mintSimModelOffset);
00645     mSimModel.mintSimModelLength += lintMetaDataLength;
00646     mAmplitudeMetaData.WriteMetaData(mpWriteFile, mSimModel.mintAmplitudeMetaDataOffset,
00647         lintMetaDataLength, mintSimModelOffset);
00648     mSimModel.mintSimModelLength += lintMetaDataLength;
00649     mConstraintMetaData.WriteMetaData(mpWriteFile, mSimModel2.mintConstraintMetaDataOffset,
00650         lintMetaDataLength, mintSimModelOffset);
00651     mSimModel.mintSimModelLength += lintMetaDataLength;
00652 
00653     lIO.BeginRewriteBlock(mintSimModelOffset, 0);
00654     lIO.Write((UnsignedInt32*)&mSimModel, mintSizeOfSimModelHeader);
00655     lIO.EndWriteBlock();
00656 
00657     lIO.BeginRewriteBlock(mintSimModelOffset, mSimModel.mintFutureTableOffset);
00658     lIO.Write((UnsignedInt32*)&mSimModel2, mintSizeOfSimModelHeader2);
00659     lIO.EndWriteBlock();
00660 
00661     mpWriteFile = NULL;
00662     return mSimModel.mintSimModelLength;
00663 }
00664 
00665 
00667 // Read Functions
00669 
00670 void CSimModel::InitRead(FILE* xpFile,
00671                          UnsignedInt32& xintAbsoluteOffset,
00672                          UnsignedInt32& xintBCCount,
00673                          UnsignedInt32& xintICCount,
00674                          UnsignedInt32& xintBCSetCount,
00675                          UnsignedInt32& xintMaterialCount,
00676                          UnsignedInt32& xintAmplitudeCount,
00677                          UnsignedInt32& xintConstraintCount)
00678 {
00679     if(mpReadFile)
00680         throw CCubitFile::eOrderError;
00681 
00682     mpReadFile = xpFile;
00683     mintSimModelOffset = xintAbsoluteOffset;
00684     CIOWrapper lIO(mpReadFile, xintAbsoluteOffset, 0);
00685 
00686     lIO.BeginReadBlock(mintSimModelOffset, 0);
00687     lIO.Read((UnsignedInt32*)&mSimModel, mintSizeOfSimModelHeader);
00688     lIO.EndReadBlock();
00689 
00690     lIO.BeginReadBlock(mintSimModelOffset, mSimModel.mintFutureTableOffset);
00691     lIO.Read((UnsignedInt32*)&mSimModel2, mintSizeOfSimModelHeader2);
00692     lIO.EndReadBlock();
00693 
00694     xintBCCount = mSimModel.mintBCCount;
00695     xintICCount = mSimModel.mintICCount;
00696     xintBCSetCount = mSimModel.mintBCSetCount;
00697     xintMaterialCount = mSimModel.mintMaterialCount;
00698     xintAmplitudeCount = mSimModel.mintAmplitudeCount;
00699     xintConstraintCount = mSimModel2.mintConstraintCount;
00700 
00701     // Restore the Boundary Condition definition header table if there is one.
00702     if(mSimModel.mintBCCount) {
00703         mpaBCs = new SCubitFileBCEntry[mSimModel.mintBCCount];
00704 
00705         lIO.BeginReadBlock(mintSimModelOffset, mSimModel.mintBCTableOffset);
00706         lIO.Read((UnsignedInt32*)mpaBCs,
00707             mSimModel.mintBCCount * mintSizeOfBCEntry);
00708         lIO.EndReadBlock();
00709     }
00710 
00711     // Restore the Initial Condition definition header table if there is one.
00712     if(mSimModel.mintICCount) {
00713         mpaICs = new SCubitFileICEntry[mSimModel.mintICCount];
00714 
00715         lIO.BeginReadBlock(mintSimModelOffset, mSimModel.mintICTableOffset);
00716         lIO.Read((UnsignedInt32*)mpaICs,
00717             mSimModel.mintICCount * mintSizeOfICEntry);
00718         lIO.EndReadBlock();
00719     }
00720 
00721     // Restore the BCSet definition header table if there is one.
00722     if(mSimModel.mintBCSetCount) {
00723         mpaBCSets = new SCubitFileBCSetEntry[mSimModel.mintBCSetCount];
00724 
00725         lIO.BeginReadBlock(mintSimModelOffset, mSimModel.mintBCSetTableOffset);
00726         lIO.Read((UnsignedInt32*)mpaBCSets,
00727             mSimModel.mintBCSetCount * mintSizeOfBCSetEntry);
00728         lIO.EndReadBlock();
00729     }
00730 
00731     // Restore the Material definition header table if there is one.
00732     if(mSimModel.mintMaterialCount) {
00733         mpaMaterials = new SCubitFileMaterialEntry[mSimModel.mintMaterialCount];
00734 
00735         lIO.BeginReadBlock(mintSimModelOffset, mSimModel.mintMaterialTableOffset);
00736         lIO.Read((UnsignedInt32*)mpaMaterials,
00737             mSimModel.mintMaterialCount * mintSizeOfMaterialEntry);
00738         lIO.EndReadBlock();
00739     }
00740 
00741     // Restore the Amplitude definition header table if there is one.
00742     if(mSimModel.mintAmplitudeCount) {
00743         mpaAmplitudes = new SCubitFileAmplitudeEntry[mSimModel.mintAmplitudeCount];
00744 
00745         lIO.BeginReadBlock(mintSimModelOffset, mSimModel.mintAmplitudeTableOffset);
00746         lIO.Read((UnsignedInt32*)mpaAmplitudes,
00747             mSimModel.mintAmplitudeCount * mintSizeOfAmplitudeEntry);
00748         lIO.EndReadBlock();
00749     }
00750 
00751     // Restore the Amplitude definition header table if there is one.
00752     if(mSimModel2.mintConstraintCount) {
00753         mpaConstraints = new SCubitFileConstraintEntry[mSimModel2.mintConstraintCount];
00754 
00755         lIO.BeginReadBlock(mintSimModelOffset, mSimModel2.mintConstraintTableOffset);
00756         lIO.Read((UnsignedInt32*)mpaConstraints,
00757             mSimModel2.mintConstraintCount * mintSizeOfConstraintEntry);
00758         lIO.EndReadBlock();
00759     }
00760 
00761     mBCMetaData.ReadMetaData(mpReadFile, mintSimModelOffset,
00762         mSimModel.mintBCMetaDataOffset, mSimModel.mintSimModelEndian);
00763     mICMetaData.ReadMetaData(mpReadFile, mintSimModelOffset,
00764         mSimModel.mintICMetaDataOffset, mSimModel.mintSimModelEndian);
00765     mBCSetMetaData.ReadMetaData(mpReadFile, mintSimModelOffset,
00766         mSimModel.mintBCSetMetaDataOffset, mSimModel.mintSimModelEndian);
00767     mMaterialMetaData.ReadMetaData(mpReadFile, mintSimModelOffset,
00768         mSimModel.mintMaterialMetaDataOffset, mSimModel.mintSimModelEndian);
00769     mAmplitudeMetaData.ReadMetaData(mpReadFile, mintSimModelOffset,
00770         mSimModel.mintAmplitudeMetaDataOffset, mSimModel.mintSimModelEndian);
00771     mConstraintMetaData.ReadMetaData(mpReadFile, mintSimModelOffset,
00772         mSimModel2.mintConstraintMetaDataOffset, mSimModel.mintSimModelEndian);
00773 }
00774 
00775 void CSimModel::ReadBCSet(UnsignedInt32 xintIndex,
00776                           UnsignedInt32& xintBCSetID,
00777                           UnsignedInt32& xintBCSetUniqueID,
00778                           UnsignedInt32& xintBCSetAnalysisType,
00779                           UnsignedInt32& xintRestraintTypesCount,
00780                           UnsignedInt32& xintLoadTypesCount,
00781                           UnsignedInt32& xintContactPairTypesCount,
00782                           SBCSetData*& xpaBCSetRestraintData,
00783                           SBCSetData*& xpaBCSetLoadData,
00784                           SBCSetData*& xpaBCSetContactPairData)
00785 {
00786     if(!mpReadFile)
00787         throw CCubitFile::eFileReadError;
00788     if(xintIndex >= mSimModel.mintBCSetCount)
00789         throw CCubitFile::eNotFound;
00790     if(!mpaBCSets)
00791         throw CCubitFile::eOrderError;
00792 
00793     xintBCSetID = mpaBCSets[xintIndex].mintBCSetID;
00794     xintBCSetUniqueID = mpaBCSets[xintIndex].mintBCSetUniqueID;
00795     xintBCSetAnalysisType = mpaBCSets[xintIndex].mintBCSetAnalysisType;
00796     xintRestraintTypesCount = mpaBCSets[xintIndex].mintRestraintTypesCount;
00797     xintLoadTypesCount = mpaBCSets[xintIndex].mintLoadTypesCount;
00798     xintContactPairTypesCount = mpaBCSets[xintIndex].mintContactPairTypesCount;
00799 
00800     // read Restraints
00801     if(xintRestraintTypesCount) 
00802     {
00803         // Resize the node set return buffer if necessary and then set the return
00804         // pointers to the buffer.
00805         xpaBCSetRestraintData = AdjustBuffer(xintRestraintTypesCount,
00806             mBCSetBuff.mintNumRestraintTypes, mBCSetBuff.mpaBCSetRestraintData);
00807         UnsignedInt32* lpIDs =
00808             AdjustBuffer(mpaBCSets[xintIndex].mintRestraintMembersCount,
00809             mBCSetBuff.mintNumRestraintMembers, mBCSetBuff.mpaintRestraintMemberIDs);
00810 
00811         // Read the node set from the file.
00812         UnsignedInt32 lintNumMembers, lintTotalMembers = 0;
00813         CIOWrapper* lpIO = new CIOWrapper(mpReadFile, mSimModel.mintSimModelEndian);
00814         lpIO->BeginReadBlock(mintSimModelOffset,
00815             mpaBCSets[xintIndex].mintRestraintsOffset);
00816         //long start_location = lpIO->GetLocation();
00817         for(UnsignedInt32 lintType = 0; lintType < xintRestraintTypesCount; lintType++) {
00818             lpIO->Read(&xpaBCSetRestraintData[lintType].mintMemberType, 1);
00819             lpIO->Read(&xpaBCSetRestraintData[lintType].mintMemberCount, 1);
00820 
00821             xpaBCSetRestraintData[lintType].mpaMemberIDs = lpIDs;
00822             lintNumMembers = xpaBCSetRestraintData[lintType].mintMemberCount;
00823             // Make sure the total number of node set members does not exceed
00824             // what was specified in the node set table entry.
00825             lintTotalMembers += lintNumMembers;
00826             if(lintTotalMembers > mpaBCSets[xintIndex].mintRestraintMembersCount)
00827                 throw CCubitFile::eFileReadError;
00828 
00829             lpIO->Read(xpaBCSetRestraintData[lintType].mpaMemberIDs, lintNumMembers);
00830 
00831             lpIDs = &lpIDs[lintNumMembers];
00832         }
00833 
00834         lpIO->EndReadBlock();
00835         delete lpIO;
00836     }
00837     else
00838         xpaBCSetRestraintData = NULL;
00839 
00840     // read Loads
00841     if(xintLoadTypesCount) 
00842     {
00843         // Resize the node set return buffer if necessary and then set the return
00844         // pointers to the buffer.
00845         xpaBCSetLoadData = AdjustBuffer(xintLoadTypesCount,
00846             mBCSetBuff.mintNumLoadTypes, mBCSetBuff.mpaBCSetLoadData);
00847         UnsignedInt32* lpIDs =
00848             AdjustBuffer(mpaBCSets[xintIndex].mintLoadMembersCount,
00849             mBCSetBuff.mintNumLoadMembers, mBCSetBuff.mpaintLoadMemberIDs);
00850 
00851         // Read the node set from the file.
00852         UnsignedInt32 lintNumMembers, lintTotalMembers = 0;
00853         CIOWrapper* lpIO = new CIOWrapper(mpReadFile, mSimModel.mintSimModelEndian);
00854         lpIO->BeginReadBlock(mintSimModelOffset,
00855             mpaBCSets[xintIndex].mintLoadsOffset);
00856         //long start_location = lpIO->GetLocation();
00857         for(UnsignedInt32 lintType = 0; lintType < xintLoadTypesCount; lintType++) {
00858             lpIO->Read(&xpaBCSetLoadData[lintType].mintMemberType, 1);
00859             lpIO->Read(&xpaBCSetLoadData[lintType].mintMemberCount, 1);
00860 
00861             xpaBCSetLoadData[lintType].mpaMemberIDs = lpIDs;
00862             lintNumMembers = xpaBCSetLoadData[lintType].mintMemberCount;
00863             // Make sure the total number of node set members does not exceed
00864             // what was specified in the node set table entry.
00865             lintTotalMembers += lintNumMembers;
00866             if(lintTotalMembers > mpaBCSets[xintIndex].mintLoadMembersCount)
00867                 throw CCubitFile::eFileReadError;
00868 
00869             lpIO->Read(xpaBCSetLoadData[lintType].mpaMemberIDs, lintNumMembers);
00870 
00871             lpIDs = &lpIDs[lintNumMembers];
00872         }
00873 
00874         lpIO->EndReadBlock();
00875         delete lpIO;
00876     }
00877     else
00878         xpaBCSetLoadData = NULL;
00879     
00880     // read ContactPairs
00881     if(xintContactPairTypesCount) 
00882     {
00883         // Resize the node set return buffer if necessary and then set the return
00884         // pointers to the buffer.
00885         xpaBCSetContactPairData = AdjustBuffer(xintContactPairTypesCount,
00886             mBCSetBuff.mintNumContactPairTypes, mBCSetBuff.mpaBCSetContactPairData);
00887         UnsignedInt32* lpIDs =
00888             AdjustBuffer(mpaBCSets[xintIndex].mintContactPairMembersCount,
00889             mBCSetBuff.mintNumContactPairMembers, mBCSetBuff.mpaintContactPairMemberIDs);
00890 
00891         // Read the node set from the file.
00892         UnsignedInt32 lintNumMembers, lintTotalMembers = 0;
00893         CIOWrapper* lpIO = new CIOWrapper(mpReadFile, mSimModel.mintSimModelEndian);
00894         lpIO->BeginReadBlock(mintSimModelOffset,
00895             mpaBCSets[xintIndex].mintContactPairsOffset);
00896         //long start_location = lpIO->GetLocation();
00897         for(UnsignedInt32 lintType = 0; lintType < xintContactPairTypesCount; lintType++) {
00898             lpIO->Read(&xpaBCSetContactPairData[lintType].mintMemberType, 1);
00899             lpIO->Read(&xpaBCSetContactPairData[lintType].mintMemberCount, 1);
00900 
00901             xpaBCSetContactPairData[lintType].mpaMemberIDs = lpIDs;
00902             lintNumMembers = xpaBCSetContactPairData[lintType].mintMemberCount;
00903             // Make sure the total number of node set members does not exceed
00904             // what was specified in the node set table entry.
00905             lintTotalMembers += lintNumMembers;
00906             if(lintTotalMembers > mpaBCSets[xintIndex].mintContactPairMembersCount)
00907                 throw CCubitFile::eFileReadError;
00908 
00909             lpIO->Read(xpaBCSetContactPairData[lintType].mpaMemberIDs, lintNumMembers);
00910 
00911             lpIDs = &lpIDs[lintNumMembers];
00912         }
00913 
00914         lpIO->EndReadBlock();
00915         delete lpIO;
00916     }
00917     else
00918         xpaBCSetContactPairData = NULL;
00919 
00920 }
00921 
00922 void CSimModel::ReadMaterial(UnsignedInt32 xintIndex,
00923                              UnsignedInt32& xintMaterialID,
00924                              UnsignedInt32& xintMaterialUniqueID,
00925                              UnsignedInt32& xintPropertiesCount,
00926                              SMaterialData*& xpaMaterialData)
00927 {
00928     if(!mpReadFile)
00929         throw CCubitFile::eFileReadError;
00930     if(xintIndex >= mSimModel.mintMaterialCount)
00931         throw CCubitFile::eNotFound;
00932     if(!mpaMaterials)
00933         throw CCubitFile::eOrderError;
00934 
00935     xintMaterialID = mpaMaterials[xintIndex].mintMaterialID;
00936     xintMaterialUniqueID = mpaMaterials[xintIndex].mintMaterialUniqueID;
00937     xintPropertiesCount = mpaMaterials[xintIndex].mintMaterialPropertiesCount;
00938 
00939     // read material data
00940     if(xintPropertiesCount) 
00941     {
00942         // Resize the material return buffer if necessary and then set the return
00943         // pointers to the buffer.
00944         xpaMaterialData = AdjustBuffer(xintPropertiesCount,
00945             mMaterialBuff.mintNumDataTypes, mMaterialBuff.mpaMaterialData);
00946         
00947         double* lpData =
00948             AdjustBuffer(mpaMaterials[xintIndex].mintPropertyDataCount,
00949                 mMaterialBuff.mintNumDataMembers, mMaterialBuff.mpadblData);
00950 
00951 
00952         // Read the material property data from the file.
00953         UnsignedInt32 lintNumMembers, lintTotalMembers = 0;
00954         CIOWrapper* lpIO = new CIOWrapper(mpReadFile, mSimModel.mintSimModelEndian);
00955         lpIO->BeginReadBlock(mintSimModelOffset,
00956             mpaMaterials[xintIndex].mintMaterialPropertiesOffset);
00957 
00958         //long start_location = lpIO->GetLocation();
00959         for(UnsignedInt32 lintType = 0; lintType < xintPropertiesCount; lintType++) {
00960             lpIO->Read(&xpaMaterialData[lintType].mintMemberType, 1);
00961             lpIO->Read(&xpaMaterialData[lintType].mintMemberRows, 1);
00962             lpIO->Read(&xpaMaterialData[lintType].mintMemberColumns, 1);
00963 
00964             xpaMaterialData[lintType].mpadblMemberData = lpData;
00965 
00966             lintNumMembers = xpaMaterialData[lintType].mintMemberRows *
00967                 xpaMaterialData[lintType].mintMemberColumns;
00968 
00969             // Make sure the total number of material members does not exceed
00970             // what was specified in the material table entry.
00971             lintTotalMembers += lintNumMembers;
00972             if(lintTotalMembers > mpaMaterials[xintIndex].mintPropertyDataCount)
00973                 throw CCubitFile::eFileReadError;
00974             
00975             lpIO->Read(xpaMaterialData[lintType].mpadblMemberData,
00976                        xpaMaterialData[lintType].mintMemberRows *
00977                         xpaMaterialData[lintType].mintMemberColumns);
00978 
00979             lpData = &lpData[lintNumMembers];
00980         }
00981 
00982         lpIO->EndReadBlock();
00983         delete lpIO;
00984     }
00985     else
00986         xpaMaterialData = NULL;
00987 }
00988 
00989 void CSimModel::ReadConstraint(UnsignedInt32 xintIndex,
00990                                UnsignedInt32& xintConstraintID, UnsignedInt32& xintConstraintUniqueID,
00991                                UnsignedInt32& xintConstraintType,
00992                                UnsignedInt32& xintIndependentTypeCount, SConstraintData*& xpaIndependentData,
00993                                UnsignedInt32& xintDependentTypeCount, SConstraintData*& xpaDependentData)
00994 {
00995     if(!mpReadFile)
00996         throw CCubitFile::eFileReadError;
00997     if(xintIndex >= mSimModel2.mintConstraintCount)
00998         throw CCubitFile::eNotFound;
00999     if(!mpaConstraints)
01000         throw CCubitFile::eOrderError;
01001 
01002     xintConstraintID = mpaConstraints[xintIndex].mintConstraintID;
01003     xintConstraintUniqueID = mpaConstraints[xintIndex].mintConstraintUniqueID;
01004     xintConstraintType = mpaConstraints[xintIndex].mintConstraintType;
01005     xintIndependentTypeCount = mpaConstraints[xintIndex].mintIndependentTypeCount;
01006     xintDependentTypeCount = mpaConstraints[xintIndex].mintDependentTypeCount;
01007 
01008     // read Dependent Constraint data
01009     if(xintDependentTypeCount) 
01010     {
01011         // Resize the Constraint return buffer if necessary and then set the return
01012         // pointers to the buffer.
01013         xpaDependentData = AdjustBuffer(xintDependentTypeCount,
01014             mConstraintBuff.mintNumDependentTypes, mConstraintBuff.mpaDependentData);
01015         UnsignedInt32* lpIDs =
01016             AdjustBuffer(mpaConstraints[xintIndex].mintDependentTypeCount,
01017             mConstraintBuff.mintNumDependentMembers, mConstraintBuff.mpaintDependentIDs);
01018 
01019         // Read the Constraint property data from the file.
01020         UnsignedInt32 lintNumMembers, lintTotalMembers = 0;
01021         CIOWrapper* lpIO = new CIOWrapper(mpReadFile, mSimModel.mintSimModelEndian);
01022         lpIO->BeginReadBlock(mintSimModelOffset,
01023             mpaConstraints[xintIndex].mintDependentDataOffset);
01024 
01025         //long start_location = lpIO->GetLocation();
01026         for(UnsignedInt32 lintType = 0; lintType < xintDependentTypeCount; lintType++)
01027         {
01028             lpIO->Read(&xpaDependentData[lintType].mintMemberType, 1);
01029             lpIO->Read(&xpaDependentData[lintType].mintMemberCount, 1);
01030 
01031             xpaDependentData[lintType].mpaMemberIDs = lpIDs;
01032             lintNumMembers = xpaDependentData[lintType].mintMemberCount;
01033             // Make sure the total number of node set members does not exceed
01034             // what was specified in the node set table entry.
01035             lintTotalMembers += lintNumMembers;
01036             if(lintTotalMembers > mpaConstraints[xintIndex].mintDependentTypeCount)
01037                 throw CCubitFile::eFileReadError;
01038 
01039             lpIO->Read(xpaDependentData[lintType].mpaMemberIDs, lintNumMembers);
01040 
01041             lpIDs = &lpIDs[lintNumMembers];
01042         }
01043 
01044         lpIO->EndReadBlock();
01045         delete lpIO;
01046     }
01047     else
01048         xpaDependentData = NULL;
01049 
01050     // read Independent Constraint data
01051     if(xintIndependentTypeCount) 
01052     {
01053         // Resize the Constraint return buffer if necessary and then set the return
01054         // pointers to the buffer.
01055         xpaIndependentData = AdjustBuffer(xintIndependentTypeCount,
01056             mConstraintBuff.mintNumIndependentTypes, mConstraintBuff.mpaIndependentData);
01057         UnsignedInt32* lpIDs =
01058             AdjustBuffer(mpaConstraints[xintIndex].mintIndependentTypeCount,
01059             mConstraintBuff.mintNumIndependentMembers, mConstraintBuff.mpaintIndependentIDs);
01060 
01061         // Read the Constraint property data from the file.
01062         UnsignedInt32 lintNumMembers, lintTotalMembers = 0;
01063         CIOWrapper* lpIO = new CIOWrapper(mpReadFile, mSimModel.mintSimModelEndian);
01064         lpIO->BeginReadBlock(mintSimModelOffset,
01065             mpaConstraints[xintIndex].mintIndependentDataOffset);
01066 
01067         //long start_location = lpIO->GetLocation();
01068         for(UnsignedInt32 lintType = 0; lintType < xintIndependentTypeCount; lintType++)
01069         {
01070             lpIO->Read(&xpaIndependentData[lintType].mintMemberType, 1);
01071             lpIO->Read(&xpaIndependentData[lintType].mintMemberCount, 1);
01072 
01073             xpaIndependentData[lintType].mpaMemberIDs = lpIDs;
01074             lintNumMembers = xpaIndependentData[lintType].mintMemberCount;
01075             // Make sure the total number of node set members does not exceed
01076             // what was specified in the node set table entry.
01077             lintTotalMembers += lintNumMembers;
01078             if(lintTotalMembers > mpaConstraints[xintIndex].mintIndependentTypeCount)
01079                 throw CCubitFile::eFileReadError;
01080 
01081             lpIO->Read(xpaIndependentData[lintType].mpaMemberIDs, lintNumMembers);
01082 
01083             lpIDs = &lpIDs[lintNumMembers];
01084         }
01085 
01086         lpIO->EndReadBlock();
01087         delete lpIO;
01088     }
01089     else
01090         xpaIndependentData = NULL;
01091 
01092 }
01093 
01094 void CSimModel::EndRead()
01095 {
01096     mpReadFile = NULL;
01097 }
01098 
01100 // Meta-Data Functions
01102 
01103 CMetaData& CSimModel::GetBCMetaData()
01104 {
01105     return mBCMetaData;
01106 }
01107 
01108 CMetaData& CSimModel::GetICMetaData()
01109 {
01110     return mICMetaData;
01111 }
01112 
01113 CMetaData& CSimModel::GetBCSetMetaData()
01114 {
01115     return mBCSetMetaData;
01116 }
01117 
01118 CMetaData& CSimModel::GetMaterialMetaData()
01119 {
01120     return mMaterialMetaData;
01121 }
01122 
01123 CMetaData& CSimModel::GetAmplitudeMetaData()
01124 {
01125     return mAmplitudeMetaData;
01126 }
01127 
01128 CMetaData& CSimModel::GetConstraintMetaData()
01129 {
01130     return mConstraintMetaData;
01131 }
01132 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines