| 1029 |
|
#endif |
| 1030 |
|
|
| 1031 |
|
} |
| 1032 |
+ |
|
| 1033 |
+ |
vector<vector<int> > ForceMatrixDecomposition::buildLayerBasedNeighborList() { |
| 1034 |
+ |
printf("buildLayerBasedNeighborList; nGroups:%d\n", nGroups_); |
| 1035 |
+ |
// Na = nGroups_ |
| 1036 |
+ |
/* cell occupancy counter */ |
| 1037 |
+ |
vector<int> k_c; |
| 1038 |
+ |
/* c_i - has cell containing atom i (size Na) */ |
| 1039 |
+ |
vector<int> c; |
| 1040 |
+ |
/* l_i - layer containing atom i (size Na) */ |
| 1041 |
+ |
vector<int> l; |
| 1042 |
+ |
|
| 1043 |
+ |
// cellList_.clear(); |
| 1044 |
+ |
|
| 1045 |
+ |
RealType rList_ = (largestRcut_ + skinThickness_); |
| 1046 |
+ |
Snapshot* snap_ = sman_->getCurrentSnapshot(); |
| 1047 |
+ |
Mat3x3d Hmat = snap_->getHmat(); |
| 1048 |
+ |
Vector3d Hx = Hmat.getColumn(0); |
| 1049 |
+ |
Vector3d Hy = Hmat.getColumn(1); |
| 1050 |
+ |
Vector3d Hz = Hmat.getColumn(2); |
| 1051 |
+ |
|
| 1052 |
+ |
nCells_.x() = (int) (Hx.length()) / rList_; |
| 1053 |
+ |
nCells_.y() = (int) (Hy.length()) / rList_; |
| 1054 |
+ |
nCells_.z() = (int) (Hz.length()) / rList_; |
| 1055 |
+ |
|
| 1056 |
+ |
Mat3x3d invHmat = snap_->getInvHmat(); |
| 1057 |
+ |
Vector3d rs, scaled, dr; |
| 1058 |
+ |
Vector3i whichCell; |
| 1059 |
+ |
int cellIndex; |
| 1060 |
+ |
int nCtot = nCells_.x() * nCells_.y() * nCells_.z(); |
| 1061 |
+ |
|
| 1062 |
+ |
// cellList_.resize(nCtot); |
| 1063 |
+ |
k_c = vector<int>(nCtot, 0); |
| 1064 |
+ |
|
| 1065 |
+ |
for (int i = 0; i < nGroups_; i++) |
| 1066 |
+ |
{ |
| 1067 |
+ |
rs = snap_->cgData.position[i]; |
| 1068 |
+ |
|
| 1069 |
+ |
// scaled positions relative to the box vectors |
| 1070 |
+ |
scaled = invHmat * rs; |
| 1071 |
+ |
|
| 1072 |
+ |
// wrap the vector back into the unit box by subtracting integer box |
| 1073 |
+ |
// numbers |
| 1074 |
+ |
for (int j = 0; j < 3; j++) |
| 1075 |
+ |
{ |
| 1076 |
+ |
scaled[j] -= roundMe(scaled[j]); |
| 1077 |
+ |
scaled[j] += 0.5; |
| 1078 |
+ |
} |
| 1079 |
+ |
|
| 1080 |
+ |
// find xyz-indices of cell that cutoffGroup is in. |
| 1081 |
+ |
whichCell.x() = nCells_.x() * scaled.x(); |
| 1082 |
+ |
whichCell.y() = nCells_.y() * scaled.y(); |
| 1083 |
+ |
whichCell.z() = nCells_.z() * scaled.z(); |
| 1084 |
+ |
|
| 1085 |
+ |
// find single index of this cell: |
| 1086 |
+ |
cellIndex = Vlinear(whichCell, nCells_); |
| 1087 |
+ |
|
| 1088 |
+ |
c.push_back(cellIndex); |
| 1089 |
+ |
|
| 1090 |
+ |
// // add this cutoff group to the list of groups in this cell; |
| 1091 |
+ |
// cellList_[cellIndex].push_back(i); |
| 1092 |
+ |
} |
| 1093 |
+ |
|
| 1094 |
+ |
int k_c_curr; |
| 1095 |
+ |
int k_c_max = 0; |
| 1096 |
+ |
/* the cell-layer occupancy matrix */ |
| 1097 |
+ |
vector<vector<int> > H_c_l = vector<vector<int> >(nCtot); |
| 1098 |
+ |
|
| 1099 |
+ |
for(int i = 0; i < nGroups_; ++i) |
| 1100 |
+ |
{ |
| 1101 |
+ |
k_c_curr = ++k_c[c[i]]; |
| 1102 |
+ |
l.push_back(k_c_curr); |
| 1103 |
+ |
|
| 1104 |
+ |
/* determines the number of layers in use */ |
| 1105 |
+ |
if(k_c_max < k_c_curr) |
| 1106 |
+ |
{ |
| 1107 |
+ |
k_c_max = k_c_curr; |
| 1108 |
+ |
} |
| 1109 |
+ |
|
| 1110 |
+ |
H_c_l[c[i]].push_back(/*l[*/i/*]*/); |
| 1111 |
+ |
} |
| 1112 |
|
|
| 1113 |
+ |
int m; |
| 1114 |
+ |
/* the neighbor matrix */ |
| 1115 |
+ |
vector<vector<int> >neighborMatW = vector<vector<int> >(nGroups_); |
| 1116 |
+ |
|
| 1117 |
+ |
// vector<pair<int, int> > neighborList; |
| 1118 |
+ |
groupCutoffs cuts; |
| 1119 |
+ |
|
| 1120 |
+ |
/* loops over objects(atoms, rigidBodies, cutoffGroups, etc.) */ |
| 1121 |
+ |
for(int i = 0; i < nGroups_; ++i) |
| 1122 |
+ |
{ |
| 1123 |
+ |
m = 0; |
| 1124 |
+ |
/* c' */ |
| 1125 |
+ |
int c1 = c[i]; |
| 1126 |
+ |
Vector3i c1v = idxToV(c1, nCells_); |
| 1127 |
+ |
|
| 1128 |
+ |
/* loops over the neighboring cells c'' */ |
| 1129 |
+ |
for (vector<Vector3i>::iterator os = cellOffsets_.begin(); os != cellOffsets_.end(); ++os) |
| 1130 |
+ |
{ |
| 1131 |
+ |
Vector3i c2v = c1v + (*os); |
| 1132 |
+ |
|
| 1133 |
+ |
if (c2v.x() >= nCells_.x()) |
| 1134 |
+ |
{ |
| 1135 |
+ |
c2v.x() = 0; |
| 1136 |
+ |
} else if (c2v.x() < 0) |
| 1137 |
+ |
{ |
| 1138 |
+ |
c2v.x() = nCells_.x() - 1; |
| 1139 |
+ |
} |
| 1140 |
+ |
|
| 1141 |
+ |
if (c2v.y() >= nCells_.y()) |
| 1142 |
+ |
{ |
| 1143 |
+ |
c2v.y() = 0; |
| 1144 |
+ |
} else if (c2v.y() < 0) |
| 1145 |
+ |
{ |
| 1146 |
+ |
c2v.y() = nCells_.y() - 1; |
| 1147 |
+ |
} |
| 1148 |
+ |
|
| 1149 |
+ |
if (c2v.z() >= nCells_.z()) |
| 1150 |
+ |
{ |
| 1151 |
+ |
c2v.z() = 0; |
| 1152 |
+ |
} else if (c2v.z() < 0) |
| 1153 |
+ |
{ |
| 1154 |
+ |
c2v.z() = nCells_.z() - 1; |
| 1155 |
+ |
} |
| 1156 |
+ |
|
| 1157 |
+ |
int c2 = Vlinear(c2v, nCells_); |
| 1158 |
+ |
/* loops over layers l to access the neighbor atoms */ |
| 1159 |
+ |
for (vector<int>::iterator j = H_c_l[c2].begin(); j != H_c_l[c2].end(); ++j) |
| 1160 |
+ |
{ |
| 1161 |
+ |
// if i'' = 0 then break // doesn't apply to vector implementation of matrix |
| 1162 |
+ |
// if(i != *j) |
| 1163 |
+ |
if (c2 != c1 || (*j) < (i)) |
| 1164 |
+ |
{ |
| 1165 |
+ |
dr = snap_->cgData.position[(*j)] - snap_->cgData.position[(i)]; |
| 1166 |
+ |
snap_->wrapVector(dr); |
| 1167 |
+ |
cuts = getGroupCutoffs((i), (*j)); |
| 1168 |
+ |
if (dr.lengthSquare() < cuts.third) |
| 1169 |
+ |
{ |
| 1170 |
+ |
++m; |
| 1171 |
+ |
/* transposed version of Rapaport W mat, to occupy successive memory locations on CPU */ |
| 1172 |
+ |
neighborMatW[i].push_back(*j); |
| 1173 |
+ |
// neighborList.push_back(make_pair((i), (*j))); |
| 1174 |
+ |
} |
| 1175 |
+ |
} |
| 1176 |
+ |
} |
| 1177 |
+ |
} |
| 1178 |
+ |
} |
| 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 |
+ |
|
| 1186 |
+ |
return neighborMatW; |
| 1187 |
+ |
} |
| 1188 |
+ |
|
| 1189 |
|
/* |
| 1190 |
|
* buildNeighborList |
| 1191 |
|
* |