2 ! Copyright (C) 2008 S. Suehara. This file is distributed under the terms of the
3 ! GNU Lesser General Public License. See the file COPYING for license details.
8 subroutine mixpulay(iscl
,n
,maxsd
,nu
,mu
,f
,d
)
9 ! !INPUT/OUTPUT PARAMETERS:
10 ! iscl : self-consistent loop number (in,integer)
11 ! n : vector length (in,integer)
12 ! maxsd : maximum subspace dimension (in,integer)
13 ! nu : current output vector as well as the next input vector of the
14 ! self-consistent loop (inout,real(n))
15 ! mu : used internally (inout,real(n,maxsd))
16 ! f : used internally (inout,real(n,maxsd))
17 ! d : RMS difference between old and new output vectors (out,real)
19 ! Pulay's mixing scheme which uses direct inversion in the iterative subspace
20 ! (DIIS). See {\it Chem. Phys. Lett.} {\bf 73}, 393 (1980).
23 ! Created October 2008 (S. Suehara, NIMS)
24 ! Modified, October 2008 (JKD)
29 integer, intent(in
) :: iscl
30 integer, intent(in
) :: n
31 integer, intent(in
) :: maxsd
32 real(8), intent(inout
) :: nu(n
)
33 real(8), intent(inout
) :: mu(n
,maxsd
)
34 real(8), intent(inout
) :: f(n
,maxsd
)
35 real(8), intent(out
) :: d
37 integer i
,j
,k
,m
,jc
,jn
,info
38 ! initial mixing parameter
39 real(8), parameter :: beta
=0.1d0
41 integer, allocatable
:: ipiv(:)
42 real(8), allocatable
:: alpha(:),a(:,:),work(:)
48 write(*,'("Error(mixpulay): n < 1 : ",I8)') n
54 write(*,'("Error(mixpulay): maxsd < 2 : ",I8)') maxsd
65 jc
=mod(iscl
-1,maxsd
)+1
69 nu(:)=beta
*nu(:)+(1.d0
-beta
)*mu(:,1)
72 if (maxsd
.ge
.3) mu(:,3)=0.d0
82 allocate(ipiv(m
),alpha(m
),a(m
,m
),work(m
))
83 ! compute f and RMS difference
86 f(k
,jc
)=nu(k
)-mu(k
,jc
)
90 ! solve the linear system
94 a(i
,j
)=a(i
,j
)+ddot(n
,f(:,i
),1,f(:,j
),1)
100 call dsysv('U',m
,1,a
,m
,ipiv
,alpha
,m
,work
,m
,info
)
103 write(*,'("Error(mixpulay): could not solve linear system")')
104 write(*,'(" DSYSV returned INFO = ",I8)') info
110 nu(:)=nu(:)+alpha(i
)*(mu(:,i
)+f(:,i
))
113 deallocate(ipiv
,alpha
,a
,work
)