# | Line 39 | Line 39 | |
---|---|---|
39 | * [4] Vardeman & Gezelter, in progress (2009). | |
40 | */ | |
41 | #include "parallel/ForceDecomposition.hpp" | |
42 | – | #include "parallel/Communicator.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 | + | /** |
50 | + | * distributeInitialData is essentially a copy of the older fortran |
51 | + | * SimulationSetup |
52 | + | */ |
53 | + | |
54 | void ForceDecomposition::distributeInitialData() { | |
55 | < | #ifdef IS_MPI |
55 | > | #ifdef IS_MPI |
56 | > | Snapshot* snap = sman_->getCurrentSnapshot(); |
57 | > | int nLocal = snap->getNumberOfAtoms(); |
58 | > | int nGroups = snap->getNumberOfCutoffGroups(); |
59 | ||
60 | < | int nAtoms; |
61 | < | int nGroups; |
60 | > | AtomCommIntI = new Communicator<Row,int>(nLocal); |
61 | > | AtomCommRealI = new Communicator<Row,RealType>(nLocal); |
62 | > | AtomCommVectorI = new Communicator<Row,Vector3d>(nLocal); |
63 | > | AtomCommMatrixI = new Communicator<Row,Mat3x3d>(nLocal); |
64 | ||
65 | < | AtomCommRealI = new Communicator<Row,RealType>(nAtoms); |
66 | < | AtomCommVectorI = new Communicator<Row,Vector3d>(nAtoms); |
67 | < | AtomCommMatrixI = new Communicator<Row,Mat3x3d>(nAtoms); |
65 | > | AtomCommIntJ = new Communicator<Column,int>(nLocal); |
66 | > | AtomCommRealJ = new Communicator<Column,RealType>(nLocal); |
67 | > | AtomCommVectorJ = new Communicator<Column,Vector3d>(nLocal); |
68 | > | AtomCommMatrixJ = new Communicator<Column,Mat3x3d>(nLocal); |
69 | ||
70 | < | AtomCommRealJ = new Communicator<Column,RealType>(nAtoms); |
58 | < | AtomCommVectorJ = new Communicator<Column,Vector3d>(nAtoms); |
59 | < | AtomCommMatrixJ = new Communicator<Column,Mat3x3d>(nAtoms); |
60 | < | |
70 | > | cgCommIntI = new Communicator<Row,int>(nGroups); |
71 | cgCommVectorI = new Communicator<Row,Vector3d>(nGroups); | |
72 | + | cgCommIntJ = new Communicator<Column,int>(nGroups); |
73 | cgCommVectorJ = new Communicator<Column,Vector3d>(nGroups); | |
74 | < | // more to come |
74 | > | |
75 | > | int nAtomsInRow = AtomCommIntI->getSize(); |
76 | > | int nAtomsInCol = AtomCommIntJ->getSize(); |
77 | > | int nGroupsInRow = cgCommIntI->getSize(); |
78 | > | int nGroupsInCol = cgCommIntJ->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 | > | AtomCommIntI->gather(info_->getIdentArray(), identsRow); |
89 | > | AtomCommIntJ->gather(info_->getIdentArray(), identsCol); |
90 | > | |
91 | > | AtomLocalToGlobal = info_->getLocalToGlobalAtomIndex(); |
92 | > | AtomCommIntI->gather(AtomLocalToGlobal, AtomRowToGlobal); |
93 | > | AtomCommIntJ->gather(AtomLocalToGlobal, AtomColToGlobal); |
94 | > | |
95 | > | cgLocalToGlobal = info_->getLocalToGlobalCutoffGroupIndex(); |
96 | > | cgCommIntI->gather(cgLocalToGlobal, cgRowToGlobal); |
97 | > | cgCommIntJ->gather(cgLocalToGlobal, cgColToGlobal); |
98 | > | |
99 | > | |
100 | > | |
101 | > | |
102 | > | |
103 | > | |
104 | > | // still need: |
105 | > | // topoDist |
106 | > | // exclude |
107 | #endif | |
108 | } | |
109 | ||
# | Line 105 | Line 148 | namespace OpenMD { | |
148 | Snapshot* snap = sman_->getCurrentSnapshot(); | |
149 | ||
150 | if (snap->atomData.getStorageLayout() & DataStorage::dslDensity) { | |
151 | + | |
152 | AtomCommRealI->scatter(snap->atomIData.density, | |
153 | snap->atomData.density); | |
154 | < | std::vector<RealType> rho_tmp; |
155 | < | int n = snap->getNumberOfAtoms(); |
156 | < | rho_tmp.reserve( n ); |
154 | > | |
155 | > | int n = snap->atomData.density.size(); |
156 | > | std::vector<RealType> rho_tmp(n, 0.0); |
157 | AtomCommRealJ->scatter(snap->atomJData.density, rho_tmp); | |
158 | for (int i = 0; i < n; i++) | |
159 | snap->atomData.density[i] += rho_tmp[i]; | |
# | Line 140 | Line 184 | namespace OpenMD { | |
184 | void ForceDecomposition::collectData() { | |
185 | #ifdef IS_MPI | |
186 | Snapshot* snap = sman_->getCurrentSnapshot(); | |
143 | – | int n = snap->getNumberOfAtoms(); |
144 | – | |
145 | – | std::vector<Vector3d> frc_tmp; |
146 | – | frc_tmp.reserve( n ); |
187 | ||
188 | + | int n = snap->atomData.force.size(); |
189 | + | vector<Vector3d> frc_tmp(n, V3Zero); |
190 | + | |
191 | AtomCommVectorI->scatter(snap->atomIData.force, frc_tmp); | |
192 | < | for (int i = 0; i < n; i++) |
192 | > | for (int i = 0; i < n; i++) { |
193 | snap->atomData.force[i] += frc_tmp[i]; | |
194 | + | frc_tmp[i] = 0.0; |
195 | + | } |
196 | ||
197 | AtomCommVectorJ->scatter(snap->atomJData.force, frc_tmp); | |
198 | for (int i = 0; i < n; i++) | |
# | Line 155 | Line 200 | namespace OpenMD { | |
200 | ||
201 | ||
202 | if (snap->atomData.getStorageLayout() & DataStorage::dslTorque) { | |
203 | < | std::vector<Vector3d> trq_tmp; |
204 | < | trq_tmp.reserve( n ); |
205 | < | |
203 | > | |
204 | > | int nt = snap->atomData.force.size(); |
205 | > | vector<Vector3d> trq_tmp(nt, V3Zero); |
206 | > | |
207 | AtomCommVectorI->scatter(snap->atomIData.torque, trq_tmp); | |
208 | < | for (int i = 0; i < n; i++) |
208 | > | for (int i = 0; i < n; i++) { |
209 | snap->atomData.torque[i] += trq_tmp[i]; | |
210 | + | trq_tmp[i] = 0.0; |
211 | + | } |
212 | ||
213 | AtomCommVectorJ->scatter(snap->atomJData.torque, trq_tmp); | |
214 | for (int i = 0; i < n; i++) | |
215 | snap->atomData.torque[i] += trq_tmp[i]; | |
216 | } | |
217 | ||
218 | < | // Still need pot! |
171 | < | |
218 | > | int nLocal = snap->getNumberOfAtoms(); |
219 | ||
220 | < | |
220 | > | vector<vector<RealType> > pot_temp(N_INTERACTION_FAMILIES, |
221 | > | vector<RealType> (nLocal, 0.0)); |
222 | > | |
223 | > | for (int i = 0; i < N_INTERACTION_FAMILIES; i++) { |
224 | > | AtomCommRealI->scatter(pot_row[i], pot_temp[i]); |
225 | > | for (int ii = 0; ii < pot_temp[i].size(); ii++ ) { |
226 | > | pot_local[i] += pot_temp[i][ii]; |
227 | > | } |
228 | > | } |
229 | #endif | |
230 | } | |
231 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |