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 |
strcpy( rawName, entry_plug->rawPotName ); |
22 |
|
23 |
//std::cerr << "Opening " << outName << " for stat\n"; |
24 |
|
25 |
outFile.open(outName, ios::out | ios::trunc ); |
26 |
|
27 |
if( !outFile ){ |
28 |
|
29 |
sprintf( painCave.errMsg, |
30 |
"Could not open \"%s\" for stat output.\n", |
31 |
outName); |
32 |
painCave.isFatal = 1; |
33 |
simError(); |
34 |
} |
35 |
|
36 |
//outFile.setf( ios::scientific ); |
37 |
outFile << "#time(fs)\ttot_E\tpotential\tkinetic\ttemperature\tpressure\tvolume\tconserved quantity\n"; |
38 |
|
39 |
if (entry_plug->useSolidThermInt && !entry_plug->useLiquidThermInt) { |
40 |
rawFile.open(rawName, ios::out | ios::trunc ); |
41 |
|
42 |
if( !rawFile ){ |
43 |
|
44 |
sprintf( painCave.errMsg, |
45 |
"Could not open \"%s\" for stat output.\n", |
46 |
rawName); |
47 |
painCave.isFatal = 1; |
48 |
simError(); |
49 |
} |
50 |
|
51 |
rawFile << "#time(fs)\tRaw Pot\t Raw Harm\n"; |
52 |
} |
53 |
|
54 |
if (entry_plug->useLiquidThermInt) { |
55 |
rawFile.open(rawName, ios::out | ios::trunc ); |
56 |
|
57 |
if( !rawFile ){ |
58 |
|
59 |
sprintf( painCave.errMsg, |
60 |
"Could not open \"%s\" for stat output.\n", |
61 |
rawName); |
62 |
painCave.isFatal = 1; |
63 |
simError(); |
64 |
} |
65 |
|
66 |
rawFile << "#time(fs)\tRaw Pot\n"; |
67 |
} |
68 |
|
69 |
#ifdef IS_MPI |
70 |
} |
71 |
|
72 |
sprintf( checkPointMsg, |
73 |
"Sucessfully opened output file for stating.\n"); |
74 |
MPIcheckPoint(); |
75 |
#endif // is_mpi |
76 |
|
77 |
tStats = new Thermo( entry_plug ); |
78 |
} |
79 |
|
80 |
StatWriter::~StatWriter( ){ |
81 |
|
82 |
#ifdef IS_MPI |
83 |
if(worldRank == 0 ){ |
84 |
#endif // is_mpi |
85 |
|
86 |
outFile.close(); |
87 |
rawFile.close(); |
88 |
delete tStats; |
89 |
|
90 |
#ifdef IS_MPI |
91 |
} |
92 |
#endif // is_mpi |
93 |
} |
94 |
|
95 |
void StatWriter::writeStat( double currentTime ){ |
96 |
|
97 |
double totE, potE, kinE, temp, press, vol; |
98 |
double conservedQuantity; |
99 |
|
100 |
totE = tStats->getTotalE(); |
101 |
potE = tStats->getPotential(); |
102 |
kinE = tStats->getKinetic(); |
103 |
temp = tStats->getTemperature(); |
104 |
press = tStats->getPressure(); |
105 |
vol = tStats->getVolume(); |
106 |
conservedQuantity = entry_plug->the_integrator->getConservedQuantity(); |
107 |
#ifdef IS_MPI |
108 |
if(worldRank == 0 ){ |
109 |
#endif // is_mpi |
110 |
|
111 |
outFile.precision(8); |
112 |
outFile |
113 |
<< currentTime << "\t" |
114 |
<< totE << "\t" |
115 |
<< potE << "\t" |
116 |
<< kinE << "\t" |
117 |
<< temp << "\t" |
118 |
<< press << "\t" |
119 |
<< vol << "\t" |
120 |
<< conservedQuantity << "\n"; |
121 |
|
122 |
outFile.flush(); |
123 |
|
124 |
#ifdef IS_MPI |
125 |
} |
126 |
#endif // is_mpi |
127 |
} |
128 |
|
129 |
void StatWriter::writeRaw( double currentTime ){ |
130 |
|
131 |
double rawPot, rawHarm; |
132 |
|
133 |
rawPot = entry_plug->vRaw; |
134 |
rawHarm = entry_plug->vHarm; |
135 |
|
136 |
#ifdef IS_MPI |
137 |
if(worldRank == 0 ){ |
138 |
#endif // is_mpi |
139 |
|
140 |
rawFile.precision(8); |
141 |
rawFile |
142 |
<< currentTime << "\t" |
143 |
<< rawPot << "\t" |
144 |
<< rawHarm << "\n"; |
145 |
|
146 |
rawFile.flush(); |
147 |
|
148 |
#ifdef IS_MPI |
149 |
} |
150 |
#endif // is_mpi |
151 |
} |