| 1 |
#define _FILE_OFFSET_BITS 64 |
| 2 |
|
| 3 |
#include <cstring> |
| 4 |
#include <iostream> |
| 5 |
#include <fstream> |
| 6 |
|
| 7 |
#include "ReadWrite.hpp" |
| 8 |
#include "simError.h" |
| 9 |
|
| 10 |
|
| 11 |
StatWriter::StatWriter( SimInfo* the_entry_plug ){ |
| 12 |
|
| 13 |
entry_plug = the_entry_plug; |
| 14 |
|
| 15 |
#ifdef IS_MPI |
| 16 |
if(worldRank == 0 ){ |
| 17 |
#endif // is_mpi |
| 18 |
|
| 19 |
strcpy( outName, entry_plug->statusName ); |
| 20 |
|
| 21 |
//std::cerr << "Opening " << outName << " for stat\n"; |
| 22 |
|
| 23 |
outFile.open(outName, ios::out | ios::trunc ); |
| 24 |
|
| 25 |
if( !outFile ){ |
| 26 |
|
| 27 |
sprintf( painCave.errMsg, |
| 28 |
"Could not open \"%s\" for stat output.\n", |
| 29 |
outName); |
| 30 |
painCave.isFatal = 1; |
| 31 |
simError(); |
| 32 |
} |
| 33 |
|
| 34 |
//outFile.setf( ios::scientific ); |
| 35 |
outFile << "#time(fs)\ttot_E\tpotential\tkinetic\ttemperature\tpressure\tvolume\tconserved quantity\n"; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#ifdef IS_MPI |
| 40 |
} |
| 41 |
|
| 42 |
sprintf( checkPointMsg, |
| 43 |
"Sucessfully opened output file for stating.\n"); |
| 44 |
MPIcheckPoint(); |
| 45 |
#endif // is_mpi |
| 46 |
|
| 47 |
tStats = new Thermo( entry_plug ); |
| 48 |
} |
| 49 |
|
| 50 |
StatWriter::~StatWriter( ){ |
| 51 |
|
| 52 |
#ifdef IS_MPI |
| 53 |
if(worldRank == 0 ){ |
| 54 |
#endif // is_mpi |
| 55 |
|
| 56 |
outFile.close(); |
| 57 |
delete tStats; |
| 58 |
|
| 59 |
#ifdef IS_MPI |
| 60 |
} |
| 61 |
#endif // is_mpi |
| 62 |
} |
| 63 |
|
| 64 |
void StatWriter::writeStat( double currentTime ){ |
| 65 |
|
| 66 |
double totE, potE, kinE, temp, press, vol; |
| 67 |
double conservedQuantity; |
| 68 |
|
| 69 |
totE = tStats->getTotalE(); |
| 70 |
potE = tStats->getPotential(); |
| 71 |
kinE = tStats->getKinetic(); |
| 72 |
temp = tStats->getTemperature(); |
| 73 |
press = tStats->getPressure(); |
| 74 |
vol = tStats->getVolume(); |
| 75 |
conservedQuantity = entry_plug->the_integrator->getConservedQuantity(); |
| 76 |
#ifdef IS_MPI |
| 77 |
if(worldRank == 0 ){ |
| 78 |
#endif // is_mpi |
| 79 |
|
| 80 |
outFile.precision(8); |
| 81 |
outFile |
| 82 |
<< currentTime << "\t" |
| 83 |
<< totE << "\t" |
| 84 |
<< potE << "\t" |
| 85 |
<< kinE << "\t" |
| 86 |
<< temp << "\t" |
| 87 |
<< press << "\t" |
| 88 |
<< vol << "\t" |
| 89 |
<< conservedQuantity << "\n"; |
| 90 |
|
| 91 |
outFile.flush(); |
| 92 |
|
| 93 |
#ifdef IS_MPI |
| 94 |
} |
| 95 |
#endif // is_mpi |
| 96 |
} |