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 |
outName = entry_plug->statusName; |
21 |
|
22 |
//std::cerr << "Opening " << outName << " for stat\n"; |
23 |
|
24 |
outFile.open(outName.c_str(), ios::out | ios::trunc ); |
25 |
|
26 |
if( !outFile ){ |
27 |
|
28 |
sprintf( painCave.errMsg, |
29 |
"Could not open \"%s\" for stat output.\n", |
30 |
outName.c_str()); |
31 |
painCave.isFatal = 1; |
32 |
simError(); |
33 |
} |
34 |
|
35 |
//outFile.setf( ios::scientific ); |
36 |
outFile << "#time(fs)\tE_tot\tV\tKE\tT(K)\tP(atm)\tVol(A^3)\tH_conserved"; |
37 |
|
38 |
if (entry_plug->useSolidThermInt || entry_plug->useLiquidThermInt) |
39 |
outFile << "\tV_raw"; |
40 |
|
41 |
if (entry_plug->useSolidThermInt) |
42 |
outFile << "\tV_harm"; |
43 |
|
44 |
outFile << "\n"; |
45 |
|
46 |
|
47 |
#ifdef IS_MPI |
48 |
} |
49 |
|
50 |
sprintf( checkPointMsg, |
51 |
"Sucessfully opened output file for stating.\n"); |
52 |
MPIcheckPoint(); |
53 |
#endif // is_mpi |
54 |
|
55 |
tStats = new Thermo( entry_plug ); |
56 |
} |
57 |
|
58 |
StatWriter::~StatWriter( ){ |
59 |
|
60 |
#ifdef IS_MPI |
61 |
if(worldRank == 0 ){ |
62 |
#endif // is_mpi |
63 |
|
64 |
outFile.close(); |
65 |
delete tStats; |
66 |
|
67 |
#ifdef IS_MPI |
68 |
} |
69 |
#endif // is_mpi |
70 |
} |
71 |
|
72 |
void StatWriter::writeStat( double currentTime ){ |
73 |
|
74 |
double totE, potE, kinE, temp, press, vol; |
75 |
double conservedQuantity; |
76 |
|
77 |
totE = tStats->getTotalE(); |
78 |
potE = tStats->getPotential(); |
79 |
kinE = tStats->getKinetic(); |
80 |
temp = tStats->getTemperature(); |
81 |
press = tStats->getPressure(); |
82 |
vol = tStats->getVolume(); |
83 |
conservedQuantity = entry_plug->the_integrator->getConservedQuantity(); |
84 |
|
85 |
#ifdef IS_MPI |
86 |
if(worldRank == 0 ){ |
87 |
#endif // is_mpi |
88 |
|
89 |
outFile.precision(8); |
90 |
outFile |
91 |
<< currentTime << "\t" |
92 |
<< totE << "\t" |
93 |
<< potE << "\t" |
94 |
<< kinE << "\t" |
95 |
<< temp << "\t" |
96 |
<< press << "\t" |
97 |
<< vol << "\t" |
98 |
<< conservedQuantity; |
99 |
|
100 |
if (entry_plug->useSolidThermInt || entry_plug->useLiquidThermInt) |
101 |
outFile << "\t" << entry_plug->vRaw; |
102 |
|
103 |
if (entry_plug->useSolidThermInt) |
104 |
outFile << "\t" << entry_plug->vHarm; |
105 |
|
106 |
outFile << "\n"; |
107 |
|
108 |
outFile.flush(); |
109 |
|
110 |
#ifdef IS_MPI |
111 |
} |
112 |
#endif // is_mpi |
113 |
} |
114 |
|