--- trunk/src/io/DumpReader.cpp 2006/08/30 20:33:44 1025 +++ branches/development/src/io/DumpReader.cpp 2011/11/22 20:38:56 1665 @@ -1,43 +1,44 @@ -/* - * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. - * - * The University of Notre Dame grants you ("Licensee") a - * non-exclusive, royalty free, license to use, modify and - * redistribute this software in source and binary code form, provided - * that the following conditions are met: - * - * 1. Acknowledgement of the program authors must be made in any - * publication of scientific results based in part on use of the - * program. An acceptable form of acknowledgement is citation of - * the article in which the program was described (Matthew - * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher - * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented - * Parallel Simulation Engine for Molecular Dynamics," - * J. Comput. Chem. 26, pp. 252-271 (2005)) - * - * 2. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 3. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the - * distribution. - * - * This software is provided "AS IS," without a warranty of any - * kind. All express or implied conditions, representations and - * warranties, including any implied warranty of merchantability, - * fitness for a particular purpose or non-infringement, are hereby - * excluded. The University of Notre Dame and its licensors shall not - * be liable for any damages suffered by licensee as a result of - * using, modifying or distributing the software or its - * derivatives. In no event will the University of Notre Dame or its - * licensors be liable for any lost revenue, profit or data, or for - * direct, indirect, special, consequential, incidental or punitive - * damages, however caused and regardless of the theory of liability, - * arising out of the use of or inability to use software, even if the - * University of Notre Dame has been advised of the possibility of - * such damages. - */ +/* + * Copyright (c) 2009 The University of Notre Dame. All Rights Reserved. + * + * The University of Notre Dame grants you ("Licensee") a + * non-exclusive, royalty free, license to use, modify and + * redistribute this software in source and binary code form, provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * This software is provided "AS IS," without a warranty of any + * kind. All express or implied conditions, representations and + * warranties, including any implied warranty of merchantability, + * fitness for a particular purpose or non-infringement, are hereby + * excluded. The University of Notre Dame and its licensors shall not + * be liable for any damages suffered by licensee as a result of + * using, modifying or distributing the software or its + * derivatives. In no event will the University of Notre Dame or its + * licensors be liable for any lost revenue, profit or data, or for + * direct, indirect, special, consequential, incidental or punitive + * damages, however caused and regardless of the theory of liability, + * arising out of the use of or inability to use software, even if the + * University of Notre Dame has been advised of the possibility of + * such damages. + * + * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your + * research, please cite the appropriate papers when you publish your + * work. Good starting points are: + * + * [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] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). + */ #define _LARGEFILE_SOURCE64 #define _FILE_OFFSET_BITS 64 @@ -67,10 +68,10 @@ #endif // is_mpi -namespace oopse { +namespace OpenMD { DumpReader::DumpReader(SimInfo* info, const std::string& filename) - : info_(info), filename_(filename), isScanned_(false), nframes_(0) { + : info_(info), filename_(filename), isScanned_(false), nframes_(0), needCOMprops_(false) { #ifdef IS_MPI @@ -92,7 +93,7 @@ namespace oopse { } strcpy(checkPointMsg, "Dump file opened for reading successfully."); - MPIcheckPoint(); + errorCheckPoint(); #endif @@ -113,7 +114,7 @@ namespace oopse { } strcpy(checkPointMsg, "Dump file closed successfully."); - MPIcheckPoint(); + errorCheckPoint(); #endif @@ -240,13 +241,29 @@ namespace oopse { } readSet(whichFrame); + + if (needCOMprops_) { + Snapshot* s = info_->getSnapshotManager()->getCurrentSnapshot(); + Vector3d com; + Vector3d comvel; + Vector3d comw; + if (needPos_ && needVel_){ + info_->getComAll(com, comvel); + comw = info_->getAngularMomentum(); + }else{ + com = info_->getCom(); + comvel = 0.0; + comw = 0.0; + } + s->setCOMprops(com, comvel, comw); + } + } void DumpReader::readSet(int whichFrame) { std::string line; #ifndef IS_MPI - inFile_->clear(); inFile_->seekg(framePos_[whichFrame]); @@ -280,8 +297,11 @@ namespace oopse { int sendBufferSize; MPI_Bcast(&sendBufferSize, 1, MPI_INT, masterNode, MPI_COMM_WORLD); char * recvBuffer = new char[sendBufferSize+1]; + assert(recvBuffer); + recvBuffer[sendBufferSize] = '\0'; MPI_Bcast(recvBuffer, sendBufferSize, MPI_CHAR, masterNode, MPI_COMM_WORLD); sstream.str(recvBuffer); + delete [] recvBuffer; } std::istream& inputStream = sstream; @@ -322,7 +342,7 @@ namespace oopse { nTokens = tokenizer.countTokens(); - if (nTokens < 2) { + if (nTokens < 2) { sprintf(painCave.errMsg, "DumpReader Error: Not enough Tokens.\n%s\n", line.c_str()); painCave.isFatal = 1; @@ -338,6 +358,35 @@ namespace oopse { } std::string type = tokenizer.nextToken(); int size = type.size(); + + size_t found; + + if (needPos_) { + found = type.find("p"); + if (found == std::string::npos) { + sprintf(painCave.errMsg, + "DumpReader Error: StuntDouble %d has no Position\n" + "\tField (\"p\") specified.\n%s\n", index, + line.c_str()); + painCave.isFatal = 1; + simError(); + } + } + + if (integrableObject->isDirectional()) { + if (needQuaternion_) { + found = type.find("q"); + if (found == std::string::npos) { + sprintf(painCave.errMsg, + "DumpReader Error: Directional StuntDouble %d has no\n" + "\tQuaternion Field (\"q\") specified.\n%s\n", index, + line.c_str()); + painCave.isFatal = 1; + simError(); + } + } + } + for(int i = 0; i < size; ++i) { switch(type[i]) { @@ -372,7 +421,7 @@ namespace oopse { q[3] = tokenizer.nextTokenAsDouble(); RealType qlen = q.length(); - if (qlen < oopse::epsilon) { //check quaternion is not equal to 0 + if (qlen < OpenMD::epsilon) { //check quaternion is not equal to 0 sprintf(painCave.errMsg, "DumpReader Error: initial quaternion error (q0^2 + q1^2 + q2^2 + q3^2) ~ 0\n"); @@ -398,6 +447,7 @@ namespace oopse { integrableObject->setJ(ji); } } + break; } case 'f': { @@ -417,6 +467,13 @@ namespace oopse { integrableObject->setTrq(torque); break; } + case 'u' : { + + RealType particlePot; + particlePot = tokenizer.nextTokenAsDouble(); + integrableObject->setParticlePot(particlePot); + break; + } default: { sprintf(painCave.errMsg, "DumpReader Error: %s is an unrecognized type\n", type.c_str()); @@ -528,4 +585,4 @@ namespace oopse { } -}//end namespace oopse +}//end namespace OpenMD