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