1 |
|
/* |
2 |
< |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
2 |
> |
* Copyright (c) 2009 The University of Notre Dame. All Rights Reserved. |
3 |
|
* |
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. Acknowledgement of the program authors must be made in any |
10 |
< |
* publication of scientific results based in part on use of the |
11 |
< |
* program. An acceptable form of acknowledgement is citation of |
12 |
< |
* the article in which the program was described (Matthew |
13 |
< |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
< |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
< |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
< |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
< |
* |
18 |
< |
* 2. Redistributions of source code must retain the above copyright |
9 |
> |
* 1. Redistributions of source code must retain the above copyright |
10 |
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
* |
12 |
< |
* 3. Redistributions in binary form must reproduce the above copyright |
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. |
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, 234107 (2008). |
39 |
+ |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
+ |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
42 |
+ |
|
43 |
+ |
#include "config.h" |
44 |
+ |
|
45 |
+ |
#ifdef IS_MPI |
46 |
+ |
#include <mpi.h> |
47 |
+ |
#endif |
48 |
|
|
49 |
|
#include "io/DumpWriter.hpp" |
50 |
|
#include "primitives/Molecule.hpp" |
51 |
|
#include "utils/simError.h" |
52 |
|
#include "io/basic_teebuf.hpp" |
53 |
+ |
#ifdef HAVE_ZLIB |
54 |
|
#include "io/gzstream.hpp" |
55 |
+ |
#endif |
56 |
|
#include "io/Globals.hpp" |
57 |
|
|
58 |
< |
#ifdef IS_MPI |
59 |
< |
#include <mpi.h> |
60 |
< |
#endif //is_mpi |
58 |
> |
#ifdef _MSC_VER |
59 |
> |
#define isnan(x) _isnan((x)) |
60 |
> |
#define isinf(x) (!_finite(x) && !_isnan(x)) |
61 |
> |
#endif |
62 |
|
|
63 |
< |
namespace oopse { |
63 |
> |
using namespace std; |
64 |
> |
namespace OpenMD { |
65 |
|
|
66 |
|
DumpWriter::DumpWriter(SimInfo* info) |
67 |
|
: info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ |
68 |
|
|
69 |
|
Globals* simParams = info->getSimParams(); |
70 |
< |
needCompression_ = simParams->getCompressDumpFile(); |
71 |
< |
needForceVector_ = simParams->getOutputForceVector(); |
70 |
> |
needCompression_ = simParams->getCompressDumpFile(); |
71 |
> |
needForceVector_ = simParams->getOutputForceVector(); |
72 |
> |
needParticlePot_ = simParams->getOutputParticlePotential(); |
73 |
> |
needFlucQ_ = simParams->getOutputFluctuatingCharges(); |
74 |
> |
needElectricField_ = simParams->getOutputElectricField(); |
75 |
> |
|
76 |
> |
if (needParticlePot_ || needFlucQ_ || needElectricField_) { |
77 |
> |
doSiteData_ = true; |
78 |
> |
} else { |
79 |
> |
doSiteData_ = false; |
80 |
> |
} |
81 |
> |
|
82 |
|
createDumpFile_ = true; |
83 |
|
#ifdef HAVE_LIBZ |
84 |
|
if (needCompression_) { |
85 |
< |
filename_ += ".gz"; |
86 |
< |
eorFilename_ += ".gz"; |
85 |
> |
filename_ += ".gz"; |
86 |
> |
eorFilename_ += ".gz"; |
87 |
|
} |
88 |
|
#endif |
89 |
|
|
90 |
|
#ifdef IS_MPI |
91 |
|
|
92 |
< |
if (worldRank == 0) { |
92 |
> |
if (worldRank == 0) { |
93 |
|
#endif // is_mpi |
73 |
– |
|
94 |
|
|
95 |
< |
dumpFile_ = createOStream(filename_); |
95 |
> |
dumpFile_ = createOStream(filename_); |
96 |
|
|
97 |
< |
if (!dumpFile_) { |
98 |
< |
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
99 |
< |
filename_.c_str()); |
100 |
< |
painCave.isFatal = 1; |
101 |
< |
simError(); |
102 |
< |
} |
97 |
> |
if (!dumpFile_) { |
98 |
> |
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
99 |
> |
filename_.c_str()); |
100 |
> |
painCave.isFatal = 1; |
101 |
> |
simError(); |
102 |
> |
} |
103 |
|
|
104 |
|
#ifdef IS_MPI |
105 |
|
|
106 |
< |
} |
106 |
> |
} |
107 |
|
|
88 |
– |
sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); |
89 |
– |
MPIcheckPoint(); |
90 |
– |
|
108 |
|
#endif // is_mpi |
109 |
|
|
110 |
< |
} |
110 |
> |
} |
111 |
|
|
112 |
|
|
113 |
|
DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) |
116 |
|
Globals* simParams = info->getSimParams(); |
117 |
|
eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
118 |
|
|
119 |
< |
needCompression_ = simParams->getCompressDumpFile(); |
120 |
< |
needForceVector_ = simParams->getOutputForceVector(); |
119 |
> |
needCompression_ = simParams->getCompressDumpFile(); |
120 |
> |
needForceVector_ = simParams->getOutputForceVector(); |
121 |
> |
needParticlePot_ = simParams->getOutputParticlePotential(); |
122 |
> |
needFlucQ_ = simParams->getOutputFluctuatingCharges(); |
123 |
> |
needElectricField_ = simParams->getOutputElectricField(); |
124 |
> |
|
125 |
> |
if (needParticlePot_ || needFlucQ_ || needElectricField_) { |
126 |
> |
doSiteData_ = true; |
127 |
> |
} else { |
128 |
> |
doSiteData_ = false; |
129 |
> |
} |
130 |
> |
|
131 |
|
createDumpFile_ = true; |
132 |
|
#ifdef HAVE_LIBZ |
133 |
|
if (needCompression_) { |
134 |
< |
filename_ += ".gz"; |
135 |
< |
eorFilename_ += ".gz"; |
134 |
> |
filename_ += ".gz"; |
135 |
> |
eorFilename_ += ".gz"; |
136 |
|
} |
137 |
|
#endif |
138 |
|
|
139 |
|
#ifdef IS_MPI |
140 |
|
|
141 |
< |
if (worldRank == 0) { |
141 |
> |
if (worldRank == 0) { |
142 |
|
#endif // is_mpi |
143 |
|
|
144 |
|
|
145 |
< |
dumpFile_ = createOStream(filename_); |
145 |
> |
dumpFile_ = createOStream(filename_); |
146 |
|
|
147 |
< |
if (!dumpFile_) { |
148 |
< |
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
149 |
< |
filename_.c_str()); |
150 |
< |
painCave.isFatal = 1; |
151 |
< |
simError(); |
152 |
< |
} |
147 |
> |
if (!dumpFile_) { |
148 |
> |
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
149 |
> |
filename_.c_str()); |
150 |
> |
painCave.isFatal = 1; |
151 |
> |
simError(); |
152 |
> |
} |
153 |
|
|
154 |
|
#ifdef IS_MPI |
155 |
|
|
156 |
< |
} |
156 |
> |
} |
157 |
|
|
131 |
– |
sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); |
132 |
– |
MPIcheckPoint(); |
133 |
– |
|
158 |
|
#endif // is_mpi |
159 |
|
|
160 |
< |
} |
160 |
> |
} |
161 |
|
|
162 |
|
DumpWriter::DumpWriter(SimInfo* info, const std::string& filename, bool writeDumpFile) |
163 |
< |
: info_(info), filename_(filename){ |
163 |
> |
: info_(info), filename_(filename){ |
164 |
|
|
165 |
|
Globals* simParams = info->getSimParams(); |
166 |
|
eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
167 |
|
|
168 |
< |
needCompression_ = simParams->getCompressDumpFile(); |
169 |
< |
needForceVector_ = simParams->getOutputForceVector(); |
170 |
< |
|
168 |
> |
needCompression_ = simParams->getCompressDumpFile(); |
169 |
> |
needForceVector_ = simParams->getOutputForceVector(); |
170 |
> |
needParticlePot_ = simParams->getOutputParticlePotential(); |
171 |
> |
needFlucQ_ = simParams->getOutputFluctuatingCharges(); |
172 |
> |
needElectricField_ = simParams->getOutputElectricField(); |
173 |
> |
|
174 |
> |
if (needParticlePot_ || needFlucQ_ || needElectricField_) { |
175 |
> |
doSiteData_ = true; |
176 |
> |
} else { |
177 |
> |
doSiteData_ = false; |
178 |
> |
} |
179 |
> |
|
180 |
|
#ifdef HAVE_LIBZ |
181 |
|
if (needCompression_) { |
182 |
|
filename_ += ".gz"; |
203 |
|
#ifdef IS_MPI |
204 |
|
|
205 |
|
} |
206 |
+ |
|
207 |
|
|
174 |
– |
sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); |
175 |
– |
MPIcheckPoint(); |
176 |
– |
|
208 |
|
#endif // is_mpi |
209 |
|
|
210 |
|
} |
180 |
– |
|
181 |
– |
|
182 |
– |
|
183 |
– |
|
184 |
– |
|
211 |
|
|
212 |
|
DumpWriter::~DumpWriter() { |
213 |
|
|
216 |
|
if (worldRank == 0) { |
217 |
|
#endif // is_mpi |
218 |
|
if (createDumpFile_){ |
219 |
+ |
writeClosing(*dumpFile_); |
220 |
|
delete dumpFile_; |
221 |
|
} |
222 |
|
#ifdef IS_MPI |
227 |
|
|
228 |
|
} |
229 |
|
|
230 |
< |
void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) { |
230 |
> |
void DumpWriter::writeFrameProperties(std::ostream& os, Snapshot* s) { |
231 |
|
|
232 |
< |
RealType currentTime; |
233 |
< |
Mat3x3d hmat; |
234 |
< |
RealType chi; |
235 |
< |
RealType integralOfChiDt; |
236 |
< |
Mat3x3d eta; |
237 |
< |
|
238 |
< |
currentTime = s->getTime(); |
232 |
> |
char buffer[1024]; |
233 |
> |
|
234 |
> |
os << " <FrameData>\n"; |
235 |
> |
|
236 |
> |
RealType currentTime = s->getTime(); |
237 |
> |
|
238 |
> |
if (isinf(currentTime) || isnan(currentTime)) { |
239 |
> |
sprintf( painCave.errMsg, |
240 |
> |
"DumpWriter detected a numerical error writing the time"); |
241 |
> |
painCave.isFatal = 1; |
242 |
> |
simError(); |
243 |
> |
} |
244 |
> |
|
245 |
> |
sprintf(buffer, " Time: %.10g\n", currentTime); |
246 |
> |
os << buffer; |
247 |
> |
|
248 |
> |
Mat3x3d hmat; |
249 |
|
hmat = s->getHmat(); |
250 |
< |
chi = s->getChi(); |
251 |
< |
integralOfChiDt = s->getIntegralOfChiDt(); |
252 |
< |
eta = s->getEta(); |
250 |
> |
|
251 |
> |
for (unsigned int i = 0; i < 3; i++) { |
252 |
> |
for (unsigned int j = 0; j < 3; j++) { |
253 |
> |
if (isinf(hmat(i,j)) || isnan(hmat(i,j))) { |
254 |
> |
sprintf( painCave.errMsg, |
255 |
> |
"DumpWriter detected a numerical error writing the box"); |
256 |
> |
painCave.isFatal = 1; |
257 |
> |
simError(); |
258 |
> |
} |
259 |
> |
} |
260 |
> |
} |
261 |
|
|
262 |
< |
os << currentTime << ";\t" |
263 |
< |
<< hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t" |
264 |
< |
<< hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t" |
265 |
< |
<< hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t"; |
262 |
> |
sprintf(buffer, " Hmat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n", |
263 |
> |
hmat(0, 0), hmat(1, 0), hmat(2, 0), |
264 |
> |
hmat(0, 1), hmat(1, 1), hmat(2, 1), |
265 |
> |
hmat(0, 2), hmat(1, 2), hmat(2, 2)); |
266 |
> |
os << buffer; |
267 |
|
|
268 |
< |
//write out additional parameters, such as chi and eta |
268 |
> |
pair<RealType, RealType> thermostat = s->getThermostat(); |
269 |
|
|
270 |
< |
os << chi << "\t" << integralOfChiDt << ";\t"; |
270 |
> |
if (isinf(thermostat.first) || isnan(thermostat.first) || |
271 |
> |
isinf(thermostat.second) || isnan(thermostat.second)) { |
272 |
> |
sprintf( painCave.errMsg, |
273 |
> |
"DumpWriter detected a numerical error writing the thermostat"); |
274 |
> |
painCave.isFatal = 1; |
275 |
> |
simError(); |
276 |
> |
} |
277 |
> |
sprintf(buffer, " Thermostat: %.10g , %.10g\n", thermostat.first, |
278 |
> |
thermostat.second); |
279 |
> |
os << buffer; |
280 |
|
|
281 |
< |
os << eta(0, 0) << "\t" << eta(1, 0) << "\t" << eta(2, 0) << ";\t" |
282 |
< |
<< eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t" |
283 |
< |
<< eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";"; |
284 |
< |
|
285 |
< |
os << "\n"; |
281 |
> |
Mat3x3d eta; |
282 |
> |
eta = s->getBarostat(); |
283 |
> |
|
284 |
> |
for (unsigned int i = 0; i < 3; i++) { |
285 |
> |
for (unsigned int j = 0; j < 3; j++) { |
286 |
> |
if (isinf(eta(i,j)) || isnan(eta(i,j))) { |
287 |
> |
sprintf( painCave.errMsg, |
288 |
> |
"DumpWriter detected a numerical error writing the barostat"); |
289 |
> |
painCave.isFatal = 1; |
290 |
> |
simError(); |
291 |
> |
} |
292 |
> |
} |
293 |
> |
} |
294 |
> |
|
295 |
> |
sprintf(buffer, " Barostat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n", |
296 |
> |
eta(0, 0), eta(1, 0), eta(2, 0), |
297 |
> |
eta(0, 1), eta(1, 1), eta(2, 1), |
298 |
> |
eta(0, 2), eta(1, 2), eta(2, 2)); |
299 |
> |
os << buffer; |
300 |
> |
|
301 |
> |
os << " </FrameData>\n"; |
302 |
|
} |
303 |
|
|
304 |
|
void DumpWriter::writeFrame(std::ostream& os) { |
234 |
– |
const int BUFFERSIZE = 2000; |
235 |
– |
const int MINIBUFFERSIZE = 100; |
305 |
|
|
306 |
< |
char tempBuffer[BUFFERSIZE]; |
307 |
< |
char writeLine[BUFFERSIZE]; |
306 |
> |
#ifdef IS_MPI |
307 |
> |
MPI_Status* istatus; |
308 |
> |
#endif |
309 |
|
|
240 |
– |
Quat4d q; |
241 |
– |
Vector3d ji; |
242 |
– |
Vector3d pos; |
243 |
– |
Vector3d vel; |
244 |
– |
Vector3d frc; |
245 |
– |
Vector3d trq; |
246 |
– |
|
310 |
|
Molecule* mol; |
311 |
< |
StuntDouble* integrableObject; |
311 |
> |
StuntDouble* sd; |
312 |
|
SimInfo::MoleculeIterator mi; |
313 |
|
Molecule::IntegrableObjectIterator ii; |
314 |
< |
|
252 |
< |
int nTotObjects; |
253 |
< |
nTotObjects = info_->getNGlobalIntegrableObjects(); |
314 |
> |
RigidBody::AtomIterator ai; |
315 |
|
|
316 |
|
#ifndef IS_MPI |
317 |
+ |
os << " <Snapshot>\n"; |
318 |
+ |
|
319 |
+ |
writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
320 |
|
|
321 |
+ |
os << " <StuntDoubles>\n"; |
322 |
+ |
for (mol = info_->beginMolecule(mi); mol != NULL; |
323 |
+ |
mol = info_->nextMolecule(mi)) { |
324 |
+ |
|
325 |
+ |
for (sd = mol->beginIntegrableObject(ii); sd != NULL; |
326 |
+ |
sd = mol->nextIntegrableObject(ii)) { |
327 |
+ |
os << prepareDumpLine(sd); |
328 |
+ |
|
329 |
+ |
} |
330 |
+ |
} |
331 |
+ |
os << " </StuntDoubles>\n"; |
332 |
|
|
333 |
< |
os << nTotObjects << "\n"; |
334 |
< |
|
335 |
< |
writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
333 |
> |
if (doSiteData_) { |
334 |
> |
os << " <SiteData>\n"; |
335 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; |
336 |
> |
mol = info_->nextMolecule(mi)) { |
337 |
> |
|
338 |
> |
for (sd = mol->beginIntegrableObject(ii); sd != NULL; |
339 |
> |
sd = mol->nextIntegrableObject(ii)) { |
340 |
|
|
341 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
341 |
> |
int ioIndex = sd->getGlobalIntegrableObjectIndex(); |
342 |
> |
// do one for the IO itself |
343 |
> |
os << prepareSiteLine(sd, ioIndex, 0); |
344 |
|
|
345 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
346 |
< |
integrableObject = mol->nextIntegrableObject(ii)) { |
347 |
< |
|
345 |
> |
if (sd->isRigidBody()) { |
346 |
> |
|
347 |
> |
RigidBody* rb = static_cast<RigidBody*>(sd); |
348 |
> |
int siteIndex = 0; |
349 |
> |
for (Atom* atom = rb->beginAtom(ai); atom != NULL; |
350 |
> |
atom = rb->nextAtom(ai)) { |
351 |
> |
os << prepareSiteLine(atom, ioIndex, siteIndex); |
352 |
> |
siteIndex++; |
353 |
> |
} |
354 |
> |
} |
355 |
> |
} |
356 |
> |
} |
357 |
> |
os << " </SiteData>\n"; |
358 |
> |
} |
359 |
> |
os << " </Snapshot>\n"; |
360 |
|
|
361 |
< |
pos = integrableObject->getPos(); |
362 |
< |
vel = integrableObject->getVel(); |
361 |
> |
os.flush(); |
362 |
> |
#else |
363 |
|
|
364 |
< |
sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
365 |
< |
integrableObject->getType().c_str(), |
366 |
< |
pos[0], pos[1], pos[2], |
274 |
< |
vel[0], vel[1], vel[2]); |
364 |
> |
const int masterNode = 0; |
365 |
> |
int worldRank; |
366 |
> |
int nProc; |
367 |
|
|
368 |
< |
strcpy(writeLine, tempBuffer); |
368 |
> |
MPI_Comm_size( MPI_COMM_WORLD, &nProc); |
369 |
> |
MPI_Comm_rank( MPI_COMM_WORLD, &worldRank); |
370 |
|
|
278 |
– |
if (integrableObject->isDirectional()) { |
279 |
– |
q = integrableObject->getQ(); |
280 |
– |
ji = integrableObject->getJ(); |
371 |
|
|
372 |
< |
sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
373 |
< |
q[0], q[1], q[2], q[3], |
374 |
< |
ji[0], ji[1], ji[2]); |
375 |
< |
strcat(writeLine, tempBuffer); |
376 |
< |
} else { |
377 |
< |
strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); |
288 |
< |
} |
372 |
> |
if (worldRank == masterNode) { |
373 |
> |
os << " <Snapshot>\n"; |
374 |
> |
writeFrameProperties(os, |
375 |
> |
info_->getSnapshotManager()->getCurrentSnapshot()); |
376 |
> |
os << " <StuntDoubles>\n"; |
377 |
> |
} |
378 |
|
|
379 |
< |
if (needForceVector_) { |
380 |
< |
frc = integrableObject->getFrc(); |
381 |
< |
trq = integrableObject->getTrq(); |
382 |
< |
|
383 |
< |
sprintf(tempBuffer, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
384 |
< |
frc[0], frc[1], frc[2], |
385 |
< |
trq[0], trq[1], trq[2]); |
297 |
< |
strcat(writeLine, tempBuffer); |
298 |
< |
} |
299 |
< |
|
300 |
< |
strcat(writeLine, "\n"); |
301 |
< |
os << writeLine; |
302 |
< |
|
379 |
> |
//every node prepares the dump lines for integrable objects belong to itself |
380 |
> |
std::string buffer; |
381 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; |
382 |
> |
mol = info_->nextMolecule(mi)) { |
383 |
> |
for (sd = mol->beginIntegrableObject(ii); sd != NULL; |
384 |
> |
sd = mol->nextIntegrableObject(ii)) { |
385 |
> |
buffer += prepareDumpLine(sd); |
386 |
|
} |
387 |
|
} |
305 |
– |
|
306 |
– |
os.flush(); |
307 |
– |
#else // is_mpi |
308 |
– |
/********************************************************************* |
309 |
– |
* Documentation? You want DOCUMENTATION? |
310 |
– |
* |
311 |
– |
* Why all the potatoes below? |
312 |
– |
* |
313 |
– |
* To make a long story short, the original version of DumpWriter |
314 |
– |
* worked in the most inefficient way possible. Node 0 would |
315 |
– |
* poke each of the node for an individual atom's formatted data |
316 |
– |
* as node 0 worked its way down the global index. This was particularly |
317 |
– |
* inefficient since the method blocked all processors at every atom |
318 |
– |
* (and did it twice!). |
319 |
– |
* |
320 |
– |
* An intermediate version of DumpWriter could be described from Node |
321 |
– |
* zero's perspective as follows: |
322 |
– |
* |
323 |
– |
* 1) Have 100 of your friends stand in a circle. |
324 |
– |
* 2) When you say go, have all of them start tossing potatoes at |
325 |
– |
* you (one at a time). |
326 |
– |
* 3) Catch the potatoes. |
327 |
– |
* |
328 |
– |
* It was an improvement, but MPI has buffers and caches that could |
329 |
– |
* best be described in this analogy as "potato nets", so there's no |
330 |
– |
* need to block the processors atom-by-atom. |
331 |
– |
* |
332 |
– |
* This new and improved DumpWriter works in an even more efficient |
333 |
– |
* way: |
334 |
– |
* |
335 |
– |
* 1) Have 100 of your friend stand in a circle. |
336 |
– |
* 2) When you say go, have them start tossing 5-pound bags of |
337 |
– |
* potatoes at you. |
338 |
– |
* 3) Once you've caught a friend's bag of potatoes, |
339 |
– |
* toss them a spud to let them know they can toss another bag. |
340 |
– |
* |
341 |
– |
* How's THAT for documentation? |
342 |
– |
* |
343 |
– |
*********************************************************************/ |
344 |
– |
const int masterNode = 0; |
345 |
– |
|
346 |
– |
int * potatoes; |
347 |
– |
int myPotato; |
348 |
– |
int nProc; |
349 |
– |
int which_node; |
350 |
– |
RealType atomData[19]; |
351 |
– |
int isDirectional; |
352 |
– |
char MPIatomTypeString[MINIBUFFERSIZE]; |
353 |
– |
int msgLen; // the length of message actually recieved at master nodes |
354 |
– |
int haveError; |
355 |
– |
MPI_Status istatus; |
356 |
– |
int nCurObj; |
388 |
|
|
389 |
< |
// code to find maximum tag value |
390 |
< |
int * tagub; |
391 |
< |
int flag; |
392 |
< |
int MAXTAG; |
393 |
< |
MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); |
389 |
> |
if (worldRank == masterNode) { |
390 |
> |
os << buffer; |
391 |
> |
|
392 |
> |
for (int i = 1; i < nProc; ++i) { |
393 |
> |
// tell processor i to start sending us data: |
394 |
> |
MPI_Bcast(&i, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
395 |
|
|
396 |
< |
if (flag) { |
397 |
< |
MAXTAG = *tagub; |
396 |
> |
// receive the length of the string buffer that was |
397 |
> |
// prepared by processor i: |
398 |
> |
int recvLength; |
399 |
> |
MPI_Recv(&recvLength, 1, MPI_INT, i, MPI_ANY_TAG, MPI_COMM_WORLD, |
400 |
> |
istatus); |
401 |
> |
|
402 |
> |
// create a buffer to receive the data |
403 |
> |
char* recvBuffer = new char[recvLength]; |
404 |
> |
if (recvBuffer == NULL) { |
405 |
> |
} else { |
406 |
> |
// receive the data: |
407 |
> |
MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i, |
408 |
> |
MPI_ANY_TAG, MPI_COMM_WORLD, istatus); |
409 |
> |
// send it to the file: |
410 |
> |
os << recvBuffer; |
411 |
> |
// get rid of the receive buffer: |
412 |
> |
delete [] recvBuffer; |
413 |
> |
} |
414 |
> |
} |
415 |
|
} else { |
416 |
< |
MAXTAG = 32767; |
417 |
< |
} |
416 |
> |
int sendBufferLength = buffer.size() + 1; |
417 |
> |
int myturn = 0; |
418 |
> |
for (int i = 1; i < nProc; ++i){ |
419 |
> |
// wait for the master node to call our number: |
420 |
> |
MPI_Bcast(&myturn, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
421 |
> |
if (myturn == worldRank){ |
422 |
> |
// send the length of our buffer: |
423 |
> |
MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); |
424 |
|
|
425 |
< |
if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file |
425 |
> |
// send our buffer: |
426 |
> |
MPI_Send((void *)buffer.c_str(), sendBufferLength, |
427 |
> |
MPI_CHAR, masterNode, 0, MPI_COMM_WORLD); |
428 |
|
|
429 |
< |
// Node 0 needs a list of the magic potatoes for each processor; |
429 |
> |
} |
430 |
> |
} |
431 |
> |
} |
432 |
> |
|
433 |
> |
if (worldRank == masterNode) { |
434 |
> |
os << " </StuntDoubles>\n"; |
435 |
> |
} |
436 |
|
|
437 |
< |
MPI_Comm_size(MPI_COMM_WORLD, &nProc); |
438 |
< |
potatoes = new int[nProc]; |
437 |
> |
if (doSiteData_) { |
438 |
> |
if (worldRank == masterNode) { |
439 |
> |
os << " <SiteData>\n"; |
440 |
> |
} |
441 |
> |
buffer.clear(); |
442 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; |
443 |
> |
mol = info_->nextMolecule(mi)) { |
444 |
> |
|
445 |
> |
for (sd = mol->beginIntegrableObject(ii); sd != NULL; |
446 |
> |
sd = mol->nextIntegrableObject(ii)) { |
447 |
> |
|
448 |
> |
int ioIndex = sd->getGlobalIntegrableObjectIndex(); |
449 |
> |
// do one for the IO itself |
450 |
> |
buffer += prepareSiteLine(sd, ioIndex, 0); |
451 |
|
|
452 |
< |
//write out the comment lines |
453 |
< |
for(int i = 0; i < nProc; i++) { |
454 |
< |
potatoes[i] = 0; |
452 |
> |
if (sd->isRigidBody()) { |
453 |
> |
|
454 |
> |
RigidBody* rb = static_cast<RigidBody*>(sd); |
455 |
> |
int siteIndex = 0; |
456 |
> |
for (Atom* atom = rb->beginAtom(ai); atom != NULL; |
457 |
> |
atom = rb->nextAtom(ai)) { |
458 |
> |
buffer += prepareSiteLine(atom, ioIndex, siteIndex); |
459 |
> |
siteIndex++; |
460 |
> |
} |
461 |
> |
} |
462 |
> |
} |
463 |
|
} |
464 |
|
|
465 |
+ |
if (worldRank == masterNode) { |
466 |
+ |
os << buffer; |
467 |
+ |
|
468 |
+ |
for (int i = 1; i < nProc; ++i) { |
469 |
+ |
|
470 |
+ |
// tell processor i to start sending us data: |
471 |
+ |
MPI_Bcast(&i, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
472 |
+ |
|
473 |
+ |
// receive the length of the string buffer that was |
474 |
+ |
// prepared by processor i: |
475 |
+ |
int recvLength; |
476 |
+ |
MPI_Recv(&recvLength, 1, MPI_INT, i, MPI_ANY_TAG, MPI_COMM_WORLD, |
477 |
+ |
istatus); |
478 |
+ |
|
479 |
+ |
// create a buffer to receive the data |
480 |
+ |
char* recvBuffer = new char[recvLength]; |
481 |
+ |
if (recvBuffer == NULL) { |
482 |
+ |
} else { |
483 |
+ |
// receive the data: |
484 |
+ |
MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i, |
485 |
+ |
MPI_ANY_TAG, MPI_COMM_WORLD, istatus); |
486 |
+ |
// send it to the file: |
487 |
+ |
os << recvBuffer; |
488 |
+ |
// get rid of the receive buffer: |
489 |
+ |
delete [] recvBuffer; |
490 |
+ |
} |
491 |
+ |
} |
492 |
+ |
} else { |
493 |
+ |
int sendBufferLength = buffer.size() + 1; |
494 |
+ |
int myturn = 0; |
495 |
+ |
for (int i = 1; i < nProc; ++i){ |
496 |
+ |
// wait for the master node to call our number: |
497 |
+ |
MPI_Bcast(&myturn, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
498 |
+ |
if (myturn == worldRank){ |
499 |
+ |
// send the length of our buffer: |
500 |
+ |
MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); |
501 |
+ |
// send our buffer: |
502 |
+ |
MPI_Send((void *)buffer.c_str(), sendBufferLength, |
503 |
+ |
MPI_CHAR, masterNode, 0, MPI_COMM_WORLD); |
504 |
+ |
} |
505 |
+ |
} |
506 |
+ |
} |
507 |
+ |
|
508 |
+ |
if (worldRank == masterNode) { |
509 |
+ |
os << " </SiteData>\n"; |
510 |
+ |
} |
511 |
+ |
} |
512 |
+ |
|
513 |
+ |
if (worldRank == masterNode) { |
514 |
+ |
os << " </Snapshot>\n"; |
515 |
+ |
os.flush(); |
516 |
+ |
} |
517 |
+ |
|
518 |
+ |
#endif // is_mpi |
519 |
+ |
|
520 |
+ |
} |
521 |
|
|
522 |
< |
os << nTotObjects << "\n"; |
523 |
< |
writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
522 |
> |
std::string DumpWriter::prepareDumpLine(StuntDouble* sd) { |
523 |
> |
|
524 |
> |
int index = sd->getGlobalIntegrableObjectIndex(); |
525 |
> |
std::string type("pv"); |
526 |
> |
std::string line; |
527 |
> |
char tempBuffer[4096]; |
528 |
|
|
529 |
< |
for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
529 |
> |
Vector3d pos; |
530 |
> |
Vector3d vel; |
531 |
> |
pos = sd->getPos(); |
532 |
|
|
533 |
< |
// Get the Node number which has this atom; |
533 |
> |
if (isinf(pos[0]) || isnan(pos[0]) || |
534 |
> |
isinf(pos[1]) || isnan(pos[1]) || |
535 |
> |
isinf(pos[2]) || isnan(pos[2]) ) { |
536 |
> |
sprintf( painCave.errMsg, |
537 |
> |
"DumpWriter detected a numerical error writing the position" |
538 |
> |
" for object %d", index); |
539 |
> |
painCave.isFatal = 1; |
540 |
> |
simError(); |
541 |
> |
} |
542 |
|
|
543 |
< |
which_node = info_->getMolToProc(i); |
543 |
> |
vel = sd->getVel(); |
544 |
|
|
545 |
< |
if (which_node != masterNode) { //current molecule is in slave node |
546 |
< |
if (potatoes[which_node] + 1 >= MAXTAG) { |
547 |
< |
// The potato was going to exceed the maximum value, |
548 |
< |
// so wrap this processor potato back to 0: |
545 |
> |
if (isinf(vel[0]) || isnan(vel[0]) || |
546 |
> |
isinf(vel[1]) || isnan(vel[1]) || |
547 |
> |
isinf(vel[2]) || isnan(vel[2]) ) { |
548 |
> |
sprintf( painCave.errMsg, |
549 |
> |
"DumpWriter detected a numerical error writing the velocity" |
550 |
> |
" for object %d", index); |
551 |
> |
painCave.isFatal = 1; |
552 |
> |
simError(); |
553 |
> |
} |
554 |
|
|
555 |
< |
potatoes[which_node] = 0; |
556 |
< |
MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, |
557 |
< |
MPI_COMM_WORLD); |
558 |
< |
} |
555 |
> |
sprintf(tempBuffer, "%18.10g %18.10g %18.10g %13e %13e %13e", |
556 |
> |
pos[0], pos[1], pos[2], |
557 |
> |
vel[0], vel[1], vel[2]); |
558 |
> |
line += tempBuffer; |
559 |
|
|
560 |
< |
myPotato = potatoes[which_node]; |
560 |
> |
if (sd->isDirectional()) { |
561 |
> |
type += "qj"; |
562 |
> |
Quat4d q; |
563 |
> |
Vector3d ji; |
564 |
> |
q = sd->getQ(); |
565 |
|
|
566 |
< |
//recieve the number of integrableObject in current molecule |
567 |
< |
MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato, |
568 |
< |
MPI_COMM_WORLD, &istatus); |
569 |
< |
myPotato++; |
566 |
> |
if (isinf(q[0]) || isnan(q[0]) || |
567 |
> |
isinf(q[1]) || isnan(q[1]) || |
568 |
> |
isinf(q[2]) || isnan(q[2]) || |
569 |
> |
isinf(q[3]) || isnan(q[3]) ) { |
570 |
> |
sprintf( painCave.errMsg, |
571 |
> |
"DumpWriter detected a numerical error writing the quaternion" |
572 |
> |
" for object %d", index); |
573 |
> |
painCave.isFatal = 1; |
574 |
> |
simError(); |
575 |
> |
} |
576 |
|
|
577 |
< |
for(int l = 0; l < nCurObj; l++) { |
410 |
< |
if (potatoes[which_node] + 2 >= MAXTAG) { |
411 |
< |
// The potato was going to exceed the maximum value, |
412 |
< |
// so wrap this processor potato back to 0: |
577 |
> |
ji = sd->getJ(); |
578 |
|
|
579 |
< |
potatoes[which_node] = 0; |
580 |
< |
MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, |
581 |
< |
0, MPI_COMM_WORLD); |
582 |
< |
} |
579 |
> |
if (isinf(ji[0]) || isnan(ji[0]) || |
580 |
> |
isinf(ji[1]) || isnan(ji[1]) || |
581 |
> |
isinf(ji[2]) || isnan(ji[2]) ) { |
582 |
> |
sprintf( painCave.errMsg, |
583 |
> |
"DumpWriter detected a numerical error writing the angular" |
584 |
> |
" momentum for object %d", index); |
585 |
> |
painCave.isFatal = 1; |
586 |
> |
simError(); |
587 |
> |
} |
588 |
|
|
589 |
< |
MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, |
590 |
< |
which_node, myPotato, MPI_COMM_WORLD, |
591 |
< |
&istatus); |
589 |
> |
sprintf(tempBuffer, " %13e %13e %13e %13e %13e %13e %13e", |
590 |
> |
q[0], q[1], q[2], q[3], |
591 |
> |
ji[0], ji[1], ji[2]); |
592 |
> |
line += tempBuffer; |
593 |
> |
} |
594 |
|
|
595 |
< |
myPotato++; |
595 |
> |
if (needForceVector_) { |
596 |
> |
type += "f"; |
597 |
> |
Vector3d frc = sd->getFrc(); |
598 |
> |
if (isinf(frc[0]) || isnan(frc[0]) || |
599 |
> |
isinf(frc[1]) || isnan(frc[1]) || |
600 |
> |
isinf(frc[2]) || isnan(frc[2]) ) { |
601 |
> |
sprintf( painCave.errMsg, |
602 |
> |
"DumpWriter detected a numerical error writing the force" |
603 |
> |
" for object %d", index); |
604 |
> |
painCave.isFatal = 1; |
605 |
> |
simError(); |
606 |
> |
} |
607 |
> |
sprintf(tempBuffer, " %13e %13e %13e", |
608 |
> |
frc[0], frc[1], frc[2]); |
609 |
> |
line += tempBuffer; |
610 |
> |
|
611 |
> |
if (sd->isDirectional()) { |
612 |
> |
type += "t"; |
613 |
> |
Vector3d trq = sd->getTrq(); |
614 |
> |
if (isinf(trq[0]) || isnan(trq[0]) || |
615 |
> |
isinf(trq[1]) || isnan(trq[1]) || |
616 |
> |
isinf(trq[2]) || isnan(trq[2]) ) { |
617 |
> |
sprintf( painCave.errMsg, |
618 |
> |
"DumpWriter detected a numerical error writing the torque" |
619 |
> |
" for object %d", index); |
620 |
> |
painCave.isFatal = 1; |
621 |
> |
simError(); |
622 |
> |
} |
623 |
> |
sprintf(tempBuffer, " %13e %13e %13e", |
624 |
> |
trq[0], trq[1], trq[2]); |
625 |
> |
line += tempBuffer; |
626 |
> |
} |
627 |
> |
} |
628 |
|
|
629 |
< |
MPI_Recv(atomData, 19, MPI_REALTYPE, which_node, myPotato, |
630 |
< |
MPI_COMM_WORLD, &istatus); |
631 |
< |
myPotato++; |
629 |
> |
sprintf(tempBuffer, "%10d %7s %s\n", index, type.c_str(), line.c_str()); |
630 |
> |
return std::string(tempBuffer); |
631 |
> |
} |
632 |
|
|
633 |
< |
MPI_Get_count(&istatus, MPI_REALTYPE, &msgLen); |
633 |
> |
std::string DumpWriter::prepareSiteLine(StuntDouble* sd, int ioIndex, int siteIndex) { |
634 |
> |
int storageLayout = info_->getSnapshotManager()->getStorageLayout(); |
635 |
|
|
636 |
< |
if (msgLen == 13 || msgLen == 19) |
637 |
< |
isDirectional = 1; |
638 |
< |
else |
639 |
< |
isDirectional = 0; |
636 |
> |
std::string id; |
637 |
> |
std::string type; |
638 |
> |
std::string line; |
639 |
> |
char tempBuffer[4096]; |
640 |
|
|
641 |
< |
// If we've survived to here, format the line: |
641 |
> |
if (sd->isRigidBody()) { |
642 |
> |
sprintf(tempBuffer, "%10d ", ioIndex); |
643 |
> |
id = std::string(tempBuffer); |
644 |
> |
} else { |
645 |
> |
sprintf(tempBuffer, "%10d %10d", ioIndex, siteIndex); |
646 |
> |
id = std::string(tempBuffer); |
647 |
> |
} |
648 |
> |
|
649 |
> |
if (needFlucQ_) { |
650 |
> |
if (storageLayout & DataStorage::dslFlucQPosition) { |
651 |
> |
type += "c"; |
652 |
> |
RealType fqPos = sd->getFlucQPos(); |
653 |
> |
if (isinf(fqPos) || isnan(fqPos) ) { |
654 |
> |
sprintf( painCave.errMsg, |
655 |
> |
"DumpWriter detected a numerical error writing the" |
656 |
> |
" fluctuating charge for object %s", id.c_str()); |
657 |
> |
painCave.isFatal = 1; |
658 |
> |
simError(); |
659 |
> |
} |
660 |
> |
sprintf(tempBuffer, " %13e ", fqPos); |
661 |
> |
line += tempBuffer; |
662 |
> |
} |
663 |
|
|
664 |
< |
if (!isDirectional) { |
665 |
< |
sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
666 |
< |
MPIatomTypeString, atomData[0], |
667 |
< |
atomData[1], atomData[2], |
668 |
< |
atomData[3], atomData[4], |
669 |
< |
atomData[5]); |
664 |
> |
if (storageLayout & DataStorage::dslFlucQVelocity) { |
665 |
> |
type += "w"; |
666 |
> |
RealType fqVel = sd->getFlucQVel(); |
667 |
> |
if (isinf(fqVel) || isnan(fqVel) ) { |
668 |
> |
sprintf( painCave.errMsg, |
669 |
> |
"DumpWriter detected a numerical error writing the" |
670 |
> |
" fluctuating charge velocity for object %s", id.c_str()); |
671 |
> |
painCave.isFatal = 1; |
672 |
> |
simError(); |
673 |
> |
} |
674 |
> |
sprintf(tempBuffer, " %13e ", fqVel); |
675 |
> |
line += tempBuffer; |
676 |
> |
} |
677 |
|
|
678 |
< |
strcat(writeLine, |
679 |
< |
"0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); |
680 |
< |
} else { |
681 |
< |
sprintf(writeLine, |
682 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
683 |
< |
MPIatomTypeString, |
684 |
< |
atomData[0], |
685 |
< |
atomData[1], |
686 |
< |
atomData[2], |
687 |
< |
atomData[3], |
688 |
< |
atomData[4], |
689 |
< |
atomData[5], |
690 |
< |
atomData[6], |
691 |
< |
atomData[7], |
692 |
< |
atomData[8], |
693 |
< |
atomData[9], |
694 |
< |
atomData[10], |
695 |
< |
atomData[11], |
696 |
< |
atomData[12]); |
697 |
< |
} |
698 |
< |
|
699 |
< |
if (needForceVector_) { |
700 |
< |
if (!isDirectional) { |
701 |
< |
sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
702 |
< |
atomData[6], |
703 |
< |
atomData[7], |
704 |
< |
atomData[8], |
705 |
< |
atomData[9], |
706 |
< |
atomData[10], |
707 |
< |
atomData[11]); |
708 |
< |
} else { |
709 |
< |
sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
710 |
< |
atomData[13], |
711 |
< |
atomData[14], |
712 |
< |
atomData[15], |
480 |
< |
atomData[16], |
481 |
< |
atomData[17], |
482 |
< |
atomData[18]); |
483 |
< |
} |
484 |
< |
} |
678 |
> |
if (needForceVector_) { |
679 |
> |
if (storageLayout & DataStorage::dslFlucQForce) { |
680 |
> |
type += "g"; |
681 |
> |
RealType fqFrc = sd->getFlucQFrc(); |
682 |
> |
if (isinf(fqFrc) || isnan(fqFrc) ) { |
683 |
> |
sprintf( painCave.errMsg, |
684 |
> |
"DumpWriter detected a numerical error writing the" |
685 |
> |
" fluctuating charge force for object %s", id.c_str()); |
686 |
> |
painCave.isFatal = 1; |
687 |
> |
simError(); |
688 |
> |
} |
689 |
> |
sprintf(tempBuffer, " %13e ", fqFrc); |
690 |
> |
line += tempBuffer; |
691 |
> |
} |
692 |
> |
} |
693 |
> |
} |
694 |
> |
|
695 |
> |
if (needElectricField_) { |
696 |
> |
if (storageLayout & DataStorage::dslElectricField) { |
697 |
> |
type += "e"; |
698 |
> |
Vector3d eField= sd->getElectricField(); |
699 |
> |
if (isinf(eField[0]) || isnan(eField[0]) || |
700 |
> |
isinf(eField[1]) || isnan(eField[1]) || |
701 |
> |
isinf(eField[2]) || isnan(eField[2]) ) { |
702 |
> |
sprintf( painCave.errMsg, |
703 |
> |
"DumpWriter detected a numerical error writing the electric" |
704 |
> |
" field for object %s", id.c_str()); |
705 |
> |
painCave.isFatal = 1; |
706 |
> |
simError(); |
707 |
> |
} |
708 |
> |
sprintf(tempBuffer, " %13e %13e %13e", |
709 |
> |
eField[0], eField[1], eField[2]); |
710 |
> |
line += tempBuffer; |
711 |
> |
} |
712 |
> |
} |
713 |
|
|
486 |
– |
sprintf(writeLine, "\n"); |
487 |
– |
os << writeLine; |
714 |
|
|
715 |
< |
} // end for(int l =0) |
716 |
< |
|
717 |
< |
potatoes[which_node] = myPotato; |
718 |
< |
} else { //master node has current molecule |
719 |
< |
|
720 |
< |
mol = info_->getMoleculeByGlobalIndex(i); |
721 |
< |
|
722 |
< |
if (mol == NULL) { |
723 |
< |
sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank); |
724 |
< |
painCave.isFatal = 1; |
725 |
< |
simError(); |
726 |
< |
} |
727 |
< |
|
502 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
503 |
< |
integrableObject = mol->nextIntegrableObject(ii)) { |
504 |
< |
|
505 |
< |
pos = integrableObject->getPos(); |
506 |
< |
vel = integrableObject->getVel(); |
507 |
< |
|
508 |
< |
atomData[0] = pos[0]; |
509 |
< |
atomData[1] = pos[1]; |
510 |
< |
atomData[2] = pos[2]; |
511 |
< |
|
512 |
< |
atomData[3] = vel[0]; |
513 |
< |
atomData[4] = vel[1]; |
514 |
< |
atomData[5] = vel[2]; |
515 |
< |
|
516 |
< |
isDirectional = 0; |
517 |
< |
|
518 |
< |
if (integrableObject->isDirectional()) { |
519 |
< |
isDirectional = 1; |
520 |
< |
|
521 |
< |
q = integrableObject->getQ(); |
522 |
< |
ji = integrableObject->getJ(); |
523 |
< |
|
524 |
< |
for(int j = 0; j < 6; j++) { |
525 |
< |
atomData[j] = atomData[j]; |
526 |
< |
} |
527 |
< |
|
528 |
< |
atomData[6] = q[0]; |
529 |
< |
atomData[7] = q[1]; |
530 |
< |
atomData[8] = q[2]; |
531 |
< |
atomData[9] = q[3]; |
532 |
< |
|
533 |
< |
atomData[10] = ji[0]; |
534 |
< |
atomData[11] = ji[1]; |
535 |
< |
atomData[12] = ji[2]; |
536 |
< |
} |
537 |
< |
|
538 |
< |
if (needForceVector_) { |
539 |
< |
frc = integrableObject->getFrc(); |
540 |
< |
trq = integrableObject->getTrq(); |
541 |
< |
|
542 |
< |
if (!isDirectional) { |
543 |
< |
atomData[6] = frc[0]; |
544 |
< |
atomData[7] = frc[1]; |
545 |
< |
atomData[8] = frc[2]; |
546 |
< |
atomData[9] = trq[0]; |
547 |
< |
atomData[10] = trq[1]; |
548 |
< |
atomData[11] = trq[2]; |
549 |
< |
} else { |
550 |
< |
atomData[13] = frc[0]; |
551 |
< |
atomData[14] = frc[1]; |
552 |
< |
atomData[15] = frc[2]; |
553 |
< |
atomData[16] = trq[0]; |
554 |
< |
atomData[17] = trq[1]; |
555 |
< |
atomData[18] = trq[2]; |
556 |
< |
} |
557 |
< |
} |
558 |
< |
|
559 |
< |
// If we've survived to here, format the line: |
560 |
< |
|
561 |
< |
if (!isDirectional) { |
562 |
< |
sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
563 |
< |
integrableObject->getType().c_str(), atomData[0], |
564 |
< |
atomData[1], atomData[2], |
565 |
< |
atomData[3], atomData[4], |
566 |
< |
atomData[5]); |
567 |
< |
|
568 |
< |
strcat(writeLine, |
569 |
< |
"0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); |
570 |
< |
} else { |
571 |
< |
sprintf(writeLine, |
572 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
573 |
< |
integrableObject->getType().c_str(), |
574 |
< |
atomData[0], |
575 |
< |
atomData[1], |
576 |
< |
atomData[2], |
577 |
< |
atomData[3], |
578 |
< |
atomData[4], |
579 |
< |
atomData[5], |
580 |
< |
atomData[6], |
581 |
< |
atomData[7], |
582 |
< |
atomData[8], |
583 |
< |
atomData[9], |
584 |
< |
atomData[10], |
585 |
< |
atomData[11], |
586 |
< |
atomData[12]); |
587 |
< |
} |
588 |
< |
|
589 |
< |
if (needForceVector_) { |
590 |
< |
if (!isDirectional) { |
591 |
< |
sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
592 |
< |
atomData[6], |
593 |
< |
atomData[7], |
594 |
< |
atomData[8], |
595 |
< |
atomData[9], |
596 |
< |
atomData[10], |
597 |
< |
atomData[11]); |
598 |
< |
} else { |
599 |
< |
sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
600 |
< |
atomData[13], |
601 |
< |
atomData[14], |
602 |
< |
atomData[15], |
603 |
< |
atomData[16], |
604 |
< |
atomData[17], |
605 |
< |
atomData[18]); |
606 |
< |
} |
607 |
< |
} |
608 |
< |
|
609 |
< |
sprintf(writeLine, "\n"); |
610 |
< |
os << writeLine; |
611 |
< |
|
612 |
< |
} //end for(iter = integrableObject.begin()) |
613 |
< |
} |
614 |
< |
} //end for(i = 0; i < mpiSim->getNmol()) |
615 |
< |
|
616 |
< |
os.flush(); |
617 |
< |
|
618 |
< |
sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
619 |
< |
MPIcheckPoint(); |
620 |
< |
|
621 |
< |
delete [] potatoes; |
622 |
< |
} else { |
623 |
< |
|
624 |
< |
// worldRank != 0, so I'm a remote node. |
625 |
< |
|
626 |
< |
// Set my magic potato to 0: |
627 |
< |
|
628 |
< |
myPotato = 0; |
629 |
< |
|
630 |
< |
for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
631 |
< |
|
632 |
< |
// Am I the node which has this integrableObject? |
633 |
< |
int whichNode = info_->getMolToProc(i); |
634 |
< |
if (whichNode == worldRank) { |
635 |
< |
if (myPotato + 1 >= MAXTAG) { |
636 |
< |
|
637 |
< |
// The potato was going to exceed the maximum value, |
638 |
< |
// so wrap this processor potato back to 0 (and block until |
639 |
< |
// node 0 says we can go: |
640 |
< |
|
641 |
< |
MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
642 |
< |
&istatus); |
643 |
< |
} |
644 |
< |
|
645 |
< |
mol = info_->getMoleculeByGlobalIndex(i); |
646 |
< |
|
647 |
< |
|
648 |
< |
nCurObj = mol->getNIntegrableObjects(); |
649 |
< |
|
650 |
< |
MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD); |
651 |
< |
myPotato++; |
652 |
< |
|
653 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
654 |
< |
integrableObject = mol->nextIntegrableObject(ii)) { |
655 |
< |
|
656 |
< |
if (myPotato + 2 >= MAXTAG) { |
657 |
< |
|
658 |
< |
// The potato was going to exceed the maximum value, |
659 |
< |
// so wrap this processor potato back to 0 (and block until |
660 |
< |
// node 0 says we can go: |
661 |
< |
|
662 |
< |
MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
663 |
< |
&istatus); |
664 |
< |
} |
665 |
< |
|
666 |
< |
pos = integrableObject->getPos(); |
667 |
< |
vel = integrableObject->getVel(); |
668 |
< |
|
669 |
< |
atomData[0] = pos[0]; |
670 |
< |
atomData[1] = pos[1]; |
671 |
< |
atomData[2] = pos[2]; |
672 |
< |
|
673 |
< |
atomData[3] = vel[0]; |
674 |
< |
atomData[4] = vel[1]; |
675 |
< |
atomData[5] = vel[2]; |
676 |
< |
|
677 |
< |
isDirectional = 0; |
678 |
< |
|
679 |
< |
if (integrableObject->isDirectional()) { |
680 |
< |
isDirectional = 1; |
681 |
< |
|
682 |
< |
q = integrableObject->getQ(); |
683 |
< |
ji = integrableObject->getJ(); |
684 |
< |
|
685 |
< |
atomData[6] = q[0]; |
686 |
< |
atomData[7] = q[1]; |
687 |
< |
atomData[8] = q[2]; |
688 |
< |
atomData[9] = q[3]; |
689 |
< |
|
690 |
< |
atomData[10] = ji[0]; |
691 |
< |
atomData[11] = ji[1]; |
692 |
< |
atomData[12] = ji[2]; |
693 |
< |
} |
694 |
< |
|
695 |
< |
if (needForceVector_) { |
696 |
< |
frc = integrableObject->getFrc(); |
697 |
< |
trq = integrableObject->getTrq(); |
698 |
< |
|
699 |
< |
if (!isDirectional) { |
700 |
< |
atomData[6] = frc[0]; |
701 |
< |
atomData[7] = frc[1]; |
702 |
< |
atomData[8] = frc[2]; |
703 |
< |
|
704 |
< |
atomData[9] = trq[0]; |
705 |
< |
atomData[10] = trq[1]; |
706 |
< |
atomData[11] = trq[2]; |
707 |
< |
} else { |
708 |
< |
atomData[13] = frc[0]; |
709 |
< |
atomData[14] = frc[1]; |
710 |
< |
atomData[15] = frc[2]; |
711 |
< |
|
712 |
< |
atomData[16] = trq[0]; |
713 |
< |
atomData[17] = trq[1]; |
714 |
< |
atomData[18] = trq[2]; |
715 |
< |
} |
716 |
< |
} |
717 |
< |
|
718 |
< |
strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE); |
719 |
< |
|
720 |
< |
// null terminate the std::string before sending (just in case): |
721 |
< |
MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0'; |
722 |
< |
|
723 |
< |
MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
724 |
< |
myPotato, MPI_COMM_WORLD); |
725 |
< |
|
726 |
< |
myPotato++; |
727 |
< |
|
728 |
< |
if (isDirectional && needForceVector_) { |
729 |
< |
MPI_Send(atomData, 19, MPI_REALTYPE, 0, myPotato, |
730 |
< |
MPI_COMM_WORLD); |
731 |
< |
} else if (isDirectional) { |
732 |
< |
MPI_Send(atomData, 13, MPI_REALTYPE, 0, myPotato, |
733 |
< |
MPI_COMM_WORLD); |
734 |
< |
} else if (needForceVector_) { |
735 |
< |
MPI_Send(atomData, 12, MPI_REALTYPE, 0, myPotato, |
736 |
< |
MPI_COMM_WORLD); |
737 |
< |
} else { |
738 |
< |
MPI_Send(atomData, 6, MPI_REALTYPE, 0, myPotato, |
739 |
< |
MPI_COMM_WORLD); |
740 |
< |
} |
741 |
< |
|
742 |
< |
myPotato++; |
743 |
< |
} |
744 |
< |
|
745 |
< |
} |
746 |
< |
|
715 |
> |
if (needParticlePot_) { |
716 |
> |
if (storageLayout & DataStorage::dslParticlePot) { |
717 |
> |
type += "u"; |
718 |
> |
RealType particlePot = sd->getParticlePot(); |
719 |
> |
if (isinf(particlePot) || isnan(particlePot)) { |
720 |
> |
sprintf( painCave.errMsg, |
721 |
> |
"DumpWriter detected a numerical error writing the particle " |
722 |
> |
" potential for object %s", id.c_str()); |
723 |
> |
painCave.isFatal = 1; |
724 |
> |
simError(); |
725 |
> |
} |
726 |
> |
sprintf(tempBuffer, " %13e", particlePot); |
727 |
> |
line += tempBuffer; |
728 |
|
} |
748 |
– |
sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
749 |
– |
MPIcheckPoint(); |
729 |
|
} |
730 |
< |
|
731 |
< |
#endif // is_mpi |
732 |
< |
|
730 |
> |
|
731 |
> |
sprintf(tempBuffer, "%s %7s %s\n", id.c_str(), type.c_str(), line.c_str()); |
732 |
> |
return std::string(tempBuffer); |
733 |
|
} |
734 |
|
|
735 |
|
void DumpWriter::writeDump() { |
742 |
|
#ifdef IS_MPI |
743 |
|
if (worldRank == 0) { |
744 |
|
#endif // is_mpi |
745 |
< |
|
745 |
> |
|
746 |
|
eorStream = createOStream(eorFilename_); |
747 |
|
|
748 |
|
#ifdef IS_MPI |
749 |
|
} |
750 |
< |
#endif // is_mpi |
751 |
< |
|
750 |
> |
#endif |
751 |
> |
|
752 |
|
writeFrame(*eorStream); |
753 |
< |
|
753 |
> |
|
754 |
|
#ifdef IS_MPI |
755 |
|
if (worldRank == 0) { |
756 |
< |
#endif // is_mpi |
757 |
< |
delete eorStream; |
758 |
< |
|
756 |
> |
#endif |
757 |
> |
|
758 |
> |
writeClosing(*eorStream); |
759 |
> |
delete eorStream; |
760 |
> |
|
761 |
|
#ifdef IS_MPI |
762 |
|
} |
763 |
|
#endif // is_mpi |
771 |
|
#ifdef IS_MPI |
772 |
|
if (worldRank == 0) { |
773 |
|
#endif // is_mpi |
793 |
– |
|
774 |
|
buffers.push_back(dumpFile_->rdbuf()); |
795 |
– |
|
775 |
|
eorStream = createOStream(eorFilename_); |
797 |
– |
|
776 |
|
buffers.push_back(eorStream->rdbuf()); |
799 |
– |
|
777 |
|
#ifdef IS_MPI |
778 |
|
} |
779 |
|
#endif // is_mpi |
780 |
|
|
781 |
|
TeeBuf tbuf(buffers.begin(), buffers.end()); |
782 |
|
std::ostream os(&tbuf); |
806 |
– |
|
783 |
|
writeFrame(os); |
784 |
|
|
785 |
|
#ifdef IS_MPI |
786 |
|
if (worldRank == 0) { |
787 |
|
#endif // is_mpi |
788 |
< |
delete eorStream; |
789 |
< |
|
788 |
> |
writeClosing(*eorStream); |
789 |
> |
delete eorStream; |
790 |
|
#ifdef IS_MPI |
791 |
|
} |
792 |
< |
#endif // is_mpi |
817 |
< |
|
792 |
> |
#endif // is_mpi |
793 |
|
} |
794 |
|
|
795 |
< |
std::ostream* DumpWriter::createOStream(const std::string& filename) { |
795 |
> |
std::ostream* DumpWriter::createOStream(const std::string& filename) { |
796 |
|
|
797 |
|
std::ostream* newOStream; |
798 |
< |
#ifdef HAVE_LIBZ |
798 |
> |
#ifdef HAVE_ZLIB |
799 |
|
if (needCompression_) { |
800 |
< |
newOStream = new ogzstream(filename.c_str()); |
800 |
> |
newOStream = new ogzstream(filename.c_str()); |
801 |
|
} else { |
802 |
< |
newOStream = new std::ofstream(filename.c_str()); |
802 |
> |
newOStream = new std::ofstream(filename.c_str()); |
803 |
|
} |
804 |
|
#else |
805 |
|
newOStream = new std::ofstream(filename.c_str()); |
806 |
|
#endif |
807 |
+ |
//write out MetaData first |
808 |
+ |
(*newOStream) << "<OpenMD version=2>" << std::endl; |
809 |
+ |
(*newOStream) << " <MetaData>" << std::endl; |
810 |
+ |
(*newOStream) << info_->getRawMetaData(); |
811 |
+ |
(*newOStream) << " </MetaData>" << std::endl; |
812 |
|
return newOStream; |
813 |
< |
} |
813 |
> |
} |
814 |
|
|
815 |
< |
}//end namespace oopse |
815 |
> |
void DumpWriter::writeClosing(std::ostream& os) { |
816 |
> |
|
817 |
> |
os << "</OpenMD>\n"; |
818 |
> |
os.flush(); |
819 |
> |
} |
820 |
> |
|
821 |
> |
}//end namespace OpenMD |