-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
371 lines (308 loc) · 8.98 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstdlib>
#include<time.h>
#include<omp.h>
#include "hamiltonian.hpp"
#include "config.hpp"
#include "kubostreda.hpp"
using namespace std;
string get_symbol(void);
string get_paramname(void);
string get_time(void);
string out_time(time_t t);
int main()
{
clock_t start = clock();
#if H_TYPE/10 < 5
MultiLayer_TBSQ hamiltonian;
#elif H_TYPE/10 < 9
return -1;
#elif H_TYPE/10 == 9
ElectronGas hamiltonian;
#else
return -1;
#endif
#if OUTPUT == 0
DC_Conductivity calc;
#elif OUTPUT == 1
Hall_Conductivity calc;
#elif OUTPUT == 2
SpinHall_Conductivity calc;
#elif OUTPUT == 3
Density_Of_States calc;
#elif OUTPUT == 4
Magnetization calc;
#elif OUTPUT == 5
TotalEnergy calc;
#elif OUTPUT == 6
MR_Amplitude calc;
#elif OUTPUT == 7
SpinOrbitTorque calc;
#elif OUTPUT == 8
SpinAccumulation calc;
#elif OUTPUT == 9
Anisotropic_Energy calc;
#else
return -1;
#endif
ofstream fout;
string symb,iname;
symb = get_symbol();
iname = get_paramname();
#if TEST_MODE == 0
stringstream fname,command,outfile,logfile;
string home(getenv("HOME"));
fname << PREFIX << hamiltonian.H_Name() << "_" << calc.Name() << "vs" << symb << SUFFIX << ".csv";
command << "mkdir " << home << "/DATA/" << DIR_NAME;
system(command.str().c_str());
command.str("");
command << "mkdir " << home << "/DATA/CALC_LOG/" << DIR_NAME;
system(command.str().c_str());
command.str("");
logfile << home << "/DATA/CALC_LOG/" << DIR_NAME << "/" << get_time() << fname.str();
outfile << home << "/DATA/" << DIR_NAME << "/" << fname.str();
fout.open(logfile.str().c_str());
if (!fout) {
cout << "Cannot open \"" << logfile.str().c_str() << "\"." <<endl;
return -1;
}
else cout << "Open file:\"" << logfile.str().c_str() << "\"." << endl;
fout << "# Kubo-Streda formulation ver." << VERSION << " (Modified " << DATE << " Done " << get_time() << ")" << endl;
fout << endl;
hamiltonian.OutputHamiltonian(fout);
fout << "# " << iname << calc.Outputs() << endl;
#elif TEST_MODE ==1
#warning "Test Mode"
fout.open("result.csv");
if (!fout) {
cout << "Cannot open \"result.csv\"." <<endl;
return -1;
}
cout << "# Kubo-Streda formulation (ver." << VERSION << ", modified " << DATE << ")" << endl;
#endif
cout << "Calculation start." << endl;
cout << "# " << iname << calc.Outputs() << endl;
double min=INPUT_MIN, max=INPUT_MAX;
double dx=(max-min)/(double)INPUT_DIV;
for(int i=0; i<=INPUT_DIV; i++){
double x = min + (double)i*dx;
hamiltonian.setParam(x);
//~ hamiltonian.printParam();
calc.Run(hamiltonian);
cout << x << ", ";
cout << calc.Results();
cout << endl;
fout << x << ", ";
fout << calc.Results();
fout << endl;
}
fout.close();
#if TEST_MODE == 0
command << "cp " << logfile.str() << " " << outfile.str();
system(command.str().c_str());
#endif
cout << endl << "Complete!" << endl;
clock_t end = clock();
cout << "Duration = " << out_time(end - start) << endl;
return 0;
}
#if TEST_MODE == 2
int main(void){
clock_t start = clock();
cout << "test mode : " << TEST_MODE << endl;
Hamiltonian h;
Hall_Conductivity calc;
BerryPhase prob;
ofstream fout;
fout.open("testlog.csv");
if (!fout) {
cout << "Cannot open file." <<endl;
return -1;
}
fout << "# Accuracy test." << endl;
double min=INPUT_MIN, max=INPUT_MAX;
double dx=(max-min)/(double)INPUT_DIV;
for(int i=0; i<=INPUT_DIV; i++){
double x = min + (double)i*dx;
h.setParam(x);
calc.Run(h);
prob.Run(h);
prob.Error(calc.Value());
cout << "AHC(" << x << "):" << calc.Value() << ", " << prob.Results() << endl;
fout << x << ", "<< calc.Value() << ", " << prob.Results() << endl;
}
cout <<"Complete." << endl;
fout.close();
clock_t end = clock();
cout << "Duration = " << out_time(end - start) << endl;
return 0;
}
#elif TEST_MODE == 3
int main(void){
clock_t start = clock();
int sum=0;
cout << "test mode : " << TEST_MODE << endl;
#ifdef _OPENMP
omp_set_num_threads(PARALLEL_NUM);
ofstream fout;
fout.open("omptest.csv");
if (!fout) {
cout << "Cannot open file." <<endl;
return -1;
}
fout << "# PARALLEL_NUM = " << PARALLEL_NUM << endl;
fout << "# process, thread_num" << endl;
#pragma omp parallel for schedule(static) reduction (+:sum)
for(int i=0; i<=200; i++){
//~ cout << i << ", "<< omp_get_thread_num() << endl;
#pragma omp critical
fout << i << ", "<< omp_get_thread_num() << endl;
sum += i;
}
cout << sum << endl;
cout <<"Complete." << endl;
#else
# warning "Unlink OPEN_MP"
#endif
clock_t end = clock();
cout << "Duration = " << out_time(end - start) << endl;
return 0;
}
#elif TEST_MODE == 4
int main(void){
clock_t start = clock();
cout << "test mode : " << TEST_MODE << endl;
Hamiltonian h;
Complex_SquareMatrix Hmat;
MR_Amplitude calc;
double min=INPUT_MIN, max=INPUT_MAX;
double dx=(max-min)/(double)INPUT_DIV;
//~ for(int i=0; i<=INPUT_DIV; i++){
//~ double x = min + (double)i*dx;
//~ h.setParam(x);
//~ calc.Run(h);
h.OutputHamiltonian();
h.getTransferTorque(Hmat,M_PI_2,0,'z');
Hmat.PrintMatrix();
//~ cout << x << ", " << calc.Value(5) << endl;
//~ }
cout <<"Complete." << endl;
clock_t end = clock();
cout << "Duration = " << out_time(end - start) << endl;
return 0;
}
#endif
string get_symbol(void){
switch (INPUT) {
case 00:
return "EXC";
case 01:
return "RSO";
case 02:
return "Tip";
case 03:
return "Top";
case 04:
if ( ROTATION_AXIS == 'z')
return "PAz";
else if ( ROTATION_AXIS == 'x')
return "PAx";
else return "PAy";
case 05:
if ( ROTATION_AXIS == 'z')
return "AAz";
else if ( ROTATION_AXIS == 'x')
return "AAx";
else return "AAy";
case 06:
return "sWID";
case 10:
return "HEX";
case 11:
return "ASO";
case 12:
return "Eimp";
case 13:
return "CFOh";
case 14:
return "dWID";
case 15:
return "CFTr";
case 20:
return "Nimp";
case 21:
return "Vsd";
case 90:
return "FEN";
case 91:
return "FIL";
case 92:
return "LYR";
}
}
string get_paramname(void){
switch (INPUT) {
case 00:
return "sd_Exchange";
case 01:
return "Rashba_SOI";
case 02:
return "Hopping_ip";
case 03:
return "Hopping_op";
case 04:
return "M_theta";
case 05:
return "M_phi";
case 06:
return "s_Lorentzian_width";
case 10:
return "Hund_coupling";
case 11:
return "Atomic_SOI";
case 12:
return "Impurity_level";
case 13:
return "Crystal_field(Oh)";
case 14:
return "d_Lorentzian_width";
case 15:
return "Tetragonal_crystal_field";
case 20:
return "Impurity_density";
case 21:
return "Hybridization";
case 90:
return "Fermi_level";
case 91:
return "Filling";
case 92:
return "Layer";
}
}
string get_time(void)
{
stringstream sstr;
time_t current;
struct tm *local;
time(¤t); // get current time
local = localtime(¤t); // transform to localtime
sstr << setw(2) << setfill('0') << local->tm_year-100;
sstr << setw(2) << setfill('0') << local->tm_mon+1;
sstr << setw(2) << setfill('0') << local->tm_mday << "_";
sstr << setw(2) << setfill('0') << local->tm_hour;
sstr << setw(2) << setfill('0') << local->tm_min;
return sstr.str();
}
string out_time(time_t t){
double sec = (double)t / CLOCKS_PER_SEC;
double min = sec/60;
double hour = min / 60;
stringstream sstr;
sstr << (int)hour << ":" ;
sstr << setw(2) << setfill('0') << (int)min % 60 << ":" ;
sstr << setw(2) << setfill('0') << (int)sec % 60;
return sstr.str();
}