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

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
29 {
30 if(argc != N_ARGS) {
31 std::cerr << USAGE << std::endl;
32 std::exit(EX_USAGE);
33 }
34 Integer_t const MAX = 100000; // 1つのファイルに書き込むデータ数の上限
35 Integer_t const dim_loc = 2; // サイト上のヒルベルト空間の次元
36 Integer_t const div = (Integer_t)std::atoll(argv[5]);
37 Integer_t const num_h = (Integer_t)std::atoll(argv[3]); // 局所ハミルトニアンに含まれるサイト数
38 Integer_t const num_op = (Integer_t)std::atoll(argv[4]); // 局所演算子に含まれるサイト数
39 Integer_t const n_max = (Integer_t)std::atoll(argv[1]); // 全スピンの数
40 Integer_t const n_min = (Integer_t)std::atoll(argv[2]);
41 Integer_t const dloc_h = pow(dim_loc, num_h); // 局所ハミルトニアンの空間の次元
42 Integer_t const dloc_op = pow(dim_loc, num_op); // 局所演算子の空間の次元
43 Integer_t const seed = 0;
44 Integer_t const repMin = MAX*div;
45 Integer_t const repMax = repMin +MAX-1;
46
47 Integer_t dim_sub; //全ヒルベルト空間の次元
48
49 Integer_t ndata, info, failed=0; // カウンタ
50 double gE, EnergyRange, OpRange, OpMin;
51 double Fluc, MaxFluc, MaxPos; // ETHの指標
52 double const cutoff = 0.45;
53 double const dE = 0.02; // ミクロカノニカル平均を計算するエネルギーシェルの幅
54 double const Emin = 0 +cutoff;
55 double const Emax = 1 -cutoff;
56
57 std::stringstream buff;
58
59 std::cout << "dloc_h=" << dloc_h << ", dloc_op=" << dloc_op << "\n";
60 if(n_min > n_max) {
61 std::cerr << "Error: n_min(" << n_min << ") > n_max(" << n_max << ")." << std::endl;
62 std::exit(EX_USAGE);
63 }
64 if( !Initialize(argc, argv) ) {
65 std::cerr << "Error: Initialization failed." << std::endl;
66 std::exit(EX_USAGE);
67 }
68 #ifndef NDEBUG
69 std::cerr << "# Successfully initialized." << std::endl;
70 #endif
71
72 //******************** Check for the directory structure ********************
73 #ifndef NDEBUG
74 std::cerr << "# Checking for the directory structure." << std::endl;
75 #endif
76 std::string d_str1(argv[6]); d_str1 += "/Probability/"; d_str1 += QUOTE(ENSEMBLE);
77 std::string d_str2(d_str1);
78 buff.str("");
79 buff.clear(std::stringstream::goodbit);
80 buff << "/" << TYPE << "randHOp_" << "Local" << num_h << "_Cut" << (Integer_t)(100*cutoff) << "_Seed" << seed << "_Min" << n_min << "_Max" << n_max;
81 d_str1 += buff.str();
82 std::filesystem::create_directories(d_str1);
83
84 if(div == 0) {
85 buff.str("");
86 buff.clear(std::stringstream::goodbit);
87 buff << "/" << TYPE << "Structure_" << "Local" << num_h << "_Seed" << seed << "_Min" << n_min << "_Max" << n_max;
88 d_str2 += buff.str();
89 std::filesystem::create_directories(d_str2);
90 }
91
92 std::ofstream OutMeasure[n_max+1];
93 for(Integer_t n = n_min;n <= n_max; ++n) {
94 buff.str("");
95 buff.clear(std::stringstream::goodbit);
96 buff << "/MeasureOfETH_N" << n << "_" << div << ".txt";
97 std::string filename(d_str1); filename += buff.str();
98 OutMeasure[n].open(filename);
99 if( OutMeasure[n].fail() ) {
100 std::cerr << "Can't open a file" << filename << "." << std::endl;
101 std::exit(EX_CANTCREAT);
102 }
103 OutMeasure[n] << std::right;
104 }
105
106 std::ofstream OutSample;
107 //******************** (END) Check for the directory structure ********************
108
109 for(Integer_t n = n_max;n >= n_min; --n) {
110 dim_sub = pow(dim_loc, n);
111 std::cout << "(n=" << n << ") dim = " << dim_sub << "\n";
112
113 OutMeasure[n] << "# (n_max=" << n_max << ") dim=" << dim_sub << "\n"
114 << "# 1.(Sample No.) 2.(Fluc_2) 3.(Fluc_infty) 4.(Pos_max_flux) 5.(ndata)\n"
115 << std::endl << std::scientific;
116 }
117
118 //***************************************************************************
119 //******************** Allocation & Initialization **************************
120 //***************************************************************************
121 #ifndef NDEBUG
122 std::cerr << "# Allocating CPU memories." << std::endl;
123 #endif
124 Integer_t const dim_max = pow(dim_loc, n_max);
125 std::vector<Integer_t> NdataInShell(dim_max);
126 std::vector<double> eigenEnergy(dim_max);
127 std::vector<double> EXPvalue(dim_max);
128 std::vector<double> MCAverage(dim_max);
129 matrix<MKL_Complex16> h(dloc_h , dloc_h );
130 matrix<MKL_Complex16> loc(dloc_op, dloc_op);
131 matrix<MKL_Complex16> h_tot(dim_max, dim_max);
132 matrix<MKL_Complex16> loc_tot(dim_max, dim_max);
133
134 double start, t_int, end, temp_t;
135 double T_diag=0, T_post=0, T_pre=0;
136 init_genrand(seed);
137 start = getETtime();
138 for(Integer_t repetition = 0;repetition < repMin; ++repetition) {
139 generateLocal_h( h, dloc_h, -1);
140 generateLocal_op(loc, dloc_op, -1);
141 }
142 end = getETtime();
143 std::cout << "(init_genrand): time=" << std::fixed << (end-start) << std::endl;
144 //***************************************************************************
145 //******************** (END) Allocation & Initialization ********************
146 //***************************************************************************
147
148 start = getETtime();
149 end = start;
150 for(Integer_t repetition = repMin;repetition <= repMax; ++repetition) {
151 // 局所ハミルトニアンと局所物理量をランダムにとる ******************************//
152 generateLocal_h( h, dloc_h, -1);
153 generateLocal_op(loc, dloc_op, -1);
154
155 if(repetition < 10000) {
156 //****************************** 局所演算子に関する性質を保存するファイルを用意 ******************************//
157 buff.str("");
158 buff.clear(std::stringstream::goodbit);
159 buff << "/Sample_No" << repetition << ".txt";
160 std::string filename(d_str2); filename += "/RawData";
161 std::filesystem::create_directory(filename);
162 filename += buff.str();
163 OutSample.open(filename);
164 if( OutSample.fail() ) {
165 std::cerr << "Can't open a file" << filename;
166 std::exit(EX_CANTCREAT);
167 }
168 OutSample << "# dim_loc=" << dim_loc << ", num_h=" << num_h << ", num_op=" << num_op << "\n"
169 // << "# wave_number=" << wave_number << "\n"
170 << "# 1.(System size) 2.(Energy density) 3.(Relative Pos) 4.(Exp. value)\n" << std::endl
171 << std::scientific;
172 //****************************** (END) 局所演算子に関する性質を保存するファイルを用意 ******************************//
173 }
174 for(Integer_t n = n_max;n >= n_min; --n) {
175 dim_sub = pow(dim_loc, n);
176
177 #ifndef NDEBUG
178 std::cout << "# (rep,n)=(" << repetition << "," << n << ")" << std::endl;
179 #endif
180 temp_t = getETtime();
181 #pragma omp parallel
182 {
183 std::cout << "parallel(rep,n)=(" << repetition << "," << n << ")" << std::endl;
184 #pragma omp sections
185 {
186 #pragma omp section
187 {
188 #pragma omp critical
189 std::cout << "section1(rep,n)=(" << repetition << "," << n << ")" << std::endl;
190 constructGlobal_h( h_tot, n, dim_loc, num_h, h);
191 }
192 #pragma omp section
193 {
194 #pragma omp critical
195 std::cout << "section2(rep,n)=(" << repetition << "," << n << ")" << std::endl;
196 constructGlobal_op(loc_tot, n, dim_loc, num_op, loc);
197 }
198 }
199 }
200 T_pre += getETtime() -temp_t;
201
202 #ifndef NDEBUG
203 std::cerr << "# Calculating eigenstate expectation values." << std::endl;
204 #endif
205 temp_t = getETtime();
206 info = EigenExpValue(EXPvalue, eigenEnergy, dim_sub, h_tot, loc_tot);
207 if(info != 0) {
208 failed += 1;
209 buff.str("");
210 buff.clear(std::stringstream::goodbit);
211 buff << "/Failed_N" << n << "_No" << repetition << ".txt";
212 std::string filename(d_str1); filename += buff.str();
213 std::ofstream ErrFp;
214 ErrFp.open(filename);
215 if( !ErrFp.is_open() ) {
216 std::cerr << "# Warning: Can't open a file " << filename << ". Continue..." << std::endl;
217 } else {
218 ErrFp << "# info=" << info << "\n\n"
219 "# seed=" << seed << ", div=" << div << ", N=" << n << ", repetition=" << repetition << "\n"
220 "# Local Hamiltonian\n";
221 h.print(ErrFp, dloc_h, dloc_h); ErrFp << "\n";
222 ErrFp << "# Local operator\n";
223 loc.print(ErrFp, dloc_op, dloc_op); ErrFp << "\n";
224 ErrFp.close();
225 }
226 continue;
227 }
228 OpRange = SpectralRange(OpMin, dim_sub, loc_tot);
229 T_diag += getETtime() -temp_t;
230
231 #ifndef NDEBUG
232 std::cerr << "# Calculating measures of the ETH." << std::endl;
233 #endif
234 temp_t = getETtime();
235 for(Integer_t i = 0;i < dim_sub; ++i) EXPvalue[i] /= OpRange;
236 EnergyRange = eigenEnergy[dim_sub-1] -eigenEnergy[0];
237 gE = eigenEnergy[0];
238 for(Integer_t i = 0;i < dim_sub; ++i) eigenEnergy[i] = (eigenEnergy[i] -gE)/EnergyRange;
239 // Calculate Microcanonical averages with energy corresponding to each eigenstate.
240 MCAverage.resize(dim); NdataInShell.resize(dim);
241 std::fill( MCAverage.begin(), MCAverage.end(), 0.0);
242 std::fill(NdataInShell.begin(), NdataInShell.end(), 0.0);
243 for(Integer_t i = 0;i < dim; ++i) {
244 MCAverage[i] = MicroCanonicalAverage(NdataInShell[i], eigenEnergy[i], dE, dim_sub, eigenEnergy, EXPvalue, i);
245 }
246
247 ndata = MeasureOfETH(Fluc, MaxFluc, MaxPos, Emin, Emax, dim_sub, eigenEnergy, EXPvalue, MCAverage);
248 T_post += getETtime() -temp_t;
249
250 OutMeasure[n] << std::setw(6) << repetition << " " << std::showpos
251 << std::setw(13) << Fluc << " "
252 << std::setw(13) << MaxFluc << " "
253 << std::setw(13) << MaxPos << " " << std::noshowpos << ndata << "\n";
254
255 if(repetition < 10000) {
256 for(Integer_t i = 0;i < dim_sub; ++i) {
257 OutSample << std::setw(2) << n << " " << std::showpos
258 << std::setw(13) << eigenEnergy[i]*(double)EnergyRange +(double)gE << " "
259 << std::setw(13) << eigenEnergy[i] << " "
260 << std::setw(13) << EXPvalue[i] << "\n" << std::noshowpos;
261 }
262 }
263 }
264 if(repetition < 10000) OutSample.close();
265 if(repetition%10 == 9) {
266 t_int = end; end = getETtime();
267 std::cerr << "(total=" << repetition+1
268 << "): timeINT=" << std::setprecision(6) << (end-t_int)
269 << ", timeTOT=" << std::setprecision(6) << (end-start)
270 << ", T_construct=" << std::setprecision(6) << T_pre << "(" << std::setprecision(1) << 100*T_pre /(end-start) << "%)"
271 << ", T_diag=" << std::setprecision(6) << T_diag << "(" << std::setprecision(1) << 100*T_diag/(end-start) << "%)"
272 << ", T_process=" << std::setprecision(6) << T_post << "(" << std::setprecision(1) << 100*T_post/(end-start) << "%)"
273 << std::endl;
274 for(Integer_t n = n_min;n <= n_max; ++n) OutMeasure[n].flush();
275 }
276 }
277
278 Finalize(argc, argv);
279 return 0;
280}
double getETtime()
Definition EnergySpectrum.c:14
std::ofstream OutMeasure[n_max+1]
Definition MeasureOfETH_CreateOutputFiles.cpp:1
int const N_ARGS
Definition generateRM.hpp:16
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 Integer_t dim_loc
Definition setVariablesForEnsemble.cpp:36
Integer_t const num_op
Definition setVariablesForEnsemble.cpp:39
Integer_t const num_h
Definition setVariablesForEnsemble.cpp:38
Integer_t const repMin
Definition setVariablesForEnsemble.cpp:31
Integer_t const n_min
Definition setVariablesForEnsemble.cpp:28
Integer_t const repMax
Definition setVariablesForEnsemble.cpp:32
Integer_t const div
Definition setVariablesForEnsemble.cpp:29
Integer_t const dloc_op
Definition setVariablesForEnsemble.cpp:41
Integer_t const dloc_h
Definition setVariablesForEnsemble.cpp:40
Integer_t const n_max
Definition setVariablesForEnsemble.cpp:27
constexpr double Emin
Definition setVariablesForMCAverage.cpp:4
constexpr double cutoff
Definition setVariablesForMCAverage.cpp:3
constexpr double Emax
Definition setVariablesForMCAverage.cpp:5
double const dE
Definition setVariablesForMCAverage.cpp:2
Integer_t EigenExpValue(std::vector< double > &EXPvalue, std::vector< double > &Eigenvalue, Integer_t const dim, matrix< Complex_t< double > > &Hamiltonian, const matrix< Complex_t< double > > &Operator, void *GPUconf)
Definition statmech.cpp:120
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
double SpectralRange(double &OpMin, Integer_t const dim, matrix< Complex_t< double > > &Operator)
Definition statmech.cpp:49
std::stringstream buff("")