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 726 by chrisfen, Fri Nov 11 15:22:11 2005 UTC vs.
branches/development/src/io/DumpWriter.cpp (file contents), Revision 1752 by gezelter, Sun Jun 10 14:05:02 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
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
86 +        
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 +      }
95  
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
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_);
138  
139 <        dumpFile_ = createOStream(filename_);
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  
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
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 +  }
153 +  
154 +  DumpWriter::DumpWriter(SimInfo* info, const std::string& filename, bool writeDumpFile)
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 +    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";
175 +      eorFilename_ += ".gz";
176 +    }
177 + #endif
178 +    
179 + #ifdef IS_MPI
180 +    
181 +    if (worldRank == 0) {
182 + #endif // is_mpi
183 +      
184 +      createDumpFile_ = writeDumpFile;
185 +      if (createDumpFile_) {
186 +        dumpFile_ = createOStream(filename_);
187 +      
188 +        if (!dumpFile_) {
189 +          sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
190 +                  filename_.c_str());
191 +          painCave.isFatal = 1;
192 +          simError();
193 +        }
194 +      }
195 + #ifdef IS_MPI
196 +      
197      }
198  
199 +    
200 + #endif // is_mpi
201 +    
202 +  }
203 +
204    DumpWriter::~DumpWriter() {
205  
206   #ifdef IS_MPI
207  
208      if (worldRank == 0) {
209   #endif // is_mpi
210 <
211 <      delete dumpFile_;
212 <
210 >      if (createDumpFile_){
211 >        writeClosing(*dumpFile_);
212 >        delete dumpFile_;
213 >      }
214   #ifdef IS_MPI
215  
216      }
# Line 152 | 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 <    double currentTime;
225 <    Mat3x3d hmat;
226 <    double chi;
227 <    double 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 >    RealType chi = s->getChi();
261 >    RealType integralOfChiDt = s->getIntegralOfChiDt();
262 >    if (isinf(chi) || isnan(chi) ||
263 >        isinf(integralOfChiDt) || isnan(integralOfChiDt)) {      
264 >      sprintf( painCave.errMsg,
265 >               "DumpWriter detected a numerical error writing the thermostat");
266 >      painCave.isFatal = 1;
267 >      simError();
268 >    }
269 >    sprintf(buffer, "  Thermostat: %.10g , %.10g\n", chi, integralOfChiDt);
270 >    os << buffer;
271  
272 <    os << chi << "\t" << integralOfChiDt << "\t;";
272 >    Mat3x3d eta;
273 >    eta = s->getEta();
274  
275 <    os << eta(0, 0) << "\t" << eta(1, 0) << "\t" << eta(2, 0) << ";\t"
276 <       << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t"
277 <       << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";";
278 <        
279 <    os << "\n";
275 >    for (unsigned int i = 0; i < 3; i++) {
276 >      for (unsigned int j = 0; j < 3; j++) {
277 >        if (isinf(eta(i,j)) || isnan(eta(i,j))) {      
278 >          sprintf( painCave.errMsg,
279 >                   "DumpWriter detected a numerical error writing the barostat");
280 >          painCave.isFatal = 1;
281 >          simError();
282 >        }        
283 >      }
284 >    }
285 >
286 >    sprintf(buffer, "    Barostat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n",
287 >            eta(0, 0), eta(1, 0), eta(2, 0),
288 >            eta(0, 1), eta(1, 1), eta(2, 1),
289 >            eta(0, 2), eta(1, 2), eta(2, 2));
290 >    os << buffer;
291 >
292 >    os << "    </FrameData>\n";
293    }
294  
295    void DumpWriter::writeFrame(std::ostream& os) {
186    const int BUFFERSIZE = 2000;
187    const int MINIBUFFERSIZE = 100;
296  
297 <    char tempBuffer[BUFFERSIZE];
298 <    char writeLine[BUFFERSIZE];
297 > #ifdef IS_MPI
298 >    MPI_Status istatus;
299 > #endif
300  
192    Quat4d q;
193    Vector3d ji;
194    Vector3d pos;
195    Vector3d vel;
196    Vector3d frc;
197    Vector3d trq;
198
301      Molecule* mol;
302      StuntDouble* integrableObject;
303      SimInfo::MoleculeIterator mi;
304      Molecule::IntegrableObjectIterator ii;
305 <  
306 <    int nTotObjects;    
205 <    nTotObjects = info_->getNGlobalIntegrableObjects();
305 >    RigidBody::AtomIterator ai;
306 >    Atom* atom;
307  
308   #ifndef IS_MPI
309 +    os << "  <Snapshot>\n";
310 +
311 +    writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot());
312  
313 <
210 <    os << nTotObjects << "\n";
211 <        
212 <    writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
213 <
313 >    os << "    <StuntDoubles>\n";
314      for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
315  
316 <      for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
317 <           integrableObject = mol->nextIntegrableObject(ii)) {
318 <                
316 >      
317 >      for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;  
318 >           integrableObject = mol->nextIntegrableObject(ii)) {  
319 >          os << prepareDumpLine(integrableObject);
320 >          
321 >      }
322 >    }    
323 >    os << "    </StuntDoubles>\n";
324  
325 <        pos = integrableObject->getPos();
326 <        vel = integrableObject->getVel();
325 >    if (doSiteData_) {
326 >      os << "    <SiteData>\n";
327 >      for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
328 >              
329 >        for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;  
330 >           integrableObject = mol->nextIntegrableObject(ii)) {  
331  
332 <        sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
333 <                integrableObject->getType().c_str(),
334 <                pos[0], pos[1], pos[2],
226 <                vel[0], vel[1], vel[2]);
332 >          int ioIndex = integrableObject->getGlobalIntegrableObjectIndex();
333 >          // do one for the IO itself
334 >          os << prepareSiteLine(integrableObject, ioIndex, 0);
335  
336 <        strcpy(writeLine, tempBuffer);
336 >          if (integrableObject->isRigidBody()) {
337 >            
338 >            RigidBody* rb = static_cast<RigidBody*>(integrableObject);
339 >            int siteIndex = 0;
340 >            for (atom = rb->beginAtom(ai); atom != NULL;  
341 >                 atom = rb->nextAtom(ai)) {                                            
342 >              os << prepareSiteLine(atom, ioIndex, siteIndex);
343 >              siteIndex++;
344 >            }
345 >          }
346 >        }
347 >      }    
348 >      os << "    </SiteData>\n";
349 >    }
350 >    os << "  </Snapshot>\n";
351  
352 <        if (integrableObject->isDirectional()) {
353 <          q = integrableObject->getQ();
354 <          ji = integrableObject->getJ();
352 >    os.flush();
353 > #else
354 >    //every node prepares the dump lines for integrable objects belong to itself
355 >    std::string buffer;
356 >    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
357  
234          sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf",
235                  q[0], q[1], q[2], q[3],
236                  ji[0], ji[1], ji[2]);
237          strcat(writeLine, tempBuffer);
238        } else {
239          strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0");
240        }
358  
359 <        if (needForceVector_) {
360 <          frc = integrableObject->getFrc();
361 <          trq = integrableObject->getTrq();
245 <          
246 <          sprintf(tempBuffer, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf",
247 <                  frc[0], frc[1], frc[2],
248 <                  trq[0], trq[1], trq[2]);
249 <          strcat(writeLine, tempBuffer);
250 <        }
251 <        
252 <        strcat(writeLine, "\n");
253 <        os << writeLine;
254 <
359 >      for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
360 >           integrableObject = mol->nextIntegrableObject(ii)) {  
361 >          buffer += prepareDumpLine(integrableObject);
362        }
363      }
364 <
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 <     *********************************************************************/
364 >    
365      const int masterNode = 0;
297
298    int * potatoes;
299    int myPotato;
366      int nProc;
367 <    int which_node;
368 <    double atomData[19];
369 <    int isDirectional;
370 <    char MPIatomTypeString[MINIBUFFERSIZE];
371 <    int msgLen; // the length of message actually recieved at master nodes
372 <    int haveError;
373 <    MPI_Status istatus;
308 <    int nCurObj;
309 <    
310 <    // code to find maximum tag value
311 <    int * tagub;
312 <    int flag;
313 <    int MAXTAG;
314 <    MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag);
367 >    MPI_Comm_size(MPI_COMM_WORLD, &nProc);
368 >    if (worldRank == masterNode) {      
369 >      os << "  <Snapshot>\n";  
370 >      writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot());
371 >      os << "    <StuntDoubles>\n";
372 >        
373 >      os << buffer;
374  
375 <    if (flag) {
376 <      MAXTAG = *tagub;
375 >      for (int i = 1; i < nProc; ++i) {
376 >
377 >        // receive the length of the string buffer that was
378 >        // prepared by processor i
379 >
380 >        MPI_Bcast(&i, 1, MPI_INT,masterNode,MPI_COMM_WORLD);
381 >        int recvLength;
382 >        MPI_Recv(&recvLength, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &istatus);
383 >        char* recvBuffer = new char[recvLength];
384 >        if (recvBuffer == NULL) {
385 >        } else {
386 >          MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i, 0, MPI_COMM_WORLD, &istatus);
387 >          os << recvBuffer;
388 >          delete [] recvBuffer;
389 >        }
390 >      }
391 >      os << "    </StuntDoubles>\n";
392 >      
393 >      os << "  </Snapshot>\n";
394 >      os.flush();
395      } else {
396 <      MAXTAG = 32767;
396 >      int sendBufferLength = buffer.size() + 1;
397 >      int myturn = 0;
398 >      for (int i = 1; i < nProc; ++i){
399 >        MPI_Bcast(&myturn,1, MPI_INT,masterNode,MPI_COMM_WORLD);
400 >        if (myturn == worldRank){
401 >          MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD);
402 >          MPI_Send((void *)buffer.c_str(), sendBufferLength, MPI_CHAR, masterNode, 0, MPI_COMM_WORLD);
403 >        }
404 >      }
405      }
406  
407 <    if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file
407 > #endif // is_mpi
408  
409 <      // Node 0 needs a list of the magic potatoes for each processor;
409 >  }
410  
411 <      MPI_Comm_size(MPI_COMM_WORLD, &nProc);
412 <      potatoes = new int[nProc];
411 >  std::string DumpWriter::prepareDumpLine(StuntDouble* integrableObject) {
412 >        
413 >    int index = integrableObject->getGlobalIntegrableObjectIndex();
414 >    std::string type("pv");
415 >    std::string line;
416 >    char tempBuffer[4096];
417  
418 <      //write out the comment lines
419 <      for(int i = 0; i < nProc; i++) {
420 <        potatoes[i] = 0;
332 <      }
418 >    Vector3d pos;
419 >    Vector3d vel;
420 >    pos = integrableObject->getPos();
421  
422 +    if (isinf(pos[0]) || isnan(pos[0]) ||
423 +        isinf(pos[1]) || isnan(pos[1]) ||
424 +        isinf(pos[2]) || isnan(pos[2]) ) {      
425 +      sprintf( painCave.errMsg,
426 +               "DumpWriter detected a numerical error writing the position"
427 +               " for object %d", index);      
428 +      painCave.isFatal = 1;
429 +      simError();
430 +    }
431  
432 <      os << nTotObjects << "\n";
336 <      writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
432 >    vel = integrableObject->getVel();          
433  
434 <      for(int i = 0; i < info_->getNGlobalMolecules(); i++) {
434 >    if (isinf(vel[0]) || isnan(vel[0]) ||
435 >        isinf(vel[1]) || isnan(vel[1]) ||
436 >        isinf(vel[2]) || isnan(vel[2]) ) {      
437 >      sprintf( painCave.errMsg,
438 >               "DumpWriter detected a numerical error writing the velocity"
439 >               " for object %d", index);      
440 >      painCave.isFatal = 1;
441 >      simError();
442 >    }
443  
444 <        // Get the Node number which has this atom;
444 >    sprintf(tempBuffer, "%18.10g %18.10g %18.10g %13e %13e %13e",
445 >            pos[0], pos[1], pos[2],
446 >            vel[0], vel[1], vel[2]);                    
447 >    line += tempBuffer;
448  
449 <        which_node = info_->getMolToProc(i);
449 >    if (integrableObject->isDirectional()) {
450 >      type += "qj";
451 >      Quat4d q;
452 >      Vector3d ji;
453 >      q = integrableObject->getQ();
454  
455 <        if (which_node != masterNode) { //current molecule is in slave node
456 <          if (potatoes[which_node] + 1 >= MAXTAG) {
457 <            // The potato was going to exceed the maximum value,
458 <            // so wrap this processor potato back to 0:        
455 >      if (isinf(q[0]) || isnan(q[0]) ||
456 >          isinf(q[1]) || isnan(q[1]) ||
457 >          isinf(q[2]) || isnan(q[2]) ||
458 >          isinf(q[3]) || isnan(q[3]) ) {      
459 >        sprintf( painCave.errMsg,
460 >                 "DumpWriter detected a numerical error writing the quaternion"
461 >                 " for object %d", index);      
462 >        painCave.isFatal = 1;
463 >        simError();
464 >      }
465  
466 <            potatoes[which_node] = 0;
350 <            MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0,
351 <                     MPI_COMM_WORLD);
352 <          }
466 >      ji = integrableObject->getJ();
467  
468 <          myPotato = potatoes[which_node];
468 >      if (isinf(ji[0]) || isnan(ji[0]) ||
469 >          isinf(ji[1]) || isnan(ji[1]) ||
470 >          isinf(ji[2]) || isnan(ji[2]) ) {      
471 >        sprintf( painCave.errMsg,
472 >                 "DumpWriter detected a numerical error writing the angular"
473 >                 " momentum for object %d", index);      
474 >        painCave.isFatal = 1;
475 >        simError();
476 >      }
477  
478 <          //recieve the number of integrableObject in current molecule
479 <          MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato,
480 <                   MPI_COMM_WORLD, &istatus);
481 <          myPotato++;
478 >      sprintf(tempBuffer, " %13e %13e %13e %13e %13e %13e %13e",
479 >              q[0], q[1], q[2], q[3],
480 >              ji[0], ji[1], ji[2]);
481 >      line += tempBuffer;
482 >    }
483  
484 <          for(int l = 0; l < nCurObj; l++) {
485 <            if (potatoes[which_node] + 2 >= MAXTAG) {
486 <              // The potato was going to exceed the maximum value,
487 <              // so wrap this processor potato back to 0:        
484 >    if (needForceVector_) {
485 >      type += "f";
486 >      Vector3d frc = integrableObject->getFrc();
487 >      if (isinf(frc[0]) || isnan(frc[0]) ||
488 >          isinf(frc[1]) || isnan(frc[1]) ||
489 >          isinf(frc[2]) || isnan(frc[2]) ) {      
490 >        sprintf( painCave.errMsg,
491 >                 "DumpWriter detected a numerical error writing the force"
492 >                 " for object %d", index);      
493 >        painCave.isFatal = 1;
494 >        simError();
495 >      }
496 >      sprintf(tempBuffer, " %13e %13e %13e",
497 >              frc[0], frc[1], frc[2]);
498 >      line += tempBuffer;
499 >      
500 >      if (integrableObject->isDirectional()) {
501 >        type += "t";
502 >        Vector3d trq = integrableObject->getTrq();        
503 >        if (isinf(trq[0]) || isnan(trq[0]) ||
504 >            isinf(trq[1]) || isnan(trq[1]) ||
505 >            isinf(trq[2]) || isnan(trq[2]) ) {      
506 >          sprintf( painCave.errMsg,
507 >                   "DumpWriter detected a numerical error writing the torque"
508 >                   " for object %d", index);      
509 >          painCave.isFatal = 1;
510 >          simError();
511 >        }        
512 >        sprintf(tempBuffer, " %13e %13e %13e",
513 >                trq[0], trq[1], trq[2]);
514 >        line += tempBuffer;
515 >      }      
516 >    }
517  
518 <              potatoes[which_node] = 0;
519 <              MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node,
520 <                       0, MPI_COMM_WORLD);
369 <            }
518 >    sprintf(tempBuffer, "%10d %7s %s\n", index, type.c_str(), line.c_str());
519 >    return std::string(tempBuffer);
520 >  }
521  
522 <            MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR,
523 <                     which_node, myPotato, MPI_COMM_WORLD,
373 <                     &istatus);
522 >  std::string DumpWriter::prepareSiteLine(StuntDouble* integrableObject, int ioIndex, int siteIndex) {
523 >        
524  
525 <            myPotato++;
525 >    std::string id;
526 >    std::string type;
527 >    std::string line;
528 >    char tempBuffer[4096];
529  
530 <            MPI_Recv(atomData, 19, MPI_DOUBLE, which_node, myPotato,
531 <                     MPI_COMM_WORLD, &istatus);
532 <            myPotato++;
530 >    if (integrableObject->isRigidBody()) {
531 >      sprintf(tempBuffer, "%10d           ", ioIndex);
532 >      id = std::string(tempBuffer);
533 >    } else {
534 >      sprintf(tempBuffer, "%10d %10d", ioIndex, siteIndex);
535 >      id = std::string(tempBuffer);
536 >    }
537 >              
538 >    if (needFlucQ_) {
539 >      type += "cw";
540 >      RealType fqPos = integrableObject->getFlucQPos();
541 >      if (isinf(fqPos) || isnan(fqPos) ) {      
542 >        sprintf( painCave.errMsg,
543 >                 "DumpWriter detected a numerical error writing the"
544 >                 " fluctuating charge for object %s", id.c_str());      
545 >        painCave.isFatal = 1;
546 >        simError();
547 >      }
548 >      sprintf(tempBuffer, " %13e ", fqPos);
549 >      line += tempBuffer;
550 >    
551 >      RealType fqVel = integrableObject->getFlucQVel();
552 >      if (isinf(fqVel) || isnan(fqVel) ) {      
553 >        sprintf( painCave.errMsg,
554 >                 "DumpWriter detected a numerical error writing the"
555 >                 " fluctuating charge velocity for object %s", id.c_str());      
556 >        painCave.isFatal = 1;
557 >        simError();
558 >      }
559 >      sprintf(tempBuffer, " %13e ", fqVel);
560 >      line += tempBuffer;
561  
562 <            MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen);
562 >      if (needForceVector_) {
563 >        type += "g";
564 >        RealType fqFrc = integrableObject->getFlucQFrc();        
565 >        if (isinf(fqFrc) || isnan(fqFrc) ) {      
566 >          sprintf( painCave.errMsg,
567 >                   "DumpWriter detected a numerical error writing the"
568 >                   " fluctuating charge force for object %s", id.c_str());      
569 >          painCave.isFatal = 1;
570 >          simError();
571 >        }
572 >        sprintf(tempBuffer, " %13e ", fqFrc);        
573 >        line += tempBuffer;
574 >      }
575 >    }
576  
577 <            if (msgLen == 13 || msgLen == 19)
578 <              isDirectional = 1;
579 <            else
580 <              isDirectional = 0;
577 >    if (needElectricField_) {
578 >      type += "e";
579 >      Vector3d eField= integrableObject->getElectricField();
580 >      if (isinf(eField[0]) || isnan(eField[0]) ||
581 >          isinf(eField[1]) || isnan(eField[1]) ||
582 >          isinf(eField[2]) || isnan(eField[2]) ) {      
583 >        sprintf( painCave.errMsg,
584 >                 "DumpWriter detected a numerical error writing the electric"
585 >                 " field for object %s", id.c_str());      
586 >        painCave.isFatal = 1;
587 >        simError();
588 >      }
589 >      sprintf(tempBuffer, " %13e %13e %13e",
590 >              eField[0], eField[1], eField[2]);
591 >      line += tempBuffer;
592 >    }
593  
388            // If we've survived to here, format the line:
594  
595 <            if (!isDirectional) {
596 <              sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
597 <                      MPIatomTypeString, atomData[0],
598 <                      atomData[1], atomData[2],
599 <                      atomData[3], atomData[4],
600 <                      atomData[5]);
601 <
602 <              strcat(writeLine,
603 <                     "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0");
399 <            } else {
400 <              sprintf(writeLine,
401 <                      "%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",
402 <                      MPIatomTypeString,
403 <                      atomData[0],
404 <                      atomData[1],
405 <                      atomData[2],
406 <                      atomData[3],
407 <                      atomData[4],
408 <                      atomData[5],
409 <                      atomData[6],
410 <                      atomData[7],
411 <                      atomData[8],
412 <                      atomData[9],
413 <                      atomData[10],
414 <                      atomData[11],
415 <                      atomData[12]);
416 <            }
417 <            
418 <            if (needForceVector_) {
419 <              if (!isDirectional) {
420 <                sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf",
421 <                        atomData[6],
422 <                        atomData[7],
423 <                        atomData[8],
424 <                        atomData[9],
425 <                        atomData[10],
426 <                        atomData[11]);
427 <              } else {
428 <                sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf",
429 <                        atomData[13],
430 <                        atomData[14],
431 <                        atomData[15],
432 <                        atomData[16],
433 <                        atomData[17],
434 <                        atomData[18]);
435 <              }
436 <            }
437 <
438 <            sprintf(writeLine, "\n");
439 <            os << writeLine;
440 <
441 <          } // end for(int l =0)
442 <
443 <          potatoes[which_node] = myPotato;
444 <        } else { //master node has current molecule
445 <
446 <          mol = info_->getMoleculeByGlobalIndex(i);
447 <
448 <          if (mol == NULL) {
449 <            sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank);
450 <            painCave.isFatal = 1;
451 <            simError();
452 <          }
453 <                
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 <            
595 >    if (needParticlePot_) {
596 >      type += "u";
597 >      RealType particlePot = integrableObject->getParticlePot();
598 >      if (isinf(particlePot) || isnan(particlePot)) {      
599 >        sprintf( painCave.errMsg,
600 >                 "DumpWriter detected a numerical error writing the particle "
601 >                 " potential for object %s", id.c_str());      
602 >        painCave.isFatal = 1;
603 >        simError();
604        }
605 <      sprintf(checkPointMsg, "Sucessfully took a dump.\n");
606 <      MPIcheckPoint();
605 >      sprintf(tempBuffer, " %13e", particlePot);
606 >      line += tempBuffer;
607      }
608 +    
609  
610 < #endif // is_mpi
611 <
610 >    sprintf(tempBuffer, "%s %7s %s\n", id.c_str(), type.c_str(), line.c_str());
611 >    return std::string(tempBuffer);
612    }
613  
614    void DumpWriter::writeDump() {
# Line 727 | Line 633 | namespace oopse {
633   #ifdef IS_MPI
634      if (worldRank == 0) {
635   #endif // is_mpi
636 <    delete eorStream;
637 <
636 >      writeClosing(*eorStream);
637 >      delete eorStream;
638   #ifdef IS_MPI
639      }
640   #endif // is_mpi  
# Line 761 | Line 667 | namespace oopse {
667   #ifdef IS_MPI
668      if (worldRank == 0) {
669   #endif // is_mpi
670 <    delete eorStream;
671 <
670 >      writeClosing(*eorStream);
671 >      delete eorStream;
672   #ifdef IS_MPI
673      }
674   #endif // is_mpi  
675      
676    }
677  
678 < std::ostream* DumpWriter::createOStream(const std::string& filename) {
678 >  std::ostream* DumpWriter::createOStream(const std::string& filename) {
679  
680      std::ostream* newOStream;
681   #ifdef HAVE_LIBZ
682      if (needCompression_) {
683 <        newOStream = new ogzstream(filename.c_str());
683 >      newOStream = new ogzstream(filename.c_str());
684      } else {
685 <        newOStream = new std::ofstream(filename.c_str());
685 >      newOStream = new std::ofstream(filename.c_str());
686      }
687   #else
688      newOStream = new std::ofstream(filename.c_str());
689   #endif
690 +    //write out MetaData first
691 +    (*newOStream) << "<OpenMD version=2>" << std::endl;
692 +    (*newOStream) << "  <MetaData>" << std::endl;
693 +    (*newOStream) << info_->getRawMetaData();
694 +    (*newOStream) << "  </MetaData>" << std::endl;
695      return newOStream;
696 < }
696 >  }
697  
698 < }//end namespace oopse
698 >  void DumpWriter::writeClosing(std::ostream& os) {
699 >
700 >    os << "</OpenMD>\n";
701 >    os.flush();
702 >  }
703 >
704 > }//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.
branches/development/src/io/DumpWriter.cpp (property svn:keywords), Revision 1752 by gezelter, Sun Jun 10 14:05:02 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines