ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/io/DumpWriter.cpp
(Generate patch)

Comparing trunk/src/io/DumpWriter.cpp (file contents):
Revision 963 by tim, Wed May 17 21:51:42 2006 UTC vs.
Revision 2020 by gezelter, Mon Sep 22 19:18:35 2014 UTC

# Line 1 | Line 1
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.
# Line 37 | Line 28
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()){
67 >    : info_(info), filename_(info->getDumpFileName()),
68 >      eorFilename_(info->getFinalConfigFileName()){
69  
70      Globals* simParams = info->getSimParams();
71 <    needCompression_ = simParams->getCompressDumpFile();
72 <    needForceVector_ = simParams->getOutputForceVector();
71 >    needCompression_   = simParams->getCompressDumpFile();
72 >    needForceVector_   = simParams->getOutputForceVector();
73 >    needParticlePot_   = simParams->getOutputParticlePotential();
74 >    needFlucQ_         = simParams->getOutputFluctuatingCharges();
75 >    needElectricField_ = simParams->getOutputElectricField();
76 >    needSitePotential_ = simParams->getOutputSitePotential();
77 >
78 >    if (needParticlePot_ || needFlucQ_ || needElectricField_ ||
79 >        needSitePotential_) {
80 >      doSiteData_ = true;
81 >    } else {
82 >      doSiteData_ = false;
83 >    }
84 >
85      createDumpFile_ = true;
86   #ifdef HAVE_LIBZ
87      if (needCompression_) {
88 <        filename_ += ".gz";
89 <        eorFilename_ += ".gz";
88 >      filename_ += ".gz";
89 >      eorFilename_ += ".gz";
90      }
91   #endif
92      
93   #ifdef IS_MPI
94  
95 <      if (worldRank == 0) {
95 >    if (worldRank == 0) {
96   #endif // is_mpi
73
97          
98 <        dumpFile_ = createOStream(filename_);
98 >      dumpFile_ = createOStream(filename_);
99  
100 <        if (!dumpFile_) {
101 <          sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
102 <                  filename_.c_str());
103 <          painCave.isFatal = 1;
104 <          simError();
105 <        }
100 >      if (!dumpFile_) {
101 >        sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
102 >                filename_.c_str());
103 >        painCave.isFatal = 1;
104 >        simError();
105 >      }
106  
107   #ifdef IS_MPI
108  
109 <      }
109 >    }
110  
88      sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
89      MPIcheckPoint();
90
111   #endif // is_mpi
112  
113 <    }
113 >  }
114  
115  
116    DumpWriter::DumpWriter(SimInfo* info, const std::string& filename)
# Line 99 | Line 119 | namespace oopse {
119      Globals* simParams = info->getSimParams();
120      eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor";    
121  
122 <    needCompression_ = simParams->getCompressDumpFile();
123 <    needForceVector_ = simParams->getOutputForceVector();
122 >    needCompression_   = simParams->getCompressDumpFile();
123 >    needForceVector_   = simParams->getOutputForceVector();
124 >    needParticlePot_   = simParams->getOutputParticlePotential();
125 >    needFlucQ_         = simParams->getOutputFluctuatingCharges();
126 >    needElectricField_ = simParams->getOutputElectricField();
127 >    needSitePotential_ = simParams->getOutputSitePotential();
128 >
129 >    if (needParticlePot_ || needFlucQ_ || needElectricField_ ||
130 >        needSitePotential_) {
131 >      doSiteData_ = true;
132 >    } else {
133 >      doSiteData_ = false;
134 >    }
135 >
136      createDumpFile_ = true;
137   #ifdef HAVE_LIBZ
138      if (needCompression_) {
139 <        filename_ += ".gz";
140 <        eorFilename_ += ".gz";
139 >      filename_ += ".gz";
140 >      eorFilename_ += ".gz";
141      }
142   #endif
143      
144   #ifdef IS_MPI
145  
146 <      if (worldRank == 0) {
146 >    if (worldRank == 0) {
147   #endif // is_mpi
148  
149        
150 <        dumpFile_ = createOStream(filename_);
150 >      dumpFile_ = createOStream(filename_);
151  
152 <        if (!dumpFile_) {
153 <          sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
154 <                  filename_.c_str());
155 <          painCave.isFatal = 1;
156 <          simError();
157 <        }
152 >      if (!dumpFile_) {
153 >        sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
154 >                filename_.c_str());
155 >        painCave.isFatal = 1;
156 >        simError();
157 >      }
158  
159   #ifdef IS_MPI
160  
161 <      }
161 >    }
162  
131      sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
132      MPIcheckPoint();
133
163   #endif // is_mpi
164  
165 <    }
165 >  }
166    
167    DumpWriter::DumpWriter(SimInfo* info, const std::string& filename, bool writeDumpFile)
168 <  : info_(info), filename_(filename){
168 >    : info_(info), filename_(filename){
169      
170      Globals* simParams = info->getSimParams();
171      eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor";    
172      
173 <    needCompression_ = simParams->getCompressDumpFile();
174 <    needForceVector_ = simParams->getOutputForceVector();
175 <    
173 >    needCompression_   = simParams->getCompressDumpFile();
174 >    needForceVector_   = simParams->getOutputForceVector();
175 >    needParticlePot_   = simParams->getOutputParticlePotential();
176 >    needFlucQ_         = simParams->getOutputFluctuatingCharges();
177 >    needElectricField_ = simParams->getOutputElectricField();
178 >    needSitePotential_ = simParams->getOutputSitePotential();
179 >
180 >    if (needParticlePot_ || needFlucQ_ || needElectricField_ ||
181 >        needSitePotential_) {
182 >      doSiteData_ = true;
183 >    } else {
184 >      doSiteData_ = false;
185 >    }
186 >
187   #ifdef HAVE_LIBZ
188      if (needCompression_) {
189        filename_ += ".gz";
# Line 170 | Line 210 | namespace oopse {
210   #ifdef IS_MPI
211        
212      }
213 +
214      
174    sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
175    MPIcheckPoint();
176    
215   #endif // is_mpi
216      
217    }
180  
181  
182  
183  
184  
218  
219    DumpWriter::~DumpWriter() {
220  
# Line 190 | Line 223 | namespace oopse {
223      if (worldRank == 0) {
224   #endif // is_mpi
225        if (createDumpFile_){
226 +        writeClosing(*dumpFile_);
227          delete dumpFile_;
228        }
229   #ifdef IS_MPI
# Line 200 | Line 234 | namespace oopse {
234  
235    }
236  
237 <  void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) {
237 >  void DumpWriter::writeFrameProperties(std::ostream& os, Snapshot* s) {
238  
239 <    RealType currentTime;
240 <    Mat3x3d hmat;
241 <    RealType chi;
242 <    RealType integralOfChiDt;
243 <    Mat3x3d eta;
239 >    char buffer[1024];
240 >
241 >    os << "    <FrameData>\n";
242 >
243 >    RealType currentTime = s->getTime();
244 >
245 >    if (isinf(currentTime) || isnan(currentTime)) {      
246 >      sprintf( painCave.errMsg,
247 >               "DumpWriter detected a numerical error writing the time");      
248 >      painCave.isFatal = 1;
249 >      simError();
250 >    }
251      
252 <    currentTime = s->getTime();
252 >    sprintf(buffer, "        Time: %.10g\n", currentTime);
253 >    os << buffer;
254 >
255 >    Mat3x3d hmat;
256      hmat = s->getHmat();
257 <    chi = s->getChi();
258 <    integralOfChiDt = s->getIntegralOfChiDt();
259 <    eta = s->getEta();
257 >
258 >    for (unsigned int i = 0; i < 3; i++) {
259 >      for (unsigned int j = 0; j < 3; j++) {
260 >        if (isinf(hmat(i,j)) || isnan(hmat(i,j))) {      
261 >          sprintf( painCave.errMsg,
262 >                   "DumpWriter detected a numerical error writing the box");
263 >          painCave.isFatal = 1;
264 >          simError();
265 >        }        
266 >      }
267 >    }
268      
269 <    os << currentTime << ";\t"
270 <       << hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t"
271 <       << hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t"
272 <       << hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t";
269 >    sprintf(buffer, "        Hmat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n",
270 >            hmat(0, 0), hmat(1, 0), hmat(2, 0),
271 >            hmat(0, 1), hmat(1, 1), hmat(2, 1),
272 >            hmat(0, 2), hmat(1, 2), hmat(2, 2));
273 >    os << buffer;
274  
275 <    //write out additional parameters, such as chi and eta
275 >    pair<RealType, RealType> thermostat = s->getThermostat();
276  
277 <    os << chi << "\t" << integralOfChiDt << ";\t";
277 >    if (isinf(thermostat.first)  || isnan(thermostat.first) ||
278 >        isinf(thermostat.second) || isnan(thermostat.second)) {      
279 >      sprintf( painCave.errMsg,
280 >               "DumpWriter detected a numerical error writing the thermostat");
281 >      painCave.isFatal = 1;
282 >      simError();
283 >    }
284 >    sprintf(buffer, "  Thermostat: %.10g , %.10g\n", thermostat.first,
285 >            thermostat.second);
286 >    os << buffer;
287  
288 <    os << eta(0, 0) << "\t" << eta(1, 0) << "\t" << eta(2, 0) << ";\t"
289 <       << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t"
290 <       << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";";
291 <        
292 <    os << "\n";
288 >    Mat3x3d eta;
289 >    eta = s->getBarostat();
290 >
291 >    for (unsigned int i = 0; i < 3; i++) {
292 >      for (unsigned int j = 0; j < 3; j++) {
293 >        if (isinf(eta(i,j)) || isnan(eta(i,j))) {      
294 >          sprintf( painCave.errMsg,
295 >                   "DumpWriter detected a numerical error writing the barostat");
296 >          painCave.isFatal = 1;
297 >          simError();
298 >        }        
299 >      }
300 >    }
301 >
302 >    sprintf(buffer, "    Barostat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n",
303 >            eta(0, 0), eta(1, 0), eta(2, 0),
304 >            eta(0, 1), eta(1, 1), eta(2, 1),
305 >            eta(0, 2), eta(1, 2), eta(2, 2));
306 >    os << buffer;
307 >
308 >    os << "    </FrameData>\n";
309    }
310  
311    void DumpWriter::writeFrame(std::ostream& os) {
234    const int BUFFERSIZE = 2000;
235    const int MINIBUFFERSIZE = 100;
312  
313 <    char tempBuffer[BUFFERSIZE];
314 <    char writeLine[BUFFERSIZE];
313 > #ifdef IS_MPI
314 >    MPI_Status istatus;
315 > #endif
316  
240    Quat4d q;
241    Vector3d ji;
242    Vector3d pos;
243    Vector3d vel;
244    Vector3d frc;
245    Vector3d trq;
246
317      Molecule* mol;
318 <    StuntDouble* integrableObject;
318 >    StuntDouble* sd;
319      SimInfo::MoleculeIterator mi;
320      Molecule::IntegrableObjectIterator ii;
321 <  
252 <    int nTotObjects;    
253 <    nTotObjects = info_->getNGlobalIntegrableObjects();
321 >    RigidBody::AtomIterator ai;
322  
323   #ifndef IS_MPI
324 +    os << "  <Snapshot>\n";
325 +
326 +    writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot());
327  
328 +    os << "    <StuntDoubles>\n";
329 +    for (mol = info_->beginMolecule(mi); mol != NULL;
330 +         mol = info_->nextMolecule(mi)) {
331 +      
332 +      for (sd = mol->beginIntegrableObject(ii); sd != NULL;  
333 +           sd = mol->nextIntegrableObject(ii)) {        
334 +          os << prepareDumpLine(sd);
335 +          
336 +      }
337 +    }    
338 +    os << "    </StuntDoubles>\n";
339  
340 <    os << nTotObjects << "\n";
341 <        
342 <    writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
340 >    if (doSiteData_) {
341 >      os << "    <SiteData>\n";
342 >      for (mol = info_->beginMolecule(mi); mol != NULL;
343 >           mol = info_->nextMolecule(mi)) {
344 >              
345 >        for (sd = mol->beginIntegrableObject(ii); sd != NULL;  
346 >           sd = mol->nextIntegrableObject(ii)) {        
347  
348 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
348 >          int ioIndex = sd->getGlobalIntegrableObjectIndex();
349 >          // do one for the IO itself
350 >          os << prepareSiteLine(sd, ioIndex, 0);
351  
352 <      for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
353 <           integrableObject = mol->nextIntegrableObject(ii)) {
354 <                
352 >          if (sd->isRigidBody()) {
353 >            
354 >            RigidBody* rb = static_cast<RigidBody*>(sd);
355 >            int siteIndex = 0;
356 >            for (Atom* atom = rb->beginAtom(ai); atom != NULL;  
357 >                 atom = rb->nextAtom(ai)) {                                            
358 >              os << prepareSiteLine(atom, ioIndex, siteIndex);
359 >              siteIndex++;
360 >            }
361 >          }
362 >        }
363 >      }    
364 >      os << "    </SiteData>\n";
365 >    }
366 >    os << "  </Snapshot>\n";
367  
368 <        pos = integrableObject->getPos();
369 <        vel = integrableObject->getVel();
368 >    os.flush();
369 > #else
370  
371 <        sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
372 <                integrableObject->getType().c_str(),
373 <                pos[0], pos[1], pos[2],
274 <                vel[0], vel[1], vel[2]);
371 >    const int masterNode = 0;
372 >    int worldRank;
373 >    int nProc;
374  
375 <        strcpy(writeLine, tempBuffer);
375 >    MPI_Comm_size( MPI_COMM_WORLD, &nProc);
376 >    MPI_Comm_rank( MPI_COMM_WORLD, &worldRank);
377  
278        if (integrableObject->isDirectional()) {
279          q = integrableObject->getQ();
280          ji = integrableObject->getJ();
378  
379 <          sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf",
380 <                  q[0], q[1], q[2], q[3],
381 <                  ji[0], ji[1], ji[2]);
382 <          strcat(writeLine, tempBuffer);
383 <        } else {
384 <          strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0");
288 <        }
379 >    if (worldRank == masterNode) {      
380 >      os << "  <Snapshot>\n";  
381 >      writeFrameProperties(os,
382 >                           info_->getSnapshotManager()->getCurrentSnapshot());
383 >      os << "    <StuntDoubles>\n";
384 >    }
385  
386 <        if (needForceVector_) {
387 <          frc = integrableObject->getFrc();
388 <          trq = integrableObject->getTrq();
389 <          
390 <          sprintf(tempBuffer, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf",
391 <                  frc[0], frc[1], frc[2],
392 <                  trq[0], trq[1], trq[2]);
297 <          strcat(writeLine, tempBuffer);
298 <        }
299 <        
300 <        strcat(writeLine, "\n");
301 <        os << writeLine;
302 <
386 >    //every node prepares the dump lines for integrable objects belong to itself
387 >    std::string buffer;
388 >    for (mol = info_->beginMolecule(mi); mol != NULL;
389 >         mol = info_->nextMolecule(mi)) {
390 >      for (sd = mol->beginIntegrableObject(ii); sd != NULL;
391 >           sd = mol->nextIntegrableObject(ii)) {        
392 >        buffer += prepareDumpLine(sd);
393        }
394      }
395 +    
396 +    if (worldRank == masterNode) {      
397 +      os << buffer;
398 +      
399 +      for (int i = 1; i < nProc; ++i) {
400 +        // tell processor i to start sending us data:
401  
402 <    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;
402 >        MPI_Bcast(&i, 1, MPI_INT, masterNode, MPI_COMM_WORLD);
403  
404 <    int * potatoes;
405 <    int myPotato;
406 <    int nProc;
407 <    int which_node;
408 <    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;
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);
404 >        // receive the length of the string buffer that was
405 >        // prepared by processor i:        
406 >        int recvLength;
407 >        MPI_Recv(&recvLength, 1, MPI_INT, i, MPI_ANY_TAG, MPI_COMM_WORLD,
408 >                 &istatus);
409  
410 <    if (flag) {
411 <      MAXTAG = *tagub;
410 >        // create a buffer to receive the data
411 >        char* recvBuffer = new char[recvLength];
412 >        if (recvBuffer == NULL) {
413 >        } else {
414 >          // receive the data:
415 >          MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i,
416 >                               MPI_ANY_TAG, MPI_COMM_WORLD, &istatus);
417 >          // send it to the file:
418 >          os << recvBuffer;
419 >          // get rid of the receive buffer:
420 >          delete [] recvBuffer;
421 >        }
422 >      }
423      } else {
424 <      MAXTAG = 32767;
425 <    }
424 >      int sendBufferLength = buffer.size() + 1;
425 >      int myturn = 0;
426 >      for (int i = 1; i < nProc; ++i){
427 >        // wait for the master node to call our number:
428 >        MPI_Bcast(&myturn, 1, MPI_INT, masterNode, MPI_COMM_WORLD);
429 >        if (myturn == worldRank){
430 >          // send the length of our buffer:
431  
432 <    if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file
432 >          MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD);
433  
434 <      // Node 0 needs a list of the magic potatoes for each processor;
434 >          // send our buffer:
435 >          MPI_Send((void *)buffer.c_str(), sendBufferLength,
436 >                   MPI_CHAR, masterNode, 0, MPI_COMM_WORLD);
437  
438 <      MPI_Comm_size(MPI_COMM_WORLD, &nProc);
439 <      potatoes = new int[nProc];
438 >        }
439 >      }
440 >    }
441 >    
442 >    if (worldRank == masterNode) {      
443 >      os << "    </StuntDoubles>\n";
444 >    }
445  
446 <      //write out the comment lines
447 <      for(int i = 0; i < nProc; i++) {
448 <        potatoes[i] = 0;
446 >    if (doSiteData_) {
447 >      if (worldRank == masterNode) {
448 >        os << "    <SiteData>\n";
449        }
450 +      buffer.clear();
451 +      for (mol = info_->beginMolecule(mi); mol != NULL;
452 +           mol = info_->nextMolecule(mi)) {
453 +              
454 +        for (sd = mol->beginIntegrableObject(ii); sd != NULL;  
455 +             sd = mol->nextIntegrableObject(ii)) {      
456 +          
457 +          int ioIndex = sd->getGlobalIntegrableObjectIndex();
458 +          // do one for the IO itself
459 +          buffer += prepareSiteLine(sd, ioIndex, 0);
460  
461 +          if (sd->isRigidBody()) {
462 +            
463 +            RigidBody* rb = static_cast<RigidBody*>(sd);
464 +            int siteIndex = 0;
465 +            for (Atom* atom = rb->beginAtom(ai); atom != NULL;  
466 +                 atom = rb->nextAtom(ai)) {                                            
467 +              buffer += prepareSiteLine(atom, ioIndex, siteIndex);
468 +              siteIndex++;
469 +            }
470 +          }
471 +        }
472 +      }
473  
474 <      os << nTotObjects << "\n";
475 <      writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
474 >      if (worldRank == masterNode) {    
475 >        os << buffer;
476 >        
477 >        for (int i = 1; i < nProc; ++i) {
478 >          
479 >          // tell processor i to start sending us data:
480 >          MPI_Bcast(&i, 1, MPI_INT, masterNode, MPI_COMM_WORLD);
481 >          
482 >          // receive the length of the string buffer that was
483 >          // prepared by processor i:        
484 >          int recvLength;
485 >          MPI_Recv(&recvLength, 1, MPI_INT, i, MPI_ANY_TAG, MPI_COMM_WORLD,
486 >                   &istatus);
487 >          
488 >          // create a buffer to receive the data
489 >          char* recvBuffer = new char[recvLength];
490 >          if (recvBuffer == NULL) {
491 >          } else {
492 >            // receive the data:
493 >            MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i,
494 >                     MPI_ANY_TAG, MPI_COMM_WORLD, &istatus);
495 >            // send it to the file:
496 >            os << recvBuffer;
497 >            // get rid of the receive buffer:
498 >            delete [] recvBuffer;
499 >          }
500 >        }      
501 >      } else {
502 >        int sendBufferLength = buffer.size() + 1;
503 >        int myturn = 0;
504 >        for (int i = 1; i < nProc; ++i){
505 >          // wait for the master node to call our number:
506 >          MPI_Bcast(&myturn, 1, MPI_INT, masterNode, MPI_COMM_WORLD);
507 >          if (myturn == worldRank){
508 >            // send the length of our buffer:
509 >            MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD);
510 >            // send our buffer:
511 >            MPI_Send((void *)buffer.c_str(), sendBufferLength,
512 >                     MPI_CHAR, masterNode, 0, MPI_COMM_WORLD);
513 >          }
514 >        }
515 >      }
516 >      
517 >      if (worldRank == masterNode) {    
518 >        os << "    </SiteData>\n";
519 >      }
520 >    }
521 >    
522 >    if (worldRank == masterNode) {
523 >      os << "  </Snapshot>\n";
524 >      os.flush();
525 >    }
526 >    
527 > #endif // is_mpi
528 >    
529 >  }
530  
531 <      for(int i = 0; i < info_->getNGlobalMolecules(); i++) {
531 >  std::string DumpWriter::prepareDumpLine(StuntDouble* sd) {
532 >        
533 >    int index = sd->getGlobalIntegrableObjectIndex();
534 >    std::string type("pv");
535 >    std::string line;
536 >    char tempBuffer[4096];
537  
538 <        // Get the Node number which has this atom;
538 >    Vector3d pos;
539 >    Vector3d vel;
540 >    pos = sd->getPos();
541  
542 <        which_node = info_->getMolToProc(i);
542 >    if (isinf(pos[0]) || isnan(pos[0]) ||
543 >        isinf(pos[1]) || isnan(pos[1]) ||
544 >        isinf(pos[2]) || isnan(pos[2]) ) {      
545 >      sprintf( painCave.errMsg,
546 >               "DumpWriter detected a numerical error writing the position"
547 >               " for object %d", index);      
548 >      painCave.isFatal = 1;
549 >      simError();
550 >    }
551  
552 <        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:        
552 >    vel = sd->getVel();        
553  
554 <            potatoes[which_node] = 0;
555 <            MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0,
556 <                     MPI_COMM_WORLD);
557 <          }
554 >    if (isinf(vel[0]) || isnan(vel[0]) ||
555 >        isinf(vel[1]) || isnan(vel[1]) ||
556 >        isinf(vel[2]) || isnan(vel[2]) ) {      
557 >      sprintf( painCave.errMsg,
558 >               "DumpWriter detected a numerical error writing the velocity"
559 >               " for object %d", index);      
560 >      painCave.isFatal = 1;
561 >      simError();
562 >    }
563  
564 <          myPotato = potatoes[which_node];
565 <
566 <          //recieve the number of integrableObject in current molecule
567 <          MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato,
406 <                   MPI_COMM_WORLD, &istatus);
407 <          myPotato++;
564 >    sprintf(tempBuffer, "%18.10g %18.10g %18.10g %13e %13e %13e",
565 >            pos[0], pos[1], pos[2],
566 >            vel[0], vel[1], vel[2]);                    
567 >    line += tempBuffer;
568  
569 <          for(int l = 0; l < nCurObj; l++) {
570 <            if (potatoes[which_node] + 2 >= MAXTAG) {
571 <              // The potato was going to exceed the maximum value,
572 <              // so wrap this processor potato back to 0:        
569 >    if (sd->isDirectional()) {
570 >      type += "qj";
571 >      Quat4d q;
572 >      Vector3d ji;
573 >      q = sd->getQ();
574  
575 <              potatoes[which_node] = 0;
576 <              MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node,
577 <                       0, MPI_COMM_WORLD);
578 <            }
575 >      if (isinf(q[0]) || isnan(q[0]) ||
576 >          isinf(q[1]) || isnan(q[1]) ||
577 >          isinf(q[2]) || isnan(q[2]) ||
578 >          isinf(q[3]) || isnan(q[3]) ) {      
579 >        sprintf( painCave.errMsg,
580 >                 "DumpWriter detected a numerical error writing the quaternion"
581 >                 " for object %d", index);      
582 >        painCave.isFatal = 1;
583 >        simError();
584 >      }
585  
586 <            MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR,
420 <                     which_node, myPotato, MPI_COMM_WORLD,
421 <                     &istatus);
586 >      ji = sd->getJ();
587  
588 <            myPotato++;
588 >      if (isinf(ji[0]) || isnan(ji[0]) ||
589 >          isinf(ji[1]) || isnan(ji[1]) ||
590 >          isinf(ji[2]) || isnan(ji[2]) ) {      
591 >        sprintf( painCave.errMsg,
592 >                 "DumpWriter detected a numerical error writing the angular"
593 >                 " momentum for object %d", index);      
594 >        painCave.isFatal = 1;
595 >        simError();
596 >      }
597  
598 <            MPI_Recv(atomData, 19, MPI_REALTYPE, which_node, myPotato,
599 <                     MPI_COMM_WORLD, &istatus);
600 <            myPotato++;
598 >      sprintf(tempBuffer, " %13e %13e %13e %13e %13e %13e %13e",
599 >              q[0], q[1], q[2], q[3],
600 >              ji[0], ji[1], ji[2]);
601 >      line += tempBuffer;
602 >    }
603  
604 <            MPI_Get_count(&istatus, MPI_REALTYPE, &msgLen);
604 >    if (needForceVector_) {
605 >      type += "f";
606 >      Vector3d frc = sd->getFrc();
607 >      if (isinf(frc[0]) || isnan(frc[0]) ||
608 >          isinf(frc[1]) || isnan(frc[1]) ||
609 >          isinf(frc[2]) || isnan(frc[2]) ) {      
610 >        sprintf( painCave.errMsg,
611 >                 "DumpWriter detected a numerical error writing the force"
612 >                 " for object %d", index);      
613 >        painCave.isFatal = 1;
614 >        simError();
615 >      }
616 >      sprintf(tempBuffer, " %13e %13e %13e",
617 >              frc[0], frc[1], frc[2]);
618 >      line += tempBuffer;
619 >      
620 >      if (sd->isDirectional()) {
621 >        type += "t";
622 >        Vector3d trq = sd->getTrq();        
623 >        if (isinf(trq[0]) || isnan(trq[0]) ||
624 >            isinf(trq[1]) || isnan(trq[1]) ||
625 >            isinf(trq[2]) || isnan(trq[2]) ) {      
626 >          sprintf( painCave.errMsg,
627 >                   "DumpWriter detected a numerical error writing the torque"
628 >                   " for object %d", index);      
629 >          painCave.isFatal = 1;
630 >          simError();
631 >        }        
632 >        sprintf(tempBuffer, " %13e %13e %13e",
633 >                trq[0], trq[1], trq[2]);
634 >        line += tempBuffer;
635 >      }      
636 >    }
637  
638 <            if (msgLen == 13 || msgLen == 19)
639 <              isDirectional = 1;
640 <            else
434 <              isDirectional = 0;
638 >    sprintf(tempBuffer, "%10d %7s %s\n", index, type.c_str(), line.c_str());
639 >    return std::string(tempBuffer);
640 >  }
641  
642 <            // If we've survived to here, format the line:
642 >  std::string DumpWriter::prepareSiteLine(StuntDouble* sd, int ioIndex, int siteIndex) {
643 >    int storageLayout = info_->getSnapshotManager()->getStorageLayout();
644  
645 <            if (!isDirectional) {
646 <              sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
647 <                      MPIatomTypeString, atomData[0],
648 <                      atomData[1], atomData[2],
442 <                      atomData[3], atomData[4],
443 <                      atomData[5]);
645 >    std::string id;
646 >    std::string type;
647 >    std::string line;
648 >    char tempBuffer[4096];
649  
650 <              strcat(writeLine,
651 <                     "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0");
652 <            } else {
653 <              sprintf(writeLine,
654 <                      "%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",
655 <                      MPIatomTypeString,
656 <                      atomData[0],
657 <                      atomData[1],
658 <                      atomData[2],
659 <                      atomData[3],
660 <                      atomData[4],
661 <                      atomData[5],
662 <                      atomData[6],
663 <                      atomData[7],
664 <                      atomData[8],
665 <                      atomData[9],
666 <                      atomData[10],
667 <                      atomData[11],
668 <                      atomData[12]);
669 <            }
670 <            
671 <            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 <            }
650 >    if (sd->isRigidBody()) {
651 >      sprintf(tempBuffer, "%10d           ", ioIndex);
652 >      id = std::string(tempBuffer);
653 >    } else {
654 >      sprintf(tempBuffer, "%10d %10d", ioIndex, siteIndex);
655 >      id = std::string(tempBuffer);
656 >    }
657 >              
658 >    if (needFlucQ_) {
659 >      if (storageLayout & DataStorage::dslFlucQPosition) {
660 >        type += "c";
661 >        RealType fqPos = sd->getFlucQPos();
662 >        if (isinf(fqPos) || isnan(fqPos) ) {      
663 >          sprintf( painCave.errMsg,
664 >                   "DumpWriter detected a numerical error writing the"
665 >                   " fluctuating charge for object %s", id.c_str());      
666 >          painCave.isFatal = 1;
667 >          simError();
668 >        }
669 >        sprintf(tempBuffer, " %13e ", fqPos);
670 >        line += tempBuffer;
671 >      }
672  
673 <            sprintf(writeLine, "\n");
674 <            os << writeLine;
673 >      if (storageLayout & DataStorage::dslFlucQVelocity) {
674 >        type += "w";    
675 >        RealType fqVel = sd->getFlucQVel();
676 >        if (isinf(fqVel) || isnan(fqVel) ) {      
677 >          sprintf( painCave.errMsg,
678 >                   "DumpWriter detected a numerical error writing the"
679 >                   " fluctuating charge velocity for object %s", id.c_str());      
680 >          painCave.isFatal = 1;
681 >          simError();
682 >        }
683 >        sprintf(tempBuffer, " %13e ", fqVel);
684 >        line += tempBuffer;
685 >      }
686  
687 <          } // end for(int l =0)
688 <
689 <          potatoes[which_node] = myPotato;
690 <        } else { //master node has current molecule
691 <
692 <          mol = info_->getMoleculeByGlobalIndex(i);
693 <
694 <          if (mol == NULL) {
695 <            sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank);
696 <            painCave.isFatal = 1;
697 <            simError();
698 <          }
699 <                
700 <          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 <            
687 >      if (needForceVector_) {
688 >        if (storageLayout & DataStorage::dslFlucQForce) {          
689 >          type += "g";
690 >          RealType fqFrc = sd->getFlucQFrc();        
691 >          if (isinf(fqFrc) || isnan(fqFrc) ) {      
692 >            sprintf( painCave.errMsg,
693 >                     "DumpWriter detected a numerical error writing the"
694 >                     " fluctuating charge force for object %s", id.c_str());      
695 >            painCave.isFatal = 1;
696 >            simError();
697 >          }
698 >          sprintf(tempBuffer, " %13e ", fqFrc);        
699 >          line += tempBuffer;
700 >        }
701        }
748      sprintf(checkPointMsg, "Sucessfully took a dump.\n");
749      MPIcheckPoint();
702      }
703 +    
704 +    if (needElectricField_) {
705 +      if (storageLayout & DataStorage::dslElectricField) {
706 +        type += "e";
707 +        Vector3d eField= sd->getElectricField();
708 +        if (isinf(eField[0]) || isnan(eField[0]) ||
709 +            isinf(eField[1]) || isnan(eField[1]) ||
710 +            isinf(eField[2]) || isnan(eField[2]) ) {      
711 +          sprintf( painCave.errMsg,
712 +                   "DumpWriter detected a numerical error writing the electric"
713 +                   " field for object %s", id.c_str());      
714 +          painCave.isFatal = 1;
715 +          simError();
716 +        }
717 +        sprintf(tempBuffer, " %13e %13e %13e",
718 +                eField[0], eField[1], eField[2]);
719 +        line += tempBuffer;
720 +      }
721 +    }
722  
723 < #endif // is_mpi
724 <
723 >    if (needSitePotential_) {
724 >      if (storageLayout & DataStorage::dslSitePotential) {          
725 >        type += "s";
726 >        RealType sPot = sd->getSitePotential();        
727 >        if (isinf(sPot) || isnan(sPot) ) {      
728 >          sprintf( painCave.errMsg,
729 >                   "DumpWriter detected a numerical error writing the"
730 >                   " site potential for object %s", id.c_str());      
731 >          painCave.isFatal = 1;
732 >          simError();
733 >        }
734 >        sprintf(tempBuffer, " %13e ", sPot);        
735 >        line += tempBuffer;
736 >      }
737 >    }    
738 >    
739 >    if (needParticlePot_) {
740 >      if (storageLayout & DataStorage::dslParticlePot) {
741 >        type += "u";
742 >        RealType particlePot = sd->getParticlePot();
743 >        if (isinf(particlePot) || isnan(particlePot)) {      
744 >          sprintf( painCave.errMsg,
745 >                   "DumpWriter detected a numerical error writing the particle "
746 >                   " potential for object %s", id.c_str());      
747 >          painCave.isFatal = 1;
748 >          simError();
749 >        }
750 >        sprintf(tempBuffer, " %13e", particlePot);
751 >        line += tempBuffer;
752 >      }
753 >    }
754 >  
755 >    sprintf(tempBuffer, "%s %7s %s\n", id.c_str(), type.c_str(), line.c_str());
756 >    return std::string(tempBuffer);
757    }
758  
759    void DumpWriter::writeDump() {
# Line 758 | Line 761 | namespace oopse {
761    }
762  
763    void DumpWriter::writeEor() {
764 <    std::ostream* eorStream;
765 <    
764 >
765 >    std::ostream* eorStream = NULL;
766 >
767   #ifdef IS_MPI
768      if (worldRank == 0) {
769   #endif // is_mpi
770 <
770 >      
771        eorStream = createOStream(eorFilename_);
772  
773   #ifdef IS_MPI
774      }
775 < #endif // is_mpi    
776 <
775 > #endif
776 >    
777      writeFrame(*eorStream);
778 <
778 >      
779   #ifdef IS_MPI
780      if (worldRank == 0) {
781 < #endif // is_mpi
782 <    delete eorStream;
783 <
781 > #endif
782 >      
783 >      writeClosing(*eorStream);
784 >      delete eorStream;
785 >      
786   #ifdef IS_MPI
787      }
788   #endif // is_mpi  
# Line 790 | Line 796 | namespace oopse {
796   #ifdef IS_MPI
797      if (worldRank == 0) {
798   #endif // is_mpi
793
799        buffers.push_back(dumpFile_->rdbuf());
795
800        eorStream = createOStream(eorFilename_);
797
801        buffers.push_back(eorStream->rdbuf());
799        
802   #ifdef IS_MPI
803      }
804   #endif // is_mpi    
805  
806      TeeBuf tbuf(buffers.begin(), buffers.end());
807      std::ostream os(&tbuf);
806
808      writeFrame(os);
809  
810   #ifdef IS_MPI
811      if (worldRank == 0) {
812   #endif // is_mpi
813 <    delete eorStream;
814 <
813 >      writeClosing(*eorStream);
814 >      delete eorStream;
815   #ifdef IS_MPI
816      }
817 < #endif // is_mpi  
817 <    
817 > #endif // is_mpi      
818    }
819  
820 < std::ostream* DumpWriter::createOStream(const std::string& filename) {
820 >  std::ostream* DumpWriter::createOStream(const std::string& filename) {
821  
822      std::ostream* newOStream;
823 < #ifdef HAVE_LIBZ
823 > #ifdef HAVE_ZLIB
824      if (needCompression_) {
825 <        newOStream = new ogzstream(filename.c_str());
825 >      newOStream = new ogzstream(filename.c_str());
826      } else {
827 <        newOStream = new std::ofstream(filename.c_str());
827 >      newOStream = new std::ofstream(filename.c_str());
828      }
829   #else
830      newOStream = new std::ofstream(filename.c_str());
831   #endif
832 +    //write out MetaData first
833 +    (*newOStream) << "<OpenMD version=2>" << std::endl;
834 +    (*newOStream) << "  <MetaData>" << std::endl;
835 +    (*newOStream) << info_->getRawMetaData();
836 +    (*newOStream) << "  </MetaData>" << std::endl;
837      return newOStream;
838 < }
838 >  }
839  
840 < }//end namespace oopse
840 >  void DumpWriter::writeClosing(std::ostream& os) {
841 >
842 >    os << "</OpenMD>\n";
843 >    os.flush();
844 >  }
845 >
846 > }//end namespace OpenMD

Comparing trunk/src/io/DumpWriter.cpp (property svn:keywords):
Revision 963 by tim, Wed May 17 21:51:42 2006 UTC vs.
Revision 2020 by gezelter, Mon Sep 22 19:18:35 2014 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines