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