Debian Codegraph @

PHonon/PH/read_wfc_rspace_and_fwfft.f90

raw symbols SCIP
1 !
2 ! This routine reads a wavefunction in real space and transform it in Fourier space
3 !
4 ! Not tested for the non-collinear case.
5 !
6 ! Matteo Calandra
7 !
8 subroutine read_wfc_rspace_and_fwfft( evc , ik , lrec , iunit , npw , igmap )
9 use kinds, ONLY : DP
10 use wvfct, ONLY : npwx, nbnd
11 USE noncollin_module, ONLY : noncolin, npol, nspin_mag
12 USE fft_base, ONLY : dffts
13 USE scatter_mod, ONLY : scatter_grid
14 USE fft_interfaces, ONLY : fwfft
15 USE io_global, ONLY : ionode_id, ionode
16 USE mp_pools, ONLY : inter_pool_comm
17 USE mp, ONLY : mp_bcast
18
19 IMPLICIT NONE
20 INTEGER, INTENT (IN) :: ik ! k-point to read
21 INTEGER, INTENT (IN) :: lrec ! length of the record
22 INTEGER, INTENT (IN) :: npw ! number of plane waves
23 INTEGER, INTENT (IN) :: iunit ! input iunit from where to read
24 INTEGER, INTENT (IN) :: igmap(npwx) ! index for the mapping of the g
25 COMPLEX(DP), INTENT (OUT) :: evc(npol*npwx,nbnd) ! wavefunction in g space
26 ! internal
27 INTEGER :: ibnd, ig, is
28 COMPLEX(DP), ALLOCATABLE :: evc_r(:,:), dist_evc_r(:,:)
29
30 allocate( evc_r( dffts%nnr, npol ) )
31 allocate( dist_evc_r( dffts%nr1x*dffts%nr2x*dffts%nr3x , npol) )
32
33 !
34 ! Fourier transform it in reciprocal space
35 !
36
37 do ibnd=1,nbnd
38 !
39 ! read wfc in real space
40 !
41 #if defined(__MPI)
42 !
43 ! ... First task reads and broadcasts ddrho to all pools
44 !
45
46 IF ( ionode ) &
47 CALL davcio (dist_evc_r, lrec, iunit, (ik-1)*nbnd+ibnd, - 1)
48
49 CALL mp_bcast( dist_evc_r, ionode_id, inter_pool_comm )
50 !
51 ! ... distributes ddrho between between the tasks of the pool
52 !
53 DO is = 1, npol
54 !
55 CALL scatter_grid ( dffts, dist_evc_r(:,is), evc_r(:,is) )
56 !
57 END DO
58 !
59 ! call mp_bcast( evc_r, ionode_id, inter_pool_comm )
60 #else
61 CALL davcio (evc_r, lrec, iunit, (ik-1)*nbnd+ibnd, - 1)
62 #endif
63
64 call fwfft('Wave',evc_r(:,1),dffts)
65 do ig = 1, npw
66 evc (ig,ibnd) = evc_r (dffts%nl (igmap (ig) ), 1 )
67 enddo
68
69 IF (noncolin) THEN
70 CALL fwfft ('Wave', evc_r(:,2), dffts)
71 DO ig = 1, npw
72 evc (ig+npwx,ibnd) = evc_r (dffts%nl(igmap(ig)),2)
73 ENDDO
74 ENDIF
75
76 enddo
77
78 deallocate( evc_r )
79 deallocate( dist_evc_r )
80
81 end subroutine read_wfc_rspace_and_fwfft