1 |
gezelter |
507 |
/* |
2 |
gezelter |
1390 |
* Copyright (c) 2009 The University of Notre Dame. All Rights Reserved. |
3 |
gezelter |
246 |
* |
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 |
gezelter |
1390 |
* 1. Redistributions of source code must retain the above copyright |
10 |
gezelter |
246 |
* notice, this list of conditions and the following disclaimer. |
11 |
|
|
* |
12 |
gezelter |
1390 |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
gezelter |
246 |
* notice, this list of conditions and the following disclaimer in the |
14 |
|
|
* documentation and/or other materials provided with the |
15 |
|
|
* distribution. |
16 |
|
|
* |
17 |
|
|
* This software is provided "AS IS," without a warranty of any |
18 |
|
|
* kind. All express or implied conditions, representations and |
19 |
|
|
* warranties, including any implied warranty of merchantability, |
20 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
21 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
22 |
|
|
* be liable for any damages suffered by licensee as a result of |
23 |
|
|
* using, modifying or distributing the software or its |
24 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
25 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
26 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
27 |
|
|
* damages, however caused and regardless of the theory of liability, |
28 |
|
|
* arising out of the use of or inability to use software, even if the |
29 |
|
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
|
* such damages. |
31 |
gezelter |
1390 |
* |
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 |
gezelter |
1665 |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
|
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
gezelter |
246 |
*/ |
42 |
|
|
|
43 |
|
|
#include "io/DumpWriter.hpp" |
44 |
|
|
#include "primitives/Molecule.hpp" |
45 |
|
|
#include "utils/simError.h" |
46 |
tim |
376 |
#include "io/basic_teebuf.hpp" |
47 |
tim |
615 |
#include "io/gzstream.hpp" |
48 |
|
|
#include "io/Globals.hpp" |
49 |
|
|
|
50 |
gezelter |
1437 |
|
51 |
gezelter |
2 |
#ifdef IS_MPI |
52 |
|
|
#include <mpi.h> |
53 |
gezelter |
246 |
#endif //is_mpi |
54 |
gezelter |
2 |
|
55 |
gezelter |
1437 |
using namespace std; |
56 |
gezelter |
1390 |
namespace OpenMD { |
57 |
gezelter |
2 |
|
58 |
gezelter |
507 |
DumpWriter::DumpWriter(SimInfo* info) |
59 |
|
|
: info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ |
60 |
tim |
615 |
|
61 |
|
|
Globals* simParams = info->getSimParams(); |
62 |
gezelter |
1714 |
needCompression_ = simParams->getCompressDumpFile(); |
63 |
|
|
needForceVector_ = simParams->getOutputForceVector(); |
64 |
|
|
needParticlePot_ = simParams->getOutputParticlePotential(); |
65 |
|
|
needFlucQ_ = simParams->getOutputFluctuatingCharges(); |
66 |
|
|
needElectricField_ = simParams->getOutputElectricField(); |
67 |
|
|
|
68 |
gezelter |
1752 |
if (needParticlePot_ || needFlucQ_ || needElectricField_) { |
69 |
|
|
doSiteData_ = true; |
70 |
|
|
} else { |
71 |
|
|
doSiteData_ = false; |
72 |
|
|
} |
73 |
|
|
|
74 |
chuckv |
791 |
createDumpFile_ = true; |
75 |
tim |
619 |
#ifdef HAVE_LIBZ |
76 |
tim |
615 |
if (needCompression_) { |
77 |
tim |
1024 |
filename_ += ".gz"; |
78 |
|
|
eorFilename_ += ".gz"; |
79 |
tim |
615 |
} |
80 |
tim |
619 |
#endif |
81 |
tim |
615 |
|
82 |
tim |
376 |
#ifdef IS_MPI |
83 |
|
|
|
84 |
tim |
1024 |
if (worldRank == 0) { |
85 |
tim |
376 |
#endif // is_mpi |
86 |
chuckv |
791 |
|
87 |
tim |
1024 |
dumpFile_ = createOStream(filename_); |
88 |
tim |
615 |
|
89 |
tim |
1024 |
if (!dumpFile_) { |
90 |
|
|
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
91 |
|
|
filename_.c_str()); |
92 |
|
|
painCave.isFatal = 1; |
93 |
|
|
simError(); |
94 |
|
|
} |
95 |
tim |
376 |
|
96 |
|
|
#ifdef IS_MPI |
97 |
|
|
|
98 |
tim |
1024 |
} |
99 |
tim |
376 |
|
100 |
|
|
#endif // is_mpi |
101 |
|
|
|
102 |
tim |
1024 |
} |
103 |
tim |
376 |
|
104 |
|
|
|
105 |
gezelter |
507 |
DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) |
106 |
|
|
: info_(info), filename_(filename){ |
107 |
tim |
615 |
|
108 |
|
|
Globals* simParams = info->getSimParams(); |
109 |
|
|
eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
110 |
|
|
|
111 |
gezelter |
1714 |
needCompression_ = simParams->getCompressDumpFile(); |
112 |
|
|
needForceVector_ = simParams->getOutputForceVector(); |
113 |
|
|
needParticlePot_ = simParams->getOutputParticlePotential(); |
114 |
|
|
needFlucQ_ = simParams->getOutputFluctuatingCharges(); |
115 |
|
|
needElectricField_ = simParams->getOutputElectricField(); |
116 |
|
|
|
117 |
gezelter |
1752 |
if (needParticlePot_ || needFlucQ_ || needElectricField_) { |
118 |
|
|
doSiteData_ = true; |
119 |
|
|
} else { |
120 |
|
|
doSiteData_ = false; |
121 |
|
|
} |
122 |
|
|
|
123 |
chuckv |
791 |
createDumpFile_ = true; |
124 |
tim |
619 |
#ifdef HAVE_LIBZ |
125 |
tim |
615 |
if (needCompression_) { |
126 |
tim |
1024 |
filename_ += ".gz"; |
127 |
|
|
eorFilename_ += ".gz"; |
128 |
tim |
615 |
} |
129 |
tim |
619 |
#endif |
130 |
tim |
615 |
|
131 |
gezelter |
246 |
#ifdef IS_MPI |
132 |
gezelter |
2 |
|
133 |
tim |
1024 |
if (worldRank == 0) { |
134 |
gezelter |
246 |
#endif // is_mpi |
135 |
gezelter |
2 |
|
136 |
chuckv |
791 |
|
137 |
tim |
1024 |
dumpFile_ = createOStream(filename_); |
138 |
tim |
615 |
|
139 |
tim |
1024 |
if (!dumpFile_) { |
140 |
|
|
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
141 |
|
|
filename_.c_str()); |
142 |
|
|
painCave.isFatal = 1; |
143 |
|
|
simError(); |
144 |
|
|
} |
145 |
gezelter |
2 |
|
146 |
|
|
#ifdef IS_MPI |
147 |
|
|
|
148 |
tim |
1024 |
} |
149 |
gezelter |
2 |
|
150 |
|
|
#endif // is_mpi |
151 |
gezelter |
246 |
|
152 |
tim |
1024 |
} |
153 |
chuckv |
791 |
|
154 |
|
|
DumpWriter::DumpWriter(SimInfo* info, const std::string& filename, bool writeDumpFile) |
155 |
tim |
1024 |
: info_(info), filename_(filename){ |
156 |
chuckv |
791 |
|
157 |
|
|
Globals* simParams = info->getSimParams(); |
158 |
|
|
eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
159 |
|
|
|
160 |
gezelter |
1714 |
needCompression_ = simParams->getCompressDumpFile(); |
161 |
|
|
needForceVector_ = simParams->getOutputForceVector(); |
162 |
|
|
needParticlePot_ = simParams->getOutputParticlePotential(); |
163 |
|
|
needFlucQ_ = simParams->getOutputFluctuatingCharges(); |
164 |
|
|
needElectricField_ = simParams->getOutputElectricField(); |
165 |
|
|
|
166 |
gezelter |
1752 |
if (needParticlePot_ || needFlucQ_ || needElectricField_) { |
167 |
|
|
doSiteData_ = true; |
168 |
|
|
} else { |
169 |
|
|
doSiteData_ = false; |
170 |
|
|
} |
171 |
|
|
|
172 |
chuckv |
791 |
#ifdef HAVE_LIBZ |
173 |
|
|
if (needCompression_) { |
174 |
|
|
filename_ += ".gz"; |
175 |
|
|
eorFilename_ += ".gz"; |
176 |
|
|
} |
177 |
|
|
#endif |
178 |
|
|
|
179 |
|
|
#ifdef IS_MPI |
180 |
|
|
|
181 |
|
|
if (worldRank == 0) { |
182 |
|
|
#endif // is_mpi |
183 |
|
|
|
184 |
|
|
createDumpFile_ = writeDumpFile; |
185 |
|
|
if (createDumpFile_) { |
186 |
|
|
dumpFile_ = createOStream(filename_); |
187 |
|
|
|
188 |
|
|
if (!dumpFile_) { |
189 |
|
|
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
190 |
|
|
filename_.c_str()); |
191 |
|
|
painCave.isFatal = 1; |
192 |
|
|
simError(); |
193 |
|
|
} |
194 |
|
|
} |
195 |
|
|
#ifdef IS_MPI |
196 |
|
|
|
197 |
|
|
} |
198 |
tim |
1024 |
|
199 |
chuckv |
791 |
|
200 |
|
|
#endif // is_mpi |
201 |
|
|
|
202 |
|
|
} |
203 |
gezelter |
2 |
|
204 |
gezelter |
507 |
DumpWriter::~DumpWriter() { |
205 |
gezelter |
2 |
|
206 |
|
|
#ifdef IS_MPI |
207 |
gezelter |
246 |
|
208 |
|
|
if (worldRank == 0) { |
209 |
gezelter |
2 |
#endif // is_mpi |
210 |
chuckv |
791 |
if (createDumpFile_){ |
211 |
tim |
1024 |
writeClosing(*dumpFile_); |
212 |
chuckv |
791 |
delete dumpFile_; |
213 |
|
|
} |
214 |
gezelter |
2 |
#ifdef IS_MPI |
215 |
gezelter |
246 |
|
216 |
|
|
} |
217 |
|
|
|
218 |
gezelter |
2 |
#endif // is_mpi |
219 |
gezelter |
246 |
|
220 |
gezelter |
507 |
} |
221 |
gezelter |
2 |
|
222 |
tim |
1024 |
void DumpWriter::writeFrameProperties(std::ostream& os, Snapshot* s) { |
223 |
gezelter |
2 |
|
224 |
tim |
1024 |
char buffer[1024]; |
225 |
|
|
|
226 |
|
|
os << " <FrameData>\n"; |
227 |
|
|
|
228 |
|
|
RealType currentTime = s->getTime(); |
229 |
gezelter |
1437 |
|
230 |
|
|
if (isinf(currentTime) || isnan(currentTime)) { |
231 |
|
|
sprintf( painCave.errMsg, |
232 |
|
|
"DumpWriter detected a numerical error writing the time"); |
233 |
|
|
painCave.isFatal = 1; |
234 |
|
|
simError(); |
235 |
|
|
} |
236 |
|
|
|
237 |
gezelter |
1025 |
sprintf(buffer, " Time: %.10g\n", currentTime); |
238 |
tim |
1024 |
os << buffer; |
239 |
|
|
|
240 |
gezelter |
246 |
Mat3x3d hmat; |
241 |
|
|
hmat = s->getHmat(); |
242 |
gezelter |
1437 |
|
243 |
|
|
for (unsigned int i = 0; i < 3; i++) { |
244 |
|
|
for (unsigned int j = 0; j < 3; j++) { |
245 |
|
|
if (isinf(hmat(i,j)) || isnan(hmat(i,j))) { |
246 |
|
|
sprintf( painCave.errMsg, |
247 |
|
|
"DumpWriter detected a numerical error writing the box"); |
248 |
|
|
painCave.isFatal = 1; |
249 |
|
|
simError(); |
250 |
|
|
} |
251 |
|
|
} |
252 |
|
|
} |
253 |
|
|
|
254 |
tim |
1024 |
sprintf(buffer, " Hmat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n", |
255 |
|
|
hmat(0, 0), hmat(1, 0), hmat(2, 0), |
256 |
|
|
hmat(0, 1), hmat(1, 1), hmat(2, 1), |
257 |
|
|
hmat(0, 2), hmat(1, 2), hmat(2, 2)); |
258 |
|
|
os << buffer; |
259 |
gezelter |
2 |
|
260 |
tim |
1024 |
RealType chi = s->getChi(); |
261 |
|
|
RealType integralOfChiDt = s->getIntegralOfChiDt(); |
262 |
gezelter |
1437 |
if (isinf(chi) || isnan(chi) || |
263 |
|
|
isinf(integralOfChiDt) || isnan(integralOfChiDt)) { |
264 |
|
|
sprintf( painCave.errMsg, |
265 |
|
|
"DumpWriter detected a numerical error writing the thermostat"); |
266 |
|
|
painCave.isFatal = 1; |
267 |
|
|
simError(); |
268 |
|
|
} |
269 |
tim |
1024 |
sprintf(buffer, " Thermostat: %.10g , %.10g\n", chi, integralOfChiDt); |
270 |
|
|
os << buffer; |
271 |
gezelter |
246 |
|
272 |
tim |
1024 |
Mat3x3d eta; |
273 |
|
|
eta = s->getEta(); |
274 |
gezelter |
1437 |
|
275 |
|
|
for (unsigned int i = 0; i < 3; i++) { |
276 |
|
|
for (unsigned int j = 0; j < 3; j++) { |
277 |
|
|
if (isinf(eta(i,j)) || isnan(eta(i,j))) { |
278 |
|
|
sprintf( painCave.errMsg, |
279 |
|
|
"DumpWriter detected a numerical error writing the barostat"); |
280 |
|
|
painCave.isFatal = 1; |
281 |
|
|
simError(); |
282 |
|
|
} |
283 |
|
|
} |
284 |
|
|
} |
285 |
|
|
|
286 |
tim |
1024 |
sprintf(buffer, " Barostat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n", |
287 |
|
|
eta(0, 0), eta(1, 0), eta(2, 0), |
288 |
|
|
eta(0, 1), eta(1, 1), eta(2, 1), |
289 |
|
|
eta(0, 2), eta(1, 2), eta(2, 2)); |
290 |
|
|
os << buffer; |
291 |
gezelter |
246 |
|
292 |
tim |
1024 |
os << " </FrameData>\n"; |
293 |
gezelter |
507 |
} |
294 |
gezelter |
2 |
|
295 |
gezelter |
507 |
void DumpWriter::writeFrame(std::ostream& os) { |
296 |
gezelter |
246 |
|
297 |
tim |
1024 |
#ifdef IS_MPI |
298 |
|
|
MPI_Status istatus; |
299 |
|
|
#endif |
300 |
gezelter |
246 |
|
301 |
|
|
Molecule* mol; |
302 |
|
|
StuntDouble* integrableObject; |
303 |
|
|
SimInfo::MoleculeIterator mi; |
304 |
|
|
Molecule::IntegrableObjectIterator ii; |
305 |
gezelter |
1752 |
RigidBody::AtomIterator ai; |
306 |
|
|
Atom* atom; |
307 |
gezelter |
2 |
|
308 |
gezelter |
246 |
#ifndef IS_MPI |
309 |
tim |
1024 |
os << " <Snapshot>\n"; |
310 |
gezelter |
1025 |
|
311 |
tim |
1024 |
writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
312 |
gezelter |
2 |
|
313 |
tim |
1024 |
os << " <StuntDoubles>\n"; |
314 |
gezelter |
246 |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
315 |
gezelter |
2 |
|
316 |
xsun |
1217 |
|
317 |
|
|
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
318 |
tim |
1024 |
integrableObject = mol->nextIntegrableObject(ii)) { |
319 |
xsun |
1217 |
os << prepareDumpLine(integrableObject); |
320 |
|
|
|
321 |
tim |
1024 |
} |
322 |
|
|
} |
323 |
|
|
os << " </StuntDoubles>\n"; |
324 |
gezelter |
1752 |
|
325 |
|
|
if (doSiteData_) { |
326 |
|
|
os << " <SiteData>\n"; |
327 |
|
|
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
328 |
|
|
|
329 |
|
|
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
330 |
|
|
integrableObject = mol->nextIntegrableObject(ii)) { |
331 |
|
|
|
332 |
|
|
int ioIndex = integrableObject->getGlobalIntegrableObjectIndex(); |
333 |
|
|
// do one for the IO itself |
334 |
|
|
os << prepareSiteLine(integrableObject, ioIndex, 0); |
335 |
|
|
|
336 |
|
|
if (integrableObject->isRigidBody()) { |
337 |
|
|
|
338 |
|
|
RigidBody* rb = static_cast<RigidBody*>(integrableObject); |
339 |
|
|
int siteIndex = 0; |
340 |
|
|
for (atom = rb->beginAtom(ai); atom != NULL; |
341 |
|
|
atom = rb->nextAtom(ai)) { |
342 |
|
|
os << prepareSiteLine(atom, ioIndex, siteIndex); |
343 |
|
|
siteIndex++; |
344 |
|
|
} |
345 |
|
|
} |
346 |
|
|
} |
347 |
|
|
} |
348 |
|
|
os << " </SiteData>\n"; |
349 |
|
|
} |
350 |
tim |
1024 |
os << " </Snapshot>\n"; |
351 |
gezelter |
2 |
|
352 |
tim |
1024 |
os.flush(); |
353 |
|
|
#else |
354 |
|
|
//every node prepares the dump lines for integrable objects belong to itself |
355 |
|
|
std::string buffer; |
356 |
|
|
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
357 |
xsun |
1217 |
|
358 |
|
|
|
359 |
tim |
1024 |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
360 |
|
|
integrableObject = mol->nextIntegrableObject(ii)) { |
361 |
xsun |
1217 |
buffer += prepareDumpLine(integrableObject); |
362 |
gezelter |
507 |
} |
363 |
gezelter |
2 |
} |
364 |
tim |
1024 |
|
365 |
gezelter |
246 |
const int masterNode = 0; |
366 |
gezelter |
1629 |
int nProc; |
367 |
|
|
MPI_Comm_size(MPI_COMM_WORLD, &nProc); |
368 |
tim |
1024 |
if (worldRank == masterNode) { |
369 |
|
|
os << " <Snapshot>\n"; |
370 |
|
|
writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
371 |
|
|
os << " <StuntDoubles>\n"; |
372 |
|
|
|
373 |
gezelter |
1025 |
os << buffer; |
374 |
|
|
|
375 |
tim |
1024 |
for (int i = 1; i < nProc; ++i) { |
376 |
gezelter |
2 |
|
377 |
tim |
1024 |
// receive the length of the string buffer that was |
378 |
|
|
// prepared by processor i |
379 |
gezelter |
2 |
|
380 |
gezelter |
1629 |
MPI_Bcast(&i, 1, MPI_INT,masterNode,MPI_COMM_WORLD); |
381 |
tim |
1024 |
int recvLength; |
382 |
|
|
MPI_Recv(&recvLength, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &istatus); |
383 |
|
|
char* recvBuffer = new char[recvLength]; |
384 |
|
|
if (recvBuffer == NULL) { |
385 |
|
|
} else { |
386 |
gezelter |
1025 |
MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i, 0, MPI_COMM_WORLD, &istatus); |
387 |
tim |
1024 |
os << recvBuffer; |
388 |
gezelter |
1313 |
delete [] recvBuffer; |
389 |
tim |
1024 |
} |
390 |
|
|
} |
391 |
|
|
os << " </StuntDoubles>\n"; |
392 |
|
|
|
393 |
|
|
os << " </Snapshot>\n"; |
394 |
gezelter |
507 |
os.flush(); |
395 |
gezelter |
246 |
} else { |
396 |
gezelter |
1025 |
int sendBufferLength = buffer.size() + 1; |
397 |
gezelter |
1629 |
int myturn = 0; |
398 |
|
|
for (int i = 1; i < nProc; ++i){ |
399 |
|
|
MPI_Bcast(&myturn,1, MPI_INT,masterNode,MPI_COMM_WORLD); |
400 |
|
|
if (myturn == worldRank){ |
401 |
|
|
MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); |
402 |
|
|
MPI_Send((void *)buffer.c_str(), sendBufferLength, MPI_CHAR, masterNode, 0, MPI_COMM_WORLD); |
403 |
|
|
} |
404 |
|
|
} |
405 |
tim |
1024 |
} |
406 |
gezelter |
2 |
|
407 |
tim |
1024 |
#endif // is_mpi |
408 |
gezelter |
2 |
|
409 |
tim |
1024 |
} |
410 |
gezelter |
2 |
|
411 |
tim |
1024 |
std::string DumpWriter::prepareDumpLine(StuntDouble* integrableObject) { |
412 |
|
|
|
413 |
|
|
int index = integrableObject->getGlobalIntegrableObjectIndex(); |
414 |
|
|
std::string type("pv"); |
415 |
|
|
std::string line; |
416 |
|
|
char tempBuffer[4096]; |
417 |
gezelter |
2 |
|
418 |
tim |
1024 |
Vector3d pos; |
419 |
|
|
Vector3d vel; |
420 |
|
|
pos = integrableObject->getPos(); |
421 |
gezelter |
1437 |
|
422 |
|
|
if (isinf(pos[0]) || isnan(pos[0]) || |
423 |
|
|
isinf(pos[1]) || isnan(pos[1]) || |
424 |
|
|
isinf(pos[2]) || isnan(pos[2]) ) { |
425 |
|
|
sprintf( painCave.errMsg, |
426 |
|
|
"DumpWriter detected a numerical error writing the position" |
427 |
|
|
" for object %d", index); |
428 |
|
|
painCave.isFatal = 1; |
429 |
|
|
simError(); |
430 |
|
|
} |
431 |
|
|
|
432 |
tim |
1024 |
vel = integrableObject->getVel(); |
433 |
gezelter |
1437 |
|
434 |
|
|
if (isinf(vel[0]) || isnan(vel[0]) || |
435 |
|
|
isinf(vel[1]) || isnan(vel[1]) || |
436 |
|
|
isinf(vel[2]) || isnan(vel[2]) ) { |
437 |
|
|
sprintf( painCave.errMsg, |
438 |
|
|
"DumpWriter detected a numerical error writing the velocity" |
439 |
|
|
" for object %d", index); |
440 |
|
|
painCave.isFatal = 1; |
441 |
|
|
simError(); |
442 |
|
|
} |
443 |
|
|
|
444 |
gezelter |
1025 |
sprintf(tempBuffer, "%18.10g %18.10g %18.10g %13e %13e %13e", |
445 |
tim |
1024 |
pos[0], pos[1], pos[2], |
446 |
|
|
vel[0], vel[1], vel[2]); |
447 |
|
|
line += tempBuffer; |
448 |
gezelter |
2 |
|
449 |
tim |
1024 |
if (integrableObject->isDirectional()) { |
450 |
|
|
type += "qj"; |
451 |
|
|
Quat4d q; |
452 |
|
|
Vector3d ji; |
453 |
|
|
q = integrableObject->getQ(); |
454 |
gezelter |
1437 |
|
455 |
|
|
if (isinf(q[0]) || isnan(q[0]) || |
456 |
|
|
isinf(q[1]) || isnan(q[1]) || |
457 |
|
|
isinf(q[2]) || isnan(q[2]) || |
458 |
|
|
isinf(q[3]) || isnan(q[3]) ) { |
459 |
|
|
sprintf( painCave.errMsg, |
460 |
|
|
"DumpWriter detected a numerical error writing the quaternion" |
461 |
|
|
" for object %d", index); |
462 |
|
|
painCave.isFatal = 1; |
463 |
|
|
simError(); |
464 |
|
|
} |
465 |
|
|
|
466 |
tim |
1024 |
ji = integrableObject->getJ(); |
467 |
gezelter |
1437 |
|
468 |
|
|
if (isinf(ji[0]) || isnan(ji[0]) || |
469 |
|
|
isinf(ji[1]) || isnan(ji[1]) || |
470 |
|
|
isinf(ji[2]) || isnan(ji[2]) ) { |
471 |
|
|
sprintf( painCave.errMsg, |
472 |
|
|
"DumpWriter detected a numerical error writing the angular" |
473 |
|
|
" momentum for object %d", index); |
474 |
|
|
painCave.isFatal = 1; |
475 |
|
|
simError(); |
476 |
|
|
} |
477 |
|
|
|
478 |
gezelter |
1025 |
sprintf(tempBuffer, " %13e %13e %13e %13e %13e %13e %13e", |
479 |
tim |
1024 |
q[0], q[1], q[2], q[3], |
480 |
|
|
ji[0], ji[1], ji[2]); |
481 |
|
|
line += tempBuffer; |
482 |
|
|
} |
483 |
gezelter |
2 |
|
484 |
tim |
1024 |
if (needForceVector_) { |
485 |
gezelter |
1437 |
type += "f"; |
486 |
gezelter |
1714 |
Vector3d frc = integrableObject->getFrc(); |
487 |
gezelter |
1437 |
if (isinf(frc[0]) || isnan(frc[0]) || |
488 |
|
|
isinf(frc[1]) || isnan(frc[1]) || |
489 |
|
|
isinf(frc[2]) || isnan(frc[2]) ) { |
490 |
|
|
sprintf( painCave.errMsg, |
491 |
|
|
"DumpWriter detected a numerical error writing the force" |
492 |
|
|
" for object %d", index); |
493 |
|
|
painCave.isFatal = 1; |
494 |
|
|
simError(); |
495 |
|
|
} |
496 |
|
|
sprintf(tempBuffer, " %13e %13e %13e", |
497 |
|
|
frc[0], frc[1], frc[2]); |
498 |
tim |
1024 |
line += tempBuffer; |
499 |
gezelter |
1437 |
|
500 |
|
|
if (integrableObject->isDirectional()) { |
501 |
|
|
type += "t"; |
502 |
gezelter |
1714 |
Vector3d trq = integrableObject->getTrq(); |
503 |
gezelter |
1437 |
if (isinf(trq[0]) || isnan(trq[0]) || |
504 |
|
|
isinf(trq[1]) || isnan(trq[1]) || |
505 |
|
|
isinf(trq[2]) || isnan(trq[2]) ) { |
506 |
|
|
sprintf( painCave.errMsg, |
507 |
|
|
"DumpWriter detected a numerical error writing the torque" |
508 |
|
|
" for object %d", index); |
509 |
|
|
painCave.isFatal = 1; |
510 |
|
|
simError(); |
511 |
gezelter |
1714 |
} |
512 |
gezelter |
1437 |
sprintf(tempBuffer, " %13e %13e %13e", |
513 |
|
|
trq[0], trq[1], trq[2]); |
514 |
|
|
line += tempBuffer; |
515 |
|
|
} |
516 |
gezelter |
246 |
} |
517 |
gezelter |
1714 |
|
518 |
gezelter |
1752 |
sprintf(tempBuffer, "%10d %7s %s\n", index, type.c_str(), line.c_str()); |
519 |
|
|
return std::string(tempBuffer); |
520 |
|
|
} |
521 |
|
|
|
522 |
|
|
std::string DumpWriter::prepareSiteLine(StuntDouble* integrableObject, int ioIndex, int siteIndex) { |
523 |
|
|
|
524 |
|
|
|
525 |
|
|
std::string id; |
526 |
|
|
std::string type; |
527 |
|
|
std::string line; |
528 |
|
|
char tempBuffer[4096]; |
529 |
|
|
|
530 |
|
|
if (integrableObject->isRigidBody()) { |
531 |
|
|
sprintf(tempBuffer, "%10d ", ioIndex); |
532 |
|
|
id = std::string(tempBuffer); |
533 |
|
|
} else { |
534 |
|
|
sprintf(tempBuffer, "%10d %10d", ioIndex, siteIndex); |
535 |
|
|
id = std::string(tempBuffer); |
536 |
gezelter |
1629 |
} |
537 |
gezelter |
1752 |
|
538 |
gezelter |
1714 |
if (needFlucQ_) { |
539 |
|
|
type += "cw"; |
540 |
|
|
RealType fqPos = integrableObject->getFlucQPos(); |
541 |
|
|
if (isinf(fqPos) || isnan(fqPos) ) { |
542 |
|
|
sprintf( painCave.errMsg, |
543 |
|
|
"DumpWriter detected a numerical error writing the" |
544 |
gezelter |
1752 |
" fluctuating charge for object %s", id.c_str()); |
545 |
gezelter |
1714 |
painCave.isFatal = 1; |
546 |
|
|
simError(); |
547 |
|
|
} |
548 |
|
|
sprintf(tempBuffer, " %13e ", fqPos); |
549 |
|
|
line += tempBuffer; |
550 |
|
|
|
551 |
|
|
RealType fqVel = integrableObject->getFlucQVel(); |
552 |
|
|
if (isinf(fqVel) || isnan(fqVel) ) { |
553 |
|
|
sprintf( painCave.errMsg, |
554 |
|
|
"DumpWriter detected a numerical error writing the" |
555 |
gezelter |
1752 |
" fluctuating charge velocity for object %s", id.c_str()); |
556 |
gezelter |
1714 |
painCave.isFatal = 1; |
557 |
|
|
simError(); |
558 |
|
|
} |
559 |
|
|
sprintf(tempBuffer, " %13e ", fqVel); |
560 |
|
|
line += tempBuffer; |
561 |
|
|
|
562 |
|
|
if (needForceVector_) { |
563 |
|
|
type += "g"; |
564 |
|
|
RealType fqFrc = integrableObject->getFlucQFrc(); |
565 |
|
|
if (isinf(fqFrc) || isnan(fqFrc) ) { |
566 |
|
|
sprintf( painCave.errMsg, |
567 |
|
|
"DumpWriter detected a numerical error writing the" |
568 |
gezelter |
1752 |
" fluctuating charge force for object %s", id.c_str()); |
569 |
gezelter |
1714 |
painCave.isFatal = 1; |
570 |
|
|
simError(); |
571 |
|
|
} |
572 |
|
|
sprintf(tempBuffer, " %13e ", fqFrc); |
573 |
|
|
line += tempBuffer; |
574 |
|
|
} |
575 |
|
|
} |
576 |
|
|
|
577 |
|
|
if (needElectricField_) { |
578 |
|
|
type += "e"; |
579 |
|
|
Vector3d eField= integrableObject->getElectricField(); |
580 |
|
|
if (isinf(eField[0]) || isnan(eField[0]) || |
581 |
|
|
isinf(eField[1]) || isnan(eField[1]) || |
582 |
|
|
isinf(eField[2]) || isnan(eField[2]) ) { |
583 |
|
|
sprintf( painCave.errMsg, |
584 |
|
|
"DumpWriter detected a numerical error writing the electric" |
585 |
gezelter |
1752 |
" field for object %s", id.c_str()); |
586 |
gezelter |
1714 |
painCave.isFatal = 1; |
587 |
|
|
simError(); |
588 |
|
|
} |
589 |
|
|
sprintf(tempBuffer, " %13e %13e %13e", |
590 |
|
|
eField[0], eField[1], eField[2]); |
591 |
|
|
line += tempBuffer; |
592 |
|
|
} |
593 |
|
|
|
594 |
gezelter |
1752 |
|
595 |
|
|
if (needParticlePot_) { |
596 |
|
|
type += "u"; |
597 |
|
|
RealType particlePot = integrableObject->getParticlePot(); |
598 |
|
|
if (isinf(particlePot) || isnan(particlePot)) { |
599 |
|
|
sprintf( painCave.errMsg, |
600 |
|
|
"DumpWriter detected a numerical error writing the particle " |
601 |
|
|
" potential for object %s", id.c_str()); |
602 |
|
|
painCave.isFatal = 1; |
603 |
|
|
simError(); |
604 |
|
|
} |
605 |
|
|
sprintf(tempBuffer, " %13e", particlePot); |
606 |
|
|
line += tempBuffer; |
607 |
|
|
} |
608 |
|
|
|
609 |
|
|
|
610 |
|
|
sprintf(tempBuffer, "%s %7s %s\n", id.c_str(), type.c_str(), line.c_str()); |
611 |
tim |
1024 |
return std::string(tempBuffer); |
612 |
gezelter |
507 |
} |
613 |
gezelter |
2 |
|
614 |
gezelter |
507 |
void DumpWriter::writeDump() { |
615 |
tim |
615 |
writeFrame(*dumpFile_); |
616 |
gezelter |
507 |
} |
617 |
tim |
376 |
|
618 |
gezelter |
507 |
void DumpWriter::writeEor() { |
619 |
tim |
615 |
std::ostream* eorStream; |
620 |
tim |
376 |
|
621 |
|
|
#ifdef IS_MPI |
622 |
|
|
if (worldRank == 0) { |
623 |
|
|
#endif // is_mpi |
624 |
|
|
|
625 |
tim |
615 |
eorStream = createOStream(eorFilename_); |
626 |
tim |
376 |
|
627 |
|
|
#ifdef IS_MPI |
628 |
|
|
} |
629 |
|
|
#endif // is_mpi |
630 |
|
|
|
631 |
tim |
615 |
writeFrame(*eorStream); |
632 |
|
|
|
633 |
|
|
#ifdef IS_MPI |
634 |
|
|
if (worldRank == 0) { |
635 |
|
|
#endif // is_mpi |
636 |
tim |
1024 |
writeClosing(*eorStream); |
637 |
|
|
delete eorStream; |
638 |
tim |
615 |
#ifdef IS_MPI |
639 |
|
|
} |
640 |
|
|
#endif // is_mpi |
641 |
|
|
|
642 |
gezelter |
507 |
} |
643 |
tim |
376 |
|
644 |
|
|
|
645 |
gezelter |
507 |
void DumpWriter::writeDumpAndEor() { |
646 |
tim |
376 |
std::vector<std::streambuf*> buffers; |
647 |
tim |
615 |
std::ostream* eorStream; |
648 |
tim |
376 |
#ifdef IS_MPI |
649 |
|
|
if (worldRank == 0) { |
650 |
|
|
#endif // is_mpi |
651 |
|
|
|
652 |
tim |
615 |
buffers.push_back(dumpFile_->rdbuf()); |
653 |
tim |
376 |
|
654 |
tim |
615 |
eorStream = createOStream(eorFilename_); |
655 |
tim |
376 |
|
656 |
tim |
615 |
buffers.push_back(eorStream->rdbuf()); |
657 |
tim |
376 |
|
658 |
|
|
#ifdef IS_MPI |
659 |
|
|
} |
660 |
|
|
#endif // is_mpi |
661 |
|
|
|
662 |
|
|
TeeBuf tbuf(buffers.begin(), buffers.end()); |
663 |
|
|
std::ostream os(&tbuf); |
664 |
|
|
|
665 |
|
|
writeFrame(os); |
666 |
tim |
615 |
|
667 |
|
|
#ifdef IS_MPI |
668 |
|
|
if (worldRank == 0) { |
669 |
|
|
#endif // is_mpi |
670 |
tim |
1024 |
writeClosing(*eorStream); |
671 |
|
|
delete eorStream; |
672 |
tim |
615 |
#ifdef IS_MPI |
673 |
|
|
} |
674 |
|
|
#endif // is_mpi |
675 |
tim |
376 |
|
676 |
gezelter |
507 |
} |
677 |
tim |
376 |
|
678 |
tim |
1024 |
std::ostream* DumpWriter::createOStream(const std::string& filename) { |
679 |
tim |
619 |
|
680 |
tim |
615 |
std::ostream* newOStream; |
681 |
tim |
619 |
#ifdef HAVE_LIBZ |
682 |
tim |
615 |
if (needCompression_) { |
683 |
tim |
1024 |
newOStream = new ogzstream(filename.c_str()); |
684 |
tim |
615 |
} else { |
685 |
tim |
1024 |
newOStream = new std::ofstream(filename.c_str()); |
686 |
tim |
615 |
} |
687 |
tim |
619 |
#else |
688 |
|
|
newOStream = new std::ofstream(filename.c_str()); |
689 |
|
|
#endif |
690 |
tim |
1024 |
//write out MetaData first |
691 |
gezelter |
1746 |
(*newOStream) << "<OpenMD version=2>" << std::endl; |
692 |
tim |
1024 |
(*newOStream) << " <MetaData>" << std::endl; |
693 |
|
|
(*newOStream) << info_->getRawMetaData(); |
694 |
|
|
(*newOStream) << " </MetaData>" << std::endl; |
695 |
tim |
615 |
return newOStream; |
696 |
tim |
1024 |
} |
697 |
tim |
376 |
|
698 |
tim |
1024 |
void DumpWriter::writeClosing(std::ostream& os) { |
699 |
|
|
|
700 |
gezelter |
1390 |
os << "</OpenMD>\n"; |
701 |
tim |
1024 |
os.flush(); |
702 |
|
|
} |
703 |
|
|
|
704 |
gezelter |
1390 |
}//end namespace OpenMD |