File: FT_PAO.c

package info (click to toggle)
openmx 3.2.4.dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze
  • size: 62,572 kB
  • ctags: 2,684
  • sloc: ansic: 130,666; python: 876; makefile: 560; xml: 63; perl: 18; sh: 4
file content (178 lines) | stat: -rw-r--r-- 4,388 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**********************************************************************
  FT_PAO.c:

     FT_PAO.c is a subroutine to Fourier transform pseudo atomic 
     orbitals.

  Log of FT_PAO.c:

     15/Sep/2002  Released by T.Ozaki

***********************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "openmx_common.h"

#ifdef nompi
#include "mimic_mpi.h"
#else
#include "mpi.h"
#endif


void FT_PAO()
{
  int numprocs,myid,ID,tag=999;
  int count,NumSpe;
  int i,kj,num_k;
  int Lspe,spe,GL,Mul;
  double dk,norm_k,h;
  double rmin,rmax,r,sum;
  double sj,sy,sjp,syp;
  double Sr,Dr,dum0;
  double **SphB,**SphBp;
  double *tmp_SphB,*tmp_SphBp;
  double TStime, TEtime;
  MPI_Status stat;
  MPI_Request request;

  dtime(&TStime);

  /* MPI */
  MPI_Comm_size(mpi_comm_level1,&numprocs);
  MPI_Comm_rank(mpi_comm_level1,&myid);

  if (myid==Host_ID) printf("<FT_PAO>          Fourier transform of pseudo atomic orbitals\n");

  for (Lspe=0; Lspe<MSpeciesNum; Lspe++){

    spe = Species_Top[myid] + Lspe;

    num_k = Ngrid_NormK;
    dk = PAO_Nkmax/(double)num_k;

    /* allocate SphB and SphBp */

    SphB = (double**)malloc(sizeof(double*)*(Spe_MaxL_Basis[spe]+3));
    for(GL=0; GL<(Spe_MaxL_Basis[spe]+3); GL++){ 
      SphB[GL] = (double*)malloc(sizeof(double)*(OneD_Grid+1));
    }

    SphBp = (double**)malloc(sizeof(double*)*(Spe_MaxL_Basis[spe]+3));
    for(GL=0; GL<(Spe_MaxL_Basis[spe]+3); GL++){ 
      SphBp[GL] = (double*)malloc(sizeof(double)*(OneD_Grid+1));
    }

    tmp_SphB  = (double*)malloc(sizeof(double)*(Spe_MaxL_Basis[spe]+3));
    tmp_SphBp = (double*)malloc(sizeof(double)*(Spe_MaxL_Basis[spe]+3));

    /* kj loop */

    for (kj=0; kj<num_k; kj++){

      norm_k = (double)kj*dk;

      /* calculate SphB */

      rmin = Spe_PAO_RV[spe][0];
      rmax = Spe_Atom_Cut1[spe] + 0.5;
      h = (rmax - rmin)/(double)OneD_Grid;

      for (i=0; i<=OneD_Grid; i++){
        r = rmin + (double)i*h;

	Spherical_Bessel(norm_k*r,Spe_MaxL_Basis[spe],tmp_SphB,tmp_SphBp);

	for(GL=0; GL<=Spe_MaxL_Basis[spe]; GL++){ 
	  SphB[GL][i]  =  tmp_SphB[GL]; 
	  SphBp[GL][i] = tmp_SphBp[GL]; 
	}
      }

      /* loof for GL and Mul */

      for (GL=0; GL<=Spe_MaxL_Basis[spe]; GL++){
	for (Mul=0; Mul<Spe_Num_Basis[spe][GL]; Mul++){

	  /****************************************************
                        \int jL(k*r)RL r^2 dr 
	  ****************************************************/

	  /* trapezoidal rule */

	  rmin = Spe_PAO_RV[spe][0];
	  rmax = Spe_Atom_Cut1[spe] + 0.5;

          sum = 0.0;
          h = (rmax - rmin)/(double)OneD_Grid;
          for (i=0; i<=OneD_Grid; i++){

            r = rmin + (double)i*h;
            sj = SphB[GL][i];

            if (i==0 || i==OneD_Grid) 
              sum += 0.5*r*r*RadialF(spe,GL,Mul,r)*sj;
            else
              sum += r*r*RadialF(spe,GL,Mul,r)*sj;
          } 
          sum = sum*h;
          Spe_RF_Bessel[spe][GL][Mul][kj] = sum;
          NormK[kj] = norm_k;

	} /* Mul */
      } /* GL */
    } /* kj */

    /* free SphB and SphBp */

    for(GL=0; GL<(Spe_MaxL_Basis[spe]+3); GL++){ 
      free(SphB[GL]);
    }
    free(SphB);

    for(GL=0; GL<(Spe_MaxL_Basis[spe]+3); GL++){ 
      free(SphBp[GL]);
    }
    free(SphBp);

    free(tmp_SphB);
    free(tmp_SphBp);

  } /* Lspe */

  /****************************************************
          generate radial grids in the k-space
  ****************************************************/

  dk = PAO_Nkmax/(double)Ngrid_NormK;
  for (i=0; i<Ngrid_NormK; i++){
    NormK[i] = (double)i*dk;
  }

  /***********************************************************
        sending and receiving of Spe_RF_Bessel by MPI
  ***********************************************************/

  for (ID=0; ID<Num_Procs2; ID++){
    NumSpe = Species_End[ID] - Species_Top[ID] + 1;
    for (Lspe=0; Lspe<NumSpe; Lspe++){
      spe = Species_Top[ID] + Lspe;
      for (GL=0; GL<=Spe_MaxL_Basis[spe]; GL++){
	for (Mul=0; Mul<Spe_Num_Basis[spe][GL]; Mul++){
	  MPI_Bcast(&Spe_RF_Bessel[spe][GL][Mul][0],
		    List_YOUSO[15],MPI_DOUBLE,ID, mpi_comm_level1);
	}
      }
    }
  }

  /***********************************************************
                         elapsed time
  ***********************************************************/

  dtime(&TEtime);

}