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 1535 by gezelter, Fri Dec 31 18:31:56 2010 UTC vs.
Revision 1569 by gezelter, Thu May 26 13:55: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"
57   #include "utils/MemoryUtils.hpp"
58   #include "utils/simError.h"
59   #include "selection/SelectionManager.hpp"
# Line 62 | Line 61
61   #include "UseTheForce/ForceField.hpp"
62   #include "nonbonded/SwitchingFunction.hpp"
63  
65 #ifdef IS_MPI
66 #include "UseTheForce/mpiComponentPlan.h"
67 #include "UseTheForce/DarkSide/simParallel_interface.h"
68 #endif
69
64   using namespace std;
65   namespace OpenMD {
66    
# Line 77 | Line 71 | namespace OpenMD {
71      nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0),
72      nAtoms_(0), nBonds_(0),  nBends_(0), nTorsions_(0), nInversions_(0),
73      nRigidBodies_(0), nIntegrableObjects_(0), nCutoffGroups_(0),
74 <    nConstraints_(0), sman_(NULL), fortranInitialized_(false),
74 >    nConstraints_(0), sman_(NULL), topologyDone_(false),
75      calcBoxDipole_(false), useAtomicVirial_(true) {    
76      
77      MoleculeStamp* molStamp;
# Line 131 | Line 125 | namespace OpenMD {
125      //equal to the total number of atoms minus number of atoms belong to
126      //cutoff group defined in meta-data file plus the number of cutoff
127      //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";
135      
136      //every free atom (atom does not belong to rigid bodies) is an
137      //integrable object therefore the total number of integrable objects
# Line 770 | Line 770 | namespace OpenMD {
770      temp = usesElectrostatic;
771      MPI_Allreduce(&temp, &usesElectrostaticAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
772   #endif
773    fInfo_.SIM_uses_PBC = usesPeriodicBoundaries_;    
774    fInfo_.SIM_uses_DirectionalAtoms = usesDirectionalAtoms_;
775    fInfo_.SIM_uses_MetallicAtoms = usesMetallicAtoms_;
776    fInfo_.SIM_requires_SkipCorrection = usesElectrostaticAtoms_;
777    fInfo_.SIM_requires_SelfCorrection = usesElectrostaticAtoms_;
778    fInfo_.SIM_uses_AtomicVirial = usesAtomicVirial_;
773    }
774  
775 <  void SimInfo::setupFortran() {
776 <    int isError;
777 <    int nExclude, nOneTwo, nOneThree, nOneFour;
778 <    vector<int> fortranGlobalGroupMembership;
775 >
776 >  vector<int> SimInfo::getGlobalAtomIndices() {
777 >    SimInfo::MoleculeIterator mi;
778 >    Molecule* mol;
779 >    Molecule::AtomIterator ai;
780 >    Atom* atom;
781 >
782 >    vector<int> GlobalAtomIndices(getNAtoms(), 0);
783      
784 <    isError = 0;
784 >    for (mol = beginMolecule(mi); mol != NULL; mol  = nextMolecule(mi)) {
785 >      
786 >      for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
787 >        GlobalAtomIndices[atom->getLocalIndex()] = atom->getGlobalIndex();
788 >      }
789 >    }
790 >    return GlobalAtomIndices;
791 >  }
792  
793 <    //globalGroupMembership_ is filled by SimCreator    
794 <    for (int i = 0; i < nGlobalAtoms_; i++) {
795 <      fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1);
793 >
794 >  vector<int> SimInfo::getGlobalGroupIndices() {
795 >    SimInfo::MoleculeIterator mi;
796 >    Molecule* mol;
797 >    Molecule::CutoffGroupIterator ci;
798 >    CutoffGroup* cg;
799 >
800 >    vector<int> GlobalGroupIndices;
801 >    
802 >    for (mol = beginMolecule(mi); mol != NULL; mol  = nextMolecule(mi)) {
803 >      
804 >      //local index of cutoff group is trivial, it only depends on the
805 >      //order of travesing
806 >      for (cg = mol->beginCutoffGroup(ci); cg != NULL;
807 >           cg = mol->nextCutoffGroup(ci)) {
808 >        GlobalGroupIndices.push_back(cg->getGlobalIndex());
809 >      }        
810      }
811 +    return GlobalGroupIndices;
812 +  }
813  
814 +
815 +  void SimInfo::prepareTopology() {
816 +    int nExclude, nOneTwo, nOneThree, nOneFour;
817 +
818      //calculate mass ratio of cutoff group
794    vector<RealType> mfact;
819      SimInfo::MoleculeIterator mi;
820      Molecule* mol;
821      Molecule::CutoffGroupIterator ci;
# Line 800 | Line 824 | namespace OpenMD {
824      Atom* atom;
825      RealType totalMass;
826  
827 <    //to avoid memory reallocation, reserve enough space for mfact
828 <    mfact.reserve(getNCutoffGroups());
827 >    //to avoid memory reallocation, reserve enough space for massFactors_
828 >    massFactors_.clear();
829 >    massFactors_.reserve(getNCutoffGroups());
830      
831      for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
832 <      for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
832 >      for (cg = mol->beginCutoffGroup(ci); cg != NULL;
833 >           cg = mol->nextCutoffGroup(ci)) {
834  
835          totalMass = cg->getMass();
836          for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
837            // Check for massless groups - set mfact to 1 if true
838            if (totalMass != 0)
839 <            mfact.push_back(atom->getMass()/totalMass);
839 >            massFactors_.push_back(atom->getMass()/totalMass);
840            else
841 <            mfact.push_back( 1.0 );
841 >            massFactors_.push_back( 1.0 );
842          }
843        }      
844      }
845  
846 <    //fill ident array of local atoms (it is actually ident of
821 <    //AtomType, it is so confusing !!!)
822 <    vector<int> identArray;
846 >    // Build the identArray_
847  
848 <    //to avoid memory reallocation, reserve enough space identArray
849 <    identArray.reserve(getNAtoms());
826 <    
848 >    identArray_.clear();
849 >    identArray_.reserve(getNAtoms());    
850      for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
851        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
852 <        identArray.push_back(atom->getIdent());
852 >        identArray_.push_back(atom->getIdent());
853        }
854      }    
832
833    //fill molMembershipArray
834    //molMembershipArray is filled by SimCreator    
835    vector<int> molMembershipArray(nGlobalAtoms_);
836    for (int i = 0; i < nGlobalAtoms_; i++) {
837      molMembershipArray[i] = globalMolMembership_[i] + 1;
838    }
855      
856 <    //setup fortran simulation
856 >    //scan topology
857  
858      nExclude = excludedInteractions_.getSize();
859      nOneTwo = oneTwoInteractions_.getSize();
# Line 849 | Line 865 | namespace OpenMD {
865      int* oneThreeList = oneThreeInteractions_.getPairList();
866      int* oneFourList = oneFourInteractions_.getPairList();
867  
868 <    setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0],
869 <                   &nExclude, excludeList,
870 <                   &nOneTwo, oneTwoList,
871 <                   &nOneThree, oneThreeList,
872 <                   &nOneFour, oneFourList,
873 <                   &molMembershipArray[0], &mfact[0], &nCutoffGroups_,
874 <                   &fortranGlobalGroupMembership[0], &isError);
868 >    //setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray_[0],
869 >    //               &nExclude, excludeList,
870 >    //               &nOneTwo, oneTwoList,
871 >    //               &nOneThree, oneThreeList,
872 >    //               &nOneFour, oneFourList,
873 >    //               &molMembershipArray[0], &mfact[0], &nCutoffGroups_,
874 >    //               &fortranGlobalGroupMembership[0], &isError);
875      
876 <    if( isError ){
861 <      
862 <      sprintf( painCave.errMsg,
863 <               "There was an error setting the simulation information in fortran.\n" );
864 <      painCave.isFatal = 1;
865 <      painCave.severity = OPENMD_ERROR;
866 <      simError();
867 <    }
868 <    
869 <    
870 <    sprintf( checkPointMsg,
871 <             "succesfully sent the simulation information to fortran.\n");
872 <    
873 <    errorCheckPoint();
874 <    
875 <    // Setup number of neighbors in neighbor list if present
876 <    if (simParams_->haveNeighborListNeighbors()) {
877 <      int nlistNeighbors = simParams_->getNeighborListNeighbors();
878 <      setNeighbors(&nlistNeighbors);
879 <    }
880 <  
881 < #ifdef IS_MPI    
882 <    //SimInfo is responsible for creating localToGlobalAtomIndex and
883 <    //localToGlobalGroupIndex
884 <    vector<int> localToGlobalAtomIndex(getNAtoms(), 0);
885 <    vector<int> localToGlobalCutoffGroupIndex;
886 <    mpiSimData parallelData;
887 <
888 <    for (mol = beginMolecule(mi); mol != NULL; mol  = nextMolecule(mi)) {
889 <
890 <      //local index(index in DataStorge) of atom is important
891 <      for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
892 <        localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1;
893 <      }
894 <
895 <      //local index of cutoff group is trivial, it only depends on the order of travesing
896 <      for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
897 <        localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1);
898 <      }        
899 <        
900 <    }
901 <
902 <    //fill up mpiSimData struct
903 <    parallelData.nMolGlobal = getNGlobalMolecules();
904 <    parallelData.nMolLocal = getNMolecules();
905 <    parallelData.nAtomsGlobal = getNGlobalAtoms();
906 <    parallelData.nAtomsLocal = getNAtoms();
907 <    parallelData.nGroupsGlobal = getNGlobalCutoffGroups();
908 <    parallelData.nGroupsLocal = getNCutoffGroups();
909 <    parallelData.myNode = worldRank;
910 <    MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors));
911 <
912 <    //pass mpiSimData struct and index arrays to fortran
913 <    setFsimParallel(&parallelData, &(parallelData.nAtomsLocal),
914 <                    &localToGlobalAtomIndex[0],  &(parallelData.nGroupsLocal),
915 <                    &localToGlobalCutoffGroupIndex[0], &isError);
916 <
917 <    if (isError) {
918 <      sprintf(painCave.errMsg,
919 <              "mpiRefresh errror: fortran didn't like something we gave it.\n");
920 <      painCave.isFatal = 1;
921 <      simError();
922 <    }
923 <
924 <    sprintf(checkPointMsg, " mpiRefresh successful.\n");
925 <    errorCheckPoint();
926 < #endif
927 <    fortranInitialized_ = true;
876 >    topologyDone_ = true;
877    }
878  
879    void SimInfo::addProperty(GenericData* genData) {
# Line 961 | Line 910 | namespace OpenMD {
910      Molecule* mol;
911      RigidBody* rb;
912      Atom* atom;
913 +    CutoffGroup* cg;
914      SimInfo::MoleculeIterator mi;
915      Molecule::RigidBodyIterator rbIter;
916 <    Molecule::AtomIterator atomIter;;
916 >    Molecule::AtomIterator atomIter;
917 >    Molecule::CutoffGroupIterator cgIter;
918  
919      for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
920          
# Line 973 | Line 924 | namespace OpenMD {
924          
925        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
926          rb->setSnapshotManager(sman_);
927 +      }
928 +
929 +      for (cg = mol->beginCutoffGroup(cgIter); cg != NULL; cg = mol->nextCutoffGroup(cgIter)) {
930 +        cg->setSnapshotManager(sman_);
931        }
932      }    
933      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines