1 /**********************************************************************
2   TRAN_Set_SurfOverlap_NC.c:
3 
4   TRAN_Set_SurfOverlap_NC.c is a subroutine to construct H00_e, H01_e,
5   S00_e, and S01_e to make surface Green's functions
6 
7   Log of TRAN_Set_SurfOverlap_NC.c:
8 
9      11/Dec/2005   Released by H.Kino
10 
11 ***********************************************************************/
12 /* revised by Y. Xiao for Noncollinear NEGF calculations */
13 
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <math.h>
18 #include <mpi.h>
19 #include "tran_prototypes.h"
20 #include "tran_variables.h"
21 
22 /*****************************************
23 
24 explanation:
25 
26 atv_ijk[Rn][1..3] has index to the supercell
27 
28 
29 Rn==0, atv_ijk[Rn][1..3]=0 => means the same cell   => S00
30 
31 atv_ijk[Rn][1]=1 or -1 means the overlap to the nearest neighbor
32 cell in the direction of the electrode
33 1 or -1 => S01
34 
35 assuming atv_ijk[Rn][1]=-1,0 or 1
36 
37 ---------------------------------------------------------
38 output
39 
40 double S00_nc_e, S01_nc_e, H00_nc_e, H01_nc_e,
41 
42 ***********************************************/
43 
44 #define S00_ref(i,j) ( ((j)-1)*NUM+(i)-1 )
45 #define S01_ref(i,j) ( ((j+NUM0)-1)*NUM+(i)-1 )
46 #define S10_ref(i,j) ( ((j)-1)*NUM+(i+NUM0)-1 )
47 #define S11_ref(i,j) ( ((j+NUM0)-1)*NUM+(i+NUM0)-1 )
48 
TRAN_Set_SurfOverlap_NC(MPI_Comm comm1,char * position,double k2,double k3)49 void TRAN_Set_SurfOverlap_NC( MPI_Comm comm1,
50                            char *position,
51                            double k2,
52                            double k3)
53 {
54   int NUM,NUM0,n2;
55   int Anum, Bnum, wanA, tnoA;
56   int i,j,k;
57   int GA_AN;
58   int GB_AN, LB_AN,wanB, tnoB,Rn;
59   int l1,l2,l3;
60   int direction,iside;
61   double si,co,kRn;
62   double s,h[10];
63   double a00,a11,a01r,a01i,b00,b11,b01;
64   static double epscutoff=1.0e-8;
65   int *MP;
66   /*debug */
67   char msg[100];
68   /*end debug */
69 
70   /*
71   printf("<TRAN_Set_SurfOverlap, direction=%s>\n",position);
72   */
73 
74   /* position -> direction */
75   if      ( strcasecmp(position,"left")==0) {
76     direction = -1;
77     iside = 0;
78   }
79   else if ( strcasecmp(position,"right")==0) {
80     direction = 1;
81     iside = 1;
82   }
83 
84   /* set MP */
85 /*  TRAN_Set_MP(0, atomnum_e[iside], WhatSpecies_e[iside], Spe_Total_CNO_e[iside], &NUM, &i); */
86   MP = (int*)malloc(sizeof(int)*(atomnum_e[iside]+1));
87   TRAN_Set_MP(1, atomnum_e[iside], WhatSpecies_e[iside], Spe_Total_CNO_e[iside], &NUM, MP);
88   NUM0=NUM;
89   NUM=2*NUM;
90 
91   n2 = NUM + 1;
92 
93   for (i=0; i<n2*n2; i++){
94     S00_nc_e[iside][i].r = 0.0;
95     S00_nc_e[iside][i].i = 0.0;
96     S01_nc_e[iside][i].r = 0.0;
97     S01_nc_e[iside][i].i = 0.0;
98   }
99 
100   for (i=0; i<n2*n2; i++){
101     H00_nc_e[iside][i].r = 0.0;
102     H00_nc_e[iside][i].i = 0.0;
103     H01_nc_e[iside][i].r = 0.0;
104     H01_nc_e[iside][i].i = 0.0;
105   }
106 
107   for (GA_AN=1; GA_AN<=atomnum_e[iside]; GA_AN++){
108 
109     wanA = WhatSpecies_e[iside][GA_AN];
110     tnoA = Spe_Total_CNO_e[iside][wanA];
111     Anum = MP[GA_AN];
112 
113     for (LB_AN=0; LB_AN<=FNAN_e[iside][GA_AN]; LB_AN++){
114 
115       GB_AN = natn_e[iside][GA_AN][LB_AN];
116       Rn = ncn_e[iside][GA_AN][LB_AN];
117       wanB = WhatSpecies_e[iside][GB_AN];
118       tnoB = Spe_Total_CNO_e[iside][wanB];
119       Bnum = MP[GB_AN];
120 
121       l1 = atv_ijk_e[iside][Rn][1];
122       l2 = atv_ijk_e[iside][Rn][2];
123       l3 = atv_ijk_e[iside][Rn][3];
124 
125       kRn = k2*(double)l2 + k3*(double)l3;
126       si = sin(2.0*PI*kRn);
127       co = cos(2.0*PI*kRn);
128 
129       if (l1==0) {
130 	for (i=0; i<tnoA; i++){
131 	  for (j=0; j<tnoB; j++){
132 
133             /* S_alpha-alpha */
134 	    S00_nc_e[iside][S00_ref(Anum+i,Bnum+j)].r += co*OLP_e[iside][0][GA_AN][LB_AN][i][j];
135 	    S00_nc_e[iside][S00_ref(Anum+i,Bnum+j)].i += si*OLP_e[iside][0][GA_AN][LB_AN][i][j];
136             /* S_beta-beta */
137             S00_nc_e[iside][S11_ref(Anum+i,Bnum+j)].r += co*OLP_e[iside][0][GA_AN][LB_AN][i][j];
138             S00_nc_e[iside][S11_ref(Anum+i,Bnum+j)].i += si*OLP_e[iside][0][GA_AN][LB_AN][i][j];
139 
140             a00=H_e[iside][0][GA_AN][LB_AN][i][j];
141             a11=H_e[iside][1][GA_AN][LB_AN][i][j];
142             a01r=H_e[iside][2][GA_AN][LB_AN][i][j];
143             a01i=H_e[iside][3][GA_AN][LB_AN][i][j];
144 
145             b00=iHNL_e[iside][0][GA_AN][LB_AN][i][j];
146             b11=iHNL_e[iside][1][GA_AN][LB_AN][i][j];
147             b01=iHNL_e[iside][2][GA_AN][LB_AN][i][j];
148             /* H_alpha-alpha */
149             H00_nc_e[iside][S00_ref(Anum+i,Bnum+j)].r += co*a00 - si*b00;
150             H00_nc_e[iside][S00_ref(Anum+i,Bnum+j)].i += co*b00 + si*a00;
151             /* H_alpha-beta */
152             H00_nc_e[iside][S01_ref(Anum+i,Bnum+j)].r += co*a01r - si*(a01i+b01);
153             H00_nc_e[iside][S01_ref(Anum+i,Bnum+j)].i += si*a01r + co*(a01i+b01);
154             /* H_beta-beta */
155             H00_nc_e[iside][S11_ref(Anum+i,Bnum+j)].r += co*a11 - si*b11;
156             H00_nc_e[iside][S11_ref(Anum+i,Bnum+j)].i += co*b11 + si*a11;
157 
158             /*
159             S00_e[iside][S00_ref(Anum+i,Bnum+j)].r += co*OLP_e[iside][0][GA_AN][LB_AN][i][j];
160             S00_e[iside][S00_ref(Anum+i,Bnum+j)].i += si*OLP_e[iside][0][GA_AN][LB_AN][i][j];
161 
162             for (k=0; k<=SpinP_switch_e[iside]; k++ ){
163               H00_e[iside][k][S00_ref(Anum+i,Bnum+j)].r += co*H_e[iside][k][GA_AN][LB_AN][i][j];
164               H00_e[iside][k][S00_ref(Anum+i,Bnum+j)].i += si*H_e[iside][k][GA_AN][LB_AN][i][j];
165             }
166             */
167 
168 	  }
169 	}
170       }
171 
172       if (l1==direction) {
173 
174 	for (i=0; i<tnoA; i++){
175 	  for (j=0; j<tnoB; j++){
176 
177             /* S_alpha-alpha */
178             S01_nc_e[iside][S00_ref(Anum+i,Bnum+j)].r += co*OLP_e[iside][0][GA_AN][LB_AN][i][j];
179             S01_nc_e[iside][S00_ref(Anum+i,Bnum+j)].i += si*OLP_e[iside][0][GA_AN][LB_AN][i][j];
180             /* S_beta-beta */
181             S01_nc_e[iside][S11_ref(Anum+i,Bnum+j)].r += co*OLP_e[iside][0][GA_AN][LB_AN][i][j];
182             S01_nc_e[iside][S11_ref(Anum+i,Bnum+j)].i += si*OLP_e[iside][0][GA_AN][LB_AN][i][j];
183 
184             a00=H_e[iside][0][GA_AN][LB_AN][i][j];
185             a11=H_e[iside][1][GA_AN][LB_AN][i][j];
186             a01r=H_e[iside][2][GA_AN][LB_AN][i][j];
187             a01i=H_e[iside][3][GA_AN][LB_AN][i][j];
188 
189             b00=iHNL_e[iside][0][GA_AN][LB_AN][i][j];
190             b11=iHNL_e[iside][1][GA_AN][LB_AN][i][j];
191             b01=iHNL_e[iside][2][GA_AN][LB_AN][i][j];
192             /* H_alpha-alpha */
193             H01_nc_e[iside][S00_ref(Anum+i,Bnum+j)].r += co*a00 - si*b00;
194             H01_nc_e[iside][S00_ref(Anum+i,Bnum+j)].i += co*b00 + si*a00;
195             /* H_alpha-beta */
196             H01_nc_e[iside][S01_ref(Anum+i,Bnum+j)].r += co*a01r - si*(a01i+b01);
197             H01_nc_e[iside][S01_ref(Anum+i,Bnum+j)].i += si*a01r + co*(a01i+b01);
198             /* H_beta-beta */
199             H01_nc_e[iside][S11_ref(Anum+i,Bnum+j)].r += co*a11 - si*b11;
200             H01_nc_e[iside][S11_ref(Anum+i,Bnum+j)].i += co*b11 + si*a11;
201 
202             /*
203 	    S01_e[iside][S00_ref(Anum+i,Bnum+j)].r += co*OLP_e[iside][0][GA_AN][LB_AN][i][j];
204 	    S01_e[iside][S00_ref(Anum+i,Bnum+j)].i += si*OLP_e[iside][0][GA_AN][LB_AN][i][j];
205 
206 	    for (k=0; k<=SpinP_switch_e[iside]; k++ ){
207 	      H01_e[iside][k][S00_ref(Anum+i,Bnum+j)].r += co*H_e[iside][k][GA_AN][LB_AN][i][j];
208 	      H01_e[iside][k][S00_ref(Anum+i,Bnum+j)].i += si*H_e[iside][k][GA_AN][LB_AN][i][j];
209 	    }
210             */
211 	  }
212 	}
213       }
214 
215     }
216   }  /* GA_AN */
217 
218    for (i=1; i<=NUM0; i++) {
219      for (j=1; j<=NUM0; j++) {
220 
221        H00_nc_e[iside][(j-1)*NUM+i+NUM0-1].r =  H00_nc_e[iside][(i+NUM0-1)*NUM+j-1].r;
222        H00_nc_e[iside][(j-1)*NUM+i+NUM0-1].i = -H00_nc_e[iside][(i+NUM0-1)*NUM+j-1].i;
223 
224        H01_nc_e[iside][(j-1)*NUM+i+NUM0-1].r =  H01_nc_e[iside][(i+NUM0-1)*NUM+j-1].r;
225        H01_nc_e[iside][(j-1)*NUM+i+NUM0-1].i = -H01_nc_e[iside][(i+NUM0-1)*NUM+j-1].i;
226 
227       }
228     }
229 
230   /* free arrays */
231 
232   free(MP);
233 }
234