void Doom3FileSystem::initDirectory(const std::string& inputPath) { if (_numDirectories == (VFS_MAXDIRS-1)) { return; } // greebo: Normalise path: Replace backslashes and ensure trailing slash _directories[_numDirectories] = os::standardPathWithSlash(inputPath); // Shortcut const std::string& path = _directories[_numDirectories]; _numDirectories++; { ArchiveDescriptor entry; entry.name = path; entry.archive = DirectoryArchivePtr(new DirectoryArchive(path)); entry.is_pakfile = false; _archives.push_back(entry); } // Instantiate a new sorting container for the filenames SortedFilenames filenameList; // Traverse the directory using the filename list as functor try { os::foreachItemInDirectory(path, [&] (const boost::filesystem::path& file) { // Just insert the name, it will get sorted correctly. filenameList.insert(file.filename().string()); }); } catch (os::DirectoryNotFoundException&) { std::cout << "[vfs] Directory '" << path << "' not found." << std::endl; } if (filenameList.empty()) { return; // nothing found } rMessage() << "[vfs] searched directory: " << path << std::endl; // Get the ArchiveLoader and try to load each file ArchiveLoader& archiveModule = GlobalArchive("PK4"); // add the entries to the vfs for (SortedFilenames::iterator i = filenameList.begin(); i != filenameList.end(); ++i) { // Assemble the filename and try to load the archive initPakFile(archiveModule, path + *i); } }
// Archive the results if it is time void ArchiveData::ArchiveResults(double atime) { double rho,rho0; double sxx,syy,sxy; char fname[500],fline[500]; int i,p; CrackHeader *nextCrack; // test global archiving GlobalArchive(atime); // see if desired if(atime<nextArchTime) return; nextArchTime+=archTime; // exit if using delayed archiving if(atime>0.9*timestep && atime<firstArchTime) return; // get relative path name to the file sprintf(fname,"%s%s.%d",outputDir,archiveRoot,fmobj->mstep); // output step number, time, and file name to results file for(i=strlen(fname);i>=0;i--) { if(fname[i]=='/') break; } sprintf(fline,"%7d %15.7e %s",fmobj->mstep,1000.*atime,&fname[i+1]); cout << fline << endl; // open the file ofstream afile; try { afile.open(fname, ios::out | ios::binary); if(!afile.is_open()) FileError("Cannot open an archive file",fname,"ArchiveData::ArchiveResults"); // write header created in SetArchiveHeader *timeStamp=1000.*atime; afile.write(archHeader,HEADER_LENGTH); if(afile.bad()) FileError("File error writing archive file header",fname,"ArchiveData::ArchiveResults"); } catch(CommonException err) { // give up on hopefully temporary file problem cout << "# " << err.Message() << endl; cout << "# Will try to continue" << endl; if(afile.is_open()) afile.close(); return; } // allocate space for one material point long blen=recSize; char *aptr=(char *)malloc(blen); if(aptr==NULL) throw CommonException("Out of memory allocating buffer for archive file","ArchiveData::ArchiveResults"); // all material points for(p=0;p<nmpms;p++) { // buffer is for one particle char *app=aptr; // must have these defaults // element ID *(int *)app=mpm[p]->ArchiveElemID(); app+=sizeof(int); // mass (g) *(double *)app=mpm[p]->mp; app+=sizeof(double); // material ID *(short *)app=mpm[p]->ArchiveMatID(); app+=sizeof(short); // fill in two zeros for byte alignment *app=0; app+=1; *app=0; app+=1; // 3D has three angles, 2D has one angle and thickness if(threeD) { // 3 material rotation angles in degrees *(double *)app=mpm[p]->GetRotationZInDegrees(); app+=sizeof(double); *(double *)app=mpm[p]->GetRotationYInDegrees(); app+=sizeof(double); *(double *)app=mpm[p]->GetRotationXInDegrees(); app+=sizeof(double); } else { // material rotation angle in degrees *(double *)app=mpm[p]->GetRotationZInDegrees(); app+=sizeof(double); // thickness (2D) in mm *(double *)app=mpm[p]->thickness(); app+=sizeof(double); } // (x,y,z) position (mm) *(double *)app=mpm[p]->pos.x; app+=sizeof(double); *(double *)app=mpm[p]->pos.y; app+=sizeof(double); if(threeD) { *(double *)app=mpm[p]->pos.z; app+=sizeof(double); } // original (x,y,z) position (mm) *(double *)app=mpm[p]->origpos.x; app+=sizeof(double); *(double *)app=mpm[p]->origpos.y; app+=sizeof(double); if(threeD) { *(double *)app=mpm[p]->origpos.z; app+=sizeof(double); } // velocity (mm/sec) if(mpmOrder[ARCH_Velocity]=='Y') { *(double *)app=mpm[p]->vel.x; app+=sizeof(double); *(double *)app=mpm[p]->vel.y; app+=sizeof(double); if(threeD) { *(double *)app=mpm[p]->vel.z; app+=sizeof(double); } } // stress - internally it is N/m^2 cm^3/g, output in N/m^2 or Pa // internal SI units are kPa/(kg/m^3) // For large deformation, need to convert Kirchoff Stress/rho0 to Cauchy stress int matid = mpm[p]->MatID(); rho0=theMaterials[matid]->rho; rho = rho0/theMaterials[matid]->GetCurrentRelativeVolume(mpm[p]); Tensor sp = mpm[p]->ReadStressTensor(); sxx=rho*sp.xx; syy=rho*sp.yy; sxy=rho*sp.xy; if(mpmOrder[ARCH_Stress]=='Y') { *(double *)app=sxx; app+=sizeof(double); *(double *)app=syy; app+=sizeof(double); *(double *)app=rho*sp.zz; app+=sizeof(double); *(double *)app=sxy; app+=sizeof(double); if(threeD) { *(double *)app=rho*sp.xz; app+=sizeof(double); *(double *)app=rho*sp.yz; app+=sizeof(double); } } // elastic strain (absolute) if(mpmOrder[ARCH_Strain]=='Y') { Tensor *ep=mpm[p]->GetStrainTensor(); *(double *)app=ep->xx; app+=sizeof(double); *(double *)app=ep->yy; app+=sizeof(double); *(double *)app=ep->zz; app+=sizeof(double); *(double *)app=ep->xy; app+=sizeof(double); if(threeD) { *(double *)app=ep->xz; app+=sizeof(double); *(double *)app=ep->yz; app+=sizeof(double); } } // plastic strain (absolute) if(mpmOrder[ARCH_PlasticStrain]=='Y') { Tensor *eplast=mpm[p]->GetPlasticStrainTensor(); *(double *)app=eplast->xx; app+=sizeof(double); *(double *)app=eplast->yy; app+=sizeof(double); *(double *)app=eplast->zz; app+=sizeof(double); *(double *)app=eplast->xy; app+=sizeof(double); if(threeD) { *(double *)app=eplast->xz; app+=sizeof(double); *(double *)app=eplast->yz; app+=sizeof(double); } } // external work (cumulative) in J if(mpmOrder[ARCH_WorkEnergy]=='Y') { *(double *)app=1.0e-6*mpm[p]->mp*mpm[p]->GetWorkEnergy(); app+=sizeof(double); } // temperature if(mpmOrder[ARCH_DeltaTemp]=='Y') { *(double *)app=mpm[p]->pTemperature; app+=sizeof(double); } // total plastic energy (Volume*energy) in J // energies in material point based on energy per unit mass // here need mass * U/(rho0 V0) if(mpmOrder[ARCH_PlasticEnergy]=='Y') { *(double *)app=1.0e-6*mpm[p]->mp*mpm[p]->GetPlastEnergy(); app+=sizeof(double); } // shear components (absolute) if(mpmOrder[ARCH_ShearComponents]=='Y') { *(double *)app=mpm[p]->GetDuDy(); app+=sizeof(double); *(double *)app=mpm[p]->GetDvDx(); app+=sizeof(double); } // total strain energy (Volume*energy) in J // energies in material point based on energy per unit mass // here need mass * U/(rho0 V0) // internal units are same as stress: N/m^2 cm^3/g = microJ/g = mJ/kg // note that rho*energy has units J/m^3 = N/m^2 (if rho in g/cm^3) if(mpmOrder[ARCH_StrainEnergy]=='Y') { *(double *)app=1.0e-6*mpm[p]->mp*mpm[p]->GetStrainEnergy(); app+=sizeof(double); } // material history data on particle (whatever units the material chooses) if(mpmOrder[ARCH_History]=='Y') { *(double *)app=theMaterials[mpm[p]->MatID()]->GetHistory(1,mpm[p]->GetHistoryPtr()); app+=sizeof(double); } else if(mpmOrder[ARCH_History]!='N') { if(mpmOrder[ARCH_History]&0x01) { *(double *)app=theMaterials[mpm[p]->MatID()]->GetHistory(1,mpm[p]->GetHistoryPtr()); app+=sizeof(double); } if(mpmOrder[ARCH_History]&0x02) { *(double *)app=theMaterials[mpm[p]->MatID()]->GetHistory(2,mpm[p]->GetHistoryPtr()); app+=sizeof(double); } if(mpmOrder[ARCH_History]&0x04) { *(double *)app=theMaterials[mpm[p]->MatID()]->GetHistory(3,mpm[p]->GetHistoryPtr()); app+=sizeof(double); } if(mpmOrder[ARCH_History]&0x08) { *(double *)app=theMaterials[mpm[p]->MatID()]->GetHistory(4,mpm[p]->GetHistoryPtr()); app+=sizeof(double); } } // concentration and gradients convert to wt fraction units using csat for this material if(mpmOrder[ARCH_Concentration]=='Y') { double csat=theMaterials[mpm[p]->MatID()]->concSaturation; *(double *)app=mpm[p]->pConcentration*csat; app+=sizeof(double); if(mpm[p]->pDiffusion!=NULL) { *(double *)app=mpm[p]->pDiffusion->Dc.x*csat; app+=sizeof(double); *(double *)app=mpm[p]->pDiffusion->Dc.y*csat; app+=sizeof(double); if(threeD) { *(double *)app=mpm[p]->pDiffusion->Dc.z*csat; app+=sizeof(double); } } else { *(double *)app=0.; app+=sizeof(double); *(double *)app=0.; app+=sizeof(double); if(threeD) { *(double *)app=0.; app+=sizeof(double); } } } // total heat energy (Volume*energy) in J // energies in material point based on energy per unit mass // here need mass * U/(rho0 V0) // internal units are same as stress: N/m^2 cm^3/g = microJ/g = mJ/kg // note that rho*energy has units J/m^3 = N/m^2 (if rho in g/cm^3) if(mpmOrder[ARCH_HeatEnergy]=='Y') { *(double *)app=1.0e-6*mpm[p]->mp*mpm[p]->GetHeatEnergy(); app+=sizeof(double); } // element crossings since last archive - now cumulative if(mpmOrder[ARCH_ElementCrossings]=='Y') { *(int *)app=mpm[p]->GetElementCrossings(); app+=sizeof(int); } // here=initial angle z (degrees) while angle(above)=here-0.5*180*wxy/PI (degrees) // Thus 0.5*180*wxy/PI = here-angle(above) or wxy = (PI/90)*(here-angle(above)) // here=initial angle y (degrees) while angle(above)=here+0.5*180*wrot.xz/PI_CONSTANT (degrees) // Thus 0.5*180*wxz/PI = -(here-angle(above)) or wxz = -(PI/90)*(here-angle(above)) // here=initial angle x (degrees) while angle(above)=here-0.5*180.*wrot.yz/PI_CONSTANT; (degrees) // Thus 0.5*180*wyz/PI = (here-angle(above)) or wyz = (PI/90)*(here-angle(above)) if(mpmOrder[ARCH_RotStrain]=='Y') { if(threeD) { *(double *)app=mpm[p]->GetAnglez0InDegrees(); app+=sizeof(double); *(double *)app=mpm[p]->GetAngley0InDegrees(); app+=sizeof(double); *(double *)app=mpm[p]->GetAnglex0InDegrees(); app+=sizeof(double); } else { *(double *)app=mpm[p]->GetAnglez0InDegrees(); app+=sizeof(double); } } // padding if(mpmRecSize<recSize) app+=recSize-mpmRecSize; // reversing bytes? if(fmobj->GetReverseBytes()) { app-=recSize; // defaults app+=Reverse(app,sizeof(int)); // element app+=Reverse(app,sizeof(double)); // mass app+=Reverse(app,sizeof(short))+2; // material ID app+=Reverse(app,sizeof(double)); // angle app+=Reverse(app,sizeof(double)); // thickness or dihedral app+=Reverse(app,sizeof(double)); // position app+=Reverse(app,sizeof(double)); if(threeD) app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); // orig position app+=Reverse(app,sizeof(double)); if(threeD) app+=Reverse(app,sizeof(double)); // velocity (mm/sec) if(mpmOrder[ARCH_Velocity]=='Y') { app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); if(threeD) app+=Reverse(app,sizeof(double)); } // stress 2D (in N/m^2) if(mpmOrder[ARCH_Stress]=='Y') { app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); if(threeD) { app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); } } // strain 2D (absolute) if(mpmOrder[ARCH_Strain]=='Y') { app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); if(threeD) { app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); } } // plastic strain (absolute) if(mpmOrder[ARCH_PlasticStrain]=='Y') { app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); if(threeD) { app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); } } // work energy (cumulative) in J if(mpmOrder[ARCH_WorkEnergy]=='Y') app+=Reverse(app,sizeof(double)); // temperature if(mpmOrder[ARCH_DeltaTemp]=='Y') app+=Reverse(app,sizeof(double)); // total plastic energy if(mpmOrder[ARCH_PlasticEnergy]=='Y') app+=Reverse(app,sizeof(double)); // shear components if(mpmOrder[ARCH_ShearComponents]=='Y') { app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); } // total strain energy if(mpmOrder[ARCH_StrainEnergy]=='Y') app+=Reverse(app,sizeof(double)); // material history data on particle if(mpmOrder[ARCH_History]=='Y') app+=Reverse(app,sizeof(double)); else if(mpmOrder[ARCH_History]!='N') { if(mpmOrder[ARCH_History]&0x01) app+=Reverse(app,sizeof(double)); if(mpmOrder[ARCH_History]&0x02) app+=Reverse(app,sizeof(double)); if(mpmOrder[ARCH_History]&0x04) app+=Reverse(app,sizeof(double)); if(mpmOrder[ARCH_History]&0x08) app+=Reverse(app,sizeof(double)); } // concentration and gradients if(mpmOrder[ARCH_Concentration]=='Y') { app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); if(threeD) app+=Reverse(app,sizeof(double)); } // total strain energy if(mpmOrder[ARCH_HeatEnergy]=='Y') app+=Reverse(app,sizeof(double)); // element crossings if(mpmOrder[ARCH_ElementCrossings]=='Y') app+=Reverse(app,sizeof(int)); // rotational strain if(mpmOrder[ARCH_RotStrain]=='Y') { app+=Reverse(app,sizeof(double)); if(threeD) { app+=Reverse(app,sizeof(double)); app+=Reverse(app,sizeof(double)); } } // padding if(mpmRecSize<recSize) app+=recSize-mpmRecSize; } // write this particle (ofstream should buffer for us) try { afile.write(aptr,blen); if(afile.bad()) FileError("File error writing material point data",fname,"ArchiveData::ArchiveResults"); } catch(CommonException err) { // give up on hopefully temporary file problem cout << "# " << err.Message() << endl; cout << "# Will try to continue" << endl; afile.close(); free(aptr); return; } } // clear material point record buffer free(aptr); // add the cracks nextCrack=firstCrack; while(nextCrack!=NULL) { nextCrack->Archive(afile); nextCrack=(CrackHeader *)nextCrack->GetNextObject(); } // close the file try { afile.close(); if(afile.bad()) FileError("File error closing an archive file",fname,"ArchiveData::ArchiveResults"); } catch(CommonException err) { // give up on hopefully temporary file problem cout << "# " << err.Message() << endl; cout << "# Will try to continue" << endl; } }