23 {
24 if(argc < 5) {
25 std::cerr << "Usage: 1.This 2.Directory 3.Nmax 4.Nmin 5.dE (Op1).SampleMin (Op2).SampleMax" << std::endl;
26 std::exit(EX_USAGE);
27 }
28 constexpr int NDIV = 100;
29 int const Nmax = (argc>=3 ? std::stoi(argv[2]) :16);
30 int const Nmin = (argc>=4 ? std::stoi(argv[3]) :16);
31 double const dE = (argc>=5 ? std::stod(argv[4]) :0.02);
32 int const SampleMin = (argc>=6 ? std::stod(argv[5]) :-1);
33 int const SampleMax = (argc>=7 ? std::stod(argv[6]) :-1);
34 if(Nmax < Nmin) {
35 std::cerr << "Error: Nmax(" << Nmax << ") < Nmin(" << Nmin << ")" << std::endl;
36 std::exit(EX_USAGE);
37 }
38
39
40 std::string const baseDir(argv[1]);
41 std::cout << "# Directory: " << baseDir << "\n";
42 std::string InDataDir(baseDir); InDataDir += "/RawData";
43 std::vector<std::string> dirList;
44 {
45 std::string str;
46 int dataNo;
47 int const idShift=(SampleMin>0? SampleMin: 0);
48 if(SampleMin>0 && SampleMax>0) dirList.resize(SampleMax-idShift+1);
49 for(
const filesystem::directory_entry &entry :
filesystem::directory_iterator(InDataDir)) {
50 if ( entry.is_directory() ) {
51 str = entry.path().string();
52 dataNo = std::atoi(str.substr(str.find("_No")+3).c_str());
53 if((SampleMin>0 || SampleMax>0) && (dataNo<SampleMin || SampleMax<dataNo)) continue;
54 debug_print(
"# dir=" << str <<
", dataNo=" << dataNo);
55 if( (SampleMin<=0 || SampleMax<=0) && dirList.size()<=dataNo) dirList.resize(dataNo+1);
56 debug_print(
"dataNo-idShift=" << dataNo-idShift <<
", dataNo=" << dataNo <<
", idShift=" << idShift);
57 dirList.at(dataNo-idShift) = str;
58 }
59 }
60 }
61
62
63 #pragma omp parallel for schedule(dynamic, 10)
64 for(size_t sample = 0;sample < dirList.size(); ++sample) {
65
66 int n, bin, binMax, binMin;
68 std::string command;
69 double OpRange, dtemp;
70 std::vector<double> eigenEnergy, eigenExpValue, MCAverage, binStddev(NDIV);
71 std::vector<Integer_t> NdataInShell;
72 std::vector<std::vector<Integer_t>> binElem(NDIV);
73 constexpr auto Bin = [&](
double x) {
return (x==1 ? NDIV-1: (int)(x*NDIV)); };
74 std::string InExpValueFname, InEnergyFname, InMatElemsFname, str;
75 std::ifstream InExpValueFs, InEnergyFs, InMatElemsFs;
76 std::string OutFname;
77 std::ofstream OutFs;
78 std::vector<std::string> candidateFileNames;
79
80
81
82 std::string OutDir(std::regex_replace(dirList[sample], std::regex("/RawData"), "/ProcessedData"));
83 filesystem::create_directories(OutDir);
84
85 bool flag = false;
86 for(n = Nmin;n <= Nmax; ++n) {
87 dim = 0;
88 std::stringstream
buff(
"");
buff <<
"_N" << n <<
".txt";
89 {
90 std::stringstream ss;
91 candidateFileNames.resize(3);
92 candidateFileNames[0] = dirList[sample] +
"/EigenExpValueZ" +
buff.str();
93 candidateFileNames[1] = dirList[sample] +
"/EigenExpValueC" +
buff.str();
94 candidateFileNames[2] = dirList[sample] +
"/EigenExpValue" +
buff.str();
95 if( InExpValueFs.is_open() ) { InExpValueFs.close(); InExpValueFs.clear(); }
96 for(auto name : candidateFileNames) {
97 InExpValueFname = name;
98 InExpValueFs.open(InExpValueFname);
99 if( InExpValueFs.is_open() ) break;
100 }
101 if( !InExpValueFs.is_open() ) continue;
102 flag = true;
103 InExpValueFs.exceptions(std::ios::badbit | std::ios::failbit);
104 while( std::getline(InExpValueFs, str) ) if(str.find("OpRange") != std::string::npos) break;
105 OpRange = std::stod(str.substr(str.find("OpRange=")+8));
106
107 eigenEnergy.resize(0);
108 eigenExpValue.resize(0);
109 try{
110 skip_header(InExpValueFs);
111 for(getline(InExpValueFs, str); !InExpValueFs.eof(); getline(InExpValueFs, str)) {
112 ss.str(str); ss.clear(std::stringstream::goodbit);
113 ss >> dtemp; eigenEnergy.push_back(dtemp);
114 ss >> dtemp;
115 ss >> dtemp; eigenExpValue.push_back(dtemp/OpRange);
116 }
117 } catch(std::exception& e) {
118 if( !InExpValueFs.eof() )
119 std::cerr << "Error(" << InExpValueFs.eof() << InExpValueFs.fail() << InExpValueFs.bad() << "):" << e.what() << std::endl;
120 }
121 InExpValueFs.close(); InExpValueFs.clear();
122 if(eigenEnergy.size() != eigenExpValue.size()) {
123 std::cerr << "Error: eigenEnergy.size() != eigenExpValue.size() for a file\n"
124 << "\t" << InExpValueFname << std::endl;
125 continue;
126 }
127 dim = eigenEnergy.size();
128 }
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199 #ifndef NDEBUG
200 std::cout << std::scientific;
201 std::cout << "# OpRange = " << OpRange << std::endl;
202 print(eigenEnergy, eigenEnergy.size());
203 print(eigenExpValue, eigenExpValue.size());
204 #endif
206
207
208 MCAverage.resize(dim); NdataInShell.resize(dim);
209 std::fill( MCAverage.begin(), MCAverage.end(), 0.0);
210 std::fill(NdataInShell.begin(), NdataInShell.end(), 0.0);
213 }
214
215 for(size_t bin = 0;bin < NDIV; ++bin) binElem[bin].resize(0);
216 for(size_t i = 0;i < dim; ++i) {
217 if( NdataInShell[i] <= 1 ) continue;
218 bin =
Bin(eigenEnergy[i]);
219 for(binMin = bin;binMin>=0 && std::abs(eigenEnergy[i] - (binMin+0.5)/NDIV) <
dE; --binMin) {}; ++binMin;
220 for(binMax = bin;binMax<NDIV && std::abs(eigenEnergy[i] - (binMax+0.5)/NDIV) <
dE; ++binMax) {}; --binMax;
221 if(binMin < 0) binMin = 0;
222 debug_print(
"binMin=" << binMin <<
", binMax=" << binMax <<
", Energy=" << eigenEnergy[i]);
223 for(bin = binMin;bin <= binMax; ++bin) binElem.at(bin).push_back(i);
224 }
225 std::fill(binStddev.begin(), binStddev.end(), 0.0);
226
227 #pragma omp parallel for
228 for(size_t bin = 0;bin < NDIV; ++bin) {
229 for(auto const& i : binElem[bin]) {
230 double dtemp = eigenExpValue[i] - MCAverage[i];
231 binStddev[bin] += dtemp*dtemp;
232 }
233 if(binElem[bin].
size() == 0) binStddev[bin] = NAN;
234 else binStddev[bin] = sqrt(binStddev[bin]/binElem[bin].
size());
235 }
236 debug_print(
"########## (END)Some process ##########\n");
237
238 {
239 std::stringstream
buff(
"");
buff <<
"_N" << n <<
".txt";
240 OutFname = OutDir +
"/SrednickiAnsatz_Diagonal" +
buff.str();
241 }
242 if( OutFs.is_open() ) { OutFs.close(); OutFs.clear(); }
244 OutFs << "# NDIV= " << NDIV << "\n"
245 <<
"# shellWidth= " <<
dE <<
"\n"
246 << "# 1.(N), 2.(Normalized energy), 3.(ExpValue), 4.(Stddev), 5.(funcF), 6.(DOS), 7.(Ndata)" << "\n\n";
247 OutFs << std::scientific << std::showpos;
248 for(size_t bin = 0;bin < NDIV; ++bin) {
249 OutFs << n << " "
250 << (bin+0.5)/NDIV << " "
251 << "nan" << " "
252 << binStddev[bin] << " "
253 << binStddev[bin]*sqrt((double)binElem[bin].size()) << " "
254 << "nan" << " "
255 << binElem[bin].
size()
256 << std::endl;
257 }
258 OutFs.close();
259 }
260 if(flag) std::cout << "# " << dirList[sample] << std::endl;
261 }
262
263 return EXIT_SUCCESS;
264}
Integer_t Bin(double x)
Definition Overlap.cpp:59
namespace filesystem
Definition Fluc_randHOp.cpp:38
Calculate the microcanonical averages with respect to a given sorted vector 'eigVal'.
Definition MicroCanonicalAverage.hpp:25
bool checkIsFileOpen(std::ifstream &file, std::string const &filename)
Definition file_util.hpp:22
debug_print("# Determining GPU configuration.")
MKL_INT Integer_t
Definition mytypes.hpp:359
double const dE
Definition setVariablesForMCAverage.cpp:2
__constant__ int size
Definition testEigenOnGPU.cu:4
std::stringstream buff("")