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

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

Comparing:
trunk/src/io/DumpWriter.cpp (property svn:keywords), Revision 965 by tim, Fri May 19 20:45:55 2006 UTC vs.
branches/development/src/io/DumpWriter.cpp (property svn:keywords), Revision 1764 by gezelter, Tue Jul 3 18:32:27 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines