ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/StatWriter.cpp
Revision: 1212
Committed: Tue Jun 1 17:15:43 2004 UTC (20 years, 3 months ago) by chrisfen
File size: 3526 byte(s)
Log Message:
Implemented a separate solid and liquid thermodynamic integration routines

File Contents

# User Rev Content
1 tim 1078 #define _LARGEFILE_SOURCE64
2 mmeineke 723 #define _FILE_OFFSET_BITS 64
3    
4 gezelter 829 #include <string.h>
5 mmeineke 377 #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 chrisfen 1180 strcpy( rawName, entry_plug->rawPotName );
22    
23 gezelter 484 //std::cerr << "Opening " << outName << " for stat\n";
24 mmeineke 377
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 chrisfen 1180
36 mmeineke 377 //outFile.setf( ios::scientific );
37 mmeineke 799 outFile << "#time(fs)\ttot_E\tpotential\tkinetic\ttemperature\tpressure\tvolume\tconserved quantity\n";
38 mmeineke 377
39 chrisfen 1212 if (entry_plug->useSolidThermInt && !entry_plug->useLiquidThermInt) {
40 chrisfen 1187 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 mmeineke 377
54 chrisfen 1212 if (entry_plug->useLiquidThermInt) {
55     if (entry_plug->useSolidThermInt) {
56     sprintf( painCave.errMsg,
57     "It appears that you have both solid and liquid thermodynamic\n"
58     "integration activated in your .bass file. To avoid confusion,\n"
59     "specify only one technique in your .bass file. Liquid-state\n"
60     "thermodynamic integration will be assumed for the current\n"
61     "simulation. If this is not what you desire, set useSolidThermInt\n"
62     "to 'true' and useLiquidThermInt to 'false' in your .bass file.",
63     rawName);
64     painCave.isFatal = 0;
65     simError();
66     }
67    
68     rawFile.open(rawName, ios::out | ios::trunc );
69    
70     if( !rawFile ){
71    
72     sprintf( painCave.errMsg,
73     "Could not open \"%s\" for stat output.\n",
74     rawName);
75     painCave.isFatal = 1;
76     simError();
77     }
78    
79     rawFile << "#time(fs)\tRaw Pot\n";
80     }
81    
82 mmeineke 377 #ifdef IS_MPI
83     }
84    
85     sprintf( checkPointMsg,
86     "Sucessfully opened output file for stating.\n");
87     MPIcheckPoint();
88     #endif // is_mpi
89    
90     tStats = new Thermo( entry_plug );
91     }
92    
93     StatWriter::~StatWriter( ){
94    
95     #ifdef IS_MPI
96     if(worldRank == 0 ){
97     #endif // is_mpi
98    
99     outFile.close();
100 chrisfen 1180 rawFile.close();
101 mmeineke 377 delete tStats;
102    
103     #ifdef IS_MPI
104     }
105     #endif // is_mpi
106     }
107    
108     void StatWriter::writeStat( double currentTime ){
109    
110 mmeineke 799 double totE, potE, kinE, temp, press, vol;
111 tim 763 double conservedQuantity;
112 mmeineke 377
113     totE = tStats->getTotalE();
114     potE = tStats->getPotential();
115     kinE = tStats->getKinetic();
116     temp = tStats->getTemperature();
117 gezelter 477 press = tStats->getPressure();
118 gezelter 484 vol = tStats->getVolume();
119 tim 763 conservedQuantity = entry_plug->the_integrator->getConservedQuantity();
120 mmeineke 377 #ifdef IS_MPI
121     if(worldRank == 0 ){
122     #endif // is_mpi
123    
124     outFile.precision(8);
125     outFile
126     << currentTime << "\t"
127     << totE << "\t"
128     << potE << "\t"
129     << kinE << "\t"
130 gezelter 468 << temp << "\t"
131 gezelter 484 << press << "\t"
132     << vol << "\t"
133 tim 763 << conservedQuantity << "\n";
134 gezelter 484
135 mmeineke 377 outFile.flush();
136    
137     #ifdef IS_MPI
138     }
139     #endif // is_mpi
140     }
141 chrisfen 1180
142     void StatWriter::writeRaw( double currentTime ){
143    
144     double rawPot, rawHarm;
145    
146     rawPot = entry_plug->vRaw;
147     rawHarm = entry_plug->vHarm;
148    
149     #ifdef IS_MPI
150     if(worldRank == 0 ){
151     #endif // is_mpi
152    
153     rawFile.precision(8);
154     rawFile
155     << currentTime << "\t"
156     << rawPot << "\t"
157     << rawHarm << "\n";
158    
159     rawFile.flush();
160    
161     #ifdef IS_MPI
162     }
163     #endif // is_mpi
164     }