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

Comparing branches/development/src/brains/SimInfo.cpp (file contents):
Revision 1553 by gezelter, Fri Apr 29 17:25:12 2011 UTC vs.
Revision 1627 by gezelter, Tue Sep 13 22:05:04 2011 UTC

# Line 60 | Line 60
60   #include "io/ForceFieldOptions.hpp"
61   #include "UseTheForce/ForceField.hpp"
62   #include "nonbonded/SwitchingFunction.hpp"
63 + #ifdef IS_MPI
64 + #include <mpi.h>
65 + #endif
66  
67   using namespace std;
68   namespace OpenMD {
# Line 71 | Line 74 | namespace OpenMD {
74      nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0),
75      nAtoms_(0), nBonds_(0),  nBends_(0), nTorsions_(0), nInversions_(0),
76      nRigidBodies_(0), nIntegrableObjects_(0), nCutoffGroups_(0),
77 <    nConstraints_(0), sman_(NULL), fortranInitialized_(false),
77 >    nConstraints_(0), sman_(NULL), topologyDone_(false),
78      calcBoxDipole_(false), useAtomicVirial_(true) {    
79      
80      MoleculeStamp* molStamp;
# Line 125 | Line 128 | namespace OpenMD {
128      //equal to the total number of atoms minus number of atoms belong to
129      //cutoff group defined in meta-data file plus the number of cutoff
130      //groups defined in meta-data file
128    std::cerr << "nGA = " << nGlobalAtoms_ << "\n";
129    std::cerr << "nCA = " << nCutoffAtoms << "\n";
130    std::cerr << "nG = " << nGroups << "\n";
131  
132      nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups;
133
134    std::cerr << "nGCG = " << nGlobalCutoffGroups_ << "\n";
133      
134      //every free atom (atom does not belong to rigid bodies) is an
135      //integrable object therefore the total number of integrable objects
# Line 273 | Line 271 | namespace OpenMD {
271      fdf_ = fdf_local;
272   #endif
273      return fdf_;
274 +  }
275 +  
276 +  unsigned int SimInfo::getNLocalCutoffGroups(){
277 +    int nLocalCutoffAtoms = 0;
278 +    Molecule* mol;
279 +    MoleculeIterator mi;
280 +    CutoffGroup* cg;
281 +    Molecule::CutoffGroupIterator ci;
282 +    
283 +    for (mol = beginMolecule(mi); mol != NULL; mol  = nextMolecule(mi)) {
284 +      
285 +      for (cg = mol->beginCutoffGroup(ci); cg != NULL;
286 +           cg = mol->nextCutoffGroup(ci)) {
287 +        nLocalCutoffAtoms += cg->getNumAtom();
288 +        
289 +      }        
290 +    }
291 +    
292 +    return nAtoms_ - nLocalCutoffAtoms + nCutoffGroups_;
293    }
294      
295    void SimInfo::calcNdfRaw() {
# Line 680 | Line 697 | namespace OpenMD {
697      Atom* atom;
698      set<AtomType*> atomTypes;
699      
700 <    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {      
701 <      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
700 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
701 >      for(atom = mol->beginAtom(ai); atom != NULL;
702 >          atom = mol->nextAtom(ai)) {
703          atomTypes.insert(atom->getAtomType());
704        }      
705      }    
706 <
706 >    
707   #ifdef IS_MPI
708  
709      // loop over the found atom types on this processor, and add their
710      // numerical idents to a vector:
711 <
711 >    
712      vector<int> foundTypes;
713      set<AtomType*>::iterator i;
714      for (i = atomTypes.begin(); i != atomTypes.end(); ++i)
# Line 699 | Line 717 | namespace OpenMD {
717      // count_local holds the number of found types on this processor
718      int count_local = foundTypes.size();
719  
702    // count holds the total number of found types on all processors
703    // (some will be redundant with the ones found locally):
704    int count;
705    MPI::COMM_WORLD.Allreduce(&count_local, &count, 1, MPI::INT, MPI::SUM);
706
707    // create a vector to hold the globally found types, and resize it:
708    vector<int> ftGlobal;
709    ftGlobal.resize(count);
710    vector<int> counts;
711
720      int nproc = MPI::COMM_WORLD.Get_size();
713    counts.resize(nproc);
714    vector<int> disps;
715    disps.resize(nproc);
721  
722 <    // now spray out the foundTypes to all the other processors:
722 >    // we need arrays to hold the counts and displacement vectors for
723 >    // all processors
724 >    vector<int> counts(nproc, 0);
725 >    vector<int> disps(nproc, 0);
726 >
727 >    // fill the counts array
728 >    MPI::COMM_WORLD.Allgather(&count_local, 1, MPI::INT, &counts[0],
729 >                              1, MPI::INT);
730 >  
731 >    // use the processor counts to compute the displacement array
732 >    disps[0] = 0;    
733 >    int totalCount = counts[0];
734 >    for (int iproc = 1; iproc < nproc; iproc++) {
735 >      disps[iproc] = disps[iproc-1] + counts[iproc-1];
736 >      totalCount += counts[iproc];
737 >    }
738 >
739 >    // we need a (possibly redundant) set of all found types:
740 >    vector<int> ftGlobal(totalCount);
741      
742 +    // now spray out the foundTypes to all the other processors:    
743      MPI::COMM_WORLD.Allgatherv(&foundTypes[0], count_local, MPI::INT,
744 <                               &ftGlobal[0], &counts[0], &disps[0], MPI::INT);
744 >                               &ftGlobal[0], &counts[0], &disps[0],
745 >                               MPI::INT);
746  
747 +    vector<int>::iterator j;
748 +
749      // foundIdents is a stl set, so inserting an already found ident
750      // will have no effect.
751      set<int> foundIdents;
752 <    vector<int>::iterator j;
752 >
753      for (j = ftGlobal.begin(); j != ftGlobal.end(); ++j)
754        foundIdents.insert((*j));
755      
756      // now iterate over the foundIdents and get the actual atom types
757      // that correspond to these:
758      set<int>::iterator it;
759 <    for (it = foundIdents.begin(); it != foundIdents.end(); ++it)
759 >    for (it = foundIdents.begin(); it != foundIdents.end(); ++it)
760        atomTypes.insert( forceField_->getAtomType((*it)) );
761  
762   #endif
763 <    
763 >
764      return atomTypes;        
765    }
766  
# Line 745 | Line 772 | namespace OpenMD {
772        if ( simParams_->getAccumulateBoxDipole() ) {
773          calcBoxDipole_ = true;      
774        }
775 <
775 >    
776      set<AtomType*>::iterator i;
777      set<AtomType*> atomTypes;
778      atomTypes = getSimulatedAtomTypes();    
# Line 758 | Line 785 | namespace OpenMD {
785        usesMetallic |= (*i)->isMetal();
786        usesDirectional |= (*i)->isDirectional();
787      }
788 <
788 >    
789   #ifdef IS_MPI    
790      int temp;
791      temp = usesDirectional;
792      MPI_Allreduce(&temp, &usesDirectionalAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
793 <
793 >    
794      temp = usesMetallic;
795      MPI_Allreduce(&temp, &usesMetallicAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
796 <
796 >    
797      temp = usesElectrostatic;
798      MPI_Allreduce(&temp, &usesElectrostaticAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
799 + #else
800 +
801 +    usesDirectionalAtoms_ = usesDirectional;
802 +    usesMetallicAtoms_ = usesMetallic;
803 +    usesElectrostaticAtoms_ = usesElectrostatic;
804 +
805   #endif
806 +    
807 +    requiresPrepair_ = usesMetallicAtoms_ ? true : false;
808 +    requiresSkipCorrection_ = usesElectrostaticAtoms_ ? true : false;
809 +    requiresSelfCorrection_ = usesElectrostaticAtoms_ ? true : false;    
810    }
811  
812  
# Line 812 | Line 849 | namespace OpenMD {
849    }
850  
851  
852 <  void SimInfo::setupFortran() {
816 <    int isError;
852 >  void SimInfo::prepareTopology() {
853      int nExclude, nOneTwo, nOneThree, nOneFour;
818    vector<int> fortranGlobalGroupMembership;
819    
820    isError = 0;
821
822    //globalGroupMembership_ is filled by SimCreator    
823    for (int i = 0; i < nGlobalAtoms_; i++) {
824      fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1);
825    }
854  
855      //calculate mass ratio of cutoff group
828    vector<RealType> mfact;
856      SimInfo::MoleculeIterator mi;
857      Molecule* mol;
858      Molecule::CutoffGroupIterator ci;
# Line 834 | Line 861 | namespace OpenMD {
861      Atom* atom;
862      RealType totalMass;
863  
864 <    //to avoid memory reallocation, reserve enough space for mfact
865 <    mfact.reserve(getNCutoffGroups());
864 >    /**
865 >     * The mass factor is the relative mass of an atom to the total
866 >     * mass of the cutoff group it belongs to.  By default, all atoms
867 >     * are their own cutoff groups, and therefore have mass factors of
868 >     * 1.  We need some special handling for massless atoms, which
869 >     * will be treated as carrying the entire mass of the cutoff
870 >     * group.
871 >     */
872 >    massFactors_.clear();
873 >    massFactors_.resize(getNAtoms(), 1.0);
874      
875      for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
876 <      for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
876 >      for (cg = mol->beginCutoffGroup(ci); cg != NULL;
877 >           cg = mol->nextCutoffGroup(ci)) {
878  
879          totalMass = cg->getMass();
880          for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
881            // Check for massless groups - set mfact to 1 if true
882 <          if (totalMass != 0)
883 <            mfact.push_back(atom->getMass()/totalMass);
882 >          if (totalMass != 0)
883 >            massFactors_[atom->getLocalIndex()] = atom->getMass()/totalMass;
884            else
885 <            mfact.push_back( 1.0 );
885 >            massFactors_[atom->getLocalIndex()] = 1.0;
886          }
887        }      
888      }
# Line 860 | Line 896 | namespace OpenMD {
896          identArray_.push_back(atom->getIdent());
897        }
898      }    
863
864    //fill molMembershipArray
865    //molMembershipArray is filled by SimCreator    
866    vector<int> molMembershipArray(nGlobalAtoms_);
867    for (int i = 0; i < nGlobalAtoms_; i++) {
868      molMembershipArray[i] = globalMolMembership_[i] + 1;
869    }
899      
900 <    //setup fortran simulation
900 >    //scan topology
901  
902      nExclude = excludedInteractions_.getSize();
903      nOneTwo = oneTwoInteractions_.getSize();
# Line 880 | Line 909 | namespace OpenMD {
909      int* oneThreeList = oneThreeInteractions_.getPairList();
910      int* oneFourList = oneFourInteractions_.getPairList();
911  
912 <    //setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray_[0],
884 <    //               &nExclude, excludeList,
885 <    //               &nOneTwo, oneTwoList,
886 <    //               &nOneThree, oneThreeList,
887 <    //               &nOneFour, oneFourList,
888 <    //               &molMembershipArray[0], &mfact[0], &nCutoffGroups_,
889 <    //               &fortranGlobalGroupMembership[0], &isError);
890 <    
891 <    // if( isError ){
892 <    //  
893 <    //  sprintf( painCave.errMsg,
894 <    //         "There was an error setting the simulation information in fortran.\n" );
895 <    //  painCave.isFatal = 1;
896 <    //  painCave.severity = OPENMD_ERROR;
897 <    //  simError();
898 <    //}
899 <    
900 <    
901 <    // sprintf( checkPointMsg,
902 <    //          "succesfully sent the simulation information to fortran.\n");
903 <    
904 <    // errorCheckPoint();
905 <    
906 <    // Setup number of neighbors in neighbor list if present
907 <    //if (simParams_->haveNeighborListNeighbors()) {
908 <    //  int nlistNeighbors = simParams_->getNeighborListNeighbors();
909 <    //  setNeighbors(&nlistNeighbors);
910 <    //}
911 <  
912 < #ifdef IS_MPI    
913 <    // mpiSimData parallelData;
914 <
915 <    //fill up mpiSimData struct
916 <    // parallelData.nMolGlobal = getNGlobalMolecules();
917 <    // parallelData.nMolLocal = getNMolecules();
918 <    // parallelData.nAtomsGlobal = getNGlobalAtoms();
919 <    // parallelData.nAtomsLocal = getNAtoms();
920 <    // parallelData.nGroupsGlobal = getNGlobalCutoffGroups();
921 <    // parallelData.nGroupsLocal = getNCutoffGroups();
922 <    // parallelData.myNode = worldRank;
923 <    // MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors));
924 <
925 <    //pass mpiSimData struct and index arrays to fortran
926 <    //setFsimParallel(&parallelData, &(parallelData.nAtomsLocal),
927 <    //                &localToGlobalAtomIndex[0],  &(parallelData.nGroupsLocal),
928 <    //                &localToGlobalCutoffGroupIndex[0], &isError);
929 <
930 <    // if (isError) {
931 <    //   sprintf(painCave.errMsg,
932 <    //           "mpiRefresh errror: fortran didn't like something we gave it.\n");
933 <    //   painCave.isFatal = 1;
934 <    //   simError();
935 <    // }
936 <
937 <    // sprintf(checkPointMsg, " mpiRefresh successful.\n");
938 <    // errorCheckPoint();
939 < #endif
940 <
941 <    // initFortranFF(&isError);
942 <    // if (isError) {
943 <    //   sprintf(painCave.errMsg,
944 <    //           "initFortranFF errror: fortran didn't like something we gave it.\n");
945 <    //   painCave.isFatal = 1;
946 <    //   simError();
947 <    // }
948 <    // fortranInitialized_ = true;
912 >    topologyDone_ = true;
913    }
914  
915    void SimInfo::addProperty(GenericData* genData) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines