--- trunk/src/io/DumpWriter.cpp 2005/09/20 21:22:38 615 +++ trunk/src/io/DumpWriter.cpp 2005/12/06 17:52:45 791 @@ -57,18 +57,21 @@ namespace oopse { Globals* simParams = info->getSimParams(); needCompression_ = simParams->getCompressDumpFile(); - + needForceVector_ = simParams->getOutputForceVector(); + createDumpFile_ = true; +#ifdef HAVE_LIBZ if (needCompression_) { filename_ += ".gz"; eorFilename_ += ".gz"; } +#endif #ifdef IS_MPI if (worldRank == 0) { #endif // is_mpi - + dumpFile_ = createOStream(filename_); if (!dumpFile_) { @@ -97,17 +100,21 @@ namespace oopse { eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; needCompression_ = simParams->getCompressDumpFile(); + needForceVector_ = simParams->getOutputForceVector(); + createDumpFile_ = true; +#ifdef HAVE_LIBZ if (needCompression_) { filename_ += ".gz"; eorFilename_ += ".gz"; } +#endif #ifdef IS_MPI if (worldRank == 0) { #endif // is_mpi - + dumpFile_ = createOStream(filename_); if (!dumpFile_) { @@ -127,6 +134,54 @@ namespace oopse { #endif // is_mpi } + + DumpWriter::DumpWriter(SimInfo* info, const std::string& filename, bool writeDumpFile) + : info_(info), filename_(filename){ + + Globals* simParams = info->getSimParams(); + eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; + + needCompression_ = simParams->getCompressDumpFile(); + needForceVector_ = simParams->getOutputForceVector(); + +#ifdef HAVE_LIBZ + if (needCompression_) { + filename_ += ".gz"; + eorFilename_ += ".gz"; + } +#endif + +#ifdef IS_MPI + + if (worldRank == 0) { +#endif // is_mpi + + createDumpFile_ = writeDumpFile; + if (createDumpFile_) { + dumpFile_ = createOStream(filename_); + + if (!dumpFile_) { + sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", + filename_.c_str()); + painCave.isFatal = 1; + simError(); + } + } +#ifdef IS_MPI + + } + + sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); + MPIcheckPoint(); + +#endif // is_mpi + + } + + + + + DumpWriter::~DumpWriter() { @@ -134,9 +189,9 @@ namespace oopse { if (worldRank == 0) { #endif // is_mpi - - delete dumpFile_; - + if (createDumpFile_){ + delete dumpFile_; + } #ifdef IS_MPI } @@ -186,6 +241,8 @@ namespace oopse { Vector3d ji; Vector3d pos; Vector3d vel; + Vector3d frc; + Vector3d trq; Molecule* mol; StuntDouble* integrableObject; @@ -222,14 +279,25 @@ namespace oopse { q = integrableObject->getQ(); ji = integrableObject->getJ(); - sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", + sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", q[0], q[1], q[2], q[3], ji[0], ji[1], ji[2]); strcat(writeLine, tempBuffer); } else { - strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); + strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); } + if (needForceVector_) { + frc = integrableObject->getFrc(); + trq = integrableObject->getTrq(); + + sprintf(tempBuffer, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", + frc[0], frc[1], frc[2], + trq[0], trq[1], trq[2]); + strcat(writeLine, tempBuffer); + } + + strcat(writeLine, "\n"); os << writeLine; } @@ -279,7 +347,7 @@ namespace oopse { int myPotato; int nProc; int which_node; - double atomData[13]; + double atomData[19]; int isDirectional; char MPIatomTypeString[MINIBUFFERSIZE]; int msgLen; // the length of message actually recieved at master nodes @@ -354,13 +422,13 @@ namespace oopse { myPotato++; - MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, + MPI_Recv(atomData, 19, MPI_DOUBLE, which_node, myPotato, MPI_COMM_WORLD, &istatus); myPotato++; MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen); - if (msgLen == 13) + if (msgLen == 13 || msgLen == 19) isDirectional = 1; else isDirectional = 0; @@ -375,10 +443,10 @@ namespace oopse { atomData[5]); strcat(writeLine, - "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); + "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); } else { sprintf(writeLine, - "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", + "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", MPIatomTypeString, atomData[0], atomData[1], @@ -393,8 +461,29 @@ namespace oopse { atomData[10], atomData[11], atomData[12]); + } + + if (needForceVector_) { + if (!isDirectional) { + sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", + atomData[6], + atomData[7], + atomData[8], + atomData[9], + atomData[10], + atomData[11]); + } else { + sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", + atomData[13], + atomData[14], + atomData[15], + atomData[16], + atomData[17], + atomData[18]); + } } + sprintf(writeLine, "\n"); os << writeLine; } // end for(int l =0) @@ -446,6 +535,27 @@ namespace oopse { atomData[12] = ji[2]; } + if (needForceVector_) { + frc = integrableObject->getFrc(); + trq = integrableObject->getTrq(); + + if (!isDirectional) { + atomData[6] = frc[0]; + atomData[7] = frc[1]; + atomData[8] = frc[2]; + atomData[9] = trq[0]; + atomData[10] = trq[1]; + atomData[11] = trq[2]; + } else { + atomData[13] = frc[0]; + atomData[14] = frc[1]; + atomData[15] = frc[2]; + atomData[16] = trq[0]; + atomData[17] = trq[1]; + atomData[18] = trq[2]; + } + } + // If we've survived to here, format the line: if (!isDirectional) { @@ -456,10 +566,10 @@ namespace oopse { atomData[5]); strcat(writeLine, - "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); + "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); } else { sprintf(writeLine, - "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", + "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", integrableObject->getType().c_str(), atomData[0], atomData[1], @@ -476,7 +586,27 @@ namespace oopse { atomData[12]); } + if (needForceVector_) { + if (!isDirectional) { + sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", + atomData[6], + atomData[7], + atomData[8], + atomData[9], + atomData[10], + atomData[11]); + } else { + sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", + atomData[13], + atomData[14], + atomData[15], + atomData[16], + atomData[17], + atomData[18]); + } + } + sprintf(writeLine, "\n"); os << writeLine; } //end for(iter = integrableObject.begin()) @@ -562,6 +692,29 @@ namespace oopse { atomData[12] = ji[2]; } + if (needForceVector_) { + frc = integrableObject->getFrc(); + trq = integrableObject->getTrq(); + + if (!isDirectional) { + atomData[6] = frc[0]; + atomData[7] = frc[1]; + atomData[8] = frc[2]; + + atomData[9] = trq[0]; + atomData[10] = trq[1]; + atomData[11] = trq[2]; + } else { + atomData[13] = frc[0]; + atomData[14] = frc[1]; + atomData[15] = frc[2]; + + atomData[16] = trq[0]; + atomData[17] = trq[1]; + atomData[18] = trq[2]; + } + } + strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE); // null terminate the std::string before sending (just in case): @@ -572,9 +725,15 @@ namespace oopse { myPotato++; - if (isDirectional) { + if (isDirectional && needForceVector_) { + MPI_Send(atomData, 19, MPI_DOUBLE, 0, myPotato, + MPI_COMM_WORLD); + } else if (isDirectional) { MPI_Send(atomData, 13, MPI_DOUBLE, 0, myPotato, MPI_COMM_WORLD); + } else if (needForceVector_) { + MPI_Send(atomData, 12, MPI_DOUBLE, 0, myPotato, + MPI_COMM_WORLD); } else { MPI_Send(atomData, 6, MPI_DOUBLE, 0, myPotato, MPI_COMM_WORLD); @@ -659,12 +818,17 @@ std::ostream* DumpWriter::createOStream(const std::str } std::ostream* DumpWriter::createOStream(const std::string& filename) { + std::ostream* newOStream; +#ifdef HAVE_LIBZ if (needCompression_) { newOStream = new ogzstream(filename.c_str()); } else { newOStream = new std::ofstream(filename.c_str()); } +#else + newOStream = new std::ofstream(filename.c_str()); +#endif return newOStream; }