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 1549 by gezelter, Wed Apr 27 18:38:15 2011 UTC vs.
Revision 1627 by gezelter, Tue Sep 13 22:05:04 2011 UTC

# Line 54 | Line 54
54   #include "math/Vector3.hpp"
55   #include "primitives/Molecule.hpp"
56   #include "primitives/StuntDouble.hpp"
57 #include "UseTheForce/DarkSide/neighborLists_interface.h"
58 #include "UseTheForce/doForces_interface.h"
57   #include "utils/MemoryUtils.hpp"
58   #include "utils/simError.h"
59   #include "selection/SelectionManager.hpp"
60   #include "io/ForceFieldOptions.hpp"
61   #include "UseTheForce/ForceField.hpp"
62   #include "nonbonded/SwitchingFunction.hpp"
65
63   #ifdef IS_MPI
64 < #include "UseTheForce/mpiComponentPlan.h"
65 < #include "UseTheForce/DarkSide/simParallel_interface.h"
69 < #endif
64 > #include <mpi.h>
65 > #endif
66  
67   using namespace std;
68   namespace OpenMD {
# Line 78 | 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 132 | 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
135    std::cerr << "nGA = " << nGlobalAtoms_ << "\n";
136    std::cerr << "nCA = " << nCutoffAtoms << "\n";
137    std::cerr << "nG = " << nGroups << "\n";
131  
132      nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups;
140
141    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 280 | 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 687 | 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 706 | Line 717 | namespace OpenMD {
717      // count_local holds the number of found types on this processor
718      int count_local = foundTypes.size();
719  
709    // count holds the total number of found types on all processors
710    // (some will be redundant with the ones found locally):
711    int count;
712    MPI::COMM_WORLD.Allreduce(&count_local, &count, 1, MPI::INT, MPI::SUM);
713
714    // create a vector to hold the globally found types, and resize it:
715    vector<int> ftGlobal;
716    ftGlobal.resize(count);
717    vector<int> counts;
718
720      int nproc = MPI::COMM_WORLD.Get_size();
720    counts.resize(nproc);
721    vector<int> disps;
722    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 752 | 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 765 | 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 <    fInfo_.SIM_uses_PBC = usesPeriodicBoundaries_;    
807 <    fInfo_.SIM_uses_DirectionalAtoms = usesDirectionalAtoms_;
808 <    fInfo_.SIM_uses_MetallicAtoms = usesMetallicAtoms_;
809 <    fInfo_.SIM_requires_SkipCorrection = usesElectrostaticAtoms_;
784 <    fInfo_.SIM_requires_SelfCorrection = usesElectrostaticAtoms_;
785 <    fInfo_.SIM_uses_AtomicVirial = usesAtomicVirial_;
806 >    
807 >    requiresPrepair_ = usesMetallicAtoms_ ? true : false;
808 >    requiresSkipCorrection_ = usesElectrostaticAtoms_ ? true : false;
809 >    requiresSelfCorrection_ = usesElectrostaticAtoms_ ? true : false;    
810    }
811  
812  
# Line 825 | Line 849 | namespace OpenMD {
849    }
850  
851  
852 <  void SimInfo::setupFortran() {
829 <    int isError;
852 >  void SimInfo::prepareTopology() {
853      int nExclude, nOneTwo, nOneThree, nOneFour;
831    vector<int> fortranGlobalGroupMembership;
832    
833    isError = 0;
854  
835    //globalGroupMembership_ is filled by SimCreator    
836    for (int i = 0; i < nGlobalAtoms_; i++) {
837      fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1);
838    }
839
855      //calculate mass ratio of cutoff group
841    vector<RealType> mfact;
856      SimInfo::MoleculeIterator mi;
857      Molecule* mol;
858      Molecule::CutoffGroupIterator ci;
# Line 847 | 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 873 | Line 896 | namespace OpenMD {
896          identArray_.push_back(atom->getIdent());
897        }
898      }    
876
877    //fill molMembershipArray
878    //molMembershipArray is filled by SimCreator    
879    vector<int> molMembershipArray(nGlobalAtoms_);
880    for (int i = 0; i < nGlobalAtoms_; i++) {
881      molMembershipArray[i] = globalMolMembership_[i] + 1;
882    }
899      
900 <    //setup fortran simulation
900 >    //scan topology
901  
902      nExclude = excludedInteractions_.getSize();
903      nOneTwo = oneTwoInteractions_.getSize();
# Line 893 | Line 909 | namespace OpenMD {
909      int* oneThreeList = oneThreeInteractions_.getPairList();
910      int* oneFourList = oneFourInteractions_.getPairList();
911  
912 <    setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray_[0],
897 <                   &nExclude, excludeList,
898 <                   &nOneTwo, oneTwoList,
899 <                   &nOneThree, oneThreeList,
900 <                   &nOneFour, oneFourList,
901 <                   &molMembershipArray[0], &mfact[0], &nCutoffGroups_,
902 <                   &fortranGlobalGroupMembership[0], &isError);
903 <    
904 <    if( isError ){
905 <      
906 <      sprintf( painCave.errMsg,
907 <               "There was an error setting the simulation information in fortran.\n" );
908 <      painCave.isFatal = 1;
909 <      painCave.severity = OPENMD_ERROR;
910 <      simError();
911 <    }
912 <    
913 <    
914 <    sprintf( checkPointMsg,
915 <             "succesfully sent the simulation information to fortran.\n");
916 <    
917 <    errorCheckPoint();
918 <    
919 <    // Setup number of neighbors in neighbor list if present
920 <    if (simParams_->haveNeighborListNeighbors()) {
921 <      int nlistNeighbors = simParams_->getNeighborListNeighbors();
922 <      setNeighbors(&nlistNeighbors);
923 <    }
924 <  
925 < #ifdef IS_MPI    
926 <    mpiSimData parallelData;
927 <
928 <    //fill up mpiSimData struct
929 <    parallelData.nMolGlobal = getNGlobalMolecules();
930 <    parallelData.nMolLocal = getNMolecules();
931 <    parallelData.nAtomsGlobal = getNGlobalAtoms();
932 <    parallelData.nAtomsLocal = getNAtoms();
933 <    parallelData.nGroupsGlobal = getNGlobalCutoffGroups();
934 <    parallelData.nGroupsLocal = getNCutoffGroups();
935 <    parallelData.myNode = worldRank;
936 <    MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors));
937 <
938 <    //pass mpiSimData struct and index arrays to fortran
939 <    //setFsimParallel(&parallelData, &(parallelData.nAtomsLocal),
940 <    //                &localToGlobalAtomIndex[0],  &(parallelData.nGroupsLocal),
941 <    //                &localToGlobalCutoffGroupIndex[0], &isError);
942 <
943 <    if (isError) {
944 <      sprintf(painCave.errMsg,
945 <              "mpiRefresh errror: fortran didn't like something we gave it.\n");
946 <      painCave.isFatal = 1;
947 <      simError();
948 <    }
949 <
950 <    sprintf(checkPointMsg, " mpiRefresh successful.\n");
951 <    errorCheckPoint();
952 < #endif
953 <
954 <    initFortranFF(&isError);
955 <    if (isError) {
956 <      sprintf(painCave.errMsg,
957 <              "initFortranFF errror: fortran didn't like something we gave it.\n");
958 <      painCave.isFatal = 1;
959 <      simError();
960 <    }
961 <    fortranInitialized_ = true;
912 >    topologyDone_ = true;
913    }
914  
915    void SimInfo::addProperty(GenericData* genData) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines