--- trunk/src/io/DumpWriter.cpp 2010/04/21 14:59:18 1437 +++ branches/development/src/io/DumpWriter.cpp 2012/06/06 02:18:54 1746 @@ -36,7 +36,8 @@ * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman & Gezelter, in progress (2009). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ #include "io/DumpWriter.hpp" @@ -58,8 +59,12 @@ namespace OpenMD { : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ Globals* simParams = info->getSimParams(); - needCompression_ = simParams->getCompressDumpFile(); - needForceVector_ = simParams->getOutputForceVector(); + needCompression_ = simParams->getCompressDumpFile(); + needForceVector_ = simParams->getOutputForceVector(); + needParticlePot_ = simParams->getOutputParticlePotential(); + needFlucQ_ = simParams->getOutputFluctuatingCharges(); + needElectricField_ = simParams->getOutputElectricField(); + createDumpFile_ = true; #ifdef HAVE_LIBZ if (needCompression_) { @@ -97,8 +102,12 @@ namespace OpenMD { Globals* simParams = info->getSimParams(); eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; - needCompression_ = simParams->getCompressDumpFile(); - needForceVector_ = simParams->getOutputForceVector(); + needCompression_ = simParams->getCompressDumpFile(); + needForceVector_ = simParams->getOutputForceVector(); + needParticlePot_ = simParams->getOutputParticlePotential(); + needFlucQ_ = simParams->getOutputFluctuatingCharges(); + needElectricField_ = simParams->getOutputElectricField(); + createDumpFile_ = true; #ifdef HAVE_LIBZ if (needCompression_) { @@ -136,9 +145,12 @@ namespace OpenMD { Globals* simParams = info->getSimParams(); eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; - needCompression_ = simParams->getCompressDumpFile(); - needForceVector_ = simParams->getOutputForceVector(); - + needCompression_ = simParams->getCompressDumpFile(); + needForceVector_ = simParams->getOutputForceVector(); + needParticlePot_ = simParams->getOutputParticlePotential(); + needFlucQ_ = simParams->getOutputFluctuatingCharges(); + needElectricField_ = simParams->getOutputElectricField(); + #ifdef HAVE_LIBZ if (needCompression_) { filename_ += ".gz"; @@ -306,7 +318,8 @@ namespace OpenMD { } const int masterNode = 0; - + int nProc; + MPI_Comm_size(MPI_COMM_WORLD, &nProc); if (worldRank == masterNode) { os << " \n"; writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot()); @@ -314,13 +327,12 @@ namespace OpenMD { os << buffer; - int nProc; - MPI_Comm_size(MPI_COMM_WORLD, &nProc); for (int i = 1; i < nProc; ++i) { // receive the length of the string buffer that was // prepared by processor i + MPI_Bcast(&i, 1, MPI_INT,masterNode,MPI_COMM_WORLD); int recvLength; MPI_Recv(&recvLength, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &istatus); char* recvBuffer = new char[recvLength]; @@ -337,8 +349,14 @@ namespace OpenMD { os.flush(); } else { int sendBufferLength = buffer.size() + 1; - MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); - MPI_Send((void *)buffer.c_str(), sendBufferLength, MPI_CHAR, masterNode, 0, MPI_COMM_WORLD); + int myturn = 0; + for (int i = 1; i < nProc; ++i){ + MPI_Bcast(&myturn,1, MPI_INT,masterNode,MPI_COMM_WORLD); + if (myturn == worldRank){ + MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); + MPI_Send((void *)buffer.c_str(), sendBufferLength, MPI_CHAR, masterNode, 0, MPI_COMM_WORLD); + } + } } #endif // is_mpi @@ -420,10 +438,7 @@ namespace OpenMD { if (needForceVector_) { type += "f"; - Vector3d frc; - - frc = integrableObject->getFrc(); - + Vector3d frc = integrableObject->getFrc(); if (isinf(frc[0]) || isnan(frc[0]) || isinf(frc[1]) || isnan(frc[1]) || isinf(frc[2]) || isnan(frc[2]) ) { @@ -439,10 +454,7 @@ namespace OpenMD { if (integrableObject->isDirectional()) { type += "t"; - Vector3d trq; - - trq = integrableObject->getTrq(); - + Vector3d trq = integrableObject->getTrq(); if (isinf(trq[0]) || isnan(trq[0]) || isinf(trq[1]) || isnan(trq[1]) || isinf(trq[2]) || isnan(trq[2]) ) { @@ -451,14 +463,83 @@ namespace OpenMD { " for object %d", index); painCave.isFatal = 1; simError(); - } - + } sprintf(tempBuffer, " %13e %13e %13e", trq[0], trq[1], trq[2]); line += tempBuffer; } } + + if (needParticlePot_) { + type += "u"; + RealType particlePot = integrableObject->getParticlePot(); + if (isinf(particlePot) || isnan(particlePot)) { + sprintf( painCave.errMsg, + "DumpWriter detected a numerical error writing the particle " + " potential for object %d", index); + painCave.isFatal = 1; + simError(); + } + sprintf(tempBuffer, " %13e", particlePot); + line += tempBuffer; + } + if (needFlucQ_) { + type += "cw"; + RealType fqPos = integrableObject->getFlucQPos(); + if (isinf(fqPos) || isnan(fqPos) ) { + sprintf( painCave.errMsg, + "DumpWriter detected a numerical error writing the" + " fluctuating charge for object %d", index); + painCave.isFatal = 1; + simError(); + } + sprintf(tempBuffer, " %13e ", fqPos); + line += tempBuffer; + + RealType fqVel = integrableObject->getFlucQVel(); + if (isinf(fqVel) || isnan(fqVel) ) { + sprintf( painCave.errMsg, + "DumpWriter detected a numerical error writing the" + " fluctuating charge velocity for object %d", index); + painCave.isFatal = 1; + simError(); + } + sprintf(tempBuffer, " %13e ", fqVel); + line += tempBuffer; + + if (needForceVector_) { + type += "g"; + RealType fqFrc = integrableObject->getFlucQFrc(); + if (isinf(fqFrc) || isnan(fqFrc) ) { + sprintf( painCave.errMsg, + "DumpWriter detected a numerical error writing the" + " fluctuating charge force for object %d", index); + painCave.isFatal = 1; + simError(); + } + sprintf(tempBuffer, " %13e ", fqFrc); + line += tempBuffer; + } + } + + if (needElectricField_) { + type += "e"; + Vector3d eField= integrableObject->getElectricField(); + if (isinf(eField[0]) || isnan(eField[0]) || + isinf(eField[1]) || isnan(eField[1]) || + isinf(eField[2]) || isnan(eField[2]) ) { + sprintf( painCave.errMsg, + "DumpWriter detected a numerical error writing the electric" + " field for object %d", index); + painCave.isFatal = 1; + simError(); + } + sprintf(tempBuffer, " %13e %13e %13e", + eField[0], eField[1], eField[2]); + line += tempBuffer; + } + sprintf(tempBuffer, "%10d %7s %s\n", index, type.c_str(), line.c_str()); return std::string(tempBuffer); } @@ -540,7 +621,7 @@ namespace OpenMD { newOStream = new std::ofstream(filename.c_str()); #endif //write out MetaData first - (*newOStream) << "" << std::endl; + (*newOStream) << "" << std::endl; (*newOStream) << " " << std::endl; (*newOStream) << info_->getRawMetaData(); (*newOStream) << " " << std::endl;