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 1613 by gezelter, Thu Aug 18 20:18:19 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]  Vardeman & Gezelter, in progress (2009).                        
40   */
41  
42   /**
# Line 79 | Line 79
79   #include "math/ParallelRandNumGen.hpp"
80   #endif
81  
82 < namespace oopse {
82 > namespace OpenMD {
83    
84 <  Globals* SimCreator::parseFile(std::istream& rawMetaDataStream, const std::string& filename, int startOfMetaDataBlock ){
84 >  Globals* SimCreator::parseFile(std::istream& rawMetaDataStream, const std::string& filename, int mdFileVersion, int startOfMetaDataBlock ){
85      Globals* simParams = NULL;
86      try {
87  
# Line 92 | Line 92 | namespace oopse {
92        const int masterNode = 0;
93        int commStatus;
94        if (worldRank == masterNode) {
95 < #endif
96 <                
95 >        commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD);
96 > #endif                
97          SimplePreprocessor preprocessor;
98          preprocessor.preprocess(rawMetaDataStream, filename, startOfMetaDataBlock, ppStream);
99                  
# Line 106 | Line 106 | namespace oopse {
106              
107                  
108        } else {
109 +
110 +        commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD);
111 +
112          //get stream size
113          commStatus = MPI_Bcast(&streamSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD);  
114 <                
114 >
115          char* buf = new char[streamSize];
116          assert(buf);
117                  
# Line 116 | Line 119 | namespace oopse {
119          commStatus = MPI_Bcast(buf, streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD);
120                  
121          ppStream.str(buf);
122 <        delete buf;
122 >        delete [] buf;
123  
124        }
125   #endif            
# Line 145 | Line 148 | namespace oopse {
148        treeParser.initializeASTFactory(factory);
149        treeParser.setASTFactory(&factory);
150        simParams = treeParser.walkTree(parser.getAST());
148
151      }
152  
153        
# Line 215 | Line 217 | namespace oopse {
217        painCave.isFatal = 1;
218        simError();        
219      }
220 <    catch (OOPSEException& e) {
220 >    catch (OpenMDException& e) {
221        sprintf(painCave.errMsg,
222                "%s\n",
223                e.getMessage().c_str());
# Line 230 | Line 232 | namespace oopse {
232        simError();
233      }
234  
235 +    simParams->setMDfileVersion(mdFileVersion);
236      return simParams;
237    }
238    
239    SimInfo*  SimCreator::createSim(const std::string & mdFileName,
240                                    bool loadInitCoords) {
241 <
241 >    
242      const int bufferSize = 65535;
243      char buffer[bufferSize];
244      int lineNo = 0;
# Line 244 | Line 247 | namespace oopse {
247      int metaDataBlockEnd = -1;
248      int i;
249      int mdOffset;
250 +    int mdFileVersion;
251  
252   #ifdef IS_MPI            
253      const int masterNode = 0;
# Line 263 | Line 267 | namespace oopse {
267        mdFile_.getline(buffer, bufferSize);
268        ++lineNo;
269        std::string line = trimLeftCopy(buffer);
270 <      i = CaseInsensitiveFind(line, "<OOPSE");
271 <      if (i == string::npos) {
270 >      i = CaseInsensitiveFind(line, "<OpenMD");
271 >      if (static_cast<size_t>(i) == string::npos) {
272 >        // try the older file strings to see if that works:
273 >        i = CaseInsensitiveFind(line, "<OOPSE");
274 >      }
275 >      
276 >      if (static_cast<size_t>(i) == string::npos) {
277 >        // still no luck!
278          sprintf(painCave.errMsg,
279 <                "SimCreator: File: %s is not an OOPSE file!\n",
279 >                "SimCreator: File: %s is not a valid OpenMD file!\n",
280                  mdFileName.c_str());
281          painCave.isFatal = 1;
282          simError();
283        }
284 +      
285 +      // found the correct opening string, now try to get the file
286 +      // format version number.
287  
288 +      StringTokenizer tokenizer(line, "=<> \t\n\r");
289 +      std::string fileType = tokenizer.nextToken();
290 +      toUpper(fileType);
291 +
292 +      mdFileVersion = 0;
293 +
294 +      if (fileType == "OPENMD") {
295 +        while (tokenizer.hasMoreTokens()) {
296 +          std::string token(tokenizer.nextToken());
297 +          toUpper(token);
298 +          if (token == "VERSION") {
299 +            mdFileVersion = tokenizer.nextTokenAsInt();
300 +            break;
301 +          }
302 +        }
303 +      }
304 +            
305        //scan through the input stream and find MetaData tag        
306        while(mdFile_.getline(buffer, bufferSize)) {
307          ++lineNo;
# Line 327 | Line 357 | namespace oopse {
357      std::stringstream rawMetaDataStream(mdRawData);
358  
359      //parse meta-data file
360 <    Globals* simParams = parseFile(rawMetaDataStream, mdFileName, metaDataBlockStart+1);
360 >    Globals* simParams = parseFile(rawMetaDataStream, mdFileName, mdFileVersion,
361 >                                   metaDataBlockStart + 1);
362      
363      //create the force field
364 <    ForceField * ff = ForceFieldFactory::getInstance()
365 <      ->createForceField(simParams->getForceField());
335 <    
364 >    ForceField * ff = ForceFieldFactory::getInstance()->createForceField(simParams->getForceField());
365 >
366      if (ff == NULL) {
367        sprintf(painCave.errMsg,
368                "ForceField Factory can not create %s force field\n",
# Line 365 | Line 395 | namespace oopse {
395      }
396      
397      ff->parse(forcefieldFileName);
368    ff->setFortranForceOptions();
398      //create SimInfo
399      SimInfo * info = new SimInfo(ff, simParams);
400  
# Line 383 | Line 412 | namespace oopse {
412      //create the molecules
413      createMolecules(info);
414      
386    
415      //allocate memory for DataStorage(circular reference, need to
416      //break it)
417      info->setSnapshotManager(new SimSnapshotManager(info));
# Line 395 | Line 423 | namespace oopse {
423      //responsibility to LocalIndexManager.
424      setGlobalIndex(info);
425      
426 <    //Although addExcludePairs is called inside SimInfo's addMolecule
426 >    //Although addInteractionPairs is called inside SimInfo's addMolecule
427      //method, at that point atoms don't have the global index yet
428      //(their global index are all initialized to -1).  Therefore we
429 <    //have to call addExcludePairs explicitly here. A way to work
429 >    //have to call addInteractionPairs explicitly here. A way to work
430      //around is that we can determine the beginning global indices of
431      //atoms before they get created.
432      SimInfo::MoleculeIterator mi;
433      Molecule* mol;
434      for (mol= info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {
435 <      info->addExcludePairs(mol);
435 >      info->addInteractionPairs(mol);
436      }
437      
438      if (loadInitCoords)
439        loadCoordinates(info, mdFileName);    
412    
440      return info;
441    }
442    
# Line 473 | Line 500 | namespace oopse {
500                "\tthe number of molecules.  This will not result in a \n"
501                "\tusable division of atoms for force decomposition.\n"
502                "\tEither try a smaller number of processors, or run the\n"
503 <              "\tsingle-processor version of OOPSE.\n", nProcessors, nGlobalMols);
503 >              "\tsingle-processor version of OpenMD.\n", nProcessors, nGlobalMols);
504        
505        painCave.isFatal = 1;
506        simError();
# Line 608 | Line 635 | namespace oopse {
635   #endif
636          
637          stampId = info->getMoleculeStampId(i);
638 <        Molecule * mol = molCreator.createMolecule(info->getForceField(), info->getMoleculeStamp(stampId),
639 <                                                   stampId, i, info->getLocalIndexManager());
638 >        Molecule * mol = molCreator.createMolecule(info->getForceField(),
639 >                                                   info->getMoleculeStamp(stampId),
640 >                                                   stampId, i,
641 >                                                   info->getLocalIndexManager());
642          
643          info->addMolecule(mol);
644          
# Line 636 | Line 665 | namespace oopse {
665      int beginRigidBodyIndex;
666      int beginCutoffGroupIndex;
667      int nGlobalAtoms = info->getNGlobalAtoms();
639
640    /**@todo fixme */
641 #ifndef IS_MPI
668      
669      beginAtomIndex = 0;
670      beginRigidBodyIndex = 0;
671      beginCutoffGroupIndex = 0;
672 <    
673 < #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)) {
672 >
673 >    for(int i = 0; i < info->getNGlobalMolecules(); i++) {
674        
675 <      //local index(index in DataStorge) of atom is important
676 <      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
677 <        atom->setGlobalIndex(beginAtomIndex++);
675 > #ifdef IS_MPI      
676 >      if (info->getMolToProc(i) == worldRank) {
677 > #endif        
678 >        // stuff to do if I own this molecule
679 >        mol = info->getMoleculeByGlobalIndex(i);
680 >
681 >        //local index(index in DataStorge) of atom is important
682 >        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
683 >          atom->setGlobalIndex(beginAtomIndex++);
684 >        }
685 >        
686 >        for(rb = mol->beginRigidBody(ri); rb != NULL;
687 >            rb = mol->nextRigidBody(ri)) {
688 >          rb->setGlobalIndex(beginRigidBodyIndex++);
689 >        }
690 >        
691 >        //local index of cutoff group is trivial, it only depends on
692 >        //the order of travesing
693 >        for(cg = mol->beginCutoffGroup(ci); cg != NULL;
694 >            cg = mol->nextCutoffGroup(ci)) {
695 >          cg->setGlobalIndex(beginCutoffGroupIndex++);
696 >        }        
697 >        
698 > #ifdef IS_MPI        
699 >      }  else {
700 >
701 >        // stuff to do if I don't own this molecule
702 >        
703 >        int stampId = info->getMoleculeStampId(i);
704 >        MoleculeStamp* stamp = info->getMoleculeStamp(stampId);
705 >
706 >        beginAtomIndex += stamp->getNAtoms();
707 >        beginRigidBodyIndex += stamp->getNRigidBodies();
708 >        beginCutoffGroupIndex += stamp->getNCutoffGroups() + stamp->getNFreeAtoms();
709        }
710 <      
711 <      for(rb = mol->beginRigidBody(ri); rb != NULL;
712 <          rb = mol->nextRigidBody(ri)) {
713 <        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 <    
710 > #endif          
711 >
712 >    } //end for(int i=0)  
713 >
714      //fill globalGroupMembership
715      std::vector<int> globalGroupMembership(info->getNGlobalAtoms(), 0);
716      for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {        
# Line 717 | Line 722 | namespace oopse {
722          
723        }      
724      }
725 <    
725 >  
726   #ifdef IS_MPI    
727      // Since the globalGroupMembership has been zero filled and we've only
728      // poked values into the atoms we know, we can do an Allreduce
729      // to get the full globalGroupMembership array (We think).
730      // This would be prettier if we could use MPI_IN_PLACE like the MPI-2
731      // docs said we could.
732 <    std::vector<int> tmpGroupMembership(nGlobalAtoms, 0);
732 >    std::vector<int> tmpGroupMembership(info->getNGlobalAtoms(), 0);
733      MPI_Allreduce(&globalGroupMembership[0], &tmpGroupMembership[0], nGlobalAtoms,
734                    MPI_INT, MPI_SUM, MPI_COMM_WORLD);
735      info->setGlobalGroupMembership(tmpGroupMembership);
# Line 736 | Line 741 | namespace oopse {
741      std::vector<int> globalMolMembership(info->getNGlobalAtoms(), 0);
742      
743      for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {
739      
744        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
745          globalMolMembership[atom->getGlobalIndex()] = mol->getGlobalIndex();
746        }
747      }
748      
749   #ifdef IS_MPI
750 <    std::vector<int> tmpMolMembership(nGlobalAtoms, 0);
750 >    std::vector<int> tmpMolMembership(info->getNGlobalAtoms(), 0);
751      
752      MPI_Allreduce(&globalMolMembership[0], &tmpMolMembership[0], nGlobalAtoms,
753                    MPI_INT, MPI_SUM, MPI_COMM_WORLD);
# Line 769 | Line 773 | namespace oopse {
773      std::vector<int> numIntegrableObjectsPerMol = nIOPerMol;
774   #endif    
775  
776 < std::vector<int> startingIOIndexForMol(info->getNGlobalMolecules());
777 <
778 < int startingIndex = 0;
779 < for (int i = 0; i < info->getNGlobalMolecules(); i++) {
780 <  startingIOIndexForMol[i] = startingIndex;
781 <  startingIndex += numIntegrableObjectsPerMol[i];
782 < }
783 <
784 < std::vector<StuntDouble*> IOIndexToIntegrableObject(info->getNGlobalIntegrableObjects(), (StuntDouble*)NULL);
785 < for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {
776 >    std::vector<int> startingIOIndexForMol(info->getNGlobalMolecules());
777 >    
778 >    int startingIndex = 0;
779 >    for (int i = 0; i < info->getNGlobalMolecules(); i++) {
780 >      startingIOIndexForMol[i] = startingIndex;
781 >      startingIndex += numIntegrableObjectsPerMol[i];
782 >    }
783 >    
784 >    std::vector<StuntDouble*> IOIndexToIntegrableObject(info->getNGlobalIntegrableObjects(), (StuntDouble*)NULL);
785 >    for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {
786        int myGlobalIndex = mol->getGlobalIndex();
787        int globalIO = startingIOIndexForMol[myGlobalIndex];
788        for (StuntDouble* integrableObject = mol->beginIntegrableObject(ioi); integrableObject != NULL;
789             integrableObject = mol->nextIntegrableObject(ioi)) {
790 <            integrableObject->setGlobalIntegrableObjectIndex(globalIO);
791 <            IOIndexToIntegrableObject[globalIO] = integrableObject;
792 <            globalIO++;
790 >        integrableObject->setGlobalIntegrableObjectIndex(globalIO);
791 >        IOIndexToIntegrableObject[globalIO] = integrableObject;
792 >        globalIO++;
793        }
794      }
795 <
796 <  info->setIOIndexToIntegrableObject(IOIndexToIntegrableObject);
797 <  
795 >      
796 >    info->setIOIndexToIntegrableObject(IOIndexToIntegrableObject);
797 >    
798    }
799    
800    void SimCreator::loadCoordinates(SimInfo* info, const std::string& mdFileName) {
801      Globals* simParams;
802 +
803      simParams = info->getSimParams();
804      
800    
805      DumpReader reader(info, mdFileName);
806      int nframes = reader.getNFrames();
807 <    
807 >
808      if (nframes > 0) {
809        reader.readFrame(nframes - 1);
810      } else {
# Line 811 | Line 815 | int startingIndex = 0;
815        painCave.isFatal = 1;
816        simError();
817      }
814    
818      //copy the current snapshot to previous snapshot
819      info->getSnapshotManager()->advance();
820    }
821    
822 < } //end namespace oopse
822 > } //end namespace OpenMD
823  
824  

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 1613 by gezelter, Thu Aug 18 20:18:19 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines