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

Comparing trunk/src/io/DumpWriter.cpp (property svn:keywords):
Revision 726 by chrisfen, Fri Nov 11 15:22:11 2005 UTC vs.
Revision 1938 by gezelter, Thu Oct 31 15:32:17 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines