# | Line 38 | Line 38 | |
---|---|---|
38 | * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). | |
39 | * [4] Vardeman & Gezelter, in progress (2009). | |
40 | */ | |
41 | < | #include "parallel/ForceDecomposition.hpp" |
42 | < | #include "parallel/Communicator.hpp" |
41 | > | #include "parallel/ForceMatrixDecomposition.hpp" |
42 | #include "math/SquareMatrix3.hpp" | |
43 | + | #include "nonbonded/NonBondedInteraction.hpp" |
44 | + | #include "brains/SnapshotManager.hpp" |
45 | ||
46 | using namespace std; | |
47 | namespace OpenMD { | |
48 | ||
49 | < | void ForceDecomposition::distributeInitialData() { |
50 | < | #ifdef IS_MPI |
49 | > | /** |
50 | > | * distributeInitialData is essentially a copy of the older fortran |
51 | > | * SimulationSetup |
52 | > | */ |
53 | > | |
54 | > | void ForceMatrixDecomposition::distributeInitialData() { |
55 | > | #ifdef IS_MPI |
56 | Snapshot* snap = sman_->getCurrentSnapshot(); | |
57 | < | int nAtoms = snap->getNumberOfAtoms(); |
57 | > | int nLocal = snap->getNumberOfAtoms(); |
58 | int nGroups = snap->getNumberOfCutoffGroups(); | |
59 | ||
60 | < | AtomCommRealI = new Communicator<Row,RealType>(nAtoms); |
61 | < | AtomCommVectorI = new Communicator<Row,Vector3d>(nAtoms); |
62 | < | AtomCommMatrixI = new Communicator<Row,Mat3x3d>(nAtoms); |
60 | > | AtomCommIntRow = new Communicator<Row,int>(nLocal); |
61 | > | AtomCommRealRow = new Communicator<Row,RealType>(nLocal); |
62 | > | AtomCommVectorRow = new Communicator<Row,Vector3d>(nLocal); |
63 | > | AtomCommMatrixRow = new Communicator<Row,Mat3x3d>(nLocal); |
64 | ||
65 | < | AtomCommRealJ = new Communicator<Column,RealType>(nAtoms); |
66 | < | AtomCommVectorJ = new Communicator<Column,Vector3d>(nAtoms); |
67 | < | AtomCommMatrixJ = new Communicator<Column,Mat3x3d>(nAtoms); |
65 | > | AtomCommIntColumn = new Communicator<Column,int>(nLocal); |
66 | > | AtomCommRealColumn = new Communicator<Column,RealType>(nLocal); |
67 | > | AtomCommVectorColumn = new Communicator<Column,Vector3d>(nLocal); |
68 | > | AtomCommMatrixColumn = new Communicator<Column,Mat3x3d>(nLocal); |
69 | ||
70 | < | cgCommVectorI = new Communicator<Row,Vector3d>(nGroups); |
71 | < | cgCommVectorJ = new Communicator<Column,Vector3d>(nGroups); |
70 | > | cgCommIntRow = new Communicator<Row,int>(nGroups); |
71 | > | cgCommVectorRow = new Communicator<Row,Vector3d>(nGroups); |
72 | > | cgCommIntColumn = new Communicator<Column,int>(nGroups); |
73 | > | cgCommVectorColumn = new Communicator<Column,Vector3d>(nGroups); |
74 | ||
75 | < | int nInRow = AtomCommRealI.getSize(); |
76 | < | int nInCol = AtomCommRealJ.getSize(); |
75 | > | int nAtomsInRow = AtomCommIntRow->getSize(); |
76 | > | int nAtomsInCol = AtomCommIntColumn->getSize(); |
77 | > | int nGroupsInRow = cgCommIntRow->getSize(); |
78 | > | int nGroupsInCol = cgCommIntColumn->getSize(); |
79 | > | |
80 | > | vector<vector<RealType> > pot_row(N_INTERACTION_FAMILIES, |
81 | > | vector<RealType> (nAtomsInRow, 0.0)); |
82 | > | vector<vector<RealType> > pot_col(N_INTERACTION_FAMILIES, |
83 | > | vector<RealType> (nAtomsInCol, 0.0)); |
84 | > | |
85 | > | vector<RealType> pot_local(N_INTERACTION_FAMILIES, 0.0); |
86 | > | |
87 | > | // gather the information for atomtype IDs (atids): |
88 | > | vector<int> identsLocal = info_->getIdentArray(); |
89 | > | identsRow.reserve(nAtomsInRow); |
90 | > | identsCol.reserve(nAtomsInCol); |
91 | > | |
92 | > | AtomCommIntRow->gather(identsLocal, identsRow); |
93 | > | AtomCommIntColumn->gather(identsLocal, identsCol); |
94 | > | |
95 | > | AtomLocalToGlobal = info_->getGlobalAtomIndices(); |
96 | > | AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal); |
97 | > | AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal); |
98 | > | |
99 | > | cgLocalToGlobal = info_->getGlobalGroupIndices(); |
100 | > | cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal); |
101 | > | cgCommIntColumn->gather(cgLocalToGlobal, cgColToGlobal); |
102 | ||
103 | < | vector<vector<RealType> > pot_row(LR_POT_TYPES, |
104 | < | vector<RealType> (nInRow, 0.0)); |
105 | < | 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 | < | |
103 | > | // still need: |
104 | > | // topoDist |
105 | > | // exclude |
106 | #endif | |
107 | } | |
108 | ||
109 | ||
110 | ||
111 | < | void ForceDecomposition::distributeData() { |
111 | > | void ForceMatrixDecomposition::distributeData() { |
112 | #ifdef IS_MPI | |
113 | Snapshot* snap = sman_->getCurrentSnapshot(); | |
114 | ||
115 | // gather up the atomic positions | |
116 | < | AtomCommVectorI->gather(snap->atomData.position, |
116 | > | AtomCommVectorRow->gather(snap->atomData.position, |
117 | snap->atomIData.position); | |
118 | < | AtomCommVectorJ->gather(snap->atomData.position, |
118 | > | AtomCommVectorColumn->gather(snap->atomData.position, |
119 | snap->atomJData.position); | |
120 | ||
121 | // gather up the cutoff group positions | |
122 | < | cgCommVectorI->gather(snap->cgData.position, |
122 | > | cgCommVectorRow->gather(snap->cgData.position, |
123 | snap->cgIData.position); | |
124 | < | cgCommVectorJ->gather(snap->cgData.position, |
124 | > | cgCommVectorColumn->gather(snap->cgData.position, |
125 | snap->cgJData.position); | |
126 | ||
127 | // if needed, gather the atomic rotation matrices | |
128 | if (snap->atomData.getStorageLayout() & DataStorage::dslAmat) { | |
129 | < | AtomCommMatrixI->gather(snap->atomData.aMat, |
129 | > | AtomCommMatrixRow->gather(snap->atomData.aMat, |
130 | snap->atomIData.aMat); | |
131 | < | AtomCommMatrixJ->gather(snap->atomData.aMat, |
131 | > | AtomCommMatrixColumn->gather(snap->atomData.aMat, |
132 | snap->atomJData.aMat); | |
133 | } | |
134 | ||
135 | // if needed, gather the atomic eletrostatic frames | |
136 | if (snap->atomData.getStorageLayout() & DataStorage::dslElectroFrame) { | |
137 | < | AtomCommMatrixI->gather(snap->atomData.electroFrame, |
137 | > | AtomCommMatrixRow->gather(snap->atomData.electroFrame, |
138 | snap->atomIData.electroFrame); | |
139 | < | AtomCommMatrixJ->gather(snap->atomData.electroFrame, |
139 | > | AtomCommMatrixColumn->gather(snap->atomData.electroFrame, |
140 | snap->atomJData.electroFrame); | |
141 | } | |
142 | #endif | |
143 | } | |
144 | ||
145 | < | void ForceDecomposition::collectIntermediateData() { |
145 | > | void ForceMatrixDecomposition::collectIntermediateData() { |
146 | #ifdef IS_MPI | |
147 | Snapshot* snap = sman_->getCurrentSnapshot(); | |
148 | ||
149 | if (snap->atomData.getStorageLayout() & DataStorage::dslDensity) { | |
150 | ||
151 | < | AtomCommRealI->scatter(snap->atomIData.density, |
151 | > | AtomCommRealRow->scatter(snap->atomIData.density, |
152 | snap->atomData.density); | |
153 | ||
154 | int n = snap->atomData.density.size(); | |
155 | std::vector<RealType> rho_tmp(n, 0.0); | |
156 | < | AtomCommRealJ->scatter(snap->atomJData.density, rho_tmp); |
156 | > | AtomCommRealColumn->scatter(snap->atomJData.density, rho_tmp); |
157 | for (int i = 0; i < n; i++) | |
158 | snap->atomData.density[i] += rho_tmp[i]; | |
159 | } | |
160 | #endif | |
161 | } | |
162 | ||
163 | < | void ForceDecomposition::distributeIntermediateData() { |
163 | > | void ForceMatrixDecomposition::distributeIntermediateData() { |
164 | #ifdef IS_MPI | |
165 | Snapshot* snap = sman_->getCurrentSnapshot(); | |
166 | if (snap->atomData.getStorageLayout() & DataStorage::dslFunctional) { | |
167 | < | AtomCommRealI->gather(snap->atomData.functional, |
167 | > | AtomCommRealRow->gather(snap->atomData.functional, |
168 | snap->atomIData.functional); | |
169 | < | AtomCommRealJ->gather(snap->atomData.functional, |
169 | > | AtomCommRealColumn->gather(snap->atomData.functional, |
170 | snap->atomJData.functional); | |
171 | } | |
172 | ||
173 | if (snap->atomData.getStorageLayout() & DataStorage::dslFunctionalDerivative) { | |
174 | < | AtomCommRealI->gather(snap->atomData.functionalDerivative, |
174 | > | AtomCommRealRow->gather(snap->atomData.functionalDerivative, |
175 | snap->atomIData.functionalDerivative); | |
176 | < | AtomCommRealJ->gather(snap->atomData.functionalDerivative, |
176 | > | AtomCommRealColumn->gather(snap->atomData.functionalDerivative, |
177 | snap->atomJData.functionalDerivative); | |
178 | } | |
179 | #endif | |
180 | } | |
181 | ||
182 | ||
183 | < | void ForceDecomposition::collectData() { |
183 | > | void ForceMatrixDecomposition::collectData() { |
184 | #ifdef IS_MPI | |
185 | Snapshot* snap = sman_->getCurrentSnapshot(); | |
186 | ||
187 | int n = snap->atomData.force.size(); | |
188 | < | std::vector<Vector3d> frc_tmp(n, 0.0); |
188 | > | vector<Vector3d> frc_tmp(n, V3Zero); |
189 | ||
190 | < | AtomCommVectorI->scatter(snap->atomIData.force, frc_tmp); |
190 | > | AtomCommVectorRow->scatter(snap->atomIData.force, frc_tmp); |
191 | for (int i = 0; i < n; i++) { | |
192 | snap->atomData.force[i] += frc_tmp[i]; | |
193 | frc_tmp[i] = 0.0; | |
194 | } | |
195 | ||
196 | < | AtomCommVectorJ->scatter(snap->atomJData.force, frc_tmp); |
196 | > | AtomCommVectorColumn->scatter(snap->atomJData.force, frc_tmp); |
197 | for (int i = 0; i < n; i++) | |
198 | snap->atomData.force[i] += frc_tmp[i]; | |
199 | ||
# | Line 171 | Line 201 | namespace OpenMD { | |
201 | if (snap->atomData.getStorageLayout() & DataStorage::dslTorque) { | |
202 | ||
203 | int nt = snap->atomData.force.size(); | |
204 | < | std::vector<Vector3d> trq_tmp(nt, 0.0); |
204 | > | vector<Vector3d> trq_tmp(nt, V3Zero); |
205 | ||
206 | < | AtomCommVectorI->scatter(snap->atomIData.torque, trq_tmp); |
206 | > | AtomCommVectorRow->scatter(snap->atomIData.torque, trq_tmp); |
207 | for (int i = 0; i < n; i++) { | |
208 | snap->atomData.torque[i] += trq_tmp[i]; | |
209 | trq_tmp[i] = 0.0; | |
210 | } | |
211 | ||
212 | < | AtomCommVectorJ->scatter(snap->atomJData.torque, trq_tmp); |
212 | > | AtomCommVectorColumn->scatter(snap->atomJData.torque, trq_tmp); |
213 | for (int i = 0; i < n; i++) | |
214 | snap->atomData.torque[i] += trq_tmp[i]; | |
215 | } | |
216 | ||
217 | + | int nLocal = snap->getNumberOfAtoms(); |
218 | + | |
219 | + | vector<vector<RealType> > pot_temp(N_INTERACTION_FAMILIES, |
220 | + | vector<RealType> (nLocal, 0.0)); |
221 | ||
222 | < | vector<vector<RealType> > pot_temp(LR_POT_TYPES, |
223 | < | 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]); |
222 | > | for (int i = 0; i < N_INTERACTION_FAMILIES; i++) { |
223 | > | AtomCommRealRow->scatter(pot_row[i], pot_temp[i]); |
224 | for (int ii = 0; ii < pot_temp[i].size(); ii++ ) { | |
225 | pot_local[i] += pot_temp[i][ii]; | |
226 | } | |
227 | } | |
197 | – | |
198 | – | |
199 | – | |
228 | #endif | |
229 | } | |
230 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |