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