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.
Revision 1025 by gezelter, Wed Aug 30 20:33:44 2006 UTC

# Line 58 | Line 58 | namespace oopse {
58      Globals* simParams = info->getSimParams();
59      needCompression_ = simParams->getCompressDumpFile();
60      needForceVector_ = simParams->getOutputForceVector();
61 <
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  
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
83   #ifdef IS_MPI
84  
85 <      }
85 >    }
86  
88      sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
89      MPIcheckPoint();
90
87   #endif // is_mpi
88  
89 <    }
89 >  }
90  
91  
92    DumpWriter::DumpWriter(SimInfo* info, const std::string& filename)
# Line 101 | Line 97 | namespace oopse {
97  
98      needCompression_ = simParams->getCompressDumpFile();
99      needForceVector_ = simParams->getOutputForceVector();
100 <
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  
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
123   #ifdef IS_MPI
124  
125 <      }
125 >    }
126  
131      sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
132      MPIcheckPoint();
133
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 152 | 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;
159    double chi;
160    double integralOfChiDt;
161    Mat3x3d eta;
162    
163    currentTime = s->getTime();
201      hmat = s->getHmat();
202 <    chi = s->getChi();
203 <    integralOfChiDt = s->getIntegralOfChiDt();
204 <    eta = s->getEta();
205 <    
206 <    os << currentTime << ";\t"
170 <       << hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t"
171 <       << hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t"
172 <       << 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"
179 <       << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t"
180 <       << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";";
181 <        
182 <    os << "\n";
221 >    os << "    </FrameData>\n";
222    }
223  
224    void DumpWriter::writeFrame(std::ostream& os) {
186    const int BUFFERSIZE = 2000;
187    const int MINIBUFFERSIZE = 100;
225  
226 <    char tempBuffer[BUFFERSIZE];
227 <    char writeLine[BUFFERSIZE];
226 > #ifdef IS_MPI
227 >    MPI_Status istatus;
228 > #endif
229  
192    Quat4d q;
193    Vector3d ji;
194    Vector3d pos;
195    Vector3d vel;
196    Vector3d frc;
197    Vector3d trq;
198
230      Molecule* mol;
231      StuntDouble* integrableObject;
232      SimInfo::MoleculeIterator mi;
233      Molecule::IntegrableObjectIterator ii;
203  
204    int nTotObjects;    
205    nTotObjects = info_->getNGlobalIntegrableObjects();
234  
235   #ifndef IS_MPI
236 +    os << "  <Snapshot>\n";
237 +
238 +    writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot());
239  
240 <
210 <    os << nTotObjects << "\n";
211 <        
212 <    writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
213 <
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",
224 <                integrableObject->getType().c_str(),
225 <                pos[0], pos[1], pos[2],
226 <                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",
260 <                  q[0], q[1], q[2], q[3],
261 <                  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 <        }
241 <
242 <        if (needForceVector_) {
243 <          frc = integrableObject->getFrc();
244 <          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 <
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 <
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 <     *********************************************************************/
264 >    
265      const int masterNode = 0;
266  
267 <    int * potatoes;
268 <    int myPotato;
269 <    int nProc;
270 <    int which_node;
271 <    double atomData[19];
272 <    int isDirectional;
304 <    char MPIatomTypeString[MINIBUFFERSIZE];
305 <    int msgLen; // the length of message actually recieved at master nodes
306 <    int haveError;
307 <    MPI_Status istatus;
308 <    int nCurObj;
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);
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) {
317 <      MAXTAG = *tagub;
318 <    } else {
319 <      MAXTAG = 32767;
320 <    }
321 <
322 <    if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file
323 <
324 <      // Node 0 needs a list of the magic potatoes for each processor;
325 <
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++) {
331 <        potatoes[i] = 0;
332 <      }
278 >        // receive the length of the string buffer that was
279 >        // prepared by processor i
280  
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();
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 <      os << nTotObjects << "\n";
336 <      writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
301 > #endif // is_mpi
302  
303 <      for(int i = 0; i < info_->getNGlobalMolecules(); i++) {
303 >  }
304  
305 <        // Get the Node number which has this atom;
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 <        which_node = info_->getMolToProc(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 <        if (which_node != masterNode) { //current molecule is in slave node
322 <          if (potatoes[which_node] + 1 >= MAXTAG) {
323 <            // The potato was going to exceed the maximum value,
324 <            // so wrap this processor potato back to 0:        
325 <
326 <            potatoes[which_node] = 0;
327 <            MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0,
328 <                     MPI_COMM_WORLD);
329 <          }
330 <
354 <          myPotato = potatoes[which_node];
355 <
356 <          //recieve the number of integrableObject in current molecule
357 <          MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato,
358 <                   MPI_COMM_WORLD, &istatus);
359 <          myPotato++;
360 <
361 <          for(int l = 0; l < nCurObj; l++) {
362 <            if (potatoes[which_node] + 2 >= MAXTAG) {
363 <              // The potato was going to exceed the maximum value,
364 <              // so wrap this processor potato back to 0:        
365 <
366 <              potatoes[which_node] = 0;
367 <              MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node,
368 <                       0, MPI_COMM_WORLD);
369 <            }
370 <
371 <            MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR,
372 <                     which_node, myPotato, MPI_COMM_WORLD,
373 <                     &istatus);
374 <
375 <            myPotato++;
376 <
377 <            MPI_Recv(atomData, 19, MPI_DOUBLE, which_node, myPotato,
378 <                     MPI_COMM_WORLD, &istatus);
379 <            myPotato++;
380 <
381 <            MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen);
382 <
383 <            if (msgLen == 13 || msgLen == 19)
384 <              isDirectional = 1;
385 <            else
386 <              isDirectional = 0;
387 <
388 <            // If we've survived to here, format the line:
389 <
390 <            if (!isDirectional) {
391 <              sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
392 <                      MPIatomTypeString, atomData[0],
393 <                      atomData[1], atomData[2],
394 <                      atomData[3], atomData[4],
395 <                      atomData[5]);
396 <
397 <              strcat(writeLine,
398 <                     "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 <            
699 <      }
700 <      sprintf(checkPointMsg, "Sucessfully took a dump.\n");
701 <      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 727 | 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 761 | 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