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 615 by tim, Tue Sep 20 21:22:38 2005 UTC vs.
Revision 1025 by gezelter, Wed Aug 30 20:33:44 2006 UTC

# Line 57 | Line 57 | namespace oopse {
57  
58      Globals* simParams = info->getSimParams();
59      needCompression_ = simParams->getCompressDumpFile();
60 <
60 >    needForceVector_ = simParams->getOutputForceVector();
61 >    createDumpFile_ = true;
62 > #ifdef HAVE_LIBZ
63      if (needCompression_) {
64 <        filename_ += ".gz";
65 <        eorFilename_ += ".gz";
64 >      filename_ += ".gz";
65 >      eorFilename_ += ".gz";
66      }
67 + #endif
68      
69   #ifdef IS_MPI
70  
71 <      if (worldRank == 0) {
71 >    if (worldRank == 0) {
72   #endif // is_mpi
73 +        
74 +      dumpFile_ = createOStream(filename_);
75  
76 +      if (!dumpFile_) {
77 +        sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
78 +                filename_.c_str());
79 +        painCave.isFatal = 1;
80 +        simError();
81 +      }
82  
72        dumpFile_ = createOStream(filename_);
73
74        if (!dumpFile_) {
75          sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
76                  filename_.c_str());
77          painCave.isFatal = 1;
78          simError();
79        }
80
83   #ifdef IS_MPI
84  
85 <      }
85 >    }
86  
85      sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
86      MPIcheckPoint();
87
87   #endif // is_mpi
88  
89 <    }
89 >  }
90  
91  
92    DumpWriter::DumpWriter(SimInfo* info, const std::string& filename)
# Line 97 | Line 96 | namespace oopse {
96      eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor";    
97  
98      needCompression_ = simParams->getCompressDumpFile();
99 +    needForceVector_ = simParams->getOutputForceVector();
100 +    createDumpFile_ = true;
101 + #ifdef HAVE_LIBZ
102      if (needCompression_) {
103 <        filename_ += ".gz";
104 <        eorFilename_ += ".gz";
103 >      filename_ += ".gz";
104 >      eorFilename_ += ".gz";
105      }
106 + #endif
107      
108   #ifdef IS_MPI
109  
110 <      if (worldRank == 0) {
110 >    if (worldRank == 0) {
111   #endif // is_mpi
112  
113 +      
114 +      dumpFile_ = createOStream(filename_);
115  
116 <        dumpFile_ = createOStream(filename_);
116 >      if (!dumpFile_) {
117 >        sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
118 >                filename_.c_str());
119 >        painCave.isFatal = 1;
120 >        simError();
121 >      }
122  
113        if (!dumpFile_) {
114          sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
115                  filename_.c_str());
116          painCave.isFatal = 1;
117          simError();
118        }
119
123   #ifdef IS_MPI
124  
125 <      }
125 >    }
126  
124      sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
125      MPIcheckPoint();
126
127   #endif // is_mpi
128  
129 +  }
130 +  
131 +  DumpWriter::DumpWriter(SimInfo* info, const std::string& filename, bool writeDumpFile)
132 +    : info_(info), filename_(filename){
133 +    
134 +    Globals* simParams = info->getSimParams();
135 +    eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor";    
136 +    
137 +    needCompression_ = simParams->getCompressDumpFile();
138 +    needForceVector_ = simParams->getOutputForceVector();
139 +    
140 + #ifdef HAVE_LIBZ
141 +    if (needCompression_) {
142 +      filename_ += ".gz";
143 +      eorFilename_ += ".gz";
144      }
145 + #endif
146 +    
147 + #ifdef IS_MPI
148 +    
149 +    if (worldRank == 0) {
150 + #endif // is_mpi
151 +      
152 +      createDumpFile_ = writeDumpFile;
153 +      if (createDumpFile_) {
154 +        dumpFile_ = createOStream(filename_);
155 +      
156 +        if (!dumpFile_) {
157 +          sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
158 +                  filename_.c_str());
159 +          painCave.isFatal = 1;
160 +          simError();
161 +        }
162 +      }
163 + #ifdef IS_MPI
164 +      
165 +    }
166  
167 +    
168 + #endif // is_mpi
169 +    
170 +  }
171 +
172    DumpWriter::~DumpWriter() {
173  
174   #ifdef IS_MPI
175  
176      if (worldRank == 0) {
177   #endif // is_mpi
178 <
179 <      delete dumpFile_;
180 <
178 >      if (createDumpFile_){
179 >        writeClosing(*dumpFile_);
180 >        delete dumpFile_;
181 >      }
182   #ifdef IS_MPI
183  
184      }
# Line 145 | Line 187 | namespace oopse {
187  
188    }
189  
190 <  void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) {
190 >  void DumpWriter::writeFrameProperties(std::ostream& os, Snapshot* s) {
191  
192 <    double currentTime;
192 >    char buffer[1024];
193 >
194 >    os << "    <FrameData>\n";
195 >
196 >    RealType currentTime = s->getTime();
197 >    sprintf(buffer, "        Time: %.10g\n", currentTime);
198 >    os << buffer;
199 >
200      Mat3x3d hmat;
152    double chi;
153    double integralOfChiDt;
154    Mat3x3d eta;
155    
156    currentTime = s->getTime();
201      hmat = s->getHmat();
202 <    chi = s->getChi();
203 <    integralOfChiDt = s->getIntegralOfChiDt();
204 <    eta = s->getEta();
205 <    
206 <    os << currentTime << ";\t"
163 <       << hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t"
164 <       << hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t"
165 <       << hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t";
202 >    sprintf(buffer, "        Hmat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n",
203 >            hmat(0, 0), hmat(1, 0), hmat(2, 0),
204 >            hmat(0, 1), hmat(1, 1), hmat(2, 1),
205 >            hmat(0, 2), hmat(1, 2), hmat(2, 2));
206 >    os << buffer;
207  
208 <    //write out additional parameters, such as chi and eta
208 >    RealType chi = s->getChi();
209 >    RealType integralOfChiDt = s->getIntegralOfChiDt();
210 >    sprintf(buffer, "  Thermostat: %.10g , %.10g\n", chi, integralOfChiDt);
211 >    os << buffer;
212  
213 <    os << chi << "\t" << integralOfChiDt << "\t;";
213 >    Mat3x3d eta;
214 >    eta = s->getEta();
215 >    sprintf(buffer, "    Barostat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n",
216 >            eta(0, 0), eta(1, 0), eta(2, 0),
217 >            eta(0, 1), eta(1, 1), eta(2, 1),
218 >            eta(0, 2), eta(1, 2), eta(2, 2));
219 >    os << buffer;
220  
221 <    os << eta(0, 0) << "\t" << eta(1, 0) << "\t" << eta(2, 0) << ";\t"
172 <       << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t"
173 <       << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";";
174 <        
175 <    os << "\n";
221 >    os << "    </FrameData>\n";
222    }
223  
224    void DumpWriter::writeFrame(std::ostream& os) {
179    const int BUFFERSIZE = 2000;
180    const int MINIBUFFERSIZE = 100;
225  
226 <    char tempBuffer[BUFFERSIZE];
227 <    char writeLine[BUFFERSIZE];
228 <
185 <    Quat4d q;
186 <    Vector3d ji;
187 <    Vector3d pos;
188 <    Vector3d vel;
226 > #ifdef IS_MPI
227 >    MPI_Status istatus;
228 > #endif
229  
230      Molecule* mol;
231      StuntDouble* integrableObject;
232      SimInfo::MoleculeIterator mi;
233      Molecule::IntegrableObjectIterator ii;
194  
195    int nTotObjects;    
196    nTotObjects = info_->getNGlobalIntegrableObjects();
234  
235   #ifndef IS_MPI
236 +    os << "  <Snapshot>\n";
237 +
238 +    writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot());
239  
240 <
201 <    os << nTotObjects << "\n";
202 <        
203 <    writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
204 <
240 >    os << "    <StuntDoubles>\n";
241      for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
242  
243        for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
244 <           integrableObject = mol->nextIntegrableObject(ii)) {
245 <                
244 >           integrableObject = mol->nextIntegrableObject(ii)) {  
245 >        os << prepareDumpLine(integrableObject);
246  
247 <        pos = integrableObject->getPos();
248 <        vel = integrableObject->getVel();
247 >      }
248 >    }    
249 >    os << "    </StuntDoubles>\n";
250  
251 <        sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
215 <                integrableObject->getType().c_str(),
216 <                pos[0], pos[1], pos[2],
217 <                vel[0], vel[1], vel[2]);
251 >    os << "  </Snapshot>\n";
252  
253 <        strcpy(writeLine, tempBuffer);
254 <
255 <        if (integrableObject->isDirectional()) {
256 <          q = integrableObject->getQ();
257 <          ji = integrableObject->getJ();
258 <
259 <          sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
260 <                  q[0], q[1], q[2], q[3],
261 <                  ji[0], ji[1], ji[2]);
228 <          strcat(writeLine, tempBuffer);
229 <        } else {
230 <          strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
231 <        }
232 <
233 <        os << writeLine;
234 <
253 >    os.flush();
254 > #else
255 >    //every node prepares the dump lines for integrable objects belong to itself
256 >    std::string buffer;
257 >    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
258 >      
259 >      for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
260 >           integrableObject = mol->nextIntegrableObject(ii)) {  
261 >        buffer += prepareDumpLine(integrableObject);
262        }
263      }
264 <
238 <    os.flush();
239 < #else // is_mpi
240 <    /*********************************************************************
241 <     * Documentation?  You want DOCUMENTATION?
242 <     *
243 <     * Why all the potatoes below?  
244 <     *
245 <     * To make a long story short, the original version of DumpWriter
246 <     * worked in the most inefficient way possible.  Node 0 would
247 <     * poke each of the node for an individual atom's formatted data
248 <     * as node 0 worked its way down the global index. This was particularly
249 <     * inefficient since the method blocked all processors at every atom
250 <     * (and did it twice!).
251 <     *
252 <     * An intermediate version of DumpWriter could be described from Node
253 <     * zero's perspective as follows:
254 <     *
255 <     *  1) Have 100 of your friends stand in a circle.
256 <     *  2) When you say go, have all of them start tossing potatoes at
257 <     *     you (one at a time).
258 <     *  3) Catch the potatoes.
259 <     *
260 <     * It was an improvement, but MPI has buffers and caches that could
261 <     * best be described in this analogy as "potato nets", so there's no
262 <     * need to block the processors atom-by-atom.
263 <     *
264 <     * This new and improved DumpWriter works in an even more efficient
265 <     * way:
266 <     *
267 <     *  1) Have 100 of your friend stand in a circle.
268 <     *  2) When you say go, have them start tossing 5-pound bags of
269 <     *     potatoes at you.
270 <     *  3) Once you've caught a friend's bag of potatoes,
271 <     *     toss them a spud to let them know they can toss another bag.
272 <     *
273 <     * How's THAT for documentation?
274 <     *
275 <     *********************************************************************/
264 >    
265      const int masterNode = 0;
266  
267 <    int * potatoes;
268 <    int myPotato;
269 <    int nProc;
270 <    int which_node;
271 <    double atomData[13];
272 <    int isDirectional;
284 <    char MPIatomTypeString[MINIBUFFERSIZE];
285 <    int msgLen; // the length of message actually recieved at master nodes
286 <    int haveError;
287 <    MPI_Status istatus;
288 <    int nCurObj;
289 <    
290 <    // code to find maximum tag value
291 <    int * tagub;
292 <    int flag;
293 <    int MAXTAG;
294 <    MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag);
267 >    if (worldRank == masterNode) {      
268 >      os << "  <Snapshot>\n";  
269 >      writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot());
270 >      os << "    <StuntDoubles>\n";
271 >        
272 >      os << buffer;
273  
274 <    if (flag) {
297 <      MAXTAG = *tagub;
298 <    } else {
299 <      MAXTAG = 32767;
300 <    }
301 <
302 <    if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file
303 <
304 <      // Node 0 needs a list of the magic potatoes for each processor;
305 <
274 >      int nProc;
275        MPI_Comm_size(MPI_COMM_WORLD, &nProc);
276 <      potatoes = new int[nProc];
276 >      for (int i = 1; i < nProc; ++i) {
277  
278 <      //write out the comment lines
279 <      for(int i = 0; i < nProc; i++) {
311 <        potatoes[i] = 0;
312 <      }
313 <
314 <
315 <      os << nTotObjects << "\n";
316 <      writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
317 <
318 <      for(int i = 0; i < info_->getNGlobalMolecules(); i++) {
319 <
320 <        // Get the Node number which has this atom;
321 <
322 <        which_node = info_->getMolToProc(i);
323 <
324 <        if (which_node != masterNode) { //current molecule is in slave node
325 <          if (potatoes[which_node] + 1 >= MAXTAG) {
326 <            // The potato was going to exceed the maximum value,
327 <            // so wrap this processor potato back to 0:        
328 <
329 <            potatoes[which_node] = 0;
330 <            MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0,
331 <                     MPI_COMM_WORLD);
332 <          }
333 <
334 <          myPotato = potatoes[which_node];
335 <
336 <          //recieve the number of integrableObject in current molecule
337 <          MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato,
338 <                   MPI_COMM_WORLD, &istatus);
339 <          myPotato++;
340 <
341 <          for(int l = 0; l < nCurObj; l++) {
342 <            if (potatoes[which_node] + 2 >= MAXTAG) {
343 <              // The potato was going to exceed the maximum value,
344 <              // so wrap this processor potato back to 0:        
345 <
346 <              potatoes[which_node] = 0;
347 <              MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node,
348 <                       0, MPI_COMM_WORLD);
349 <            }
278 >        // receive the length of the string buffer that was
279 >        // prepared by processor i
280  
281 <            MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR,
282 <                     which_node, myPotato, MPI_COMM_WORLD,
283 <                     &istatus);
284 <
285 <            myPotato++;
286 <
287 <            MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato,
288 <                     MPI_COMM_WORLD, &istatus);
289 <            myPotato++;
290 <
291 <            MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen);
292 <
293 <            if (msgLen == 13)
364 <              isDirectional = 1;
365 <            else
366 <              isDirectional = 0;
367 <
368 <            // If we've survived to here, format the line:
369 <
370 <            if (!isDirectional) {
371 <              sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
372 <                      MPIatomTypeString, atomData[0],
373 <                      atomData[1], atomData[2],
374 <                      atomData[3], atomData[4],
375 <                      atomData[5]);
376 <
377 <              strcat(writeLine,
378 <                     "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
379 <            } else {
380 <              sprintf(writeLine,
381 <                      "%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\n",
382 <                      MPIatomTypeString,
383 <                      atomData[0],
384 <                      atomData[1],
385 <                      atomData[2],
386 <                      atomData[3],
387 <                      atomData[4],
388 <                      atomData[5],
389 <                      atomData[6],
390 <                      atomData[7],
391 <                      atomData[8],
392 <                      atomData[9],
393 <                      atomData[10],
394 <                      atomData[11],
395 <                      atomData[12]);
396 <            }
397 <
398 <            os << writeLine;
399 <
400 <          } // end for(int l =0)
401 <
402 <          potatoes[which_node] = myPotato;
403 <        } else { //master node has current molecule
404 <
405 <          mol = info_->getMoleculeByGlobalIndex(i);
406 <
407 <          if (mol == NULL) {
408 <            sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank);
409 <            painCave.isFatal = 1;
410 <            simError();
411 <          }
412 <                
413 <          for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
414 <               integrableObject = mol->nextIntegrableObject(ii)) {      
415 <
416 <            pos = integrableObject->getPos();
417 <            vel = integrableObject->getVel();
418 <
419 <            atomData[0] = pos[0];
420 <            atomData[1] = pos[1];
421 <            atomData[2] = pos[2];
422 <
423 <            atomData[3] = vel[0];
424 <            atomData[4] = vel[1];
425 <            atomData[5] = vel[2];
426 <
427 <            isDirectional = 0;
428 <
429 <            if (integrableObject->isDirectional()) {
430 <              isDirectional = 1;
431 <
432 <              q = integrableObject->getQ();
433 <              ji = integrableObject->getJ();
434 <
435 <              for(int j = 0; j < 6; j++) {
436 <                atomData[j] = atomData[j];
437 <              }
438 <
439 <              atomData[6] = q[0];
440 <              atomData[7] = q[1];
441 <              atomData[8] = q[2];
442 <              atomData[9] = q[3];
443 <
444 <              atomData[10] = ji[0];
445 <              atomData[11] = ji[1];
446 <              atomData[12] = ji[2];
447 <            }
448 <
449 <            // If we've survived to here, format the line:
450 <
451 <            if (!isDirectional) {
452 <              sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
453 <                      integrableObject->getType().c_str(), atomData[0],
454 <                      atomData[1], atomData[2],
455 <                      atomData[3], atomData[4],
456 <                      atomData[5]);
457 <
458 <              strcat(writeLine,
459 <                     "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
460 <            } else {
461 <              sprintf(writeLine,
462 <                      "%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\n",
463 <                      integrableObject->getType().c_str(),
464 <                      atomData[0],
465 <                      atomData[1],
466 <                      atomData[2],
467 <                      atomData[3],
468 <                      atomData[4],
469 <                      atomData[5],
470 <                      atomData[6],
471 <                      atomData[7],
472 <                      atomData[8],
473 <                      atomData[9],
474 <                      atomData[10],
475 <                      atomData[11],
476 <                      atomData[12]);
477 <            }
478 <
479 <
480 <            os << writeLine;
481 <
482 <          } //end for(iter = integrableObject.begin())
483 <        }
484 <      } //end for(i = 0; i < mpiSim->getNmol())
485 <
281 >        int recvLength;
282 >        MPI_Recv(&recvLength, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &istatus);
283 >        char* recvBuffer = new char[recvLength];
284 >        if (recvBuffer == NULL) {
285 >        } else {
286 >          MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i, 0, MPI_COMM_WORLD, &istatus);
287 >          os << recvBuffer;
288 >          delete recvBuffer;
289 >        }
290 >      }
291 >      os << "    </StuntDoubles>\n";
292 >      
293 >      os << "  </Snapshot>\n";
294        os.flush();
487        
488      sprintf(checkPointMsg, "Sucessfully took a dump.\n");
489      MPIcheckPoint();
490
491      delete [] potatoes;
295      } else {
296 +      int sendBufferLength = buffer.size() + 1;
297 +      MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD);
298 +      MPI_Send((void *)buffer.c_str(), sendBufferLength, MPI_CHAR, masterNode, 0, MPI_COMM_WORLD);
299 +    }
300  
301 <      // worldRank != 0, so I'm a remote node.  
301 > #endif // is_mpi
302  
303 <      // Set my magic potato to 0:
303 >  }
304  
305 <      myPotato = 0;
305 >  std::string DumpWriter::prepareDumpLine(StuntDouble* integrableObject) {
306 >        
307 >    int index = integrableObject->getGlobalIntegrableObjectIndex();
308 >    std::string type("pv");
309 >    std::string line;
310 >    char tempBuffer[4096];
311  
312 <      for(int i = 0; i < info_->getNGlobalMolecules(); i++) {
312 >    Vector3d pos;
313 >    Vector3d vel;
314 >    pos = integrableObject->getPos();
315 >    vel = integrableObject->getVel();          
316 >    sprintf(tempBuffer, "%18.10g %18.10g %18.10g %13e %13e %13e",
317 >            pos[0], pos[1], pos[2],
318 >            vel[0], vel[1], vel[2]);                    
319 >    line += tempBuffer;
320  
321 <        // Am I the node which has this integrableObject?
322 <        int whichNode = info_->getMolToProc(i);
323 <        if (whichNode == worldRank) {
324 <          if (myPotato + 1 >= MAXTAG) {
325 <
326 <            // The potato was going to exceed the maximum value,
327 <            // so wrap this processor potato back to 0 (and block until
328 <            // node 0 says we can go:
329 <
330 <            MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
512 <                     &istatus);
513 <          }
514 <
515 <          mol = info_->getMoleculeByGlobalIndex(i);
516 <
517 <                
518 <          nCurObj = mol->getNIntegrableObjects();
519 <
520 <          MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD);
521 <          myPotato++;
522 <
523 <          for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
524 <               integrableObject = mol->nextIntegrableObject(ii)) {
525 <
526 <            if (myPotato + 2 >= MAXTAG) {
527 <
528 <              // The potato was going to exceed the maximum value,
529 <              // so wrap this processor potato back to 0 (and block until
530 <              // node 0 says we can go:
531 <
532 <              MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
533 <                       &istatus);
534 <            }
535 <
536 <            pos = integrableObject->getPos();
537 <            vel = integrableObject->getVel();
538 <
539 <            atomData[0] = pos[0];
540 <            atomData[1] = pos[1];
541 <            atomData[2] = pos[2];
542 <
543 <            atomData[3] = vel[0];
544 <            atomData[4] = vel[1];
545 <            atomData[5] = vel[2];
546 <
547 <            isDirectional = 0;
548 <
549 <            if (integrableObject->isDirectional()) {
550 <              isDirectional = 1;
551 <
552 <              q = integrableObject->getQ();
553 <              ji = integrableObject->getJ();
554 <
555 <              atomData[6] = q[0];
556 <              atomData[7] = q[1];
557 <              atomData[8] = q[2];
558 <              atomData[9] = q[3];
559 <
560 <              atomData[10] = ji[0];
561 <              atomData[11] = ji[1];
562 <              atomData[12] = ji[2];
563 <            }
564 <
565 <            strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE);
566 <
567 <            // null terminate the  std::string before sending (just in case):
568 <            MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0';
569 <
570 <            MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
571 <                     myPotato, MPI_COMM_WORLD);
572 <
573 <            myPotato++;
574 <
575 <            if (isDirectional) {
576 <              MPI_Send(atomData, 13, MPI_DOUBLE, 0, myPotato,
577 <                       MPI_COMM_WORLD);
578 <            } else {
579 <              MPI_Send(atomData, 6, MPI_DOUBLE, 0, myPotato,
580 <                       MPI_COMM_WORLD);
581 <            }
582 <
583 <            myPotato++;
584 <          }
585 <                    
586 <        }
587 <            
588 <      }
589 <      sprintf(checkPointMsg, "Sucessfully took a dump.\n");
590 <      MPIcheckPoint();
321 >    if (integrableObject->isDirectional()) {
322 >      type += "qj";
323 >      Quat4d q;
324 >      Vector3d ji;
325 >      q = integrableObject->getQ();
326 >      ji = integrableObject->getJ();
327 >      sprintf(tempBuffer, " %13e %13e %13e %13e %13e %13e %13e",
328 >              q[0], q[1], q[2], q[3],
329 >              ji[0], ji[1], ji[2]);
330 >      line += tempBuffer;
331      }
332  
333 < #endif // is_mpi
334 <
333 >    if (needForceVector_) {
334 >      type += "ft";
335 >      Vector3d frc;
336 >      Vector3d trq;
337 >      frc = integrableObject->getFrc();
338 >      trq = integrableObject->getTrq();
339 >              
340 >      sprintf(tempBuffer, " %13e %13e %13e %13e %13e %13e",
341 >              frc[0], frc[1], frc[2],
342 >              trq[0], trq[1], trq[2]);
343 >      line += tempBuffer;
344 >    }
345 >        
346 >    sprintf(tempBuffer, "%10d %7s %s\n", index, type.c_str(), line.c_str());
347 >    return std::string(tempBuffer);
348    }
349  
350    void DumpWriter::writeDump() {
# Line 616 | Line 369 | namespace oopse {
369   #ifdef IS_MPI
370      if (worldRank == 0) {
371   #endif // is_mpi
372 <    delete eorStream;
373 <
372 >      writeClosing(*eorStream);
373 >      delete eorStream;
374   #ifdef IS_MPI
375      }
376   #endif // is_mpi  
# Line 650 | Line 403 | namespace oopse {
403   #ifdef IS_MPI
404      if (worldRank == 0) {
405   #endif // is_mpi
406 <    delete eorStream;
407 <
406 >      writeClosing(*eorStream);
407 >      delete eorStream;
408   #ifdef IS_MPI
409      }
410   #endif // is_mpi  
411      
412    }
413  
414 < std::ostream* DumpWriter::createOStream(const std::string& filename) {
414 >  std::ostream* DumpWriter::createOStream(const std::string& filename) {
415 >
416      std::ostream* newOStream;
417 + #ifdef HAVE_LIBZ
418      if (needCompression_) {
419 <        newOStream = new ogzstream(filename.c_str());
419 >      newOStream = new ogzstream(filename.c_str());
420      } else {
421 <        newOStream = new std::ofstream(filename.c_str());
421 >      newOStream = new std::ofstream(filename.c_str());
422      }
423 + #else
424 +    newOStream = new std::ofstream(filename.c_str());
425 + #endif
426 +    //write out MetaData first
427 +    (*newOStream) << "<OOPSE version=4>" << std::endl;
428 +    (*newOStream) << "  <MetaData>" << std::endl;
429 +    (*newOStream) << info_->getRawMetaData();
430 +    (*newOStream) << "  </MetaData>" << std::endl;
431      return newOStream;
432 < }
432 >  }
433  
434 +  void DumpWriter::writeClosing(std::ostream& os) {
435 +
436 +    os << "</OOPSE>\n";
437 +    os.flush();
438 +  }
439 +
440   }//end namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines