-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathberry_HWR_main.cpp
executable file
·237 lines (209 loc) · 5.99 KB
/
berry_HWR_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
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <complex>
#define _USE_MATH_DEFINES
#include <math.h>
#include "variables.hpp"
#include "loadInput.hpp"
#include "loadInput_HWR.hpp"
#include "initialize.hpp"
#include "utils.hpp"
#include "interpretEquation.hpp"
#include "lapack.hpp"
using namespace std;
int main(int argc, const char** argv){
//initial message
cout << "#Berry curvature calculation from a .HWR file of OpenMX\n";
initialize();
//load input file
char fileName[fileName_length];
char HWRName[fileName_length];
if(argc<3){
printf("Usage: %s input HWR\n", argv[0]);
return -1;
}
//with parameters -> input file name is argv[1]
strcpy(fileName, argv[1]);
cout << "#Input file: " << fileName << endl;
FILE* input=fopen(fileName,"r");
if(input==NULL){
cout << "Error in opening the input file" << endl;
return -1;
}
//load input
int loadInput_status=loadInput(input,false);
if(loadInput_status==1){
cout << "#Finished loading input" << endl;
}else{
cout << "Failed in loading input" << endl;
return -1;
}
//close input file
fclose(input);
// HWR file
strcpy(HWRName, argv[2]);
cout << "#HWR file: " << HWRName << endl;
FILE* HWR=fopen(HWRName, "r");
if(HWR==NULL){
cout << "Error in opening the HWR file" << endl;
return -1;
}
loadInput_status=loadInput_HWR(HWR);
if(loadInput_status==1){
cout << "#Finished loading HWR" << endl;
}else{
cout << "Failed in loading HWR" << endl;
return -1;
}
//add kx, ky, kz, I to parameters
addKI();
//evaluation of basis vectors and delta_k
complex<double> evaluated_value;
int i,j,k,l,m,n;
int interpretEquation_status;
char evaluationOutput_format[format_length];
cout << "#Evaluation of k basis vectors" << endl;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
interpretEquation_status=interpretEquation(k_bases_string[i][j],allParams_name,allParams_value,&evaluated_value);
if(interpretEquation_status!=1){
printf("Error in evaluating k_bases[%d][%d]",i,j);
return -1;
}else{
k_bases[i][j]=evaluated_value.real();
sprintf(evaluationOutput_format,"#k_bases[%%d][%%d]=%s\n",realNumber_format);
printf(evaluationOutput_format,i,j,k_bases[i][j]);
}
}
}
cout << "#Evaluation of delta_k" << endl;
interpretEquation_status=interpretEquation(delta_k_string,allParams_name,allParams_value,&evaluated_value);
if(interpretEquation_status!=1){
cout << "Error in evaluating delta_k" << endl;
return -1;
}else{
delta_k=evaluated_value.real();
sprintf(evaluationOutput_format,"#delta_k=%s\n",realNumber_format);
printf(evaluationOutput_format,delta_k);
}
cout << "#Evaluation succeeded" << endl;
//make k coordinates list
double* k1List;
double* k2List;
double* k3List;
makeKList(&k1List,0);
makeKList(&k2List,1);
makeKList(&k3List,2);
//eigenvalue calculation
//initialization
zheevInit();
if(INFO!=0){
cout << "zheevInit error" << endl;
return -1;
}
double k1,k2,k3;
int Dimension=0;
for(i=0;i<3;i++){
if(k_split[i]>0){
Dimension++;
}
}
//eigenvector of k+Delta k, k, k-Delta k
complex<double>** psi_plus=alloc_zmatrix(N,N);
complex<double>** psi=alloc_zmatrix(N,N);
complex<double>** psi_minus=alloc_zmatrix(N,N);
//k gradient of psi(k) [xyz][eigenvalue order][vector index]
complex<double>** grad_psi[3];
for(i=0;i<3;i++){
grad_psi[i]=alloc_zmatrix(N,N);
}
printf("#kx ky kz\t");
for(i=0;i<N;i++){
printf("Omega_x[%d] Omega_y[%d] Omega_z[%d]\t",i,i,i);
}
printf("\n");
char berryCurvatureOutput_format[format_length];
sprintf(berryCurvatureOutput_format,"%s %s %s\t",realNumber_format,realNumber_format,realNumber_format);
//z, z^\prime in Algorithm.md
complex<double> psi_norm, psi_norm_prime;
//psi_(plus|minus) value without phase difference
complex<double> psi_value_plus,psi_value_minus;
complex<double> k_default;
double phase_plus,phase_minus;
double omega_x,omega_y,omega_z;
for(i=0;i<=k_split[0];i++){
k1=k1List[i];
for(j=0;j<=k_split[1];j++){
k2=k2List[j];
for(k=0;k<=k_split[2];k++){
k3=k3List[k];
compositeK(k1,k2,k3);
printf(realNumber_format,allParams_value[0].real());
printf("\t");
printf(realNumber_format,allParams_value[1].real());
printf("\t");
printf(realNumber_format,allParams_value[2].real());
printf("\t");
for(l=0;l<3;l++){
//calculate k[l] derivative of psi(k)
k_default=allParams_value[l];
compositeMatrix_HWR();
zheev();
if(INFO!=0){
cout << "zheev error" << endl;
return -1;
}
copy_zmatrix(psi,matrix,N,N);
//k+Delta k
allParams_value[l]=k_default+(complex<double>)delta_k;
compositeMatrix_HWR();
zheev();
if(INFO!=0){
cout << "zheev error" << endl;
return -1;
}
copy_zmatrix(psi_plus,matrix,N,N);
//k-Delta k
allParams_value[l]=k_default-(complex<double>)delta_k;
compositeMatrix_HWR();
zheev();
if(INFO!=0){
cout << "zheev error" << endl;
return -1;
}
copy_zmatrix(psi_minus,matrix,N,N);
//reset k value
allParams_value[l]=k_default;
for(m=0;m<N;m++){
psi_norm=zNorm(psi[m],psi_plus[m],N);
psi_norm_prime=zNorm(psi[m],psi_minus[m],N);
phase_plus=arg(psi_norm);
phase_minus=arg(psi_norm_prime);
for(n=0;n<N;n++){
psi_value_plus=exp(-(complex<double>(0,1))*phase_plus)*psi_plus[m][n];
psi_value_minus=exp(-(complex<double>(0,1))*phase_minus)*psi_minus[m][n];
grad_psi[l][m][n]=(psi_value_plus-psi_value_minus)/((complex<double>(2,0))*delta_k);
}
}
}
//print Berry curvature
for(m=0;m<N;m++){
//Berry curvature of m-th eigenvector
omega_x=-2*(zNorm(grad_psi[1][m],grad_psi[2][m],N).imag());
omega_y=-2*(zNorm(grad_psi[2][m],grad_psi[0][m],N).imag());
omega_z=-2*(zNorm(grad_psi[0][m],grad_psi[1][m],N).imag());
printf(berryCurvatureOutput_format,omega_x,omega_y,omega_z);
}
printf("\n");
}
if(k_split[2]!=0 && Dimension>1){
printf("\n");
}
}
if(k_split[2]==0 && Dimension>1){
printf("\n");
}
}
return 0;
}