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

Functions

int main (int argc, char **argv)
 

Variables

namespace filesystem = std::experimental::filesystem
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
23 {
24 if(argc < 6) {
25 std::cerr << "Usage: 1.This 2.Directory 3.Nmax 4.Nmin 5.dE 6.Emin 7.Emax (Op1).NdataMax" << std::endl;
26 std::exit(EX_USAGE);
27 }
28 int const Nmax = (argc>=3 ? std::stoi(argv[2]) :16);
29 int const Nmin = (argc>=4 ? std::stoi(argv[3]) :16);
30 double const dE = (argc>=5 ? std::stod(argv[4]) :0.02);
31 double const Emin = (argc>=6 ? std::stod(argv[5]) :0.45);
32 double const Emax = (argc>=7 ? std::stod(argv[6]) :0.55);
33 int const NdataMax = (argc>=8 ? std::stod(argv[7]) :-1);
34
35 std::string const baseDir(argv[1]);
36 std::cout << "# Directory: " << baseDir << "\n";
37 std::string const InDataDir(baseDir+"/RawData");
38 std::vector<std::string> dirList;
39 {
40 std::string str;
41 int dataNo;
42 if(NdataMax>0) dirList.resize(NdataMax);
43 for(const filesystem::directory_entry &entry : filesystem::directory_iterator(InDataDir)) {
44 if ( entry.is_directory() ) {
45 str = entry.path().string();
46 dataNo = std::atoi(str.substr(str.find("_No")+3).c_str());
47 if(NdataMax>0 && dataNo>=NdataMax) continue;
48 debug_print("# dir=" << str << ", dataNo=" << dataNo);
49 if(NdataMax<=0 && dirList.size()<=dataNo) dirList.resize(dataNo+1);
50 dirList.at(dataNo) = str;
51 }
52 }
53 }
54
55
56 class measureOfETH {
57 public:
58 double Fluc;
59 double MaxFluc;
60 double MaxPos;
61 Integer_t Ndata;
62 measureOfETH() : Fluc(NAN), MaxFluc(NAN), MaxPos(NAN), Ndata(-1) {};
63 };
64 std::vector<std::vector<measureOfETH>> Data(Nmax+1);
65 for(size_t n = Nmin;n <= Nmax; ++n) {
66 Data.at(n).resize(dirList.size());
67 // std::fill(Data.at(n).begin(), Data.at(n).end(), -1);
68 }
69
70 #pragma omp parallel for schedule(dynamic, 10)
71 for(size_t sample = 0;sample < dirList.size(); ++sample) {
72 std::string str;
73 std::stringstream ss;
74 Integer_t dim;
75 std::vector<Integer_t> NdataInShell;
76 std::vector<double> eigenEnergy;
77 std::vector<double> eigenExpValue;
78 std::vector<double> MCAverage;
79 double OpRange, dtemp, energy;
80
81 std::ifstream InExpValueFs;
82 std::string InExpValueFname;
83 std::vector<std::string> candidateFileNames;
84
85
86 #pragma omp critical
87 std::cout << "# " << dirList[sample] << std::endl;
88 for(size_t n = Nmin;n <= Nmax; ++n) {
89 bool failFlag = false;
90 std::stringstream buff(""); buff << "_N" << n << ".txt";
91 //-------------------- Load eigen-energies --------------------//
92 candidateFileNames.resize(3);
93 candidateFileNames[0] = dirList[sample] + "/EigenExpValueZ" + buff.str();
94 candidateFileNames[1] = dirList[sample] + "/EigenExpValueC" + buff.str();
95 candidateFileNames[2] = dirList[sample] + "/EigenExpValue" + buff.str();
96 if( InExpValueFs.is_open() ) { InExpValueFs.close(); InExpValueFs.clear(); }
97 for(auto name : candidateFileNames) {
98 InExpValueFname = name;
99 InExpValueFs.open(InExpValueFname);
100 if( InExpValueFs.is_open() ) break;
101 }
102 if( !InExpValueFs.is_open() ) {
103 #pragma omp critical
104 std::cout << "Warning(N=" << n << "): Nodata file for '" << dirList[sample] <<"'." << std::endl;
105 continue;
106 }
107 InExpValueFs.exceptions(std::ios::badbit | std::ios::failbit);
108 #pragma omp critical
109 debug_print("InFileName= " << InExpValueFname);
110 while( std::getline(InExpValueFs, str) ) if(str.find("OpRange") != std::string::npos) break;
111 OpRange = std::stod(str.substr(str.find("OpRange=")+8));
112
113 eigenEnergy.resize(0);
114 eigenExpValue.resize(0);
115 try{
116 skip_header(InExpValueFs);
117 for(getline(InExpValueFs, str); !InExpValueFs.eof(); getline(InExpValueFs, str)) {
118 // debug_print(" Read line= " << str);
119 ss.str(str); ss.clear(std::stringstream::goodbit);
120 ss >> energy; eigenEnergy.push_back(energy);
121 ss >> dtemp;
122 ss >> dtemp; eigenExpValue.push_back(dtemp/OpRange);
123 if( (Emin<energy && energy<Emax) && (isnan(dtemp) || isinf(dtemp)) ) { failFlag=true; break; }
124 }
125 } catch(std::exception& e) {
126 if( !InExpValueFs.eof() )
127 std::cerr << "Error(" << InExpValueFs.eof() << InExpValueFs.fail() << InExpValueFs.bad() << "):" << e.what() << std::endl;
128 }
129 InExpValueFs.close(); InExpValueFs.clear();
130 if(failFlag) {
131 #pragma omp critical
132 std::cerr << "File: " << InExpValueFname << " contains NAN." << std::endl;
133 continue;
134 }
135
136 if(eigenEnergy.size() != eigenExpValue.size()) {
137 std::cerr << "Error: eigenEnergy.size() != eigenExpValue.size() for a file\n"
138 << "\t" << InExpValueFname << std::endl;
139 continue;
140 }
141 dim = eigenEnergy.size();
142
143 debug_print("########## Some process ##########");
144 // Calculate Microcanonical averages with energy corresponding to each eigenstate.
145 MCAverage.resize(dim); NdataInShell.resize(dim);
146 std::fill( MCAverage.begin(), MCAverage.end(), 0.0);
147 std::fill(NdataInShell.begin(), NdataInShell.end(), 0.0);
148 for(Integer_t i = 0;i < dim; ++i) {
149 MCAverage[i] = MicroCanonicalAverage(NdataInShell[i], eigenEnergy[i], dE, dim, eigenEnergy, eigenExpValue, i);
150 }
151
152 double Fluc, MaxFluc, MaxPos;
153 Integer_t ndata;
154 ndata = MeasureOfETH(Fluc, MaxFluc, MaxPos, Emin, Emax, dim, eigenEnergy, eigenExpValue, MCAverage);
155 // #pragma omp critical
156 // debug_print("Fluc=" << Fluc << ", MaxFluc=" << MaxFluc << ", MaxPos=" << MaxPos << ", Ndata=" << ndata);
157 Data.at(n).at(sample).Fluc = Fluc;
158 Data.at(n).at(sample).MaxFluc = MaxFluc;
159 Data.at(n).at(sample).MaxPos = MaxPos;
160 Data.at(n).at(sample).Ndata = (ndata > 0 ? ndata : -1);
161 debug_print("########## (END)Some process ##########\n");
162 }
163 }
164
165
166 std::string OutDir, OutFname;
167 std::ofstream OutFs;
168 {
169 std::stringstream buff("");
170 buff << "/Measure_Emin" << Emin << "_Emax" << Emax << "_dE" << dE;
171 OutDir = baseDir+buff.str();
172 filesystem::create_directories(OutDir);
173 }
174 #pragma omp parallel for
175 for(size_t n = Nmin;n <= Nmax; ++n) {
176 std::stringstream buff(""); buff << "/MeasureOfETH_N" << n << ".txt";
177 std::string OutFname(OutDir + buff.str());
178 std::ofstream OutFs(OutFname); checkIsFileOpen(OutFs, OutFname);
179 OutFs << "# 1.(Sample No.) 2.(Fluc) 3.(MaxFluc) 4.(MaxPos) 5.(Ndata)\n\n";
180 OutFs << std::scientific << std::showpos << std::setprecision(6);
181 for(size_t sample = 0;sample < dirList.size(); ++sample) {
182 if(Data.at(n).at(sample).Ndata == -1) continue;
183 OutFs << sample << " "
184 << Data[n][sample].Fluc << " "
185 << Data[n][sample].MaxFluc << " "
186 << Data[n][sample].MaxPos << " "
187 << Data[n][sample].Ndata
188 << std::endl;
189 }
190 }
191
192 return EXIT_SUCCESS;
193}
namespace filesystem
Definition MeasureOfETH.cpp:15
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
constexpr double Emin
Definition setVariablesForMCAverage.cpp:4
constexpr double Emax
Definition setVariablesForMCAverage.cpp:5
double const dE
Definition setVariablesForMCAverage.cpp:2
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
std::stringstream buff("")

Variable Documentation

◆ filesystem

namespace filesystem = std::experimental::filesystem