pwdft  0.1
PW-DFT code for education
scf Module Reference

Functions/Subroutines

subroutine scf_loop ()
 
subroutine kohn_sham_eq (linit, Fvec)
 
subroutine initialize_wf (psi)
 Initialize wave function with random number. More...
 

Variables

integer, save electron_maxstep
 Max number of iteration. More...
 
real(8), save mixing_beta
 Mixing for SCF. More...
 
real(8), save conv_thr
 Convergence threshold [Htr]. More...
 

Function/Subroutine Documentation

◆ scf_loop()

subroutine scf::scf_loop

Definition at line 36 of file scf.F90.

36  !
37  use gvec, only : g_rh
38  use rho_v, only : vks
39  use constant, only : htr2ev
40  !
41  integer :: istep, jstep
42  logical :: linit
43  real(8) :: alpha, res, &
44  & Fvec0(g_rh%nr), dVks(g_rh%nr), Fvec(g_rh%nr), dFvec(g_rh%nr), &
45  & jacob1(g_rh%nr,2:electron_maxstep), jacob2(g_rh%nr,2:electron_maxstep)
46  !
47  linit = .true.
48  !
49  do istep = 1, electron_maxstep
50  !
51  write(*,*) " Iteration ", istep
52  !
53  call kohn_sham_eq(linit, fvec)
54  linit = .false.
55  res = sqrt(dot_product(fvec(1:g_rh%nr), fvec(1:g_rh%nr))) / dble(g_rh%nr)
56  write(*,*) " delta Vks [eV] : ", res * htr2ev
57  if(res < conv_thr) exit
58  !
59  if(istep > 1) then
60  !
61  ! Update Jacobian with dFvec
62  !
63  dfvec(1:g_rh%nr) = fvec(1:g_rh%nr) - fvec0(1:g_rh%nr)
64  !
65  jacob1(1:g_rh%nr,istep) = mixing_beta * dfvec(1:g_rh%nr) + dvks(1:g_rh%nr)
66  do jstep = 2, istep - 1
67  alpha = dot_product(jacob2(1:g_rh%nr,jstep), dfvec(1:g_rh%nr))
68  jacob1(1:g_rh%nr,istep) = jacob1(1:g_rh%nr,istep) - jacob1(1:g_rh%nr,jstep) * alpha
69  end do
70  !
71  alpha = dot_product(dfvec(1:g_rh%nr), dfvec(1:g_rh%nr))
72  jacob2(1:g_rh%nr,istep) = dfvec(1:g_rh%nr) / alpha
73  !
74  end if
75  !
76  ! Compute dVks with new Jacobian & Fvec
77  !
78  dvks(1:g_rh%nr) = mixing_beta * fvec(1:g_rh%nr)
79  do jstep = 2, istep
80  alpha = dot_product(jacob2(1:g_rh%nr,jstep), fvec(1:g_rh%nr))
81  dvks(1:g_rh%nr) = dvks(1:g_rh%nr) - jacob1(1:g_rh%nr,jstep) * alpha
82  end do
83  fvec0(1:g_rh%nr) = fvec(1:g_rh%nr)
84  !
85  vks(1:g_rh%nr) = vks(1:g_rh%nr) + dvks(1:g_rh%nr)
86  !
87  end do ! istep
88  !
89  if(istep >= electron_maxstep) then
90  write(*,'(/,7x,"Not converged ! res = ",e12.5,/)') res
91  else
92  write(*,'(/,7x,"Converged ! iter = ",i0,/)') istep
93  end if
94  !

References conv_thr, electron_maxstep, gvec::g_rh, constant::htr2ev, kohn_sham_eq(), mixing_beta, and rho_v::vks.

Referenced by pwdft().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kohn_sham_eq()

subroutine scf::kohn_sham_eq ( logical, intent(in)  linit,
real(8), dimension(g_rh%nr), intent(out)  Fvec 
)

Definition at line 100 of file scf.F90.

100  !
101  use gvec, only : g_wf, g_rh
102  use kohn_sham, only : nbnd, eval, evec, calculation
103  use k_point, only : kvec, nk, ksum_rho
104  use rho_v, only : vks, vps, hartree_pot, xc_pot
105  use diag_direct, only : direct
106  use lobpcg, only : lobpcg_main
107  !
108  logical,intent(in) :: linit
109  real(8),intent(out) :: Fvec(g_rh%nr)
110  !
111  integer :: ik, istep, avestep
112  !
113  if(calculation == "direct") then
114  do ik = 1, nk
115  call direct(g_wf%npw,kvec(1:3,ik),evec(1:g_wf%npw,1:nbnd,ik),eval(1:nbnd,ik))
116  end do
117  else
118  avestep = 0
119  if(linit) call initialize_wf(evec(1:g_wf%npw,1:nbnd,1))
120  do ik = 1, nk
121  call lobpcg_main(g_wf%npw, kvec(1:3,ik),&
122  & evec(1:g_wf%npw,1:nbnd,ik),eval(1:nbnd,ik), istep)
123  avestep = avestep + istep
124  if(linit .and. ik /= nk) evec(1:g_wf%npw,1:nbnd,ik+1) &
125  & = evec(1:g_wf%npw,1:nbnd,ik)
126  end do
127  write(*,*) " Average LOBPCG steps : ", avestep / nk
128  end if
129  !
130  if(calculation == "scf") then
131  !
132  call ksum_rho()
133  !
134  fvec(1:g_rh%nr) = vps(1:g_rh%nr)
135  call hartree_pot(fvec)
136  call xc_pot(fvec)
137  !
138  fvec(1:g_rh%nr) = fvec(1:g_rh%nr) - vks(1:g_rh%nr)
139  !
140  else
141  fvec(1:g_rh%nr) = 0.0d0
142  end if
143  !

References kohn_sham::calculation, diag_direct::direct(), kohn_sham::eval, kohn_sham::evec, gvec::g_rh, gvec::g_wf, rho_v::hartree_pot(), initialize_wf(), k_point::ksum_rho(), k_point::kvec, lobpcg::lobpcg_main(), kohn_sham::nbnd, k_point::nk, rho_v::vks, rho_v::vps, and rho_v::xc_pot().

Referenced by pwdft(), and scf_loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize_wf()

subroutine scf::initialize_wf ( complex(8), dimension(g_wf%npw,nbnd), intent(out)  psi)

Initialize wave function with random number.

Definition at line 149 of file scf.F90.

149  !
150  use kohn_sham, only : nbnd
151  use gvec, only : g_wf
152  !
153  complex(8),intent(out) :: psi(g_wf%npw,nbnd)
154  !
155  integer :: ibnd, nseed
156  integer :: seed(256)
157  real(8) :: rpsi(g_wf%npw,nbnd), ipsi(g_wf%npw,nbnd), norm
158  !
159  call random_seed(size=nseed)
160  seed(1:nseed)=2
161  call random_seed(put=seed)
162  call random_number(rpsi)
163  call random_number(ipsi)
164  !
165  psi(1:g_wf%npw,1:nbnd) = cmplx(rpsi(1:g_wf%npw,1:nbnd), &
166  & ipsi(1:g_wf%npw,1:nbnd), 8)
167  !
168  do ibnd = 1, nbnd
169  norm = sqrt(dble(dot_product(psi(1:g_wf%npw,ibnd), psi(1:g_wf%npw,ibnd))))
170  psi(1:g_wf%npw,ibnd) = psi(1:g_wf%npw,ibnd) / norm
171  end do
172  !

References gvec::g_wf, and kohn_sham::nbnd.

Referenced by kohn_sham_eq().

Here is the caller graph for this function:

Variable Documentation

◆ electron_maxstep

integer, save scf::electron_maxstep

Max number of iteration.

Definition at line 27 of file scf.F90.

27  integer,save :: &
28  & electron_maxstep !< Max number of iteration

Referenced by stdin::read_stdin(), and scf_loop().

◆ mixing_beta

real(8), save scf::mixing_beta

Mixing for SCF.

Definition at line 29 of file scf.F90.

29  real(8),save :: &
30  & mixing_beta, & !< Mixing for SCF
31  & conv_thr !< Convergence threshold [Htr]

Referenced by stdin::read_stdin(), and scf_loop().

◆ conv_thr

real(8), save scf::conv_thr

Convergence threshold [Htr].

Definition at line 29 of file scf.F90.

Referenced by stdin::read_stdin(), and scf_loop().

diag_direct
Definition: diag_direct.F90:23
constant
Definition: constant.F90:23
kohn_sham::calculation
character(256), save calculation
Calculation mode.
Definition: kohn_sham.F90:27
rho_v::xc_pot
subroutine xc_pot(Vloc)
Add XC potential (LDA)
Definition: rho_v.F90:175
rho_v
Definition: rho_v.F90:23
rho_v::vps
real(8), dimension(:), allocatable vps
(g_rhnr) Pseudopotential [Htr]
Definition: rho_v.F90:27
k_point
Definition: k_point.F90:23
k_point::ksum_rho
subroutine ksum_rho()
Definition: k_point.F90:35
lobpcg
Definition: lobpcg.F90:23
gvec
Definition: gvec.F90:23
rho_v::vks
real(8), dimension(:), allocatable vks
(g_rhnr) Kohn-Sham potential [Htr]
Definition: rho_v.F90:27
rho_v::hartree_pot
subroutine hartree_pot(Vloc)
Add Hartree potential.
Definition: rho_v.F90:143
lobpcg::lobpcg_main
subroutine lobpcg_main(npw, kvec, evec, eval, istep)
Definition: lobpcg.F90:75
kohn_sham
Definition: kohn_sham.F90:23
diag_direct::direct
subroutine direct(npw, kvec, evec, eval)
Definition: diag_direct.F90:30