ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/SimCreator.cpp
(Generate patch)

Comparing:
trunk/src/brains/SimCreator.cpp (file contents), Revision 1241 by gezelter, Fri Apr 25 15:14:47 2008 UTC vs.
branches/development/src/brains/SimCreator.cpp (file contents), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

# Line 6 | Line 6
6   * redistribute this software in source and binary code form, provided
7   * that the following conditions are met:
8   *
9 < * 1. Acknowledgement of the program authors must be made in any
10 < *    publication of scientific results based in part on use of the
11 < *    program.  An acceptable form of acknowledgement is citation of
12 < *    the article in which the program was described (Matthew
13 < *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 < *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 < *    Parallel Simulation Engine for Molecular Dynamics,"
16 < *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 < *
18 < * 2. Redistributions of source code must retain the above copyright
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
12 > * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in the
14   *    documentation and/or other materials provided with the
15   *    distribution.
# Line 37 | Line 28
28   * arising out of the use of or inability to use software, even if the
29   * University of Notre Dame has been advised of the possibility of
30   * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
35 + *                                                                      
36 + * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 + * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 + * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 + * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 + * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43   /**
# Line 76 | Line 77
77   #include "antlr/NoViableAltException.hpp"
78  
79   #ifdef IS_MPI
80 + #include "mpi.h"
81   #include "math/ParallelRandNumGen.hpp"
82   #endif
83  
84 < namespace oopse {
84 > namespace OpenMD {
85    
86 <  Globals* SimCreator::parseFile(std::istream& rawMetaDataStream, const std::string& filename, int startOfMetaDataBlock ){
86 >  Globals* SimCreator::parseFile(std::istream& rawMetaDataStream, const std::string& filename, int mdFileVersion, int startOfMetaDataBlock ){
87      Globals* simParams = NULL;
88      try {
89  
# Line 92 | Line 94 | namespace oopse {
94        const int masterNode = 0;
95        int commStatus;
96        if (worldRank == masterNode) {
97 < #endif
98 <                
97 >        commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD);
98 > #endif                
99          SimplePreprocessor preprocessor;
100          preprocessor.preprocess(rawMetaDataStream, filename, startOfMetaDataBlock, ppStream);
101                  
# Line 106 | Line 108 | namespace oopse {
108              
109                  
110        } else {
111 +
112 +        commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD);
113 +
114          //get stream size
115          commStatus = MPI_Bcast(&streamSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD);  
116 <                
116 >
117          char* buf = new char[streamSize];
118          assert(buf);
119                  
# Line 116 | Line 121 | namespace oopse {
121          commStatus = MPI_Bcast(buf, streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD);
122                  
123          ppStream.str(buf);
124 <        delete buf;
124 >        delete [] buf;
125  
126        }
127   #endif            
# Line 145 | Line 150 | namespace oopse {
150        treeParser.initializeASTFactory(factory);
151        treeParser.setASTFactory(&factory);
152        simParams = treeParser.walkTree(parser.getAST());
148
153      }
154  
155        
# Line 215 | Line 219 | namespace oopse {
219        painCave.isFatal = 1;
220        simError();        
221      }
222 <    catch (OOPSEException& e) {
222 >    catch (OpenMDException& e) {
223        sprintf(painCave.errMsg,
224                "%s\n",
225                e.getMessage().c_str());
# Line 230 | Line 234 | namespace oopse {
234        simError();
235      }
236  
237 +    simParams->setMDfileVersion(mdFileVersion);
238      return simParams;
239    }
240    
241    SimInfo*  SimCreator::createSim(const std::string & mdFileName,
242                                    bool loadInitCoords) {
243 <
243 >    
244      const int bufferSize = 65535;
245      char buffer[bufferSize];
246      int lineNo = 0;
# Line 244 | Line 249 | namespace oopse {
249      int metaDataBlockEnd = -1;
250      int i;
251      int mdOffset;
252 +    int mdFileVersion;
253  
254   #ifdef IS_MPI            
255      const int masterNode = 0;
# Line 263 | Line 269 | namespace oopse {
269        mdFile_.getline(buffer, bufferSize);
270        ++lineNo;
271        std::string line = trimLeftCopy(buffer);
272 <      i = CaseInsensitiveFind(line, "<OOPSE");
273 <      if (i == string::npos) {
272 >      i = CaseInsensitiveFind(line, "<OpenMD");
273 >      if (static_cast<size_t>(i) == string::npos) {
274 >        // try the older file strings to see if that works:
275 >        i = CaseInsensitiveFind(line, "<OOPSE");
276 >      }
277 >      
278 >      if (static_cast<size_t>(i) == string::npos) {
279 >        // still no luck!
280          sprintf(painCave.errMsg,
281 <                "SimCreator: File: %s is not an OOPSE file!\n",
281 >                "SimCreator: File: %s is not a valid OpenMD file!\n",
282                  mdFileName.c_str());
283          painCave.isFatal = 1;
284          simError();
285        }
286 +      
287 +      // found the correct opening string, now try to get the file
288 +      // format version number.
289 +
290 +      StringTokenizer tokenizer(line, "=<> \t\n\r");
291 +      std::string fileType = tokenizer.nextToken();
292 +      toUpper(fileType);
293  
294 +      mdFileVersion = 0;
295 +
296 +      if (fileType == "OPENMD") {
297 +        while (tokenizer.hasMoreTokens()) {
298 +          std::string token(tokenizer.nextToken());
299 +          toUpper(token);
300 +          if (token == "VERSION") {
301 +            mdFileVersion = tokenizer.nextTokenAsInt();
302 +            break;
303 +          }
304 +        }
305 +      }
306 +            
307        //scan through the input stream and find MetaData tag        
308        while(mdFile_.getline(buffer, bufferSize)) {
309          ++lineNo;
# Line 327 | Line 359 | namespace oopse {
359      std::stringstream rawMetaDataStream(mdRawData);
360  
361      //parse meta-data file
362 <    Globals* simParams = parseFile(rawMetaDataStream, mdFileName, metaDataBlockStart+1);
362 >    Globals* simParams = parseFile(rawMetaDataStream, mdFileName, mdFileVersion,
363 >                                   metaDataBlockStart + 1);
364      
365      //create the force field
366 <    ForceField * ff = ForceFieldFactory::getInstance()
367 <      ->createForceField(simParams->getForceField());
335 <    
366 >    ForceField * ff = ForceFieldFactory::getInstance()->createForceField(simParams->getForceField());
367 >
368      if (ff == NULL) {
369        sprintf(painCave.errMsg,
370                "ForceField Factory can not create %s force field\n",
# Line 365 | Line 397 | namespace oopse {
397      }
398      
399      ff->parse(forcefieldFileName);
368    ff->setFortranForceOptions();
400      //create SimInfo
401      SimInfo * info = new SimInfo(ff, simParams);
402  
# Line 383 | Line 414 | namespace oopse {
414      //create the molecules
415      createMolecules(info);
416      
386    
417      //allocate memory for DataStorage(circular reference, need to
418      //break it)
419      info->setSnapshotManager(new SimSnapshotManager(info));
# Line 395 | Line 425 | namespace oopse {
425      //responsibility to LocalIndexManager.
426      setGlobalIndex(info);
427      
428 <    //Although addExcludePairs is called inside SimInfo's addMolecule
428 >    //Although addInteractionPairs is called inside SimInfo's addMolecule
429      //method, at that point atoms don't have the global index yet
430      //(their global index are all initialized to -1).  Therefore we
431 <    //have to call addExcludePairs explicitly here. A way to work
431 >    //have to call addInteractionPairs explicitly here. A way to work
432      //around is that we can determine the beginning global indices of
433      //atoms before they get created.
434      SimInfo::MoleculeIterator mi;
435      Molecule* mol;
436      for (mol= info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {
437 <      info->addExcludePairs(mol);
437 >      info->addInteractionPairs(mol);
438      }
439      
440      if (loadInitCoords)
441        loadCoordinates(info, mdFileName);    
412    
442      return info;
443    }
444    
# Line 473 | Line 502 | namespace oopse {
502                "\tthe number of molecules.  This will not result in a \n"
503                "\tusable division of atoms for force decomposition.\n"
504                "\tEither try a smaller number of processors, or run the\n"
505 <              "\tsingle-processor version of OOPSE.\n", nProcessors, nGlobalMols);
505 >              "\tsingle-processor version of OpenMD.\n", nProcessors, nGlobalMols);
506        
507        painCave.isFatal = 1;
508        simError();
# Line 608 | Line 637 | namespace oopse {
637   #endif
638          
639          stampId = info->getMoleculeStampId(i);
640 <        Molecule * mol = molCreator.createMolecule(info->getForceField(), info->getMoleculeStamp(stampId),
641 <                                                   stampId, i, info->getLocalIndexManager());
640 >        Molecule * mol = molCreator.createMolecule(info->getForceField(),
641 >                                                   info->getMoleculeStamp(stampId),
642 >                                                   stampId, i,
643 >                                                   info->getLocalIndexManager());
644          
645          info->addMolecule(mol);
646          
# Line 636 | Line 667 | namespace oopse {
667      int beginRigidBodyIndex;
668      int beginCutoffGroupIndex;
669      int nGlobalAtoms = info->getNGlobalAtoms();
639
640    /**@todo fixme */
641 #ifndef IS_MPI
670      
671      beginAtomIndex = 0;
672      beginRigidBodyIndex = 0;
673      beginCutoffGroupIndex = 0;
674 <    
675 < #else
648 <    
649 <    int nproc;
650 <    int myNode;
651 <    
652 <    myNode = worldRank;
653 <    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
654 <    
655 <    std::vector < int > tmpAtomsInProc(nproc, 0);
656 <    std::vector < int > tmpRigidBodiesInProc(nproc, 0);
657 <    std::vector < int > tmpCutoffGroupsInProc(nproc, 0);
658 <    std::vector < int > NumAtomsInProc(nproc, 0);
659 <    std::vector < int > NumRigidBodiesInProc(nproc, 0);
660 <    std::vector < int > NumCutoffGroupsInProc(nproc, 0);
661 <    
662 <    tmpAtomsInProc[myNode] = info->getNAtoms();
663 <    tmpRigidBodiesInProc[myNode] = info->getNRigidBodies();
664 <    tmpCutoffGroupsInProc[myNode] = info->getNCutoffGroups();
665 <    
666 <    //do MPI_ALLREDUCE to exchange the total number of atoms, rigidbodies and cutoff groups
667 <    MPI_Allreduce(&tmpAtomsInProc[0], &NumAtomsInProc[0], nproc, MPI_INT,
668 <                  MPI_SUM, MPI_COMM_WORLD);
669 <    MPI_Allreduce(&tmpRigidBodiesInProc[0], &NumRigidBodiesInProc[0], nproc,
670 <                  MPI_INT, MPI_SUM, MPI_COMM_WORLD);
671 <    MPI_Allreduce(&tmpCutoffGroupsInProc[0], &NumCutoffGroupsInProc[0], nproc,
672 <                  MPI_INT, MPI_SUM, MPI_COMM_WORLD);
673 <    
674 <    beginAtomIndex = 0;
675 <    beginRigidBodyIndex = 0;
676 <    beginCutoffGroupIndex = 0;
677 <    
678 <    for(int i = 0; i < myNode; i++) {
679 <      beginAtomIndex += NumAtomsInProc[i];
680 <      beginRigidBodyIndex += NumRigidBodiesInProc[i];
681 <      beginCutoffGroupIndex += NumCutoffGroupsInProc[i];
682 <    }
683 <    
684 < #endif
685 <    
686 <    //rigidbody's index begins right after atom's
687 <    beginRigidBodyIndex += info->getNGlobalAtoms();
688 <    
689 <    for(mol = info->beginMolecule(mi); mol != NULL;
690 <        mol = info->nextMolecule(mi)) {
674 >
675 >    for(int i = 0; i < info->getNGlobalMolecules(); i++) {
676        
677 <      //local index(index in DataStorge) of atom is important
678 <      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
679 <        atom->setGlobalIndex(beginAtomIndex++);
677 > #ifdef IS_MPI      
678 >      if (info->getMolToProc(i) == worldRank) {
679 > #endif        
680 >        // stuff to do if I own this molecule
681 >        mol = info->getMoleculeByGlobalIndex(i);
682 >
683 >        //local index(index in DataStorge) of atom is important
684 >        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
685 >          atom->setGlobalIndex(beginAtomIndex++);
686 >        }
687 >        
688 >        for(rb = mol->beginRigidBody(ri); rb != NULL;
689 >            rb = mol->nextRigidBody(ri)) {
690 >          rb->setGlobalIndex(beginRigidBodyIndex++);
691 >        }
692 >        
693 >        //local index of cutoff group is trivial, it only depends on
694 >        //the order of travesing
695 >        for(cg = mol->beginCutoffGroup(ci); cg != NULL;
696 >            cg = mol->nextCutoffGroup(ci)) {
697 >          cg->setGlobalIndex(beginCutoffGroupIndex++);
698 >        }        
699 >        
700 > #ifdef IS_MPI        
701 >      }  else {
702 >
703 >        // stuff to do if I don't own this molecule
704 >        
705 >        int stampId = info->getMoleculeStampId(i);
706 >        MoleculeStamp* stamp = info->getMoleculeStamp(stampId);
707 >
708 >        beginAtomIndex += stamp->getNAtoms();
709 >        beginRigidBodyIndex += stamp->getNRigidBodies();
710 >        beginCutoffGroupIndex += stamp->getNCutoffGroups() + stamp->getNFreeAtoms();
711        }
712 <      
713 <      for(rb = mol->beginRigidBody(ri); rb != NULL;
714 <          rb = mol->nextRigidBody(ri)) {
715 <        rb->setGlobalIndex(beginRigidBodyIndex++);
700 <      }
701 <      
702 <      //local index of cutoff group is trivial, it only depends on the order of travesing
703 <      for(cg = mol->beginCutoffGroup(ci); cg != NULL;
704 <          cg = mol->nextCutoffGroup(ci)) {
705 <        cg->setGlobalIndex(beginCutoffGroupIndex++);
706 <      }
707 <    }
708 <    
712 > #endif          
713 >
714 >    } //end for(int i=0)  
715 >
716      //fill globalGroupMembership
717      std::vector<int> globalGroupMembership(info->getNGlobalAtoms(), 0);
718      for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {        
# Line 717 | Line 724 | namespace oopse {
724          
725        }      
726      }
727 <    
727 >  
728   #ifdef IS_MPI    
729      // Since the globalGroupMembership has been zero filled and we've only
730      // poked values into the atoms we know, we can do an Allreduce
731      // to get the full globalGroupMembership array (We think).
732      // This would be prettier if we could use MPI_IN_PLACE like the MPI-2
733      // docs said we could.
734 <    std::vector<int> tmpGroupMembership(nGlobalAtoms, 0);
734 >    std::vector<int> tmpGroupMembership(info->getNGlobalAtoms(), 0);
735      MPI_Allreduce(&globalGroupMembership[0], &tmpGroupMembership[0], nGlobalAtoms,
736                    MPI_INT, MPI_SUM, MPI_COMM_WORLD);
737      info->setGlobalGroupMembership(tmpGroupMembership);
# Line 736 | Line 743 | namespace oopse {
743      std::vector<int> globalMolMembership(info->getNGlobalAtoms(), 0);
744      
745      for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {
739      
746        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
747          globalMolMembership[atom->getGlobalIndex()] = mol->getGlobalIndex();
748        }
749      }
750      
751   #ifdef IS_MPI
752 <    std::vector<int> tmpMolMembership(nGlobalAtoms, 0);
752 >    std::vector<int> tmpMolMembership(info->getNGlobalAtoms(), 0);
753      
754      MPI_Allreduce(&globalMolMembership[0], &tmpMolMembership[0], nGlobalAtoms,
755                    MPI_INT, MPI_SUM, MPI_COMM_WORLD);
# Line 769 | Line 775 | namespace oopse {
775      std::vector<int> numIntegrableObjectsPerMol = nIOPerMol;
776   #endif    
777  
778 < std::vector<int> startingIOIndexForMol(info->getNGlobalMolecules());
779 <
780 < int startingIndex = 0;
781 < for (int i = 0; i < info->getNGlobalMolecules(); i++) {
782 <  startingIOIndexForMol[i] = startingIndex;
783 <  startingIndex += numIntegrableObjectsPerMol[i];
784 < }
785 <
786 < std::vector<StuntDouble*> IOIndexToIntegrableObject(info->getNGlobalIntegrableObjects(), (StuntDouble*)NULL);
787 < for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {
778 >    std::vector<int> startingIOIndexForMol(info->getNGlobalMolecules());
779 >    
780 >    int startingIndex = 0;
781 >    for (int i = 0; i < info->getNGlobalMolecules(); i++) {
782 >      startingIOIndexForMol[i] = startingIndex;
783 >      startingIndex += numIntegrableObjectsPerMol[i];
784 >    }
785 >    
786 >    std::vector<StuntDouble*> IOIndexToIntegrableObject(info->getNGlobalIntegrableObjects(), (StuntDouble*)NULL);
787 >    for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {
788        int myGlobalIndex = mol->getGlobalIndex();
789        int globalIO = startingIOIndexForMol[myGlobalIndex];
790        for (StuntDouble* integrableObject = mol->beginIntegrableObject(ioi); integrableObject != NULL;
791             integrableObject = mol->nextIntegrableObject(ioi)) {
792 <            integrableObject->setGlobalIntegrableObjectIndex(globalIO);
793 <            IOIndexToIntegrableObject[globalIO] = integrableObject;
794 <            globalIO++;
792 >        integrableObject->setGlobalIntegrableObjectIndex(globalIO);
793 >        IOIndexToIntegrableObject[globalIO] = integrableObject;
794 >        globalIO++;
795        }
796      }
797 <
798 <  info->setIOIndexToIntegrableObject(IOIndexToIntegrableObject);
799 <  
797 >      
798 >    info->setIOIndexToIntegrableObject(IOIndexToIntegrableObject);
799 >    
800    }
801    
802    void SimCreator::loadCoordinates(SimInfo* info, const std::string& mdFileName) {
803      Globals* simParams;
804 +
805      simParams = info->getSimParams();
806      
800    
807      DumpReader reader(info, mdFileName);
808      int nframes = reader.getNFrames();
809 <    
809 >
810      if (nframes > 0) {
811        reader.readFrame(nframes - 1);
812      } else {
# Line 811 | Line 817 | int startingIndex = 0;
817        painCave.isFatal = 1;
818        simError();
819      }
814    
820      //copy the current snapshot to previous snapshot
821      info->getSnapshotManager()->advance();
822    }
823    
824 < } //end namespace oopse
824 > } //end namespace OpenMD
825  
826  

Comparing:
trunk/src/brains/SimCreator.cpp (property svn:keywords), Revision 1241 by gezelter, Fri Apr 25 15:14:47 2008 UTC vs.
branches/development/src/brains/SimCreator.cpp (property svn:keywords), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines