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

Functions

double getETtime ()
 
int main (int argc, char **argv)
 

Function Documentation

◆ getETtime()

double getETtime ( )
14 {
15 struct timeval tv;
16 gettimeofday(&tv, NULL);
17 return tv.tv_sec +(double)tv.tv_usec *1e-6;
18}

◆ main()

int main ( int  argc,
char **  argv 
)
20 {
21 if(argc != 7) {
22 fprintf(stderr, "Usage: 1.This 2.(Number of elements) 3.(Number of blocks) 4.(Max elements on a site) 5.|U|*100 6.|V|*100 7.OutDir\n");
23 exit(EX_USAGE);
24 }
25 const MKL_INT N = atoi(argv[1]);
26 const MKL_INT L = atoi(argv[2]);
27 const MKL_INT MaxOnSite = atoi(argv[3]);
28 const double U = -atoi(argv[4])/100.0;
29 const double V = -atoi(argv[5])/100.0;
30
31 MKL_INT dim_tot, dim_odd, dim_even, NumPairs, **basis=NULL, *order=NULL;
32 double *eigenEnergy;
33 MKL_Complex16 **Hamiltonian_Odd, **Hamiltonian_Even;
34
35 const MKL_INT BUFSIZE = 1000;
36 char dstr[BUFSIZE], str[BUFSIZE], stemp[BUFSIZE];
37 char *filename = str;
38 double start, end;
39
40 //******************** Check for the directory structure ********************
41 strcpy(dstr, argv[6]);
42 strcat(dstr, "/BICData"); mkdir(dstr, 0744);
43 strcat(dstr, "/PBC"); mkdir(dstr, 0744);
44 if(U > 0) {
45 sprintf(stemp, "/N%lld_U%lld_nV%lld_Max%lld_L%lld", N, (MKL_INT)(100*U), (MKL_INT)(-100*V), MaxOnSite, L);
46 } else {
47 sprintf(stemp, "/N%lld_nU%lld_nV%lld_Max%lld_L%lld", N, (MKL_INT)(-100*U), (MKL_INT)(-100*V), MaxOnSite, L);
48 }
49 strcat(dstr, stemp); mkdir(dstr, 0744);
50 //******************** (END)Check for the directory structure ********************
51
52 //******************** Allocation ********************//
53 fprintf(stdout, "# Generating basis vectors...\n");
54 dim_tot = alloc_BasisVectors(N, L, MaxOnSite, &basis, &order, &NumPairs);
55 dim_odd = NumPairs;
56 dim_even = dim_tot -dim_odd;
57 fprintf(stdout, "# dim_tot = %lld, dim_even = %lld, dim_odd = %lld\n", dim_tot, dim_even, dim_odd);
58 eigenEnergy = alloc_dvector(dim_tot);
59 Hamiltonian_Odd = alloc_zmatrix(dim_odd, dim_odd);
60 Hamiltonian_Even = alloc_zmatrix(dim_even, dim_even);
61 //******************** (END)Allocation ********************//
62
63 //****************************************//
64 //****************************************//
65 fprintf(stdout, "# Constructing Hamiltonian...\n");
66 Construct_Hamiltonian(Hamiltonian_Odd, dim_odd, Hamiltonian_Even, dim_even, L, basis, U, V);
67
68 start = getETtime();
69 fprintf(stdout, "# Diagonalizing Hamiltonian...\n"); fflush(stdout);
70 Diagonalize_zmatrix(dim_even, Hamiltonian_Even, &(eigenEnergy[0]));
71 Diagonalize_zmatrix(dim_odd, Hamiltonian_Odd, &(eigenEnergy[dim_even]));
72 end = getETtime();
73 fprintf(stderr, "# (%lld %lld), Real time(sec): %.6lf sec\n", N, L, end-start);
74 fflush(stdout); fflush(stderr);
75
76 //************************************************************//
77 //************************************************************//
78 //************************************************************//
79 start = getETtime();
80 FILE *Outfp;
81 double **Observable, *KineticEnergy, *ImpurityEnergy;
82 KineticEnergy = alloc_dvector(dim_tot);
83 ImpurityEnergy = alloc_dvector(dim_tot);
84 for(int i = 0;i < dim_tot; ++i) {
85 KineticEnergy[i] = 0;
86 ImpurityEnergy[i] = 0;
87 }
88
89 fprintf(stdout, "# Calculating probability distribution...\n"); fflush(stdout);
90 Observable = Probability(Hamiltonian_Even, Hamiltonian_Odd, N, L, basis, dim_tot, NumPairs);
91 strcpy(str, dstr);
92 sprintf(stemp, "/Probability.txt");
93 strcat(str, stemp);
94 Outfp = fopen(filename, "w");
95 if(Outfp == NULL) {
96 printf("Can't open a file %s.", filename);
97 exit(EX_CANTCREAT);
98 }
99 fprintf(Outfp, "# N=%lld, L=%lld, MaxOnSite=%lld\n", N, L, MaxOnSite);
100 fprintf(Outfp, "# U=%+lf, V=%+lf\n", U, V);
101 for(int alpha = 0;alpha < dim_tot; ++alpha) {
102 double Cumulative = 0;
103 for(int j = 0;j < L/2; ++j) {
104 Cumulative += Observable[alpha][j];
105 fprintf(Outfp, "%d %+lld %le %d %le %le\n", alpha, 1-2*(alpha/dim_even), eigenEnergy[alpha], j, Observable[alpha][j], 1-Cumulative);
106 }
107 fprintf(Outfp, "\n");
108 }
109 free_dmatrix(Observable); Observable = NULL;
110
111
112 fprintf(stdout, "# Calculating particle density distribution...\n"); fflush(stdout);
113 Observable = ParticleDensity(Hamiltonian_Even, Hamiltonian_Odd, N, L, basis, dim_tot, NumPairs);
114 strcpy(str, dstr);
115 sprintf(stemp, "/ParticleDensity.txt");
116 strcat(str, stemp);
117 Outfp = fopen(filename, "w");
118 if(Outfp == NULL) {
119 printf("Can't open a file %s.", filename);
120 exit(EX_CANTCREAT);
121 }
122 fprintf(Outfp, "# N=%lld, L=%lld, MaxOnSite=%lld\n", N, L, MaxOnSite);
123 fprintf(Outfp, "# U=%+lf, V=%+lf\n", U, V);
124 for(int alpha = 0;alpha < dim_tot; ++alpha) {
125 for(int j = 0;j < L; ++j) fprintf(Outfp, "%d %+lld %le %d %le\n", alpha, 1-2*(alpha/dim_even), eigenEnergy[alpha], j, Observable[alpha][j]);
126 fprintf(Outfp, "\n");
127 ImpurityEnergy[alpha] = V*N*Observable[alpha][L/2];
128 }
129 free_dmatrix(Observable); Observable = NULL;
130
131 fprintf(stdout, "# Calculating pseudo-momentum distribution...\n"); fflush(stdout);
132 Observable = MomentumDistribution(Hamiltonian_Even, Hamiltonian_Odd, N, L, basis, order, dim_tot, NumPairs);
133 strcpy(str, dstr);
134 sprintf(stemp, "/MomentumDistribution.txt");
135 strcat(str, stemp);
136 Outfp = fopen(filename, "w");
137 if(Outfp == NULL) {
138 printf("Can't open a file %s.", filename);
139 exit(EX_CANTCREAT);
140 }
141 fprintf(Outfp, "# N=%lld, L=%lld, MaxOnSite=%lld\n", N, L, MaxOnSite);
142 fprintf(Outfp, "# U=%+lf, V=%+lf\n", U, V);
143 for(int alpha = 0;alpha < dim_tot; ++alpha) {
144 for(int j = 0;j < L; ++j) {
145 fprintf(Outfp, "%d %+lld %le %d %le\n", alpha, 1-2*(alpha/dim_even), eigenEnergy[alpha], j, Observable[alpha][j]);
146 KineticEnergy[alpha] += -2*cos(2*M_PI*j/L)*Observable[alpha][j]*N/(double)L;
147 }
148 fprintf(Outfp, "\n");
149 }
150
151
152 strcpy(str, dstr);
153 sprintf(stemp, "/Energy.txt");
154 strcat(str, stemp);
155 Outfp = fopen(filename, "w");
156 if(Outfp == NULL) {
157 printf("Can't open a file %s.", filename);
158 exit(EX_CANTCREAT);
159 }
160 fprintf(Outfp, "# N=%lld, L=%lld, MaxOnSite=%lld\n", N, L, MaxOnSite);
161 fprintf(Outfp, "# U=%+lf, V=%+lf\n", U, V);
162 fprintf(Outfp, "# 1.No 2.Parity 3.EigenEnergy 4.KineticEnergy 5.InteractionEnergy 6.ImpurityEnergy\n");
163 for(int alpha = 0;alpha < dim_tot; ++alpha) {
164 double InteractionEnergy = eigenEnergy[alpha] -(KineticEnergy[alpha] +ImpurityEnergy[alpha]);
165 fprintf(Outfp, "%d %+lld %le %le %le %le\n", alpha, 1-2*(alpha/dim_even), eigenEnergy[alpha], KineticEnergy[alpha], InteractionEnergy, ImpurityEnergy[alpha]);
166 }
167
168 //******************** Free ********************//
169 free_dvector(eigenEnergy);
170 free_zmatrix(Hamiltonian_Odd);
171 free_zmatrix(Hamiltonian_Even);
172 free_BasisVectors(basis, order);
173 //******************** (END)Free ********************//
174
175 return 0;
176}
double getETtime()
Definition PBC.c:14
void free_zmatrix(double complex **mat)
Definition translation.c:73
double complex ** alloc_zmatrix(int m, int n)
Definition translation.c:54