Commit 27064180 authored by Gregor Michalicek's avatar Gregor Michalicek

First output to out.xml

Note: This commit also introduces formatted output to out.xml.
It is not yet complete and not yet fully used for the small
test output of total energy contributions in this commit.
parent e2452f13
......@@ -18,7 +18,9 @@ MODULE m_xmlOutput
INTEGER, SAVE :: xmlOutputUnit
CHARACTER(LEN= 40), ALLOCATABLE :: elementList(:)
PUBLIC startXMLOutput, endXMLOutput, writeXMLElementPoly, writeXMLElement
PUBLIC startXMLOutput, endXMLOutput
PUBLIC writeXMLElementFormPoly, writeXMLElementPoly
PUBLIC writeXMLElementForm, writeXMLElement
PUBLIC openXMLElementPoly, openXMLElementNoAttributes, openXMLElement, closeXMLElement
PUBLIC getXMLOutputUnitNumber
......@@ -53,21 +55,24 @@ MODULE m_xmlOutput
CLOSE(xmlOutputUnit)
END SUBROUTINE endXMLOutput
SUBROUTINE writeXMLElementPoly(elementName,attributeNames,attributeValues,contentList)
SUBROUTINE writeXMLElementFormPoly(elementName,attributeNames,attributeValues,lengths,contentList)
IMPLICIT NONE
CHARACTER(LEN=*) :: elementName
CHARACTER(LEN= 40), INTENT(IN) :: attributeNames(:)
CLASS(*), INTENT(IN) :: attributeValues(:)
CLASS(*), INTENT(IN) :: contentList(:)
CHARACTER(LEN=*), INTENT(IN) :: elementName
CHARACTER(LEN=*), INTENT(IN) :: attributeNames(:)
CLASS(*), INTENT(IN) :: attributeValues(:)
INTEGER, INTENT(IN) :: lengths(:,:)
CLASS(*), INTENT(IN), OPTIONAL :: contentList(:)
CHARACTER(LEN= 30), ALLOCATABLE :: charAttributeValues(:)
CHARACTER(LEN= 30), ALLOCATABLE :: charContentList(:)
INTEGER :: i
ALLOCATE(charAttributeValues(SIZE(attributeValues)))
ALLOCATE(charContentList(SIZE(contentList)))
IF (PRESENT(contentList)) THEN
ALLOCATE(charContentList(SIZE(contentList)))
END IF
charAttributeValues = ''
charContentList = ''
......@@ -85,74 +90,154 @@ MODULE m_xmlOutput
END SELECT
END DO
DO i = 1, SIZE(contentList)
SELECT TYPE(contentList)
TYPE IS(INTEGER)
WRITE(charContentList(i),'(i0)'), contentList(i)
TYPE IS(REAL)
WRITE(charContentList(i),'(f20.10)'), contentList(i)
TYPE IS(LOGICAL)
WRITE(charContentList(i),'(l1)'), contentList(i)
CLASS DEFAULT
STOP 'Type of contentList not allowed'
END SELECT
END DO
IF (PRESENT(contentList)) THEN
DO i = 1, SIZE(contentList)
SELECT TYPE(contentList)
TYPE IS(INTEGER)
WRITE(charContentList(i),'(i0)'), contentList(i)
TYPE IS(REAL)
WRITE(charContentList(i),'(f20.10)'), contentList(i)
TYPE IS(LOGICAL)
WRITE(charContentList(i),'(l1)'), contentList(i)
CLASS DEFAULT
STOP 'Type of contentList not allowed'
END SELECT
END DO
CALL writeXMLElementForm(elementName,attributeNames,charAttributeValues,lengths,charContentList)
DEALLOCATE(charContentList,charAttributeValues)
ELSE
CALL writeXMLElementForm(elementName,attributeNames,charAttributeValues,lengths)
END IF
END SUBROUTINE writeXMLElementFormPoly
SUBROUTINE writeXMLElementPoly(elementName,attributeNames,attributeValues,contentList)
IMPLICIT NONE
CHARACTER(LEN=*), INTENT(IN) :: elementName
CHARACTER(LEN=*), INTENT(IN) :: attributeNames(:)
CLASS(*), INTENT(IN) :: attributeValues(:)
CLASS(*), INTENT(IN), OPTIONAL :: contentList(:)
CALL writeXMLElement(elementName,attributeNames,charAttributeValues,charContentList)
INTEGER, ALLOCATABLE :: lengths(:,:)
INTEGER :: contentListSize
DEALLOCATE(charContentList,charAttributeValues)
contentListSize = 0
IF (PRESENT(contentList)) THEN
contentListSize = SIZE(contentList)
END IF
ALLOCATE(lengths(MAX(SIZE(attributeNames),contentListSize),3))
lengths = 0
CALL writeXMLElementFormPoly(elementName,attributeNames,attributeValues,lengths,contentList)
DEALLOCATE(lengths)
END SUBROUTINE writeXMLElementPoly
SUBROUTINE writeXMLElement(elementName,attributeNames,attributeValues,contentList)
SUBROUTINE writeXMLElementForm(elementName,attributeNames,attributeValues,lengths,contentList)
IMPLICIT NONE
!! Overloading for different types of attributes, data elements?
CHARACTER(LEN=*) :: elementName
CHARACTER(LEN= 40), INTENT(IN) :: attributeNames(:)
CHARACTER(LEN= 30), INTENT(IN) :: attributeValues(:)
CHARACTER(LEN= 30), INTENT(IN) :: contentList(:)
CHARACTER(LEN=*), INTENT(IN) :: elementName
CHARACTER(LEN=*), INTENT(IN) :: attributeNames(:)
CHARACTER(LEN=*), INTENT(IN) :: attributeValues(:)
INTEGER, INTENT(IN) :: lengths(:,:)
CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: contentList(:)
CHARACTER(LEN=200), ALLOCATABLE :: contentLineList(:)
INTEGER :: i, contentLineLength, contentLineListSize
INTEGER, ALLOCATABLE :: bigLengths(:,:)
INTEGER :: i, j, contentLineLength, contentLineListSize
CHARACTER(LEN=70) :: format
CHARACTER(LEN=200) :: outputString
INTEGER :: contentListSize, overallListSize
INTEGER :: lengthsShape(2)
IF(SIZE(attributeNames).NE.SIZE(attributeValues)) THEN
WRITE(*,*) 'attributeNames', attributeNames
WRITE(*,*) 'attributeValues', attributeValues
STOP 'ERROR: SIZE(attributeNames).NE.SIZE(attributeValues)'
END IF
contentLineLength = 6 ! At most 6 data elements per line
contentLineListSize = SIZE(contentList) / contentLineLength
IF(contentLineListSize*contentLineLength.NE.SIZE(contentList)) THEN
contentLineListSize = contentLineListSize + 1
lengthsShape = SHAPE(lengths)
contentListSize = 0
IF (PRESENT(contentList)) THEN
contentListSize = SIZE(contentList)
END IF
ALLOCATE(contentLineList(contentLineListSize))
CALL fillContentLineList(contentList,contentLineList,contentLineLength)
overallListSize = MAX(SIZE(attributeNames),contentListSize)
ALLOCATE(bigLengths(overallListSize,2))
bigLengths = 0
DO j = 1, 2
DO i = 1, MIN(overallListSize,lengthsShape(1))
bigLengths(i,j) = lengths(i,j)
END DO
END DO
outputString = '<'//TRIM(ADJUSTL(elementName))
DO i = 1, SIZE(attributeNames)
outputString = TRIM(ADJUSTL(outputString))//' '//TRIM(ADJUSTL(attributeNames(i)))//'="'//TRIM(ADJUSTL(attributeValues(i)))//'"'
WRITE(format,'(a)') "(a,a,a"
IF (bigLengths(i,1).GT.0) WRITE(format,'(a,i0)') TRIM(ADJUSTL(format)),bigLengths(i,1)
WRITE(format,'(a,a)') TRIM(ADJUSTL(format)),",a,a"
IF (bigLengths(i,2).GT.0) WRITE(format,'(a,i0)') TRIM(ADJUSTL(format)),bigLengths(i,2)
WRITE(format,'(a,a)') TRIM(ADJUSTL(format)),",a)"
WRITE(*,*) TRIM(ADJUSTL(format))
WRITE(outputString,format) TRIM(ADJUSTL(outputString)), ' ', TRIM(ADJUSTL(attributeNames(i))),&
'="', TRIM(ADJUSTL(attributeValues(i))), '"'
! outputString = TRIM(ADJUSTL(outputString))//' '//TRIM(ADJUSTL(attributeNames(i)))//'="'//TRIM(ADJUSTL(attributeValues(i)))//'"'
END DO
IF(SIZE(contentLineList).EQ.0) THEN
outputString = TRIM(ADJUSTL(outputString))//'/>'
ELSE IF(SIZE(contentLineList).EQ.1) THEN
outputString = TRIM(ADJUSTL(outputString))//'>'//contentLineList(1)//'</'//TRIM(ADJUSTL(elementName))//'>'
ELSE
outputString = TRIM(ADJUSTL(outputString))//'>'
END IF
WRITE(format,'(a,i0,a)') "(a",3*(currentElementIndex+1),",a)"
WRITE(xmlOutputUnit,format) ' ', TRIM(ADJUSTL(outputString))
IF(SIZE(contentLineList).GT.1) THEN
WRITE(format,'(a,i0,a)') "(a",3*(currentElementIndex+2),",a)"
DO i = 1, SIZE(contentLineList)
WRITE(xmlOutputUnit,format) ' ', TRIM(ADJUSTL(contentLineList(i)))
END DO
WRITE(format,'(a,i0,a)') "(a",3*(currentElementIndex+1),",a)"
outputString = '</'//TRIM(ADJUSTL(elementName))//'>'
IF (PRESENT(contentList)) THEN
contentLineLength = 5 ! At most 5 data elements per line
contentLineListSize = SIZE(contentList) / contentLineLength
IF(contentLineListSize*contentLineLength.NE.SIZE(contentList)) THEN
contentLineListSize = contentLineListSize + 1
END IF
ALLOCATE(contentLineList(contentLineListSize))
CALL fillContentLineList(contentList,contentLineList,contentLineLength)
IF(SIZE(contentLineList).LE.1) THEN
outputString = TRIM(ADJUSTL(outputString))//'>'//contentLineList(1)//'</'//TRIM(ADJUSTL(elementName))//'>'
ELSE
outputString = TRIM(ADJUSTL(outputString))//'>'
END IF
WRITE(xmlOutputUnit,format) ' ', TRIM(ADJUSTL(outputString))
IF(SIZE(contentLineList).GT.1) THEN
WRITE(format,'(a,i0,a)') "(a",3*(currentElementIndex+2),",a)"
DO i = 1, SIZE(contentLineList)
WRITE(xmlOutputUnit,format) ' ', TRIM(ADJUSTL(contentLineList(i)))
END DO
WRITE(format,'(a,i0,a)') "(a",3*(currentElementIndex+1),",a)"
outputString = '</'//TRIM(ADJUSTL(elementName))//'>'
WRITE(xmlOutputUnit,format) ' ', TRIM(ADJUSTL(outputString))
END IF
ELSE
outputString = TRIM(ADJUSTL(outputString))//'/>'
WRITE(xmlOutputUnit,format) ' ', TRIM(ADJUSTL(outputString))
END IF
DEALLOCATE (bigLengths)
END SUBROUTINE writeXMLElementForm
SUBROUTINE writeXMLElement(elementName,attributeNames,attributeValues,contentList)
IMPLICIT NONE
CHARACTER(LEN=*), INTENT(IN) :: elementName
CHARACTER(LEN=*), INTENT(IN) :: attributeNames(:)
CHARACTER(LEN=*), INTENT(IN) :: attributeValues(:)
CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: contentList(:)
INTEGER, ALLOCATABLE :: lengths(:,:)
INTEGER :: contentListSize
contentListSize = 0
IF (PRESENT(contentList)) THEN
contentListSize = SIZE(contentList)
END IF
ALLOCATE(lengths(MAX(SIZE(attributeNames),contentListSize),2))
lengths = 0
CALL writeXMLElementForm(elementName,attributeNames,attributeValues,lengths,contentList)
DEALLOCATE(lengths)
END SUBROUTINE writeXMLElement
SUBROUTINE fillContentLineList(contentList,contentLineList,contentLineLength)
......
......@@ -44,6 +44,7 @@ CONTAINS
USE m_loddop
USE icorrkeys
USE m_types
USE m_xmlOutput
IMPLICIT NONE
TYPE(t_results),INTENT(INOUT) :: results
......@@ -65,6 +66,7 @@ CONTAINS
! .. Local Scalars ..
REAL rhs,totz,vmd,zintn_r
INTEGER n,j,nt,iter,i
CHARACTER(LEN=20) totalEnergyString
! .. Local Arrays ..
REAL dpj(atoms%jmtd)
......@@ -80,6 +82,12 @@ CONTAINS
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) )
!
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
WRITE (6,FMT=8000)
WRITE (16,FMT=8000)
8000 FORMAT (/,/,/,5x,'t o t a l e n e r g y')
......@@ -87,6 +95,10 @@ CONTAINS
! ---> sum of eigenvalues (core, semicore and valence states)
!
results%tote = results%seigscv + results%seigc
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')
WRITE (6,FMT=8010) results%tote
WRITE (16,FMT=8010) results%tote
8010 FORMAT (/,10x,'sum of eigenvalues =',t40,f20.10)
......@@ -94,6 +106,7 @@ CONTAINS
! ---> add contribution of coulomb potential
!
results%tote = results%tote + 0.5e0*results%te_vcoul
CALL writeXMLElementPoly('densityCoulombPotentialIntegral',(/'value'/),(/results%te_vcoul/))
WRITE (6,FMT=8020) results%te_vcoul
WRITE (16,FMT=8020) results%te_vcoul
8020 FORMAT (/,10x,'density-coulomb potential integral =',t40,f20.10)
......@@ -101,6 +114,7 @@ CONTAINS
! ---> add contribution of effective potential
!
results%tote = results%tote - results%te_veff
CALL writeXMLElementPoly('densityEffectivePotentialIntegral',(/'value'/),(/results%te_veff/))
WRITE (6,FMT=8030) results%te_veff
WRITE (16,FMT=8030) results%te_veff
8030 FORMAT (/,10x,'density-effective potential integral =',t40,f20.10)
......@@ -108,6 +122,7 @@ CONTAINS
! ---> add contribution of exchange-correlation energy
!
results%tote = results%tote + results%te_exc
CALL writeXMLElementPoly('chargeDenXCDenIntegral',(/'value'/),(/results%te_exc/))
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)
......@@ -120,6 +135,8 @@ CONTAINS
ELSE IF ( xcpot%icorr .EQ. icorr_exx ) THEN
results%tote = results%tote + 0.5e0*results%te_hfex%valence
END IF
CALL writeXMLElementPoly('FockExchangeEnergyValence',(/'value'/),(/0.5e0*results%te_hfex%valence/))
CALL writeXMLElementPoly('FockExchangeEnergyCore',(/'value'/),(/0.5e0*results%te_hfex%core/))
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
......@@ -182,6 +199,7 @@ CONTAINS
! ----> coulomb interaction between electrons and nuclei of different m.t.s
!
DO n = 1,atoms%ntype
CALL openXMLElementPoly('atomTypeDependentContributions',(/'atomType'/),(/n/))
DO j = 1,atoms%jri(n)
dpj(j) = rho(j,0,n,1)/atoms%rmsh(j,n)
ENDDO
......@@ -190,16 +208,20 @@ CONTAINS
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.
CALL writeXMLElementPoly('electronNucleiInteractionDifferentMTs',(/'value'/),(/zintn_r/))
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))
CALL writeXMLElementPoly('MadelungTerm',(/'value'/),(/vmd/))
WRITE (6,FMT=8050) n,vmd
WRITE (16,FMT=8050) n,vmd
results%tote = results%tote + vmd
CALL closeXMLElement('atomTypeDependentContributions')
ENDDO
IF (atoms%n_u.GT.0) THEN
CALL writeXMLElementPoly('dft+uCorrection',(/'value'/),(/results%e_ldau/))
WRITE ( 6,FMT=8090) results%e_ldau
WRITE (16,FMT=8090) results%e_ldau
results%tote = results%tote - results%e_ldau ! gu test
......@@ -234,6 +256,10 @@ CONTAINS
WRITE ( 6,FMT=8081) results%tote-0.5e0*results%ts
WRITE (16,FMT=8081) results%tote-0.5e0*results%ts
END IF
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')
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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment