totale.f90 11.6 KB
 Markus Betzinger committed Apr 26, 2016 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 ``````MODULE m_totale CONTAINS SUBROUTINE totale(atoms,sphhar,stars,vacuum, & sym,input,noco,cell,oneD, xcpot,hybrid, it,results) ! ! *************************************************** ! subroutine calculates the total energy of the slab ! c.l.fu ! *************************************************** ! single particle energies ! SEIGC sum of the eigenvalues of the core states ! calculated in cdngen.f ! SEIGSCV sum of the eigenvalues of the semicore and valence states ! calculated in fermie.f ! TS : entropy contribution to the free energy ! SEIGC,SEIGSCV, TS are calculated in fermie.f ! *************************************************** ! TE_VCOUL : charge density-coulomb potential integral ! TE_VEFF: charge density-effective potential integral ! TE_EXC : charge density-ex-corr.energy density integral ! exchange-correlation energy ! TE_VCOUL,TE_VEFF,TE_EXC are calculated in vgen.f ! VMD : Madelung term ! *************************************************** ! TOTE : total energy due to all electrons ! TOTE = SEIGC + SEIGSCV + TE_VCOUL/2 -TE_VEFF + TE_EXC + VMD ! ! if HF calculation/hybrid-functional calculation : ! TOTE = SEIGC + SEIGSCV + TE_VCOUL/2 -TE_VEFF + TE_EXC_loc + VMD - 1/2 E_FOCK ! ! E_FOCK: sum of diagonal elements of fock matrix ! ! *************************************************** ! FREE ENRGY: F = TOTE - TS ! total electron energy extrapolated for T->0 ! E0 = TOTE - TS/2 ! *************************************************** ! USE m_intgr , ONLY : intgr3 USE m_constants, ONLY : sfp_const USE m_force_a4 USE m_force_a3 USE m_forcew USE m_loddop USE icorrkeys USE m_types `````` Gregor Michalicek committed Jun 03, 2016 47 `````` USE m_xmlOutput `````` Markus Betzinger committed Apr 26, 2016 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 `````` IMPLICIT NONE TYPE(t_results),INTENT(INOUT) :: results TYPE(t_xcpot),INTENT(IN) :: xcpot TYPE(t_oneD),INTENT(IN) :: oneD TYPE(t_hybrid),INTENT(IN) :: hybrid TYPE(t_input),INTENT(IN) :: input TYPE(t_vacuum),INTENT(IN) :: vacuum TYPE(t_noco),INTENT(IN) :: noco TYPE(t_sym),INTENT(IN) :: sym TYPE(t_stars),INTENT(IN) :: stars TYPE(t_cell),INTENT(IN) :: cell TYPE(t_sphhar),INTENT(IN) :: sphhar TYPE(t_atoms),INTENT(IN) :: atoms ! .. ! .. Scalar Arguments .. INTEGER,INTENT (IN) :: it ! .. ! .. Local Scalars .. REAL rhs,totz,vmd,zintn_r INTEGER n,j,nt,iter,i `````` Gregor Michalicek committed Jun 03, 2016 69 `````` CHARACTER(LEN=20) totalEnergyString `````` Markus Betzinger committed Apr 26, 2016 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 `````` ! .. Local Arrays .. REAL dpj(atoms%jmtd) !.....density REAL, ALLOCATABLE :: rho(:,:,:,:),rht(:,:,:) COMPLEX, ALLOCATABLE :: qpw(:,:),rhtxy(:,:,:,:) !.....potential REAL, ALLOCATABLE :: vr(:,:,:,:),vz(:,:,:) COMPLEX, ALLOCATABLE :: vpw(:,:),vxy(:,:,:,:) ! .. ALLOCATE ( rho(atoms%jmtd,0:sphhar%nlhd,atoms%ntypd,input%jspins),rht(vacuum%nmzd,2,input%jspins),& qpw(stars%n3d,input%jspins),rhtxy(vacuum%nmzxyd,oneD%odi%n2d-1,2,input%jspins),& vr(atoms%jmtd,0:sphhar%nlhd,atoms%ntypd,input%jspins),vz(vacuum%nmzd,2,input%jspins),& vpw(stars%n3d,input%jspins),vxy(vacuum%nmzxyd,oneD%odi%n2d-1,2,input%jspins) ) ! `````` Gregor Michalicek committed Jun 03, 2016 85 86 87 88 89 90 `````` WRITE(totalEnergyString,'(f20.10)'), results%tote IF (hybrid%l_calhf) THEN CALL openXMLElement('totalEnergy',(/'value','units','comment'/),(/totalEnergyString,'Htr','HF'/)) ELSE CALL openXMLElement('totalEnergy',(/'value','units'/),(/totalEnergyString,'Htr'/)) END IF `````` Markus Betzinger committed Apr 26, 2016 91 92 93 94 95 96 97 `````` WRITE (6,FMT=8000) WRITE (16,FMT=8000) 8000 FORMAT (/,/,/,5x,'t o t a l e n e r g y') ! ! ---> sum of eigenvalues (core, semicore and valence states) ! results%tote = results%seigscv + results%seigc `````` Gregor Michalicek committed Jun 03, 2016 98 99 100 101 `````` CALL openXMLElementPoly('sumOfEigenvalues',(/'value'/),(/results%tote/)) CALL writeXMLElementFormPoly('coreElectrons',(/'value'/),(/results%seigc/),reshape((/17,20/),(/1,2/))) CALL writeXMLElementFormPoly('valenceElectrons',(/'value'/),(/results%seigscv/),reshape((/14,20/),(/1,2/))) CALL closeXMLElement('sumOfEigenvalues') `````` Markus Betzinger committed Apr 26, 2016 102 103 104 105 106 107 108 `````` WRITE (6,FMT=8010) results%tote WRITE (16,FMT=8010) results%tote 8010 FORMAT (/,10x,'sum of eigenvalues =',t40,f20.10) ! ! ---> add contribution of coulomb potential ! results%tote = results%tote + 0.5e0*results%te_vcoul `````` Gregor Michalicek committed Jun 03, 2016 109 `````` CALL writeXMLElementPoly('densityCoulombPotentialIntegral',(/'value'/),(/results%te_vcoul/)) `````` Markus Betzinger committed Apr 26, 2016 110 111 112 113 114 115 116 `````` WRITE (6,FMT=8020) results%te_vcoul WRITE (16,FMT=8020) results%te_vcoul 8020 FORMAT (/,10x,'density-coulomb potential integral =',t40,f20.10) ! ! ---> add contribution of effective potential ! results%tote = results%tote - results%te_veff `````` Gregor Michalicek committed Jun 03, 2016 117 `````` CALL writeXMLElementPoly('densityEffectivePotentialIntegral',(/'value'/),(/results%te_veff/)) `````` Markus Betzinger committed Apr 26, 2016 118 119 120 121 122 123 124 `````` WRITE (6,FMT=8030) results%te_veff WRITE (16,FMT=8030) results%te_veff 8030 FORMAT (/,10x,'density-effective potential integral =',t40,f20.10) ! ! ---> add contribution of exchange-correlation energy ! results%tote = results%tote + results%te_exc `````` Gregor Michalicek committed Jun 03, 2016 125 `````` CALL writeXMLElementPoly('chargeDenXCDenIntegral',(/'value'/),(/results%te_exc/)) `````` Markus Betzinger committed Apr 26, 2016 126 127 128 129 130 131 132 133 134 135 136 137 `````` WRITE (6,FMT=8040) results%te_exc WRITE (16,FMT=8040) results%te_exc 8040 FORMAT (/,10x,'charge density-ex.-corr.energy density integral=', t40,f20.10) ! ! ---> Fock exchange contribution ! IF( xcpot%icorr .EQ. icorr_hf .OR. xcpot%icorr .EQ. icorr_pbe0 & .OR. xcpot%icorr .EQ. icorr_hse .OR. xcpot%icorr .EQ. icorr_vhse ) THEN results%tote = results%tote - 0.5e0*results%te_hfex%valence + 0.5e0*results%te_hfex%core ELSE IF ( xcpot%icorr .EQ. icorr_exx ) THEN results%tote = results%tote + 0.5e0*results%te_hfex%valence END IF `````` Gregor Michalicek committed Jun 03, 2016 138 139 `````` CALL writeXMLElementPoly('FockExchangeEnergyValence',(/'value'/),(/0.5e0*results%te_hfex%valence/)) CALL writeXMLElementPoly('FockExchangeEnergyCore',(/'value'/),(/0.5e0*results%te_hfex%core/)) `````` Markus Betzinger committed Apr 26, 2016 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 `````` WRITE (6,FMT=8100) 0.5e0*results%te_hfex%valence WRITE (16,FMT=8100) 0.5e0*results%te_hfex%valence WRITE (6,FMT=8101) 0.5e0*results%te_hfex%core WRITE (16,FMT=8101) 0.5e0*results%te_hfex%core 8100 FORMAT (/,10x,'Fock-exchange energy (valence)=',t40,f20.10) 8101 FORMAT (10x,'Fock-exchange energy (core)=',t40,f20.10) ! ----> VM terms ! ---> reload the density ! IF (noco%l_noco) THEN nt = 70 OPEN (nt,file='cdn',form='unformatted',status='old') ELSE nt = 71 OPEN (nt,file='cdn1',form='unformatted',status='old') ENDIF CALL loddop(stars,vacuum,atoms,sphhar, input,sym,& nt, iter,rho,qpw,rht,rhtxy) CLOSE (nt) !+for ! ---> reload the COULOMB potential ! OPEN (11,file='potcoul',form='unformatted',status='old') REWIND 11 CALL loddop(stars,vacuum,atoms,sphhar, input,sym,& 11, iter,vr,vpw,vz,vxy) CLOSE (11) ! ! CLASSICAL HELLMAN-FEYNMAN FORCE ! CALL force_a3(atoms,sphhar, input, rho,vr, results%force) ! IF (input%l_f) THEN ! ! core contribution to force: needs TOTAL POTENTIAL and core charge OPEN (8,file='pottot',form='unformatted',status='old') REWIND 8 CALL loddop(stars,vacuum,atoms,sphhar, input,sym,& 8, iter,vr,vpw,vz,vxy) CLOSE (8) ! CALL force_a4(atoms,sphhar,input, vr, results%force) ! ENDIF ! !-for ! ---> add spin-up and spin-down charge density for lh=0 ! IF (input%jspins.EQ.2) THEN DO n = 1,atoms%ntype DO i = 1,atoms%jri(n) rho(i,0,n,1) = rho(i,0,n,1) + rho(i,0,n,input%jspins) ENDDO ENDDO END IF ! ! ----> coulomb interaction between electrons and nuclei of different m.t.s ! DO n = 1,atoms%ntype `````` Gregor Michalicek committed Jun 03, 2016 202 `````` CALL openXMLElementPoly('atomTypeDependentContributions',(/'atomType'/),(/n/)) `````` Markus Betzinger committed Apr 26, 2016 203 204 205 206 207 208 209 210 `````` DO j = 1,atoms%jri(n) dpj(j) = rho(j,0,n,1)/atoms%rmsh(j,n) ENDDO CALL intgr3(dpj,atoms%rmsh(1,n),atoms%dx(n),atoms%jri(n),rhs) ! results%tote = results%tote - atoms%neq(n)*atoms%zatom(n)*sfp_const*rhs/2. ! zintn_r = atoms%neq(n)*atoms%zatom(n)*sfp_const*rhs/2. `````` Gregor Michalicek committed Jun 03, 2016 211 `````` CALL writeXMLElementPoly('electronNucleiInteractionDifferentMTs',(/'value'/),(/zintn_r/)) `````` Markus Betzinger committed Apr 26, 2016 212 213 214 215 216 `````` WRITE (6,FMT=8045) zintn_r WRITE (16,FMT=8045) zintn_r CALL intgr3(rho(1,0,n,1),atoms%rmsh(1,n),atoms%dx(n),atoms%jri(n),totz) vmd = atoms%rmt(n)*atoms%vr0(n)/sfp_const + atoms%zatom(n) - totz*sfp_const vmd = -atoms%neq(n)*atoms%zatom(n)*vmd/ (2.*atoms%rmt(n)) `````` Gregor Michalicek committed Jun 03, 2016 217 `````` CALL writeXMLElementPoly('MadelungTerm',(/'value'/),(/vmd/)) `````` Markus Betzinger committed Apr 26, 2016 218 219 220 `````` WRITE (6,FMT=8050) n,vmd WRITE (16,FMT=8050) n,vmd results%tote = results%tote + vmd `````` Gregor Michalicek committed Jun 03, 2016 221 `````` CALL closeXMLElement('atomTypeDependentContributions') `````` Markus Betzinger committed Apr 26, 2016 222 223 `````` ENDDO IF (atoms%n_u.GT.0) THEN `````` Gregor Michalicek committed Jun 03, 2016 224 `````` CALL writeXMLElementPoly('dft+uCorrection',(/'value'/),(/results%e_ldau/)) `````` Markus Betzinger committed Apr 26, 2016 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 `````` WRITE ( 6,FMT=8090) results%e_ldau WRITE (16,FMT=8090) results%e_ldau results%tote = results%tote - results%e_ldau ! gu test ENDIF ! print 'HF' before total energy to make it grepable IF ( .NOT. hybrid%l_calhf ) THEN WRITE ( 6,FMT=8060) results%tote WRITE (16,FMT=8060) results%tote ELSE WRITE ( 6,FMT=8061) results%tote WRITE (16,FMT=8061) results%tote END IF CALL force_w(input,atoms,sym,results,cell,oneD) ! ! ---> calculate the free energy and the ground state energy, ! extrapolated for T->0 ! ! print 'HF' before all energies to make them grepable IF ( .NOT. hybrid%l_calhf ) THEN WRITE ( 6,FMT=8065) results%ts WRITE (16,FMT=8065) results%ts WRITE ( 6,FMT=8070) results%tote-results%ts WRITE (16,FMT=8070) results%tote-results%ts WRITE ( 6,FMT=8080) results%tote-0.5e0*results%ts WRITE (16,FMT=8080) results%tote-0.5e0*results%ts ELSE WRITE ( 6,FMT=8066) results%ts WRITE (16,FMT=8066) results%ts WRITE ( 6,FMT=8071) results%tote-results%ts WRITE (16,FMT=8071) results%tote-results%ts WRITE ( 6,FMT=8081) results%tote-0.5e0*results%ts WRITE (16,FMT=8081) results%tote-0.5e0*results%ts END IF `````` Gregor Michalicek committed Jun 03, 2016 259 260 261 262 `````` CALL writeXMLElementPoly('tkbTimesEntropy',(/'value'/),(/results%ts/)) CALL writeXMLElementPoly('freeEnergy',(/'value'/),(/results%tote-results%ts/)) CALL writeXMLElementPoly('extrapolationTo0K',(/'value'/),(/results%tote-0.5e0*results%ts/)) CALL closeXMLElement('totalEnergy') `````` Markus Betzinger committed Apr 26, 2016 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 ``````8060 FORMAT (/,/,' ----> input%total energy=',t40,f20.10,' htr') 8061 FORMAT (/,/,' ----> HF input%total energy=',t40,f20.10,' htr') 8050 FORMAT (/,10x,'Madelung term for atom type:',i3,t40,f20.10) 8045 FORMAT (/,10x,'el.-nucl. inter. diff. m.t.',t40,f20.10) 8065 FORMAT (/,/,' ----> (input%tkb*entropy) TS=',t40,f20.10,' htr') 8066 FORMAT (/,/,' ----> HF (input%tkb*entropy) TS=',t40,f20.10,' htr') 8070 FORMAT (/,/,' ----> free energy=',t40,f20.10,' htr') 8071 FORMAT (/,/,' ----> HF free energy=',t40,f20.10,' htr') 8080 FORMAT (/,/,' extrapolation for T->0',& /,' ----> input%total electron energy=',t40,f20.10,' htr') 8081 FORMAT (/,/,' extrapolation for T->0',& /,' ----> HF input%total electron energy=',t40,f20.10,' htr') 8090 FORMAT (/,/,' ----> correction for lda+U =',t40,f20.10,' htr') DEALLOCATE ( rho,rht,qpw,rhtxy,vr,vz,vpw,vxy ) END SUBROUTINE totale END MODULE m_totale``````