StatMech
Loading...
Searching...
No Matches
TSS.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 
)
81 {
82 if(argc != N_ARGS) {
83 std::cerr << USAGE << std::endl;
84 std::exit(EX_USAGE);
85 }
86 if( !Initialize(argc, argv) ) {
87 std::cerr << "Error: Initialization failed." << std::endl;
88 std::exit(EX_USAGE);
89 }
90
91 Integer_t const MAX = 100000; // 1つのファイルに書き込むデータ数の上限
92 Integer_t const dim_loc = 2; // サイト上のヒルベルト空間の次元
93 Integer_t const div = (Integer_t)std::atoll(argv[3]);
94 Integer_t const n_max = (Integer_t)std::atoll(argv[1]); // 全スピンの数
95 Integer_t const n_min = (Integer_t)std::atoll(argv[2]);
96 Integer_t const num_h = 2;
97 Integer_t const num_op = 2;
98 Integer_t const dloc_h = 4; // 局所ハミルトニアンの空間の次元
99 Integer_t const dloc_op = dloc_h; // 局所演算子の空間の次元
100 Integer_t const seed = 0;
101 Integer_t const repMin = MAX*div;
102 Integer_t const repMax = repMin +MAX-1;
103
104 Integer_t dim_sub; //全ヒルベルト空間の次元
105
106 Integer_t ndata, info, failed=0; // カウンタ
107 double gE, EnergyRange, OpRange, OpMin;
108 double Fluc, MaxFluc, MaxPos; // ETHの指標
109 double const cutoff = 0.45;
110 double const dE = 0.02; // ミクロカノニカル平均を計算するエネルギーシェルの幅
111 double const Emin = 0 +cutoff;
112 double const Emax = 1 -cutoff;
113
114 std::stringstream buff;
115
116 double start, t_int, end, temp_t;
117 double T_diag=0, T_post=0, T_pre=0;
118 //******************** Check for the directory structure ********************
119 std::string d_str1(argv[4]); d_str1 += "/Probability/"; d_str1 += QUOTE(ENSEMBLE);
120 std::string d_str2(d_str1);
121 buff.str("");
122 buff.clear(std::stringstream::goodbit);
123 buff << "/randHOp_" << "Local" << num_h << "_Cut" << (Integer_t)(100*cutoff) << "_Seed" << seed << "_Min" << n_min << "_Max" << n_max;
124 d_str1 += buff.str();
125 filesystem::create_directories(d_str1);
126
127 if(div == 0) {
128 buff.str("");
129 buff.clear(std::stringstream::goodbit);
130 buff << "/Structure_" << "Local" << num_h << "_Seed" << seed << "_Min" << n_min << "_Max" << n_max;
131 d_str2 += buff.str();
132 filesystem::create_directories(d_str2);
133 }
134
135 std::ofstream OutMeasure[n_max+1];
136 for(Integer_t n = n_min;n <= n_max; ++n) {
137 buff.str("");
138 buff.clear(std::stringstream::goodbit);
139 buff << "/MeasureOfETH_N" << n << "_" << div << ".txt";
140 std::string filename(d_str1); filename += buff.str();
141 OutMeasure[n].open(filename);
142 if( OutMeasure[n].fail() ) {
143 std::cerr << "Can't open a file" << filename << "." << std::endl;
144 std::exit(EX_CANTCREAT);
145 }
146 OutMeasure[n] << std::right << std::scientific;
147 }
148
149 std::ofstream OutSample;
150 //******************** (END) Check for the directory structure ********************
151
152 //******************** Allocation & Initialization ********************
153 Integer_t const dim_max = n_max+1;
154 std::vector<Integer_t> NdataInShell(dim_max);
155 std::vector<double> MCAverage(dim_max);
156 std::vector<double> eigenEnergy(dim_max);
157 std::vector<double> EXPvalue(dim_max);
158 matrix<MKL_Complex16> h(dloc_h , dloc_h );
159 matrix<MKL_Complex16> loc(dloc_op, dloc_op);
160 matrix<MKL_Complex16> h_tot(dim_max, dim_max);
161 matrix<MKL_Complex16> loc_tot(dim_max, dim_max);
162 std::cout << "dloc_h=" << dloc_h << ", dloc_op=" << dloc_op << "\n";
163
164 init_genrand(seed);
165 start = getETtime();
166 for(Integer_t repetition = 0;repetition < repMin; ++repetition) {
167 generateLocal_h(h, dloc_h, -1);
168 generateLocal_op(loc, dloc_op, -1);
169 }
170 end = getETtime();
171 std::cout << "(init_genrand): time=" << std::fixed << (double)(end-start)/CLOCKS_PER_SEC << std::endl;
172 std::cerr << std::fixed << std::setprecision(6);
173 //******************** (END) Allocation & Initialization ********************
174
175 start = getETtime();
176 end = start;
177 std::string OutSampleFname;
178 for(Integer_t repetition = repMin;repetition <= repMax; ++repetition) {
179 // 局所ハミルトニアンと局所物理量をランダムにとる ******************************//
180 generateLocal_h(h, dloc_h, -1);
181 generateLocal_op(loc, dloc_op, -1);
182
183 if(repetition < 10000) {
184 //****************************** 局所演算子に関する性質を保存するファイルを用意 ******************************//
185 buff.str("");
186 buff.clear(std::stringstream::goodbit);
187 buff << "/Sample_No" << repetition << ".txt";
188 OutSampleFname = d_str2; OutSampleFname += "/RawData";
189 filesystem::create_directory(OutSampleFname);
190 OutSampleFname += buff.str();
191 OutSample.open(OutSampleFname);
192 if( OutSample.fail() ) {
193 std::cerr << "Can't open a file" << OutSampleFname;
194 std::exit(EX_CANTCREAT);
195 }
196 OutSample << "# dim_loc=" << dim_loc << ", num_h=" << num_h << ", num_op=" << num_op << "\n"
197 << "# 1.(System size) 2.(Energy density) 3.(Relative Pos) 4.(Exp. value)\n" << std::endl
198 << std::scientific;
199 //****************************** (END) 局所演算子に関する性質を保存するファイルを用意 ******************************//
200 }
201
202 double s;
203 for(Integer_t n = n_max;n >= n_min; --n) {
204 dim_sub = n+1;
205 s = n/2.0;
206 temp_t = getETtime();
207 constructGlobal_h( h_tot, n, s, dim_loc, h);
208 constructGlobal_op(loc_tot, n, s, dim_loc, loc);
209 T_pre += getETtime() -temp_t;
210
211 temp_t = getETtime();
212 info = EigenExpValue(EXPvalue, eigenEnergy, dim_sub, h_tot, loc_tot);
213 if(info != 0) {
214 failed += 1;
215 buff.str("");
216 buff.clear(std::stringstream::goodbit);
217 buff << "/Failed_N" << n << "_No" << repetition << ".txt";
218 std::string filename(d_str1); filename += buff.str();
219 std::ofstream ErrFp;
220 ErrFp.open(filename);
221 if( !ErrFp.is_open() ) {
222 std::cerr << "# Warning: Can't open a file " << filename << ". Continue..." << std::endl;
223 } else {
224 ErrFp << "# info=" << info << "\n\n"
225 "# seed=" << seed << ", div=" << div << ", N=" << n << ", repetition=" << repetition << "\n"
226 "# Local Hamiltonian\n";
227 h.print(ErrFp, dloc_h, dloc_h); ErrFp << "\n";
228 ErrFp << "# Local operator\n";
229 loc.print(ErrFp, dloc_op, dloc_op); ErrFp << "\n";
230 ErrFp.close();
231 }
232 continue;
233 }
234 if(dim_sub==n+1) OpRange = SpectralRange(OpMin, dim_sub, loc_tot);
235 T_diag += getETtime() -temp_t;
236
237 temp_t = getETtime();
238 {
239 for(Integer_t i = 0;i < dim_sub; ++i) EXPvalue[i] /= OpRange;
240 gE = eigenEnergy[0];
241 EnergyRange = eigenEnergy[dim_sub-1] -gE;
242 for(Integer_t i = 0;i < dim_sub; ++i) eigenEnergy[i] = (eigenEnergy[i] -gE)/EnergyRange;
243 EnergyRange /= (double)n;
244 gE /= (double)n;
245
246 // Calculate Microcanonical averages with energy corresponding to each eigenstate.
247 MCAverage.resize(dim); NdataInShell.resize(dim);
248 std::fill( MCAverage.begin(), MCAverage.end(), 0.0);
249 std::fill(NdataInShell.begin(), NdataInShell.end(), 0.0);
250 for(Integer_t i = 0;i < dim; ++i) {
251 MCAverage[i] = MicroCanonicalAverage(NdataInShell[i], eigenEnergy[i], dE, dim_sub, eigenEnergy, EXPvalue, i);
252 }
253
254 ndata = MeasureOfETH(Fluc, MaxFluc, MaxPos, Emin, Emax, dim_sub, eigenEnergy, EXPvalue, MCAverage);
255 }
256 T_post += getETtime() -temp_t;
257
258 OutMeasure[n] << std::setw(6) << repetition << " " << std::showpos
259 << std::setw(13) << Fluc << " "
260 << std::setw(13) << MaxFluc << " "
261 << std::setw(13) << MaxPos << " " << std::noshowpos << ndata << "\n";
262
263 if(repetition < 10000) {
264 for(Integer_t i = 0;i < dim_sub; ++i) {
265 assert(eigenEnergy[i] <= 1);
266 OutSample << std::setw(2) << n << " " << std::showpos
267 << std::setw(13) << eigenEnergy[i]*(double)EnergyRange +(double)gE << " "
268 << std::setw(13) << eigenEnergy[i] << " "
269 << std::setw(13) << EXPvalue[i] << " " << MCAverage[i] << " " << std::noshowpos
270 << std::scientific << std::setprecision(6) << "\n";
271 }
272 OutSample << std::endl;
273 }
274 }
275 if(repetition < 10000) {
276 OutSample.close();
277 buff.str("");
278 buff.clear(std::stringstream::goodbit);
279 buff << "cd " << d_str2 << " && xz " << OutSampleFname << " && rm -f " << OutSampleFname << " 2>>error.log &";
280 std::system(buff.str().c_str());
281 }
282 if(repetition%10 == 9) {
283 t_int = end; end = getETtime();
284 std::cerr << "(total=" << repetition+1
285 << "): timeINT=" << std::setprecision(6) << (end-t_int)
286 << ", timeTOT=" << std::setprecision(6) << (end-start)
287 << ", T_construct=" << std::setprecision(6) << T_pre << "(" << std::setprecision(1) << 100*T_pre /(end-start) << "%)"
288 << ", T_diag=" << std::setprecision(6) << T_diag << "(" << std::setprecision(1) << 100*T_diag/(end-start) << "%)"
289 << ", T_process=" << std::setprecision(6) << T_post << "(" << std::setprecision(1) << 100*T_post/(end-start) << "%)"
290 << std::endl;
291 for(Integer_t n = n_min;n <= n_max; ++n) OutMeasure[n].flush();
292 }
293 }
294
295 Finalize(argc, argv);
296 return 0;
297}
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("")

Variable Documentation

◆ filesystem

namespace filesystem = std::experimental::filesystem