1 /**********************************************************************
2   TRAN_Add_ADensity_Lead.c:
3 
4   TRAN_Add_ADensity_Lead.c is a subroutine to correct atomic charge
5   density near the boundary region of the extended system
6   The super position of atomic charge density from that of electrodes
7   is added to the regions [0:TRAN_grid_bound[0]] and
8   [TRAN_grid_bound[1]:Ngrid1-1].
9 
10   Log of TRAN_Add_ADensity_Lead.c:
11 
12      24/July/2008  Released by T.Ozaki
13      24/Apr/2012   Modified by T.Ozaki
14 
15 ***********************************************************************/
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <mpi.h>
21 #include "tran_variables.h"
22 #include "tran_prototypes.h"
23 
24 
TRAN_Add_ADensity_Lead(MPI_Comm comm1,int SpinP_switch,int Ngrid1,int Ngrid2,int Ngrid3,int My_NumGridB_AB,double * ADensity_Grid_B)25 void TRAN_Add_ADensity_Lead(
26             MPI_Comm comm1,
27             int SpinP_switch,
28             int Ngrid1,
29             int Ngrid2,
30             int Ngrid3,
31             int My_NumGridB_AB,
32             double *ADensity_Grid_B)
33 
34 #define grid_e_ref(i,j,k)  ( ((i)-l1[0]) *Ngrid2*Ngrid3+(j)*Ngrid3+(k) )
35 
36 {
37   int side,l1[2],N2D,GNs;
38   int i,j,k,spin,GN,BN_AB;
39   int myid,numprocs;
40 
41   MPI_Comm_size(comm1,&numprocs);
42   MPI_Comm_rank(comm1,&myid);
43 
44   if (myid==Host_ID){
45     printf("<TRAN_Add_ADensity_Lead>\n");
46   }
47 
48   /* set N2D and GNs */
49 
50   N2D = Ngrid1*Ngrid2;
51   GNs = ((myid*N2D+numprocs-1)/numprocs)*Ngrid3;
52 
53   /***********************************************************
54     add contribution to atomic charge density from electrodes
55 
56     side=0 -> left lead
57     side=1 -> right lead
58   ***********************************************************/
59 
60   for (side=0; side<=1; side++){
61 
62     if (side==0){
63       l1[0] = 0;
64       l1[1] = TRAN_grid_bound[0];
65     }
66     else{
67       l1[0] = TRAN_grid_bound[1];
68       l1[1] = Ngrid1-1;
69     }
70 
71     for (BN_AB=0; BN_AB<My_NumGridB_AB; BN_AB++){
72 
73       GN = BN_AB + GNs;
74       i = GN/(Ngrid2*Ngrid3);
75       j = (GN - i*Ngrid2*Ngrid3)/Ngrid3;
76       k = GN - i*Ngrid2*Ngrid3 - j*Ngrid3;
77 
78       if ( l1[0]<=i && i<=l1[1] ) {
79 
80 	ADensity_Grid_B[BN_AB] += ElectrodeADensity_Grid[side][ grid_e_ref(i,j,k) ];
81       }
82     }
83   }
84 }
85