| 57 |  | storageLayout_ = sman_->getStorageLayout(); | 
| 58 |  | ff_ = info_->getForceField(); | 
| 59 |  | nLocal_ = snap_->getNumberOfAtoms(); | 
| 60 | < |  | 
| 60 | > |  | 
| 61 |  | nGroups_ = info_->getNLocalCutoffGroups(); | 
| 62 | – | cerr << "in dId, nGroups = " << nGroups_ << "\n"; | 
| 62 |  | // gather the information for atomtype IDs (atids): | 
| 63 |  | idents = info_->getIdentArray(); | 
| 64 |  | AtomLocalToGlobal = info_->getGlobalAtomIndices(); | 
| 65 |  | cgLocalToGlobal = info_->getGlobalGroupIndices(); | 
| 66 |  | vector<int> globalGroupMembership = info_->getGlobalGroupMembership(); | 
| 67 | + |  | 
| 68 |  | massFactors = info_->getMassFactors(); | 
| 69 | – | PairList excludes = info_->getExcludedInteractions(); | 
| 70 | – | PairList oneTwo = info_->getOneTwoInteractions(); | 
| 71 | – | PairList oneThree = info_->getOneThreeInteractions(); | 
| 72 | – | PairList oneFour = info_->getOneFourInteractions(); | 
| 69 |  |  | 
| 70 | + | PairList* excludes = info_->getExcludedInteractions(); | 
| 71 | + | PairList* oneTwo = info_->getOneTwoInteractions(); | 
| 72 | + | PairList* oneThree = info_->getOneThreeInteractions(); | 
| 73 | + | PairList* oneFour = info_->getOneFourInteractions(); | 
| 74 | + |  | 
| 75 |  | #ifdef IS_MPI | 
| 76 |  |  | 
| 77 |  | AtomCommIntRow = new Communicator<Row,int>(nLocal_); | 
| 112 |  | AtomCommIntRow->gather(idents, identsRow); | 
| 113 |  | AtomCommIntColumn->gather(idents, identsCol); | 
| 114 |  |  | 
| 115 | + | // allocate memory for the parallel objects | 
| 116 | + | AtomRowToGlobal.resize(nAtomsInRow_); | 
| 117 | + | AtomColToGlobal.resize(nAtomsInCol_); | 
| 118 | + | cgRowToGlobal.resize(nGroupsInRow_); | 
| 119 | + | cgColToGlobal.resize(nGroupsInCol_); | 
| 120 | + | massFactorsRow.resize(nAtomsInRow_); | 
| 121 | + | massFactorsCol.resize(nAtomsInCol_); | 
| 122 | + | pot_row.resize(nAtomsInRow_); | 
| 123 | + | pot_col.resize(nAtomsInCol_); | 
| 124 | + |  | 
| 125 |  | AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal); | 
| 126 |  | AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal); | 
| 127 |  |  | 
| 153 |  | } | 
| 154 |  | } | 
| 155 |  |  | 
| 156 | < | skipsForAtom.clear(); | 
| 157 | < | skipsForAtom.resize(nAtomsInRow_); | 
| 156 | > | excludesForAtom.clear(); | 
| 157 | > | excludesForAtom.resize(nAtomsInRow_); | 
| 158 |  | toposForAtom.clear(); | 
| 159 |  | toposForAtom.resize(nAtomsInRow_); | 
| 160 |  | topoDist.clear(); | 
| 165 |  | for (int j = 0; j < nAtomsInCol_; j++) { | 
| 166 |  | int jglob = AtomColToGlobal[j]; | 
| 167 |  |  | 
| 168 | < | if (excludes.hasPair(iglob, jglob)) | 
| 169 | < | skipsForAtom[i].push_back(j); | 
| 168 | > | if (excludes->hasPair(iglob, jglob)) | 
| 169 | > | excludesForAtom[i].push_back(j); | 
| 170 |  |  | 
| 171 | < | if (oneTwo.hasPair(iglob, jglob)) { | 
| 171 | > | if (oneTwo->hasPair(iglob, jglob)) { | 
| 172 |  | toposForAtom[i].push_back(j); | 
| 173 |  | topoDist[i].push_back(1); | 
| 174 |  | } else { | 
| 175 | < | if (oneThree.hasPair(iglob, jglob)) { | 
| 175 | > | if (oneThree->hasPair(iglob, jglob)) { | 
| 176 |  | toposForAtom[i].push_back(j); | 
| 177 |  | topoDist[i].push_back(2); | 
| 178 |  | } else { | 
| 179 | < | if (oneFour.hasPair(iglob, jglob)) { | 
| 179 | > | if (oneFour->hasPair(iglob, jglob)) { | 
| 180 |  | toposForAtom[i].push_back(j); | 
| 181 |  | topoDist[i].push_back(3); | 
| 182 |  | } | 
| 199 |  | } | 
| 200 |  | } | 
| 201 |  |  | 
| 202 | < | skipsForAtom.clear(); | 
| 203 | < | skipsForAtom.resize(nLocal_); | 
| 202 | > | excludesForAtom.clear(); | 
| 203 | > | excludesForAtom.resize(nLocal_); | 
| 204 |  | toposForAtom.clear(); | 
| 205 |  | toposForAtom.resize(nLocal_); | 
| 206 |  | topoDist.clear(); | 
| 212 |  | for (int j = 0; j < nLocal_; j++) { | 
| 213 |  | int jglob = AtomLocalToGlobal[j]; | 
| 214 |  |  | 
| 215 | < | if (excludes.hasPair(iglob, jglob)) | 
| 216 | < | skipsForAtom[i].push_back(j); | 
| 215 | > | if (excludes->hasPair(iglob, jglob)) | 
| 216 | > | excludesForAtom[i].push_back(j); | 
| 217 |  |  | 
| 218 | < | if (oneTwo.hasPair(iglob, jglob)) { | 
| 218 | > | if (oneTwo->hasPair(iglob, jglob)) { | 
| 219 |  | toposForAtom[i].push_back(j); | 
| 220 |  | topoDist[i].push_back(1); | 
| 221 |  | } else { | 
| 222 | < | if (oneThree.hasPair(iglob, jglob)) { | 
| 222 | > | if (oneThree->hasPair(iglob, jglob)) { | 
| 223 |  | toposForAtom[i].push_back(j); | 
| 224 |  | topoDist[i].push_back(2); | 
| 225 |  | } else { | 
| 226 | < | if (oneFour.hasPair(iglob, jglob)) { | 
| 226 | > | if (oneFour->hasPair(iglob, jglob)) { | 
| 227 |  | toposForAtom[i].push_back(j); | 
| 228 |  | topoDist[i].push_back(3); | 
| 229 |  | } | 
| 233 |  | } | 
| 234 |  |  | 
| 235 |  | createGtypeCutoffMap(); | 
| 236 | + |  | 
| 237 |  | } | 
| 238 |  |  | 
| 239 |  | void ForceMatrixDecomposition::createGtypeCutoffMap() { | 
| 240 | < |  | 
| 240 | > |  | 
| 241 |  | RealType tol = 1e-6; | 
| 242 |  | RealType rc; | 
| 243 |  | int atid; | 
| 244 |  | set<AtomType*> atypes = info_->getSimulatedAtomTypes(); | 
| 245 | < | vector<RealType> atypeCutoff; | 
| 234 | < | atypeCutoff.resize( atypes.size() ); | 
| 245 | > | map<int, RealType> atypeCutoff; | 
| 246 |  |  | 
| 247 |  | for (set<AtomType*>::iterator at = atypes.begin(); | 
| 248 |  | at != atypes.end(); ++at){ | 
| 249 |  | atid = (*at)->getIdent(); | 
| 250 | < |  | 
| 240 | < | if (userChoseCutoff_) | 
| 250 | > | if (userChoseCutoff_) | 
| 251 |  | atypeCutoff[atid] = userCutoff_; | 
| 252 | < | else | 
| 252 | > | else | 
| 253 |  | atypeCutoff[atid] = interactionMan_->getSuggestedCutoffRadius(*at); | 
| 254 |  | } | 
| 255 |  |  | 
| 256 |  | vector<RealType> gTypeCutoffs; | 
| 247 | – |  | 
| 257 |  | // first we do a single loop over the cutoff groups to find the | 
| 258 |  | // largest cutoff for any atypes present in this group. | 
| 259 |  | #ifdef IS_MPI | 
| 311 |  |  | 
| 312 |  | vector<RealType> groupCutoff(nGroups_, 0.0); | 
| 313 |  | groupToGtype.resize(nGroups_); | 
| 305 | – |  | 
| 306 | – | cerr << "nGroups = " << nGroups_ << "\n"; | 
| 314 |  | for (int cg1 = 0; cg1 < nGroups_; cg1++) { | 
| 315 |  |  | 
| 316 |  | groupCutoff[cg1] = 0.0; | 
| 339 |  | } | 
| 340 |  | #endif | 
| 341 |  |  | 
| 335 | – | cerr << "gTypeCutoffs.size() = " << gTypeCutoffs.size() << "\n"; | 
| 342 |  | // Now we find the maximum group cutoff value present in the simulation | 
| 343 |  |  | 
| 344 | < | RealType groupMax = *max_element(gTypeCutoffs.begin(), gTypeCutoffs.end()); | 
| 344 | > | RealType groupMax = *max_element(gTypeCutoffs.begin(), | 
| 345 | > | gTypeCutoffs.end()); | 
| 346 |  |  | 
| 347 |  | #ifdef IS_MPI | 
| 348 | < | MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE, MPI::MAX); | 
| 348 | > | MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE, | 
| 349 | > | MPI::MAX); | 
| 350 |  | #endif | 
| 351 |  |  | 
| 352 |  | RealType tradRcut = groupMax; | 
| 442 |  | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); | 
| 443 |  |  | 
| 444 |  | if (storageLayout_ & DataStorage::dslParticlePot) { | 
| 445 | < | fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(), 0.0); | 
| 446 | < | fill(atomColData.particlePot.begin(), atomColData.particlePot.end(), 0.0); | 
| 445 | > | fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(), | 
| 446 | > | 0.0); | 
| 447 | > | fill(atomColData.particlePot.begin(), atomColData.particlePot.end(), | 
| 448 | > | 0.0); | 
| 449 |  | } | 
| 450 |  |  | 
| 451 |  | if (storageLayout_ & DataStorage::dslDensity) { | 
| 454 |  | } | 
| 455 |  |  | 
| 456 |  | if (storageLayout_ & DataStorage::dslFunctional) { | 
| 457 | < | fill(atomRowData.functional.begin(), atomRowData.functional.end(), 0.0); | 
| 458 | < | fill(atomColData.functional.begin(), atomColData.functional.end(), 0.0); | 
| 457 | > | fill(atomRowData.functional.begin(), atomRowData.functional.end(), | 
| 458 | > | 0.0); | 
| 459 | > | fill(atomColData.functional.begin(), atomColData.functional.end(), | 
| 460 | > | 0.0); | 
| 461 |  | } | 
| 462 |  |  | 
| 463 |  | if (storageLayout_ & DataStorage::dslFunctionalDerivative) { | 
| 467 |  | atomColData.functionalDerivative.end(), 0.0); | 
| 468 |  | } | 
| 469 |  |  | 
| 470 | < | #else | 
| 471 | < |  | 
| 470 | > | if (storageLayout_ & DataStorage::dslSkippedCharge) { | 
| 471 | > | fill(atomRowData.skippedCharge.begin(), | 
| 472 | > | atomRowData.skippedCharge.end(), 0.0); | 
| 473 | > | fill(atomColData.skippedCharge.begin(), | 
| 474 | > | atomColData.skippedCharge.end(), 0.0); | 
| 475 | > | } | 
| 476 | > |  | 
| 477 | > | #endif | 
| 478 | > | // even in parallel, we need to zero out the local arrays: | 
| 479 | > |  | 
| 480 |  | if (storageLayout_ & DataStorage::dslParticlePot) { | 
| 481 |  | fill(snap_->atomData.particlePot.begin(), | 
| 482 |  | snap_->atomData.particlePot.end(), 0.0); | 
| 494 |  | fill(snap_->atomData.functionalDerivative.begin(), | 
| 495 |  | snap_->atomData.functionalDerivative.end(), 0.0); | 
| 496 |  | } | 
| 497 | < | #endif | 
| 497 | > | if (storageLayout_ & DataStorage::dslSkippedCharge) { | 
| 498 | > | fill(snap_->atomData.skippedCharge.begin(), | 
| 499 | > | snap_->atomData.skippedCharge.end(), 0.0); | 
| 500 | > | } | 
| 501 |  |  | 
| 502 |  | } | 
| 503 |  |  | 
| 534 |  | AtomCommMatrixColumn->gather(snap_->atomData.electroFrame, | 
| 535 |  | atomColData.electroFrame); | 
| 536 |  | } | 
| 537 | + |  | 
| 538 |  | #endif | 
| 539 |  | } | 
| 540 |  |  | 
| 601 |  | AtomCommVectorColumn->scatter(atomColData.force, frc_tmp); | 
| 602 |  | for (int i = 0; i < n; i++) | 
| 603 |  | snap_->atomData.force[i] += frc_tmp[i]; | 
| 604 | < |  | 
| 581 | < |  | 
| 604 | > |  | 
| 605 |  | if (storageLayout_ & DataStorage::dslTorque) { | 
| 606 |  |  | 
| 607 | < | int nt = snap_->atomData.force.size(); | 
| 607 | > | int nt = snap_->atomData.torque.size(); | 
| 608 |  | vector<Vector3d> trq_tmp(nt, V3Zero); | 
| 609 |  |  | 
| 610 |  | AtomCommVectorRow->scatter(atomRowData.torque, trq_tmp); | 
| 611 | < | for (int i = 0; i < n; i++) { | 
| 611 | > | for (int i = 0; i < nt; i++) { | 
| 612 |  | snap_->atomData.torque[i] += trq_tmp[i]; | 
| 613 |  | trq_tmp[i] = 0.0; | 
| 614 |  | } | 
| 615 |  |  | 
| 616 |  | AtomCommVectorColumn->scatter(atomColData.torque, trq_tmp); | 
| 617 | < | for (int i = 0; i < n; i++) | 
| 617 | > | for (int i = 0; i < nt; i++) | 
| 618 |  | snap_->atomData.torque[i] += trq_tmp[i]; | 
| 619 |  | } | 
| 620 | + |  | 
| 621 | + | if (storageLayout_ & DataStorage::dslSkippedCharge) { | 
| 622 | + |  | 
| 623 | + | int ns = snap_->atomData.skippedCharge.size(); | 
| 624 | + | vector<RealType> skch_tmp(ns, 0.0); | 
| 625 | + |  | 
| 626 | + | AtomCommRealRow->scatter(atomRowData.skippedCharge, skch_tmp); | 
| 627 | + | for (int i = 0; i < ns; i++) { | 
| 628 | + | snap_->atomData.skippedCharge[i] += skch_tmp[i]; | 
| 629 | + | skch_tmp[i] = 0.0; | 
| 630 | + | } | 
| 631 | + |  | 
| 632 | + | AtomCommRealColumn->scatter(atomColData.skippedCharge, skch_tmp); | 
| 633 | + | for (int i = 0; i < ns; i++) | 
| 634 | + | snap_->atomData.skippedCharge[i] += skch_tmp[i]; | 
| 635 | + | } | 
| 636 |  |  | 
| 637 |  | nLocal_ = snap_->getNumberOfAtoms(); | 
| 638 |  |  | 
| 755 |  | return d; | 
| 756 |  | } | 
| 757 |  |  | 
| 758 | < | vector<int> ForceMatrixDecomposition::getSkipsForAtom(int atom1) { | 
| 759 | < | return skipsForAtom[atom1]; | 
| 758 | > | vector<int> ForceMatrixDecomposition::getExcludesForAtom(int atom1) { | 
| 759 | > | return excludesForAtom[atom1]; | 
| 760 |  | } | 
| 761 |  |  | 
| 762 |  | /** | 
| 763 | < | * There are a number of reasons to skip a pair or a | 
| 725 | < | * particle. Mostly we do this to exclude atoms who are involved in | 
| 726 | < | * short range interactions (bonds, bends, torsions), but we also | 
| 727 | < | * need to exclude some overcounted interactions that result from | 
| 763 | > | * We need to exclude some overcounted interactions that result from | 
| 764 |  | * the parallel decomposition. | 
| 765 |  | */ | 
| 766 |  | bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) { | 
| 780 |  | } else { | 
| 781 |  | if ((unique_id_1 + unique_id_2) % 2 == 1) return true; | 
| 782 |  | } | 
| 783 | + | #endif | 
| 784 | + | return false; | 
| 785 | + | } | 
| 786 | + |  | 
| 787 | + | /** | 
| 788 | + | * We need to handle the interactions for atoms who are involved in | 
| 789 | + | * the same rigid body as well as some short range interactions | 
| 790 | + | * (bonds, bends, torsions) differently from other interactions. | 
| 791 | + | * We'll still visit the pairwise routines, but with a flag that | 
| 792 | + | * tells those routines to exclude the pair from direct long range | 
| 793 | + | * interactions.  Some indirect interactions (notably reaction | 
| 794 | + | * field) must still be handled for these pairs. | 
| 795 | + | */ | 
| 796 | + | bool ForceMatrixDecomposition::excludeAtomPair(int atom1, int atom2) { | 
| 797 | + | int unique_id_2; | 
| 798 | + |  | 
| 799 | + | #ifdef IS_MPI | 
| 800 | + | // in MPI, we have to look up the unique IDs for the row atom. | 
| 801 | + | unique_id_2 = AtomColToGlobal[atom2]; | 
| 802 |  | #else | 
| 803 |  | // in the normal loop, the atom numbers are unique | 
| 749 | – | unique_id_1 = atom1; | 
| 804 |  | unique_id_2 = atom2; | 
| 805 |  | #endif | 
| 806 |  |  | 
| 807 | < | for (vector<int>::iterator i = skipsForAtom[atom1].begin(); | 
| 808 | < | i != skipsForAtom[atom1].end(); ++i) { | 
| 807 | > | for (vector<int>::iterator i = excludesForAtom[atom1].begin(); | 
| 808 | > | i != excludesForAtom[atom1].end(); ++i) { | 
| 809 |  | if ( (*i) == unique_id_2 ) return true; | 
| 810 |  | } | 
| 811 |  |  | 
| 831 |  |  | 
| 832 |  | // filling interaction blocks with pointers | 
| 833 |  | void ForceMatrixDecomposition::fillInteractionData(InteractionData &idat, | 
| 834 | < | int atom1, int atom2) { | 
| 834 | > | int atom1, int atom2) { | 
| 835 | > |  | 
| 836 | > | idat.excluded = excludeAtomPair(atom1, atom2); | 
| 837 | > |  | 
| 838 |  | #ifdef IS_MPI | 
| 839 |  |  | 
| 840 |  | idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), | 
| 875 |  | idat.particlePot2 = &(atomColData.particlePot[atom2]); | 
| 876 |  | } | 
| 877 |  |  | 
| 878 | + | if (storageLayout_ & DataStorage::dslSkippedCharge) { | 
| 879 | + | idat.skippedCharge1 = &(atomRowData.skippedCharge[atom1]); | 
| 880 | + | idat.skippedCharge2 = &(atomColData.skippedCharge[atom2]); | 
| 881 | + | } | 
| 882 | + |  | 
| 883 |  | #else | 
| 884 |  |  | 
| 885 |  | idat.atypes = make_pair( ff_->getAtomType(idents[atom1]), | 
| 920 |  | idat.particlePot2 = &(snap_->atomData.particlePot[atom2]); | 
| 921 |  | } | 
| 922 |  |  | 
| 923 | + | if (storageLayout_ & DataStorage::dslSkippedCharge) { | 
| 924 | + | idat.skippedCharge1 = &(snap_->atomData.skippedCharge[atom1]); | 
| 925 | + | idat.skippedCharge2 = &(snap_->atomData.skippedCharge[atom2]); | 
| 926 | + | } | 
| 927 |  | #endif | 
| 928 |  | } | 
| 929 |  |  | 
| 941 |  | snap_->atomData.force[atom1] += *(idat.f1); | 
| 942 |  | snap_->atomData.force[atom2] -= *(idat.f1); | 
| 943 |  | #endif | 
| 944 | < |  | 
| 879 | < | } | 
| 880 | < |  | 
| 881 | < |  | 
| 882 | < | void ForceMatrixDecomposition::fillSkipData(InteractionData &idat, | 
| 883 | < | int atom1, int atom2) { | 
| 884 | < | // Still Missing:: skippedCharge fill must be added to DataStorage | 
| 885 | < | #ifdef IS_MPI | 
| 886 | < | idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), | 
| 887 | < | ff_->getAtomType(identsCol[atom2]) ); | 
| 888 | < |  | 
| 889 | < | if (storageLayout_ & DataStorage::dslElectroFrame) { | 
| 890 | < | idat.eFrame1 = &(atomRowData.electroFrame[atom1]); | 
| 891 | < | idat.eFrame2 = &(atomColData.electroFrame[atom2]); | 
| 892 | < | } | 
| 893 | < | if (storageLayout_ & DataStorage::dslTorque) { | 
| 894 | < | idat.t1 = &(atomRowData.torque[atom1]); | 
| 895 | < | idat.t2 = &(atomColData.torque[atom2]); | 
| 896 | < | } | 
| 897 | < | #else | 
| 898 | < | idat.atypes = make_pair( ff_->getAtomType(idents[atom1]), | 
| 899 | < | ff_->getAtomType(idents[atom2]) ); | 
| 900 | < |  | 
| 901 | < | if (storageLayout_ & DataStorage::dslElectroFrame) { | 
| 902 | < | idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]); | 
| 903 | < | idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]); | 
| 904 | < | } | 
| 905 | < | if (storageLayout_ & DataStorage::dslTorque) { | 
| 906 | < | idat.t1 = &(snap_->atomData.torque[atom1]); | 
| 907 | < | idat.t2 = &(snap_->atomData.torque[atom2]); | 
| 908 | < | } | 
| 909 | < | #endif | 
| 944 | > |  | 
| 945 |  | } | 
| 946 |  |  | 
| 912 | – |  | 
| 913 | – | void ForceMatrixDecomposition::unpackSkipData(InteractionData &idat, int atom1, int atom2) { | 
| 914 | – | #ifdef IS_MPI | 
| 915 | – | pot_row[atom1] += 0.5 *  *(idat.pot); | 
| 916 | – | pot_col[atom2] += 0.5 *  *(idat.pot); | 
| 917 | – | #else | 
| 918 | – | pairwisePot += *(idat.pot); | 
| 919 | – | #endif | 
| 920 | – |  | 
| 921 | – | } | 
| 922 | – |  | 
| 923 | – |  | 
| 947 |  | /* | 
| 948 |  | * buildNeighborList | 
| 949 |  | * | 
| 954 |  |  | 
| 955 |  | vector<pair<int, int> > neighborList; | 
| 956 |  | groupCutoffs cuts; | 
| 957 | + | bool doAllPairs = false; | 
| 958 | + |  | 
| 959 |  | #ifdef IS_MPI | 
| 960 |  | cellListRow_.clear(); | 
| 961 |  | cellListCol_.clear(); | 
| 975 |  | nCells_.y() = (int) ( Hy.length() )/ rList_; | 
| 976 |  | nCells_.z() = (int) ( Hz.length() )/ rList_; | 
| 977 |  |  | 
| 978 | + | // handle small boxes where the cell offsets can end up repeating cells | 
| 979 | + |  | 
| 980 | + | if (nCells_.x() < 3) doAllPairs = true; | 
| 981 | + | if (nCells_.y() < 3) doAllPairs = true; | 
| 982 | + | if (nCells_.z() < 3) doAllPairs = true; | 
| 983 | + |  | 
| 984 |  | Mat3x3d invHmat = snap_->getInvHmat(); | 
| 985 |  | Vector3d rs, scaled, dr; | 
| 986 |  | Vector3i whichCell; | 
| 994 |  | cellList_.resize(nCtot); | 
| 995 |  | #endif | 
| 996 |  |  | 
| 997 | + | if (!doAllPairs) { | 
| 998 |  | #ifdef IS_MPI | 
| 967 | – | for (int i = 0; i < nGroupsInRow_; i++) { | 
| 968 | – | rs = cgRowData.position[i]; | 
| 999 |  |  | 
| 1000 | < | // scaled positions relative to the box vectors | 
| 1001 | < | scaled = invHmat * rs; | 
| 1002 | < |  | 
| 1003 | < | // wrap the vector back into the unit box by subtracting integer box | 
| 1004 | < | // numbers | 
| 1005 | < | for (int j = 0; j < 3; j++) { | 
| 1006 | < | scaled[j] -= roundMe(scaled[j]); | 
| 1007 | < | scaled[j] += 0.5; | 
| 1008 | < | } | 
| 1009 | < |  | 
| 1010 | < | // find xyz-indices of cell that cutoffGroup is in. | 
| 1011 | < | whichCell.x() = nCells_.x() * scaled.x(); | 
| 1012 | < | whichCell.y() = nCells_.y() * scaled.y(); | 
| 1013 | < | whichCell.z() = nCells_.z() * scaled.z(); | 
| 1014 | < |  | 
| 1015 | < | // find single index of this cell: | 
| 1016 | < | cellIndex = Vlinear(whichCell, nCells_); | 
| 1017 | < |  | 
| 1018 | < | // add this cutoff group to the list of groups in this cell; | 
| 1019 | < | cellListRow_[cellIndex].push_back(i); | 
| 1020 | < | } | 
| 1021 | < |  | 
| 1022 | < | for (int i = 0; i < nGroupsInCol_; i++) { | 
| 993 | < | rs = cgColData.position[i]; | 
| 994 | < |  | 
| 995 | < | // scaled positions relative to the box vectors | 
| 996 | < | scaled = invHmat * rs; | 
| 997 | < |  | 
| 998 | < | // wrap the vector back into the unit box by subtracting integer box | 
| 999 | < | // numbers | 
| 1000 | < | for (int j = 0; j < 3; j++) { | 
| 1001 | < | scaled[j] -= roundMe(scaled[j]); | 
| 1002 | < | scaled[j] += 0.5; | 
| 1000 | > | for (int i = 0; i < nGroupsInRow_; i++) { | 
| 1001 | > | rs = cgRowData.position[i]; | 
| 1002 | > |  | 
| 1003 | > | // scaled positions relative to the box vectors | 
| 1004 | > | scaled = invHmat * rs; | 
| 1005 | > |  | 
| 1006 | > | // wrap the vector back into the unit box by subtracting integer box | 
| 1007 | > | // numbers | 
| 1008 | > | for (int j = 0; j < 3; j++) { | 
| 1009 | > | scaled[j] -= roundMe(scaled[j]); | 
| 1010 | > | scaled[j] += 0.5; | 
| 1011 | > | } | 
| 1012 | > |  | 
| 1013 | > | // find xyz-indices of cell that cutoffGroup is in. | 
| 1014 | > | whichCell.x() = nCells_.x() * scaled.x(); | 
| 1015 | > | whichCell.y() = nCells_.y() * scaled.y(); | 
| 1016 | > | whichCell.z() = nCells_.z() * scaled.z(); | 
| 1017 | > |  | 
| 1018 | > | // find single index of this cell: | 
| 1019 | > | cellIndex = Vlinear(whichCell, nCells_); | 
| 1020 | > |  | 
| 1021 | > | // add this cutoff group to the list of groups in this cell; | 
| 1022 | > | cellListRow_[cellIndex].push_back(i); | 
| 1023 |  | } | 
| 1024 | < |  | 
| 1025 | < | // find xyz-indices of cell that cutoffGroup is in. | 
| 1026 | < | whichCell.x() = nCells_.x() * scaled.x(); | 
| 1027 | < | whichCell.y() = nCells_.y() * scaled.y(); | 
| 1028 | < | whichCell.z() = nCells_.z() * scaled.z(); | 
| 1029 | < |  | 
| 1030 | < | // find single index of this cell: | 
| 1031 | < | cellIndex = Vlinear(whichCell, nCells_); | 
| 1032 | < |  | 
| 1033 | < | // add this cutoff group to the list of groups in this cell; | 
| 1034 | < | cellListCol_[cellIndex].push_back(i); | 
| 1035 | < | } | 
| 1024 | > |  | 
| 1025 | > | for (int i = 0; i < nGroupsInCol_; i++) { | 
| 1026 | > | rs = cgColData.position[i]; | 
| 1027 | > |  | 
| 1028 | > | // scaled positions relative to the box vectors | 
| 1029 | > | scaled = invHmat * rs; | 
| 1030 | > |  | 
| 1031 | > | // wrap the vector back into the unit box by subtracting integer box | 
| 1032 | > | // numbers | 
| 1033 | > | for (int j = 0; j < 3; j++) { | 
| 1034 | > | scaled[j] -= roundMe(scaled[j]); | 
| 1035 | > | scaled[j] += 0.5; | 
| 1036 | > | } | 
| 1037 | > |  | 
| 1038 | > | // find xyz-indices of cell that cutoffGroup is in. | 
| 1039 | > | whichCell.x() = nCells_.x() * scaled.x(); | 
| 1040 | > | whichCell.y() = nCells_.y() * scaled.y(); | 
| 1041 | > | whichCell.z() = nCells_.z() * scaled.z(); | 
| 1042 | > |  | 
| 1043 | > | // find single index of this cell: | 
| 1044 | > | cellIndex = Vlinear(whichCell, nCells_); | 
| 1045 | > |  | 
| 1046 | > | // add this cutoff group to the list of groups in this cell; | 
| 1047 | > | cellListCol_[cellIndex].push_back(i); | 
| 1048 | > | } | 
| 1049 |  | #else | 
| 1050 | < | for (int i = 0; i < nGroups_; i++) { | 
| 1051 | < | rs = snap_->cgData.position[i]; | 
| 1052 | < |  | 
| 1053 | < | // scaled positions relative to the box vectors | 
| 1054 | < | scaled = invHmat * rs; | 
| 1055 | < |  | 
| 1056 | < | // wrap the vector back into the unit box by subtracting integer box | 
| 1057 | < | // numbers | 
| 1058 | < | for (int j = 0; j < 3; j++) { | 
| 1059 | < | scaled[j] -= roundMe(scaled[j]); | 
| 1060 | < | scaled[j] += 0.5; | 
| 1050 | > | for (int i = 0; i < nGroups_; i++) { | 
| 1051 | > | rs = snap_->cgData.position[i]; | 
| 1052 | > |  | 
| 1053 | > | // scaled positions relative to the box vectors | 
| 1054 | > | scaled = invHmat * rs; | 
| 1055 | > |  | 
| 1056 | > | // wrap the vector back into the unit box by subtracting integer box | 
| 1057 | > | // numbers | 
| 1058 | > | for (int j = 0; j < 3; j++) { | 
| 1059 | > | scaled[j] -= roundMe(scaled[j]); | 
| 1060 | > | scaled[j] += 0.5; | 
| 1061 | > | } | 
| 1062 | > |  | 
| 1063 | > | // find xyz-indices of cell that cutoffGroup is in. | 
| 1064 | > | whichCell.x() = nCells_.x() * scaled.x(); | 
| 1065 | > | whichCell.y() = nCells_.y() * scaled.y(); | 
| 1066 | > | whichCell.z() = nCells_.z() * scaled.z(); | 
| 1067 | > |  | 
| 1068 | > | // find single index of this cell: | 
| 1069 | > | cellIndex = Vlinear(whichCell, nCells_); | 
| 1070 | > |  | 
| 1071 | > | // add this cutoff group to the list of groups in this cell; | 
| 1072 | > | cellList_[cellIndex].push_back(i); | 
| 1073 |  | } | 
| 1029 | – |  | 
| 1030 | – | // find xyz-indices of cell that cutoffGroup is in. | 
| 1031 | – | whichCell.x() = nCells_.x() * scaled.x(); | 
| 1032 | – | whichCell.y() = nCells_.y() * scaled.y(); | 
| 1033 | – | whichCell.z() = nCells_.z() * scaled.z(); | 
| 1034 | – |  | 
| 1035 | – | // find single index of this cell: | 
| 1036 | – | cellIndex = Vlinear(whichCell, nCells_); | 
| 1037 | – |  | 
| 1038 | – | // add this cutoff group to the list of groups in this cell; | 
| 1039 | – | cellList_[cellIndex].push_back(i); | 
| 1040 | – | } | 
| 1074 |  | #endif | 
| 1075 |  |  | 
| 1076 | < | for (int m1z = 0; m1z < nCells_.z(); m1z++) { | 
| 1077 | < | for (int m1y = 0; m1y < nCells_.y(); m1y++) { | 
| 1078 | < | for (int m1x = 0; m1x < nCells_.x(); m1x++) { | 
| 1079 | < | Vector3i m1v(m1x, m1y, m1z); | 
| 1080 | < | int m1 = Vlinear(m1v, nCells_); | 
| 1048 | < |  | 
| 1049 | < | for (vector<Vector3i>::iterator os = cellOffsets_.begin(); | 
| 1050 | < | os != cellOffsets_.end(); ++os) { | 
| 1076 | > | for (int m1z = 0; m1z < nCells_.z(); m1z++) { | 
| 1077 | > | for (int m1y = 0; m1y < nCells_.y(); m1y++) { | 
| 1078 | > | for (int m1x = 0; m1x < nCells_.x(); m1x++) { | 
| 1079 | > | Vector3i m1v(m1x, m1y, m1z); | 
| 1080 | > | int m1 = Vlinear(m1v, nCells_); | 
| 1081 |  |  | 
| 1082 | < | Vector3i m2v = m1v + (*os); | 
| 1083 | < |  | 
| 1084 | < | if (m2v.x() >= nCells_.x()) { | 
| 1085 | < | m2v.x() = 0; | 
| 1086 | < | } else if (m2v.x() < 0) { | 
| 1087 | < | m2v.x() = nCells_.x() - 1; | 
| 1088 | < | } | 
| 1089 | < |  | 
| 1090 | < | if (m2v.y() >= nCells_.y()) { | 
| 1091 | < | m2v.y() = 0; | 
| 1092 | < | } else if (m2v.y() < 0) { | 
| 1093 | < | m2v.y() = nCells_.y() - 1; | 
| 1094 | < | } | 
| 1095 | < |  | 
| 1096 | < | if (m2v.z() >= nCells_.z()) { | 
| 1097 | < | m2v.z() = 0; | 
| 1098 | < | } else if (m2v.z() < 0) { | 
| 1099 | < | m2v.z() = nCells_.z() - 1; | 
| 1100 | < | } | 
| 1101 | < |  | 
| 1102 | < | int m2 = Vlinear (m2v, nCells_); | 
| 1103 | < |  | 
| 1082 | > | for (vector<Vector3i>::iterator os = cellOffsets_.begin(); | 
| 1083 | > | os != cellOffsets_.end(); ++os) { | 
| 1084 | > |  | 
| 1085 | > | Vector3i m2v = m1v + (*os); | 
| 1086 | > |  | 
| 1087 | > | if (m2v.x() >= nCells_.x()) { | 
| 1088 | > | m2v.x() = 0; | 
| 1089 | > | } else if (m2v.x() < 0) { | 
| 1090 | > | m2v.x() = nCells_.x() - 1; | 
| 1091 | > | } | 
| 1092 | > |  | 
| 1093 | > | if (m2v.y() >= nCells_.y()) { | 
| 1094 | > | m2v.y() = 0; | 
| 1095 | > | } else if (m2v.y() < 0) { | 
| 1096 | > | m2v.y() = nCells_.y() - 1; | 
| 1097 | > | } | 
| 1098 | > |  | 
| 1099 | > | if (m2v.z() >= nCells_.z()) { | 
| 1100 | > | m2v.z() = 0; | 
| 1101 | > | } else if (m2v.z() < 0) { | 
| 1102 | > | m2v.z() = nCells_.z() - 1; | 
| 1103 | > | } | 
| 1104 | > |  | 
| 1105 | > | int m2 = Vlinear (m2v, nCells_); | 
| 1106 | > |  | 
| 1107 |  | #ifdef IS_MPI | 
| 1108 | < | for (vector<int>::iterator j1 = cellListRow_[m1].begin(); | 
| 1109 | < | j1 != cellListRow_[m1].end(); ++j1) { | 
| 1110 | < | for (vector<int>::iterator j2 = cellListCol_[m2].begin(); | 
| 1111 | < | j2 != cellListCol_[m2].end(); ++j2) { | 
| 1112 | < |  | 
| 1113 | < | // Always do this if we're in different cells or if | 
| 1114 | < | // we're in the same cell and the global index of the | 
| 1115 | < | // j2 cutoff group is less than the j1 cutoff group | 
| 1116 | < |  | 
| 1117 | < | if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) { | 
| 1118 | < | dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; | 
| 1119 | < | snap_->wrapVector(dr); | 
| 1120 | < | cuts = getGroupCutoffs( (*j1), (*j2) ); | 
| 1121 | < | if (dr.lengthSquare() < cuts.third) { | 
| 1122 | < | neighborList.push_back(make_pair((*j1), (*j2))); | 
| 1108 | > | for (vector<int>::iterator j1 = cellListRow_[m1].begin(); | 
| 1109 | > | j1 != cellListRow_[m1].end(); ++j1) { | 
| 1110 | > | for (vector<int>::iterator j2 = cellListCol_[m2].begin(); | 
| 1111 | > | j2 != cellListCol_[m2].end(); ++j2) { | 
| 1112 | > |  | 
| 1113 | > | // Always do this if we're in different cells or if | 
| 1114 | > | // we're in the same cell and the global index of the | 
| 1115 | > | // j2 cutoff group is less than the j1 cutoff group | 
| 1116 | > |  | 
| 1117 | > | if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) { | 
| 1118 | > | dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; | 
| 1119 | > | snap_->wrapVector(dr); | 
| 1120 | > | cuts = getGroupCutoffs( (*j1), (*j2) ); | 
| 1121 | > | if (dr.lengthSquare() < cuts.third) { | 
| 1122 | > | neighborList.push_back(make_pair((*j1), (*j2))); | 
| 1123 | > | } | 
| 1124 |  | } | 
| 1125 |  | } | 
| 1126 |  | } | 
| 1093 | – | } | 
| 1127 |  | #else | 
| 1128 | < |  | 
| 1129 | < | for (vector<int>::iterator j1 = cellList_[m1].begin(); | 
| 1130 | < | j1 != cellList_[m1].end(); ++j1) { | 
| 1131 | < | for (vector<int>::iterator j2 = cellList_[m2].begin(); | 
| 1132 | < | j2 != cellList_[m2].end(); ++j2) { | 
| 1133 | < |  | 
| 1134 | < | // Always do this if we're in different cells or if | 
| 1135 | < | // we're in the same cell and the global index of the | 
| 1136 | < | // j2 cutoff group is less than the j1 cutoff group | 
| 1137 | < |  | 
| 1138 | < | if (m2 != m1 || (*j2) < (*j1)) { | 
| 1139 | < | dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)]; | 
| 1140 | < | snap_->wrapVector(dr); | 
| 1141 | < | cuts = getGroupCutoffs( (*j1), (*j2) ); | 
| 1142 | < | if (dr.lengthSquare() < cuts.third) { | 
| 1143 | < | neighborList.push_back(make_pair((*j1), (*j2))); | 
| 1128 | > |  | 
| 1129 | > | for (vector<int>::iterator j1 = cellList_[m1].begin(); | 
| 1130 | > | j1 != cellList_[m1].end(); ++j1) { | 
| 1131 | > | for (vector<int>::iterator j2 = cellList_[m2].begin(); | 
| 1132 | > | j2 != cellList_[m2].end(); ++j2) { | 
| 1133 | > |  | 
| 1134 | > | // Always do this if we're in different cells or if | 
| 1135 | > | // we're in the same cell and the global index of the | 
| 1136 | > | // j2 cutoff group is less than the j1 cutoff group | 
| 1137 | > |  | 
| 1138 | > | if (m2 != m1 || (*j2) < (*j1)) { | 
| 1139 | > | dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)]; | 
| 1140 | > | snap_->wrapVector(dr); | 
| 1141 | > | cuts = getGroupCutoffs( (*j1), (*j2) ); | 
| 1142 | > | if (dr.lengthSquare() < cuts.third) { | 
| 1143 | > | neighborList.push_back(make_pair((*j1), (*j2))); | 
| 1144 | > | } | 
| 1145 |  | } | 
| 1146 |  | } | 
| 1147 |  | } | 
| 1114 | – | } | 
| 1148 |  | #endif | 
| 1149 | + | } | 
| 1150 |  | } | 
| 1151 |  | } | 
| 1152 |  | } | 
| 1153 | + | } else { | 
| 1154 | + | // branch to do all cutoff group pairs | 
| 1155 | + | #ifdef IS_MPI | 
| 1156 | + | for (int j1 = 0; j1 < nGroupsInRow_; j1++) { | 
| 1157 | + | for (int j2 = 0; j2 < nGroupsInCol_; j2++) { | 
| 1158 | + | dr = cgColData.position[j2] - cgRowData.position[j1]; | 
| 1159 | + | snap_->wrapVector(dr); | 
| 1160 | + | cuts = getGroupCutoffs( j1, j2 ); | 
| 1161 | + | if (dr.lengthSquare() < cuts.third) { | 
| 1162 | + | neighborList.push_back(make_pair(j1, j2)); | 
| 1163 | + | } | 
| 1164 | + | } | 
| 1165 | + | } | 
| 1166 | + | #else | 
| 1167 | + | for (int j1 = 0; j1 < nGroups_ - 1; j1++) { | 
| 1168 | + | for (int j2 = j1 + 1; j2 < nGroups_; j2++) { | 
| 1169 | + | dr = snap_->cgData.position[j2] - snap_->cgData.position[j1]; | 
| 1170 | + | snap_->wrapVector(dr); | 
| 1171 | + | cuts = getGroupCutoffs( j1, j2 ); | 
| 1172 | + | if (dr.lengthSquare() < cuts.third) { | 
| 1173 | + | neighborList.push_back(make_pair(j1, j2)); | 
| 1174 | + | } | 
| 1175 | + | } | 
| 1176 | + | } | 
| 1177 | + | #endif | 
| 1178 |  | } | 
| 1179 | < |  | 
| 1179 | > |  | 
| 1180 |  | // save the local cutoff group positions for the check that is | 
| 1181 |  | // done on each loop: | 
| 1182 |  | saved_CG_positions_.clear(); | 
| 1183 |  | for (int i = 0; i < nGroups_; i++) | 
| 1184 |  | saved_CG_positions_.push_back(snap_->cgData.position[i]); | 
| 1185 | < |  | 
| 1185 | > |  | 
| 1186 |  | return neighborList; | 
| 1187 |  | } | 
| 1188 |  | } //end namespace OpenMD |