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 |
chuckv |
1538 |
|
46 |
gezelter |
1541 |
using namespace std; |
47 |
gezelter |
1539 |
namespace OpenMD { |
48 |
chuckv |
1538 |
|
49 |
gezelter |
1544 |
/** |
50 |
|
|
* distributeInitialData is essentially a copy of the older fortran |
51 |
|
|
* SimulationSetup |
52 |
|
|
*/ |
53 |
|
|
|
54 |
gezelter |
1549 |
void ForceMatrixDecomposition::distributeInitialData() { |
55 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
56 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
57 |
gezelter |
1567 |
nLocal_ = snap_->getNumberOfAtoms(); |
58 |
|
|
nGroups_ = snap_->getNumberOfCutoffGroups(); |
59 |
chuckv |
1538 |
|
60 |
gezelter |
1567 |
#ifdef IS_MPI |
61 |
|
|
|
62 |
|
|
AtomCommIntRow = new Communicator<Row,int>(nLocal_); |
63 |
|
|
AtomCommRealRow = new Communicator<Row,RealType>(nLocal_); |
64 |
|
|
AtomCommVectorRow = new Communicator<Row,Vector3d>(nLocal_); |
65 |
|
|
AtomCommMatrixRow = new Communicator<Row,Mat3x3d>(nLocal_); |
66 |
chuckv |
1538 |
|
67 |
gezelter |
1567 |
AtomCommIntColumn = new Communicator<Column,int>(nLocal_); |
68 |
|
|
AtomCommRealColumn = new Communicator<Column,RealType>(nLocal_); |
69 |
|
|
AtomCommVectorColumn = new Communicator<Column,Vector3d>(nLocal_); |
70 |
|
|
AtomCommMatrixColumn = new Communicator<Column,Mat3x3d>(nLocal_); |
71 |
gezelter |
1541 |
|
72 |
gezelter |
1567 |
cgCommIntRow = new Communicator<Row,int>(nGroups_); |
73 |
|
|
cgCommVectorRow = new Communicator<Row,Vector3d>(nGroups_); |
74 |
|
|
cgCommIntColumn = new Communicator<Column,int>(nGroups_); |
75 |
|
|
cgCommVectorColumn = new Communicator<Column,Vector3d>(nGroups_); |
76 |
gezelter |
1551 |
|
77 |
gezelter |
1567 |
nAtomsInRow_ = AtomCommIntRow->getSize(); |
78 |
|
|
nAtomsInCol_ = AtomCommIntColumn->getSize(); |
79 |
|
|
nGroupsInRow_ = cgCommIntRow->getSize(); |
80 |
|
|
nGroupsInCol_ = cgCommIntColumn->getSize(); |
81 |
|
|
|
82 |
gezelter |
1551 |
// Modify the data storage objects with the correct layouts and sizes: |
83 |
gezelter |
1567 |
atomRowData.resize(nAtomsInRow_); |
84 |
gezelter |
1551 |
atomRowData.setStorageLayout(storageLayout_); |
85 |
gezelter |
1567 |
atomColData.resize(nAtomsInCol_); |
86 |
gezelter |
1551 |
atomColData.setStorageLayout(storageLayout_); |
87 |
gezelter |
1567 |
cgRowData.resize(nGroupsInRow_); |
88 |
gezelter |
1551 |
cgRowData.setStorageLayout(DataStorage::dslPosition); |
89 |
gezelter |
1567 |
cgColData.resize(nGroupsInCol_); |
90 |
gezelter |
1551 |
cgColData.setStorageLayout(DataStorage::dslPosition); |
91 |
gezelter |
1549 |
|
92 |
gezelter |
1544 |
vector<vector<RealType> > pot_row(N_INTERACTION_FAMILIES, |
93 |
gezelter |
1567 |
vector<RealType> (nAtomsInRow_, 0.0)); |
94 |
gezelter |
1544 |
vector<vector<RealType> > pot_col(N_INTERACTION_FAMILIES, |
95 |
gezelter |
1567 |
vector<RealType> (nAtomsInCol_, 0.0)); |
96 |
gezelter |
1551 |
|
97 |
|
|
|
98 |
gezelter |
1544 |
vector<RealType> pot_local(N_INTERACTION_FAMILIES, 0.0); |
99 |
gezelter |
1549 |
|
100 |
gezelter |
1544 |
// gather the information for atomtype IDs (atids): |
101 |
gezelter |
1547 |
vector<int> identsLocal = info_->getIdentArray(); |
102 |
gezelter |
1567 |
identsRow.reserve(nAtomsInRow_); |
103 |
|
|
identsCol.reserve(nAtomsInCol_); |
104 |
gezelter |
1549 |
|
105 |
|
|
AtomCommIntRow->gather(identsLocal, identsRow); |
106 |
|
|
AtomCommIntColumn->gather(identsLocal, identsCol); |
107 |
|
|
|
108 |
|
|
AtomLocalToGlobal = info_->getGlobalAtomIndices(); |
109 |
|
|
AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal); |
110 |
|
|
AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal); |
111 |
|
|
|
112 |
|
|
cgLocalToGlobal = info_->getGlobalGroupIndices(); |
113 |
|
|
cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal); |
114 |
|
|
cgCommIntColumn->gather(cgLocalToGlobal, cgColToGlobal); |
115 |
gezelter |
1541 |
|
116 |
gezelter |
1544 |
// still need: |
117 |
|
|
// topoDist |
118 |
|
|
// exclude |
119 |
chuckv |
1538 |
#endif |
120 |
gezelter |
1539 |
} |
121 |
|
|
|
122 |
chuckv |
1538 |
|
123 |
|
|
|
124 |
gezelter |
1549 |
void ForceMatrixDecomposition::distributeData() { |
125 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
126 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
127 |
chuckv |
1538 |
#ifdef IS_MPI |
128 |
gezelter |
1540 |
|
129 |
gezelter |
1539 |
// gather up the atomic positions |
130 |
gezelter |
1551 |
AtomCommVectorRow->gather(snap_->atomData.position, |
131 |
|
|
atomRowData.position); |
132 |
|
|
AtomCommVectorColumn->gather(snap_->atomData.position, |
133 |
|
|
atomColData.position); |
134 |
gezelter |
1539 |
|
135 |
|
|
// gather up the cutoff group positions |
136 |
gezelter |
1551 |
cgCommVectorRow->gather(snap_->cgData.position, |
137 |
|
|
cgRowData.position); |
138 |
|
|
cgCommVectorColumn->gather(snap_->cgData.position, |
139 |
|
|
cgColData.position); |
140 |
gezelter |
1539 |
|
141 |
|
|
// if needed, gather the atomic rotation matrices |
142 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslAmat) { |
143 |
|
|
AtomCommMatrixRow->gather(snap_->atomData.aMat, |
144 |
|
|
atomRowData.aMat); |
145 |
|
|
AtomCommMatrixColumn->gather(snap_->atomData.aMat, |
146 |
|
|
atomColData.aMat); |
147 |
gezelter |
1539 |
} |
148 |
|
|
|
149 |
|
|
// if needed, gather the atomic eletrostatic frames |
150 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslElectroFrame) { |
151 |
|
|
AtomCommMatrixRow->gather(snap_->atomData.electroFrame, |
152 |
|
|
atomRowData.electroFrame); |
153 |
|
|
AtomCommMatrixColumn->gather(snap_->atomData.electroFrame, |
154 |
|
|
atomColData.electroFrame); |
155 |
gezelter |
1539 |
} |
156 |
|
|
#endif |
157 |
|
|
} |
158 |
|
|
|
159 |
gezelter |
1549 |
void ForceMatrixDecomposition::collectIntermediateData() { |
160 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
161 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
162 |
gezelter |
1539 |
#ifdef IS_MPI |
163 |
|
|
|
164 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslDensity) { |
165 |
|
|
|
166 |
|
|
AtomCommRealRow->scatter(atomRowData.density, |
167 |
|
|
snap_->atomData.density); |
168 |
|
|
|
169 |
|
|
int n = snap_->atomData.density.size(); |
170 |
gezelter |
1541 |
std::vector<RealType> rho_tmp(n, 0.0); |
171 |
gezelter |
1551 |
AtomCommRealColumn->scatter(atomColData.density, rho_tmp); |
172 |
gezelter |
1539 |
for (int i = 0; i < n; i++) |
173 |
gezelter |
1551 |
snap_->atomData.density[i] += rho_tmp[i]; |
174 |
gezelter |
1539 |
} |
175 |
chuckv |
1538 |
#endif |
176 |
gezelter |
1539 |
} |
177 |
|
|
|
178 |
gezelter |
1549 |
void ForceMatrixDecomposition::distributeIntermediateData() { |
179 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
180 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
181 |
chuckv |
1538 |
#ifdef IS_MPI |
182 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslFunctional) { |
183 |
|
|
AtomCommRealRow->gather(snap_->atomData.functional, |
184 |
|
|
atomRowData.functional); |
185 |
|
|
AtomCommRealColumn->gather(snap_->atomData.functional, |
186 |
|
|
atomColData.functional); |
187 |
gezelter |
1539 |
} |
188 |
|
|
|
189 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
190 |
|
|
AtomCommRealRow->gather(snap_->atomData.functionalDerivative, |
191 |
|
|
atomRowData.functionalDerivative); |
192 |
|
|
AtomCommRealColumn->gather(snap_->atomData.functionalDerivative, |
193 |
|
|
atomColData.functionalDerivative); |
194 |
gezelter |
1539 |
} |
195 |
chuckv |
1538 |
#endif |
196 |
|
|
} |
197 |
gezelter |
1539 |
|
198 |
|
|
|
199 |
gezelter |
1549 |
void ForceMatrixDecomposition::collectData() { |
200 |
gezelter |
1551 |
snap_ = sman_->getCurrentSnapshot(); |
201 |
|
|
storageLayout_ = sman_->getStorageLayout(); |
202 |
|
|
#ifdef IS_MPI |
203 |
|
|
int n = snap_->atomData.force.size(); |
204 |
gezelter |
1544 |
vector<Vector3d> frc_tmp(n, V3Zero); |
205 |
gezelter |
1541 |
|
206 |
gezelter |
1551 |
AtomCommVectorRow->scatter(atomRowData.force, frc_tmp); |
207 |
gezelter |
1541 |
for (int i = 0; i < n; i++) { |
208 |
gezelter |
1551 |
snap_->atomData.force[i] += frc_tmp[i]; |
209 |
gezelter |
1541 |
frc_tmp[i] = 0.0; |
210 |
|
|
} |
211 |
gezelter |
1540 |
|
212 |
gezelter |
1551 |
AtomCommVectorColumn->scatter(atomColData.force, frc_tmp); |
213 |
gezelter |
1540 |
for (int i = 0; i < n; i++) |
214 |
gezelter |
1551 |
snap_->atomData.force[i] += frc_tmp[i]; |
215 |
gezelter |
1540 |
|
216 |
|
|
|
217 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslTorque) { |
218 |
gezelter |
1541 |
|
219 |
gezelter |
1551 |
int nt = snap_->atomData.force.size(); |
220 |
gezelter |
1544 |
vector<Vector3d> trq_tmp(nt, V3Zero); |
221 |
gezelter |
1541 |
|
222 |
gezelter |
1551 |
AtomCommVectorRow->scatter(atomRowData.torque, trq_tmp); |
223 |
gezelter |
1541 |
for (int i = 0; i < n; i++) { |
224 |
gezelter |
1551 |
snap_->atomData.torque[i] += trq_tmp[i]; |
225 |
gezelter |
1541 |
trq_tmp[i] = 0.0; |
226 |
|
|
} |
227 |
gezelter |
1540 |
|
228 |
gezelter |
1551 |
AtomCommVectorColumn->scatter(atomColData.torque, trq_tmp); |
229 |
gezelter |
1540 |
for (int i = 0; i < n; i++) |
230 |
gezelter |
1551 |
snap_->atomData.torque[i] += trq_tmp[i]; |
231 |
gezelter |
1540 |
} |
232 |
|
|
|
233 |
gezelter |
1567 |
nLocal_ = snap_->getNumberOfAtoms(); |
234 |
gezelter |
1544 |
|
235 |
|
|
vector<vector<RealType> > pot_temp(N_INTERACTION_FAMILIES, |
236 |
gezelter |
1567 |
vector<RealType> (nLocal_, 0.0)); |
237 |
gezelter |
1540 |
|
238 |
gezelter |
1544 |
for (int i = 0; i < N_INTERACTION_FAMILIES; i++) { |
239 |
gezelter |
1549 |
AtomCommRealRow->scatter(pot_row[i], pot_temp[i]); |
240 |
gezelter |
1541 |
for (int ii = 0; ii < pot_temp[i].size(); ii++ ) { |
241 |
|
|
pot_local[i] += pot_temp[i][ii]; |
242 |
|
|
} |
243 |
|
|
} |
244 |
gezelter |
1539 |
#endif |
245 |
chuckv |
1538 |
} |
246 |
gezelter |
1551 |
|
247 |
chuckv |
1538 |
|
248 |
gezelter |
1551 |
Vector3d ForceMatrixDecomposition::getIntergroupVector(int cg1, int cg2){ |
249 |
|
|
Vector3d d; |
250 |
|
|
|
251 |
|
|
#ifdef IS_MPI |
252 |
|
|
d = cgColData.position[cg2] - cgRowData.position[cg1]; |
253 |
|
|
#else |
254 |
|
|
d = snap_->cgData.position[cg2] - snap_->cgData.position[cg1]; |
255 |
|
|
#endif |
256 |
|
|
|
257 |
|
|
snap_->wrapVector(d); |
258 |
|
|
return d; |
259 |
|
|
} |
260 |
|
|
|
261 |
|
|
|
262 |
|
|
Vector3d ForceMatrixDecomposition::getAtomToGroupVectorRow(int atom1, int cg1){ |
263 |
|
|
|
264 |
|
|
Vector3d d; |
265 |
|
|
|
266 |
|
|
#ifdef IS_MPI |
267 |
|
|
d = cgRowData.position[cg1] - atomRowData.position[atom1]; |
268 |
|
|
#else |
269 |
|
|
d = snap_->cgData.position[cg1] - snap_->atomData.position[atom1]; |
270 |
|
|
#endif |
271 |
|
|
|
272 |
|
|
snap_->wrapVector(d); |
273 |
|
|
return d; |
274 |
|
|
} |
275 |
|
|
|
276 |
|
|
Vector3d ForceMatrixDecomposition::getAtomToGroupVectorColumn(int atom2, int cg2){ |
277 |
|
|
Vector3d d; |
278 |
|
|
|
279 |
|
|
#ifdef IS_MPI |
280 |
|
|
d = cgColData.position[cg2] - atomColData.position[atom2]; |
281 |
|
|
#else |
282 |
|
|
d = snap_->cgData.position[cg2] - snap_->atomData.position[atom2]; |
283 |
|
|
#endif |
284 |
|
|
|
285 |
|
|
snap_->wrapVector(d); |
286 |
|
|
return d; |
287 |
|
|
} |
288 |
|
|
|
289 |
|
|
Vector3d ForceMatrixDecomposition::getInteratomicVector(int atom1, int atom2){ |
290 |
|
|
Vector3d d; |
291 |
|
|
|
292 |
|
|
#ifdef IS_MPI |
293 |
|
|
d = atomColData.position[atom2] - atomRowData.position[atom1]; |
294 |
|
|
#else |
295 |
|
|
d = snap_->atomData.position[atom2] - snap_->atomData.position[atom1]; |
296 |
|
|
#endif |
297 |
|
|
|
298 |
|
|
snap_->wrapVector(d); |
299 |
|
|
return d; |
300 |
|
|
} |
301 |
|
|
|
302 |
|
|
void ForceMatrixDecomposition::addForceToAtomRow(int atom1, Vector3d fg){ |
303 |
|
|
#ifdef IS_MPI |
304 |
|
|
atomRowData.force[atom1] += fg; |
305 |
|
|
#else |
306 |
|
|
snap_->atomData.force[atom1] += fg; |
307 |
|
|
#endif |
308 |
|
|
} |
309 |
|
|
|
310 |
|
|
void ForceMatrixDecomposition::addForceToAtomColumn(int atom2, Vector3d fg){ |
311 |
|
|
#ifdef IS_MPI |
312 |
|
|
atomColData.force[atom2] += fg; |
313 |
|
|
#else |
314 |
|
|
snap_->atomData.force[atom2] += fg; |
315 |
|
|
#endif |
316 |
|
|
} |
317 |
|
|
|
318 |
|
|
// filling interaction blocks with pointers |
319 |
|
|
InteractionData ForceMatrixDecomposition::fillInteractionData(int atom1, int atom2) { |
320 |
gezelter |
1567 |
InteractionData idat; |
321 |
gezelter |
1551 |
|
322 |
|
|
#ifdef IS_MPI |
323 |
|
|
if (storageLayout_ & DataStorage::dslAmat) { |
324 |
gezelter |
1554 |
idat.A1 = &(atomRowData.aMat[atom1]); |
325 |
|
|
idat.A2 = &(atomColData.aMat[atom2]); |
326 |
gezelter |
1551 |
} |
327 |
gezelter |
1567 |
|
328 |
gezelter |
1551 |
if (storageLayout_ & DataStorage::dslElectroFrame) { |
329 |
gezelter |
1554 |
idat.eFrame1 = &(atomRowData.electroFrame[atom1]); |
330 |
|
|
idat.eFrame2 = &(atomColData.electroFrame[atom2]); |
331 |
gezelter |
1551 |
} |
332 |
|
|
|
333 |
|
|
if (storageLayout_ & DataStorage::dslTorque) { |
334 |
gezelter |
1554 |
idat.t1 = &(atomRowData.torque[atom1]); |
335 |
|
|
idat.t2 = &(atomColData.torque[atom2]); |
336 |
gezelter |
1551 |
} |
337 |
|
|
|
338 |
|
|
if (storageLayout_ & DataStorage::dslDensity) { |
339 |
gezelter |
1554 |
idat.rho1 = &(atomRowData.density[atom1]); |
340 |
|
|
idat.rho2 = &(atomColData.density[atom2]); |
341 |
gezelter |
1551 |
} |
342 |
|
|
|
343 |
|
|
if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
344 |
gezelter |
1554 |
idat.dfrho1 = &(atomRowData.functionalDerivative[atom1]); |
345 |
|
|
idat.dfrho2 = &(atomColData.functionalDerivative[atom2]); |
346 |
gezelter |
1551 |
} |
347 |
gezelter |
1562 |
#else |
348 |
|
|
if (storageLayout_ & DataStorage::dslAmat) { |
349 |
|
|
idat.A1 = &(snap_->atomData.aMat[atom1]); |
350 |
|
|
idat.A2 = &(snap_->atomData.aMat[atom2]); |
351 |
|
|
} |
352 |
|
|
|
353 |
|
|
if (storageLayout_ & DataStorage::dslElectroFrame) { |
354 |
|
|
idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]); |
355 |
|
|
idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]); |
356 |
|
|
} |
357 |
|
|
|
358 |
|
|
if (storageLayout_ & DataStorage::dslTorque) { |
359 |
|
|
idat.t1 = &(snap_->atomData.torque[atom1]); |
360 |
|
|
idat.t2 = &(snap_->atomData.torque[atom2]); |
361 |
|
|
} |
362 |
|
|
|
363 |
|
|
if (storageLayout_ & DataStorage::dslDensity) { |
364 |
|
|
idat.rho1 = &(snap_->atomData.density[atom1]); |
365 |
|
|
idat.rho2 = &(snap_->atomData.density[atom2]); |
366 |
|
|
} |
367 |
|
|
|
368 |
|
|
if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
369 |
|
|
idat.dfrho1 = &(snap_->atomData.functionalDerivative[atom1]); |
370 |
|
|
idat.dfrho2 = &(snap_->atomData.functionalDerivative[atom2]); |
371 |
|
|
} |
372 |
gezelter |
1551 |
#endif |
373 |
gezelter |
1567 |
return idat; |
374 |
gezelter |
1551 |
} |
375 |
gezelter |
1567 |
|
376 |
gezelter |
1551 |
InteractionData ForceMatrixDecomposition::fillSkipData(int atom1, int atom2){ |
377 |
gezelter |
1567 |
|
378 |
gezelter |
1562 |
InteractionData idat; |
379 |
|
|
#ifdef IS_MPI |
380 |
|
|
if (storageLayout_ & DataStorage::dslElectroFrame) { |
381 |
|
|
idat.eFrame1 = &(atomRowData.electroFrame[atom1]); |
382 |
|
|
idat.eFrame2 = &(atomColData.electroFrame[atom2]); |
383 |
|
|
} |
384 |
|
|
if (storageLayout_ & DataStorage::dslTorque) { |
385 |
|
|
idat.t1 = &(atomRowData.torque[atom1]); |
386 |
|
|
idat.t2 = &(atomColData.torque[atom2]); |
387 |
|
|
} |
388 |
gezelter |
1567 |
if (storageLayout_ & DataStorage::dslForce) { |
389 |
|
|
idat.t1 = &(atomRowData.force[atom1]); |
390 |
|
|
idat.t2 = &(atomColData.force[atom2]); |
391 |
|
|
} |
392 |
|
|
#else |
393 |
|
|
if (storageLayout_ & DataStorage::dslElectroFrame) { |
394 |
|
|
idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]); |
395 |
|
|
idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]); |
396 |
|
|
} |
397 |
|
|
if (storageLayout_ & DataStorage::dslTorque) { |
398 |
|
|
idat.t1 = &(snap_->atomData.torque[atom1]); |
399 |
|
|
idat.t2 = &(snap_->atomData.torque[atom2]); |
400 |
|
|
} |
401 |
|
|
if (storageLayout_ & DataStorage::dslForce) { |
402 |
|
|
idat.t1 = &(snap_->atomData.force[atom1]); |
403 |
|
|
idat.t2 = &(snap_->atomData.force[atom2]); |
404 |
|
|
} |
405 |
|
|
#endif |
406 |
gezelter |
1562 |
|
407 |
gezelter |
1551 |
} |
408 |
gezelter |
1567 |
|
409 |
|
|
|
410 |
gezelter |
1551 |
|
411 |
gezelter |
1562 |
|
412 |
|
|
/* |
413 |
|
|
* buildNeighborList |
414 |
|
|
* |
415 |
|
|
* first element of pair is row-indexed CutoffGroup |
416 |
|
|
* second element of pair is column-indexed CutoffGroup |
417 |
|
|
*/ |
418 |
gezelter |
1567 |
vector<pair<int, int> > ForceMatrixDecomposition::buildNeighborList() { |
419 |
|
|
|
420 |
|
|
vector<pair<int, int> > neighborList; |
421 |
|
|
#ifdef IS_MPI |
422 |
gezelter |
1568 |
cellListRow_.clear(); |
423 |
|
|
cellListCol_.clear(); |
424 |
gezelter |
1567 |
#else |
425 |
gezelter |
1568 |
cellList_.clear(); |
426 |
gezelter |
1567 |
#endif |
427 |
gezelter |
1562 |
|
428 |
gezelter |
1567 |
// dangerous to not do error checking. |
429 |
|
|
RealType rCut_; |
430 |
|
|
|
431 |
|
|
RealType rList_ = (rCut_ + skinThickness_); |
432 |
|
|
RealType rl2 = rList_ * rList_; |
433 |
|
|
Snapshot* snap_ = sman_->getCurrentSnapshot(); |
434 |
gezelter |
1562 |
Mat3x3d Hmat = snap_->getHmat(); |
435 |
|
|
Vector3d Hx = Hmat.getColumn(0); |
436 |
|
|
Vector3d Hy = Hmat.getColumn(1); |
437 |
|
|
Vector3d Hz = Hmat.getColumn(2); |
438 |
|
|
|
439 |
gezelter |
1568 |
nCells_.x() = (int) ( Hx.length() )/ rList_; |
440 |
|
|
nCells_.y() = (int) ( Hy.length() )/ rList_; |
441 |
|
|
nCells_.z() = (int) ( Hz.length() )/ rList_; |
442 |
gezelter |
1562 |
|
443 |
gezelter |
1567 |
Mat3x3d invHmat = snap_->getInvHmat(); |
444 |
|
|
Vector3d rs, scaled, dr; |
445 |
|
|
Vector3i whichCell; |
446 |
|
|
int cellIndex; |
447 |
|
|
|
448 |
|
|
#ifdef IS_MPI |
449 |
|
|
for (int i = 0; i < nGroupsInRow_; i++) { |
450 |
gezelter |
1562 |
rs = cgRowData.position[i]; |
451 |
gezelter |
1567 |
// scaled positions relative to the box vectors |
452 |
|
|
scaled = invHmat * rs; |
453 |
|
|
// wrap the vector back into the unit box by subtracting integer box |
454 |
|
|
// numbers |
455 |
|
|
for (int j = 0; j < 3; j++) |
456 |
|
|
scaled[j] -= roundMe(scaled[j]); |
457 |
|
|
|
458 |
|
|
// find xyz-indices of cell that cutoffGroup is in. |
459 |
gezelter |
1568 |
whichCell.x() = nCells_.x() * scaled.x(); |
460 |
|
|
whichCell.y() = nCells_.y() * scaled.y(); |
461 |
|
|
whichCell.z() = nCells_.z() * scaled.z(); |
462 |
gezelter |
1567 |
|
463 |
|
|
// find single index of this cell: |
464 |
gezelter |
1568 |
cellIndex = Vlinear(whichCell, nCells_); |
465 |
gezelter |
1567 |
// add this cutoff group to the list of groups in this cell; |
466 |
gezelter |
1568 |
cellListRow_[cellIndex].push_back(i); |
467 |
gezelter |
1562 |
} |
468 |
|
|
|
469 |
gezelter |
1567 |
for (int i = 0; i < nGroupsInCol_; i++) { |
470 |
|
|
rs = cgColData.position[i]; |
471 |
|
|
// scaled positions relative to the box vectors |
472 |
|
|
scaled = invHmat * rs; |
473 |
|
|
// wrap the vector back into the unit box by subtracting integer box |
474 |
|
|
// numbers |
475 |
|
|
for (int j = 0; j < 3; j++) |
476 |
|
|
scaled[j] -= roundMe(scaled[j]); |
477 |
|
|
|
478 |
|
|
// find xyz-indices of cell that cutoffGroup is in. |
479 |
gezelter |
1568 |
whichCell.x() = nCells_.x() * scaled.x(); |
480 |
|
|
whichCell.y() = nCells_.y() * scaled.y(); |
481 |
|
|
whichCell.z() = nCells_.z() * scaled.z(); |
482 |
gezelter |
1567 |
|
483 |
|
|
// find single index of this cell: |
484 |
gezelter |
1568 |
cellIndex = Vlinear(whichCell, nCells_); |
485 |
gezelter |
1567 |
// add this cutoff group to the list of groups in this cell; |
486 |
gezelter |
1568 |
cellListCol_[cellIndex].push_back(i); |
487 |
gezelter |
1562 |
} |
488 |
gezelter |
1567 |
#else |
489 |
|
|
for (int i = 0; i < nGroups_; i++) { |
490 |
|
|
rs = snap_->cgData.position[i]; |
491 |
|
|
// scaled positions relative to the box vectors |
492 |
|
|
scaled = invHmat * rs; |
493 |
|
|
// wrap the vector back into the unit box by subtracting integer box |
494 |
|
|
// numbers |
495 |
|
|
for (int j = 0; j < 3; j++) |
496 |
|
|
scaled[j] -= roundMe(scaled[j]); |
497 |
|
|
|
498 |
|
|
// find xyz-indices of cell that cutoffGroup is in. |
499 |
gezelter |
1568 |
whichCell.x() = nCells_.x() * scaled.x(); |
500 |
|
|
whichCell.y() = nCells_.y() * scaled.y(); |
501 |
|
|
whichCell.z() = nCells_.z() * scaled.z(); |
502 |
gezelter |
1567 |
|
503 |
|
|
// find single index of this cell: |
504 |
gezelter |
1568 |
cellIndex = Vlinear(whichCell, nCells_); |
505 |
gezelter |
1567 |
// add this cutoff group to the list of groups in this cell; |
506 |
gezelter |
1568 |
cellList_[cellIndex].push_back(i); |
507 |
gezelter |
1567 |
} |
508 |
|
|
#endif |
509 |
|
|
|
510 |
|
|
|
511 |
|
|
|
512 |
gezelter |
1568 |
for (int m1z = 0; m1z < nCells_.z(); m1z++) { |
513 |
|
|
for (int m1y = 0; m1y < nCells_.y(); m1y++) { |
514 |
|
|
for (int m1x = 0; m1x < nCells_.x(); m1x++) { |
515 |
gezelter |
1562 |
Vector3i m1v(m1x, m1y, m1z); |
516 |
gezelter |
1568 |
int m1 = Vlinear(m1v, nCells_); |
517 |
gezelter |
1562 |
|
518 |
gezelter |
1568 |
for (vector<Vector3i>::iterator os = cellOffsets_.begin(); |
519 |
|
|
os != cellOffsets_.end(); ++os) { |
520 |
|
|
|
521 |
|
|
Vector3i m2v = m1v + (*os); |
522 |
|
|
|
523 |
|
|
if (m2v.x() >= nCells_.x()) { |
524 |
gezelter |
1562 |
m2v.x() = 0; |
525 |
|
|
} else if (m2v.x() < 0) { |
526 |
gezelter |
1568 |
m2v.x() = nCells_.x() - 1; |
527 |
gezelter |
1562 |
} |
528 |
gezelter |
1568 |
|
529 |
|
|
if (m2v.y() >= nCells_.y()) { |
530 |
gezelter |
1562 |
m2v.y() = 0; |
531 |
|
|
} else if (m2v.y() < 0) { |
532 |
gezelter |
1568 |
m2v.y() = nCells_.y() - 1; |
533 |
gezelter |
1562 |
} |
534 |
gezelter |
1568 |
|
535 |
|
|
if (m2v.z() >= nCells_.z()) { |
536 |
gezelter |
1567 |
m2v.z() = 0; |
537 |
|
|
} else if (m2v.z() < 0) { |
538 |
gezelter |
1568 |
m2v.z() = nCells_.z() - 1; |
539 |
gezelter |
1567 |
} |
540 |
gezelter |
1568 |
|
541 |
|
|
int m2 = Vlinear (m2v, nCells_); |
542 |
gezelter |
1567 |
|
543 |
|
|
#ifdef IS_MPI |
544 |
gezelter |
1568 |
for (vector<int>::iterator j1 = cellListRow_[m1].begin(); |
545 |
|
|
j1 != cellListRow_[m1].end(); ++j1) { |
546 |
|
|
for (vector<int>::iterator j2 = cellListCol_[m2].begin(); |
547 |
|
|
j2 != cellListCol_[m2].end(); ++j2) { |
548 |
gezelter |
1567 |
|
549 |
|
|
// Always do this if we're in different cells or if |
550 |
|
|
// we're in the same cell and the global index of the |
551 |
|
|
// j2 cutoff group is less than the j1 cutoff group |
552 |
|
|
|
553 |
|
|
if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) { |
554 |
|
|
dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; |
555 |
|
|
snap_->wrapVector(dr); |
556 |
|
|
if (dr.lengthSquare() < rl2) { |
557 |
|
|
neighborList.push_back(make_pair((*j1), (*j2))); |
558 |
gezelter |
1562 |
} |
559 |
|
|
} |
560 |
|
|
} |
561 |
|
|
} |
562 |
gezelter |
1567 |
#else |
563 |
gezelter |
1568 |
for (vector<int>::iterator j1 = cellList_[m1].begin(); |
564 |
|
|
j1 != cellList_[m1].end(); ++j1) { |
565 |
|
|
for (vector<int>::iterator j2 = cellList_[m2].begin(); |
566 |
|
|
j2 != cellList_[m2].end(); ++j2) { |
567 |
gezelter |
1567 |
|
568 |
|
|
// Always do this if we're in different cells or if |
569 |
|
|
// we're in the same cell and the global index of the |
570 |
|
|
// j2 cutoff group is less than the j1 cutoff group |
571 |
|
|
|
572 |
|
|
if (m2 != m1 || (*j2) < (*j1)) { |
573 |
|
|
dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)]; |
574 |
|
|
snap_->wrapVector(dr); |
575 |
|
|
if (dr.lengthSquare() < rl2) { |
576 |
|
|
neighborList.push_back(make_pair((*j1), (*j2))); |
577 |
|
|
} |
578 |
|
|
} |
579 |
|
|
} |
580 |
|
|
} |
581 |
|
|
#endif |
582 |
gezelter |
1562 |
} |
583 |
|
|
} |
584 |
|
|
} |
585 |
|
|
} |
586 |
gezelter |
1568 |
|
587 |
|
|
// save the local cutoff group positions for the check that is |
588 |
|
|
// done on each loop: |
589 |
|
|
saved_CG_positions_.clear(); |
590 |
|
|
for (int i = 0; i < nGroups_; i++) |
591 |
|
|
saved_CG_positions_.push_back(snap_->cgData.position[i]); |
592 |
|
|
|
593 |
gezelter |
1567 |
return neighborList; |
594 |
gezelter |
1562 |
} |
595 |
gezelter |
1539 |
} //end namespace OpenMD |