1 |
gezelter |
1539 |
/* |
2 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
chuckv |
1538 |
* |
4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
6 |
|
|
* redistribute this software in source and binary code form, provided |
7 |
|
|
* that the following conditions are met: |
8 |
|
|
* |
9 |
|
|
* 1. Redistributions of source code must retain the above copyright |
10 |
|
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
|
* |
12 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
|
* notice, this list of conditions and the following disclaimer in the |
14 |
|
|
* documentation and/or other materials provided with the |
15 |
|
|
* distribution. |
16 |
|
|
* |
17 |
|
|
* This software is provided "AS IS," without a warranty of any |
18 |
|
|
* kind. All express or implied conditions, representations and |
19 |
|
|
* warranties, including any implied warranty of merchantability, |
20 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
21 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
22 |
|
|
* be liable for any damages suffered by licensee as a result of |
23 |
|
|
* using, modifying or distributing the software or its |
24 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
25 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
26 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
27 |
|
|
* damages, however caused and regardless of the theory of liability, |
28 |
|
|
* arising out of the use of or inability to use software, even if the |
29 |
|
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
|
* such damages. |
31 |
|
|
* |
32 |
|
|
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
|
|
* research, please cite the appropriate papers when you publish your |
34 |
|
|
* work. Good starting points are: |
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). |
40 |
|
|
*/ |
41 |
gezelter |
1549 |
#include "parallel/ForceMatrixDecomposition.hpp" |
42 |
gezelter |
1539 |
#include "math/SquareMatrix3.hpp" |
43 |
gezelter |
1544 |
#include "nonbonded/NonBondedInteraction.hpp" |
44 |
|
|
#include "brains/SnapshotManager.hpp" |
45 |
gezelter |
1570 |
#include "brains/PairList.hpp" |
46 |
chuckv |
1538 |
|
47 |
gezelter |
1541 |
using namespace std; |
48 |
gezelter |
1539 |
namespace OpenMD { |
49 |
chuckv |
1538 |
|
50 |
gezelter |
1544 |
/** |
51 |
|
|
* distributeInitialData is essentially a copy of the older fortran |
52 |
|
|
* SimulationSetup |
53 |
|
|
*/ |
54 |
|
|
|
55 |
gezelter |
1549 |
void ForceMatrixDecomposition::distributeInitialData() { |
56 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
57 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
58 |
gezelter |
1571 |
ff_ = info_->getForceField(); |
59 |
gezelter |
1567 |
nLocal_ = snap_->getNumberOfAtoms(); |
60 |
chuckv |
1538 |
|
61 |
gezelter |
1577 |
nGroups_ = info_->getNLocalCutoffGroups(); |
62 |
gezelter |
1579 |
cerr << "in dId, nGroups = " << nGroups_ << "\n"; |
63 |
gezelter |
1569 |
// gather the information for atomtype IDs (atids): |
64 |
gezelter |
1571 |
identsLocal = info_->getIdentArray(); |
65 |
gezelter |
1569 |
AtomLocalToGlobal = info_->getGlobalAtomIndices(); |
66 |
|
|
cgLocalToGlobal = info_->getGlobalGroupIndices(); |
67 |
|
|
vector<int> globalGroupMembership = info_->getGlobalGroupMembership(); |
68 |
|
|
vector<RealType> massFactorsLocal = info_->getMassFactors(); |
69 |
gezelter |
1570 |
PairList excludes = info_->getExcludedInteractions(); |
70 |
|
|
PairList oneTwo = info_->getOneTwoInteractions(); |
71 |
|
|
PairList oneThree = info_->getOneThreeInteractions(); |
72 |
|
|
PairList oneFour = info_->getOneFourInteractions(); |
73 |
gezelter |
1569 |
|
74 |
gezelter |
1567 |
#ifdef IS_MPI |
75 |
|
|
|
76 |
|
|
AtomCommIntRow = new Communicator<Row,int>(nLocal_); |
77 |
|
|
AtomCommRealRow = new Communicator<Row,RealType>(nLocal_); |
78 |
|
|
AtomCommVectorRow = new Communicator<Row,Vector3d>(nLocal_); |
79 |
|
|
AtomCommMatrixRow = new Communicator<Row,Mat3x3d>(nLocal_); |
80 |
gezelter |
1575 |
AtomCommPotRow = new Communicator<Row,potVec>(nLocal_); |
81 |
chuckv |
1538 |
|
82 |
gezelter |
1567 |
AtomCommIntColumn = new Communicator<Column,int>(nLocal_); |
83 |
|
|
AtomCommRealColumn = new Communicator<Column,RealType>(nLocal_); |
84 |
|
|
AtomCommVectorColumn = new Communicator<Column,Vector3d>(nLocal_); |
85 |
|
|
AtomCommMatrixColumn = new Communicator<Column,Mat3x3d>(nLocal_); |
86 |
gezelter |
1575 |
AtomCommPotColumn = new Communicator<Column,potVec>(nLocal_); |
87 |
gezelter |
1541 |
|
88 |
gezelter |
1567 |
cgCommIntRow = new Communicator<Row,int>(nGroups_); |
89 |
|
|
cgCommVectorRow = new Communicator<Row,Vector3d>(nGroups_); |
90 |
|
|
cgCommIntColumn = new Communicator<Column,int>(nGroups_); |
91 |
|
|
cgCommVectorColumn = new Communicator<Column,Vector3d>(nGroups_); |
92 |
gezelter |
1551 |
|
93 |
gezelter |
1567 |
nAtomsInRow_ = AtomCommIntRow->getSize(); |
94 |
|
|
nAtomsInCol_ = AtomCommIntColumn->getSize(); |
95 |
|
|
nGroupsInRow_ = cgCommIntRow->getSize(); |
96 |
|
|
nGroupsInCol_ = cgCommIntColumn->getSize(); |
97 |
|
|
|
98 |
gezelter |
1551 |
// Modify the data storage objects with the correct layouts and sizes: |
99 |
gezelter |
1567 |
atomRowData.resize(nAtomsInRow_); |
100 |
gezelter |
1551 |
atomRowData.setStorageLayout(storageLayout_); |
101 |
gezelter |
1567 |
atomColData.resize(nAtomsInCol_); |
102 |
gezelter |
1551 |
atomColData.setStorageLayout(storageLayout_); |
103 |
gezelter |
1567 |
cgRowData.resize(nGroupsInRow_); |
104 |
gezelter |
1551 |
cgRowData.setStorageLayout(DataStorage::dslPosition); |
105 |
gezelter |
1567 |
cgColData.resize(nGroupsInCol_); |
106 |
gezelter |
1551 |
cgColData.setStorageLayout(DataStorage::dslPosition); |
107 |
gezelter |
1575 |
|
108 |
gezelter |
1577 |
identsRow.resize(nAtomsInRow_); |
109 |
|
|
identsCol.resize(nAtomsInCol_); |
110 |
gezelter |
1549 |
|
111 |
|
|
AtomCommIntRow->gather(identsLocal, identsRow); |
112 |
|
|
AtomCommIntColumn->gather(identsLocal, identsCol); |
113 |
|
|
|
114 |
|
|
AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal); |
115 |
|
|
AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal); |
116 |
|
|
|
117 |
|
|
cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal); |
118 |
|
|
cgCommIntColumn->gather(cgLocalToGlobal, cgColToGlobal); |
119 |
gezelter |
1541 |
|
120 |
gezelter |
1569 |
AtomCommRealRow->gather(massFactorsLocal, massFactorsRow); |
121 |
|
|
AtomCommRealColumn->gather(massFactorsLocal, massFactorsCol); |
122 |
|
|
|
123 |
|
|
groupListRow_.clear(); |
124 |
gezelter |
1577 |
groupListRow_.resize(nGroupsInRow_); |
125 |
gezelter |
1569 |
for (int i = 0; i < nGroupsInRow_; i++) { |
126 |
|
|
int gid = cgRowToGlobal[i]; |
127 |
|
|
for (int j = 0; j < nAtomsInRow_; j++) { |
128 |
|
|
int aid = AtomRowToGlobal[j]; |
129 |
|
|
if (globalGroupMembership[aid] == gid) |
130 |
|
|
groupListRow_[i].push_back(j); |
131 |
|
|
} |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
groupListCol_.clear(); |
135 |
gezelter |
1577 |
groupListCol_.resize(nGroupsInCol_); |
136 |
gezelter |
1569 |
for (int i = 0; i < nGroupsInCol_; i++) { |
137 |
|
|
int gid = cgColToGlobal[i]; |
138 |
|
|
for (int j = 0; j < nAtomsInCol_; j++) { |
139 |
|
|
int aid = AtomColToGlobal[j]; |
140 |
|
|
if (globalGroupMembership[aid] == gid) |
141 |
|
|
groupListCol_[i].push_back(j); |
142 |
|
|
} |
143 |
|
|
} |
144 |
|
|
|
145 |
gezelter |
1579 |
skipsForAtom.clear(); |
146 |
|
|
skipsForAtom.resize(nAtomsInRow_); |
147 |
|
|
toposForAtom.clear(); |
148 |
|
|
toposForAtom.resize(nAtomsInRow_); |
149 |
|
|
topoDist.clear(); |
150 |
|
|
topoDist.resize(nAtomsInRow_); |
151 |
gezelter |
1570 |
for (int i = 0; i < nAtomsInRow_; i++) { |
152 |
gezelter |
1571 |
int iglob = AtomRowToGlobal[i]; |
153 |
gezelter |
1579 |
|
154 |
gezelter |
1570 |
for (int j = 0; j < nAtomsInCol_; j++) { |
155 |
gezelter |
1579 |
int jglob = AtomColToGlobal[j]; |
156 |
|
|
|
157 |
gezelter |
1570 |
if (excludes.hasPair(iglob, jglob)) |
158 |
gezelter |
1579 |
skipsForAtom[i].push_back(j); |
159 |
|
|
|
160 |
gezelter |
1570 |
if (oneTwo.hasPair(iglob, jglob)) { |
161 |
gezelter |
1579 |
toposForAtom[i].push_back(j); |
162 |
|
|
topoDist[i].push_back(1); |
163 |
|
|
} else { |
164 |
|
|
if (oneThree.hasPair(iglob, jglob)) { |
165 |
|
|
toposForAtom[i].push_back(j); |
166 |
|
|
topoDist[i].push_back(2); |
167 |
|
|
} else { |
168 |
|
|
if (oneFour.hasPair(iglob, jglob)) { |
169 |
|
|
toposForAtom[i].push_back(j); |
170 |
|
|
topoDist[i].push_back(3); |
171 |
|
|
} |
172 |
|
|
} |
173 |
gezelter |
1570 |
} |
174 |
|
|
} |
175 |
|
|
} |
176 |
|
|
|
177 |
gezelter |
1569 |
#endif |
178 |
gezelter |
1579 |
|
179 |
gezelter |
1569 |
groupList_.clear(); |
180 |
gezelter |
1577 |
groupList_.resize(nGroups_); |
181 |
gezelter |
1569 |
for (int i = 0; i < nGroups_; i++) { |
182 |
|
|
int gid = cgLocalToGlobal[i]; |
183 |
|
|
for (int j = 0; j < nLocal_; j++) { |
184 |
|
|
int aid = AtomLocalToGlobal[j]; |
185 |
gezelter |
1577 |
if (globalGroupMembership[aid] == gid) { |
186 |
gezelter |
1569 |
groupList_[i].push_back(j); |
187 |
gezelter |
1577 |
} |
188 |
gezelter |
1569 |
} |
189 |
|
|
} |
190 |
|
|
|
191 |
gezelter |
1579 |
skipsForAtom.clear(); |
192 |
|
|
skipsForAtom.resize(nLocal_); |
193 |
|
|
toposForAtom.clear(); |
194 |
|
|
toposForAtom.resize(nLocal_); |
195 |
|
|
topoDist.clear(); |
196 |
|
|
topoDist.resize(nLocal_); |
197 |
gezelter |
1569 |
|
198 |
gezelter |
1570 |
for (int i = 0; i < nLocal_; i++) { |
199 |
|
|
int iglob = AtomLocalToGlobal[i]; |
200 |
gezelter |
1579 |
|
201 |
gezelter |
1570 |
for (int j = 0; j < nLocal_; j++) { |
202 |
gezelter |
1579 |
int jglob = AtomLocalToGlobal[j]; |
203 |
|
|
|
204 |
gezelter |
1570 |
if (excludes.hasPair(iglob, jglob)) |
205 |
gezelter |
1579 |
skipsForAtom[i].push_back(j); |
206 |
|
|
|
207 |
gezelter |
1570 |
if (oneTwo.hasPair(iglob, jglob)) { |
208 |
gezelter |
1579 |
toposForAtom[i].push_back(j); |
209 |
|
|
topoDist[i].push_back(1); |
210 |
|
|
} else { |
211 |
|
|
if (oneThree.hasPair(iglob, jglob)) { |
212 |
|
|
toposForAtom[i].push_back(j); |
213 |
|
|
topoDist[i].push_back(2); |
214 |
|
|
} else { |
215 |
|
|
if (oneFour.hasPair(iglob, jglob)) { |
216 |
|
|
toposForAtom[i].push_back(j); |
217 |
|
|
topoDist[i].push_back(3); |
218 |
|
|
} |
219 |
|
|
} |
220 |
gezelter |
1570 |
} |
221 |
|
|
} |
222 |
gezelter |
1579 |
} |
223 |
|
|
|
224 |
|
|
createGtypeCutoffMap(); |
225 |
gezelter |
1576 |
} |
226 |
|
|
|
227 |
|
|
void ForceMatrixDecomposition::createGtypeCutoffMap() { |
228 |
|
|
|
229 |
|
|
RealType tol = 1e-6; |
230 |
|
|
RealType rc; |
231 |
|
|
int atid; |
232 |
|
|
set<AtomType*> atypes = info_->getSimulatedAtomTypes(); |
233 |
|
|
vector<RealType> atypeCutoff; |
234 |
gezelter |
1577 |
atypeCutoff.resize( atypes.size() ); |
235 |
gezelter |
1576 |
|
236 |
gezelter |
1579 |
for (set<AtomType*>::iterator at = atypes.begin(); |
237 |
|
|
at != atypes.end(); ++at){ |
238 |
gezelter |
1576 |
rc = interactionMan_->getSuggestedCutoffRadius(*at); |
239 |
|
|
atid = (*at)->getIdent(); |
240 |
|
|
atypeCutoff[atid] = rc; |
241 |
gezelter |
1570 |
} |
242 |
gezelter |
1576 |
|
243 |
|
|
vector<RealType> gTypeCutoffs; |
244 |
|
|
|
245 |
|
|
// first we do a single loop over the cutoff groups to find the |
246 |
|
|
// largest cutoff for any atypes present in this group. |
247 |
|
|
#ifdef IS_MPI |
248 |
|
|
vector<RealType> groupCutoffRow(nGroupsInRow_, 0.0); |
249 |
gezelter |
1579 |
groupRowToGtype.resize(nGroupsInRow_); |
250 |
gezelter |
1576 |
for (int cg1 = 0; cg1 < nGroupsInRow_; cg1++) { |
251 |
|
|
vector<int> atomListRow = getAtomsInGroupRow(cg1); |
252 |
|
|
for (vector<int>::iterator ia = atomListRow.begin(); |
253 |
|
|
ia != atomListRow.end(); ++ia) { |
254 |
|
|
int atom1 = (*ia); |
255 |
|
|
atid = identsRow[atom1]; |
256 |
|
|
if (atypeCutoff[atid] > groupCutoffRow[cg1]) { |
257 |
|
|
groupCutoffRow[cg1] = atypeCutoff[atid]; |
258 |
|
|
} |
259 |
|
|
} |
260 |
|
|
|
261 |
|
|
bool gTypeFound = false; |
262 |
|
|
for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { |
263 |
|
|
if (abs(groupCutoffRow[cg1] - gTypeCutoffs[gt]) < tol) { |
264 |
|
|
groupRowToGtype[cg1] = gt; |
265 |
|
|
gTypeFound = true; |
266 |
|
|
} |
267 |
|
|
} |
268 |
|
|
if (!gTypeFound) { |
269 |
|
|
gTypeCutoffs.push_back( groupCutoffRow[cg1] ); |
270 |
|
|
groupRowToGtype[cg1] = gTypeCutoffs.size() - 1; |
271 |
|
|
} |
272 |
|
|
|
273 |
|
|
} |
274 |
|
|
vector<RealType> groupCutoffCol(nGroupsInCol_, 0.0); |
275 |
gezelter |
1579 |
groupColToGtype.resize(nGroupsInCol_); |
276 |
gezelter |
1576 |
for (int cg2 = 0; cg2 < nGroupsInCol_; cg2++) { |
277 |
|
|
vector<int> atomListCol = getAtomsInGroupColumn(cg2); |
278 |
|
|
for (vector<int>::iterator jb = atomListCol.begin(); |
279 |
|
|
jb != atomListCol.end(); ++jb) { |
280 |
|
|
int atom2 = (*jb); |
281 |
|
|
atid = identsCol[atom2]; |
282 |
|
|
if (atypeCutoff[atid] > groupCutoffCol[cg2]) { |
283 |
|
|
groupCutoffCol[cg2] = atypeCutoff[atid]; |
284 |
|
|
} |
285 |
|
|
} |
286 |
|
|
bool gTypeFound = false; |
287 |
|
|
for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { |
288 |
|
|
if (abs(groupCutoffCol[cg2] - gTypeCutoffs[gt]) < tol) { |
289 |
|
|
groupColToGtype[cg2] = gt; |
290 |
|
|
gTypeFound = true; |
291 |
|
|
} |
292 |
|
|
} |
293 |
|
|
if (!gTypeFound) { |
294 |
|
|
gTypeCutoffs.push_back( groupCutoffCol[cg2] ); |
295 |
|
|
groupColToGtype[cg2] = gTypeCutoffs.size() - 1; |
296 |
|
|
} |
297 |
|
|
} |
298 |
|
|
#else |
299 |
gezelter |
1579 |
|
300 |
gezelter |
1576 |
vector<RealType> groupCutoff(nGroups_, 0.0); |
301 |
gezelter |
1579 |
groupToGtype.resize(nGroups_); |
302 |
|
|
|
303 |
|
|
cerr << "nGroups = " << nGroups_ << "\n"; |
304 |
gezelter |
1576 |
for (int cg1 = 0; cg1 < nGroups_; cg1++) { |
305 |
gezelter |
1579 |
|
306 |
gezelter |
1576 |
groupCutoff[cg1] = 0.0; |
307 |
|
|
vector<int> atomList = getAtomsInGroupRow(cg1); |
308 |
gezelter |
1579 |
|
309 |
gezelter |
1576 |
for (vector<int>::iterator ia = atomList.begin(); |
310 |
|
|
ia != atomList.end(); ++ia) { |
311 |
|
|
int atom1 = (*ia); |
312 |
|
|
atid = identsLocal[atom1]; |
313 |
|
|
if (atypeCutoff[atid] > groupCutoff[cg1]) { |
314 |
|
|
groupCutoff[cg1] = atypeCutoff[atid]; |
315 |
|
|
} |
316 |
|
|
} |
317 |
|
|
|
318 |
|
|
bool gTypeFound = false; |
319 |
|
|
for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { |
320 |
|
|
if (abs(groupCutoff[cg1] - gTypeCutoffs[gt]) < tol) { |
321 |
|
|
groupToGtype[cg1] = gt; |
322 |
|
|
gTypeFound = true; |
323 |
|
|
} |
324 |
|
|
} |
325 |
|
|
if (!gTypeFound) { |
326 |
|
|
gTypeCutoffs.push_back( groupCutoff[cg1] ); |
327 |
|
|
groupToGtype[cg1] = gTypeCutoffs.size() - 1; |
328 |
|
|
} |
329 |
|
|
} |
330 |
|
|
#endif |
331 |
|
|
|
332 |
gezelter |
1579 |
cerr << "gTypeCutoffs.size() = " << gTypeCutoffs.size() << "\n"; |
333 |
gezelter |
1576 |
// Now we find the maximum group cutoff value present in the simulation |
334 |
|
|
|
335 |
gezelter |
1579 |
RealType groupMax = *max_element(gTypeCutoffs.begin(), gTypeCutoffs.end()); |
336 |
gezelter |
1576 |
|
337 |
|
|
#ifdef IS_MPI |
338 |
|
|
MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE, MPI::MAX); |
339 |
|
|
#endif |
340 |
|
|
|
341 |
|
|
RealType tradRcut = groupMax; |
342 |
|
|
|
343 |
|
|
for (int i = 0; i < gTypeCutoffs.size(); i++) { |
344 |
gezelter |
1579 |
for (int j = 0; j < gTypeCutoffs.size(); j++) { |
345 |
gezelter |
1576 |
RealType thisRcut; |
346 |
|
|
switch(cutoffPolicy_) { |
347 |
|
|
case TRADITIONAL: |
348 |
|
|
thisRcut = tradRcut; |
349 |
gezelter |
1579 |
break; |
350 |
gezelter |
1576 |
case MIX: |
351 |
|
|
thisRcut = 0.5 * (gTypeCutoffs[i] + gTypeCutoffs[j]); |
352 |
gezelter |
1579 |
break; |
353 |
gezelter |
1576 |
case MAX: |
354 |
|
|
thisRcut = max(gTypeCutoffs[i], gTypeCutoffs[j]); |
355 |
gezelter |
1579 |
break; |
356 |
gezelter |
1576 |
default: |
357 |
|
|
sprintf(painCave.errMsg, |
358 |
|
|
"ForceMatrixDecomposition::createGtypeCutoffMap " |
359 |
|
|
"hit an unknown cutoff policy!\n"); |
360 |
|
|
painCave.severity = OPENMD_ERROR; |
361 |
|
|
painCave.isFatal = 1; |
362 |
gezelter |
1579 |
simError(); |
363 |
|
|
break; |
364 |
gezelter |
1576 |
} |
365 |
|
|
|
366 |
|
|
pair<int,int> key = make_pair(i,j); |
367 |
|
|
gTypeCutoffMap[key].first = thisRcut; |
368 |
|
|
|
369 |
|
|
if (thisRcut > largestRcut_) largestRcut_ = thisRcut; |
370 |
|
|
|
371 |
|
|
gTypeCutoffMap[key].second = thisRcut*thisRcut; |
372 |
|
|
|
373 |
|
|
gTypeCutoffMap[key].third = pow(thisRcut + skinThickness_, 2); |
374 |
|
|
|
375 |
|
|
// sanity check |
376 |
|
|
|
377 |
|
|
if (userChoseCutoff_) { |
378 |
|
|
if (abs(gTypeCutoffMap[key].first - userCutoff_) > 0.0001) { |
379 |
|
|
sprintf(painCave.errMsg, |
380 |
|
|
"ForceMatrixDecomposition::createGtypeCutoffMap " |
381 |
|
|
"user-specified rCut does not match computed group Cutoff\n"); |
382 |
|
|
painCave.severity = OPENMD_ERROR; |
383 |
|
|
painCave.isFatal = 1; |
384 |
|
|
simError(); |
385 |
|
|
} |
386 |
|
|
} |
387 |
|
|
} |
388 |
|
|
} |
389 |
gezelter |
1539 |
} |
390 |
gezelter |
1576 |
|
391 |
|
|
|
392 |
|
|
groupCutoffs ForceMatrixDecomposition::getGroupCutoffs(int cg1, int cg2) { |
393 |
gezelter |
1579 |
int i, j; |
394 |
gezelter |
1576 |
#ifdef IS_MPI |
395 |
|
|
i = groupRowToGtype[cg1]; |
396 |
|
|
j = groupColToGtype[cg2]; |
397 |
|
|
#else |
398 |
|
|
i = groupToGtype[cg1]; |
399 |
|
|
j = groupToGtype[cg2]; |
400 |
gezelter |
1579 |
#endif |
401 |
gezelter |
1576 |
return gTypeCutoffMap[make_pair(i,j)]; |
402 |
|
|
} |
403 |
|
|
|
404 |
gezelter |
1579 |
int ForceMatrixDecomposition::getTopologicalDistance(int atom1, int atom2) { |
405 |
|
|
for (int j = 0; j < toposForAtom[atom1].size(); j++) { |
406 |
|
|
if (toposForAtom[atom1][j] == atom2) |
407 |
|
|
return topoDist[atom1][j]; |
408 |
|
|
} |
409 |
|
|
return 0; |
410 |
|
|
} |
411 |
gezelter |
1576 |
|
412 |
gezelter |
1575 |
void ForceMatrixDecomposition::zeroWorkArrays() { |
413 |
|
|
|
414 |
|
|
for (int j = 0; j < N_INTERACTION_FAMILIES; j++) { |
415 |
|
|
longRangePot_[j] = 0.0; |
416 |
|
|
} |
417 |
|
|
|
418 |
|
|
#ifdef IS_MPI |
419 |
|
|
if (storageLayout_ & DataStorage::dslForce) { |
420 |
|
|
fill(atomRowData.force.begin(), atomRowData.force.end(), V3Zero); |
421 |
|
|
fill(atomColData.force.begin(), atomColData.force.end(), V3Zero); |
422 |
|
|
} |
423 |
|
|
|
424 |
|
|
if (storageLayout_ & DataStorage::dslTorque) { |
425 |
|
|
fill(atomRowData.torque.begin(), atomRowData.torque.end(), V3Zero); |
426 |
|
|
fill(atomColData.torque.begin(), atomColData.torque.end(), V3Zero); |
427 |
|
|
} |
428 |
|
|
|
429 |
|
|
fill(pot_row.begin(), pot_row.end(), |
430 |
|
|
Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
431 |
|
|
|
432 |
|
|
fill(pot_col.begin(), pot_col.end(), |
433 |
|
|
Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
434 |
|
|
|
435 |
|
|
pot_local = Vector<RealType, N_INTERACTION_FAMILIES>(0.0); |
436 |
|
|
|
437 |
|
|
if (storageLayout_ & DataStorage::dslParticlePot) { |
438 |
|
|
fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(), 0.0); |
439 |
|
|
fill(atomColData.particlePot.begin(), atomColData.particlePot.end(), 0.0); |
440 |
|
|
} |
441 |
|
|
|
442 |
|
|
if (storageLayout_ & DataStorage::dslDensity) { |
443 |
|
|
fill(atomRowData.density.begin(), atomRowData.density.end(), 0.0); |
444 |
|
|
fill(atomColData.density.begin(), atomColData.density.end(), 0.0); |
445 |
|
|
} |
446 |
|
|
|
447 |
|
|
if (storageLayout_ & DataStorage::dslFunctional) { |
448 |
|
|
fill(atomRowData.functional.begin(), atomRowData.functional.end(), 0.0); |
449 |
|
|
fill(atomColData.functional.begin(), atomColData.functional.end(), 0.0); |
450 |
|
|
} |
451 |
|
|
|
452 |
|
|
if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
453 |
|
|
fill(atomRowData.functionalDerivative.begin(), |
454 |
|
|
atomRowData.functionalDerivative.end(), 0.0); |
455 |
|
|
fill(atomColData.functionalDerivative.begin(), |
456 |
|
|
atomColData.functionalDerivative.end(), 0.0); |
457 |
|
|
} |
458 |
|
|
|
459 |
|
|
#else |
460 |
|
|
|
461 |
|
|
if (storageLayout_ & DataStorage::dslParticlePot) { |
462 |
|
|
fill(snap_->atomData.particlePot.begin(), |
463 |
|
|
snap_->atomData.particlePot.end(), 0.0); |
464 |
|
|
} |
465 |
|
|
|
466 |
|
|
if (storageLayout_ & DataStorage::dslDensity) { |
467 |
|
|
fill(snap_->atomData.density.begin(), |
468 |
|
|
snap_->atomData.density.end(), 0.0); |
469 |
|
|
} |
470 |
|
|
if (storageLayout_ & DataStorage::dslFunctional) { |
471 |
|
|
fill(snap_->atomData.functional.begin(), |
472 |
|
|
snap_->atomData.functional.end(), 0.0); |
473 |
|
|
} |
474 |
|
|
if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
475 |
|
|
fill(snap_->atomData.functionalDerivative.begin(), |
476 |
|
|
snap_->atomData.functionalDerivative.end(), 0.0); |
477 |
|
|
} |
478 |
|
|
#endif |
479 |
|
|
|
480 |
|
|
} |
481 |
|
|
|
482 |
|
|
|
483 |
gezelter |
1549 |
void ForceMatrixDecomposition::distributeData() { |
484 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
485 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
486 |
chuckv |
1538 |
#ifdef IS_MPI |
487 |
gezelter |
1540 |
|
488 |
gezelter |
1539 |
// gather up the atomic positions |
489 |
gezelter |
1551 |
AtomCommVectorRow->gather(snap_->atomData.position, |
490 |
|
|
atomRowData.position); |
491 |
|
|
AtomCommVectorColumn->gather(snap_->atomData.position, |
492 |
|
|
atomColData.position); |
493 |
gezelter |
1539 |
|
494 |
|
|
// gather up the cutoff group positions |
495 |
gezelter |
1551 |
cgCommVectorRow->gather(snap_->cgData.position, |
496 |
|
|
cgRowData.position); |
497 |
|
|
cgCommVectorColumn->gather(snap_->cgData.position, |
498 |
|
|
cgColData.position); |
499 |
gezelter |
1539 |
|
500 |
|
|
// if needed, gather the atomic rotation matrices |
501 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslAmat) { |
502 |
|
|
AtomCommMatrixRow->gather(snap_->atomData.aMat, |
503 |
|
|
atomRowData.aMat); |
504 |
|
|
AtomCommMatrixColumn->gather(snap_->atomData.aMat, |
505 |
|
|
atomColData.aMat); |
506 |
gezelter |
1539 |
} |
507 |
|
|
|
508 |
|
|
// if needed, gather the atomic eletrostatic frames |
509 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslElectroFrame) { |
510 |
|
|
AtomCommMatrixRow->gather(snap_->atomData.electroFrame, |
511 |
|
|
atomRowData.electroFrame); |
512 |
|
|
AtomCommMatrixColumn->gather(snap_->atomData.electroFrame, |
513 |
|
|
atomColData.electroFrame); |
514 |
gezelter |
1539 |
} |
515 |
|
|
#endif |
516 |
|
|
} |
517 |
|
|
|
518 |
gezelter |
1575 |
/* collects information obtained during the pre-pair loop onto local |
519 |
|
|
* data structures. |
520 |
|
|
*/ |
521 |
gezelter |
1549 |
void ForceMatrixDecomposition::collectIntermediateData() { |
522 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
523 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
524 |
gezelter |
1539 |
#ifdef IS_MPI |
525 |
|
|
|
526 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslDensity) { |
527 |
|
|
|
528 |
|
|
AtomCommRealRow->scatter(atomRowData.density, |
529 |
|
|
snap_->atomData.density); |
530 |
|
|
|
531 |
|
|
int n = snap_->atomData.density.size(); |
532 |
gezelter |
1575 |
vector<RealType> rho_tmp(n, 0.0); |
533 |
gezelter |
1551 |
AtomCommRealColumn->scatter(atomColData.density, rho_tmp); |
534 |
gezelter |
1539 |
for (int i = 0; i < n; i++) |
535 |
gezelter |
1551 |
snap_->atomData.density[i] += rho_tmp[i]; |
536 |
gezelter |
1539 |
} |
537 |
chuckv |
1538 |
#endif |
538 |
gezelter |
1539 |
} |
539 |
gezelter |
1575 |
|
540 |
|
|
/* |
541 |
|
|
* redistributes information obtained during the pre-pair loop out to |
542 |
|
|
* row and column-indexed data structures |
543 |
|
|
*/ |
544 |
gezelter |
1549 |
void ForceMatrixDecomposition::distributeIntermediateData() { |
545 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
546 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
547 |
chuckv |
1538 |
#ifdef IS_MPI |
548 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslFunctional) { |
549 |
|
|
AtomCommRealRow->gather(snap_->atomData.functional, |
550 |
|
|
atomRowData.functional); |
551 |
|
|
AtomCommRealColumn->gather(snap_->atomData.functional, |
552 |
|
|
atomColData.functional); |
553 |
gezelter |
1539 |
} |
554 |
|
|
|
555 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
556 |
|
|
AtomCommRealRow->gather(snap_->atomData.functionalDerivative, |
557 |
|
|
atomRowData.functionalDerivative); |
558 |
|
|
AtomCommRealColumn->gather(snap_->atomData.functionalDerivative, |
559 |
|
|
atomColData.functionalDerivative); |
560 |
gezelter |
1539 |
} |
561 |
chuckv |
1538 |
#endif |
562 |
|
|
} |
563 |
gezelter |
1539 |
|
564 |
|
|
|
565 |
gezelter |
1549 |
void ForceMatrixDecomposition::collectData() { |
566 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
567 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
568 |
|
|
#ifdef IS_MPI |
569 |
|
|
int n = snap_->atomData.force.size(); |
570 |
gezelter |
1544 |
vector<Vector3d> frc_tmp(n, V3Zero); |
571 |
gezelter |
1541 |
|
572 |
gezelter |
1551 |
AtomCommVectorRow->scatter(atomRowData.force, frc_tmp); |
573 |
gezelter |
1541 |
for (int i = 0; i < n; i++) { |
574 |
gezelter |
1551 |
snap_->atomData.force[i] += frc_tmp[i]; |
575 |
gezelter |
1541 |
frc_tmp[i] = 0.0; |
576 |
|
|
} |
577 |
gezelter |
1540 |
|
578 |
gezelter |
1551 |
AtomCommVectorColumn->scatter(atomColData.force, frc_tmp); |
579 |
gezelter |
1540 |
for (int i = 0; i < n; i++) |
580 |
gezelter |
1551 |
snap_->atomData.force[i] += frc_tmp[i]; |
581 |
gezelter |
1540 |
|
582 |
|
|
|
583 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslTorque) { |
584 |
gezelter |
1541 |
|
585 |
gezelter |
1551 |
int nt = snap_->atomData.force.size(); |
586 |
gezelter |
1544 |
vector<Vector3d> trq_tmp(nt, V3Zero); |
587 |
gezelter |
1541 |
|
588 |
gezelter |
1551 |
AtomCommVectorRow->scatter(atomRowData.torque, trq_tmp); |
589 |
gezelter |
1541 |
for (int i = 0; i < n; i++) { |
590 |
gezelter |
1551 |
snap_->atomData.torque[i] += trq_tmp[i]; |
591 |
gezelter |
1541 |
trq_tmp[i] = 0.0; |
592 |
|
|
} |
593 |
gezelter |
1540 |
|
594 |
gezelter |
1551 |
AtomCommVectorColumn->scatter(atomColData.torque, trq_tmp); |
595 |
gezelter |
1540 |
for (int i = 0; i < n; i++) |
596 |
gezelter |
1551 |
snap_->atomData.torque[i] += trq_tmp[i]; |
597 |
gezelter |
1540 |
} |
598 |
|
|
|
599 |
gezelter |
1567 |
nLocal_ = snap_->getNumberOfAtoms(); |
600 |
gezelter |
1544 |
|
601 |
gezelter |
1575 |
vector<potVec> pot_temp(nLocal_, |
602 |
|
|
Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
603 |
|
|
|
604 |
|
|
// scatter/gather pot_row into the members of my column |
605 |
|
|
|
606 |
|
|
AtomCommPotRow->scatter(pot_row, pot_temp); |
607 |
|
|
|
608 |
|
|
for (int ii = 0; ii < pot_temp.size(); ii++ ) |
609 |
|
|
pot_local += pot_temp[ii]; |
610 |
gezelter |
1540 |
|
611 |
gezelter |
1575 |
fill(pot_temp.begin(), pot_temp.end(), |
612 |
|
|
Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
613 |
|
|
|
614 |
|
|
AtomCommPotColumn->scatter(pot_col, pot_temp); |
615 |
|
|
|
616 |
|
|
for (int ii = 0; ii < pot_temp.size(); ii++ ) |
617 |
|
|
pot_local += pot_temp[ii]; |
618 |
|
|
|
619 |
gezelter |
1539 |
#endif |
620 |
chuckv |
1538 |
} |
621 |
gezelter |
1551 |
|
622 |
gezelter |
1570 |
int ForceMatrixDecomposition::getNAtomsInRow() { |
623 |
|
|
#ifdef IS_MPI |
624 |
|
|
return nAtomsInRow_; |
625 |
|
|
#else |
626 |
|
|
return nLocal_; |
627 |
|
|
#endif |
628 |
|
|
} |
629 |
|
|
|
630 |
gezelter |
1569 |
/** |
631 |
|
|
* returns the list of atoms belonging to this group. |
632 |
|
|
*/ |
633 |
|
|
vector<int> ForceMatrixDecomposition::getAtomsInGroupRow(int cg1){ |
634 |
|
|
#ifdef IS_MPI |
635 |
|
|
return groupListRow_[cg1]; |
636 |
|
|
#else |
637 |
|
|
return groupList_[cg1]; |
638 |
|
|
#endif |
639 |
|
|
} |
640 |
|
|
|
641 |
|
|
vector<int> ForceMatrixDecomposition::getAtomsInGroupColumn(int cg2){ |
642 |
|
|
#ifdef IS_MPI |
643 |
|
|
return groupListCol_[cg2]; |
644 |
|
|
#else |
645 |
|
|
return groupList_[cg2]; |
646 |
|
|
#endif |
647 |
|
|
} |
648 |
chuckv |
1538 |
|
649 |
gezelter |
1551 |
Vector3d ForceMatrixDecomposition::getIntergroupVector(int cg1, int cg2){ |
650 |
|
|
Vector3d d; |
651 |
|
|
|
652 |
|
|
#ifdef IS_MPI |
653 |
|
|
d = cgColData.position[cg2] - cgRowData.position[cg1]; |
654 |
|
|
#else |
655 |
|
|
d = snap_->cgData.position[cg2] - snap_->cgData.position[cg1]; |
656 |
|
|
#endif |
657 |
|
|
|
658 |
|
|
snap_->wrapVector(d); |
659 |
|
|
return d; |
660 |
|
|
} |
661 |
|
|
|
662 |
|
|
|
663 |
|
|
Vector3d ForceMatrixDecomposition::getAtomToGroupVectorRow(int atom1, int cg1){ |
664 |
|
|
|
665 |
|
|
Vector3d d; |
666 |
|
|
|
667 |
|
|
#ifdef IS_MPI |
668 |
|
|
d = cgRowData.position[cg1] - atomRowData.position[atom1]; |
669 |
|
|
#else |
670 |
|
|
d = snap_->cgData.position[cg1] - snap_->atomData.position[atom1]; |
671 |
|
|
#endif |
672 |
|
|
|
673 |
|
|
snap_->wrapVector(d); |
674 |
|
|
return d; |
675 |
|
|
} |
676 |
|
|
|
677 |
|
|
Vector3d ForceMatrixDecomposition::getAtomToGroupVectorColumn(int atom2, int cg2){ |
678 |
|
|
Vector3d d; |
679 |
|
|
|
680 |
|
|
#ifdef IS_MPI |
681 |
|
|
d = cgColData.position[cg2] - atomColData.position[atom2]; |
682 |
|
|
#else |
683 |
|
|
d = snap_->cgData.position[cg2] - snap_->atomData.position[atom2]; |
684 |
|
|
#endif |
685 |
|
|
|
686 |
|
|
snap_->wrapVector(d); |
687 |
|
|
return d; |
688 |
|
|
} |
689 |
gezelter |
1569 |
|
690 |
|
|
RealType ForceMatrixDecomposition::getMassFactorRow(int atom1) { |
691 |
|
|
#ifdef IS_MPI |
692 |
|
|
return massFactorsRow[atom1]; |
693 |
|
|
#else |
694 |
|
|
return massFactorsLocal[atom1]; |
695 |
|
|
#endif |
696 |
|
|
} |
697 |
|
|
|
698 |
|
|
RealType ForceMatrixDecomposition::getMassFactorColumn(int atom2) { |
699 |
|
|
#ifdef IS_MPI |
700 |
|
|
return massFactorsCol[atom2]; |
701 |
|
|
#else |
702 |
|
|
return massFactorsLocal[atom2]; |
703 |
|
|
#endif |
704 |
|
|
|
705 |
|
|
} |
706 |
gezelter |
1551 |
|
707 |
|
|
Vector3d ForceMatrixDecomposition::getInteratomicVector(int atom1, int atom2){ |
708 |
|
|
Vector3d d; |
709 |
|
|
|
710 |
|
|
#ifdef IS_MPI |
711 |
|
|
d = atomColData.position[atom2] - atomRowData.position[atom1]; |
712 |
|
|
#else |
713 |
|
|
d = snap_->atomData.position[atom2] - snap_->atomData.position[atom1]; |
714 |
|
|
#endif |
715 |
|
|
|
716 |
|
|
snap_->wrapVector(d); |
717 |
|
|
return d; |
718 |
|
|
} |
719 |
|
|
|
720 |
gezelter |
1579 |
vector<int> ForceMatrixDecomposition::getSkipsForAtom(int atom1) { |
721 |
|
|
return skipsForAtom[atom1]; |
722 |
gezelter |
1570 |
} |
723 |
|
|
|
724 |
|
|
/** |
725 |
gezelter |
1575 |
* There are a number of reasons to skip a pair or a |
726 |
|
|
* particle. Mostly we do this to exclude atoms who are involved in |
727 |
|
|
* short range interactions (bonds, bends, torsions), but we also |
728 |
|
|
* need to exclude some overcounted interactions that result from |
729 |
|
|
* the parallel decomposition. |
730 |
gezelter |
1570 |
*/ |
731 |
|
|
bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) { |
732 |
|
|
int unique_id_1, unique_id_2; |
733 |
|
|
|
734 |
|
|
#ifdef IS_MPI |
735 |
|
|
// in MPI, we have to look up the unique IDs for each atom |
736 |
|
|
unique_id_1 = AtomRowToGlobal[atom1]; |
737 |
|
|
unique_id_2 = AtomColToGlobal[atom2]; |
738 |
|
|
|
739 |
|
|
// this situation should only arise in MPI simulations |
740 |
|
|
if (unique_id_1 == unique_id_2) return true; |
741 |
|
|
|
742 |
|
|
// this prevents us from doing the pair on multiple processors |
743 |
|
|
if (unique_id_1 < unique_id_2) { |
744 |
|
|
if ((unique_id_1 + unique_id_2) % 2 == 0) return true; |
745 |
|
|
} else { |
746 |
|
|
if ((unique_id_1 + unique_id_2) % 2 == 1) return true; |
747 |
|
|
} |
748 |
|
|
#else |
749 |
|
|
// in the normal loop, the atom numbers are unique |
750 |
|
|
unique_id_1 = atom1; |
751 |
|
|
unique_id_2 = atom2; |
752 |
|
|
#endif |
753 |
|
|
|
754 |
gezelter |
1579 |
for (vector<int>::iterator i = skipsForAtom[atom1].begin(); |
755 |
|
|
i != skipsForAtom[atom1].end(); ++i) { |
756 |
gezelter |
1570 |
if ( (*i) == unique_id_2 ) return true; |
757 |
|
|
} |
758 |
gezelter |
1579 |
|
759 |
gezelter |
1570 |
} |
760 |
|
|
|
761 |
|
|
|
762 |
gezelter |
1551 |
void ForceMatrixDecomposition::addForceToAtomRow(int atom1, Vector3d fg){ |
763 |
|
|
#ifdef IS_MPI |
764 |
|
|
atomRowData.force[atom1] += fg; |
765 |
|
|
#else |
766 |
|
|
snap_->atomData.force[atom1] += fg; |
767 |
|
|
#endif |
768 |
|
|
} |
769 |
|
|
|
770 |
|
|
void ForceMatrixDecomposition::addForceToAtomColumn(int atom2, Vector3d fg){ |
771 |
|
|
#ifdef IS_MPI |
772 |
|
|
atomColData.force[atom2] += fg; |
773 |
|
|
#else |
774 |
|
|
snap_->atomData.force[atom2] += fg; |
775 |
|
|
#endif |
776 |
|
|
} |
777 |
|
|
|
778 |
|
|
// filling interaction blocks with pointers |
779 |
|
|
InteractionData ForceMatrixDecomposition::fillInteractionData(int atom1, int atom2) { |
780 |
gezelter |
1567 |
InteractionData idat; |
781 |
gezelter |
1551 |
|
782 |
|
|
#ifdef IS_MPI |
783 |
gezelter |
1571 |
|
784 |
|
|
idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
785 |
|
|
ff_->getAtomType(identsCol[atom2]) ); |
786 |
|
|
|
787 |
gezelter |
1575 |
|
788 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslAmat) { |
789 |
gezelter |
1554 |
idat.A1 = &(atomRowData.aMat[atom1]); |
790 |
|
|
idat.A2 = &(atomColData.aMat[atom2]); |
791 |
gezelter |
1551 |
} |
792 |
gezelter |
1567 |
|
793 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslElectroFrame) { |
794 |
gezelter |
1554 |
idat.eFrame1 = &(atomRowData.electroFrame[atom1]); |
795 |
|
|
idat.eFrame2 = &(atomColData.electroFrame[atom2]); |
796 |
gezelter |
1551 |
} |
797 |
|
|
|
798 |
|
|
if (storageLayout_ & DataStorage::dslTorque) { |
799 |
gezelter |
1554 |
idat.t1 = &(atomRowData.torque[atom1]); |
800 |
|
|
idat.t2 = &(atomColData.torque[atom2]); |
801 |
gezelter |
1551 |
} |
802 |
|
|
|
803 |
|
|
if (storageLayout_ & DataStorage::dslDensity) { |
804 |
gezelter |
1554 |
idat.rho1 = &(atomRowData.density[atom1]); |
805 |
|
|
idat.rho2 = &(atomColData.density[atom2]); |
806 |
gezelter |
1551 |
} |
807 |
|
|
|
808 |
gezelter |
1575 |
if (storageLayout_ & DataStorage::dslFunctional) { |
809 |
|
|
idat.frho1 = &(atomRowData.functional[atom1]); |
810 |
|
|
idat.frho2 = &(atomColData.functional[atom2]); |
811 |
|
|
} |
812 |
|
|
|
813 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
814 |
gezelter |
1554 |
idat.dfrho1 = &(atomRowData.functionalDerivative[atom1]); |
815 |
|
|
idat.dfrho2 = &(atomColData.functionalDerivative[atom2]); |
816 |
gezelter |
1551 |
} |
817 |
gezelter |
1570 |
|
818 |
gezelter |
1575 |
if (storageLayout_ & DataStorage::dslParticlePot) { |
819 |
|
|
idat.particlePot1 = &(atomRowData.particlePot[atom1]); |
820 |
|
|
idat.particlePot2 = &(atomColData.particlePot[atom2]); |
821 |
|
|
} |
822 |
|
|
|
823 |
gezelter |
1562 |
#else |
824 |
gezelter |
1571 |
|
825 |
|
|
idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]), |
826 |
|
|
ff_->getAtomType(identsLocal[atom2]) ); |
827 |
|
|
|
828 |
gezelter |
1562 |
if (storageLayout_ & DataStorage::dslAmat) { |
829 |
|
|
idat.A1 = &(snap_->atomData.aMat[atom1]); |
830 |
|
|
idat.A2 = &(snap_->atomData.aMat[atom2]); |
831 |
|
|
} |
832 |
|
|
|
833 |
|
|
if (storageLayout_ & DataStorage::dslElectroFrame) { |
834 |
|
|
idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]); |
835 |
|
|
idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]); |
836 |
|
|
} |
837 |
|
|
|
838 |
|
|
if (storageLayout_ & DataStorage::dslTorque) { |
839 |
|
|
idat.t1 = &(snap_->atomData.torque[atom1]); |
840 |
|
|
idat.t2 = &(snap_->atomData.torque[atom2]); |
841 |
|
|
} |
842 |
|
|
|
843 |
|
|
if (storageLayout_ & DataStorage::dslDensity) { |
844 |
|
|
idat.rho1 = &(snap_->atomData.density[atom1]); |
845 |
|
|
idat.rho2 = &(snap_->atomData.density[atom2]); |
846 |
|
|
} |
847 |
|
|
|
848 |
gezelter |
1575 |
if (storageLayout_ & DataStorage::dslFunctional) { |
849 |
|
|
idat.frho1 = &(snap_->atomData.functional[atom1]); |
850 |
|
|
idat.frho2 = &(snap_->atomData.functional[atom2]); |
851 |
|
|
} |
852 |
|
|
|
853 |
gezelter |
1562 |
if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
854 |
|
|
idat.dfrho1 = &(snap_->atomData.functionalDerivative[atom1]); |
855 |
|
|
idat.dfrho2 = &(snap_->atomData.functionalDerivative[atom2]); |
856 |
|
|
} |
857 |
gezelter |
1575 |
|
858 |
|
|
if (storageLayout_ & DataStorage::dslParticlePot) { |
859 |
|
|
idat.particlePot1 = &(snap_->atomData.particlePot[atom1]); |
860 |
|
|
idat.particlePot2 = &(snap_->atomData.particlePot[atom2]); |
861 |
|
|
} |
862 |
|
|
|
863 |
gezelter |
1551 |
#endif |
864 |
gezelter |
1567 |
return idat; |
865 |
gezelter |
1551 |
} |
866 |
gezelter |
1567 |
|
867 |
gezelter |
1575 |
|
868 |
|
|
void ForceMatrixDecomposition::unpackInteractionData(InteractionData idat, int atom1, int atom2) { |
869 |
|
|
#ifdef IS_MPI |
870 |
|
|
pot_row[atom1] += 0.5 * *(idat.pot); |
871 |
|
|
pot_col[atom2] += 0.5 * *(idat.pot); |
872 |
|
|
|
873 |
|
|
atomRowData.force[atom1] += *(idat.f1); |
874 |
|
|
atomColData.force[atom2] -= *(idat.f1); |
875 |
|
|
#else |
876 |
|
|
longRangePot_ += *(idat.pot); |
877 |
|
|
|
878 |
|
|
snap_->atomData.force[atom1] += *(idat.f1); |
879 |
|
|
snap_->atomData.force[atom2] -= *(idat.f1); |
880 |
|
|
#endif |
881 |
|
|
|
882 |
|
|
} |
883 |
|
|
|
884 |
|
|
|
885 |
gezelter |
1551 |
InteractionData ForceMatrixDecomposition::fillSkipData(int atom1, int atom2){ |
886 |
gezelter |
1567 |
|
887 |
gezelter |
1562 |
InteractionData idat; |
888 |
|
|
#ifdef IS_MPI |
889 |
gezelter |
1571 |
idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]), |
890 |
|
|
ff_->getAtomType(identsCol[atom2]) ); |
891 |
|
|
|
892 |
gezelter |
1562 |
if (storageLayout_ & DataStorage::dslElectroFrame) { |
893 |
|
|
idat.eFrame1 = &(atomRowData.electroFrame[atom1]); |
894 |
|
|
idat.eFrame2 = &(atomColData.electroFrame[atom2]); |
895 |
|
|
} |
896 |
|
|
if (storageLayout_ & DataStorage::dslTorque) { |
897 |
|
|
idat.t1 = &(atomRowData.torque[atom1]); |
898 |
|
|
idat.t2 = &(atomColData.torque[atom2]); |
899 |
|
|
} |
900 |
gezelter |
1567 |
#else |
901 |
gezelter |
1571 |
idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]), |
902 |
|
|
ff_->getAtomType(identsLocal[atom2]) ); |
903 |
|
|
|
904 |
gezelter |
1567 |
if (storageLayout_ & DataStorage::dslElectroFrame) { |
905 |
|
|
idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]); |
906 |
|
|
idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]); |
907 |
|
|
} |
908 |
|
|
if (storageLayout_ & DataStorage::dslTorque) { |
909 |
|
|
idat.t1 = &(snap_->atomData.torque[atom1]); |
910 |
|
|
idat.t2 = &(snap_->atomData.torque[atom2]); |
911 |
|
|
} |
912 |
gezelter |
1571 |
#endif |
913 |
gezelter |
1551 |
} |
914 |
gezelter |
1567 |
|
915 |
gezelter |
1562 |
/* |
916 |
|
|
* buildNeighborList |
917 |
|
|
* |
918 |
|
|
* first element of pair is row-indexed CutoffGroup |
919 |
|
|
* second element of pair is column-indexed CutoffGroup |
920 |
|
|
*/ |
921 |
gezelter |
1567 |
vector<pair<int, int> > ForceMatrixDecomposition::buildNeighborList() { |
922 |
|
|
|
923 |
|
|
vector<pair<int, int> > neighborList; |
924 |
gezelter |
1576 |
groupCutoffs cuts; |
925 |
gezelter |
1567 |
#ifdef IS_MPI |
926 |
gezelter |
1568 |
cellListRow_.clear(); |
927 |
|
|
cellListCol_.clear(); |
928 |
gezelter |
1567 |
#else |
929 |
gezelter |
1568 |
cellList_.clear(); |
930 |
gezelter |
1567 |
#endif |
931 |
gezelter |
1562 |
|
932 |
gezelter |
1576 |
RealType rList_ = (largestRcut_ + skinThickness_); |
933 |
gezelter |
1567 |
RealType rl2 = rList_ * rList_; |
934 |
|
|
Snapshot* snap_ = sman_->getCurrentSnapshot(); |
935 |
gezelter |
1562 |
Mat3x3d Hmat = snap_->getHmat(); |
936 |
|
|
Vector3d Hx = Hmat.getColumn(0); |
937 |
|
|
Vector3d Hy = Hmat.getColumn(1); |
938 |
|
|
Vector3d Hz = Hmat.getColumn(2); |
939 |
|
|
|
940 |
gezelter |
1568 |
nCells_.x() = (int) ( Hx.length() )/ rList_; |
941 |
|
|
nCells_.y() = (int) ( Hy.length() )/ rList_; |
942 |
|
|
nCells_.z() = (int) ( Hz.length() )/ rList_; |
943 |
gezelter |
1562 |
|
944 |
gezelter |
1567 |
Mat3x3d invHmat = snap_->getInvHmat(); |
945 |
|
|
Vector3d rs, scaled, dr; |
946 |
|
|
Vector3i whichCell; |
947 |
|
|
int cellIndex; |
948 |
gezelter |
1579 |
int nCtot = nCells_.x() * nCells_.y() * nCells_.z(); |
949 |
gezelter |
1567 |
|
950 |
|
|
#ifdef IS_MPI |
951 |
gezelter |
1579 |
cellListRow_.resize(nCtot); |
952 |
|
|
cellListCol_.resize(nCtot); |
953 |
|
|
#else |
954 |
|
|
cellList_.resize(nCtot); |
955 |
|
|
#endif |
956 |
|
|
|
957 |
|
|
#ifdef IS_MPI |
958 |
gezelter |
1567 |
for (int i = 0; i < nGroupsInRow_; i++) { |
959 |
gezelter |
1562 |
rs = cgRowData.position[i]; |
960 |
gezelter |
1567 |
// scaled positions relative to the box vectors |
961 |
|
|
scaled = invHmat * rs; |
962 |
|
|
// wrap the vector back into the unit box by subtracting integer box |
963 |
|
|
// numbers |
964 |
|
|
for (int j = 0; j < 3; j++) |
965 |
|
|
scaled[j] -= roundMe(scaled[j]); |
966 |
|
|
|
967 |
|
|
// find xyz-indices of cell that cutoffGroup is in. |
968 |
gezelter |
1568 |
whichCell.x() = nCells_.x() * scaled.x(); |
969 |
|
|
whichCell.y() = nCells_.y() * scaled.y(); |
970 |
|
|
whichCell.z() = nCells_.z() * scaled.z(); |
971 |
gezelter |
1567 |
|
972 |
|
|
// find single index of this cell: |
973 |
gezelter |
1568 |
cellIndex = Vlinear(whichCell, nCells_); |
974 |
gezelter |
1567 |
// add this cutoff group to the list of groups in this cell; |
975 |
gezelter |
1568 |
cellListRow_[cellIndex].push_back(i); |
976 |
gezelter |
1562 |
} |
977 |
|
|
|
978 |
gezelter |
1567 |
for (int i = 0; i < nGroupsInCol_; i++) { |
979 |
|
|
rs = cgColData.position[i]; |
980 |
|
|
// scaled positions relative to the box vectors |
981 |
|
|
scaled = invHmat * rs; |
982 |
|
|
// wrap the vector back into the unit box by subtracting integer box |
983 |
|
|
// numbers |
984 |
|
|
for (int j = 0; j < 3; j++) |
985 |
|
|
scaled[j] -= roundMe(scaled[j]); |
986 |
|
|
|
987 |
|
|
// find xyz-indices of cell that cutoffGroup is in. |
988 |
gezelter |
1568 |
whichCell.x() = nCells_.x() * scaled.x(); |
989 |
|
|
whichCell.y() = nCells_.y() * scaled.y(); |
990 |
|
|
whichCell.z() = nCells_.z() * scaled.z(); |
991 |
gezelter |
1567 |
|
992 |
|
|
// find single index of this cell: |
993 |
gezelter |
1568 |
cellIndex = Vlinear(whichCell, nCells_); |
994 |
gezelter |
1567 |
// add this cutoff group to the list of groups in this cell; |
995 |
gezelter |
1568 |
cellListCol_[cellIndex].push_back(i); |
996 |
gezelter |
1562 |
} |
997 |
gezelter |
1567 |
#else |
998 |
|
|
for (int i = 0; i < nGroups_; i++) { |
999 |
|
|
rs = snap_->cgData.position[i]; |
1000 |
|
|
// scaled positions relative to the box vectors |
1001 |
|
|
scaled = invHmat * rs; |
1002 |
|
|
// wrap the vector back into the unit box by subtracting integer box |
1003 |
|
|
// numbers |
1004 |
|
|
for (int j = 0; j < 3; j++) |
1005 |
|
|
scaled[j] -= roundMe(scaled[j]); |
1006 |
|
|
|
1007 |
|
|
// find xyz-indices of cell that cutoffGroup is in. |
1008 |
gezelter |
1568 |
whichCell.x() = nCells_.x() * scaled.x(); |
1009 |
|
|
whichCell.y() = nCells_.y() * scaled.y(); |
1010 |
|
|
whichCell.z() = nCells_.z() * scaled.z(); |
1011 |
gezelter |
1567 |
|
1012 |
|
|
// find single index of this cell: |
1013 |
gezelter |
1568 |
cellIndex = Vlinear(whichCell, nCells_); |
1014 |
gezelter |
1567 |
// add this cutoff group to the list of groups in this cell; |
1015 |
gezelter |
1568 |
cellList_[cellIndex].push_back(i); |
1016 |
gezelter |
1567 |
} |
1017 |
|
|
#endif |
1018 |
|
|
|
1019 |
gezelter |
1568 |
for (int m1z = 0; m1z < nCells_.z(); m1z++) { |
1020 |
|
|
for (int m1y = 0; m1y < nCells_.y(); m1y++) { |
1021 |
|
|
for (int m1x = 0; m1x < nCells_.x(); m1x++) { |
1022 |
gezelter |
1562 |
Vector3i m1v(m1x, m1y, m1z); |
1023 |
gezelter |
1568 |
int m1 = Vlinear(m1v, nCells_); |
1024 |
gezelter |
1562 |
|
1025 |
gezelter |
1568 |
for (vector<Vector3i>::iterator os = cellOffsets_.begin(); |
1026 |
|
|
os != cellOffsets_.end(); ++os) { |
1027 |
|
|
|
1028 |
|
|
Vector3i m2v = m1v + (*os); |
1029 |
|
|
|
1030 |
|
|
if (m2v.x() >= nCells_.x()) { |
1031 |
gezelter |
1562 |
m2v.x() = 0; |
1032 |
|
|
} else if (m2v.x() < 0) { |
1033 |
gezelter |
1568 |
m2v.x() = nCells_.x() - 1; |
1034 |
gezelter |
1562 |
} |
1035 |
gezelter |
1568 |
|
1036 |
|
|
if (m2v.y() >= nCells_.y()) { |
1037 |
gezelter |
1562 |
m2v.y() = 0; |
1038 |
|
|
} else if (m2v.y() < 0) { |
1039 |
gezelter |
1568 |
m2v.y() = nCells_.y() - 1; |
1040 |
gezelter |
1562 |
} |
1041 |
gezelter |
1568 |
|
1042 |
|
|
if (m2v.z() >= nCells_.z()) { |
1043 |
gezelter |
1567 |
m2v.z() = 0; |
1044 |
|
|
} else if (m2v.z() < 0) { |
1045 |
gezelter |
1568 |
m2v.z() = nCells_.z() - 1; |
1046 |
gezelter |
1567 |
} |
1047 |
gezelter |
1568 |
|
1048 |
|
|
int m2 = Vlinear (m2v, nCells_); |
1049 |
gezelter |
1567 |
|
1050 |
|
|
#ifdef IS_MPI |
1051 |
gezelter |
1568 |
for (vector<int>::iterator j1 = cellListRow_[m1].begin(); |
1052 |
|
|
j1 != cellListRow_[m1].end(); ++j1) { |
1053 |
|
|
for (vector<int>::iterator j2 = cellListCol_[m2].begin(); |
1054 |
|
|
j2 != cellListCol_[m2].end(); ++j2) { |
1055 |
gezelter |
1567 |
|
1056 |
|
|
// Always do this if we're in different cells or if |
1057 |
|
|
// we're in the same cell and the global index of the |
1058 |
|
|
// j2 cutoff group is less than the j1 cutoff group |
1059 |
|
|
|
1060 |
|
|
if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) { |
1061 |
|
|
dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; |
1062 |
|
|
snap_->wrapVector(dr); |
1063 |
gezelter |
1576 |
cuts = getGroupCutoffs( (*j1), (*j2) ); |
1064 |
|
|
if (dr.lengthSquare() < cuts.third) { |
1065 |
gezelter |
1567 |
neighborList.push_back(make_pair((*j1), (*j2))); |
1066 |
gezelter |
1562 |
} |
1067 |
|
|
} |
1068 |
|
|
} |
1069 |
|
|
} |
1070 |
gezelter |
1567 |
#else |
1071 |
gezelter |
1568 |
for (vector<int>::iterator j1 = cellList_[m1].begin(); |
1072 |
|
|
j1 != cellList_[m1].end(); ++j1) { |
1073 |
|
|
for (vector<int>::iterator j2 = cellList_[m2].begin(); |
1074 |
|
|
j2 != cellList_[m2].end(); ++j2) { |
1075 |
gezelter |
1567 |
|
1076 |
|
|
// Always do this if we're in different cells or if |
1077 |
|
|
// we're in the same cell and the global index of the |
1078 |
|
|
// j2 cutoff group is less than the j1 cutoff group |
1079 |
|
|
|
1080 |
|
|
if (m2 != m1 || (*j2) < (*j1)) { |
1081 |
|
|
dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)]; |
1082 |
|
|
snap_->wrapVector(dr); |
1083 |
gezelter |
1576 |
cuts = getGroupCutoffs( (*j1), (*j2) ); |
1084 |
|
|
if (dr.lengthSquare() < cuts.third) { |
1085 |
gezelter |
1567 |
neighborList.push_back(make_pair((*j1), (*j2))); |
1086 |
|
|
} |
1087 |
|
|
} |
1088 |
|
|
} |
1089 |
|
|
} |
1090 |
|
|
#endif |
1091 |
gezelter |
1562 |
} |
1092 |
|
|
} |
1093 |
|
|
} |
1094 |
|
|
} |
1095 |
gezelter |
1568 |
|
1096 |
|
|
// save the local cutoff group positions for the check that is |
1097 |
|
|
// done on each loop: |
1098 |
|
|
saved_CG_positions_.clear(); |
1099 |
|
|
for (int i = 0; i < nGroups_; i++) |
1100 |
|
|
saved_CG_positions_.push_back(snap_->cgData.position[i]); |
1101 |
|
|
|
1102 |
gezelter |
1567 |
return neighborList; |
1103 |
gezelter |
1562 |
} |
1104 |
gezelter |
1539 |
} //end namespace OpenMD |