StatMech
Loading...
Searching...
No Matches
ParticipationRatio.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 
)
26 {
27 if(argc < 6) {
28 std::cerr << "Usage: 1.This 2.Directory 3.Nmax 4.Nmin 5.dE 6.Type (Op1).SampleMin (Op2).SampleMax" << std::endl;
29 std::cerr << " : Type should be either (a)vsOp, (b)MF, or (c)btw2samples." << std::endl;
30 std::exit(EX_USAGE);
31 }
32 constexpr int MaxDeg = 8;
33 int const Nmax = (argc>=3 ? std::stoi(argv[2]) :16);
34 int const Nmin = (argc>=4 ? std::stoi(argv[3]) :16);
35 double const dE = (argc>=5 ? std::stod(argv[4]) :0.05);
36 double const Emin = 0.5-dE;
37 double const Emax = 0.5+dE;
38 int const SampleMin = (argc>=7 ? std::stod(argv[6]) :-1);
39 int const SampleMax = (argc>=8 ? std::stod(argv[7]) :-1);
40 std::string const Type(argv[5]);
41
42 int const n_max = Nmax;
43 int const n_min = Nmin;
44 int const dim_loc = 2;
45 //******************** Translation invariance ********************
46 debug_print("# Calculating translation-invariant sectors.");
48 //******************** (END)Translation invariance ********************
49
50 std::string const baseDir(argv[1]);
51 std::cout << "# Directory: " << baseDir << "\n";
52 std::string const InDataDir(baseDir+"/ProcessedData");
53 std::vector<std::string> dirList;
54 {
55 std::string str;
56 int dataNo;
57 int const idShift=(SampleMin>0? SampleMin: 0);
58 if(SampleMin>0 && SampleMax>0) dirList.resize(SampleMax-idShift+1);
59 for(const filesystem::directory_entry &entry : filesystem::directory_iterator(InDataDir)) {
60 if ( entry.is_directory() ) {
61 str = entry.path().string();
62 dataNo = std::atoi(str.substr(str.find("_No")+3).c_str());
63 if((SampleMin>0 || SampleMax>0) && (dataNo<SampleMin || SampleMax<dataNo)) continue;
64 debug_print("# dir=" << str << ", dataNo=" << dataNo);
65 if( (SampleMin<=0 || SampleMax<=0) && dirList.size()<=dataNo) dirList.resize(dataNo+1);
66 debug_print("# dataNo-idShift=" << dataNo-idShift << ", dataNo=" << dataNo << ", idShift=" << idShift);
67 dirList.at(dataNo-idShift) = str;
68 }
69 }
70 }
71
72 std::vector<std::vector<std::vector<double>>> FractalDimension(Nmax+1, std::vector<std::vector<double>>(MaxDeg+1, std::vector<double>(dirList.size(), NAN)));
73 #pragma omp parallel for schedule(dynamic, 10)
74 for(size_t sample = 0;sample < dirList.size(); ++sample) {
75 double dtemp;
76 std::string InFname, str;
77 std::ifstream InFs;
78 std::vector<std::string> candidateFileNames;
79 bool flag = false;
80 #pragma omp critical
81 std::cout << "# " << dirList[sample] << std::endl;
82 for(int n = Nmax;n >= Nmin ; --n) {
83 std::stringstream buff(""); buff << "_N" << n << ".txt";
84 { //-------------------- Load EigenEnergies --------------------//
85 candidateFileNames.resize(3);
86 candidateFileNames[0] = dirList[sample] + "/MultiFractalZ_" + Type + buff.str();
87 candidateFileNames[1] = dirList[sample] + "/MultiFractalC_" + Type + buff.str();
88 candidateFileNames[2] = dirList[sample] + "/MultiFractal_" + Type + buff.str();
89 if( InFs.is_open() ) { InFs.close(); InFs.clear(); }
90 for(auto name : candidateFileNames) {
91 InFname = name;
92 InFs.open(InFname);
93 if( InFs.is_open() ) break;
94 }
95 if( !InFs.is_open() ) continue;
96 InFs.exceptions(std::ios::badbit);
97 flag = true;
98 std::stringstream ss;
99 double MinEigenEnergy=NAN, MaxEigenEnergy=NAN;
100 try{
101 skip_header(InFs);
102 for(getline(InFs, str); !InFs.eof(); getline(InFs, str)) {
103 ss.str(str); ss.clear(std::stringstream::goodbit);
104 ss >> dtemp;
105 MinEigenEnergy = std::fmin(dtemp, MinEigenEnergy);
106 MaxEigenEnergy = std::fmax(dtemp, MaxEigenEnergy);
107 }
108 } catch(std::exception& e) {
109 if( !InFs.eof() )
110 std::cerr << "Error(" << InFs.eof() << InFs.fail() << InFs.bad() << "):" << e.what() << std::endl;
111 }
112 double EnergyRange=MaxEigenEnergy-MinEigenEnergy;
113 // #pragma omp critical
114 // std::cout << "# " << dirList[sample] << ", EnergyRange=" << EnergyRange << std::endl;
115 InFs.clear(); InFs.seekg(0, std::ios::beg);
116 try {
117 skip_header(InFs);
118 for(getline(InFs, str); !InFs.eof(); getline(InFs, str)) {
119 ss.str(str); ss.clear(std::stringstream::goodbit);
120 ss >> dtemp; dtemp = (dtemp-MinEigenEnergy)/EnergyRange;
121 if(dtemp<Emin || Emax<dtemp) continue;
122 for(int deg=2;deg <= MaxDeg; ++deg) {
123 ss >> dtemp;
124 FractalDimension[n][deg][sample] = std::fmin(dtemp, FractalDimension[n][deg][sample]);
125 }
126 }
127 } catch(std::exception& e) {
128 if( !InFs.eof() )
129 std::cerr << "Error(" << InFs.eof() << InFs.fail() << InFs.bad() << "):" << e.what() << std::endl;
130 }
131 InFs.close(); InFs.clear();
132 }
133 }
134
135 if(!flag) continue;
136 {
137 std::string OutDIR(dirList[sample]);
138 std::filesystem::create_directories(OutDIR);
139 std::stringstream buff("");
140 buff << "/InverseParticipationRatio_" +Type+ "_dE" << std::setprecision(2) << dE << ".txt";
141 std::string OutFName(OutDIR + buff.str());
142 std::ofstream OutFs(OutFName); checkIsFileOpen(OutFs, OutFName);
143 OutFs << "# 1.(N) 2.(deg 2) 3.(deg 3) 4.(deg 4) 5.(deg 5) 6.(deg 6) 7.(deg 7) 8.(deg 8) 9.(deg 9)" << std::endl;
144 OutFs << std::scientific;
145 for(int n = Nmax;n >= Nmin ; --n) {
146 OutFs << n << " ";
147 for(int deg=2;deg <= MaxDeg; ++deg) {
148 FractalDimension[n][deg][sample] = std::exp( -std::log((double)SectorDimension(Sector[n]))*(deg-1)*(-1+FractalDimension[n][deg][sample]) );
149 OutFs << FractalDimension[n][deg][sample] << " ";
150 }
151 OutFs << std::endl;
152 }
153 }
154 }
155
156 std::string OutDIR(baseDir+"/Output");
157 std::filesystem::create_directories(OutDIR);
158 std::cout << "# OutDIR: " << OutDIR << "\n";
159
160 #pragma omp parallel for
161 for(int deg=2; deg<=MaxDeg; ++deg) {
162 std::stringstream buff("");
163 buff << "/AverageIPR_"+Type+"_dE" << std::setprecision(2) << dE << "_deg" << deg << ".txt";
164 std::string OutFName(OutDIR+buff.str());
165 std::ofstream OutFs(OutFName); checkIsFileOpen(OutFs, OutFName);
166 OutFs.exceptions(std::ios::badbit);
167 OutFs << "# 1.(N) 2.(Ensemble Average) 3.(Ensemble Stddev) 4.(ndata)\n" << std::endl;
168 OutFs << std::scientific;
169 for(int n = Nmax;n >=Nmin ; --n) {
170 double ave=0.0, var=0.0, dtemp;
171 int ndata = 0;
172 for(size_t sample = 0;sample < dirList.size(); ++sample) {
173 if( isnan(FractalDimension[n][deg][sample]) || isinf(FractalDimension[n][deg][sample]) ) continue;
174 ndata += 1;
175 ave += FractalDimension[n][deg][sample];
176 }
177 ave /= (double)ndata;
178 for(size_t sample = 0;sample < dirList.size(); ++sample) {
179 if( isnan(FractalDimension[n][deg][sample]) || isinf(FractalDimension[n][deg][sample]) ) continue;
180 dtemp = FractalDimension[n][deg][sample] - ave;
181 var += dtemp * dtemp;
182 }
183 var /= (double)ndata;
184 OutFs << n << " "
185 << ave << " "
186 << std::sqrt(var) << " "
187 << ndata
188 << std::endl;
189 }
190 }
191
192
193 return 0;
194}
namespace filesystem
Definition ParticipationRatio.cpp:14
std::vector< TransSector > Sector(n_max+1)
bool checkIsFileOpen(std::ifstream &file, std::string const &filename)
Definition file_util.hpp:22
debug_print("# Determining GPU configuration.")
constexpr Integer_t dim_loc
Definition setVariablesForEnsemble.cpp:36
Integer_t const n_min
Definition setVariablesForEnsemble.cpp:28
Integer_t const n_max
Definition setVariablesForEnsemble.cpp:27
constexpr double Emin
Definition setVariablesForMCAverage.cpp:4
constexpr double Emax
Definition setVariablesForMCAverage.cpp:5
double const dE
Definition setVariablesForMCAverage.cpp:2
std::stringstream buff("")

Variable Documentation

◆ filesystem

namespace filesystem = std::experimental::filesystem