root / src / Hupdate_Bofill.f90 @ 3
Historique | Voir | Annoter | Télécharger (3,05 ko)
| 1 |
! This program reads an old hessian, old forces, new forces |
|---|---|
| 2 |
! and print the updated hessian and old coordinates. |
| 3 |
! Instead of the Murtagh-Sargent update, we use the Bofill update |
| 4 |
! which is an average of Murtagh-Sargent and Powell-symmetryc-Broyden |
| 5 |
! cf JCP 1999, vol 111 (19), p 8773 |
| 6 |
|
| 7 |
! This subroutine slightly differs from previous ones as |
| 8 |
! it is written with the Gradient as input and not the forces |
| 9 |
! Using the relation F=-Grad, one can easily go from older |
| 10 |
! versions to this one (which more closely mimics the JCP article) |
| 11 |
|
| 12 |
SUBROUTINE Hupdate_Bofill(Nfree,ds,dgrad,Hess) |
| 13 |
|
| 14 |
IMPLICIT NONE |
| 15 |
|
| 16 |
INTEGER, PARAMETER :: KINT=KIND(1) |
| 17 |
INTEGER, PARAMETER :: KREAL=KIND(1.D0) |
| 18 |
|
| 19 |
INTEGER(KINT), INTENT(IN) :: NFREE |
| 20 |
REAL(KREAL), INTENT(INOUT) :: Hess(Nfree,Nfree) |
| 21 |
REAL(KREAL), INTENT(IN) :: ds(Nfree) |
| 22 |
REAL(KREAL), INTENT(IN) :: dGrad(Nfree) |
| 23 |
|
| 24 |
|
| 25 |
REAL(KREAL), ALLOCATABLE :: HessOld(:,:) , HupMS(:,:) |
| 26 |
REAL(KREAL), ALLOCATABLE :: HupPSB(:,:), Hup(:,:) |
| 27 |
REAL(KREAL), ALLOCATABLE :: HupInt(:) |
| 28 |
REAL(KREAL), ALLOCATABLE :: HS(:), Num(:,:), Num2(:,:) |
| 29 |
REAL(KREAL) :: Phi, Num3, Den, Den2,NormDS |
| 30 |
INTEGER(KINT) :: i,j, idx |
| 31 |
|
| 32 |
LOGICAL debug,valid |
| 33 |
EXTERNAL valid |
| 34 |
|
| 35 |
debug=valid("Hupdate").OR.Valid("Hupdate_bofill")
|
| 36 |
|
| 37 |
if (debug) WRITE(*,*) "=========================== Entering Hupdate_Bofill ====================" |
| 38 |
|
| 39 |
ALLOCATE(HessOld(nfree,nfree), HupMS(nfree,nfree), & |
| 40 |
HupPSB(nfree,nfree), Hup(nfree,nfree), & |
| 41 |
HupInt(nfree), HS(nfree), & |
| 42 |
Num(nfree,nfree), Num2(nfree,nfree) ) |
| 43 |
|
| 44 |
HessOld=Hess |
| 45 |
|
| 46 |
if (debug) THEN |
| 47 |
WRITE(*,*) 'DBG Hupdate HessOld' |
| 48 |
Idx=min(12,Nfree) |
| 49 |
DO I=1,NFree |
| 50 |
WRITE(*,'(12(1X,F8.4))') HessOld(I,1:Idx) |
| 51 |
END DO |
| 52 |
WRITE(*,*) 'DBG Hupdate ds' |
| 53 |
WRITE(*,'(12(1X,F8.4))') ds(1:Idx) |
| 54 |
WRITE(*,*) 'DBG Hupdate dGrad' |
| 55 |
WRITE(*,'(12(1X,F8.4))') dGrad(1:Idx) |
| 56 |
END IF |
| 57 |
|
| 58 |
NormDS=sqrt(DOT_PRODUCT(DS,DS)) |
| 59 |
if (NormDS>=1e-6) THEN |
| 60 |
|
| 61 |
HS=0 |
| 62 |
DO I=1,nfree |
| 63 |
DO J=1,nfree |
| 64 |
HS(I)=HS(I)+HessOld(i,j)*Ds(j) |
| 65 |
END DO |
| 66 |
END DO |
| 67 |
HupInt=DGrad-HS |
| 68 |
|
| 69 |
! WE calculate the MS update |
| 70 |
Num=0. |
| 71 |
Den=0. |
| 72 |
DO I=1,nfree |
| 73 |
DO J=1,nfree |
| 74 |
Num(I,J)=HUpInt(i)*HupInt(j) |
| 75 |
END DO |
| 76 |
Den=Den+Hupint(i)*Ds(i) |
| 77 |
END DO |
| 78 |
|
| 79 |
HupMS=Num/Den |
| 80 |
|
| 81 |
! Now we calculate the PSB update |
| 82 |
Num=0 |
| 83 |
Num2=0 |
| 84 |
Num3=0 |
| 85 |
Den=0 |
| 86 |
DO I=1,nfree |
| 87 |
DO J=1,nfree |
| 88 |
Num(I,J)=HUpInt(i)*Ds(j)+Ds(i)*HupInt(j) |
| 89 |
Num2(I,J)=DS(i)*DS(j) |
| 90 |
END DO |
| 91 |
Den=Den+Ds(i)*Ds(i) |
| 92 |
Num3=Num3+DS(i)*HupInt(i) |
| 93 |
END DO |
| 94 |
HupPSB=Num/Den-Num3*Num2/(Den)**2 |
| 95 |
|
| 96 |
! We calculate Phi |
| 97 |
Den2=0. |
| 98 |
Do I=1,nfree |
| 99 |
Den2=Den2+HupInt(i)*HupInt(i) |
| 100 |
END DO |
| 101 |
Phi=Num3**2/(Den*Den2) |
| 102 |
|
| 103 |
Hup=Phi*HupMS+(1-Phi)*HupPSB |
| 104 |
|
| 105 |
Hess=HessOld+Hup |
| 106 |
ELSE |
| 107 |
Hess=HessOld |
| 108 |
END IF |
| 109 |
! WRITE(*,*) 'New hess' |
| 110 |
! DO I=1,nfree |
| 111 |
! WRITE(*,fmt) Hess(i,:) |
| 112 |
! END DO |
| 113 |
|
| 114 |
DEALLOCATE(HessOld, HupMS, HupPSB, Hup, & |
| 115 |
HupInt, HS, Num, Num2 ) |
| 116 |
|
| 117 |
if (debug) WRITE(*,*) "=========================== Hupdate Over ====================" |
| 118 |
|
| 119 |
END SUBROUTINE Hupdate_Bofill |