root / src / Step_DIIS_all.f90 @ 3
Historique | Voir | Annoter | Télécharger (16,33 ko)
| 1 | 1 | pfleura2 | !C HEAT is never used, not even in call of Space(...) |
|---|---|---|---|
| 2 | 1 | pfleura2 | !C Geom = input parameter vector (Geometry). |
| 3 | 1 | pfleura2 | !C Grad = input gradient vector. |
| 4 | 1 | pfleura2 | !C Geom_new = New Geometry. |
| 5 | 1 | pfleura2 | |
| 6 | 1 | pfleura2 | SUBROUTINE Step_diis_all(NGeomF,IGeom,Step,Geom,Grad,HP,HEAT,Hess,NCoord,allocation_flag,Tangent) |
| 7 | 1 | pfleura2 | ! IMPLICIT DOUBLE PRECISION (A-H,O-Z) |
| 8 | 1 | pfleura2 | |
| 9 | 1 | pfleura2 | USE Io_module, only : IoOut |
| 10 | 1 | pfleura2 | USE Path_module, only : Vfree |
| 11 | 1 | pfleura2 | |
| 12 | 1 | pfleura2 | IMPLICIT NONE |
| 13 | 1 | pfleura2 | INTEGER, parameter :: KINT = kind(1) |
| 14 | 1 | pfleura2 | INTEGER, parameter :: KREAL = kind(1.0d0) |
| 15 | 1 | pfleura2 | |
| 16 | 1 | pfleura2 | ! INCLUDE 'SIZES' |
| 17 | 1 | pfleura2 | |
| 18 | 1 | pfleura2 | INTEGER(KINT) :: NGeomF,IGeom |
| 19 | 1 | pfleura2 | INTEGER(KINT), INTENT(IN) :: NCoord |
| 20 | 1 | pfleura2 | |
| 21 | 2 | pfleura2 | REAL(KREAL) :: Geom(NCoord), Grad(NCoord) |
| 22 | 1 | pfleura2 | REAL(KREAL) :: Hess(NCoord*NCoord),Step(NCoord) |
| 23 | 1 | pfleura2 | REAL(KREAL) :: HEAT,HP |
| 24 | 1 | pfleura2 | LOGICAL :: allocation_flag |
| 25 | 1 | pfleura2 | REAL(KREAL), INTENT(INOUT) :: Tangent(Ncoord) |
| 26 | 1 | pfleura2 | |
| 27 | 1 | pfleura2 | !************************************************************************ |
| 28 | 1 | pfleura2 | !* * |
| 29 | 1 | pfleura2 | !* DIIS PERFORMS DIRECT INVERSION IN THE ITERATIVE SUBSPACE * |
| 30 | 1 | pfleura2 | !* * |
| 31 | 1 | pfleura2 | !* THIS INVOLVES SOLVING FOR C IN Geom(NEW) = Geom' - HG' * |
| 32 | 1 | pfleura2 | !* * |
| 33 | 1 | pfleura2 | !* WHERE Geom' = SUM(C(I)Geom(I), THE C COEFFICIENTES COMING FROM * |
| 34 | 1 | pfleura2 | !* * |
| 35 | 1 | pfleura2 | !* | B 1 | . | C | = | 0 | * |
| 36 | 1 | pfleura2 | !* | 1 0 | |-L | | 1 | * |
| 37 | 1 | pfleura2 | !* * |
| 38 | 1 | pfleura2 | !* WHERE B(I,J) =GRAD(I)H(T)HGRAD(J) GRAD(I) = GRADIENT ON CYCLE I * |
| 39 | 1 | pfleura2 | !* Hess = INVERSE HESSIAN * |
| 40 | 1 | pfleura2 | !* * |
| 41 | 1 | pfleura2 | !* REFERENCE * |
| 42 | 1 | pfleura2 | !* * |
| 43 | 1 | pfleura2 | !* P. CSASZAR, P. PULAY, J. MOL. STRUCT. (THEOCHEM), 114, 31 (1984) * |
| 44 | 1 | pfleura2 | !* * |
| 45 | 1 | pfleura2 | !************************************************************************ |
| 46 | 1 | pfleura2 | !************************************************************************ |
| 47 | 1 | pfleura2 | !* * |
| 48 | 1 | pfleura2 | !* GEOMETRY OPTIMIZATION USING THE METHOD OF DIRECT INVERSION IN * |
| 49 | 1 | pfleura2 | !* THE ITERATIVE SUBSPACE (GDIIS), COMBINED WITH THE BFGS OPTIMIZER * |
| 50 | 1 | pfleura2 | !* (A VARIABLE METRIC METHOD) * |
| 51 | 1 | pfleura2 | !* * |
| 52 | 1 | pfleura2 | !* WRITTEN BY PETER L. CUMMINS, UNIVERSITY OF SYDNEY, AUSTRALIA * |
| 53 | 1 | pfleura2 | !* * |
| 54 | 1 | pfleura2 | !* REFERENCE * |
| 55 | 1 | pfleura2 | !* * |
| 56 | 1 | pfleura2 | !* "COMPUTATIONAL STRATEGIES FOR THE OPTIMIZATION OF EQUILIBRIUM * |
| 57 | 1 | pfleura2 | !* GEOMETRIES AND TRANSITION-STATE STRUCTURES AT THE SEMIEMPIRICAL * |
| 58 | 1 | pfleura2 | !* LEVEL", PETER L. CUMMINS, JILL E. GREADY, J. COMP. CHEM., 10, * |
| 59 | 1 | pfleura2 | !* 939-950 (1989). * |
| 60 | 1 | pfleura2 | !* * |
| 61 | 1 | pfleura2 | !* MODIFIED BY JJPS TO CONFORM TO EXISTING MOPAC CONVENTIONS * |
| 62 | 1 | pfleura2 | !* * |
| 63 | 1 | pfleura2 | !************************************************************************ |
| 64 | 1 | pfleura2 | |
| 65 | 1 | pfleura2 | ! MRESET = maximum number of iterations. |
| 66 | 1 | pfleura2 | INTEGER(KINT), PARAMETER :: MRESET=15, M2=(MRESET+1)*(MRESET+1) !M2 = 256 |
| 67 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE, SAVE :: GeomSet(:,:),GradSet(:,:),ERR(:,:) ! MRESET*NCoord |
| 68 | 1 | pfleura2 | REAL(KREAL), SAVE :: ESET(MRESET) |
| 69 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE, SAVE :: DXTMP(:,:),GSAVE(:,:) !NCoord, why DXTMP has SAVE attribute?? |
| 70 | 2 | pfleura2 | REAL(KREAL) :: B(M2), BS(M2) |
| 71 | 1 | pfleura2 | LOGICAL DEBUG, PRINT |
| 72 | 1 | pfleura2 | INTEGER(KINT), ALLOCATABLE, SAVE :: MSET(:) |
| 73 | 1 | pfleura2 | LOGICAL, ALLOCATABLE, SAVE :: FRST(:) |
| 74 | 1 | pfleura2 | INTEGER(KINT) :: NDIIS, MPLUS, INV, ITERA, MM, NFree, I, J, K |
| 75 | 1 | pfleura2 | INTEGER(KINT) :: JJ, KJ, JNV, II, IONE, IJ, INK,ITmp, Isch, Idx |
| 76 | 1 | pfleura2 | REAL(KREAL) :: XMax, XNorm, S, DET, THRES, Norm |
| 77 | 1 | pfleura2 | REAL(KREAL), PARAMETER :: eps=1e-12 |
| 78 | 1 | pfleura2 | REAL(KREAL), PARAMETER :: crit=1e-8 |
| 79 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: Tanf(:) ! NCoord |
| 80 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: HFree(:) ! NFree*NFree |
| 81 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: Htmp(:,:) ! NCoord,NFree |
| 82 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: Grad_free(:),Grad_new_free_inter(:),Step_free(:) ! NFree |
| 83 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: Geom_free(:),Geom_new_free_inter(:),Geom_new_free(:) ! NFree |
| 84 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE, SAVE :: GeomSet_free(:,:),GradSet_free(:,:) |
| 85 | 1 | pfleura2 | |
| 86 | 1 | pfleura2 | DEBUG=.TRUE. |
| 87 | 1 | pfleura2 | PRINT=.TRUE. |
| 88 | 1 | pfleura2 | |
| 89 | 1 | pfleura2 | IF (PRINT) WRITE(*,'(/,'' BEGIN GDIIS '')') |
| 90 | 1 | pfleura2 | |
| 91 | 1 | pfleura2 | ! Initialization |
| 92 | 1 | pfleura2 | IF (allocation_flag) THEN ! allocation_flag = .TRUE. at the begining and effective for all geometries in path. |
| 93 | 1 | pfleura2 | ! FRST(IGeom) will be set to False in Space, so no need to modify it here |
| 94 | 1 | pfleura2 | IF (ALLOCATED(GeomSet)) THEN |
| 95 | 1 | pfleura2 | IF (PRINT) WRITE(*,'(/,'' In FRST, GDIIS Dealloc '')') |
| 96 | 1 | pfleura2 | DEALLOCATE(GeomSet,GradSet,ERR,DXTMP,GSave,GeomSet_free,GradSet_free) |
| 97 | 1 | pfleura2 | RETURN |
| 98 | 1 | pfleura2 | ELSE |
| 99 | 1 | pfleura2 | ! these allocated arrays need to be properly deallocated. |
| 100 | 1 | pfleura2 | IF (PRINT) WRITE(*,'(/,'' In FRST, GDIIS Alloc '')') |
| 101 | 1 | pfleura2 | ALLOCATE(GeomSet(NGeomF,MRESET*NCoord),GradSet(NGeomF,MRESET*NCoord),ERR(NGeomF,MRESET*NCoord)) |
| 102 | 1 | pfleura2 | ALLOCATE(GeomSet_free(NGeomF,MRESET*NCoord),GradSet_free(NGeomF,MRESET*NCoord)) |
| 103 | 1 | pfleura2 | ALLOCATE(DXTMP(NGeomF,NCoord),GSAVE(NGeomF,NCoord),MSET(NGeomF),FRST(NGeomF)) |
| 104 | 1 | pfleura2 | DO I=1,NGeomF |
| 105 | 1 | pfleura2 | FRST(I) = .TRUE. |
| 106 | 1 | pfleura2 | GeomSet(I,:) = 0.d0 |
| 107 | 1 | pfleura2 | GradSet(I,:) = 0.d0 |
| 108 | 1 | pfleura2 | ERR(I,:) = 0.d0 |
| 109 | 1 | pfleura2 | GeomSet_free(I,:) = 0.d0 |
| 110 | 1 | pfleura2 | GradSet_free(I,:) = 0.d0 |
| 111 | 1 | pfleura2 | DXTMP(I,:)=0.d0 |
| 112 | 1 | pfleura2 | GSAVE(I,:)=0.d0 |
| 113 | 1 | pfleura2 | END DO |
| 114 | 1 | pfleura2 | MSET(:)=0 |
| 115 | 1 | pfleura2 | END IF |
| 116 | 1 | pfleura2 | allocation_flag = .FALSE. |
| 117 | 1 | pfleura2 | END IF |
| 118 | 1 | pfleura2 | |
| 119 | 1 | pfleura2 | ! Addded from here: |
| 120 | 1 | pfleura2 | Call FreeMv(NCoord,Vfree) ! VFree(Ncoord,Ncoord) |
| 121 | 1 | pfleura2 | ! we orthogonalize Vfree to the tangent vector of this geom only if Tangent/=0.d0 |
| 122 | 1 | pfleura2 | Norm=sqrt(dot_product(Tangent,Tangent)) |
| 123 | 1 | pfleura2 | IF (Norm.GT.eps) THEN |
| 124 | 1 | pfleura2 | ALLOCATE(Tanf(NCoord)) |
| 125 | 1 | pfleura2 | |
| 126 | 1 | pfleura2 | ! We normalize Tangent |
| 127 | 1 | pfleura2 | Tangent=Tangent/Norm |
| 128 | 1 | pfleura2 | |
| 129 | 1 | pfleura2 | ! We convert Tangent into Vfree only displacements. This is useless for now (2007.Apr.23) |
| 130 | 1 | pfleura2 | ! as Vfree=Id matrix but it will be usefull as soon as we introduce constraints. |
| 131 | 1 | pfleura2 | DO I=1,NCoord |
| 132 | 1 | pfleura2 | Tanf(I)=dot_product(reshape(Vfree(:,I),(/NCoord/)),Tangent) |
| 133 | 1 | pfleura2 | END DO |
| 134 | 1 | pfleura2 | Tangent=0.d0 |
| 135 | 1 | pfleura2 | DO I=1,NCoord |
| 136 | 1 | pfleura2 | Tangent=Tangent+Tanf(I)*Vfree(:,I) |
| 137 | 1 | pfleura2 | END DO |
| 138 | 1 | pfleura2 | ! first we subtract Tangent from vfree |
| 139 | 1 | pfleura2 | DO I=1,NCoord |
| 140 | 1 | pfleura2 | Norm=dot_product(reshape(vfree(:,I),(/NCoord/)),Tangent) |
| 141 | 1 | pfleura2 | Vfree(:,I)=Vfree(:,I)-Norm*Tangent |
| 142 | 1 | pfleura2 | END DO |
| 143 | 1 | pfleura2 | |
| 144 | 1 | pfleura2 | Idx=0. |
| 145 | 1 | pfleura2 | ! Schmidt orthogonalization of the Vfree vectors |
| 146 | 1 | pfleura2 | DO I=1,NCoord |
| 147 | 1 | pfleura2 | ! We subtract the first vectors, we do it twice as the Schmidt procedure is not numerically stable. |
| 148 | 1 | pfleura2 | DO Isch=1,2 |
| 149 | 1 | pfleura2 | DO J=1,Idx |
| 150 | 1 | pfleura2 | Norm=dot_product(reshape(Vfree(:,I),(/NCoord/)),reshape(Vfree(:,J),(/NCoord/))) |
| 151 | 1 | pfleura2 | Vfree(:,I)=Vfree(:,I)-Norm*Vfree(:,J) |
| 152 | 1 | pfleura2 | END DO |
| 153 | 1 | pfleura2 | END DO |
| 154 | 1 | pfleura2 | Norm=dot_product(reshape(Vfree(:,I),(/NCoord/)),reshape(Vfree(:,I),(/NCoord/))) |
| 155 | 1 | pfleura2 | IF (Norm.GE.crit) THEN |
| 156 | 1 | pfleura2 | Idx=Idx+1 |
| 157 | 1 | pfleura2 | Vfree(:,Idx)=Vfree(:,I)/sqrt(Norm) |
| 158 | 1 | pfleura2 | END IF |
| 159 | 1 | pfleura2 | END DO |
| 160 | 1 | pfleura2 | |
| 161 | 1 | pfleura2 | Print *, 'Idx=', Idx |
| 162 | 1 | pfleura2 | IF (Idx/= NCoord-1) THEN |
| 163 | 1 | pfleura2 | WRITE(*,*) "Pb in orthogonalizing Vfree to tangent for geom",IGeom |
| 164 | 1 | pfleura2 | WRITE(IoOut,*) "Pb in orthogonalizing Vfree to tangent for geom",IGeom |
| 165 | 1 | pfleura2 | STOP |
| 166 | 1 | pfleura2 | END IF |
| 167 | 1 | pfleura2 | |
| 168 | 1 | pfleura2 | DEALLOCATE(Tanf) |
| 169 | 1 | pfleura2 | NFree=Idx |
| 170 | 1 | pfleura2 | ELSE ! Tangent =0, matches IF (Norm.GT.eps) THEN |
| 171 | 1 | pfleura2 | if (debug) WRITE(*,*) "Tangent=0, using full displacement" |
| 172 | 1 | pfleura2 | NFree=NCoord |
| 173 | 1 | pfleura2 | END IF !IF (Norm.GT.eps) THEN |
| 174 | 1 | pfleura2 | |
| 175 | 1 | pfleura2 | if (debug) WRITE(*,*) 'DBG Step_DIIS_All, IGeom, NFree=', IGeom, NFree |
| 176 | 1 | pfleura2 | |
| 177 | 1 | pfleura2 | ! We now calculate the new step |
| 178 | 1 | pfleura2 | ! we project the hessian onto the free vectors |
| 179 | 1 | pfleura2 | ALLOCATE(HFree(NFree*NFree),Htmp(NCoord,NFree),Grad_free(NFree),Grad_new_free_inter(NFree)) |
| 180 | 1 | pfleura2 | ALLOCATE(Geom_free(NFree),Step_free(NFree),Geom_new_free_inter(NFree),Geom_new_free(NFree)) |
| 181 | 1 | pfleura2 | DO J=1,NFree |
| 182 | 1 | pfleura2 | DO I=1,NCoord |
| 183 | 1 | pfleura2 | Htmp(I,J)=0.d0 |
| 184 | 1 | pfleura2 | DO K=1,NCoord |
| 185 | 1 | pfleura2 | Htmp(I,J)=Htmp(I,J)+Hess(((I-1)*NCoord)+K)*Vfree(K,J) |
| 186 | 1 | pfleura2 | END DO |
| 187 | 1 | pfleura2 | END DO |
| 188 | 1 | pfleura2 | END DO |
| 189 | 1 | pfleura2 | DO J=1,NFree |
| 190 | 1 | pfleura2 | DO I=1,NFree |
| 191 | 1 | pfleura2 | HFree(I+((J-1)*NFree))=0.d0 |
| 192 | 1 | pfleura2 | DO K=1,NCoord |
| 193 | 1 | pfleura2 | HFree(I+((J-1)*NFree))=HFree(I+((J-1)*NFree))+Vfree(K,I)*Htmp(K,J) |
| 194 | 1 | pfleura2 | END DO |
| 195 | 1 | pfleura2 | END DO |
| 196 | 1 | pfleura2 | END DO |
| 197 | 1 | pfleura2 | |
| 198 | 1 | pfleura2 | DO I=1,NFree |
| 199 | 1 | pfleura2 | Grad_free(I)=dot_product(reshape(Vfree(:,I),(/NCoord/)),Grad) |
| 200 | 1 | pfleura2 | Geom_free(I)=dot_product(reshape(Vfree(:,I),(/NCoord/)),Geom) |
| 201 | 1 | pfleura2 | END DO |
| 202 | 1 | pfleura2 | !Added Ends here.*********************************************** |
| 203 | 1 | pfleura2 | |
| 204 | 1 | pfleura2 | !C SPACE SIMPLY LOADS THE CURRENT VALUES OF Geom AND GRAD INTO |
| 205 | 1 | pfleura2 | !C THE ARRAYS GeomSet AND GradSet |
| 206 | 1 | pfleura2 | !C HEAT is never used, not even in Space_all(...) |
| 207 | 1 | pfleura2 | |
| 208 | 1 | pfleura2 | CALL Space_all(NGeomF,IGeom,MRESET,MSET,Geom,Grad,HEAT,NCoord,GeomSet,GradSet,ESET,FRST) |
| 209 | 1 | pfleura2 | |
| 210 | 1 | pfleura2 | IF (PRINT) WRITE(*,'(/,'' GDIIS after Space '')') |
| 211 | 1 | pfleura2 | |
| 212 | 1 | pfleura2 | DO J=1,MSet(IGeom) |
| 213 | 1 | pfleura2 | DO K=1,NFree |
| 214 | 1 | pfleura2 | GradSet_free(IGeom,((J-1)*NFree)+K)=dot_product(reshape(Vfree(:,K),(/NCoord/)),& |
| 215 | 1 | pfleura2 | GradSet(IGeom,((J-1)*NCoord)+1:((J-1)*NCoord)+NCoord)) |
| 216 | 1 | pfleura2 | GeomSet_free(IGeom,((J-1)*NFree)+K)=dot_product(reshape(Vfree(:,K),(/NCoord/)),& |
| 217 | 1 | pfleura2 | GeomSet(IGeom,((J-1)*NCoord)+1:((J-1)*NCoord)+NCoord)) |
| 218 | 1 | pfleura2 | END DO |
| 219 | 1 | pfleura2 | END DO |
| 220 | 1 | pfleura2 | !C |
| 221 | 1 | pfleura2 | !C INITIALIZE SOME VARIABLES AND CONSTANTS |
| 222 | 1 | pfleura2 | !C |
| 223 | 1 | pfleura2 | NDIIS = MSET(IGeom) |
| 224 | 1 | pfleura2 | MPLUS = MSET(IGeom) + 1 |
| 225 | 1 | pfleura2 | MM = MPLUS * MPLUS |
| 226 | 1 | pfleura2 | !C |
| 227 | 1 | pfleura2 | !C COMPUTE THE APPROXIMATE ERROR VECTORS |
| 228 | 1 | pfleura2 | !C |
| 229 | 1 | pfleura2 | INV=-NFree |
| 230 | 1 | pfleura2 | DO 30 I=1,MSET(IGeom) |
| 231 | 1 | pfleura2 | INV = INV + NFree |
| 232 | 1 | pfleura2 | DO 30 J=1,NFree |
| 233 | 1 | pfleura2 | S = 0.D0 |
| 234 | 1 | pfleura2 | KJ=(J*(J-1))/2 |
| 235 | 1 | pfleura2 | DO 10 K=1,J |
| 236 | 1 | pfleura2 | KJ = KJ+1 |
| 237 | 1 | pfleura2 | 10 S = S - HFree(KJ) * GradSet_free(IGeom,INV+K) |
| 238 | 1 | pfleura2 | DO 20 K=J+1,NFree |
| 239 | 1 | pfleura2 | KJ = (K*(K-1))/2+J |
| 240 | 1 | pfleura2 | 20 S = S - HFree(KJ) * GradSet_free(IGeom,INV+K) |
| 241 | 1 | pfleura2 | 30 ERR(IGeom,INV+J) = S |
| 242 | 1 | pfleura2 | |
| 243 | 1 | pfleura2 | !C |
| 244 | 1 | pfleura2 | !C CONSTRUCT THE GDIIS MATRIX |
| 245 | 1 | pfleura2 | !C |
| 246 | 1 | pfleura2 | DO 40 I=1,MM |
| 247 | 1 | pfleura2 | 40 B(I) = 1.D0 |
| 248 | 1 | pfleura2 | |
| 249 | 1 | pfleura2 | JJ=0 |
| 250 | 1 | pfleura2 | INV=-NFree |
| 251 | 1 | pfleura2 | DO 50 I=1,MSET(IGeom) |
| 252 | 1 | pfleura2 | INV=INV+NFree |
| 253 | 1 | pfleura2 | JNV=-NFree |
| 254 | 1 | pfleura2 | DO 50 J=1,MSET(IGeom) |
| 255 | 1 | pfleura2 | JNV=JNV+NFree |
| 256 | 1 | pfleura2 | JJ = JJ + 1 |
| 257 | 1 | pfleura2 | B(JJ)=0.D0 |
| 258 | 1 | pfleura2 | DO 50 K=1,NFree |
| 259 | 1 | pfleura2 | !Print *, 'B(',JJ,')=', B(JJ) + ERR(IGeom,INV+K) * ERR(IGeom,JNV+K)
|
| 260 | 1 | pfleura2 | 50 B(JJ) = B(JJ) + ERR(IGeom,INV+K) * ERR(IGeom,JNV+K) |
| 261 | 1 | pfleura2 | |
| 262 | 1 | pfleura2 | ! The following shifting is required to correct indices of B_ij elements in the GDIIS matrix. |
| 263 | 1 | pfleura2 | ! The correction is needed because the last coloumn of the matrix contains all 1 and one zero. |
| 264 | 1 | pfleura2 | DO 60 I=MSET(IGeom)-1,1,-1 |
| 265 | 1 | pfleura2 | DO 60 J=MSET(IGeom),1,-1 |
| 266 | 1 | pfleura2 | 60 B(I*MSET(IGeom)+J+I) = B(I*MSET(IGeom)+J) |
| 267 | 1 | pfleura2 | |
| 268 | 1 | pfleura2 | ! For the last row and last column of GEDIIS matrix: |
| 269 | 1 | pfleura2 | DO 70 I=1,MPLUS |
| 270 | 1 | pfleura2 | B(MPLUS*I) = 1.D0 |
| 271 | 1 | pfleura2 | 70 B(MPLUS*MSET(IGeom)+I) = 1.D0 |
| 272 | 1 | pfleura2 | B(MM) = 0.D0 |
| 273 | 1 | pfleura2 | !C |
| 274 | 1 | pfleura2 | !C ELIMINATE ERROR VECTORS WITH THE LARGEST NORM |
| 275 | 1 | pfleura2 | !C |
| 276 | 1 | pfleura2 | 80 CONTINUE |
| 277 | 1 | pfleura2 | DO 90 I=1,MM |
| 278 | 1 | pfleura2 | 90 BS(I) = B(I) |
| 279 | 1 | pfleura2 | |
| 280 | 1 | pfleura2 | IF (NDIIS .EQ. MSET(IGeom)) GO TO 140 |
| 281 | 1 | pfleura2 | DO 130 II=1,MSET(IGeom)-NDIIS |
| 282 | 1 | pfleura2 | XMAX = -1.D10 |
| 283 | 1 | pfleura2 | ITERA = 0 |
| 284 | 1 | pfleura2 | DO 110 I=1,MSET(IGeom) |
| 285 | 1 | pfleura2 | XNORM = 0.D0 |
| 286 | 1 | pfleura2 | INV = (I-1) * MPLUS |
| 287 | 1 | pfleura2 | DO 100 J=1,MSET(IGeom) |
| 288 | 1 | pfleura2 | 100 XNORM = XNORM + ABS(B(INV + J)) |
| 289 | 1 | pfleura2 | IF (XMAX.LT.XNORM .AND. XNORM.NE.1.0D0) THEN |
| 290 | 1 | pfleura2 | XMAX = XNORM |
| 291 | 1 | pfleura2 | ITERA = I |
| 292 | 1 | pfleura2 | IONE = INV + I |
| 293 | 1 | pfleura2 | ENDIF |
| 294 | 1 | pfleura2 | 110 CONTINUE |
| 295 | 1 | pfleura2 | |
| 296 | 1 | pfleura2 | DO 120 I=1,MPLUS |
| 297 | 1 | pfleura2 | INV = (I-1) * MPLUS |
| 298 | 1 | pfleura2 | DO 120 J=1,MPLUS |
| 299 | 1 | pfleura2 | JNV = (J-1) * MPLUS |
| 300 | 1 | pfleura2 | IF (J.EQ.ITERA) B(INV + J) = 0.D0 |
| 301 | 1 | pfleura2 | B(JNV + I) = B(INV + J) |
| 302 | 1 | pfleura2 | !Print *,'B(JNV + I)=',B(JNV + I) |
| 303 | 1 | pfleura2 | 120 CONTINUE |
| 304 | 1 | pfleura2 | B(IONE) = 1.0D0 |
| 305 | 1 | pfleura2 | 130 CONTINUE |
| 306 | 1 | pfleura2 | 140 CONTINUE |
| 307 | 1 | pfleura2 | !C |
| 308 | 1 | pfleura2 | !C OUTPUT THE GDIIS MATRIX |
| 309 | 1 | pfleura2 | !C |
| 310 | 1 | pfleura2 | IF (DEBUG) THEN |
| 311 | 1 | pfleura2 | WRITE(*,'(/5X,'' GDIIS MATRIX'')') |
| 312 | 1 | pfleura2 | ITmp=min(12,MPLUS) |
| 313 | 1 | pfleura2 | DO IJ=1,MPLUS |
| 314 | 1 | pfleura2 | WRITE(*,'(12(F12.4,1X))') B((IJ-1)*MPLUS+1:(IJ-1)*MPLUS+ITmp) |
| 315 | 1 | pfleura2 | END DO |
| 316 | 1 | pfleura2 | ENDIF |
| 317 | 1 | pfleura2 | !C |
| 318 | 1 | pfleura2 | !C SCALE DIIS MATRIX BEFORE INVERSION |
| 319 | 1 | pfleura2 | !C |
| 320 | 1 | pfleura2 | DO 160 I=1,MPLUS |
| 321 | 1 | pfleura2 | II = MPLUS * (I-1) + I |
| 322 | 1 | pfleura2 | !Print *, 'B(',II,')=', B(II)
|
| 323 | 1 | pfleura2 | !Print *, 'GSave(',IGeom,',',I,')=', 1.D0 / DSQRT(1.D-20+DABS(B(II)))
|
| 324 | 1 | pfleura2 | 160 GSAVE(IGeom,I) = 1.D0 / DSQRT(1.D-20+DABS(B(II))) |
| 325 | 1 | pfleura2 | |
| 326 | 1 | pfleura2 | GSAVE(IGeom,MPLUS) = 1.D0 |
| 327 | 1 | pfleura2 | !Print *, 'GSave(',IGeom,',',MPlus,')=1.D0'
|
| 328 | 1 | pfleura2 | |
| 329 | 1 | pfleura2 | DO 170 I=1,MPLUS |
| 330 | 1 | pfleura2 | DO 170 J=1,MPLUS |
| 331 | 1 | pfleura2 | IJ = MPLUS * (I-1) + J |
| 332 | 1 | pfleura2 | 170 B(IJ) = B(IJ) * GSAVE(IGeom,I) * GSAVE(IGeom,J) |
| 333 | 1 | pfleura2 | !C |
| 334 | 1 | pfleura2 | !C OUTPUT SCALED GDIIS MATRIX |
| 335 | 1 | pfleura2 | !C |
| 336 | 1 | pfleura2 | IF (DEBUG) THEN |
| 337 | 1 | pfleura2 | WRITE(*,'(/5X,'' GDIIS MATRIX (SCALED)'')') |
| 338 | 1 | pfleura2 | ITmp=min(12,MPLUS) |
| 339 | 1 | pfleura2 | DO IJ=1,MPLUS |
| 340 | 1 | pfleura2 | WRITE(*,'(12(F12.4,1X))') B((IJ-1)*MPLUS+1:(IJ-1)*MPLUS+ITmp) |
| 341 | 1 | pfleura2 | END DO |
| 342 | 1 | pfleura2 | ENDIF |
| 343 | 1 | pfleura2 | !C |
| 344 | 1 | pfleura2 | !C INVERT THE GDIIS MATRIX B |
| 345 | 1 | pfleura2 | !C |
| 346 | 1 | pfleura2 | CALL MINV(B,MPLUS,DET) ! matrix inversion. |
| 347 | 1 | pfleura2 | |
| 348 | 1 | pfleura2 | DO 190 I=1,MPLUS |
| 349 | 1 | pfleura2 | DO 190 J=1,MPLUS |
| 350 | 1 | pfleura2 | IJ = MPLUS * (I-1) + J |
| 351 | 1 | pfleura2 | !Print *, 'B(',IJ,')=', B(IJ)
|
| 352 | 1 | pfleura2 | !Print *, 'GSAVE(',IGeom,',',I,')=', GSAVE(IGeom,I)
|
| 353 | 1 | pfleura2 | !Print *, 'GSAVE(',IGeom,',',J,')=', GSAVE(IGeom,J)
|
| 354 | 1 | pfleura2 | !Print *, 'B(',IJ,')=', B(IJ) * GSAVE(I) * GSAVE(J)
|
| 355 | 1 | pfleura2 | 190 B(IJ) = B(IJ) * GSAVE(IGeom,I) * GSAVE(IGeom,J) |
| 356 | 1 | pfleura2 | !C |
| 357 | 1 | pfleura2 | !C COMPUTE THE INTERMEDIATE INTERPOLATED PARAMETER AND GRADIENT VECTORS |
| 358 | 1 | pfleura2 | !C |
| 359 | 1 | pfleura2 | !Print *, 'MSET(',IGeom,')=', MSET(IGeom), ' MPLUS=', MPLUS
|
| 360 | 1 | pfleura2 | DO 200 K=1,NFree |
| 361 | 1 | pfleura2 | Geom_new_free_inter(K) = 0.D0 |
| 362 | 1 | pfleura2 | Grad_new_free_inter(K) = 0.D0 |
| 363 | 1 | pfleura2 | DO 200 I=1,MSET(IGeom) |
| 364 | 1 | pfleura2 | INK = (I-1) * NFree + K |
| 365 | 1 | pfleura2 | Geom_new_free_inter(K) = Geom_new_free_inter(K) + B(MPLUS*MSET(IGeom)+I) * GeomSet_free(IGeom,INK) |
| 366 | 1 | pfleura2 | !Print *, 'Geom_new_free_inter(',K,')=', Geom_new_free_inter(K)
|
| 367 | 1 | pfleura2 | !Print *, 'B(MPLUS*MSET(',IGeom,')+',I,')=', B(MPLUS*MSET(IGeom)+I)
|
| 368 | 1 | pfleura2 | !Print *, 'GeomSet_free(',IGeom,',',INK,')=', GeomSet_free(IGeom,INK)
|
| 369 | 1 | pfleura2 | 200 Grad_new_free_inter(K) = Grad_new_free_inter(K) + B(MPLUS*MSET(IGeom)+I) * GradSet_free(IGeom,INK) |
| 370 | 1 | pfleura2 | HP=0.D0 |
| 371 | 1 | pfleura2 | DO 210 I=1,MSET(IGeom) |
| 372 | 1 | pfleura2 | 210 HP=HP+B(MPLUS*MSET(IGeom)+I)*ESET(I) |
| 373 | 1 | pfleura2 | DO 220 K=1,NFree |
| 374 | 1 | pfleura2 | 220 DXTMP(IGeom,K) = Geom_free(K) - Geom_new_free_inter(K) |
| 375 | 1 | pfleura2 | XNORM = SQRT(DOT_PRODUCT(DXTMP(IGeom,1:NFree),DXTMP(IGeom,1:NFree))) |
| 376 | 1 | pfleura2 | IF (PRINT) THEN |
| 377 | 1 | pfleura2 | WRITE (6,'(/10X,''DEVIATION IN X '',F10.6, 8X,''DETERMINANT '',G9.3)') XNORM,DET |
| 378 | 1 | pfleura2 | WRITE(*,'(10X,''GDIIS COEFFICIENTS'')') |
| 379 | 1 | pfleura2 | WRITE(*,'(10X,5F12.5)') (B(MPLUS*MSET(IGeom)+I),I=1,MSET(IGeom)) |
| 380 | 1 | pfleura2 | ENDIF |
| 381 | 1 | pfleura2 | |
| 382 | 1 | pfleura2 | !C THE FOLLOWING TOLERENCES FOR XNORM AND DET ARE SOMEWHAT ARBITRARY! |
| 383 | 1 | pfleura2 | THRES = MAX(10.D0**(-NFree), 1.D-25) |
| 384 | 1 | pfleura2 | IF (XNORM.GT.2.D0 .OR. DABS(DET).LT. THRES) THEN |
| 385 | 1 | pfleura2 | IF (PRINT)THEN |
| 386 | 1 | pfleura2 | WRITE(*,*) "THE DIIS MATRIX IS ILL CONDITIONED" |
| 387 | 1 | pfleura2 | WRITE(*,*) " - PROBABLY, VECTORS ARE LINEARLY DEPENDENT - " |
| 388 | 1 | pfleura2 | WRITE(*,*) "THE DIIS STEP WILL BE REPEATED WITH A SMALLER SPACE" |
| 389 | 1 | pfleura2 | END IF |
| 390 | 1 | pfleura2 | DO 230 K=1,MM |
| 391 | 1 | pfleura2 | 230 B(K) = BS(K) |
| 392 | 1 | pfleura2 | NDIIS = NDIIS - 1 |
| 393 | 1 | pfleura2 | IF (NDIIS .GT. 0) GO TO 80 |
| 394 | 1 | pfleura2 | IF (PRINT) WRITE(*,'(10X,''NEWTON-RAPHSON STEP TAKEN'')') |
| 395 | 1 | pfleura2 | DO 240 K=1,NFree |
| 396 | 1 | pfleura2 | Geom_new_free_inter(K) = Geom_free(K) |
| 397 | 1 | pfleura2 | 240 Grad_new_free_inter(K) = Grad_free(K) |
| 398 | 1 | pfleura2 | ENDIF ! matches IF (XNORM.GT.2.D0 .OR. DABS(DET).LT. THRES) THEN, L378 |
| 399 | 1 | pfleura2 | |
| 400 | 1 | pfleura2 | ! q_{m+1} = q'_{m+1} - H^{-1}g'_{m+1}
|
| 401 | 1 | pfleura2 | Geom_new_free=0.d0 |
| 402 | 1 | pfleura2 | DO I = 1, NFree |
| 403 | 1 | pfleura2 | DO J = 1, NFree |
| 404 | 1 | pfleura2 | ! If Hinv=.False., then we need to invert Hess |
| 405 | 1 | pfleura2 | !Geom_new_free(:) = Geom_new_free(:) + HFree(:,I)*Grad_new_free_inter(I) |
| 406 | 1 | pfleura2 | Geom_new_free(J) = Geom_new_free(J) + HFree(I+((J-1)*NFree))*Grad_new_free_inter(I) |
| 407 | 1 | pfleura2 | END DO |
| 408 | 1 | pfleura2 | END DO |
| 409 | 1 | pfleura2 | Geom_new_free(:) = Geom_new_free_inter(:) - Geom_new_free(:) |
| 410 | 1 | pfleura2 | |
| 411 | 1 | pfleura2 | Step_free = Geom_new_free - Geom_free |
| 412 | 1 | pfleura2 | |
| 413 | 1 | pfleura2 | Step = 0.d0 |
| 414 | 1 | pfleura2 | DO I=1,NFree |
| 415 | 1 | pfleura2 | Step = Step + Step_free(I)*Vfree(:,I) |
| 416 | 1 | pfleura2 | END DO |
| 417 | 1 | pfleura2 | |
| 418 | 1 | pfleura2 | DEALLOCATE(Hfree,Htmp,Grad_free,Grad_new_free_inter,Step_free,Geom_free) |
| 419 | 1 | pfleura2 | DEALLOCATE(Geom_new_free_inter,Geom_new_free) |
| 420 | 1 | pfleura2 | |
| 421 | 1 | pfleura2 | IF (PRINT) WRITE(*,'(/,'' END GDIIS '',/)') |
| 422 | 1 | pfleura2 | |
| 423 | 1 | pfleura2 | END SUBROUTINE Step_diis_all |