StatMech
Loading...
Searching...
No Matches
OpAverage.cpp File Reference

Classes

class  Histogram
 

Functions

int main (int argc, char **argv)
 

Variables

namespace filesystem = std::experimental::filesystem
 
Integer_t const NBIN = 100
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
85 {
86 if(argc < 3) {
87 printf("Usage: 1.This 2.Directory 3.Shell width\n");
88 exit(EXIT_FAILURE);
89 }
90 std::string const d_str(argv[1]);
91 double const shellWidth = (double)std::atof(argv[2]);
92 std::cout << "Directory: " << d_str << "\n";
93
94 Integer_t n, Nmin, Nmax=0, bin, count=0, Nline;
95 double relEnergy, expval;
96 double Emin, Emax, StddevInShell, dtemp;
97 std::vector<Integer_t> Ndata, NdataInShell;
98 std::vector<double> MCAverage;
99 std::vector<std::vector<double>> eigenEnergy;
100 std::vector<std::vector<double>> ExpValue;
101 std::vector<Histogram> Average;
102 Histogram BinData;
103
104 std::string line;
105
106 //********** Output fileを作成 ********** //
107 std::string OutProcDIR(d_str); OutProcDIR += "/ProcessedData/";
108 filesystem::create_directory(OutProcDIR);
109 std::string OutProcFName;
110 //********** (END)Output fileを作成 ********** //
111
112 //********** Input directory ********** //
113 std::string InDataDir(d_str); InDataDir += "/RawData";
114 for(const std::filesystem::directory_entry &data : std::filesystem::directory_iterator(InDataDir)) {
115 if( data.path().string().find("Sample_No") == std::string::npos ) continue;
116 if( data.path().extension() != ".txt" ) continue;
117 std::ifstream Infs(data.path());
118 Infs.exceptions(std::ios::badbit | std::ios::failbit);
119 if( !Infs.is_open() ) {
120 std::cerr << "Can't open a file \"" << data.path() << "\"" << std::endl;
121 continue;
122 }
123 try { skip_header(Infs); }
124 catch(std::exception& e) {
125 std::cerr << "Warning(skip_header): " << e.what() << std::endl;
126 std::cerr << "File: \"" << data.path() << "\" is empty." << std::endl;
127 continue;
128 }
129
130 //********** Read data **********//
131 ++count;
132 Nmin=INT_MAX; Nmax=INT_MIN;
133 std::fill(Ndata.begin(),Ndata.end(),0);
134 for(n = 0;n < eigenEnergy.size(); ++n) eigenEnergy.at(n).resize(0);
135 for(n = 0;n < ExpValue.size(); ++n) ExpValue.at(n).resize(0);
136 try{
137 Nline = 0;
138 for(std::getline(Infs, line); !Infs.eof(); std::getline(Infs, line)) {
139 ++Nline;
140 std::cout << "(count=" << count << ", line=" << Nline << "): " << line << ": " << Infs.eof() << "\r";
141 std::istringstream inStream(line);
142 inStream >> n >> dtemp >> relEnergy >> expval;
143 if( isinf(expval) || isnan(expval) ) std::cerr << expval << std::endl;
144 if(n < Nmin) Nmin = n;
145 if(n > Nmax) Nmax = n;
146 if(n >= Ndata.size()) Ndata.resize(n+1);
147 if(n >= eigenEnergy.size()) eigenEnergy.resize(n+1);
148 if(n >= ExpValue.size()) ExpValue.resize(n+1);
149 Ndata.at(n) += 1;
150 eigenEnergy.at(n).push_back(relEnergy);
151 ExpValue.at(n).push_back(expval);
152 }
153 } catch(std::exception& e) {
154 if( !Infs.eof() ) {
155 std::cout << std::endl;
156 std::cerr << "Error(" << Infs.eof() << Infs.fail() << Infs.bad() << "): " << e.what() << std::endl;
157 }
158 }
159 Infs.close();
160 //********** (END) Read data **********//
161
162 OutProcFName = OutProcDIR + data.path().filename().string();
163 std::ofstream OutProcfs(OutProcFName);
164 OutProcfs.exceptions(std::ios::badbit | std::ios::failbit);
165 if( !OutProcfs.is_open() ) {
166 std::cerr << "Can't open a file " << OutProcFName << std::endl;
167 std::exit(EX_CANTCREAT);
168 }
169 OutProcfs << "# NBIN = " << NBIN << "\n"
170 << "# shellWidth = " << shellWidth << "\n"
171 << "# 1.(N), 2.(ratio), 3.(ExpValue), 4.(Stddev), 5.(funcF), 6.(DOS), 7.(Ndata), 8.(Nan data)\n"
172 << std::scientific
173 << std::endl;
174 std::cout << "(count=" << count << ") Output file(Histogram): " << OutProcFName << std::endl;
175
176 if(Nmax >= Average.size()) Average.resize(Nmax+1);
177 for(n = Nmax;n >= Nmin; --n) {
178 if(Ndata[n] != eigenEnergy[n].size()) {
179 std::cerr << "Error: Ndata[" << n << "](" << Ndata[n]
180 << ") != eigenEnergy[" << n << "].size (" << eigenEnergy[n].size() << ")"
181 << std::endl;
182 std::exit(EX_DATAERR);
183 }
184 if(Ndata[n] != ExpValue[n].size()) {
185 std::cerr << "Error: Ndata[" << n << "](" << Ndata[n]
186 << ") != ExpValue[" << n << "].size (" << ExpValue[n].size() << ")"
187 << std::endl;
188 std::exit(EX_DATAERR);
189 }
190
191 MCAverage.resize(Ndata[n]); NdataInShell.resize(Ndata[n]);
192 std::fill( MCAverage.begin(), MCAverage.end(), 0.0);
193 std::fill(NdataInShell.begin(), NdataInShell.end(), 0.0);
194 for(Integer_t i = 0;i < Ndata[n]; ++i) {
195 MCAverage[i] = MicroCanonicalAverage(NdataInShell[i], eigenEnergy[n][i], shellWidth, Ndata[n], eigenEnergy[n], ExpValue[n], i);
196 }
197
198 BinData.clear();
199 for(int i = 0;i < Ndata[n]; ++i) {
200 Emin = eigenEnergy[n][i] -shellWidth;
201 Emax = eigenEnergy[n][i] +shellWidth;
202 if((bin=MeasureOfETH(StddevInShell, dtemp, dtemp, Emin, Emax, Ndata[n], eigenEnergy[n], ExpValue[n], MCAverage)) != NdataInShell[i]) {
203 std::cerr << "Warning:(n,Nmax,i)=(" << n << "," << Nmax << "," << i << ") MeasureOfETH(" << bin << ") != NdataInShell[" << NdataInShell[i] << "]" << std::endl;
204 }
205 BinData.add(eigenEnergy[n][i], ExpValue[n][i], StddevInShell, NdataInShell[i]);
206 }
207
208 for(bin = 0;bin < NBIN; ++bin) {
209
210 BinData.DOS[bin] = BinData.Ndata[bin]*NBIN/(double)BinData.Ntot;
211 OutProcfs << std::noshowpos
212 << std::setw(2) << n << " "
213 << std::showpos
214 << std::setw(13) << (bin+0.5)/(double)NBIN << " "
215 << std::setw(13) << BinData.ExpValue[bin] << " "
216 << std::setw(13) << BinData.Stddev[bin] << " "
217 << std::setw(13) << BinData.funcF[bin] << " "
218 << std::setw(13) << BinData.DOS[bin] << " "
219 << std::setw(4) << BinData.Ndata[bin] << "\n";
220 }
221 OutProcfs << std::endl;
222
223 if(BinData.Ntot > 0 && n==Nmax) Average.at(n).add(BinData);
224 }
225 OutProcfs.close();
226 }
227 //********** (END) Input directory ********** //
228
229
230 //********** アンサンブル平均のファイルへの書き込み **********//
231 std::string OutDIR(d_str); OutDIR += "/Output";
232 filesystem::create_directory(OutDIR);
233 std::stringstream buff;
234 buff.str("");
235 buff.clear(std::stringstream::goodbit);
236 buff << "/EnsembleAverage" << ".txt";
237 std::string OutAveFName(OutDIR); OutAveFName += buff.str();
238 std::ofstream OutAvefs(OutAveFName);
239 OutAvefs.exceptions(std::ios::badbit | std::ios::failbit);
240 if( !OutAvefs.is_open() ) {
241 std::cerr << "Can't open a file " << OutAveFName << std::endl;
242 std::exit(EX_CANTCREAT);
243 }
244 OutAvefs << "# NBIN = " << NBIN << "\n"
245 << "# Nsample = " << Average[Nmax].Ntot << "\n"
246 << "# shellWidth = " << shellWidth << "\n"
247 << "# 1.(N), 2.(ratio), 3.(ExpValue), 4.(Stddev), 5.(funcF), 6.(DOS), 7.(Ndata), 8.(Nan data)\n"
248 << std::scientific
249 << std::endl;
250 std::cout << "Output file: " << OutAveFName << std::endl;
251
252 Integer_t flag;
253 for(n = Nmax;n >= Nmin; --n) {
254 flag = 0;
255 for(bin = 0;bin < NBIN; ++bin) {
256 if( Average[n].Ndata[bin] == 0) continue;
257 flag = 1;
258 OutAvefs << std::noshowpos
259 << std::setw(2) << n << " "
260 << std::showpos
261 << std::setw(13) << (bin+0.5)/(double)NBIN << " "
262 << std::setw(13) << Average[n].ExpValue[bin] << " "
263 << std::setw(13) << Average[n].Stddev[bin] << " "
264 << std::setw(13) << Average[n].funcF[bin] << " "
265 << std::setw(13) << Average[n].DOS[bin] << " "
266 << std::setw(13) << Average[n].Ndata[bin] << " "
267 << std::setw(4) << Average[n].Nnan[bin] << "\n";
268 }
269 if(flag == 1) OutAvefs << std::endl;
270 }
271 OutAvefs.close();
272 //********** (END)アンサンブル平均のファイルへの書き込み **********//
273
274 return 0;
275}
namespace filesystem
Definition OpAverage.cpp:14
Integer_t const NBIN
Definition OpAverage.cpp:20
Definition OpAverage.cpp:21
std::vector< double > funcF
Definition OpAverage.cpp:29
void add(double relEnergy, double Expval, double stddev, Integer_t NdataInShell)
Definition OpAverage.cpp:33
std::vector< double > Stddev
Definition OpAverage.cpp:28
std::vector< Integer_t > Ndata
Definition OpAverage.cpp:25
std::vector< double > ExpValue
Definition OpAverage.cpp:27
std::vector< double > DOS
Definition OpAverage.cpp:30
void clear()
Definition OpAverage.cpp:74
Integer_t Ntot
Definition OpAverage.cpp:24
Calculate the microcanonical averages with respect to a given sorted vector 'eigVal'.
Definition MicroCanonicalAverage.hpp:25
MKL_INT Integer_t
Definition mytypes.hpp:359
constexpr double Emin
Definition setVariablesForMCAverage.cpp:4
constexpr double Emax
Definition setVariablesForMCAverage.cpp:5
Integer_t MeasureOfETH(double &Fluc_2, double &Fluc_inf, double &MaxPos, double const Emin, double const Emax, Integer_t const dim, const std::vector< double > &eigenEnergy, const std::vector< double > &EXPvalue, const std::vector< double > &MCAverage)
Definition statmech.cpp:244
__constant__ int size
Definition testEigenOnGPU.cu:4
std::stringstream buff("")

Variable Documentation

◆ filesystem

namespace filesystem = std::experimental::filesystem

◆ NBIN

Integer_t const NBIN = 100