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 |
1539 |
#include "parallel/ForceDecomposition.hpp" |
42 |
|
|
#include "parallel/Communicator.hpp" |
43 |
|
|
#include "math/SquareMatrix3.hpp" |
44 |
chuckv |
1538 |
|
45 |
gezelter |
1541 |
using namespace std; |
46 |
gezelter |
1539 |
namespace OpenMD { |
47 |
chuckv |
1538 |
|
48 |
gezelter |
1539 |
void ForceDecomposition::distributeInitialData() { |
49 |
chuckv |
1538 |
#ifdef IS_MPI |
50 |
gezelter |
1541 |
Snapshot* snap = sman_->getCurrentSnapshot(); |
51 |
|
|
int nAtoms = snap->getNumberOfAtoms(); |
52 |
|
|
int nGroups = snap->getNumberOfCutoffGroups(); |
53 |
chuckv |
1538 |
|
54 |
gezelter |
1540 |
AtomCommRealI = new Communicator<Row,RealType>(nAtoms); |
55 |
|
|
AtomCommVectorI = new Communicator<Row,Vector3d>(nAtoms); |
56 |
|
|
AtomCommMatrixI = new Communicator<Row,Mat3x3d>(nAtoms); |
57 |
chuckv |
1538 |
|
58 |
gezelter |
1540 |
AtomCommRealJ = new Communicator<Column,RealType>(nAtoms); |
59 |
|
|
AtomCommVectorJ = new Communicator<Column,Vector3d>(nAtoms); |
60 |
|
|
AtomCommMatrixJ = new Communicator<Column,Mat3x3d>(nAtoms); |
61 |
chuckv |
1538 |
|
62 |
gezelter |
1540 |
cgCommVectorI = new Communicator<Row,Vector3d>(nGroups); |
63 |
|
|
cgCommVectorJ = new Communicator<Column,Vector3d>(nGroups); |
64 |
gezelter |
1541 |
|
65 |
|
|
int nInRow = AtomCommRealI.getSize(); |
66 |
|
|
int nInCol = AtomCommRealJ.getSize(); |
67 |
|
|
|
68 |
|
|
vector<vector<RealType> > pot_row(LR_POT_TYPES, |
69 |
|
|
vector<RealType> (nInRow, 0.0)); |
70 |
|
|
vector<vector<RealType> > pot_col(LR_POT_TYPES, |
71 |
|
|
vector<RealType> (nInCol, 0.0)); |
72 |
|
|
|
73 |
|
|
vector<vector<RealType> > pot_local(LR_POT_TYPES, |
74 |
|
|
vector<RealType> (nAtoms, 0.0)); |
75 |
|
|
|
76 |
chuckv |
1538 |
#endif |
77 |
gezelter |
1539 |
} |
78 |
|
|
|
79 |
chuckv |
1538 |
|
80 |
|
|
|
81 |
gezelter |
1539 |
void ForceDecomposition::distributeData() { |
82 |
chuckv |
1538 |
#ifdef IS_MPI |
83 |
gezelter |
1539 |
Snapshot* snap = sman_->getCurrentSnapshot(); |
84 |
gezelter |
1540 |
|
85 |
gezelter |
1539 |
// gather up the atomic positions |
86 |
|
|
AtomCommVectorI->gather(snap->atomData.position, |
87 |
|
|
snap->atomIData.position); |
88 |
|
|
AtomCommVectorJ->gather(snap->atomData.position, |
89 |
gezelter |
1540 |
snap->atomJData.position); |
90 |
gezelter |
1539 |
|
91 |
|
|
// gather up the cutoff group positions |
92 |
|
|
cgCommVectorI->gather(snap->cgData.position, |
93 |
gezelter |
1540 |
snap->cgIData.position); |
94 |
gezelter |
1539 |
cgCommVectorJ->gather(snap->cgData.position, |
95 |
gezelter |
1540 |
snap->cgJData.position); |
96 |
gezelter |
1539 |
|
97 |
|
|
// if needed, gather the atomic rotation matrices |
98 |
|
|
if (snap->atomData.getStorageLayout() & DataStorage::dslAmat) { |
99 |
|
|
AtomCommMatrixI->gather(snap->atomData.aMat, |
100 |
gezelter |
1540 |
snap->atomIData.aMat); |
101 |
gezelter |
1539 |
AtomCommMatrixJ->gather(snap->atomData.aMat, |
102 |
gezelter |
1540 |
snap->atomJData.aMat); |
103 |
gezelter |
1539 |
} |
104 |
|
|
|
105 |
|
|
// if needed, gather the atomic eletrostatic frames |
106 |
|
|
if (snap->atomData.getStorageLayout() & DataStorage::dslElectroFrame) { |
107 |
|
|
AtomCommMatrixI->gather(snap->atomData.electroFrame, |
108 |
gezelter |
1540 |
snap->atomIData.electroFrame); |
109 |
gezelter |
1539 |
AtomCommMatrixJ->gather(snap->atomData.electroFrame, |
110 |
gezelter |
1540 |
snap->atomJData.electroFrame); |
111 |
gezelter |
1539 |
} |
112 |
|
|
#endif |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
void ForceDecomposition::collectIntermediateData() { |
116 |
|
|
#ifdef IS_MPI |
117 |
|
|
Snapshot* snap = sman_->getCurrentSnapshot(); |
118 |
|
|
|
119 |
|
|
if (snap->atomData.getStorageLayout() & DataStorage::dslDensity) { |
120 |
gezelter |
1541 |
|
121 |
gezelter |
1539 |
AtomCommRealI->scatter(snap->atomIData.density, |
122 |
gezelter |
1540 |
snap->atomData.density); |
123 |
gezelter |
1541 |
|
124 |
|
|
int n = snap->atomData.density.size(); |
125 |
|
|
std::vector<RealType> rho_tmp(n, 0.0); |
126 |
gezelter |
1539 |
AtomCommRealJ->scatter(snap->atomJData.density, rho_tmp); |
127 |
|
|
for (int i = 0; i < n; i++) |
128 |
|
|
snap->atomData.density[i] += rho_tmp[i]; |
129 |
|
|
} |
130 |
chuckv |
1538 |
#endif |
131 |
gezelter |
1539 |
} |
132 |
|
|
|
133 |
|
|
void ForceDecomposition::distributeIntermediateData() { |
134 |
chuckv |
1538 |
#ifdef IS_MPI |
135 |
gezelter |
1539 |
Snapshot* snap = sman_->getCurrentSnapshot(); |
136 |
|
|
if (snap->atomData.getStorageLayout() & DataStorage::dslFunctional) { |
137 |
|
|
AtomCommRealI->gather(snap->atomData.functional, |
138 |
gezelter |
1540 |
snap->atomIData.functional); |
139 |
gezelter |
1539 |
AtomCommRealJ->gather(snap->atomData.functional, |
140 |
gezelter |
1540 |
snap->atomJData.functional); |
141 |
gezelter |
1539 |
} |
142 |
|
|
|
143 |
|
|
if (snap->atomData.getStorageLayout() & DataStorage::dslFunctionalDerivative) { |
144 |
|
|
AtomCommRealI->gather(snap->atomData.functionalDerivative, |
145 |
gezelter |
1540 |
snap->atomIData.functionalDerivative); |
146 |
gezelter |
1539 |
AtomCommRealJ->gather(snap->atomData.functionalDerivative, |
147 |
gezelter |
1540 |
snap->atomJData.functionalDerivative); |
148 |
gezelter |
1539 |
} |
149 |
chuckv |
1538 |
#endif |
150 |
|
|
} |
151 |
gezelter |
1539 |
|
152 |
|
|
|
153 |
|
|
void ForceDecomposition::collectData() { |
154 |
|
|
#ifdef IS_MPI |
155 |
gezelter |
1540 |
Snapshot* snap = sman_->getCurrentSnapshot(); |
156 |
|
|
|
157 |
gezelter |
1541 |
int n = snap->atomData.force.size(); |
158 |
|
|
std::vector<Vector3d> frc_tmp(n, 0.0); |
159 |
|
|
|
160 |
gezelter |
1540 |
AtomCommVectorI->scatter(snap->atomIData.force, frc_tmp); |
161 |
gezelter |
1541 |
for (int i = 0; i < n; i++) { |
162 |
gezelter |
1540 |
snap->atomData.force[i] += frc_tmp[i]; |
163 |
gezelter |
1541 |
frc_tmp[i] = 0.0; |
164 |
|
|
} |
165 |
gezelter |
1540 |
|
166 |
|
|
AtomCommVectorJ->scatter(snap->atomJData.force, frc_tmp); |
167 |
|
|
for (int i = 0; i < n; i++) |
168 |
|
|
snap->atomData.force[i] += frc_tmp[i]; |
169 |
|
|
|
170 |
|
|
|
171 |
|
|
if (snap->atomData.getStorageLayout() & DataStorage::dslTorque) { |
172 |
gezelter |
1541 |
|
173 |
|
|
int nt = snap->atomData.force.size(); |
174 |
|
|
std::vector<Vector3d> trq_tmp(nt, 0.0); |
175 |
|
|
|
176 |
gezelter |
1540 |
AtomCommVectorI->scatter(snap->atomIData.torque, trq_tmp); |
177 |
gezelter |
1541 |
for (int i = 0; i < n; i++) { |
178 |
gezelter |
1540 |
snap->atomData.torque[i] += trq_tmp[i]; |
179 |
gezelter |
1541 |
trq_tmp[i] = 0.0; |
180 |
|
|
} |
181 |
gezelter |
1540 |
|
182 |
|
|
AtomCommVectorJ->scatter(snap->atomJData.torque, trq_tmp); |
183 |
|
|
for (int i = 0; i < n; i++) |
184 |
|
|
snap->atomData.torque[i] += trq_tmp[i]; |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
|
188 |
gezelter |
1541 |
vector<vector<RealType> > pot_temp(LR_POT_TYPES, |
189 |
|
|
vector<RealType> (nAtoms, 0.0)); |
190 |
|
|
|
191 |
|
|
for (int i = 0; i < LR_POT_TYPES; i++) { |
192 |
|
|
AtomCommRealI->scatter(pot_row[i], pot_temp[i]); |
193 |
|
|
for (int ii = 0; ii < pot_temp[i].size(); ii++ ) { |
194 |
|
|
pot_local[i] += pot_temp[i][ii]; |
195 |
|
|
} |
196 |
|
|
} |
197 |
|
|
|
198 |
gezelter |
1540 |
|
199 |
|
|
|
200 |
gezelter |
1539 |
#endif |
201 |
chuckv |
1538 |
} |
202 |
|
|
|
203 |
gezelter |
1539 |
} //end namespace OpenMD |