StatMech
Loading...
Searching...
No Matches
Perturbation.c File Reference

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
59 {
60 if(argc < 5) {
61 printf("Usage: 1.This 2.n_max 3.num_h 4.num_op 5.Output dir\n");
62 exit(1);
63 }
64
65 int i,j;
66 int dim_tot, dim_sub, s; //全ヒルベルト空間の次元
67 int dim_loc = 2; // サイト上のヒルベルト空間の次元
68 int n,n_min;
69 int n_max = atoi(argv[1]); // 全スピンの数
70 int num_h = atoi(argv[2]); // 局所ハミルトニアンに含まれるサイト数
71 int num_op = atoi(argv[3]); // 局所演算子に含まれるサイト数
72 int dloc_h = pow(dim_loc, num_h); // 局所ハミルトニアンの空間の次元
73 int dloc_op = pow(dim_loc, num_op); // 局所演算子の空間の次元
74 int count, ndata; // カウンタ
75 const int seed = 0;
76 int div;
77 const int divMax = 100;
78
79 int MinShell, MaxShell;
80 double complex **h, **h_int, **loc; // 局所ハミルトニアン、局所物理量
81 double complex **h_tot, **loc_tot; // 運動量セクターにおけるハミルトニアンと物理量
82 double lambda, res, MicroAverage;
83 double Stddev_inShell, Max_inShell;
84 const double delta = 0.02; // ミクロカノニカル平均を計算するエネルギーシェルの幅
85
86 double dE, Erel, range;
87 double *eigenvalue, *expvalue;
88 double complex expectation, *intermediate;
89
90 //********** For LAPACK and BLASS
91 const char e_value = 'V';
92 const char upper = 'U';
93 double complex *work;
94 double *rwork;
95 int info;
96 const char trans = 'T', ntrans = 'N', ctrans = 'C';
97 const double complex alpha = 1;
98 const double complex beta = 0;
99 const int incx = 1;
100 const int incy = 1;
101 //********** (END) For LAPACK and BLASS
102
103 const int BUFSIZE = 1000;
104 char d_str[BUFSIZE], str[BUFSIZE], stemp[BUFSIZE];
105 char *filename = str;
106 FILE* FpOperators = NULL;
107
108 clock_t start, end, temp_t;
109
110 //******************** Check for the directory structure ********************
111 strcpy(d_str, argv[4]);
112 sprintf(stemp,"/Perturbation_Local%d_Seed%d_Max%d", num_h, seed, n_max);
113 strcat(d_str, stemp);
114 mkdir(d_str, 0744);
115 //******************** (END) Check for the directory structure ********************
116
117 //******************** Allocation & Initialization ********************
118 if(num_op > num_h) n_min = num_op; else n_min = num_h;
119 dim_tot = pow(dim_loc, 2*n_max);
120 s = 3*dim_tot;
121
122 expvalue = alloc_dvector(dim_tot);
123 eigenvalue = alloc_dvector(dim_tot);
124 intermediate = alloc_zvector(dim_tot);
125
126 printf("dloc_h=%d, dloc_op=%d\n", dloc_h, dloc_op);
128 h_int = alloc_zmatrix(dloc_h, dloc_h);
130 work = alloc_zvector(s);
131 rwork = alloc_dvector(s);
132
133 init_genrand(seed);
134 fflush(stdout);
135 //******************** (END) Allocation & Initialization ********************
136
137 start = clock();
138 end = start;
139 //****************************** 局所演算子に関する性質を保存するファイルを用意 ******************************//
140 strcpy(str, d_str);
141 sprintf(stemp, "/Operators_%d.txt", seed);
142 strcat(str, stemp);
143 FpOperators = fopen(filename, "w");
144 if(FpOperators == NULL) {
145 printf("Can't open a file %s.", filename);
146 exit(1);
147 }
148 fprintf(FpOperators, "#dim_loc=%d, num_h=%d, num_op=%d, delta=%lf\n", dim_loc, num_h, num_op, delta);
149 fprintf(FpOperators, "#Fixed disorder strength\n");
150 fprintf(FpOperators, "#1.lambda, 2.System size, 3.Energy density, 4.Relative Pos, 5.Exp value, 6.Micro average, 7.f(E,0) in shell, 8.MaxFluc in shell, 9.Dim of shell\n\n");
151 //****************************** (END) 局所演算子に関する性質を保存するファイルを用意 ******************************//
152
153 //****************************** 局所ハミルトニアンと局所物理量をランダムにとる ******************************//
154 //printf("\rCreating Random matrices. dloc_h=%d, dloc_op=%d", dloc_h, dloc_op);
155 //fflush(stdout);
156 prepare_h(h, dloc_h , -1);
157 prepare_h(loc, dloc_op, -1);
158
159 lambda = 0;
160 for(div = 0;div <= divMax; ++div) {
161 lambda = (double)div/divMax;
162 printf("lambda=%.2f\n", lambda);
163 for(n = n_max;n >= n_min; --n) {
164 dim_sub = pow(dim_loc, 2*n);
165 h_tot = alloc_zmatrix(dim_sub, dim_sub);
166 loc_tot = alloc_zmatrix(dim_sub, dim_sub);
167 for(i = 0;i < dim_sub; ++i) for(j = 0;j < dim_sub; ++j) {
168 h_tot[i][j] = 0;
169 loc_tot[i][j] = 0;
170 }
171
172 for(i = 0;i < dloc_h; ++i) for(j = 0;j < dloc_h; ++j) h_int[i][j] = lambda *h[i][j];
173 //****************************** nにおける全系のハミルトニアンと演算子を構成する ******************************//
174 // printf("n=%d\n", n);
175 for(i = 0;i <= n-num_h; ++i) {
176 imbed_locOp(i, h, h_tot, num_h, n, dim_sub, dim_loc);
177 // printf("%d ", i);
178 }
179 for(i = n-num_h+1;i < n; ++i) {
180 imbed_locOp(i, h_int, h_tot, num_h, n, dim_sub, dim_loc);
181 // printf("%d ", i);
182 }
183 for(i = n;i <= 2*n-num_h; ++i) {
184 imbed_locOp(i, h, h_tot, num_h, n, dim_sub, dim_loc);
185 // printf("%d ", i);
186 }
187 // printf("\n");
188 local_to_global(loc, loc_tot, num_op, n, dim_sub, dim_loc, "open", 0.0);
189
190
191 //****************************** (END) nにおける全系のハミルトニアンと演算子を構成する ******************************//
192
193 //****************************** 全系のハミルトニアンを対角化する ******************************//
194 zheev_(&e_value, &upper, &dim_sub, &h_tot[0][0], &dim_sub, &eigenvalue[0], &work[0], &s, &rwork[0], &info);
195 if(info != 0) {
196 fprintf(stderr, "Error: LAPACK::zheev failed\n");
197 exit(1);
198 }
199 for(i = 0;i < dim_sub; ++i) eigenvalue[i] /= (double)n;
200 range = eigenvalue[dim_sub-1] -eigenvalue[0];
201 dE = delta*range;
202 //****************************** (END)全系のハミルトニアンを対角化する ******************************//
203
204 //****************************** 全系の物理量のエネルギー固有状態に関する期待値を計算 ******************************//
205 for(i = 0;i < dim_sub; ++i) {
206 for(j = 0;j < dim_sub; ++j) intermediate[j] = 0;
207 expectation = 0;
208 zgemv_(&ntrans, &dim_sub, &dim_sub, &alpha, &loc_tot[0][0], &dim_sub, &h_tot[i][0], &incx, &beta, &intermediate[0], &incy);
209 // SOMETHING IS WRONG IN BLAS zdotc_ // zdotc_(&expectation, &dim_sub, &h_tot[i][0], &incx, intermediate, &incy);
210 for(int p=0;p < dim_sub; ++p) expectation += conj(h_tot[i][p])*intermediate[p];
211 expvalue[i] = creal(expectation)/(double)n;
212 }
213 //****************************** (END) 全系の物理量のエネルギー固有状態に関する期待値を計算 ******************************//
214
215 //****************************** ミクロカノニカル平均まわりのゆらぎを計算 ******************************//
216 ndata = 0;
217 for(i = 0;i < dim_sub; ++i) {
218 //********** ミクロカノニカル平均を計算
219 MicroAverage = 0;
220 count = 0;
221 MinShell = dim_sub; MaxShell = 0;
222 for(j = 0;j<dim_sub && eigenvalue[j]<eigenvalue[i]+dE; ++j) {
223 if( eigenvalue[j] < eigenvalue[i]-dE ) continue;
224 if (j < MinShell) MinShell = j;
225 if (j > MaxShell) MaxShell = j;
226 MicroAverage += expvalue[j];
227 count += 1;
228 }
229 if (count!= MaxShell-MinShell+1) {
230 printf("(n=%d, dim_sub=%d) count=%d, (MinShell, MaxShell) = (%d,%d), delta=%d\n", n, dim_sub, count, MinShell, MaxShell, MaxShell-MinShell+1);
231 exit(1);
232 }
233 MicroAverage /= (double)count;
234 //********** (END) ミクロカノニカル平均を計算
235 Erel = (eigenvalue[i]-eigenvalue[0])/range;
236 //********** シェル内のゆらぎの大きさを計算
237 res = 0;
238 Stddev_inShell = 0;
239 Max_inShell = 0;
240 for(j = MinShell;j <= MaxShell; ++j) {
241 res = expvalue[j] -MicroAverage;
242 Stddev_inShell += res*res;
243 if( fabs(res) > Max_inShell ) Max_inShell = fabs(res);
244 }
245 Stddev_inShell /= (MaxShell-MinShell);
246 Stddev_inShell = sqrt(Stddev_inShell);
247 //********** (END) シェル内のゆらぎの大きさを計算
248 fprintf(FpOperators, "%le %d %le %le %le %le %le %le %d\n", lambda, n, eigenvalue[i], Erel, expvalue[i], MicroAverage, Stddev_inShell*sqrt((double)count), Max_inShell, count);
249 }
250 //****************************** (END) ミクロカノニカル平均まわりのゆらぎを計算 ******************************//
251 fprintf(FpOperators, "\n");
252 //******************** Free in for(n) ********************//
253 free_zmatrix(h_tot);
254 free_zmatrix(loc_tot);
255 //******************** (END) Free in for(n) ********************//
256 }
257 }
258
259 fclose(FpOperators);
260 fflush(stdout);
261
262 //******************** Free ********************//
263 free_dvector(expvalue);
264 free_dvector(eigenvalue);
265 free_zvector(intermediate);
266
267 free_zmatrix(h);
268 free_zmatrix(loc);
269 free_zvector(work);
270 free_dvector(rwork);
271 //******************** (END) Free ********************//
272
273 return 0;
274}
std::conditional_t< std::is_same_v< T, float >, myFloatComplex, std::conditional_t< std::is_same_v< T, double >, myDoubleComplex, myComplex< T > > > complex
Definition mytypes.hpp:133
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 n_min
Definition setVariablesForEnsemble.cpp:28
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
double const dE
Definition setVariablesForMCAverage.cpp:2
void zgemv_(char *TRANS, int *M, int *N, double complex *ALPHA, double complex *A, int *LDA, double complex *X, int *INCX, double complex *BETA, double complex *Y, int *INCY)
void free_zmatrix(double complex **mat)
Definition translation.c:73
void free_zvector(double complex *vec)
Definition translation.c:70
void zheev_(char *JOBZ, char *UPLO, int *N, double complex *A, int *LDA, double *W, double complex *WORK, int *LWORK, double *RWORK, int *INFO)
double complex ** alloc_zmatrix(int m, int n)
Definition translation.c:54
double complex * alloc_zvector(int m)
Definition translation.c:44