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, 24107 (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 "io/DumpWriter.hpp" |
47 |
|
#include "io/gzstream.hpp" |
48 |
|
#include "io/Globals.hpp" |
49 |
|
|
50 |
+ |
|
51 |
|
#ifdef IS_MPI |
52 |
|
#include <mpi.h> |
53 |
|
#endif //is_mpi |
54 |
|
|
55 |
< |
namespace oopse { |
55 |
> |
using namespace std; |
56 |
> |
namespace OpenMD { |
57 |
|
|
58 |
|
DumpWriter::DumpWriter(SimInfo* info) |
59 |
|
: info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ |
60 |
|
|
61 |
|
Globals* simParams = info->getSimParams(); |
62 |
< |
needCompression_ = simParams->getCompressDumpFile(); |
63 |
< |
needForceVector_ = simParams->getOutputForceVector(); |
62 |
> |
needCompression_ = simParams->getCompressDumpFile(); |
63 |
> |
needForceVector_ = simParams->getOutputForceVector(); |
64 |
> |
needParticlePot_ = simParams->getOutputParticlePotential(); |
65 |
> |
needFlucQ_ = simParams->getOutputFluctuatingCharges(); |
66 |
> |
needElectricField_ = simParams->getOutputElectricField(); |
67 |
> |
|
68 |
|
createDumpFile_ = true; |
69 |
|
#ifdef HAVE_LIBZ |
70 |
|
if (needCompression_) { |
71 |
< |
filename_ += ".gz"; |
72 |
< |
eorFilename_ += ".gz"; |
71 |
> |
filename_ += ".gz"; |
72 |
> |
eorFilename_ += ".gz"; |
73 |
|
} |
74 |
|
#endif |
75 |
|
|
76 |
|
#ifdef IS_MPI |
77 |
|
|
78 |
< |
if (worldRank == 0) { |
78 |
> |
if (worldRank == 0) { |
79 |
|
#endif // is_mpi |
73 |
– |
|
80 |
|
|
81 |
< |
dumpFile_ = createOStream(filename_); |
81 |
> |
dumpFile_ = createOStream(filename_); |
82 |
|
|
83 |
< |
if (!dumpFile_) { |
84 |
< |
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
85 |
< |
filename_.c_str()); |
86 |
< |
painCave.isFatal = 1; |
87 |
< |
simError(); |
88 |
< |
} |
83 |
> |
if (!dumpFile_) { |
84 |
> |
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
85 |
> |
filename_.c_str()); |
86 |
> |
painCave.isFatal = 1; |
87 |
> |
simError(); |
88 |
> |
} |
89 |
|
|
90 |
|
#ifdef IS_MPI |
91 |
|
|
92 |
< |
} |
92 |
> |
} |
93 |
|
|
88 |
– |
sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); |
89 |
– |
MPIcheckPoint(); |
90 |
– |
|
94 |
|
#endif // is_mpi |
95 |
|
|
96 |
< |
} |
96 |
> |
} |
97 |
|
|
98 |
|
|
99 |
|
DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) |
102 |
|
Globals* simParams = info->getSimParams(); |
103 |
|
eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
104 |
|
|
105 |
< |
needCompression_ = simParams->getCompressDumpFile(); |
106 |
< |
needForceVector_ = simParams->getOutputForceVector(); |
105 |
> |
needCompression_ = simParams->getCompressDumpFile(); |
106 |
> |
needForceVector_ = simParams->getOutputForceVector(); |
107 |
> |
needParticlePot_ = simParams->getOutputParticlePotential(); |
108 |
> |
needFlucQ_ = simParams->getOutputFluctuatingCharges(); |
109 |
> |
needElectricField_ = simParams->getOutputElectricField(); |
110 |
> |
|
111 |
|
createDumpFile_ = true; |
112 |
|
#ifdef HAVE_LIBZ |
113 |
|
if (needCompression_) { |
114 |
< |
filename_ += ".gz"; |
115 |
< |
eorFilename_ += ".gz"; |
114 |
> |
filename_ += ".gz"; |
115 |
> |
eorFilename_ += ".gz"; |
116 |
|
} |
117 |
|
#endif |
118 |
|
|
119 |
|
#ifdef IS_MPI |
120 |
|
|
121 |
< |
if (worldRank == 0) { |
121 |
> |
if (worldRank == 0) { |
122 |
|
#endif // is_mpi |
123 |
|
|
124 |
|
|
125 |
< |
dumpFile_ = createOStream(filename_); |
125 |
> |
dumpFile_ = createOStream(filename_); |
126 |
|
|
127 |
< |
if (!dumpFile_) { |
128 |
< |
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
129 |
< |
filename_.c_str()); |
130 |
< |
painCave.isFatal = 1; |
131 |
< |
simError(); |
132 |
< |
} |
127 |
> |
if (!dumpFile_) { |
128 |
> |
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
129 |
> |
filename_.c_str()); |
130 |
> |
painCave.isFatal = 1; |
131 |
> |
simError(); |
132 |
> |
} |
133 |
|
|
134 |
|
#ifdef IS_MPI |
135 |
|
|
136 |
< |
} |
136 |
> |
} |
137 |
|
|
131 |
– |
sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); |
132 |
– |
MPIcheckPoint(); |
133 |
– |
|
138 |
|
#endif // is_mpi |
139 |
|
|
140 |
< |
} |
140 |
> |
} |
141 |
|
|
142 |
|
DumpWriter::DumpWriter(SimInfo* info, const std::string& filename, bool writeDumpFile) |
143 |
< |
: info_(info), filename_(filename){ |
143 |
> |
: info_(info), filename_(filename){ |
144 |
|
|
145 |
|
Globals* simParams = info->getSimParams(); |
146 |
|
eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
147 |
|
|
148 |
< |
needCompression_ = simParams->getCompressDumpFile(); |
149 |
< |
needForceVector_ = simParams->getOutputForceVector(); |
150 |
< |
|
148 |
> |
needCompression_ = simParams->getCompressDumpFile(); |
149 |
> |
needForceVector_ = simParams->getOutputForceVector(); |
150 |
> |
needParticlePot_ = simParams->getOutputParticlePotential(); |
151 |
> |
needFlucQ_ = simParams->getOutputFluctuatingCharges(); |
152 |
> |
needElectricField_ = simParams->getOutputElectricField(); |
153 |
> |
|
154 |
|
#ifdef HAVE_LIBZ |
155 |
|
if (needCompression_) { |
156 |
|
filename_ += ".gz"; |
177 |
|
#ifdef IS_MPI |
178 |
|
|
179 |
|
} |
180 |
+ |
|
181 |
|
|
174 |
– |
sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); |
175 |
– |
MPIcheckPoint(); |
176 |
– |
|
182 |
|
#endif // is_mpi |
183 |
|
|
184 |
|
} |
180 |
– |
|
181 |
– |
|
182 |
– |
|
183 |
– |
|
184 |
– |
|
185 |
|
|
186 |
|
DumpWriter::~DumpWriter() { |
187 |
|
|
190 |
|
if (worldRank == 0) { |
191 |
|
#endif // is_mpi |
192 |
|
if (createDumpFile_){ |
193 |
+ |
writeClosing(*dumpFile_); |
194 |
|
delete dumpFile_; |
195 |
|
} |
196 |
|
#ifdef IS_MPI |
201 |
|
|
202 |
|
} |
203 |
|
|
204 |
< |
void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) { |
204 |
> |
void DumpWriter::writeFrameProperties(std::ostream& os, Snapshot* s) { |
205 |
|
|
206 |
< |
RealType currentTime; |
207 |
< |
Mat3x3d hmat; |
208 |
< |
RealType chi; |
209 |
< |
RealType integralOfChiDt; |
210 |
< |
Mat3x3d eta; |
211 |
< |
|
212 |
< |
currentTime = s->getTime(); |
213 |
< |
hmat = s->getHmat(); |
214 |
< |
chi = s->getChi(); |
215 |
< |
integralOfChiDt = s->getIntegralOfChiDt(); |
216 |
< |
eta = s->getEta(); |
206 |
> |
char buffer[1024]; |
207 |
> |
|
208 |
> |
os << " <FrameData>\n"; |
209 |
> |
|
210 |
> |
RealType currentTime = s->getTime(); |
211 |
> |
|
212 |
> |
if (isinf(currentTime) || isnan(currentTime)) { |
213 |
> |
sprintf( painCave.errMsg, |
214 |
> |
"DumpWriter detected a numerical error writing the time"); |
215 |
> |
painCave.isFatal = 1; |
216 |
> |
simError(); |
217 |
> |
} |
218 |
|
|
219 |
< |
os << currentTime << ";\t" |
220 |
< |
<< hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t" |
219 |
< |
<< hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t" |
220 |
< |
<< hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t"; |
219 |
> |
sprintf(buffer, " Time: %.10g\n", currentTime); |
220 |
> |
os << buffer; |
221 |
|
|
222 |
< |
//write out additional parameters, such as chi and eta |
222 |
> |
Mat3x3d hmat; |
223 |
> |
hmat = s->getHmat(); |
224 |
|
|
225 |
< |
os << chi << "\t" << integralOfChiDt << ";\t"; |
225 |
> |
for (unsigned int i = 0; i < 3; i++) { |
226 |
> |
for (unsigned int j = 0; j < 3; j++) { |
227 |
> |
if (isinf(hmat(i,j)) || isnan(hmat(i,j))) { |
228 |
> |
sprintf( painCave.errMsg, |
229 |
> |
"DumpWriter detected a numerical error writing the box"); |
230 |
> |
painCave.isFatal = 1; |
231 |
> |
simError(); |
232 |
> |
} |
233 |
> |
} |
234 |
> |
} |
235 |
> |
|
236 |
> |
sprintf(buffer, " Hmat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n", |
237 |
> |
hmat(0, 0), hmat(1, 0), hmat(2, 0), |
238 |
> |
hmat(0, 1), hmat(1, 1), hmat(2, 1), |
239 |
> |
hmat(0, 2), hmat(1, 2), hmat(2, 2)); |
240 |
> |
os << buffer; |
241 |
|
|
242 |
< |
os << eta(0, 0) << "\t" << eta(1, 0) << "\t" << eta(2, 0) << ";\t" |
243 |
< |
<< eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t" |
244 |
< |
<< eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";"; |
245 |
< |
|
246 |
< |
os << "\n"; |
242 |
> |
RealType chi = s->getChi(); |
243 |
> |
RealType integralOfChiDt = s->getIntegralOfChiDt(); |
244 |
> |
if (isinf(chi) || isnan(chi) || |
245 |
> |
isinf(integralOfChiDt) || isnan(integralOfChiDt)) { |
246 |
> |
sprintf( painCave.errMsg, |
247 |
> |
"DumpWriter detected a numerical error writing the thermostat"); |
248 |
> |
painCave.isFatal = 1; |
249 |
> |
simError(); |
250 |
> |
} |
251 |
> |
sprintf(buffer, " Thermostat: %.10g , %.10g\n", chi, integralOfChiDt); |
252 |
> |
os << buffer; |
253 |
> |
|
254 |
> |
Mat3x3d eta; |
255 |
> |
eta = s->getEta(); |
256 |
> |
|
257 |
> |
for (unsigned int i = 0; i < 3; i++) { |
258 |
> |
for (unsigned int j = 0; j < 3; j++) { |
259 |
> |
if (isinf(eta(i,j)) || isnan(eta(i,j))) { |
260 |
> |
sprintf( painCave.errMsg, |
261 |
> |
"DumpWriter detected a numerical error writing the barostat"); |
262 |
> |
painCave.isFatal = 1; |
263 |
> |
simError(); |
264 |
> |
} |
265 |
> |
} |
266 |
> |
} |
267 |
> |
|
268 |
> |
sprintf(buffer, " Barostat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n", |
269 |
> |
eta(0, 0), eta(1, 0), eta(2, 0), |
270 |
> |
eta(0, 1), eta(1, 1), eta(2, 1), |
271 |
> |
eta(0, 2), eta(1, 2), eta(2, 2)); |
272 |
> |
os << buffer; |
273 |
> |
|
274 |
> |
os << " </FrameData>\n"; |
275 |
|
} |
276 |
|
|
277 |
|
void DumpWriter::writeFrame(std::ostream& os) { |
234 |
– |
const int BUFFERSIZE = 2000; |
235 |
– |
const int MINIBUFFERSIZE = 100; |
278 |
|
|
279 |
< |
char tempBuffer[BUFFERSIZE]; |
280 |
< |
char writeLine[BUFFERSIZE]; |
279 |
> |
#ifdef IS_MPI |
280 |
> |
MPI_Status istatus; |
281 |
> |
#endif |
282 |
|
|
240 |
– |
Quat4d q; |
241 |
– |
Vector3d ji; |
242 |
– |
Vector3d pos; |
243 |
– |
Vector3d vel; |
244 |
– |
Vector3d frc; |
245 |
– |
Vector3d trq; |
246 |
– |
|
283 |
|
Molecule* mol; |
284 |
|
StuntDouble* integrableObject; |
285 |
|
SimInfo::MoleculeIterator mi; |
286 |
|
Molecule::IntegrableObjectIterator ii; |
251 |
– |
|
252 |
– |
int nTotObjects; |
253 |
– |
nTotObjects = info_->getNGlobalIntegrableObjects(); |
287 |
|
|
288 |
|
#ifndef IS_MPI |
289 |
+ |
os << " <Snapshot>\n"; |
290 |
+ |
|
291 |
+ |
writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
292 |
|
|
293 |
+ |
os << " <StuntDoubles>\n"; |
294 |
+ |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
295 |
|
|
296 |
< |
os << nTotObjects << "\n"; |
297 |
< |
|
298 |
< |
writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
296 |
> |
|
297 |
> |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
298 |
> |
integrableObject = mol->nextIntegrableObject(ii)) { |
299 |
> |
os << prepareDumpLine(integrableObject); |
300 |
> |
|
301 |
> |
} |
302 |
> |
} |
303 |
> |
os << " </StuntDoubles>\n"; |
304 |
> |
|
305 |
> |
os << " </Snapshot>\n"; |
306 |
|
|
307 |
+ |
os.flush(); |
308 |
+ |
#else |
309 |
+ |
//every node prepares the dump lines for integrable objects belong to itself |
310 |
+ |
std::string buffer; |
311 |
|
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
312 |
|
|
264 |
– |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
265 |
– |
integrableObject = mol->nextIntegrableObject(ii)) { |
266 |
– |
|
313 |
|
|
314 |
< |
pos = integrableObject->getPos(); |
315 |
< |
vel = integrableObject->getVel(); |
316 |
< |
|
317 |
< |
sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
272 |
< |
integrableObject->getType().c_str(), |
273 |
< |
pos[0], pos[1], pos[2], |
274 |
< |
vel[0], vel[1], vel[2]); |
275 |
< |
|
276 |
< |
strcpy(writeLine, tempBuffer); |
277 |
< |
|
278 |
< |
if (integrableObject->isDirectional()) { |
279 |
< |
q = integrableObject->getQ(); |
280 |
< |
ji = integrableObject->getJ(); |
281 |
< |
|
282 |
< |
sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
283 |
< |
q[0], q[1], q[2], q[3], |
284 |
< |
ji[0], ji[1], ji[2]); |
285 |
< |
strcat(writeLine, tempBuffer); |
286 |
< |
} else { |
287 |
< |
strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); |
288 |
< |
} |
289 |
< |
|
290 |
< |
if (needForceVector_) { |
291 |
< |
frc = integrableObject->getFrc(); |
292 |
< |
trq = integrableObject->getTrq(); |
293 |
< |
|
294 |
< |
sprintf(tempBuffer, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
295 |
< |
frc[0], frc[1], frc[2], |
296 |
< |
trq[0], trq[1], trq[2]); |
297 |
< |
strcat(writeLine, tempBuffer); |
298 |
< |
} |
299 |
< |
|
300 |
< |
strcat(writeLine, "\n"); |
301 |
< |
os << writeLine; |
302 |
< |
|
303 |
< |
} |
314 |
> |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
315 |
> |
integrableObject = mol->nextIntegrableObject(ii)) { |
316 |
> |
buffer += prepareDumpLine(integrableObject); |
317 |
> |
} |
318 |
|
} |
319 |
< |
|
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 |
< |
*********************************************************************/ |
319 |
> |
|
320 |
|
const int masterNode = 0; |
345 |
– |
|
346 |
– |
int * potatoes; |
347 |
– |
int myPotato; |
321 |
|
int nProc; |
322 |
< |
int which_node; |
323 |
< |
RealType atomData[19]; |
324 |
< |
int isDirectional; |
325 |
< |
char MPIatomTypeString[MINIBUFFERSIZE]; |
326 |
< |
int msgLen; // the length of message actually recieved at master nodes |
327 |
< |
int haveError; |
328 |
< |
MPI_Status istatus; |
356 |
< |
int nCurObj; |
357 |
< |
|
358 |
< |
// code to find maximum tag value |
359 |
< |
int * tagub; |
360 |
< |
int flag; |
361 |
< |
int MAXTAG; |
362 |
< |
MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); |
322 |
> |
MPI_Comm_size(MPI_COMM_WORLD, &nProc); |
323 |
> |
if (worldRank == masterNode) { |
324 |
> |
os << " <Snapshot>\n"; |
325 |
> |
writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
326 |
> |
os << " <StuntDoubles>\n"; |
327 |
> |
|
328 |
> |
os << buffer; |
329 |
|
|
330 |
< |
if (flag) { |
365 |
< |
MAXTAG = *tagub; |
366 |
< |
} else { |
367 |
< |
MAXTAG = 32767; |
368 |
< |
} |
330 |
> |
for (int i = 1; i < nProc; ++i) { |
331 |
|
|
332 |
< |
if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file |
332 |
> |
// receive the length of the string buffer that was |
333 |
> |
// prepared by processor i |
334 |
|
|
335 |
< |
// Node 0 needs a list of the magic potatoes for each processor; |
336 |
< |
|
337 |
< |
MPI_Comm_size(MPI_COMM_WORLD, &nProc); |
338 |
< |
potatoes = new int[nProc]; |
339 |
< |
|
340 |
< |
//write out the comment lines |
341 |
< |
for(int i = 0; i < nProc; i++) { |
342 |
< |
potatoes[i] = 0; |
335 |
> |
MPI_Bcast(&i, 1, MPI_INT,masterNode,MPI_COMM_WORLD); |
336 |
> |
int recvLength; |
337 |
> |
MPI_Recv(&recvLength, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &istatus); |
338 |
> |
char* recvBuffer = new char[recvLength]; |
339 |
> |
if (recvBuffer == NULL) { |
340 |
> |
} else { |
341 |
> |
MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i, 0, MPI_COMM_WORLD, &istatus); |
342 |
> |
os << recvBuffer; |
343 |
> |
delete [] recvBuffer; |
344 |
> |
} |
345 |
> |
} |
346 |
> |
os << " </StuntDoubles>\n"; |
347 |
> |
|
348 |
> |
os << " </Snapshot>\n"; |
349 |
> |
os.flush(); |
350 |
> |
} else { |
351 |
> |
int sendBufferLength = buffer.size() + 1; |
352 |
> |
int myturn = 0; |
353 |
> |
for (int i = 1; i < nProc; ++i){ |
354 |
> |
MPI_Bcast(&myturn,1, MPI_INT,masterNode,MPI_COMM_WORLD); |
355 |
> |
if (myturn == worldRank){ |
356 |
> |
MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); |
357 |
> |
MPI_Send((void *)buffer.c_str(), sendBufferLength, MPI_CHAR, masterNode, 0, MPI_COMM_WORLD); |
358 |
> |
} |
359 |
|
} |
360 |
+ |
} |
361 |
|
|
362 |
+ |
#endif // is_mpi |
363 |
|
|
364 |
< |
os << nTotObjects << "\n"; |
384 |
< |
writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
364 |
> |
} |
365 |
|
|
366 |
< |
for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
366 |
> |
std::string DumpWriter::prepareDumpLine(StuntDouble* integrableObject) { |
367 |
> |
|
368 |
> |
int index = integrableObject->getGlobalIntegrableObjectIndex(); |
369 |
> |
std::string type("pv"); |
370 |
> |
std::string line; |
371 |
> |
char tempBuffer[4096]; |
372 |
|
|
373 |
< |
// Get the Node number which has this atom; |
373 |
> |
Vector3d pos; |
374 |
> |
Vector3d vel; |
375 |
> |
pos = integrableObject->getPos(); |
376 |
|
|
377 |
< |
which_node = info_->getMolToProc(i); |
377 |
> |
if (isinf(pos[0]) || isnan(pos[0]) || |
378 |
> |
isinf(pos[1]) || isnan(pos[1]) || |
379 |
> |
isinf(pos[2]) || isnan(pos[2]) ) { |
380 |
> |
sprintf( painCave.errMsg, |
381 |
> |
"DumpWriter detected a numerical error writing the position" |
382 |
> |
" for object %d", index); |
383 |
> |
painCave.isFatal = 1; |
384 |
> |
simError(); |
385 |
> |
} |
386 |
|
|
387 |
< |
if (which_node != masterNode) { //current molecule is in slave node |
393 |
< |
if (potatoes[which_node] + 1 >= MAXTAG) { |
394 |
< |
// The potato was going to exceed the maximum value, |
395 |
< |
// so wrap this processor potato back to 0: |
387 |
> |
vel = integrableObject->getVel(); |
388 |
|
|
389 |
< |
potatoes[which_node] = 0; |
390 |
< |
MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, |
391 |
< |
MPI_COMM_WORLD); |
392 |
< |
} |
389 |
> |
if (isinf(vel[0]) || isnan(vel[0]) || |
390 |
> |
isinf(vel[1]) || isnan(vel[1]) || |
391 |
> |
isinf(vel[2]) || isnan(vel[2]) ) { |
392 |
> |
sprintf( painCave.errMsg, |
393 |
> |
"DumpWriter detected a numerical error writing the velocity" |
394 |
> |
" for object %d", index); |
395 |
> |
painCave.isFatal = 1; |
396 |
> |
simError(); |
397 |
> |
} |
398 |
|
|
399 |
< |
myPotato = potatoes[which_node]; |
399 |
> |
sprintf(tempBuffer, "%18.10g %18.10g %18.10g %13e %13e %13e", |
400 |
> |
pos[0], pos[1], pos[2], |
401 |
> |
vel[0], vel[1], vel[2]); |
402 |
> |
line += tempBuffer; |
403 |
|
|
404 |
< |
//recieve the number of integrableObject in current molecule |
405 |
< |
MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato, |
406 |
< |
MPI_COMM_WORLD, &istatus); |
407 |
< |
myPotato++; |
404 |
> |
if (integrableObject->isDirectional()) { |
405 |
> |
type += "qj"; |
406 |
> |
Quat4d q; |
407 |
> |
Vector3d ji; |
408 |
> |
q = integrableObject->getQ(); |
409 |
|
|
410 |
< |
for(int l = 0; l < nCurObj; l++) { |
411 |
< |
if (potatoes[which_node] + 2 >= MAXTAG) { |
412 |
< |
// The potato was going to exceed the maximum value, |
413 |
< |
// so wrap this processor potato back to 0: |
410 |
> |
if (isinf(q[0]) || isnan(q[0]) || |
411 |
> |
isinf(q[1]) || isnan(q[1]) || |
412 |
> |
isinf(q[2]) || isnan(q[2]) || |
413 |
> |
isinf(q[3]) || isnan(q[3]) ) { |
414 |
> |
sprintf( painCave.errMsg, |
415 |
> |
"DumpWriter detected a numerical error writing the quaternion" |
416 |
> |
" for object %d", index); |
417 |
> |
painCave.isFatal = 1; |
418 |
> |
simError(); |
419 |
> |
} |
420 |
|
|
421 |
< |
potatoes[which_node] = 0; |
415 |
< |
MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, |
416 |
< |
0, MPI_COMM_WORLD); |
417 |
< |
} |
421 |
> |
ji = integrableObject->getJ(); |
422 |
|
|
423 |
< |
MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, |
424 |
< |
which_node, myPotato, MPI_COMM_WORLD, |
425 |
< |
&istatus); |
426 |
< |
|
427 |
< |
myPotato++; |
423 |
> |
if (isinf(ji[0]) || isnan(ji[0]) || |
424 |
> |
isinf(ji[1]) || isnan(ji[1]) || |
425 |
> |
isinf(ji[2]) || isnan(ji[2]) ) { |
426 |
> |
sprintf( painCave.errMsg, |
427 |
> |
"DumpWriter detected a numerical error writing the angular" |
428 |
> |
" momentum for object %d", index); |
429 |
> |
painCave.isFatal = 1; |
430 |
> |
simError(); |
431 |
> |
} |
432 |
|
|
433 |
< |
MPI_Recv(atomData, 19, MPI_REALTYPE, which_node, myPotato, |
434 |
< |
MPI_COMM_WORLD, &istatus); |
435 |
< |
myPotato++; |
433 |
> |
sprintf(tempBuffer, " %13e %13e %13e %13e %13e %13e %13e", |
434 |
> |
q[0], q[1], q[2], q[3], |
435 |
> |
ji[0], ji[1], ji[2]); |
436 |
> |
line += tempBuffer; |
437 |
> |
} |
438 |
|
|
439 |
< |
MPI_Get_count(&istatus, MPI_REALTYPE, &msgLen); |
439 |
> |
if (needForceVector_) { |
440 |
> |
type += "f"; |
441 |
> |
Vector3d frc = integrableObject->getFrc(); |
442 |
> |
if (isinf(frc[0]) || isnan(frc[0]) || |
443 |
> |
isinf(frc[1]) || isnan(frc[1]) || |
444 |
> |
isinf(frc[2]) || isnan(frc[2]) ) { |
445 |
> |
sprintf( painCave.errMsg, |
446 |
> |
"DumpWriter detected a numerical error writing the force" |
447 |
> |
" for object %d", index); |
448 |
> |
painCave.isFatal = 1; |
449 |
> |
simError(); |
450 |
> |
} |
451 |
> |
sprintf(tempBuffer, " %13e %13e %13e", |
452 |
> |
frc[0], frc[1], frc[2]); |
453 |
> |
line += tempBuffer; |
454 |
> |
|
455 |
> |
if (integrableObject->isDirectional()) { |
456 |
> |
type += "t"; |
457 |
> |
Vector3d trq = integrableObject->getTrq(); |
458 |
> |
if (isinf(trq[0]) || isnan(trq[0]) || |
459 |
> |
isinf(trq[1]) || isnan(trq[1]) || |
460 |
> |
isinf(trq[2]) || isnan(trq[2]) ) { |
461 |
> |
sprintf( painCave.errMsg, |
462 |
> |
"DumpWriter detected a numerical error writing the torque" |
463 |
> |
" for object %d", index); |
464 |
> |
painCave.isFatal = 1; |
465 |
> |
simError(); |
466 |
> |
} |
467 |
> |
sprintf(tempBuffer, " %13e %13e %13e", |
468 |
> |
trq[0], trq[1], trq[2]); |
469 |
> |
line += tempBuffer; |
470 |
> |
} |
471 |
> |
} |
472 |
|
|
473 |
< |
if (msgLen == 13 || msgLen == 19) |
474 |
< |
isDirectional = 1; |
475 |
< |
else |
476 |
< |
isDirectional = 0; |
473 |
> |
if (needParticlePot_) { |
474 |
> |
type += "u"; |
475 |
> |
RealType particlePot = integrableObject->getParticlePot(); |
476 |
> |
if (isinf(particlePot) || isnan(particlePot)) { |
477 |
> |
sprintf( painCave.errMsg, |
478 |
> |
"DumpWriter detected a numerical error writing the particle " |
479 |
> |
" potential for object %d", index); |
480 |
> |
painCave.isFatal = 1; |
481 |
> |
simError(); |
482 |
> |
} |
483 |
> |
sprintf(tempBuffer, " %13e", particlePot); |
484 |
> |
line += tempBuffer; |
485 |
> |
} |
486 |
> |
|
487 |
> |
if (needFlucQ_) { |
488 |
> |
type += "cw"; |
489 |
> |
RealType fqPos = integrableObject->getFlucQPos(); |
490 |
> |
if (isinf(fqPos) || isnan(fqPos) ) { |
491 |
> |
sprintf( painCave.errMsg, |
492 |
> |
"DumpWriter detected a numerical error writing the" |
493 |
> |
" fluctuating charge for object %d", index); |
494 |
> |
painCave.isFatal = 1; |
495 |
> |
simError(); |
496 |
> |
} |
497 |
> |
sprintf(tempBuffer, " %13e ", fqPos); |
498 |
> |
line += tempBuffer; |
499 |
> |
|
500 |
> |
RealType fqVel = integrableObject->getFlucQVel(); |
501 |
> |
if (isinf(fqVel) || isnan(fqVel) ) { |
502 |
> |
sprintf( painCave.errMsg, |
503 |
> |
"DumpWriter detected a numerical error writing the" |
504 |
> |
" fluctuating charge velocity for object %d", index); |
505 |
> |
painCave.isFatal = 1; |
506 |
> |
simError(); |
507 |
> |
} |
508 |
> |
sprintf(tempBuffer, " %13e ", fqVel); |
509 |
> |
line += tempBuffer; |
510 |
|
|
511 |
< |
// If we've survived to here, format the line: |
512 |
< |
|
513 |
< |
if (!isDirectional) { |
514 |
< |
sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
515 |
< |
MPIatomTypeString, atomData[0], |
516 |
< |
atomData[1], atomData[2], |
517 |
< |
atomData[3], atomData[4], |
518 |
< |
atomData[5]); |
519 |
< |
|
520 |
< |
strcat(writeLine, |
521 |
< |
"0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); |
522 |
< |
} else { |
523 |
< |
sprintf(writeLine, |
524 |
< |
"%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", |
450 |
< |
MPIatomTypeString, |
451 |
< |
atomData[0], |
452 |
< |
atomData[1], |
453 |
< |
atomData[2], |
454 |
< |
atomData[3], |
455 |
< |
atomData[4], |
456 |
< |
atomData[5], |
457 |
< |
atomData[6], |
458 |
< |
atomData[7], |
459 |
< |
atomData[8], |
460 |
< |
atomData[9], |
461 |
< |
atomData[10], |
462 |
< |
atomData[11], |
463 |
< |
atomData[12]); |
464 |
< |
} |
465 |
< |
|
466 |
< |
if (needForceVector_) { |
467 |
< |
if (!isDirectional) { |
468 |
< |
sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
469 |
< |
atomData[6], |
470 |
< |
atomData[7], |
471 |
< |
atomData[8], |
472 |
< |
atomData[9], |
473 |
< |
atomData[10], |
474 |
< |
atomData[11]); |
475 |
< |
} else { |
476 |
< |
sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
477 |
< |
atomData[13], |
478 |
< |
atomData[14], |
479 |
< |
atomData[15], |
480 |
< |
atomData[16], |
481 |
< |
atomData[17], |
482 |
< |
atomData[18]); |
483 |
< |
} |
484 |
< |
} |
485 |
< |
|
486 |
< |
os << writeLine << "\n"; |
487 |
< |
|
488 |
< |
} // end for(int l =0) |
489 |
< |
|
490 |
< |
potatoes[which_node] = myPotato; |
491 |
< |
} else { //master node has current molecule |
492 |
< |
|
493 |
< |
mol = info_->getMoleculeByGlobalIndex(i); |
494 |
< |
|
495 |
< |
if (mol == NULL) { |
496 |
< |
sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank); |
497 |
< |
painCave.isFatal = 1; |
498 |
< |
simError(); |
499 |
< |
} |
500 |
< |
|
501 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
502 |
< |
integrableObject = mol->nextIntegrableObject(ii)) { |
503 |
< |
|
504 |
< |
pos = integrableObject->getPos(); |
505 |
< |
vel = integrableObject->getVel(); |
506 |
< |
|
507 |
< |
atomData[0] = pos[0]; |
508 |
< |
atomData[1] = pos[1]; |
509 |
< |
atomData[2] = pos[2]; |
510 |
< |
|
511 |
< |
atomData[3] = vel[0]; |
512 |
< |
atomData[4] = vel[1]; |
513 |
< |
atomData[5] = vel[2]; |
514 |
< |
|
515 |
< |
isDirectional = 0; |
516 |
< |
|
517 |
< |
if (integrableObject->isDirectional()) { |
518 |
< |
isDirectional = 1; |
519 |
< |
|
520 |
< |
q = integrableObject->getQ(); |
521 |
< |
ji = integrableObject->getJ(); |
522 |
< |
|
523 |
< |
for(int j = 0; j < 6; j++) { |
524 |
< |
atomData[j] = atomData[j]; |
525 |
< |
} |
526 |
< |
|
527 |
< |
atomData[6] = q[0]; |
528 |
< |
atomData[7] = q[1]; |
529 |
< |
atomData[8] = q[2]; |
530 |
< |
atomData[9] = q[3]; |
531 |
< |
|
532 |
< |
atomData[10] = ji[0]; |
533 |
< |
atomData[11] = ji[1]; |
534 |
< |
atomData[12] = ji[2]; |
535 |
< |
} |
536 |
< |
|
537 |
< |
if (needForceVector_) { |
538 |
< |
frc = integrableObject->getFrc(); |
539 |
< |
trq = integrableObject->getTrq(); |
540 |
< |
|
541 |
< |
if (!isDirectional) { |
542 |
< |
atomData[6] = frc[0]; |
543 |
< |
atomData[7] = frc[1]; |
544 |
< |
atomData[8] = frc[2]; |
545 |
< |
atomData[9] = trq[0]; |
546 |
< |
atomData[10] = trq[1]; |
547 |
< |
atomData[11] = trq[2]; |
548 |
< |
} else { |
549 |
< |
atomData[13] = frc[0]; |
550 |
< |
atomData[14] = frc[1]; |
551 |
< |
atomData[15] = frc[2]; |
552 |
< |
atomData[16] = trq[0]; |
553 |
< |
atomData[17] = trq[1]; |
554 |
< |
atomData[18] = trq[2]; |
555 |
< |
} |
556 |
< |
} |
557 |
< |
|
558 |
< |
// If we've survived to here, format the line: |
559 |
< |
|
560 |
< |
if (!isDirectional) { |
561 |
< |
sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
562 |
< |
integrableObject->getType().c_str(), atomData[0], |
563 |
< |
atomData[1], atomData[2], |
564 |
< |
atomData[3], atomData[4], |
565 |
< |
atomData[5]); |
511 |
> |
if (needForceVector_) { |
512 |
> |
type += "g"; |
513 |
> |
RealType fqFrc = integrableObject->getFlucQFrc(); |
514 |
> |
if (isinf(fqFrc) || isnan(fqFrc) ) { |
515 |
> |
sprintf( painCave.errMsg, |
516 |
> |
"DumpWriter detected a numerical error writing the" |
517 |
> |
" fluctuating charge force for object %d", index); |
518 |
> |
painCave.isFatal = 1; |
519 |
> |
simError(); |
520 |
> |
} |
521 |
> |
sprintf(tempBuffer, " %13e ", fqFrc); |
522 |
> |
line += tempBuffer; |
523 |
> |
} |
524 |
> |
} |
525 |
|
|
526 |
< |
strcat(writeLine, |
527 |
< |
"0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); |
528 |
< |
} else { |
529 |
< |
sprintf(writeLine, |
530 |
< |
"%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", |
531 |
< |
integrableObject->getType().c_str(), |
532 |
< |
atomData[0], |
533 |
< |
atomData[1], |
534 |
< |
atomData[2], |
535 |
< |
atomData[3], |
536 |
< |
atomData[4], |
578 |
< |
atomData[5], |
579 |
< |
atomData[6], |
580 |
< |
atomData[7], |
581 |
< |
atomData[8], |
582 |
< |
atomData[9], |
583 |
< |
atomData[10], |
584 |
< |
atomData[11], |
585 |
< |
atomData[12]); |
586 |
< |
} |
587 |
< |
|
588 |
< |
if (needForceVector_) { |
589 |
< |
if (!isDirectional) { |
590 |
< |
sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
591 |
< |
atomData[6], |
592 |
< |
atomData[7], |
593 |
< |
atomData[8], |
594 |
< |
atomData[9], |
595 |
< |
atomData[10], |
596 |
< |
atomData[11]); |
597 |
< |
} else { |
598 |
< |
sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", |
599 |
< |
atomData[13], |
600 |
< |
atomData[14], |
601 |
< |
atomData[15], |
602 |
< |
atomData[16], |
603 |
< |
atomData[17], |
604 |
< |
atomData[18]); |
605 |
< |
} |
606 |
< |
} |
607 |
< |
|
608 |
< |
os << writeLine << "\n"; |
609 |
< |
|
610 |
< |
} //end for(iter = integrableObject.begin()) |
611 |
< |
} |
612 |
< |
} //end for(i = 0; i < mpiSim->getNmol()) |
613 |
< |
|
614 |
< |
os.flush(); |
615 |
< |
|
616 |
< |
sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
617 |
< |
MPIcheckPoint(); |
618 |
< |
|
619 |
< |
delete [] potatoes; |
620 |
< |
} else { |
621 |
< |
|
622 |
< |
// worldRank != 0, so I'm a remote node. |
623 |
< |
|
624 |
< |
// Set my magic potato to 0: |
625 |
< |
|
626 |
< |
myPotato = 0; |
627 |
< |
|
628 |
< |
for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
629 |
< |
|
630 |
< |
// Am I the node which has this integrableObject? |
631 |
< |
int whichNode = info_->getMolToProc(i); |
632 |
< |
if (whichNode == worldRank) { |
633 |
< |
if (myPotato + 1 >= MAXTAG) { |
634 |
< |
|
635 |
< |
// The potato was going to exceed the maximum value, |
636 |
< |
// so wrap this processor potato back to 0 (and block until |
637 |
< |
// node 0 says we can go: |
638 |
< |
|
639 |
< |
MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
640 |
< |
&istatus); |
641 |
< |
} |
642 |
< |
|
643 |
< |
mol = info_->getMoleculeByGlobalIndex(i); |
644 |
< |
|
645 |
< |
|
646 |
< |
nCurObj = mol->getNIntegrableObjects(); |
647 |
< |
|
648 |
< |
MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD); |
649 |
< |
myPotato++; |
650 |
< |
|
651 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
652 |
< |
integrableObject = mol->nextIntegrableObject(ii)) { |
653 |
< |
|
654 |
< |
if (myPotato + 2 >= MAXTAG) { |
655 |
< |
|
656 |
< |
// The potato was going to exceed the maximum value, |
657 |
< |
// so wrap this processor potato back to 0 (and block until |
658 |
< |
// node 0 says we can go: |
659 |
< |
|
660 |
< |
MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
661 |
< |
&istatus); |
662 |
< |
} |
663 |
< |
|
664 |
< |
pos = integrableObject->getPos(); |
665 |
< |
vel = integrableObject->getVel(); |
666 |
< |
|
667 |
< |
atomData[0] = pos[0]; |
668 |
< |
atomData[1] = pos[1]; |
669 |
< |
atomData[2] = pos[2]; |
670 |
< |
|
671 |
< |
atomData[3] = vel[0]; |
672 |
< |
atomData[4] = vel[1]; |
673 |
< |
atomData[5] = vel[2]; |
674 |
< |
|
675 |
< |
isDirectional = 0; |
676 |
< |
|
677 |
< |
if (integrableObject->isDirectional()) { |
678 |
< |
isDirectional = 1; |
679 |
< |
|
680 |
< |
q = integrableObject->getQ(); |
681 |
< |
ji = integrableObject->getJ(); |
682 |
< |
|
683 |
< |
atomData[6] = q[0]; |
684 |
< |
atomData[7] = q[1]; |
685 |
< |
atomData[8] = q[2]; |
686 |
< |
atomData[9] = q[3]; |
687 |
< |
|
688 |
< |
atomData[10] = ji[0]; |
689 |
< |
atomData[11] = ji[1]; |
690 |
< |
atomData[12] = ji[2]; |
691 |
< |
} |
692 |
< |
|
693 |
< |
if (needForceVector_) { |
694 |
< |
frc = integrableObject->getFrc(); |
695 |
< |
trq = integrableObject->getTrq(); |
696 |
< |
|
697 |
< |
if (!isDirectional) { |
698 |
< |
atomData[6] = frc[0]; |
699 |
< |
atomData[7] = frc[1]; |
700 |
< |
atomData[8] = frc[2]; |
701 |
< |
|
702 |
< |
atomData[9] = trq[0]; |
703 |
< |
atomData[10] = trq[1]; |
704 |
< |
atomData[11] = trq[2]; |
705 |
< |
} else { |
706 |
< |
atomData[13] = frc[0]; |
707 |
< |
atomData[14] = frc[1]; |
708 |
< |
atomData[15] = frc[2]; |
709 |
< |
|
710 |
< |
atomData[16] = trq[0]; |
711 |
< |
atomData[17] = trq[1]; |
712 |
< |
atomData[18] = trq[2]; |
713 |
< |
} |
714 |
< |
} |
715 |
< |
|
716 |
< |
strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE); |
717 |
< |
|
718 |
< |
// null terminate the std::string before sending (just in case): |
719 |
< |
MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0'; |
720 |
< |
|
721 |
< |
MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
722 |
< |
myPotato, MPI_COMM_WORLD); |
723 |
< |
|
724 |
< |
myPotato++; |
725 |
< |
|
726 |
< |
if (isDirectional && needForceVector_) { |
727 |
< |
MPI_Send(atomData, 19, MPI_REALTYPE, 0, myPotato, |
728 |
< |
MPI_COMM_WORLD); |
729 |
< |
} else if (isDirectional) { |
730 |
< |
MPI_Send(atomData, 13, MPI_REALTYPE, 0, myPotato, |
731 |
< |
MPI_COMM_WORLD); |
732 |
< |
} else if (needForceVector_) { |
733 |
< |
MPI_Send(atomData, 12, MPI_REALTYPE, 0, myPotato, |
734 |
< |
MPI_COMM_WORLD); |
735 |
< |
} else { |
736 |
< |
MPI_Send(atomData, 6, MPI_REALTYPE, 0, myPotato, |
737 |
< |
MPI_COMM_WORLD); |
738 |
< |
} |
739 |
< |
|
740 |
< |
myPotato++; |
741 |
< |
} |
742 |
< |
|
743 |
< |
} |
744 |
< |
|
526 |
> |
if (needElectricField_) { |
527 |
> |
type += "e"; |
528 |
> |
Vector3d eField= integrableObject->getElectricField(); |
529 |
> |
if (isinf(eField[0]) || isnan(eField[0]) || |
530 |
> |
isinf(eField[1]) || isnan(eField[1]) || |
531 |
> |
isinf(eField[2]) || isnan(eField[2]) ) { |
532 |
> |
sprintf( painCave.errMsg, |
533 |
> |
"DumpWriter detected a numerical error writing the electric" |
534 |
> |
" field for object %d", index); |
535 |
> |
painCave.isFatal = 1; |
536 |
> |
simError(); |
537 |
|
} |
538 |
< |
sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
539 |
< |
MPIcheckPoint(); |
538 |
> |
sprintf(tempBuffer, " %13e %13e %13e", |
539 |
> |
eField[0], eField[1], eField[2]); |
540 |
> |
line += tempBuffer; |
541 |
|
} |
542 |
|
|
543 |
< |
#endif // is_mpi |
544 |
< |
|
543 |
> |
sprintf(tempBuffer, "%10d %7s %s\n", index, type.c_str(), line.c_str()); |
544 |
> |
return std::string(tempBuffer); |
545 |
|
} |
546 |
|
|
547 |
|
void DumpWriter::writeDump() { |
566 |
|
#ifdef IS_MPI |
567 |
|
if (worldRank == 0) { |
568 |
|
#endif // is_mpi |
569 |
< |
delete eorStream; |
570 |
< |
|
569 |
> |
writeClosing(*eorStream); |
570 |
> |
delete eorStream; |
571 |
|
#ifdef IS_MPI |
572 |
|
} |
573 |
|
#endif // is_mpi |
600 |
|
#ifdef IS_MPI |
601 |
|
if (worldRank == 0) { |
602 |
|
#endif // is_mpi |
603 |
< |
delete eorStream; |
604 |
< |
|
603 |
> |
writeClosing(*eorStream); |
604 |
> |
delete eorStream; |
605 |
|
#ifdef IS_MPI |
606 |
|
} |
607 |
|
#endif // is_mpi |
608 |
|
|
609 |
|
} |
610 |
|
|
611 |
< |
std::ostream* DumpWriter::createOStream(const std::string& filename) { |
611 |
> |
std::ostream* DumpWriter::createOStream(const std::string& filename) { |
612 |
|
|
613 |
|
std::ostream* newOStream; |
614 |
|
#ifdef HAVE_LIBZ |
615 |
|
if (needCompression_) { |
616 |
< |
newOStream = new ogzstream(filename.c_str()); |
616 |
> |
newOStream = new ogzstream(filename.c_str()); |
617 |
|
} else { |
618 |
< |
newOStream = new std::ofstream(filename.c_str()); |
618 |
> |
newOStream = new std::ofstream(filename.c_str()); |
619 |
|
} |
620 |
|
#else |
621 |
|
newOStream = new std::ofstream(filename.c_str()); |
622 |
|
#endif |
623 |
+ |
//write out MetaData first |
624 |
+ |
(*newOStream) << "<OpenMD version=1>" << std::endl; |
625 |
+ |
(*newOStream) << " <MetaData>" << std::endl; |
626 |
+ |
(*newOStream) << info_->getRawMetaData(); |
627 |
+ |
(*newOStream) << " </MetaData>" << std::endl; |
628 |
|
return newOStream; |
629 |
< |
} |
629 |
> |
} |
630 |
|
|
631 |
< |
}//end namespace oopse |
631 |
> |
void DumpWriter::writeClosing(std::ostream& os) { |
632 |
> |
|
633 |
> |
os << "</OpenMD>\n"; |
634 |
> |
os.flush(); |
635 |
> |
} |
636 |
> |
|
637 |
> |
}//end namespace OpenMD |