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

Comparing branches/development/src/brains/SimCreator.cpp (file contents):
Revision 1465 by chuckv, Fri Jul 9 23:08:25 2010 UTC vs.
Revision 1613 by gezelter, Thu Aug 18 20:18:19 2011 UTC

# Line 81 | Line 81 | namespace OpenMD {
81  
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 OpenMD {
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 OpenMD {
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  
# Line 229 | Line 232 | namespace OpenMD {
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 243 | Line 247 | namespace OpenMD {
247      int metaDataBlockEnd = -1;
248      int i;
249      int mdOffset;
250 +    int mdFileVersion;
251  
252   #ifdef IS_MPI            
253      const int masterNode = 0;
# Line 276 | Line 281 | namespace OpenMD {
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 332 | Line 357 | namespace OpenMD {
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()->createForceField(simParams->getForceField());
# Line 369 | Line 395 | namespace OpenMD {
395      }
396      
397      ff->parse(forcefieldFileName);
372    ff->setFortranForceOptions();
398      //create SimInfo
399      SimInfo * info = new SimInfo(ff, simParams);
400  
# Line 387 | Line 412 | namespace OpenMD {
412      //create the molecules
413      createMolecules(info);
414      
390    
415      //allocate memory for DataStorage(circular reference, need to
416      //break it)
417      info->setSnapshotManager(new SimSnapshotManager(info));
# Line 413 | Line 437 | namespace OpenMD {
437      
438      if (loadInitCoords)
439        loadCoordinates(info, mdFileName);    
416    
440      return info;
441    }
442    
# Line 612 | Line 635 | namespace OpenMD {
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 640 | Line 665 | namespace OpenMD {
665      int beginRigidBodyIndex;
666      int beginCutoffGroupIndex;
667      int nGlobalAtoms = info->getNGlobalAtoms();
643
644    /**@todo fixme */
645 #ifndef IS_MPI
668      
669      beginAtomIndex = 0;
670      beginRigidBodyIndex = 0;
671      beginCutoffGroupIndex = 0;
672 <    
673 < #else
652 <    
653 <    int nproc;
654 <    int myNode;
655 <    
656 <    myNode = worldRank;
657 <    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
658 <    
659 <    std::vector < int > tmpAtomsInProc(nproc, 0);
660 <    std::vector < int > tmpRigidBodiesInProc(nproc, 0);
661 <    std::vector < int > tmpCutoffGroupsInProc(nproc, 0);
662 <    std::vector < int > NumAtomsInProc(nproc, 0);
663 <    std::vector < int > NumRigidBodiesInProc(nproc, 0);
664 <    std::vector < int > NumCutoffGroupsInProc(nproc, 0);
665 <    
666 <    tmpAtomsInProc[myNode] = info->getNAtoms();
667 <    tmpRigidBodiesInProc[myNode] = info->getNRigidBodies();
668 <    tmpCutoffGroupsInProc[myNode] = info->getNCutoffGroups();
669 <    
670 <    //do MPI_ALLREDUCE to exchange the total number of atoms, rigidbodies and cutoff groups
671 <    MPI_Allreduce(&tmpAtomsInProc[0], &NumAtomsInProc[0], nproc, MPI_INT,
672 <                  MPI_SUM, MPI_COMM_WORLD);
673 <    MPI_Allreduce(&tmpRigidBodiesInProc[0], &NumRigidBodiesInProc[0], nproc,
674 <                  MPI_INT, MPI_SUM, MPI_COMM_WORLD);
675 <    MPI_Allreduce(&tmpCutoffGroupsInProc[0], &NumCutoffGroupsInProc[0], nproc,
676 <                  MPI_INT, MPI_SUM, MPI_COMM_WORLD);
677 <    
678 <    beginAtomIndex = 0;
679 <    beginRigidBodyIndex = 0;
680 <    beginCutoffGroupIndex = 0;
681 <    
682 <    for(int i = 0; i < myNode; i++) {
683 <      beginAtomIndex += NumAtomsInProc[i];
684 <      beginRigidBodyIndex += NumRigidBodiesInProc[i];
685 <      beginCutoffGroupIndex += NumCutoffGroupsInProc[i];
686 <    }
687 <    
688 < #endif
689 <    
690 <    //rigidbody's index begins right after atom's
691 <    beginRigidBodyIndex += info->getNGlobalAtoms();
692 <    
693 <    for(mol = info->beginMolecule(mi); mol != NULL;
694 <        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++);
704 <      }
705 <      
706 <      //local index of cutoff group is trivial, it only depends on the order of travesing
707 <      for(cg = mol->beginCutoffGroup(ci); cg != NULL;
708 <          cg = mol->nextCutoffGroup(ci)) {
709 <        cg->setGlobalIndex(beginCutoffGroupIndex++);
710 <      }
711 <    }
712 <    
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 721 | Line 722 | namespace OpenMD {
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
# Line 791 | Line 792 | namespace OpenMD {
792          globalIO++;
793        }
794      }
795 <    
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      
803    
805      DumpReader reader(info, mdFileName);
806      int nframes = reader.getNFrames();
807 <    
807 >
808      if (nframes > 0) {
809        reader.readFrame(nframes - 1);
810      } else {
# Line 814 | Line 815 | namespace OpenMD {
815        painCave.isFatal = 1;
816        simError();
817      }
817    
818      //copy the current snapshot to previous snapshot
819      info->getSnapshotManager()->advance();
820    }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines