--- trunk/src/brains/SimCreator.cpp 2010/05/10 17:28:26 1442 +++ trunk/src/brains/SimCreator.cpp 2015/03/07 21:41:51 2071 @@ -35,17 +35,23 @@ * * [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). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ /** * @file SimCreator.cpp * @author tlin * @date 11/03/2004 - * @time 13:51am * @version 1.0 */ + +#ifdef IS_MPI +#include "mpi.h" +#include "math/ParallelRandNumGen.hpp" +#endif + #include #include #include @@ -55,9 +61,10 @@ #include "brains/SimCreator.hpp" #include "brains/SimSnapshotManager.hpp" #include "io/DumpReader.hpp" -#include "UseTheForce/ForceFieldFactory.hpp" +#include "brains/ForceField.hpp" #include "utils/simError.h" #include "utils/StringUtils.hpp" +#include "utils/Revision.hpp" #include "math/SeqRandNumGen.hpp" #include "mdParser/MDLexer.hpp" #include "mdParser/MDParser.hpp" @@ -75,13 +82,18 @@ #include "antlr/NoViableAltForCharException.hpp" #include "antlr/NoViableAltException.hpp" -#ifdef IS_MPI -#include "math/ParallelRandNumGen.hpp" -#endif +#include "types/DirectionalAdapter.hpp" +#include "types/MultipoleAdapter.hpp" +#include "types/EAMAdapter.hpp" +#include "types/SuttonChenAdapter.hpp" +#include "types/PolarizableAdapter.hpp" +#include "types/FixedChargeAdapter.hpp" +#include "types/FluctuatingChargeAdapter.hpp" + namespace OpenMD { - Globals* SimCreator::parseFile(std::istream& rawMetaDataStream, const std::string& filename, int startOfMetaDataBlock ){ + Globals* SimCreator::parseFile(std::istream& rawMetaDataStream, const std::string& filename, int mdFileVersion, int startOfMetaDataBlock ){ Globals* simParams = NULL; try { @@ -90,34 +102,34 @@ namespace OpenMD { #ifdef IS_MPI int streamSize; const int masterNode = 0; - int commStatus; + if (worldRank == masterNode) { -#endif - + MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD); +#endif SimplePreprocessor preprocessor; - preprocessor.preprocess(rawMetaDataStream, filename, startOfMetaDataBlock, ppStream); + preprocessor.preprocess(rawMetaDataStream, filename, + startOfMetaDataBlock, ppStream); #ifdef IS_MPI - //brocasting the stream size + //broadcasting the stream size streamSize = ppStream.str().size() +1; - commStatus = MPI_Bcast(&streamSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD); - - commStatus = MPI_Bcast(static_cast(const_cast(ppStream.str().c_str())), streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD); - - + MPI_Bcast(&streamSize, 1, MPI_INT, masterNode, MPI_COMM_WORLD); + MPI_Bcast(static_cast(const_cast(ppStream.str().c_str())), + streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD); } else { - //get stream size - commStatus = MPI_Bcast(&streamSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD); + MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD); + + //get stream size + MPI_Bcast(&streamSize, 1, MPI_INT, masterNode, MPI_COMM_WORLD); char* buf = new char[streamSize]; assert(buf); //receive file content - commStatus = MPI_Bcast(buf, streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD); - + MPI_Bcast(buf, streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD); + ppStream.str(buf); delete [] buf; - } #endif // Create a scanner that reads from the input stream @@ -139,7 +151,6 @@ namespace OpenMD { parser.initializeASTFactory(factory); parser.setASTFactory(&factory); parser.mdfile(); - // Create a tree parser that reads information into Globals MDTreeParser treeParser; treeParser.initializeASTFactory(factory); @@ -217,7 +228,7 @@ namespace OpenMD { catch (OpenMDException& e) { sprintf(painCave.errMsg, "%s\n", - e.getMessage().c_str()); + e.what()); painCave.isFatal = 1; simError(); } @@ -229,27 +240,47 @@ namespace OpenMD { simError(); } + simParams->setMDfileVersion(mdFileVersion); return simParams; } SimInfo* SimCreator::createSim(const std::string & mdFileName, bool loadInitCoords) { - + const int bufferSize = 65535; char buffer[bufferSize]; int lineNo = 0; std::string mdRawData; int metaDataBlockStart = -1; int metaDataBlockEnd = -1; - int i; - int mdOffset; + streamoff mdOffset; + int mdFileVersion(2); + + // Create a string for embedding the version information in the MetaData + std::string version; + version.assign("## Last run using OpenMD Version: "); + version.append(OPENMD_VERSION_MAJOR); + version.append("."); + version.append(OPENMD_VERSION_MINOR); + std::string svnrev(g_REVISION, strnlen(g_REVISION, 20)); + //convert a macro from compiler to a string in c++ + // STR_DEFINE(svnrev, SVN_REV ); + version.append(" Revision: "); + // If there's no SVN revision, just call this the RELEASE revision. + if (!svnrev.empty()) { + version.append(svnrev); + } else { + version.append("RELEASE"); + } + #ifdef IS_MPI const int masterNode = 0; if (worldRank == masterNode) { #endif - std::ifstream mdFile_(mdFileName.c_str()); + std::ifstream mdFile_; + mdFile_.open(mdFileName.c_str(), ifstream::in | ifstream::binary); if (mdFile_.fail()) { sprintf(painCave.errMsg, @@ -262,13 +293,13 @@ namespace OpenMD { mdFile_.getline(buffer, bufferSize); ++lineNo; std::string line = trimLeftCopy(buffer); - i = CaseInsensitiveFind(line, "(i) == string::npos) { + std::size_t i = CaseInsensitiveFind(line, "(i) == string::npos) { + if (i == string::npos) { // still no luck! sprintf(painCave.errMsg, "SimCreator: File: %s is not a valid OpenMD file!\n", @@ -276,20 +307,40 @@ namespace OpenMD { painCave.isFatal = 1; simError(); } + + // found the correct opening string, now try to get the file + // format version number. + StringTokenizer tokenizer(line, "=<> \t\n\r"); + std::string fileType = tokenizer.nextToken(); + toUpper(fileType); + + mdFileVersion = 0; + + if (fileType == "OPENMD") { + while (tokenizer.hasMoreTokens()) { + std::string token(tokenizer.nextToken()); + toUpper(token); + if (token == "VERSION") { + mdFileVersion = tokenizer.nextTokenAsInt(); + break; + } + } + } + //scan through the input stream and find MetaData tag while(mdFile_.getline(buffer, bufferSize)) { ++lineNo; std::string line = trimLeftCopy(buffer); if (metaDataBlockStart == -1) { - i = CaseInsensitiveFind(line, ""); + std::size_t i = CaseInsensitiveFind(line, ""); if (i != string::npos) { metaDataBlockStart = lineNo; mdOffset = mdFile_.tellg(); } } else { - i = CaseInsensitiveFind(line, ""); + std::size_t i = CaseInsensitiveFind(line, ""); if (i != string::npos) { metaDataBlockEnd = lineNo; } @@ -317,12 +368,24 @@ namespace OpenMD { mdRawData.clear(); + bool foundVersion = false; + for (int i = 0; i < metaDataBlockEnd - metaDataBlockStart - 1; ++i) { mdFile_.getline(buffer, bufferSize); - mdRawData += buffer; + std::string line = trimLeftCopy(buffer); + std::size_t j = CaseInsensitiveFind(line, + "## Last run using OpenMD Version"); + if (j != string::npos) { + foundVersion = true; + mdRawData += version; + } else { + mdRawData += buffer; + } mdRawData += "\n"; } - + + if (!foundVersion) mdRawData += version + "\n"; + mdFile_.close(); #ifdef IS_MPI @@ -332,10 +395,11 @@ namespace OpenMD { std::stringstream rawMetaDataStream(mdRawData); //parse meta-data file - Globals* simParams = parseFile(rawMetaDataStream, mdFileName, metaDataBlockStart+1); + Globals* simParams = parseFile(rawMetaDataStream, mdFileName, mdFileVersion, + metaDataBlockStart + 1); //create the force field - ForceField * ff = ForceFieldFactory::getInstance()->createForceField(simParams->getForceField()); + ForceField * ff = new ForceField(simParams->getForceField()); if (ff == NULL) { sprintf(painCave.errMsg, @@ -369,7 +433,6 @@ namespace OpenMD { } ff->parse(forcefieldFileName); - ff->setFortranForceOptions(); //create SimInfo SimInfo * info = new SimInfo(ff, simParams); @@ -387,10 +450,13 @@ namespace OpenMD { //create the molecules createMolecules(info); - + //find the storage layout + + int storageLayout = computeStorageLayout(info); + //allocate memory for DataStorage(circular reference, need to //break it) - info->setSnapshotManager(new SimSnapshotManager(info)); + info->setSnapshotManager(new SimSnapshotManager(info, storageLayout)); //set the global index of atoms, rigidbodies and cutoffgroups //(only need to be set once, the global index will never change @@ -413,7 +479,6 @@ namespace OpenMD { if (loadInitCoords) loadCoordinates(info, mdFileName); - return info; } @@ -448,27 +513,15 @@ namespace OpenMD { #ifdef IS_MPI void SimCreator::divideMolecules(SimInfo *info) { - RealType numerator; - RealType denominator; - RealType precast; - RealType x; - RealType y; RealType a; - int old_atoms; - int add_atoms; - int new_atoms; - int nTarget; - int done; - int i; - int j; - int loops; - int which_proc; int nProcessors; std::vector atomsPerProc; int nGlobalMols = info->getNGlobalMolecules(); - std::vector molToProcMap(nGlobalMols, -1); // default to an error condition: + std::vector molToProcMap(nGlobalMols, -1); // default to an + // error + // condition: - MPI_Comm_size(MPI_COMM_WORLD, &nProcessors); + MPI_Comm_size( MPI_COMM_WORLD, &nProcessors); if (nProcessors > nGlobalMols) { sprintf(painCave.errMsg, @@ -477,17 +530,18 @@ namespace OpenMD { "\tthe number of molecules. This will not result in a \n" "\tusable division of atoms for force decomposition.\n" "\tEither try a smaller number of processors, or run the\n" - "\tsingle-processor version of OpenMD.\n", nProcessors, nGlobalMols); + "\tsingle-processor version of OpenMD.\n", nProcessors, + nGlobalMols); painCave.isFatal = 1; simError(); } - int seedValue; Globals * simParams = info->getSimParams(); - SeqRandNumGen* myRandom; //divide labor does not need Parallel random number generator + SeqRandNumGen* myRandom; //divide labor does not need Parallel + //random number generator if (simParams->haveSeed()) { - seedValue = simParams->getSeed(); + int seedValue = simParams->getSeed(); myRandom = new SeqRandNumGen(seedValue); }else { myRandom = new SeqRandNumGen(); @@ -500,43 +554,46 @@ namespace OpenMD { atomsPerProc.insert(atomsPerProc.end(), nProcessors, 0); if (worldRank == 0) { - numerator = info->getNGlobalAtoms(); - denominator = nProcessors; - precast = numerator / denominator; - nTarget = (int)(precast + 0.5); + RealType numerator = info->getNGlobalAtoms(); + RealType denominator = nProcessors; + RealType precast = numerator / denominator; + int nTarget = (int)(precast + 0.5); - for(i = 0; i < nGlobalMols; i++) { - done = 0; - loops = 0; + for(int i = 0; i < nGlobalMols; i++) { + + int done = 0; + int loops = 0; while (!done) { loops++; // Pick a processor at random - which_proc = (int) (myRandom->rand() * nProcessors); + int which_proc = (int) (myRandom->rand() * nProcessors); //get the molecule stamp first int stampId = info->getMoleculeStampId(i); MoleculeStamp * moleculeStamp = info->getMoleculeStamp(stampId); // How many atoms does this processor have so far? - old_atoms = atomsPerProc[which_proc]; - add_atoms = moleculeStamp->getNAtoms(); - new_atoms = old_atoms + add_atoms; + int old_atoms = atomsPerProc[which_proc]; + int add_atoms = moleculeStamp->getNAtoms(); + int new_atoms = old_atoms + add_atoms; // If we've been through this loop too many times, we need // to just give up and assign the molecule to this processor // and be done with it. if (loops > 100) { + sprintf(painCave.errMsg, - "I've tried 100 times to assign molecule %d to a " - " processor, but can't find a good spot.\n" - "I'm assigning it at random to processor %d.\n", + "There have been 100 attempts to assign molecule %d to an\n" + "\tunderworked processor, but there's no good place to\n" + "\tleave it. OpenMD is assigning it at random to processor %d.\n", i, which_proc); - + painCave.isFatal = 0; + painCave.severity = OPENMD_INFO; simError(); molToProcMap[i] = which_proc; @@ -565,8 +622,8 @@ namespace OpenMD { // Pacc(x) = exp(- a * x) // where a = penalty / (average atoms per molecule) - x = (RealType)(new_atoms - nTarget); - y = myRandom->rand(); + RealType x = (RealType)(new_atoms - nTarget); + RealType y = myRandom->rand(); if (y < exp(- a * x)) { molToProcMap[i] = which_proc; @@ -581,15 +638,15 @@ namespace OpenMD { } delete myRandom; - + // Spray out this nonsense to all other processors: - MPI_Bcast(&molToProcMap[0], nGlobalMols, MPI_INT, 0, MPI_COMM_WORLD); + } else { // Listen to your marching orders from processor 0: - MPI_Bcast(&molToProcMap[0], nGlobalMols, MPI_INT, 0, MPI_COMM_WORLD); + } info->setMolToProcMap(molToProcMap); @@ -612,8 +669,10 @@ namespace OpenMD { #endif stampId = info->getMoleculeStampId(i); - Molecule * mol = molCreator.createMolecule(info->getForceField(), info->getMoleculeStamp(stampId), - stampId, i, info->getLocalIndexManager()); + Molecule * mol = molCreator.createMolecule(info->getForceField(), + info->getMoleculeStamp(stampId), + stampId, i, + info->getLocalIndexManager()); info->addMolecule(mol); @@ -626,102 +685,243 @@ namespace OpenMD { } //end for(int i=0) } + int SimCreator::computeStorageLayout(SimInfo* info) { + + Globals* simParams = info->getSimParams(); + int nRigidBodies = info->getNGlobalRigidBodies(); + set atomTypes = info->getSimulatedAtomTypes(); + set::iterator i; + bool hasDirectionalAtoms = false; + bool hasFixedCharge = false; + bool hasDipoles = false; + bool hasQuadrupoles = false; + bool hasPolarizable = false; + bool hasFluctuatingCharge = false; + bool hasMetallic = false; + int storageLayout = 0; + storageLayout |= DataStorage::dslPosition; + storageLayout |= DataStorage::dslVelocity; + storageLayout |= DataStorage::dslForce; + + for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { + + DirectionalAdapter da = DirectionalAdapter( (*i) ); + MultipoleAdapter ma = MultipoleAdapter( (*i) ); + EAMAdapter ea = EAMAdapter( (*i) ); + SuttonChenAdapter sca = SuttonChenAdapter( (*i) ); + PolarizableAdapter pa = PolarizableAdapter( (*i) ); + FixedChargeAdapter fca = FixedChargeAdapter( (*i) ); + FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter( (*i) ); + + if (da.isDirectional()){ + hasDirectionalAtoms = true; + } + if (ma.isDipole()){ + hasDipoles = true; + } + if (ma.isQuadrupole()){ + hasQuadrupoles = true; + } + if (ea.isEAM() || sca.isSuttonChen()){ + hasMetallic = true; + } + if ( fca.isFixedCharge() ){ + hasFixedCharge = true; + } + if ( fqa.isFluctuatingCharge() ){ + hasFluctuatingCharge = true; + } + if ( pa.isPolarizable() ){ + hasPolarizable = true; + } + } + + if (nRigidBodies > 0 || hasDirectionalAtoms) { + storageLayout |= DataStorage::dslAmat; + if(storageLayout & DataStorage::dslVelocity) { + storageLayout |= DataStorage::dslAngularMomentum; + } + if (storageLayout & DataStorage::dslForce) { + storageLayout |= DataStorage::dslTorque; + } + } + if (hasDipoles) { + storageLayout |= DataStorage::dslDipole; + } + if (hasQuadrupoles) { + storageLayout |= DataStorage::dslQuadrupole; + } + if (hasFixedCharge || hasFluctuatingCharge) { + storageLayout |= DataStorage::dslSkippedCharge; + } + if (hasMetallic) { + storageLayout |= DataStorage::dslDensity; + storageLayout |= DataStorage::dslFunctional; + storageLayout |= DataStorage::dslFunctionalDerivative; + } + if (hasPolarizable) { + storageLayout |= DataStorage::dslElectricField; + } + if (hasFluctuatingCharge){ + storageLayout |= DataStorage::dslFlucQPosition; + if(storageLayout & DataStorage::dslVelocity) { + storageLayout |= DataStorage::dslFlucQVelocity; + } + if (storageLayout & DataStorage::dslForce) { + storageLayout |= DataStorage::dslFlucQForce; + } + } + + // if the user has asked for them, make sure we've got the memory for the + // objects defined. + + if (simParams->getOutputParticlePotential()) { + storageLayout |= DataStorage::dslParticlePot; + } + + if (simParams->havePrintHeatFlux()) { + if (simParams->getPrintHeatFlux()) { + storageLayout |= DataStorage::dslParticlePot; + } + } + + if (simParams->getOutputElectricField() | + simParams->haveElectricField() | simParams->haveUniformField() | + simParams->haveUniformGradientStrength() | + simParams->haveUniformGradientDirection1() | + simParams->haveUniformGradientDirection2() ) { + storageLayout |= DataStorage::dslElectricField; + } + + if (simParams->getOutputSitePotential() ) { + storageLayout |= DataStorage::dslSitePotential; + } + + if (simParams->getOutputFluctuatingCharges()) { + storageLayout |= DataStorage::dslFlucQPosition; + storageLayout |= DataStorage::dslFlucQVelocity; + storageLayout |= DataStorage::dslFlucQForce; + } + + info->setStorageLayout(storageLayout); + + return storageLayout; + } + void SimCreator::setGlobalIndex(SimInfo *info) { SimInfo::MoleculeIterator mi; Molecule::AtomIterator ai; Molecule::RigidBodyIterator ri; Molecule::CutoffGroupIterator ci; + Molecule::BondIterator boi; + Molecule::BendIterator bei; + Molecule::TorsionIterator ti; + Molecule::InversionIterator ii; Molecule::IntegrableObjectIterator ioi; - Molecule * mol; - Atom * atom; - RigidBody * rb; - CutoffGroup * cg; + Molecule* mol; + Atom* atom; + RigidBody* rb; + CutoffGroup* cg; + Bond* bond; + Bend* bend; + Torsion* torsion; + Inversion* inversion; int beginAtomIndex; int beginRigidBodyIndex; int beginCutoffGroupIndex; + int beginBondIndex; + int beginBendIndex; + int beginTorsionIndex; + int beginInversionIndex; +#ifdef IS_MPI int nGlobalAtoms = info->getNGlobalAtoms(); - - /**@todo fixme */ -#ifndef IS_MPI + int nGlobalRigidBodies = info->getNGlobalRigidBodies(); +#endif beginAtomIndex = 0; - beginRigidBodyIndex = 0; + // The rigid body indices begin immediately after the atom indices: + beginRigidBodyIndex = info->getNGlobalAtoms(); beginCutoffGroupIndex = 0; - -#else - - int nproc; - int myNode; - - myNode = worldRank; - MPI_Comm_size(MPI_COMM_WORLD, &nproc); - - std::vector < int > tmpAtomsInProc(nproc, 0); - std::vector < int > tmpRigidBodiesInProc(nproc, 0); - std::vector < int > tmpCutoffGroupsInProc(nproc, 0); - std::vector < int > NumAtomsInProc(nproc, 0); - std::vector < int > NumRigidBodiesInProc(nproc, 0); - std::vector < int > NumCutoffGroupsInProc(nproc, 0); - - tmpAtomsInProc[myNode] = info->getNAtoms(); - tmpRigidBodiesInProc[myNode] = info->getNRigidBodies(); - tmpCutoffGroupsInProc[myNode] = info->getNCutoffGroups(); - - //do MPI_ALLREDUCE to exchange the total number of atoms, rigidbodies and cutoff groups - MPI_Allreduce(&tmpAtomsInProc[0], &NumAtomsInProc[0], nproc, MPI_INT, - MPI_SUM, MPI_COMM_WORLD); - MPI_Allreduce(&tmpRigidBodiesInProc[0], &NumRigidBodiesInProc[0], nproc, - MPI_INT, MPI_SUM, MPI_COMM_WORLD); - MPI_Allreduce(&tmpCutoffGroupsInProc[0], &NumCutoffGroupsInProc[0], nproc, - MPI_INT, MPI_SUM, MPI_COMM_WORLD); - - beginAtomIndex = 0; - beginRigidBodyIndex = 0; - beginCutoffGroupIndex = 0; - - for(int i = 0; i < myNode; i++) { - beginAtomIndex += NumAtomsInProc[i]; - beginRigidBodyIndex += NumRigidBodiesInProc[i]; - beginCutoffGroupIndex += NumCutoffGroupsInProc[i]; - } - -#endif - - //rigidbody's index begins right after atom's - beginRigidBodyIndex += info->getNGlobalAtoms(); - - for(mol = info->beginMolecule(mi); mol != NULL; - mol = info->nextMolecule(mi)) { + beginBondIndex = 0; + beginBendIndex = 0; + beginTorsionIndex = 0; + beginInversionIndex = 0; + + for(int i = 0; i < info->getNGlobalMolecules(); i++) { - //local index(index in DataStorge) of atom is important - for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { - atom->setGlobalIndex(beginAtomIndex++); +#ifdef IS_MPI + if (info->getMolToProc(i) == worldRank) { +#endif + // stuff to do if I own this molecule + mol = info->getMoleculeByGlobalIndex(i); + + // The local index(index in DataStorge) of the atom is important: + for(atom = mol->beginAtom(ai); atom != NULL; + atom = mol->nextAtom(ai)) { + atom->setGlobalIndex(beginAtomIndex++); + } + + for(rb = mol->beginRigidBody(ri); rb != NULL; + rb = mol->nextRigidBody(ri)) { + rb->setGlobalIndex(beginRigidBodyIndex++); + } + + // The local index of other objects only depends on the order + // of traversal: + for(cg = mol->beginCutoffGroup(ci); cg != NULL; + cg = mol->nextCutoffGroup(ci)) { + cg->setGlobalIndex(beginCutoffGroupIndex++); + } + for(bond = mol->beginBond(boi); bond != NULL; + bond = mol->nextBond(boi)) { + bond->setGlobalIndex(beginBondIndex++); + } + for(bend = mol->beginBend(bei); bend != NULL; + bend = mol->nextBend(bei)) { + bend->setGlobalIndex(beginBendIndex++); + } + for(torsion = mol->beginTorsion(ti); torsion != NULL; + torsion = mol->nextTorsion(ti)) { + torsion->setGlobalIndex(beginTorsionIndex++); + } + for(inversion = mol->beginInversion(ii); inversion != NULL; + inversion = mol->nextInversion(ii)) { + inversion->setGlobalIndex(beginInversionIndex++); + } + +#ifdef IS_MPI + } else { + + // stuff to do if I don't own this molecule + + int stampId = info->getMoleculeStampId(i); + MoleculeStamp* stamp = info->getMoleculeStamp(stampId); + + beginAtomIndex += stamp->getNAtoms(); + beginRigidBodyIndex += stamp->getNRigidBodies(); + beginCutoffGroupIndex += stamp->getNCutoffGroups() + stamp->getNFreeAtoms(); + beginBondIndex += stamp->getNBonds(); + beginBendIndex += stamp->getNBends(); + beginTorsionIndex += stamp->getNTorsions(); + beginInversionIndex += stamp->getNInversions(); } - - for(rb = mol->beginRigidBody(ri); rb != NULL; - rb = mol->nextRigidBody(ri)) { - rb->setGlobalIndex(beginRigidBodyIndex++); - } - - //local index of cutoff group is trivial, it only depends on the order of travesing - for(cg = mol->beginCutoffGroup(ci); cg != NULL; - cg = mol->nextCutoffGroup(ci)) { - cg->setGlobalIndex(beginCutoffGroupIndex++); - } - } - +#endif + + } //end for(int i=0) + //fill globalGroupMembership std::vector globalGroupMembership(info->getNGlobalAtoms(), 0); - for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { - for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { - + for(mol = info->beginMolecule(mi); mol != NULL; + mol = info->nextMolecule(mi)) { + for (cg = mol->beginCutoffGroup(ci); cg != NULL; + cg = mol->nextCutoffGroup(ci)) { for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { globalGroupMembership[atom->getGlobalIndex()] = cg->getGlobalIndex(); } } } - + #ifdef IS_MPI // Since the globalGroupMembership has been zero filled and we've only // poked values into the atoms we know, we can do an Allreduce @@ -729,26 +929,35 @@ namespace OpenMD { // This would be prettier if we could use MPI_IN_PLACE like the MPI-2 // docs said we could. std::vector tmpGroupMembership(info->getNGlobalAtoms(), 0); - MPI_Allreduce(&globalGroupMembership[0], &tmpGroupMembership[0], nGlobalAtoms, + MPI_Allreduce(&globalGroupMembership[0], + &tmpGroupMembership[0], nGlobalAtoms, MPI_INT, MPI_SUM, MPI_COMM_WORLD); + info->setGlobalGroupMembership(tmpGroupMembership); #else info->setGlobalGroupMembership(globalGroupMembership); #endif //fill molMembership - std::vector globalMolMembership(info->getNGlobalAtoms(), 0); + std::vector globalMolMembership(info->getNGlobalAtoms() + + info->getNGlobalRigidBodies(), 0); - for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { + for(mol = info->beginMolecule(mi); mol != NULL; + mol = info->nextMolecule(mi)) { for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { globalMolMembership[atom->getGlobalIndex()] = mol->getGlobalIndex(); } + for (rb = mol->beginRigidBody(ri); rb != NULL; + rb = mol->nextRigidBody(ri)) { + globalMolMembership[rb->getGlobalIndex()] = mol->getGlobalIndex(); + } } #ifdef IS_MPI - std::vector tmpMolMembership(info->getNGlobalAtoms(), 0); - - MPI_Allreduce(&globalMolMembership[0], &tmpMolMembership[0], nGlobalAtoms, + std::vector tmpMolMembership(info->getNGlobalAtoms() + + info->getNGlobalRigidBodies(), 0); + MPI_Allreduce(&globalMolMembership[0], &tmpMolMembership[0], + nGlobalAtoms + nGlobalRigidBodies, MPI_INT, MPI_SUM, MPI_COMM_WORLD); info->setGlobalMolMembership(tmpMolMembership); @@ -760,14 +969,15 @@ namespace OpenMD { // here the molecules are listed by their global indices. std::vector nIOPerMol(info->getNGlobalMolecules(), 0); - for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { + for (mol = info->beginMolecule(mi); mol != NULL; + mol = info->nextMolecule(mi)) { nIOPerMol[mol->getGlobalIndex()] = mol->getNIntegrableObjects(); } #ifdef IS_MPI std::vector numIntegrableObjectsPerMol(info->getNGlobalMolecules(), 0); MPI_Allreduce(&nIOPerMol[0], &numIntegrableObjectsPerMol[0], - info->getNGlobalMolecules(), MPI_INT, MPI_SUM, MPI_COMM_WORLD); + info->getNGlobalMolecules(), MPI_INT, MPI_SUM, MPI_COMM_WORLD); #else std::vector numIntegrableObjectsPerMol = nIOPerMol; #endif @@ -781,26 +991,24 @@ namespace OpenMD { } std::vector IOIndexToIntegrableObject(info->getNGlobalIntegrableObjects(), (StuntDouble*)NULL); - for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { + for (mol = info->beginMolecule(mi); mol != NULL; + mol = info->nextMolecule(mi)) { int myGlobalIndex = mol->getGlobalIndex(); int globalIO = startingIOIndexForMol[myGlobalIndex]; - for (StuntDouble* integrableObject = mol->beginIntegrableObject(ioi); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ioi)) { - integrableObject->setGlobalIntegrableObjectIndex(globalIO); - IOIndexToIntegrableObject[globalIO] = integrableObject; + for (StuntDouble* sd = mol->beginIntegrableObject(ioi); sd != NULL; + sd = mol->nextIntegrableObject(ioi)) { + sd->setGlobalIntegrableObjectIndex(globalIO); + IOIndexToIntegrableObject[globalIO] = sd; globalIO++; } } - + info->setIOIndexToIntegrableObject(IOIndexToIntegrableObject); } void SimCreator::loadCoordinates(SimInfo* info, const std::string& mdFileName) { - Globals* simParams; - simParams = info->getSimParams(); - DumpReader reader(info, mdFileName); int nframes = reader.getNFrames(); @@ -814,7 +1022,6 @@ namespace OpenMD { painCave.isFatal = 1; simError(); } - //copy the current snapshot to previous snapshot info->getSnapshotManager()->advance(); }