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). |
39 |
< |
* [4] Vardeman & Gezelter, in progress (2009). |
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 |
|
*/ |
42 |
|
#include "parallel/ForceMatrixDecomposition.hpp" |
43 |
|
#include "math/SquareMatrix3.hpp" |
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(); |
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(); |
123 |
< |
MPI::Intracomm col = colComm.getComm(); |
122 |
> |
MPI_Comm row = rowComm.getComm(); |
123 |
> |
MPI_Comm col = colComm.getComm(); |
124 |
|
|
125 |
|
AtomPlanIntRow = new Plan<int>(row, nLocal_); |
126 |
|
AtomPlanRealRow = new Plan<RealType>(row, nLocal_); |
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_); |
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); |
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; |
298 |
– |
RealType rc; |
324 |
|
int atid; |
325 |
|
set<AtomType*> atypes = info_->getSimulatedAtomTypes(); |
326 |
|
|
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; |
424 |
|
gTypeCutoffs.end()); |
425 |
|
|
426 |
|
#ifdef IS_MPI |
427 |
< |
MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE, |
428 |
< |
MPI::MAX); |
427 |
> |
MPI_Allreduce(MPI_IN_PLACE, &groupMax, 1, MPI_REALTYPE, |
428 |
> |
MPI_MAX, MPI_COMM_WORLD); |
429 |
|
#endif |
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: |
462 |
|
break; |
463 |
|
} |
464 |
|
|
465 |
< |
pair<int,int> key = make_pair(i,j); |
432 |
< |
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_); |
486 |
|
} |
487 |
|
} |
488 |
|
|
489 |
< |
|
453 |
< |
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]; |
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) { |
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); |
572 |
|
atomColData.skippedCharge.end(), 0.0); |
573 |
|
} |
574 |
|
|
575 |
+ |
if (storageLayout_ & DataStorage::dslFlucQForce) { |
576 |
+ |
fill(atomRowData.flucQFrc.begin(), |
577 |
+ |
atomRowData.flucQFrc.end(), 0.0); |
578 |
+ |
fill(atomColData.flucQFrc.begin(), |
579 |
+ |
atomColData.flucQFrc.end(), 0.0); |
580 |
+ |
} |
581 |
+ |
|
582 |
+ |
if (storageLayout_ & DataStorage::dslElectricField) { |
583 |
+ |
fill(atomRowData.electricField.begin(), |
584 |
+ |
atomRowData.electricField.end(), V3Zero); |
585 |
+ |
fill(atomColData.electricField.begin(), |
586 |
+ |
atomColData.electricField.end(), V3Zero); |
587 |
+ |
} |
588 |
+ |
|
589 |
+ |
if (storageLayout_ & DataStorage::dslSitePotential) { |
590 |
+ |
fill(atomRowData.sitePotential.begin(), |
591 |
+ |
atomRowData.sitePotential.end(), 0.0); |
592 |
+ |
fill(atomColData.sitePotential.begin(), |
593 |
+ |
atomColData.sitePotential.end(), 0.0); |
594 |
+ |
} |
595 |
+ |
|
596 |
|
#endif |
597 |
|
// even in parallel, we need to zero out the local arrays: |
598 |
|
|
605 |
|
fill(snap_->atomData.density.begin(), |
606 |
|
snap_->atomData.density.end(), 0.0); |
607 |
|
} |
608 |
+ |
|
609 |
|
if (storageLayout_ & DataStorage::dslFunctional) { |
610 |
|
fill(snap_->atomData.functional.begin(), |
611 |
|
snap_->atomData.functional.end(), 0.0); |
612 |
|
} |
613 |
+ |
|
614 |
|
if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
615 |
|
fill(snap_->atomData.functionalDerivative.begin(), |
616 |
|
snap_->atomData.functionalDerivative.end(), 0.0); |
617 |
|
} |
618 |
+ |
|
619 |
|
if (storageLayout_ & DataStorage::dslSkippedCharge) { |
620 |
|
fill(snap_->atomData.skippedCharge.begin(), |
621 |
|
snap_->atomData.skippedCharge.end(), 0.0); |
622 |
|
} |
623 |
< |
|
623 |
> |
|
624 |
> |
if (storageLayout_ & DataStorage::dslElectricField) { |
625 |
> |
fill(snap_->atomData.electricField.begin(), |
626 |
> |
snap_->atomData.electricField.end(), V3Zero); |
627 |
> |
} |
628 |
> |
if (storageLayout_ & DataStorage::dslSitePotential) { |
629 |
> |
fill(snap_->atomData.sitePotential.begin(), |
630 |
> |
snap_->atomData.sitePotential.end(), 0.0); |
631 |
> |
} |
632 |
|
} |
633 |
|
|
634 |
|
|
651 |
|
cgPlanVectorColumn->gather(snap_->cgData.position, |
652 |
|
cgColData.position); |
653 |
|
|
654 |
+ |
|
655 |
+ |
|
656 |
+ |
if (needVelocities_) { |
657 |
+ |
// gather up the atomic velocities |
658 |
+ |
AtomPlanVectorColumn->gather(snap_->atomData.velocity, |
659 |
+ |
atomColData.velocity); |
660 |
+ |
|
661 |
+ |
cgPlanVectorColumn->gather(snap_->cgData.velocity, |
662 |
+ |
cgColData.velocity); |
663 |
+ |
} |
664 |
+ |
|
665 |
|
|
666 |
|
// if needed, gather the atomic rotation matrices |
667 |
|
if (storageLayout_ & DataStorage::dslAmat) { |
670 |
|
AtomPlanMatrixColumn->gather(snap_->atomData.aMat, |
671 |
|
atomColData.aMat); |
672 |
|
} |
673 |
< |
|
674 |
< |
// if needed, gather the atomic eletrostatic frames |
675 |
< |
if (storageLayout_ & DataStorage::dslElectroFrame) { |
676 |
< |
AtomPlanMatrixRow->gather(snap_->atomData.electroFrame, |
677 |
< |
atomRowData.electroFrame); |
678 |
< |
AtomPlanMatrixColumn->gather(snap_->atomData.electroFrame, |
679 |
< |
atomColData.electroFrame); |
673 |
> |
|
674 |
> |
// if needed, gather the atomic eletrostatic information |
675 |
> |
if (storageLayout_ & DataStorage::dslDipole) { |
676 |
> |
AtomPlanVectorRow->gather(snap_->atomData.dipole, |
677 |
> |
atomRowData.dipole); |
678 |
> |
AtomPlanVectorColumn->gather(snap_->atomData.dipole, |
679 |
> |
atomColData.dipole); |
680 |
> |
} |
681 |
> |
|
682 |
> |
if (storageLayout_ & DataStorage::dslQuadrupole) { |
683 |
> |
AtomPlanMatrixRow->gather(snap_->atomData.quadrupole, |
684 |
> |
atomRowData.quadrupole); |
685 |
> |
AtomPlanMatrixColumn->gather(snap_->atomData.quadrupole, |
686 |
> |
atomColData.quadrupole); |
687 |
> |
} |
688 |
> |
|
689 |
> |
// if needed, gather the atomic fluctuating charge values |
690 |
> |
if (storageLayout_ & DataStorage::dslFlucQPosition) { |
691 |
> |
AtomPlanRealRow->gather(snap_->atomData.flucQPos, |
692 |
> |
atomRowData.flucQPos); |
693 |
> |
AtomPlanRealColumn->gather(snap_->atomData.flucQPos, |
694 |
> |
atomColData.flucQPos); |
695 |
|
} |
696 |
|
|
697 |
|
#endif |
716 |
|
for (int i = 0; i < n; i++) |
717 |
|
snap_->atomData.density[i] += rho_tmp[i]; |
718 |
|
} |
719 |
+ |
|
720 |
+ |
// this isn't necessary if we don't have polarizable atoms, but |
721 |
+ |
// we'll leave it here for now. |
722 |
+ |
if (storageLayout_ & DataStorage::dslElectricField) { |
723 |
+ |
|
724 |
+ |
AtomPlanVectorRow->scatter(atomRowData.electricField, |
725 |
+ |
snap_->atomData.electricField); |
726 |
+ |
|
727 |
+ |
int n = snap_->atomData.electricField.size(); |
728 |
+ |
vector<Vector3d> field_tmp(n, V3Zero); |
729 |
+ |
AtomPlanVectorColumn->scatter(atomColData.electricField, |
730 |
+ |
field_tmp); |
731 |
+ |
for (int i = 0; i < n; i++) |
732 |
+ |
snap_->atomData.electricField[i] += field_tmp[i]; |
733 |
+ |
} |
734 |
|
#endif |
735 |
|
} |
736 |
|
|
810 |
|
|
811 |
|
} |
812 |
|
|
813 |
+ |
if (storageLayout_ & DataStorage::dslFlucQForce) { |
814 |
+ |
|
815 |
+ |
int nq = snap_->atomData.flucQFrc.size(); |
816 |
+ |
vector<RealType> fqfrc_tmp(nq, 0.0); |
817 |
+ |
|
818 |
+ |
AtomPlanRealRow->scatter(atomRowData.flucQFrc, fqfrc_tmp); |
819 |
+ |
for (int i = 0; i < nq; i++) { |
820 |
+ |
snap_->atomData.flucQFrc[i] += fqfrc_tmp[i]; |
821 |
+ |
fqfrc_tmp[i] = 0.0; |
822 |
+ |
} |
823 |
+ |
|
824 |
+ |
AtomPlanRealColumn->scatter(atomColData.flucQFrc, fqfrc_tmp); |
825 |
+ |
for (int i = 0; i < nq; i++) |
826 |
+ |
snap_->atomData.flucQFrc[i] += fqfrc_tmp[i]; |
827 |
+ |
|
828 |
+ |
} |
829 |
+ |
|
830 |
+ |
if (storageLayout_ & DataStorage::dslElectricField) { |
831 |
+ |
|
832 |
+ |
int nef = snap_->atomData.electricField.size(); |
833 |
+ |
vector<Vector3d> efield_tmp(nef, V3Zero); |
834 |
+ |
|
835 |
+ |
AtomPlanVectorRow->scatter(atomRowData.electricField, efield_tmp); |
836 |
+ |
for (int i = 0; i < nef; i++) { |
837 |
+ |
snap_->atomData.electricField[i] += efield_tmp[i]; |
838 |
+ |
efield_tmp[i] = 0.0; |
839 |
+ |
} |
840 |
+ |
|
841 |
+ |
AtomPlanVectorColumn->scatter(atomColData.electricField, efield_tmp); |
842 |
+ |
for (int i = 0; i < nef; i++) |
843 |
+ |
snap_->atomData.electricField[i] += efield_tmp[i]; |
844 |
+ |
} |
845 |
+ |
|
846 |
+ |
if (storageLayout_ & DataStorage::dslSitePotential) { |
847 |
+ |
|
848 |
+ |
int nsp = snap_->atomData.sitePotential.size(); |
849 |
+ |
vector<RealType> sp_tmp(nsp, 0.0); |
850 |
+ |
|
851 |
+ |
AtomPlanRealRow->scatter(atomRowData.sitePotential, sp_tmp); |
852 |
+ |
for (int i = 0; i < nsp; i++) { |
853 |
+ |
snap_->atomData.sitePotential[i] += sp_tmp[i]; |
854 |
+ |
sp_tmp[i] = 0.0; |
855 |
+ |
} |
856 |
+ |
|
857 |
+ |
AtomPlanRealColumn->scatter(atomColData.sitePotential, sp_tmp); |
858 |
+ |
for (int i = 0; i < nsp; i++) |
859 |
+ |
snap_->atomData.sitePotential[i] += sp_tmp[i]; |
860 |
+ |
} |
861 |
+ |
|
862 |
|
nLocal_ = snap_->getNumberOfAtoms(); |
863 |
|
|
864 |
|
vector<potVec> pot_temp(nLocal_, |
865 |
|
Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
866 |
+ |
vector<potVec> expot_temp(nLocal_, |
867 |
+ |
Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
868 |
|
|
869 |
|
// scatter/gather pot_row into the members of my column |
870 |
|
|
871 |
|
AtomPlanPotRow->scatter(pot_row, pot_temp); |
872 |
+ |
AtomPlanPotRow->scatter(expot_row, expot_temp); |
873 |
|
|
874 |
< |
for (int ii = 0; ii < pot_temp.size(); ii++ ) |
874 |
> |
for (int ii = 0; ii < pot_temp.size(); ii++ ) |
875 |
|
pairwisePot += pot_temp[ii]; |
876 |
< |
|
876 |
> |
|
877 |
> |
for (int ii = 0; ii < expot_temp.size(); ii++ ) |
878 |
> |
excludedPot += expot_temp[ii]; |
879 |
> |
|
880 |
> |
if (storageLayout_ & DataStorage::dslParticlePot) { |
881 |
> |
// This is the pairwise contribution to the particle pot. The |
882 |
> |
// embedding contribution is added in each of the low level |
883 |
> |
// non-bonded routines. In single processor, this is done in |
884 |
> |
// unpackInteractionData, not in collectData. |
885 |
> |
for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { |
886 |
> |
for (int i = 0; i < nLocal_; i++) { |
887 |
> |
// factor of two is because the total potential terms are divided |
888 |
> |
// by 2 in parallel due to row/ column scatter |
889 |
> |
snap_->atomData.particlePot[i] += 2.0 * pot_temp[i](ii); |
890 |
> |
} |
891 |
> |
} |
892 |
> |
} |
893 |
> |
|
894 |
|
fill(pot_temp.begin(), pot_temp.end(), |
895 |
|
Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
896 |
+ |
fill(expot_temp.begin(), expot_temp.end(), |
897 |
+ |
Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
898 |
|
|
899 |
|
AtomPlanPotColumn->scatter(pot_col, pot_temp); |
900 |
+ |
AtomPlanPotColumn->scatter(expot_col, expot_temp); |
901 |
|
|
902 |
|
for (int ii = 0; ii < pot_temp.size(); ii++ ) |
903 |
|
pairwisePot += pot_temp[ii]; |
904 |
+ |
|
905 |
+ |
for (int ii = 0; ii < expot_temp.size(); ii++ ) |
906 |
+ |
excludedPot += expot_temp[ii]; |
907 |
+ |
|
908 |
+ |
if (storageLayout_ & DataStorage::dslParticlePot) { |
909 |
+ |
// This is the pairwise contribution to the particle pot. The |
910 |
+ |
// embedding contribution is added in each of the low level |
911 |
+ |
// non-bonded routines. In single processor, this is done in |
912 |
+ |
// unpackInteractionData, not in collectData. |
913 |
+ |
for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { |
914 |
+ |
for (int i = 0; i < nLocal_; i++) { |
915 |
+ |
// factor of two is because the total potential terms are divided |
916 |
+ |
// by 2 in parallel due to row/ column scatter |
917 |
+ |
snap_->atomData.particlePot[i] += 2.0 * pot_temp[i](ii); |
918 |
+ |
} |
919 |
+ |
} |
920 |
+ |
} |
921 |
|
|
922 |
+ |
if (storageLayout_ & DataStorage::dslParticlePot) { |
923 |
+ |
int npp = snap_->atomData.particlePot.size(); |
924 |
+ |
vector<RealType> ppot_temp(npp, 0.0); |
925 |
+ |
|
926 |
+ |
// This is the direct or embedding contribution to the particle |
927 |
+ |
// pot. |
928 |
+ |
|
929 |
+ |
AtomPlanRealRow->scatter(atomRowData.particlePot, ppot_temp); |
930 |
+ |
for (int i = 0; i < npp; i++) { |
931 |
+ |
snap_->atomData.particlePot[i] += ppot_temp[i]; |
932 |
+ |
} |
933 |
+ |
|
934 |
+ |
fill(ppot_temp.begin(), ppot_temp.end(), 0.0); |
935 |
+ |
|
936 |
+ |
AtomPlanRealColumn->scatter(atomColData.particlePot, ppot_temp); |
937 |
+ |
for (int i = 0; i < npp; i++) { |
938 |
+ |
snap_->atomData.particlePot[i] += ppot_temp[i]; |
939 |
+ |
} |
940 |
+ |
} |
941 |
+ |
|
942 |
|
for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { |
943 |
|
RealType ploc1 = pairwisePot[ii]; |
944 |
|
RealType ploc2 = 0.0; |
945 |
< |
MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM); |
945 |
> |
MPI_Allreduce(&ploc1, &ploc2, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
946 |
|
pairwisePot[ii] = ploc2; |
947 |
|
} |
948 |
|
|
949 |
|
for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { |
950 |
< |
RealType ploc1 = embeddingPot[ii]; |
950 |
> |
RealType ploc1 = excludedPot[ii]; |
951 |
|
RealType ploc2 = 0.0; |
952 |
< |
MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM); |
953 |
< |
embeddingPot[ii] = ploc2; |
952 |
> |
MPI_Allreduce(&ploc1, &ploc2, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
953 |
> |
excludedPot[ii] = ploc2; |
954 |
|
} |
955 |
|
|
956 |
+ |
// Here be dragons. |
957 |
+ |
MPI_Comm col = colComm.getComm(); |
958 |
+ |
|
959 |
+ |
MPI_Allreduce(MPI_IN_PLACE, |
960 |
+ |
&snap_->frameData.conductiveHeatFlux[0], 3, |
961 |
+ |
MPI_REALTYPE, MPI_SUM, col); |
962 |
+ |
|
963 |
+ |
|
964 |
|
#endif |
965 |
|
|
966 |
|
} |
967 |
|
|
968 |
< |
int ForceMatrixDecomposition::getNAtomsInRow() { |
968 |
> |
/** |
969 |
> |
* Collects information obtained during the post-pair (and embedding |
970 |
> |
* functional) loops onto local data structures. |
971 |
> |
*/ |
972 |
> |
void ForceMatrixDecomposition::collectSelfData() { |
973 |
> |
snap_ = sman_->getCurrentSnapshot(); |
974 |
> |
storageLayout_ = sman_->getStorageLayout(); |
975 |
> |
|
976 |
|
#ifdef IS_MPI |
977 |
+ |
for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { |
978 |
+ |
RealType ploc1 = embeddingPot[ii]; |
979 |
+ |
RealType ploc2 = 0.0; |
980 |
+ |
MPI_Allreduce(&ploc1, &ploc2, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
981 |
+ |
embeddingPot[ii] = ploc2; |
982 |
+ |
} |
983 |
+ |
for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { |
984 |
+ |
RealType ploc1 = excludedSelfPot[ii]; |
985 |
+ |
RealType ploc2 = 0.0; |
986 |
+ |
MPI_Allreduce(&ploc1, &ploc2, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
987 |
+ |
excludedSelfPot[ii] = ploc2; |
988 |
+ |
} |
989 |
+ |
#endif |
990 |
+ |
|
991 |
+ |
} |
992 |
+ |
|
993 |
+ |
|
994 |
+ |
|
995 |
+ |
int& ForceMatrixDecomposition::getNAtomsInRow() { |
996 |
+ |
#ifdef IS_MPI |
997 |
|
return nAtomsInRow_; |
998 |
|
#else |
999 |
|
return nLocal_; |
1003 |
|
/** |
1004 |
|
* returns the list of atoms belonging to this group. |
1005 |
|
*/ |
1006 |
< |
vector<int> ForceMatrixDecomposition::getAtomsInGroupRow(int cg1){ |
1006 |
> |
vector<int>& ForceMatrixDecomposition::getAtomsInGroupRow(int cg1){ |
1007 |
|
#ifdef IS_MPI |
1008 |
|
return groupListRow_[cg1]; |
1009 |
|
#else |
1011 |
|
#endif |
1012 |
|
} |
1013 |
|
|
1014 |
< |
vector<int> ForceMatrixDecomposition::getAtomsInGroupColumn(int cg2){ |
1014 |
> |
vector<int>& ForceMatrixDecomposition::getAtomsInGroupColumn(int cg2){ |
1015 |
|
#ifdef IS_MPI |
1016 |
|
return groupListCol_[cg2]; |
1017 |
|
#else |
1028 |
|
d = snap_->cgData.position[cg2] - snap_->cgData.position[cg1]; |
1029 |
|
#endif |
1030 |
|
|
1031 |
< |
snap_->wrapVector(d); |
1031 |
> |
if (usePeriodicBoundaryConditions_) { |
1032 |
> |
snap_->wrapVector(d); |
1033 |
> |
} |
1034 |
|
return d; |
1035 |
|
} |
1036 |
|
|
1037 |
+ |
Vector3d& ForceMatrixDecomposition::getGroupVelocityColumn(int cg2){ |
1038 |
+ |
#ifdef IS_MPI |
1039 |
+ |
return cgColData.velocity[cg2]; |
1040 |
+ |
#else |
1041 |
+ |
return snap_->cgData.velocity[cg2]; |
1042 |
+ |
#endif |
1043 |
+ |
} |
1044 |
|
|
1045 |
+ |
Vector3d& ForceMatrixDecomposition::getAtomVelocityColumn(int atom2){ |
1046 |
+ |
#ifdef IS_MPI |
1047 |
+ |
return atomColData.velocity[atom2]; |
1048 |
+ |
#else |
1049 |
+ |
return snap_->atomData.velocity[atom2]; |
1050 |
+ |
#endif |
1051 |
+ |
} |
1052 |
+ |
|
1053 |
+ |
|
1054 |
|
Vector3d ForceMatrixDecomposition::getAtomToGroupVectorRow(int atom1, int cg1){ |
1055 |
|
|
1056 |
|
Vector3d d; |
1060 |
|
#else |
1061 |
|
d = snap_->cgData.position[cg1] - snap_->atomData.position[atom1]; |
1062 |
|
#endif |
1063 |
< |
|
1064 |
< |
snap_->wrapVector(d); |
1063 |
> |
if (usePeriodicBoundaryConditions_) { |
1064 |
> |
snap_->wrapVector(d); |
1065 |
> |
} |
1066 |
|
return d; |
1067 |
|
} |
1068 |
|
|
1074 |
|
#else |
1075 |
|
d = snap_->cgData.position[cg2] - snap_->atomData.position[atom2]; |
1076 |
|
#endif |
1077 |
< |
|
1078 |
< |
snap_->wrapVector(d); |
1077 |
> |
if (usePeriodicBoundaryConditions_) { |
1078 |
> |
snap_->wrapVector(d); |
1079 |
> |
} |
1080 |
|
return d; |
1081 |
|
} |
1082 |
|
|
1083 |
< |
RealType ForceMatrixDecomposition::getMassFactorRow(int atom1) { |
1083 |
> |
RealType& ForceMatrixDecomposition::getMassFactorRow(int atom1) { |
1084 |
|
#ifdef IS_MPI |
1085 |
|
return massFactorsRow[atom1]; |
1086 |
|
#else |
1088 |
|
#endif |
1089 |
|
} |
1090 |
|
|
1091 |
< |
RealType ForceMatrixDecomposition::getMassFactorColumn(int atom2) { |
1091 |
> |
RealType& ForceMatrixDecomposition::getMassFactorColumn(int atom2) { |
1092 |
|
#ifdef IS_MPI |
1093 |
|
return massFactorsCol[atom2]; |
1094 |
|
#else |
1105 |
|
#else |
1106 |
|
d = snap_->atomData.position[atom2] - snap_->atomData.position[atom1]; |
1107 |
|
#endif |
1108 |
< |
|
1109 |
< |
snap_->wrapVector(d); |
1108 |
> |
if (usePeriodicBoundaryConditions_) { |
1109 |
> |
snap_->wrapVector(d); |
1110 |
> |
} |
1111 |
|
return d; |
1112 |
|
} |
1113 |
|
|
1114 |
< |
vector<int> ForceMatrixDecomposition::getExcludesForAtom(int atom1) { |
1114 |
> |
vector<int>& ForceMatrixDecomposition::getExcludesForAtom(int atom1) { |
1115 |
|
return excludesForAtom[atom1]; |
1116 |
|
} |
1117 |
|
|
1119 |
|
* We need to exclude some overcounted interactions that result from |
1120 |
|
* the parallel decomposition. |
1121 |
|
*/ |
1122 |
< |
bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) { |
1122 |
> |
bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2, int cg1, int cg2) { |
1123 |
|
int unique_id_1, unique_id_2; |
1124 |
|
|
1125 |
|
#ifdef IS_MPI |
1126 |
|
// in MPI, we have to look up the unique IDs for each atom |
1127 |
|
unique_id_1 = AtomRowToGlobal[atom1]; |
1128 |
|
unique_id_2 = AtomColToGlobal[atom2]; |
1129 |
+ |
// group1 = cgRowToGlobal[cg1]; |
1130 |
+ |
// group2 = cgColToGlobal[cg2]; |
1131 |
|
#else |
1132 |
|
unique_id_1 = AtomLocalToGlobal[atom1]; |
1133 |
|
unique_id_2 = AtomLocalToGlobal[atom2]; |
1134 |
+ |
int group1 = cgLocalToGlobal[cg1]; |
1135 |
+ |
int group2 = cgLocalToGlobal[cg2]; |
1136 |
|
#endif |
1137 |
|
|
1138 |
|
if (unique_id_1 == unique_id_2) return true; |
1144 |
|
} else { |
1145 |
|
if ((unique_id_1 + unique_id_2) % 2 == 1) return true; |
1146 |
|
} |
1147 |
+ |
#endif |
1148 |
+ |
|
1149 |
+ |
#ifndef IS_MPI |
1150 |
+ |
if (group1 == group2) { |
1151 |
+ |
if (unique_id_1 < unique_id_2) return true; |
1152 |
+ |
} |
1153 |
|
#endif |
1154 |
|
|
1155 |
|
return false; |
1201 |
|
idat.excluded = excludeAtomPair(atom1, atom2); |
1202 |
|
|
1203 |
|
#ifdef IS_MPI |
1204 |
< |
idat.atypes = make_pair( atypesRow[atom1], atypesCol[atom2]); |
1205 |
< |
//idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
1206 |
< |
// ff_->getAtomType(identsCol[atom2]) ); |
1207 |
< |
|
1204 |
> |
//idat.atypes = make_pair( atypesRow[atom1], atypesCol[atom2]); |
1205 |
> |
idat.atid1 = identsRow[atom1]; |
1206 |
> |
idat.atid2 = identsCol[atom2]; |
1207 |
> |
|
1208 |
> |
if (regionsRow[atom1] >= 0 && regionsCol[atom2] >= 0) { |
1209 |
> |
idat.sameRegion = (regionsRow[atom1] == regionsCol[atom2]); |
1210 |
> |
} else { |
1211 |
> |
idat.sameRegion = false; |
1212 |
> |
} |
1213 |
> |
|
1214 |
|
if (storageLayout_ & DataStorage::dslAmat) { |
1215 |
|
idat.A1 = &(atomRowData.aMat[atom1]); |
1216 |
|
idat.A2 = &(atomColData.aMat[atom2]); |
1217 |
|
} |
1218 |
|
|
917 |
– |
if (storageLayout_ & DataStorage::dslElectroFrame) { |
918 |
– |
idat.eFrame1 = &(atomRowData.electroFrame[atom1]); |
919 |
– |
idat.eFrame2 = &(atomColData.electroFrame[atom2]); |
920 |
– |
} |
921 |
– |
|
1219 |
|
if (storageLayout_ & DataStorage::dslTorque) { |
1220 |
|
idat.t1 = &(atomRowData.torque[atom1]); |
1221 |
|
idat.t2 = &(atomColData.torque[atom2]); |
1222 |
|
} |
1223 |
|
|
1224 |
+ |
if (storageLayout_ & DataStorage::dslDipole) { |
1225 |
+ |
idat.dipole1 = &(atomRowData.dipole[atom1]); |
1226 |
+ |
idat.dipole2 = &(atomColData.dipole[atom2]); |
1227 |
+ |
} |
1228 |
+ |
|
1229 |
+ |
if (storageLayout_ & DataStorage::dslQuadrupole) { |
1230 |
+ |
idat.quadrupole1 = &(atomRowData.quadrupole[atom1]); |
1231 |
+ |
idat.quadrupole2 = &(atomColData.quadrupole[atom2]); |
1232 |
+ |
} |
1233 |
+ |
|
1234 |
|
if (storageLayout_ & DataStorage::dslDensity) { |
1235 |
|
idat.rho1 = &(atomRowData.density[atom1]); |
1236 |
|
idat.rho2 = &(atomColData.density[atom2]); |
1256 |
|
idat.skippedCharge2 = &(atomColData.skippedCharge[atom2]); |
1257 |
|
} |
1258 |
|
|
1259 |
+ |
if (storageLayout_ & DataStorage::dslFlucQPosition) { |
1260 |
+ |
idat.flucQ1 = &(atomRowData.flucQPos[atom1]); |
1261 |
+ |
idat.flucQ2 = &(atomColData.flucQPos[atom2]); |
1262 |
+ |
} |
1263 |
+ |
|
1264 |
|
#else |
1265 |
+ |
|
1266 |
+ |
//idat.atypes = make_pair( atypesLocal[atom1], atypesLocal[atom2]); |
1267 |
+ |
idat.atid1 = idents[atom1]; |
1268 |
+ |
idat.atid2 = idents[atom2]; |
1269 |
|
|
1270 |
< |
idat.atypes = make_pair( atypesLocal[atom1], atypesLocal[atom2]); |
1271 |
< |
//idat.atypes = make_pair( ff_->getAtomType(idents[atom1]), |
1272 |
< |
// ff_->getAtomType(idents[atom2]) ); |
1270 |
> |
if (regions[atom1] >= 0 && regions[atom2] >= 0) { |
1271 |
> |
idat.sameRegion = (regions[atom1] == regions[atom2]); |
1272 |
> |
} else { |
1273 |
> |
idat.sameRegion = false; |
1274 |
> |
} |
1275 |
|
|
1276 |
|
if (storageLayout_ & DataStorage::dslAmat) { |
1277 |
|
idat.A1 = &(snap_->atomData.aMat[atom1]); |
1278 |
|
idat.A2 = &(snap_->atomData.aMat[atom2]); |
1279 |
|
} |
1280 |
|
|
963 |
– |
if (storageLayout_ & DataStorage::dslElectroFrame) { |
964 |
– |
idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]); |
965 |
– |
idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]); |
966 |
– |
} |
967 |
– |
|
1281 |
|
if (storageLayout_ & DataStorage::dslTorque) { |
1282 |
|
idat.t1 = &(snap_->atomData.torque[atom1]); |
1283 |
|
idat.t2 = &(snap_->atomData.torque[atom2]); |
1284 |
|
} |
1285 |
|
|
1286 |
+ |
if (storageLayout_ & DataStorage::dslDipole) { |
1287 |
+ |
idat.dipole1 = &(snap_->atomData.dipole[atom1]); |
1288 |
+ |
idat.dipole2 = &(snap_->atomData.dipole[atom2]); |
1289 |
+ |
} |
1290 |
+ |
|
1291 |
+ |
if (storageLayout_ & DataStorage::dslQuadrupole) { |
1292 |
+ |
idat.quadrupole1 = &(snap_->atomData.quadrupole[atom1]); |
1293 |
+ |
idat.quadrupole2 = &(snap_->atomData.quadrupole[atom2]); |
1294 |
+ |
} |
1295 |
+ |
|
1296 |
|
if (storageLayout_ & DataStorage::dslDensity) { |
1297 |
|
idat.rho1 = &(snap_->atomData.density[atom1]); |
1298 |
|
idat.rho2 = &(snap_->atomData.density[atom2]); |
1317 |
|
idat.skippedCharge1 = &(snap_->atomData.skippedCharge[atom1]); |
1318 |
|
idat.skippedCharge2 = &(snap_->atomData.skippedCharge[atom2]); |
1319 |
|
} |
1320 |
+ |
|
1321 |
+ |
if (storageLayout_ & DataStorage::dslFlucQPosition) { |
1322 |
+ |
idat.flucQ1 = &(snap_->atomData.flucQPos[atom1]); |
1323 |
+ |
idat.flucQ2 = &(snap_->atomData.flucQPos[atom2]); |
1324 |
+ |
} |
1325 |
+ |
|
1326 |
|
#endif |
1327 |
|
} |
1328 |
|
|
1329 |
|
|
1330 |
|
void ForceMatrixDecomposition::unpackInteractionData(InteractionData &idat, int atom1, int atom2) { |
1331 |
|
#ifdef IS_MPI |
1332 |
< |
pot_row[atom1] += 0.5 * *(idat.pot); |
1333 |
< |
pot_col[atom2] += 0.5 * *(idat.pot); |
1332 |
> |
pot_row[atom1] += RealType(0.5) * *(idat.pot); |
1333 |
> |
pot_col[atom2] += RealType(0.5) * *(idat.pot); |
1334 |
> |
expot_row[atom1] += RealType(0.5) * *(idat.excludedPot); |
1335 |
> |
expot_col[atom2] += RealType(0.5) * *(idat.excludedPot); |
1336 |
|
|
1337 |
|
atomRowData.force[atom1] += *(idat.f1); |
1338 |
|
atomColData.force[atom2] -= *(idat.f1); |
1339 |
+ |
|
1340 |
+ |
if (storageLayout_ & DataStorage::dslFlucQForce) { |
1341 |
+ |
atomRowData.flucQFrc[atom1] -= *(idat.dVdFQ1); |
1342 |
+ |
atomColData.flucQFrc[atom2] -= *(idat.dVdFQ2); |
1343 |
+ |
} |
1344 |
+ |
|
1345 |
+ |
if (storageLayout_ & DataStorage::dslElectricField) { |
1346 |
+ |
atomRowData.electricField[atom1] += *(idat.eField1); |
1347 |
+ |
atomColData.electricField[atom2] += *(idat.eField2); |
1348 |
+ |
} |
1349 |
+ |
|
1350 |
+ |
if (storageLayout_ & DataStorage::dslSitePotential) { |
1351 |
+ |
atomRowData.sitePotential[atom1] += *(idat.sPot1); |
1352 |
+ |
atomColData.sitePotential[atom2] += *(idat.sPot2); |
1353 |
+ |
} |
1354 |
+ |
|
1355 |
|
#else |
1356 |
|
pairwisePot += *(idat.pot); |
1357 |
+ |
excludedPot += *(idat.excludedPot); |
1358 |
|
|
1359 |
|
snap_->atomData.force[atom1] += *(idat.f1); |
1360 |
|
snap_->atomData.force[atom2] -= *(idat.f1); |
1361 |
+ |
|
1362 |
+ |
if (idat.doParticlePot) { |
1363 |
+ |
// This is the pairwise contribution to the particle pot. The |
1364 |
+ |
// embedding contribution is added in each of the low level |
1365 |
+ |
// non-bonded routines. In parallel, this calculation is done |
1366 |
+ |
// in collectData, not in unpackInteractionData. |
1367 |
+ |
snap_->atomData.particlePot[atom1] += *(idat.vpair) * *(idat.sw); |
1368 |
+ |
snap_->atomData.particlePot[atom2] += *(idat.vpair) * *(idat.sw); |
1369 |
+ |
} |
1370 |
+ |
|
1371 |
+ |
if (storageLayout_ & DataStorage::dslFlucQForce) { |
1372 |
+ |
snap_->atomData.flucQFrc[atom1] -= *(idat.dVdFQ1); |
1373 |
+ |
snap_->atomData.flucQFrc[atom2] -= *(idat.dVdFQ2); |
1374 |
+ |
} |
1375 |
+ |
|
1376 |
+ |
if (storageLayout_ & DataStorage::dslElectricField) { |
1377 |
+ |
snap_->atomData.electricField[atom1] += *(idat.eField1); |
1378 |
+ |
snap_->atomData.electricField[atom2] += *(idat.eField2); |
1379 |
+ |
} |
1380 |
+ |
|
1381 |
+ |
if (storageLayout_ & DataStorage::dslSitePotential) { |
1382 |
+ |
snap_->atomData.sitePotential[atom1] += *(idat.sPot1); |
1383 |
+ |
snap_->atomData.sitePotential[atom2] += *(idat.sPot2); |
1384 |
+ |
} |
1385 |
+ |
|
1386 |
|
#endif |
1387 |
|
|
1388 |
|
} |
1393 |
|
* first element of pair is row-indexed CutoffGroup |
1394 |
|
* second element of pair is column-indexed CutoffGroup |
1395 |
|
*/ |
1396 |
< |
vector<pair<int, int> > ForceMatrixDecomposition::buildNeighborList() { |
1397 |
< |
|
1398 |
< |
vector<pair<int, int> > neighborList; |
1396 |
> |
void ForceMatrixDecomposition::buildNeighborList(vector<pair<int,int> >& neighborList) { |
1397 |
> |
|
1398 |
> |
neighborList.clear(); |
1399 |
|
groupCutoffs cuts; |
1400 |
|
bool doAllPairs = false; |
1401 |
|
|
1402 |
+ |
RealType rList_ = (largestRcut_ + skinThickness_); |
1403 |
+ |
RealType rcut, rcutsq, rlistsq; |
1404 |
+ |
Snapshot* snap_ = sman_->getCurrentSnapshot(); |
1405 |
+ |
Mat3x3d box; |
1406 |
+ |
Mat3x3d invBox; |
1407 |
+ |
|
1408 |
+ |
Vector3d rs, scaled, dr; |
1409 |
+ |
Vector3i whichCell; |
1410 |
+ |
int cellIndex; |
1411 |
+ |
|
1412 |
|
#ifdef IS_MPI |
1413 |
|
cellListRow_.clear(); |
1414 |
|
cellListCol_.clear(); |
1415 |
|
#else |
1416 |
|
cellList_.clear(); |
1417 |
|
#endif |
1418 |
< |
|
1419 |
< |
RealType rList_ = (largestRcut_ + skinThickness_); |
1420 |
< |
RealType rl2 = rList_ * rList_; |
1421 |
< |
Snapshot* snap_ = sman_->getCurrentSnapshot(); |
1422 |
< |
Mat3x3d Hmat = snap_->getHmat(); |
1423 |
< |
Vector3d Hx = Hmat.getColumn(0); |
1424 |
< |
Vector3d Hy = Hmat.getColumn(1); |
1425 |
< |
Vector3d Hz = Hmat.getColumn(2); |
1426 |
< |
|
1427 |
< |
nCells_.x() = (int) ( Hx.length() )/ rList_; |
1428 |
< |
nCells_.y() = (int) ( Hy.length() )/ rList_; |
1429 |
< |
nCells_.z() = (int) ( Hz.length() )/ rList_; |
1430 |
< |
|
1418 |
> |
|
1419 |
> |
if (!usePeriodicBoundaryConditions_) { |
1420 |
> |
box = snap_->getBoundingBox(); |
1421 |
> |
invBox = snap_->getInvBoundingBox(); |
1422 |
> |
} else { |
1423 |
> |
box = snap_->getHmat(); |
1424 |
> |
invBox = snap_->getInvHmat(); |
1425 |
> |
} |
1426 |
> |
|
1427 |
> |
Vector3d boxX = box.getColumn(0); |
1428 |
> |
Vector3d boxY = box.getColumn(1); |
1429 |
> |
Vector3d boxZ = box.getColumn(2); |
1430 |
> |
|
1431 |
> |
nCells_.x() = int( boxX.length() / rList_ ); |
1432 |
> |
nCells_.y() = int( boxY.length() / rList_ ); |
1433 |
> |
nCells_.z() = int( boxZ.length() / rList_ ); |
1434 |
> |
|
1435 |
|
// handle small boxes where the cell offsets can end up repeating cells |
1436 |
|
|
1437 |
|
if (nCells_.x() < 3) doAllPairs = true; |
1438 |
|
if (nCells_.y() < 3) doAllPairs = true; |
1439 |
|
if (nCells_.z() < 3) doAllPairs = true; |
1440 |
< |
|
1054 |
< |
Mat3x3d invHmat = snap_->getInvHmat(); |
1055 |
< |
Vector3d rs, scaled, dr; |
1056 |
< |
Vector3i whichCell; |
1057 |
< |
int cellIndex; |
1440 |
> |
|
1441 |
|
int nCtot = nCells_.x() * nCells_.y() * nCells_.z(); |
1442 |
< |
|
1442 |
> |
|
1443 |
|
#ifdef IS_MPI |
1444 |
|
cellListRow_.resize(nCtot); |
1445 |
|
cellListCol_.resize(nCtot); |
1446 |
|
#else |
1447 |
|
cellList_.resize(nCtot); |
1448 |
|
#endif |
1449 |
< |
|
1449 |
> |
|
1450 |
|
if (!doAllPairs) { |
1451 |
|
#ifdef IS_MPI |
1452 |
< |
|
1452 |
> |
|
1453 |
|
for (int i = 0; i < nGroupsInRow_; i++) { |
1454 |
|
rs = cgRowData.position[i]; |
1455 |
|
|
1456 |
|
// scaled positions relative to the box vectors |
1457 |
< |
scaled = invHmat * rs; |
1457 |
> |
scaled = invBox * rs; |
1458 |
|
|
1459 |
|
// wrap the vector back into the unit box by subtracting integer box |
1460 |
|
// numbers |
1461 |
|
for (int j = 0; j < 3; j++) { |
1462 |
|
scaled[j] -= roundMe(scaled[j]); |
1463 |
|
scaled[j] += 0.5; |
1464 |
+ |
// Handle the special case when an object is exactly on the |
1465 |
+ |
// boundary (a scaled coordinate of 1.0 is the same as |
1466 |
+ |
// scaled coordinate of 0.0) |
1467 |
+ |
if (scaled[j] >= 1.0) scaled[j] -= 1.0; |
1468 |
|
} |
1469 |
|
|
1470 |
|
// find xyz-indices of cell that cutoffGroup is in. |
1482 |
|
rs = cgColData.position[i]; |
1483 |
|
|
1484 |
|
// scaled positions relative to the box vectors |
1485 |
< |
scaled = invHmat * rs; |
1485 |
> |
scaled = invBox * rs; |
1486 |
|
|
1487 |
|
// wrap the vector back into the unit box by subtracting integer box |
1488 |
|
// numbers |
1489 |
|
for (int j = 0; j < 3; j++) { |
1490 |
|
scaled[j] -= roundMe(scaled[j]); |
1491 |
|
scaled[j] += 0.5; |
1492 |
+ |
// Handle the special case when an object is exactly on the |
1493 |
+ |
// boundary (a scaled coordinate of 1.0 is the same as |
1494 |
+ |
// scaled coordinate of 0.0) |
1495 |
+ |
if (scaled[j] >= 1.0) scaled[j] -= 1.0; |
1496 |
|
} |
1497 |
|
|
1498 |
|
// find xyz-indices of cell that cutoffGroup is in. |
1506 |
|
// add this cutoff group to the list of groups in this cell; |
1507 |
|
cellListCol_[cellIndex].push_back(i); |
1508 |
|
} |
1509 |
< |
|
1509 |
> |
|
1510 |
|
#else |
1511 |
|
for (int i = 0; i < nGroups_; i++) { |
1512 |
|
rs = snap_->cgData.position[i]; |
1513 |
|
|
1514 |
|
// scaled positions relative to the box vectors |
1515 |
< |
scaled = invHmat * rs; |
1515 |
> |
scaled = invBox * rs; |
1516 |
|
|
1517 |
|
// wrap the vector back into the unit box by subtracting integer box |
1518 |
|
// numbers |
1519 |
|
for (int j = 0; j < 3; j++) { |
1520 |
|
scaled[j] -= roundMe(scaled[j]); |
1521 |
|
scaled[j] += 0.5; |
1522 |
+ |
// Handle the special case when an object is exactly on the |
1523 |
+ |
// boundary (a scaled coordinate of 1.0 is the same as |
1524 |
+ |
// scaled coordinate of 0.0) |
1525 |
+ |
if (scaled[j] >= 1.0) scaled[j] -= 1.0; |
1526 |
|
} |
1527 |
|
|
1528 |
|
// find xyz-indices of cell that cutoffGroup is in. |
1529 |
< |
whichCell.x() = nCells_.x() * scaled.x(); |
1530 |
< |
whichCell.y() = nCells_.y() * scaled.y(); |
1531 |
< |
whichCell.z() = nCells_.z() * scaled.z(); |
1529 |
> |
whichCell.x() = int(nCells_.x() * scaled.x()); |
1530 |
> |
whichCell.y() = int(nCells_.y() * scaled.y()); |
1531 |
> |
whichCell.z() = int(nCells_.z() * scaled.z()); |
1532 |
|
|
1533 |
|
// find single index of this cell: |
1534 |
|
cellIndex = Vlinear(whichCell, nCells_); |
1581 |
|
// & column indicies and will divide labor in the |
1582 |
|
// force evaluation later. |
1583 |
|
dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; |
1584 |
< |
snap_->wrapVector(dr); |
1585 |
< |
cuts = getGroupCutoffs( (*j1), (*j2) ); |
1586 |
< |
if (dr.lengthSquare() < cuts.third) { |
1584 |
> |
if (usePeriodicBoundaryConditions_) { |
1585 |
> |
snap_->wrapVector(dr); |
1586 |
> |
} |
1587 |
> |
getGroupCutoffs( (*j1), (*j2), rcut, rcutsq, rlistsq ); |
1588 |
> |
if (dr.lengthSquare() < rlistsq) { |
1589 |
|
neighborList.push_back(make_pair((*j1), (*j2))); |
1590 |
|
} |
1591 |
|
} |
1605 |
|
// allows atoms within a single cutoff group to |
1606 |
|
// interact with each other. |
1607 |
|
|
1211 |
– |
|
1212 |
– |
|
1608 |
|
if (m2 != m1 || (*j2) >= (*j1) ) { |
1609 |
|
|
1610 |
|
dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)]; |
1611 |
< |
snap_->wrapVector(dr); |
1612 |
< |
cuts = getGroupCutoffs( (*j1), (*j2) ); |
1613 |
< |
if (dr.lengthSquare() < cuts.third) { |
1611 |
> |
if (usePeriodicBoundaryConditions_) { |
1612 |
> |
snap_->wrapVector(dr); |
1613 |
> |
} |
1614 |
> |
getGroupCutoffs( (*j1), (*j2), rcut, rcutsq, rlistsq ); |
1615 |
> |
if (dr.lengthSquare() < rlistsq) { |
1616 |
|
neighborList.push_back(make_pair((*j1), (*j2))); |
1617 |
|
} |
1618 |
|
} |
1629 |
|
for (int j1 = 0; j1 < nGroupsInRow_; j1++) { |
1630 |
|
for (int j2 = 0; j2 < nGroupsInCol_; j2++) { |
1631 |
|
dr = cgColData.position[j2] - cgRowData.position[j1]; |
1632 |
< |
snap_->wrapVector(dr); |
1633 |
< |
cuts = getGroupCutoffs( j1, j2 ); |
1634 |
< |
if (dr.lengthSquare() < cuts.third) { |
1632 |
> |
if (usePeriodicBoundaryConditions_) { |
1633 |
> |
snap_->wrapVector(dr); |
1634 |
> |
} |
1635 |
> |
getGroupCutoffs( j1, j2, rcut, rcutsq, rlistsq); |
1636 |
> |
if (dr.lengthSquare() < rlistsq) { |
1637 |
|
neighborList.push_back(make_pair(j1, j2)); |
1638 |
|
} |
1639 |
|
} |
1644 |
|
// include self group interactions j2 == j1 |
1645 |
|
for (int j2 = j1; j2 < nGroups_; j2++) { |
1646 |
|
dr = snap_->cgData.position[j2] - snap_->cgData.position[j1]; |
1647 |
< |
snap_->wrapVector(dr); |
1648 |
< |
cuts = getGroupCutoffs( j1, j2 ); |
1649 |
< |
if (dr.lengthSquare() < cuts.third) { |
1647 |
> |
if (usePeriodicBoundaryConditions_) { |
1648 |
> |
snap_->wrapVector(dr); |
1649 |
> |
} |
1650 |
> |
getGroupCutoffs( j1, j2, rcut, rcutsq, rlistsq ); |
1651 |
> |
if (dr.lengthSquare() < rlistsq) { |
1652 |
|
neighborList.push_back(make_pair(j1, j2)); |
1653 |
|
} |
1654 |
|
} |
1661 |
|
saved_CG_positions_.clear(); |
1662 |
|
for (int i = 0; i < nGroups_; i++) |
1663 |
|
saved_CG_positions_.push_back(snap_->cgData.position[i]); |
1263 |
– |
|
1264 |
– |
return neighborList; |
1664 |
|
} |
1665 |
|
} //end namespace OpenMD |