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

Functions

void zheev_ (char *JOBZ, char *UPLO, int *N, double complex *A, int *LDA, double *W, double complex *WORK, int *LWORK, double *RWORK, int *INFO)
 
void zgeev_ (char *JOBVL, char *JOBVR, int *N, double complex *A, int *LDA, double complex *W, double complex *VL, int *LDVL, double complex *VR, int *LDVR, double complex *WORK, int *LWORK, double *RWORK, int *INFO)
 
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 zgemm_ (char *TRANSA, char *TRANSB, int *M, int *N, int *K, double complex *ALPHA, double complex *A, int *LDA, double complex *B, int *LDB, double complex *BETA, double complex *C, int *LDC)
 
void zdotc_ (double complex *result, int *N, double complex *X, int *INCX, double complex *Y, int *INCY)
 
double complexalloc_zvector (int m)
 
double complex ** alloc_zmatrix (int m, int n)
 
void free_zvector (double complex *vec)
 
void free_zmatrix (double complex **mat)
 
void i_to_spin (int i, int *spin, int dim_loc, int n)
 
int spin_to_i (int *const spin, int dim_loc, int n, int trans)
 
int main (int argc, char **argv)
 

Function Documentation

◆ alloc_zmatrix()

double complex ** alloc_zmatrix ( int  m,
int  n 
)
54 {
55 int i;
56 double complex **mat;
57 mat = (double complex**)malloc((size_t)(m * sizeof(double complex*)));
58 if (mat == NULL) {
59 fprintf(stderr, "Error: allocation failed in alloc_zmatrix\n");
60 exit(1);
61 }
62 mat[0] = (double complex*)malloc((size_t)(m * n * sizeof(double complex)));
63 if (mat[0] == NULL) {
64 fprintf(stderr, "Error: allocation failed in alloc_zmatrix\n");
65 exit(1);
66 }
67 for (i = 1; i < m; ++i) mat[i] = mat[i-1] + n;
68 return mat;
69}
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

◆ alloc_zvector()

double complex * alloc_zvector ( int  m)
44 {
45 int i;
46 double complex *vec;
47 vec = (double complex*)malloc((size_t)(m * sizeof(double complex)));
48 if (vec == NULL) {
49 fprintf(stderr, "Error: allocation failed in alloc_zmatrix\n");
50 exit(1);
51 }
52 return vec;
53}

◆ free_zmatrix()

void free_zmatrix ( double complex **  mat)
73 {
74 free(mat[0]);
75 free(mat);
76}

◆ free_zvector()

void free_zvector ( double complex vec)
70 {
71 free(vec);
72};

◆ i_to_spin()

void i_to_spin ( int  i,
int *  spin,
int  dim_loc,
int  n 
)
78 {
79 int j, x;
80 int dim_tot = pow(dim_loc, n);
81 for (j = 0;j < n; ++j) {
82 spin[j] = i%dim_loc;
83 i = (i-spin[j])/dim_loc;
84 }
85}
constexpr Integer_t dim_loc
Definition setVariablesForEnsemble.cpp:36

◆ main()

int main ( int  argc,
char **  argv 
)
97 {
98 int i,j,k,l,m;
99 int x,y;
100 int dim_loc = 2;
101 int n = 11;
102 int dim_tot = pow(dim_loc, n);
103 int *spin;
104 int *#wave_number, *n_momentum, *calculated;
105 double complex **translation, **eigenvectors, **temp;
106
107 char trans = 'T', ntrans = 'N', ctrans = 'C';
108 double complex alpha = 1.0;
109 double complex beta = 0;
110
111
112 #wave_number = alloc_ivector(dim_tot);
113 n_momentum = alloc_ivector(n);
114 calculated = alloc_ivector(dim_tot);
115 spin = alloc_ivector(n);
116 // translation = alloc_zmatrix(dim_tot, dim_tot);
117
118 temp = alloc_zmatrix(dim_tot, dim_tot);
119
120 printf("\r(n = %d) Initializing.", n);
121 fflush(stdout);
122 for (i = 0;i < n; ++i) n_momentum[i] = 0;
123 for (i = 0;i < dim_tot; ++i) calculated[i] = 0;
124
125 printf("\r(n = %d) Calculating the number of Eigenvectors.", n);
126 fflush(stdout);
127
128 m = 0;
129 for (i = 0;i < dim_tot; ++i) {
130 if (calculated[i] == 1) {
131 // printf("y = %d, i = %d is already calculated.\n", y, i);
132 continue;
133 }
134 i_to_spin(i, spin, dim_loc, n);
135 /*
136 printf("i = %d, spin = ", i);
137 for (j = n-1;j >= 0; --j) {
138 printf("%d ", spin[j]);
139 }
140 printf(", spin_to_i = %d\n", spin_to_i(spin, dim_loc, n, 0));
141 */
142
143 j = 1; // T^j|> = |> となる最小のj
144 while (j != 0) {
145 k = 0;
146 while (spin[(k+j)%n] == spin[k] && k < n) {
147 // printf("(k+j)%%n = %d, k = %d, j = %d, n =%d\n", (k+j)%n, k, j, n);
148 k += 1;
149 }
150 if (k == n) break;
151 j += 1;
152 }
153 y = n/j;
154 for (k = 0;k < j; ++k) {
155 n_momentum[k*y] += 1;
156 for (l = 0;l < j; ++l) {
157 x = spin_to_i(spin, dim_loc, n, l);
158 calculated[x] = 1;
159 // printf("\ry = %d, i = %d, j = %d, k = %d, m = %d, dim_tot = %d, x = %d, l = %d",y, i, j, k, m, dim_tot, x, l);
160 // fflush(stdout);
161 }
162 m += 1;
163 if (m > dim_tot) {
164 printf("m = %d > dim_tot = %d.\n", m, dim_tot);
165 exit(1);
166 }
167 }
168 }
169
170 printf("\r(n = %d) Calculating the Eigenvectors with p=0.", n);
171 fflush(stdout);
172 for (i = 0;i < dim_tot; ++i) calculated[i] = 0;
173 eigenvectors = alloc_zmatrix(n_momentum[0], dim_tot);
174 m = 0;
175 for (i = 0;i < dim_tot; ++i) {
176 if (calculated[i] == 1) continue;
177 i_to_spin(i, spin, dim_loc, n);
178
179 j = 1; // T^j|> = |> となる最小のj
180 while (j != 0) {
181 k = 0;
182 while (spin[(k+j)%n] == spin[k] && k < n) k += 1;
183 if (k == n) break;
184 j += 1;
185 }
186 y = n/j;
187 for (k = 0;k < j; ++k) {
188 for (l = 0;l < j; ++l) {
189 x = spin_to_i(spin, dim_loc, n, l);
190 if(k == 0) eigenvectors[m][x] = 1.0/sqrt(1.0*j);
191 calculated[x] = 1;
192 // printf("y = %d, i = %d, j = %d, k = %d, m = %d, dim_tot = %d, x = %d, l = %d\n",y, i, j, k, m, dim_tot, x, l);
193 // fflush(stdout);
194 }
195 }
196 m += 1;
197 }
198 // printf("m = %d\n", m);
199
200 /*
201 printf("\r(n = %d) Checking Eigenvectors.", n);
202 zgemm_(&trans, &ntrans, &dim_tot, &dim_tot, &dim_tot, &alpha, &translation[0][0], &dim_tot, &eigenvectors[0][0], &dim_tot, &beta, &temp[0][0], &dim_tot);
203 zgemm_(&ctrans, &ntrans, &dim_tot, &dim_tot, &dim_tot, &alpha, &eigenvectors[0][0], &dim_tot, &temp[0][0], &dim_tot, &beta, &translation[0][0], &dim_tot);
204
205 for (i = 0;i < dim_tot; ++i) {
206 x = ( (int)( n+ 0.5 +n*cimag( clog(1.0*translation[i][i])/2.0/M_PI )) )%n;
207 printf("diagonal[%d] = %d, #wave_number[%d] = %d, %d, %lf\n", i, x, i, #wave_number[i], (x-#wave_number[i] +n)%n, n*cimag( clog(translation[i][i])/2.0/M_PI ));
208 }
209 for (i = 0;i < dim_tot; ++i) {
210 for (j = 0;j < dim_tot; ++j) {
211 if (i == j) continue;
212 if ( (int)creal(translation[i][j]) != 0) {
213 printf("Non-zero off-diagonal element translation[%d][%d] = %.3lf+i%+.3lf\n", i,j, creal(translation[i][j]), cimag(translation[i][j]));
214 } else {
215 translation[i][j] = 0;
216 }
217 }
218 }
219 */
220 printf("\n");
221 for (i = 0;i < n; ++i) {
222 printf("n_momentum[%d] = %d\n", i, n_momentum[i]);
223 }
224
225 free_ivector(#wave_number);
226 free_ivector(n_momentum);
227 free_ivector(calculated);
228
229 free_ivector(spin);
230 // free_zmatrix(translation);
231 free_zmatrix(eigenvectors);
232 free_zmatrix(temp);
233
234 return 0;
235}
constexpr Integer_t wave_number
Definition TranslationInvariantSectors.cpp:1
void free_zmatrix(double complex **mat)
Definition translation.c:73
void i_to_spin(int i, int *spin, int dim_loc, int n)
Definition translation.c:78
double complex ** alloc_zmatrix(int m, int n)
Definition translation.c:54
int spin_to_i(int *const spin, int dim_loc, int n, int trans)
Definition translation.c:86

◆ spin_to_i()

int spin_to_i ( int *const  spin,
int  dim_loc,
int  n,
int  trans 
)
86 {
87 int j, x, y;
88 x = 0;
89 y = 1;
90 for (j = 0;j < n; ++j) {
91 x += y*spin[(j+trans)%n];
92 y *= dim_loc;
93 }
94 return x;
95}

◆ zdotc_()

void zdotc_ ( double complex result,
int *  N,
double complex X,
int *  INCX,
double complex Y,
int *  INCY 
)

◆ zgeev_()

void zgeev_ ( char *  JOBVL,
char *  JOBVR,
int *  N,
double complex A,
int *  LDA,
double complex W,
double complex VL,
int *  LDVL,
double complex VR,
int *  LDVR,
double complex WORK,
int *  LWORK,
double *  RWORK,
int *  INFO 
)

◆ zgemm_()

void zgemm_ ( char *  TRANSA,
char *  TRANSB,
int *  M,
int *  N,
int *  K,
double complex ALPHA,
double complex A,
int *  LDA,
double complex B,
int *  LDB,
double complex BETA,
double complex C,
int *  LDC 
)

◆ zgemv_()

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 
)

◆ zheev_()

void zheev_ ( char *  JOBZ,
char *  UPLO,
int *  N,
double complex A,
int *  LDA,
double *  W,
double complex WORK,
int *  LWORK,
double *  RWORK,
int *  INFO 
)