ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/DumpWriter.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/DumpWriter.cpp (file contents):
Revision 929 by tim, Tue Jan 13 15:46:49 2004 UTC vs.
Revision 936 by tim, Tue Jan 13 20:35:25 2004 UTC

# Line 40 | Line 40 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
40        simError();
41      }
42  
43    //outFile.setf( ios::scientific );
44
43   #ifdef IS_MPI
44    }
45  
# Line 102 | Line 100 | void DumpWriter::writeDump(double currentTime){
100   #endif
101  
102   void DumpWriter::writeDump(double currentTime){
105  
106 // write to eor file
107  writeFinal(currentTime);
103  
104 < //write to dump file
105 <  writeFrame(dumpFile, currentTime);
104 >  ofstream finalOut;
105 >  vector<ofstream*> fileStreams;
106 >
107 > #ifdef IS_MPI
108 >  if(worldRank == 0 ){
109 >    
110 >    finalOut.open( entry_plug->finalName, ios::out | ios::trunc );
111 >    if( !finalOut ){
112 >      sprintf( painCave.errMsg,
113 >               "Could not open \"%s\" for final dump output.\n",
114 >               entry_plug->finalName );
115 >      painCave.isFatal = 1;
116 >      simError();
117 >    }
118 >  }
119 > #endif // is_mpi
120 >
121 >  fileStreams.push_back(&finalOut);
122 >  fileStreams.push_back(&dumpFile);
123 >
124 >  writeFrame(fileStreams, currentTime);
125 >
126 > #ifdef IS_MPI
127 >  finalOut.close();
128 > #endif
129          
130   }
131  
132   void DumpWriter::writeFinal(double currentTime){
133  
134 <  ofstream finalOut;    
135 <  
136 <  //Open eor file
134 >  ofstream finalOut;
135 >  vector<ofstream*> fileStreams;
136 >
137   #ifdef IS_MPI
138    if(worldRank == 0 ){
121 #endif // is_mpi
139  
140      finalOut.open( entry_plug->finalName, ios::out | ios::trunc );
141 +
142      if( !finalOut ){
143        sprintf( painCave.errMsg,
144                 "Could not open \"%s\" for final dump output.\n",
# Line 128 | Line 146 | void DumpWriter::writeFinal(double currentTime){
146        painCave.isFatal = 1;
147        simError();
148      }
149 <    
132 < #ifdef IS_MPI
149 >
150    }
134 #endif
135  
136  //write to eor file  
137  writeFrame(finalOut, currentTime);
138  
139  //close eor file      
140 #ifdef IS_MPI
141  if(worldRank == 0 ){
142    finalOut.close();
143  }
151   #endif // is_mpi
152 +  
153 +  fileStreams.push_back(&finalOut);  
154 +  writeFrame(fileStreams, currentTime);
155  
156 + #ifdef IS_MPI
157 +  finalOut.close();
158 + #endif
159 +  
160   }
161  
162 < void DumpWriter::writeFrame( ofstream& outFile, double currentTime ){
162 > void DumpWriter::writeFrame( vector<ofstream*>& outFile, double currentTime ){
163  
164    const int BUFFERSIZE = 2000;
165    const int MINIBUFFERSIZE = 100;
166  
167 <  char tempBuffer[BUFFERSIZE];
167 >  char tempBuffer[BUFFERSIZE];  
168    char writeLine[BUFFERSIZE];
169  
170 <  int i;
170 >  int i, k;
171  
172   #ifdef IS_MPI
173    
# Line 178 | Line 192 | void DumpWriter::writeFrame( ofstream& outFile, double
192    double pos[3], vel[3];
193  
194   #ifndef IS_MPI
195 <
196 <  outFile << nAtoms << "\n";
195 >  
196 >  for(k = 0; k < outFile.size(); k++){
197 >    *outFile[k] << nAtoms << "\n";
198  
199 <  outFile << currentTime << ";\t"
200 <          << entry_plug->Hmat[0][0] << "\t"
201 <          << entry_plug->Hmat[1][0] << "\t"
202 <          << entry_plug->Hmat[2][0] << ";\t"
199 >    *outFile[k] << currentTime << ";\t"
200 >               << entry_plug->Hmat[0][0] << "\t"
201 >                     << entry_plug->Hmat[1][0] << "\t"
202 >                     << entry_plug->Hmat[2][0] << ";\t"
203 >              
204 >               << entry_plug->Hmat[0][1] << "\t"
205 >                     << entry_plug->Hmat[1][1] << "\t"
206 >                     << entry_plug->Hmat[2][1] << ";\t"
207  
208 <          << entry_plug->Hmat[0][1] << "\t"
209 <          << entry_plug->Hmat[1][1] << "\t"
210 <          << entry_plug->Hmat[2][1] << ";\t"
208 >                     << entry_plug->Hmat[0][2] << "\t"
209 >                     << entry_plug->Hmat[1][2] << "\t"
210 >                     << entry_plug->Hmat[2][2] << ";";
211  
212 <          << entry_plug->Hmat[0][2] << "\t"
213 <          << entry_plug->Hmat[1][2] << "\t"
214 <          << entry_plug->Hmat[2][2] << ";";
215 <  //write out additional parameters, such as chi and eta
197 <  outFile << entry_plug->the_integrator->getAdditionalParameters();
198 <  outFile << endl;
199 <
212 >    //write out additional parameters, such as chi and eta
213 >    *outFile[k] << entry_plug->the_integrator->getAdditionalParameters() << endl;
214 >  }
215 >  
216    for( i=0; i<nAtoms; i++ ){
217  
218      atoms[i]->getPos(pos);
# Line 232 | Line 248 | void DumpWriter::writeFrame( ofstream& outFile, double
248      else
249        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
250  
251 <    outFile << writeLine;
251 >    for(k = 0; k < outFile.size(); k++)
252 >      *outFile[k] << writeLine;
253    }
254  
255   #else // is_mpi
# Line 261 | Line 278 | void DumpWriter::writeFrame( ofstream& outFile, double
278      nProc = mpiSim->getNumberProcessors();
279      potatoes = new int[nProc];
280  
281 +    //write out the comment lines
282      for (i = 0; i < nProc; i++)
283        potatoes[i] = 0;
284      
285 <    outFile << mpiSim->getTotAtoms() << "\n";
285 >      for(k = 0; k < outFile.size(); k++){
286 >        *outFile[k] << mpiSim->getTotAtoms() << "\n";
287  
288 <    outFile << currentTime << ";\t"
289 <            << entry_plug->Hmat[0][0] << "\t"
290 <            << entry_plug->Hmat[1][0] << "\t"
291 <            << entry_plug->Hmat[2][0] << ";\t"
288 >        *outFile[k] << currentTime << ";\t"
289 >                         << entry_plug->Hmat[0][0] << "\t"
290 >                         << entry_plug->Hmat[1][0] << "\t"
291 >                         << entry_plug->Hmat[2][0] << ";\t"
292  
293 <            << entry_plug->Hmat[0][1] << "\t"
294 <            << entry_plug->Hmat[1][1] << "\t"
295 <            << entry_plug->Hmat[2][1] << ";\t"
293 >                         << entry_plug->Hmat[0][1] << "\t"
294 >                         << entry_plug->Hmat[1][1] << "\t"
295 >                         << entry_plug->Hmat[2][1] << ";\t"
296  
297 <            << entry_plug->Hmat[0][2] << "\t"
298 <            << entry_plug->Hmat[1][2] << "\t"
299 <            << entry_plug->Hmat[2][2] << ";";
297 >                         << entry_plug->Hmat[0][2] << "\t"
298 >                         << entry_plug->Hmat[1][2] << "\t"
299 >                         << entry_plug->Hmat[2][2] << ";";
300 >  
301 >        *outFile[k] << entry_plug->the_integrator->getAdditionalParameters() << endl;
302 >    }
303  
282    outFile << entry_plug->the_integrator->getAdditionalParameters();
283    outFile << endl;
284    outFile.flush();
285    
304      currentIndex = 0;
305 +
306      for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
307        
308        // Get the Node number which has this atom;
# Line 328 | Line 347 | void DumpWriter::writeFrame( ofstream& outFile, double
347  
348        } else {
349          
350 <        haveError = 0;
351 <        which_atom = i;
350 >        haveError = 0;
351 >              which_atom = i;
352          
353          local_index = indexArray[currentIndex].first;        
354                  
# Line 337 | Line 356 | void DumpWriter::writeFrame( ofstream& outFile, double
356            
357            atomTypeString = atoms[local_index]->getType();
358  
359 <          atoms[local_index]->getPos(pos);
360 <          atoms[local_index]->getVel(vel);          
359 >                atoms[local_index]->getPos(pos);
360 >                atoms[local_index]->getVel(vel);          
361  
362            atomData6[0] = pos[0];
363            atomData6[1] = pos[1];
# Line 371 | Line 390 | void DumpWriter::writeFrame( ofstream& outFile, double
390            }
391            
392          } else {
393 <          sprintf(painCave.errMsg,
394 <                  "Atom %d not found on processor %d\n",
395 <                  i, worldRank );
396 <          haveError= 1;
397 <          simError();
398 <        }
393 >          sprintf(painCave.errMsg,
394 >                              "Atom %d not found on processor %d\n",
395 >                              i, worldRank );
396 >                haveError= 1;
397 >                simError();
398 >              }
399          
400 <        if(haveError) DieDieDie();
400 >        if(haveError) DieDieDie();
401          
402          currentIndex ++;
403        }
# Line 386 | Line 405 | void DumpWriter::writeFrame( ofstream& outFile, double
405        
406        if (!isDirectional) {
407          
408 <        sprintf( writeLine,
409 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
410 <                 atomTypeString,
411 <                 atomData6[0],
412 <                 atomData6[1],
413 <                 atomData6[2],
414 <                 atomData6[3],
415 <                 atomData6[4],
416 <                 atomData6[5]);
408 >        sprintf( writeLine,
409 >                             "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
410 >                             atomTypeString,
411 >                             atomData6[0],
412 >                             atomData6[1],
413 >                             atomData6[2],
414 >                             atomData6[3],
415 >                             atomData6[4],
416 >                             atomData6[5]);
417  
418 <        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
418 >              strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
419          
420        } else {
421          
422 <        sprintf( writeLine,
423 <                 "%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",
424 <                 atomTypeString,
425 <                 atomData13[0],
426 <                 atomData13[1],
427 <                 atomData13[2],
428 <                 atomData13[3],
429 <                 atomData13[4],
430 <                 atomData13[5],
431 <                 atomData13[6],
432 <                 atomData13[7],
433 <                 atomData13[8],
434 <                 atomData13[9],
435 <                 atomData13[10],
436 <                 atomData13[11],
437 <                 atomData13[12]);
422 >              sprintf( writeLine,
423 >                             "%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",
424 >                             atomTypeString,
425 >                             atomData13[0],
426 >                             atomData13[1],
427 >                             atomData13[2],
428 >                             atomData13[3],
429 >                             atomData13[4],
430 >                             atomData13[5],
431 >                             atomData13[6],
432 >                             atomData13[7],
433 >                             atomData13[8],
434 >                             atomData13[9],
435 >                             atomData13[10],
436 >                             atomData13[11],
437 >                             atomData13[12]);
438          
439        }
440        
441 <      outFile << writeLine;
441 >      for(k = 0; k < outFile.size(); k++)
442 >        *outFile[k] << writeLine;
443      }
444      
445 <
446 <    outFile.flush();
445 >    for(k = 0; k < outFile.size(); k++)
446 >      outFile[k]->flush();
447 >    
448      sprintf( checkPointMsg,
449               "Sucessfully took a dump.\n");
450 +
451      MPIcheckPoint();        
452 +
453      delete[] potatoes;
454 +
455    } else {
456  
457      // worldRank != 0, so I'm a remote node.  
# Line 459 | Line 483 | void DumpWriter::writeFrame( ofstream& outFile, double
483          
484            atomTypeString = atoms[local_index]->getType();
485  
486 <          atoms[local_index]->getPos(pos);
487 <          atoms[local_index]->getVel(vel);
486 >                atoms[local_index]->getPos(pos);
487 >                atoms[local_index]->getVel(vel);
488  
489            atomData6[0] = pos[0];
490            atomData6[1] = pos[1];
# Line 486 | Line 510 | void DumpWriter::writeFrame( ofstream& outFile, double
510              atomData13[7] = q[1];
511              atomData13[8] = q[2];
512              atomData13[9] = q[3];
513 <
513 >  
514              atomData13[10] = dAtom->getJx();
515              atomData13[11] = dAtom->getJy();
516              atomData13[12] = dAtom->getJz();
517            }
518  
519          } else {
520 <          sprintf(painCave.errMsg,
521 <                  "Atom %d not found on processor %d\n",
522 <                  i, worldRank );
523 <          haveError= 1;
524 <          simError();
525 <        }
520 >                sprintf(painCave.errMsg,
521 >                              "Atom %d not found on processor %d\n",
522 >                              i, worldRank );
523 >                haveError= 1;
524 >                simError();
525 >              }
526  
527          strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE);
528  
# Line 506 | Line 530 | void DumpWriter::writeFrame( ofstream& outFile, double
530          MPIatomTypeString[MINIBUFFERSIZE-1] = '\0';
531  
532          MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
533 <                 myPotato, MPI_COMM_WORLD);
533 >                             myPotato, MPI_COMM_WORLD);
534          
535          myPotato++;
536  
537          MPI_Send(&isDirectional, 1, MPI_INT, 0,
538 <                 myPotato, MPI_COMM_WORLD);
538 >                             myPotato, MPI_COMM_WORLD);
539          
540          myPotato++;
541          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines