ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/parallel/ForceMatrixDecomposition.cpp
(Generate patch)

Comparing:
branches/development/src/parallel/ForceMatrixDecomposition.cpp (file contents), Revision 1721 by gezelter, Thu May 24 14:17:42 2012 UTC vs.
trunk/src/parallel/ForceMatrixDecomposition.cpp (file contents), Revision 1930 by gezelter, Mon Aug 19 13:51:04 2013 UTC

# Line 35 | Line 35
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).          
38 > * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).          
39   * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40   * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
# Line 95 | Line 95 | namespace OpenMD {
95      storageLayout_ = sman_->getStorageLayout();
96      ff_ = info_->getForceField();
97      nLocal_ = snap_->getNumberOfAtoms();
98 <    
98 >  
99      nGroups_ = info_->getNLocalCutoffGroups();
100      // gather the information for atomtype IDs (atids):
101      idents = info_->getIdentArray();
102 +    regions = info_->getRegions();
103      AtomLocalToGlobal = info_->getGlobalAtomIndices();
104      cgLocalToGlobal = info_->getGlobalGroupIndices();
105      vector<int> globalGroupMembership = info_->getGlobalGroupMembership();
# Line 109 | Line 110 | namespace OpenMD {
110      PairList* oneTwo = info_->getOneTwoInteractions();
111      PairList* oneThree = info_->getOneThreeInteractions();
112      PairList* oneFour = info_->getOneFourInteractions();
113 <
113 >    
114 >    if (needVelocities_)
115 >      snap_->cgData.setStorageLayout(DataStorage::dslPosition |
116 >                                     DataStorage::dslVelocity);
117 >    else
118 >      snap_->cgData.setStorageLayout(DataStorage::dslPosition);
119 >    
120   #ifdef IS_MPI
121  
122      MPI::Intracomm row = rowComm.getComm();
# Line 145 | Line 152 | namespace OpenMD {
152      cgRowData.resize(nGroupsInRow_);
153      cgRowData.setStorageLayout(DataStorage::dslPosition);
154      cgColData.resize(nGroupsInCol_);
155 <    cgColData.setStorageLayout(DataStorage::dslPosition);
156 <        
155 >    if (needVelocities_)
156 >      // we only need column velocities if we need them.
157 >      cgColData.setStorageLayout(DataStorage::dslPosition |
158 >                                 DataStorage::dslVelocity);
159 >    else    
160 >      cgColData.setStorageLayout(DataStorage::dslPosition);
161 >      
162      identsRow.resize(nAtomsInRow_);
163      identsCol.resize(nAtomsInCol_);
164      
165      AtomPlanIntRow->gather(idents, identsRow);
166      AtomPlanIntColumn->gather(idents, identsCol);
167 +
168 +    regionsRow.resize(nAtomsInRow_);
169 +    regionsCol.resize(nAtomsInCol_);
170      
171 +    AtomPlanIntRow->gather(regions, regionsRow);
172 +    AtomPlanIntColumn->gather(regions, regionsCol);
173 +    
174      // allocate memory for the parallel objects
175      atypesRow.resize(nAtomsInRow_);
176      atypesCol.resize(nAtomsInCol_);
# Line 165 | Line 183 | namespace OpenMD {
183      pot_row.resize(nAtomsInRow_);
184      pot_col.resize(nAtomsInCol_);
185  
186 +    expot_row.resize(nAtomsInRow_);
187 +    expot_col.resize(nAtomsInCol_);
188 +
189      AtomRowToGlobal.resize(nAtomsInRow_);
190      AtomColToGlobal.resize(nAtomsInCol_);
191      AtomPlanIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal);
# Line 294 | Line 315 | namespace OpenMD {
315    
316    void ForceMatrixDecomposition::createGtypeCutoffMap() {
317      
318 +    GrCut.clear();
319 +    GrCutSq.clear();
320 +    GrlistSq.clear();
321 +
322      RealType tol = 1e-6;
323      largestRcut_ = 0.0;
299    RealType rc;
324      int atid;
325      set<AtomType*> atypes = info_->getSimulatedAtomTypes();
326      
# Line 381 | Line 405 | namespace OpenMD {
405        }
406        
407        bool gTypeFound = false;
408 <      for (int gt = 0; gt < gTypeCutoffs.size(); gt++) {
408 >      for (unsigned int gt = 0; gt < gTypeCutoffs.size(); gt++) {
409          if (abs(groupCutoff[cg1] - gTypeCutoffs[gt]) < tol) {
410            groupToGtype[cg1] = gt;
411            gTypeFound = true;
# Line 406 | Line 430 | namespace OpenMD {
430      
431      RealType tradRcut = groupMax;
432  
433 <    for (int i = 0; i < gTypeCutoffs.size();  i++) {
434 <      for (int j = 0; j < gTypeCutoffs.size();  j++) {      
433 >    GrCut.resize( gTypeCutoffs.size() );
434 >    GrCutSq.resize( gTypeCutoffs.size() );
435 >    GrlistSq.resize( gTypeCutoffs.size() );
436 >
437 >
438 >    for (unsigned int i = 0; i < gTypeCutoffs.size();  i++) {
439 >      GrCut[i].resize( gTypeCutoffs.size() , 0.0);
440 >      GrCutSq[i].resize( gTypeCutoffs.size(), 0.0 );
441 >      GrlistSq[i].resize( gTypeCutoffs.size(), 0.0 );
442 >
443 >      for (unsigned int j = 0; j < gTypeCutoffs.size();  j++) {      
444          RealType thisRcut;
445          switch(cutoffPolicy_) {
446          case TRADITIONAL:
# Line 429 | Line 462 | namespace OpenMD {
462            break;
463          }
464  
465 <        pair<int,int> key = make_pair(i,j);
433 <        gTypeCutoffMap[key].first = thisRcut;
465 >        GrCut[i][j] = thisRcut;
466          if (thisRcut > largestRcut_) largestRcut_ = thisRcut;
467 <        gTypeCutoffMap[key].second = thisRcut*thisRcut;
468 <        gTypeCutoffMap[key].third = pow(thisRcut + skinThickness_, 2);
467 >        GrCutSq[i][j] = thisRcut * thisRcut;
468 >        GrlistSq[i][j] = pow(thisRcut + skinThickness_, 2);
469 >
470 >        // pair<int,int> key = make_pair(i,j);
471 >        // gTypeCutoffMap[key].first = thisRcut;
472 >        // gTypeCutoffMap[key].third = pow(thisRcut + skinThickness_, 2);
473          // sanity check
474          
475          if (userChoseCutoff_) {
476 <          if (abs(gTypeCutoffMap[key].first - userCutoff_) > 0.0001) {
476 >          if (abs(GrCut[i][j] - userCutoff_) > 0.0001) {
477              sprintf(painCave.errMsg,
478                      "ForceMatrixDecomposition::createGtypeCutoffMap "
479                      "user-specified rCut (%lf) does not match computed group Cutoff\n", userCutoff_);
# Line 450 | Line 486 | namespace OpenMD {
486      }
487    }
488  
489 <
454 <  groupCutoffs ForceMatrixDecomposition::getGroupCutoffs(int cg1, int cg2) {
489 >  void ForceMatrixDecomposition::getGroupCutoffs(int &cg1, int &cg2, RealType &rcut, RealType &rcutsq, RealType &rlistsq) {
490      int i, j;  
491   #ifdef IS_MPI
492      i = groupRowToGtype[cg1];
# Line 460 | Line 495 | namespace OpenMD {
495      i = groupToGtype[cg1];
496      j = groupToGtype[cg2];
497   #endif    
498 <    return gTypeCutoffMap[make_pair(i,j)];
498 >    rcut = GrCut[i][j];
499 >    rcutsq = GrCutSq[i][j];
500 >    rlistsq = GrlistSq[i][j];
501 >    return;
502 >    //return gTypeCutoffMap[make_pair(i,j)];
503    }
504  
505    int ForceMatrixDecomposition::getTopologicalDistance(int atom1, int atom2) {
506 <    for (int j = 0; j < toposForAtom[atom1].size(); j++) {
506 >    for (unsigned int j = 0; j < toposForAtom[atom1].size(); j++) {
507        if (toposForAtom[atom1][j] == atom2)
508          return topoDist[atom1][j];
509 <    }
509 >    }                                          
510      return 0;
511    }
512  
513    void ForceMatrixDecomposition::zeroWorkArrays() {
514      pairwisePot = 0.0;
515      embeddingPot = 0.0;
516 +    excludedPot = 0.0;
517 +    excludedSelfPot = 0.0;
518  
519   #ifdef IS_MPI
520      if (storageLayout_ & DataStorage::dslForce) {
# Line 492 | Line 533 | namespace OpenMD {
533      fill(pot_col.begin(), pot_col.end(),
534           Vector<RealType, N_INTERACTION_FAMILIES> (0.0));  
535  
536 +    fill(expot_row.begin(), expot_row.end(),
537 +         Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
538 +
539 +    fill(expot_col.begin(), expot_col.end(),
540 +         Vector<RealType, N_INTERACTION_FAMILIES> (0.0));  
541 +
542      if (storageLayout_ & DataStorage::dslParticlePot) {    
543        fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(),
544             0.0);
# Line 539 | Line 586 | namespace OpenMD {
586             atomColData.electricField.end(), V3Zero);
587      }
588  
542    if (storageLayout_ & DataStorage::dslFlucQForce) {    
543      fill(atomRowData.flucQFrc.begin(), atomRowData.flucQFrc.end(),
544           0.0);
545      fill(atomColData.flucQFrc.begin(), atomColData.flucQFrc.end(),
546           0.0);
547    }
548
589   #endif
590      // even in parallel, we need to zero out the local arrays:
591  
# Line 600 | Line 640 | namespace OpenMD {
640      cgPlanVectorColumn->gather(snap_->cgData.position,
641                                 cgColData.position);
642  
643 +
644 +
645 +    if (needVelocities_) {
646 +      // gather up the atomic velocities
647 +      AtomPlanVectorColumn->gather(snap_->atomData.velocity,
648 +                                   atomColData.velocity);
649 +      
650 +      cgPlanVectorColumn->gather(snap_->cgData.velocity,
651 +                                 cgColData.velocity);
652 +    }
653 +
654      
655      // if needed, gather the atomic rotation matrices
656      if (storageLayout_ & DataStorage::dslAmat) {
# Line 608 | Line 659 | namespace OpenMD {
659        AtomPlanMatrixColumn->gather(snap_->atomData.aMat,
660                                     atomColData.aMat);
661      }
662 <    
663 <    // if needed, gather the atomic eletrostatic frames
664 <    if (storageLayout_ & DataStorage::dslElectroFrame) {
665 <      AtomPlanMatrixRow->gather(snap_->atomData.electroFrame,
666 <                                atomRowData.electroFrame);
667 <      AtomPlanMatrixColumn->gather(snap_->atomData.electroFrame,
668 <                                   atomColData.electroFrame);
662 >
663 >    // if needed, gather the atomic eletrostatic information
664 >    if (storageLayout_ & DataStorage::dslDipole) {
665 >      AtomPlanVectorRow->gather(snap_->atomData.dipole,
666 >                                atomRowData.dipole);
667 >      AtomPlanVectorColumn->gather(snap_->atomData.dipole,
668 >                                   atomColData.dipole);
669      }
670  
671 +    if (storageLayout_ & DataStorage::dslQuadrupole) {
672 +      AtomPlanMatrixRow->gather(snap_->atomData.quadrupole,
673 +                                atomRowData.quadrupole);
674 +      AtomPlanMatrixColumn->gather(snap_->atomData.quadrupole,
675 +                                   atomColData.quadrupole);
676 +    }
677 +        
678      // if needed, gather the atomic fluctuating charge values
679      if (storageLayout_ & DataStorage::dslFlucQPosition) {
680        AtomPlanRealRow->gather(snap_->atomData.flucQPos,
# Line 648 | Line 706 | namespace OpenMD {
706          snap_->atomData.density[i] += rho_tmp[i];
707      }
708  
709 +    // this isn't necessary if we don't have polarizable atoms, but
710 +    // we'll leave it here for now.
711      if (storageLayout_ & DataStorage::dslElectricField) {
712        
713        AtomPlanVectorRow->scatter(atomRowData.electricField,
# Line 655 | Line 715 | namespace OpenMD {
715        
716        int n = snap_->atomData.electricField.size();
717        vector<Vector3d> field_tmp(n, V3Zero);
718 <      AtomPlanVectorColumn->scatter(atomColData.electricField, field_tmp);
718 >      AtomPlanVectorColumn->scatter(atomColData.electricField,
719 >                                    field_tmp);
720        for (int i = 0; i < n; i++)
721          snap_->atomData.electricField[i] += field_tmp[i];
722      }
# Line 755 | Line 816 | namespace OpenMD {
816              
817      }
818  
819 +    if (storageLayout_ & DataStorage::dslElectricField) {
820 +
821 +      int nef = snap_->atomData.electricField.size();
822 +      vector<Vector3d> efield_tmp(nef, V3Zero);
823 +
824 +      AtomPlanVectorRow->scatter(atomRowData.electricField, efield_tmp);
825 +      for (int i = 0; i < nef; i++) {
826 +        snap_->atomData.electricField[i] += efield_tmp[i];
827 +        efield_tmp[i] = 0.0;
828 +      }
829 +      
830 +      AtomPlanVectorColumn->scatter(atomColData.electricField, efield_tmp);
831 +      for (int i = 0; i < nef; i++)
832 +        snap_->atomData.electricField[i] += efield_tmp[i];
833 +    }
834 +
835 +
836      nLocal_ = snap_->getNumberOfAtoms();
837  
838      vector<potVec> pot_temp(nLocal_,
839                              Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
840 +    vector<potVec> expot_temp(nLocal_,
841 +                              Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
842  
843      // scatter/gather pot_row into the members of my column
844            
845      AtomPlanPotRow->scatter(pot_row, pot_temp);
846 +    AtomPlanPotRow->scatter(expot_row, expot_temp);
847  
848 <    for (int ii = 0;  ii < pot_temp.size(); ii++ )
848 >    for (int ii = 0;  ii < pot_temp.size(); ii++ )
849        pairwisePot += pot_temp[ii];
850 <    
850 >
851 >    for (int ii = 0;  ii < expot_temp.size(); ii++ )
852 >      excludedPot += expot_temp[ii];
853 >        
854 >    if (storageLayout_ & DataStorage::dslParticlePot) {
855 >      // This is the pairwise contribution to the particle pot.  The
856 >      // embedding contribution is added in each of the low level
857 >      // non-bonded routines.  In single processor, this is done in
858 >      // unpackInteractionData, not in collectData.
859 >      for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
860 >        for (int i = 0; i < nLocal_; i++) {
861 >          // factor of two is because the total potential terms are divided
862 >          // by 2 in parallel due to row/ column scatter      
863 >          snap_->atomData.particlePot[i] += 2.0 * pot_temp[i](ii);
864 >        }
865 >      }
866 >    }
867 >
868      fill(pot_temp.begin(), pot_temp.end(),
869           Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
870 +    fill(expot_temp.begin(), expot_temp.end(),
871 +         Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
872        
873      AtomPlanPotColumn->scatter(pot_col, pot_temp);    
874 +    AtomPlanPotColumn->scatter(expot_col, expot_temp);    
875      
876      for (int ii = 0;  ii < pot_temp.size(); ii++ )
877        pairwisePot += pot_temp[ii];    
878 +
879 +    for (int ii = 0;  ii < expot_temp.size(); ii++ )
880 +      excludedPot += expot_temp[ii];    
881 +
882 +    if (storageLayout_ & DataStorage::dslParticlePot) {
883 +      // This is the pairwise contribution to the particle pot.  The
884 +      // embedding contribution is added in each of the low level
885 +      // non-bonded routines.  In single processor, this is done in
886 +      // unpackInteractionData, not in collectData.
887 +      for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
888 +        for (int i = 0; i < nLocal_; i++) {
889 +          // factor of two is because the total potential terms are divided
890 +          // by 2 in parallel due to row/ column scatter      
891 +          snap_->atomData.particlePot[i] += 2.0 * pot_temp[i](ii);
892 +        }
893 +      }
894 +    }
895      
896 +    if (storageLayout_ & DataStorage::dslParticlePot) {
897 +      int npp = snap_->atomData.particlePot.size();
898 +      vector<RealType> ppot_temp(npp, 0.0);
899 +
900 +      // This is the direct or embedding contribution to the particle
901 +      // pot.
902 +      
903 +      AtomPlanRealRow->scatter(atomRowData.particlePot, ppot_temp);
904 +      for (int i = 0; i < npp; i++) {
905 +        snap_->atomData.particlePot[i] += ppot_temp[i];
906 +      }
907 +
908 +      fill(ppot_temp.begin(), ppot_temp.end(), 0.0);
909 +      
910 +      AtomPlanRealColumn->scatter(atomColData.particlePot, ppot_temp);
911 +      for (int i = 0; i < npp; i++) {
912 +        snap_->atomData.particlePot[i] += ppot_temp[i];
913 +      }
914 +    }
915 +
916      for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
917        RealType ploc1 = pairwisePot[ii];
918        RealType ploc2 = 0.0;
# Line 783 | Line 921 | namespace OpenMD {
921      }
922  
923      for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
924 <      RealType ploc1 = embeddingPot[ii];
924 >      RealType ploc1 = excludedPot[ii];
925        RealType ploc2 = 0.0;
926        MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM);
927 <      embeddingPot[ii] = ploc2;
927 >      excludedPot[ii] = ploc2;
928      }
929  
930 +    // Here be dragons.
931 +    MPI::Intracomm col = colComm.getComm();
932 +
933 +    col.Allreduce(MPI::IN_PLACE,
934 +                  &snap_->frameData.conductiveHeatFlux[0], 3,
935 +                  MPI::REALTYPE, MPI::SUM);
936 +
937 +
938   #endif
939  
940    }
941  
942 <  int ForceMatrixDecomposition::getNAtomsInRow() {  
942 >  /**
943 >   * Collects information obtained during the post-pair (and embedding
944 >   * functional) loops onto local data structures.
945 >   */
946 >  void ForceMatrixDecomposition::collectSelfData() {
947 >    snap_ = sman_->getCurrentSnapshot();
948 >    storageLayout_ = sman_->getStorageLayout();
949 >
950   #ifdef IS_MPI
951 +    for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
952 +      RealType ploc1 = embeddingPot[ii];
953 +      RealType ploc2 = 0.0;
954 +      MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM);
955 +      embeddingPot[ii] = ploc2;
956 +    }    
957 +    for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
958 +      RealType ploc1 = excludedSelfPot[ii];
959 +      RealType ploc2 = 0.0;
960 +      MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM);
961 +      excludedSelfPot[ii] = ploc2;
962 +    }    
963 + #endif
964 +    
965 +  }
966 +
967 +
968 +
969 +  int& ForceMatrixDecomposition::getNAtomsInRow() {  
970 + #ifdef IS_MPI
971      return nAtomsInRow_;
972   #else
973      return nLocal_;
# Line 804 | Line 977 | namespace OpenMD {
977    /**
978     * returns the list of atoms belonging to this group.  
979     */
980 <  vector<int> ForceMatrixDecomposition::getAtomsInGroupRow(int cg1){
980 >  vector<int>& ForceMatrixDecomposition::getAtomsInGroupRow(int cg1){
981   #ifdef IS_MPI
982      return groupListRow_[cg1];
983   #else
# Line 812 | Line 985 | namespace OpenMD {
985   #endif
986    }
987  
988 <  vector<int> ForceMatrixDecomposition::getAtomsInGroupColumn(int cg2){
988 >  vector<int>& ForceMatrixDecomposition::getAtomsInGroupColumn(int cg2){
989   #ifdef IS_MPI
990      return groupListCol_[cg2];
991   #else
# Line 829 | Line 1002 | namespace OpenMD {
1002      d = snap_->cgData.position[cg2] - snap_->cgData.position[cg1];
1003   #endif
1004      
1005 <    snap_->wrapVector(d);
1005 >    if (usePeriodicBoundaryConditions_) {
1006 >      snap_->wrapVector(d);
1007 >    }
1008      return d;    
1009    }
1010  
1011 +  Vector3d& ForceMatrixDecomposition::getGroupVelocityColumn(int cg2){
1012 + #ifdef IS_MPI
1013 +    return cgColData.velocity[cg2];
1014 + #else
1015 +    return snap_->cgData.velocity[cg2];
1016 + #endif
1017 +  }
1018  
1019 +  Vector3d& ForceMatrixDecomposition::getAtomVelocityColumn(int atom2){
1020 + #ifdef IS_MPI
1021 +    return atomColData.velocity[atom2];
1022 + #else
1023 +    return snap_->atomData.velocity[atom2];
1024 + #endif
1025 +  }
1026 +
1027 +
1028    Vector3d ForceMatrixDecomposition::getAtomToGroupVectorRow(int atom1, int cg1){
1029  
1030      Vector3d d;
# Line 843 | Line 1034 | namespace OpenMD {
1034   #else
1035      d = snap_->cgData.position[cg1] - snap_->atomData.position[atom1];
1036   #endif
1037 <
1038 <    snap_->wrapVector(d);
1037 >    if (usePeriodicBoundaryConditions_) {
1038 >      snap_->wrapVector(d);
1039 >    }
1040      return d;    
1041    }
1042    
# Line 856 | Line 1048 | namespace OpenMD {
1048   #else
1049      d = snap_->cgData.position[cg2] - snap_->atomData.position[atom2];
1050   #endif
1051 <    
1052 <    snap_->wrapVector(d);
1051 >    if (usePeriodicBoundaryConditions_) {
1052 >      snap_->wrapVector(d);
1053 >    }
1054      return d;    
1055    }
1056  
1057 <  RealType ForceMatrixDecomposition::getMassFactorRow(int atom1) {
1057 >  RealType& ForceMatrixDecomposition::getMassFactorRow(int atom1) {
1058   #ifdef IS_MPI
1059      return massFactorsRow[atom1];
1060   #else
# Line 869 | Line 1062 | namespace OpenMD {
1062   #endif
1063    }
1064  
1065 <  RealType ForceMatrixDecomposition::getMassFactorColumn(int atom2) {
1065 >  RealType& ForceMatrixDecomposition::getMassFactorColumn(int atom2) {
1066   #ifdef IS_MPI
1067      return massFactorsCol[atom2];
1068   #else
# Line 886 | Line 1079 | namespace OpenMD {
1079   #else
1080      d = snap_->atomData.position[atom2] - snap_->atomData.position[atom1];
1081   #endif
1082 <
1083 <    snap_->wrapVector(d);
1082 >    if (usePeriodicBoundaryConditions_) {
1083 >      snap_->wrapVector(d);
1084 >    }
1085      return d;    
1086    }
1087  
1088 <  vector<int> ForceMatrixDecomposition::getExcludesForAtom(int atom1) {
1088 >  vector<int>& ForceMatrixDecomposition::getExcludesForAtom(int atom1) {
1089      return excludesForAtom[atom1];
1090    }
1091  
# Line 899 | Line 1093 | namespace OpenMD {
1093     * We need to exclude some overcounted interactions that result from
1094     * the parallel decomposition.
1095     */
1096 <  bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) {
1096 >  bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2, int cg1, int cg2) {
1097      int unique_id_1, unique_id_2;
1098          
1099   #ifdef IS_MPI
1100      // in MPI, we have to look up the unique IDs for each atom
1101      unique_id_1 = AtomRowToGlobal[atom1];
1102      unique_id_2 = AtomColToGlobal[atom2];
1103 +    // group1 = cgRowToGlobal[cg1];
1104 +    // group2 = cgColToGlobal[cg2];
1105   #else
1106      unique_id_1 = AtomLocalToGlobal[atom1];
1107      unique_id_2 = AtomLocalToGlobal[atom2];
1108 +    int group1 = cgLocalToGlobal[cg1];
1109 +    int group2 = cgLocalToGlobal[cg2];
1110   #endif  
1111  
1112      if (unique_id_1 == unique_id_2) return true;
# Line 920 | Line 1118 | namespace OpenMD {
1118      } else {
1119        if ((unique_id_1 + unique_id_2) % 2 == 1) return true;
1120      }
1121 + #endif    
1122 +
1123 + #ifndef IS_MPI
1124 +    if (group1 == group2) {
1125 +      if (unique_id_1 < unique_id_2) return true;
1126 +    }
1127   #endif
1128      
1129      return false;
# Line 971 | Line 1175 | namespace OpenMD {
1175      idat.excluded = excludeAtomPair(atom1, atom2);
1176    
1177   #ifdef IS_MPI
1178 <    idat.atypes = make_pair( atypesRow[atom1], atypesCol[atom2]);
1179 <    //idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]),
1180 <    //                         ff_->getAtomType(identsCol[atom2]) );
1181 <    
1178 >    //idat.atypes = make_pair( atypesRow[atom1], atypesCol[atom2]);
1179 >    idat.atid1 = identsRow[atom1];
1180 >    idat.atid2 = identsCol[atom2];
1181 >
1182 >    if (regionsRow[atom1] >= 0 && regionsCol[atom2] >= 0)
1183 >      idat.sameRegion = (regionsRow[atom1] == regionsCol[atom2]);
1184 >      
1185      if (storageLayout_ & DataStorage::dslAmat) {
1186        idat.A1 = &(atomRowData.aMat[atom1]);
1187        idat.A2 = &(atomColData.aMat[atom2]);
1188      }
1189      
983    if (storageLayout_ & DataStorage::dslElectroFrame) {
984      idat.eFrame1 = &(atomRowData.electroFrame[atom1]);
985      idat.eFrame2 = &(atomColData.electroFrame[atom2]);
986    }
987
1190      if (storageLayout_ & DataStorage::dslTorque) {
1191        idat.t1 = &(atomRowData.torque[atom1]);
1192        idat.t2 = &(atomColData.torque[atom2]);
1193      }
1194  
1195 +    if (storageLayout_ & DataStorage::dslDipole) {
1196 +      idat.dipole1 = &(atomRowData.dipole[atom1]);
1197 +      idat.dipole2 = &(atomColData.dipole[atom2]);
1198 +    }
1199 +
1200 +    if (storageLayout_ & DataStorage::dslQuadrupole) {
1201 +      idat.quadrupole1 = &(atomRowData.quadrupole[atom1]);
1202 +      idat.quadrupole2 = &(atomColData.quadrupole[atom2]);
1203 +    }
1204 +
1205      if (storageLayout_ & DataStorage::dslDensity) {
1206        idat.rho1 = &(atomRowData.density[atom1]);
1207        idat.rho2 = &(atomColData.density[atom2]);
# Line 1022 | Line 1234 | namespace OpenMD {
1234  
1235   #else
1236      
1237 +    //idat.atypes = make_pair( atypesLocal[atom1], atypesLocal[atom2]);
1238 +    idat.atid1 = idents[atom1];
1239 +    idat.atid2 = idents[atom2];
1240  
1241 <    // cerr << "atoms = " << atom1 << " " << atom2 << "\n";
1242 <    // cerr << "pos1 = " << snap_->atomData.position[atom1] << "\n";
1028 <    // cerr << "pos2 = " << snap_->atomData.position[atom2] << "\n";
1241 >    if (regions[atom1] >= 0 && regions[atom2] >= 0)
1242 >      idat.sameRegion = (regions[atom1] == regions[atom2]);
1243  
1030    idat.atypes = make_pair( atypesLocal[atom1], atypesLocal[atom2]);
1031    //idat.atypes = make_pair( ff_->getAtomType(idents[atom1]),
1032    //                         ff_->getAtomType(idents[atom2]) );
1033
1244      if (storageLayout_ & DataStorage::dslAmat) {
1245        idat.A1 = &(snap_->atomData.aMat[atom1]);
1246        idat.A2 = &(snap_->atomData.aMat[atom2]);
1247      }
1248  
1039    if (storageLayout_ & DataStorage::dslElectroFrame) {
1040      idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]);
1041      idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]);
1042    }
1043
1249      if (storageLayout_ & DataStorage::dslTorque) {
1250        idat.t1 = &(snap_->atomData.torque[atom1]);
1251        idat.t2 = &(snap_->atomData.torque[atom2]);
1252      }
1253  
1254 +    if (storageLayout_ & DataStorage::dslDipole) {
1255 +      idat.dipole1 = &(snap_->atomData.dipole[atom1]);
1256 +      idat.dipole2 = &(snap_->atomData.dipole[atom2]);
1257 +    }
1258 +
1259 +    if (storageLayout_ & DataStorage::dslQuadrupole) {
1260 +      idat.quadrupole1 = &(snap_->atomData.quadrupole[atom1]);
1261 +      idat.quadrupole2 = &(snap_->atomData.quadrupole[atom2]);
1262 +    }
1263 +
1264      if (storageLayout_ & DataStorage::dslDensity) {    
1265        idat.rho1 = &(snap_->atomData.density[atom1]);
1266        idat.rho2 = &(snap_->atomData.density[atom2]);
# Line 1084 | Line 1299 | namespace OpenMD {
1299   #ifdef IS_MPI
1300      pot_row[atom1] += RealType(0.5) *  *(idat.pot);
1301      pot_col[atom2] += RealType(0.5) *  *(idat.pot);
1302 +    expot_row[atom1] += RealType(0.5) *  *(idat.excludedPot);
1303 +    expot_col[atom2] += RealType(0.5) *  *(idat.excludedPot);
1304  
1305      atomRowData.force[atom1] += *(idat.f1);
1306      atomColData.force[atom2] -= *(idat.f1);
1307  
1308      if (storageLayout_ & DataStorage::dslFlucQForce) {              
1309 <      atomRowData.flucQFrc[atom1] += *(idat.dVdFQ1);
1310 <      atomColData.flucQFrc[atom2] += *(idat.dVdFQ2);
1309 >      atomRowData.flucQFrc[atom1] -= *(idat.dVdFQ1);
1310 >      atomColData.flucQFrc[atom2] -= *(idat.dVdFQ2);
1311      }
1312  
1313      if (storageLayout_ & DataStorage::dslElectricField) {              
# Line 1098 | Line 1315 | namespace OpenMD {
1315        atomColData.electricField[atom2] += *(idat.eField2);
1316      }
1317  
1101    // should particle pot be done here also?
1318   #else
1319      pairwisePot += *(idat.pot);
1320 +    excludedPot += *(idat.excludedPot);
1321  
1322      snap_->atomData.force[atom1] += *(idat.f1);
1323      snap_->atomData.force[atom2] -= *(idat.f1);
1324  
1325      if (idat.doParticlePot) {
1326 +      // This is the pairwise contribution to the particle pot.  The
1327 +      // embedding contribution is added in each of the low level
1328 +      // non-bonded routines.  In parallel, this calculation is done
1329 +      // in collectData, not in unpackInteractionData.
1330        snap_->atomData.particlePot[atom1] += *(idat.vpair) * *(idat.sw);
1331 <      snap_->atomData.particlePot[atom2] -= *(idat.vpair) * *(idat.sw);
1331 >      snap_->atomData.particlePot[atom2] += *(idat.vpair) * *(idat.sw);
1332      }
1333      
1334      if (storageLayout_ & DataStorage::dslFlucQForce) {              
1335 <      snap_->atomData.flucQFrc[atom1] += *(idat.dVdFQ1);
1335 >      snap_->atomData.flucQFrc[atom1] -= *(idat.dVdFQ1);
1336        snap_->atomData.flucQFrc[atom2] -= *(idat.dVdFQ2);
1337      }
1338  
# Line 1130 | Line 1351 | namespace OpenMD {
1351     * first element of pair is row-indexed CutoffGroup
1352     * second element of pair is column-indexed CutoffGroup
1353     */
1354 <  vector<pair<int, int> > ForceMatrixDecomposition::buildNeighborList() {
1355 <      
1356 <    vector<pair<int, int> > neighborList;
1354 >  void ForceMatrixDecomposition::buildNeighborList(vector<pair<int,int> >& neighborList) {
1355 >    
1356 >    neighborList.clear();
1357      groupCutoffs cuts;
1358      bool doAllPairs = false;
1359  
1360 +    RealType rList_ = (largestRcut_ + skinThickness_);
1361 +    RealType rcut, rcutsq, rlistsq;
1362 +    Snapshot* snap_ = sman_->getCurrentSnapshot();
1363 +    Mat3x3d box;
1364 +    Mat3x3d invBox;
1365 +
1366 +    Vector3d rs, scaled, dr;
1367 +    Vector3i whichCell;
1368 +    int cellIndex;
1369 +
1370   #ifdef IS_MPI
1371      cellListRow_.clear();
1372      cellListCol_.clear();
1373   #else
1374      cellList_.clear();
1375   #endif
1376 <
1377 <    RealType rList_ = (largestRcut_ + skinThickness_);
1378 <    RealType rl2 = rList_ * rList_;
1379 <    Snapshot* snap_ = sman_->getCurrentSnapshot();
1380 <    Mat3x3d Hmat = snap_->getHmat();
1381 <    Vector3d Hx = Hmat.getColumn(0);
1382 <    Vector3d Hy = Hmat.getColumn(1);
1383 <    Vector3d Hz = Hmat.getColumn(2);
1384 <
1385 <    nCells_.x() = (int) ( Hx.length() )/ rList_;
1386 <    nCells_.y() = (int) ( Hy.length() )/ rList_;
1387 <    nCells_.z() = (int) ( Hz.length() )/ rList_;
1388 <
1376 >    
1377 >    if (!usePeriodicBoundaryConditions_) {
1378 >      box = snap_->getBoundingBox();
1379 >      invBox = snap_->getInvBoundingBox();
1380 >    } else {
1381 >      box = snap_->getHmat();
1382 >      invBox = snap_->getInvHmat();
1383 >    }
1384 >    
1385 >    Vector3d boxX = box.getColumn(0);
1386 >    Vector3d boxY = box.getColumn(1);
1387 >    Vector3d boxZ = box.getColumn(2);
1388 >    
1389 >    nCells_.x() = (int) ( boxX.length() )/ rList_;
1390 >    nCells_.y() = (int) ( boxY.length() )/ rList_;
1391 >    nCells_.z() = (int) ( boxZ.length() )/ rList_;
1392 >    
1393      // handle small boxes where the cell offsets can end up repeating cells
1394      
1395      if (nCells_.x() < 3) doAllPairs = true;
1396      if (nCells_.y() < 3) doAllPairs = true;
1397      if (nCells_.z() < 3) doAllPairs = true;
1398 <
1164 <    Mat3x3d invHmat = snap_->getInvHmat();
1165 <    Vector3d rs, scaled, dr;
1166 <    Vector3i whichCell;
1167 <    int cellIndex;
1398 >    
1399      int nCtot = nCells_.x() * nCells_.y() * nCells_.z();
1400 <
1400 >    
1401   #ifdef IS_MPI
1402      cellListRow_.resize(nCtot);
1403      cellListCol_.resize(nCtot);
1404   #else
1405      cellList_.resize(nCtot);
1406   #endif
1407 <
1407 >    
1408      if (!doAllPairs) {
1409   #ifdef IS_MPI
1410 <
1410 >      
1411        for (int i = 0; i < nGroupsInRow_; i++) {
1412          rs = cgRowData.position[i];
1413          
1414          // scaled positions relative to the box vectors
1415 <        scaled = invHmat * rs;
1415 >        scaled = invBox * rs;
1416          
1417          // wrap the vector back into the unit box by subtracting integer box
1418          // numbers
1419          for (int j = 0; j < 3; j++) {
1420            scaled[j] -= roundMe(scaled[j]);
1421            scaled[j] += 0.5;
1422 +          // Handle the special case when an object is exactly on the
1423 +          // boundary (a scaled coordinate of 1.0 is the same as
1424 +          // scaled coordinate of 0.0)
1425 +          if (scaled[j] >= 1.0) scaled[j] -= 1.0;
1426          }
1427          
1428          // find xyz-indices of cell that cutoffGroup is in.
# Line 1205 | Line 1440 | namespace OpenMD {
1440          rs = cgColData.position[i];
1441          
1442          // scaled positions relative to the box vectors
1443 <        scaled = invHmat * rs;
1443 >        scaled = invBox * rs;
1444          
1445          // wrap the vector back into the unit box by subtracting integer box
1446          // numbers
1447          for (int j = 0; j < 3; j++) {
1448            scaled[j] -= roundMe(scaled[j]);
1449            scaled[j] += 0.5;
1450 +          // Handle the special case when an object is exactly on the
1451 +          // boundary (a scaled coordinate of 1.0 is the same as
1452 +          // scaled coordinate of 0.0)
1453 +          if (scaled[j] >= 1.0) scaled[j] -= 1.0;
1454          }
1455          
1456          // find xyz-indices of cell that cutoffGroup is in.
# Line 1225 | Line 1464 | namespace OpenMD {
1464          // add this cutoff group to the list of groups in this cell;
1465          cellListCol_[cellIndex].push_back(i);
1466        }
1467 <    
1467 >      
1468   #else
1469        for (int i = 0; i < nGroups_; i++) {
1470          rs = snap_->cgData.position[i];
1471          
1472          // scaled positions relative to the box vectors
1473 <        scaled = invHmat * rs;
1473 >        scaled = invBox * rs;
1474          
1475          // wrap the vector back into the unit box by subtracting integer box
1476          // numbers
1477          for (int j = 0; j < 3; j++) {
1478            scaled[j] -= roundMe(scaled[j]);
1479            scaled[j] += 0.5;
1480 +          // Handle the special case when an object is exactly on the
1481 +          // boundary (a scaled coordinate of 1.0 is the same as
1482 +          // scaled coordinate of 0.0)
1483 +          if (scaled[j] >= 1.0) scaled[j] -= 1.0;
1484          }
1485          
1486          // find xyz-indices of cell that cutoffGroup is in.
# Line 1296 | Line 1539 | namespace OpenMD {
1539                    // & column indicies and will divide labor in the
1540                    // force evaluation later.
1541                    dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)];
1542 <                  snap_->wrapVector(dr);
1543 <                  cuts = getGroupCutoffs( (*j1), (*j2) );
1544 <                  if (dr.lengthSquare() < cuts.third) {
1542 >                  if (usePeriodicBoundaryConditions_) {
1543 >                    snap_->wrapVector(dr);
1544 >                  }
1545 >                  getGroupCutoffs( (*j1), (*j2), rcut, rcutsq, rlistsq );
1546 >                  if (dr.lengthSquare() < rlistsq) {
1547                      neighborList.push_back(make_pair((*j1), (*j2)));
1548                    }                  
1549                  }
# Line 1318 | Line 1563 | namespace OpenMD {
1563                    // allows atoms within a single cutoff group to
1564                    // interact with each other.
1565  
1321
1322
1566                    if (m2 != m1 || (*j2) >= (*j1) ) {
1567  
1568                      dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)];
1569 <                    snap_->wrapVector(dr);
1570 <                    cuts = getGroupCutoffs( (*j1), (*j2) );
1571 <                    if (dr.lengthSquare() < cuts.third) {
1569 >                    if (usePeriodicBoundaryConditions_) {
1570 >                      snap_->wrapVector(dr);
1571 >                    }
1572 >                    getGroupCutoffs( (*j1), (*j2), rcut, rcutsq, rlistsq );
1573 >                    if (dr.lengthSquare() < rlistsq) {
1574                        neighborList.push_back(make_pair((*j1), (*j2)));
1575                      }
1576                    }
# Line 1342 | Line 1587 | namespace OpenMD {
1587        for (int j1 = 0; j1 < nGroupsInRow_; j1++) {
1588          for (int j2 = 0; j2 < nGroupsInCol_; j2++) {    
1589            dr = cgColData.position[j2] - cgRowData.position[j1];
1590 <          snap_->wrapVector(dr);
1591 <          cuts = getGroupCutoffs( j1, j2 );
1592 <          if (dr.lengthSquare() < cuts.third) {
1590 >          if (usePeriodicBoundaryConditions_) {
1591 >            snap_->wrapVector(dr);
1592 >          }
1593 >          getGroupCutoffs( j1, j2, rcut, rcutsq, rlistsq);
1594 >          if (dr.lengthSquare() < rlistsq) {
1595              neighborList.push_back(make_pair(j1, j2));
1596            }
1597          }
# Line 1355 | Line 1602 | namespace OpenMD {
1602          // include self group interactions j2 == j1
1603          for (int j2 = j1; j2 < nGroups_; j2++) {
1604            dr = snap_->cgData.position[j2] - snap_->cgData.position[j1];
1605 <          snap_->wrapVector(dr);
1606 <          cuts = getGroupCutoffs( j1, j2 );
1607 <          if (dr.lengthSquare() < cuts.third) {
1605 >          if (usePeriodicBoundaryConditions_) {
1606 >            snap_->wrapVector(dr);
1607 >          }
1608 >          getGroupCutoffs( j1, j2, rcut, rcutsq, rlistsq );
1609 >          if (dr.lengthSquare() < rlistsq) {
1610              neighborList.push_back(make_pair(j1, j2));
1611            }
1612          }    
# Line 1370 | Line 1619 | namespace OpenMD {
1619      saved_CG_positions_.clear();
1620      for (int i = 0; i < nGroups_; i++)
1621        saved_CG_positions_.push_back(snap_->cgData.position[i]);
1373    
1374    return neighborList;
1622    }
1623   } //end namespace OpenMD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines