cdnpot_io_common.F90 8.37 KB
Newer Older
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60
!--------------------------------------------------------------------------------
! Copyright (c) 2017 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!
!!! This module contains common subroutines required for density IO
!!! as well as for potential IO
!!!
!!!                             GM'17
!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

MODULE m_cdnpot_io_common

   USE m_types
   USE m_juDFT
   USE m_cdnpot_io_hdf
#ifdef CPP_HDF
   USE hdf5
#endif

   CONTAINS

   SUBROUTINE compareStars(stars, refStars, l_same)

      TYPE(t_stars),INTENT(IN)  :: stars
      TYPE(t_stars),INTENT(IN)  :: refStars

      LOGICAL,      INTENT(OUT) :: l_same

      l_same = .TRUE.

      IF(ABS(stars%gmaxInit-refStars%gmaxInit).GT.1e-10) l_same = .FALSE.
      IF(stars%ng3.NE.refStars%ng3) l_same = .FALSE.
      IF(stars%ng2.NE.refStars%ng2) l_same = .FALSE.
      IF(stars%mx1.NE.refStars%mx1) l_same = .FALSE.
      IF(stars%mx2.NE.refStars%mx2) l_same = .FALSE.
      IF(stars%mx3.NE.refStars%mx3) l_same = .FALSE.

   END SUBROUTINE compareStars

   SUBROUTINE compareStepfunctions(stars, refStars, l_same)

      TYPE(t_stars),INTENT(IN)  :: stars
      TYPE(t_stars),INTENT(IN)  :: refStars

      LOGICAL,      INTENT(OUT) :: l_same

      l_same = .TRUE.

      IF(stars%ng3.NE.refStars%ng3) l_same = .FALSE.
      IF(stars%mx1.NE.refStars%mx1) l_same = .FALSE.
      IF(stars%mx2.NE.refStars%mx2) l_same = .FALSE.
      IF(stars%mx3.NE.refStars%mx3) l_same = .FALSE.

   END SUBROUTINE compareStepfunctions

61 62
   SUBROUTINE compareStructure(atoms, vacuum, cell, sym, refAtoms, refVacuum,&
                               refCell, refSym, l_same)
63 64 65 66

      TYPE(t_atoms),INTENT(IN)  :: atoms, refAtoms
      TYPE(t_vacuum),INTENT(IN) :: vacuum, refVacuum
      TYPE(t_cell),INTENT(IN)   :: cell, refCell
67
      TYPE(t_sym),INTENT(IN)    :: sym, refSym
68 69 70 71 72 73 74 75 76 77

      LOGICAL,      INTENT(OUT) :: l_same

      l_same = .TRUE.

      IF(atoms%ntype.NE.refAtoms%ntype) l_same = .FALSE.
      IF(atoms%nat.NE.refAtoms%nat) l_same = .FALSE.
      IF(atoms%lmaxd.NE.refAtoms%lmaxd) l_same = .FALSE.
      IF(atoms%jmtd.NE.refAtoms%jmtd) l_same = .FALSE.
      IF(vacuum%dvac.NE.refVacuum%dvac) l_same = .FALSE.
78 79 80
      IF(sym%nop.NE.refSym%nop) l_same = .FALSE.
      IF(sym%nop2.NE.refSym%nop2) l_same = .FALSE.

81 82 83
      IF(ANY(ABS(cell%amat(:,:)-refCell%amat(:,:)).GT.1e-10)) l_same = .FALSE.
      IF(l_same) THEN
         IF(ANY(atoms%nz(:).NE.refAtoms%nz(:))) l_same = .FALSE.
84 85
         IF(ANY(sym%mrot(:,:,:sym%nop).NE.refSym%mrot(:,:,:sym%nop))) l_same = .FALSE.
         IF(ANY(ABS(sym%tau(:,:sym%nop)-refSym%tau(:,:sym%nop)).GT.1e-10)) l_same = .FALSE.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
      END IF
      IF(l_same) THEN
         DO i = 1, atoms%nat
            IF(ANY(ABS(atoms%pos(:,i)-refAtoms%pos(:,i)).GT.1e-10)) l_same = .FALSE.
         END DO
      END IF

      ! NOTE: This subroutine certainly is not yet complete. Especially symmetry should
      !       also be stored and compared for structure considerations.

   END SUBROUTINE compareStructure

   SUBROUTINE compareLatharms(latharms, refLatharms, l_same)

      TYPE(t_sphhar)       :: latharms, refLatharms

      LOGICAL,      INTENT(OUT) :: l_same

      l_same = .TRUE.

      IF(latharms%ntypsd.NE.refLatharms%ntypsd) l_same = .FALSE.
      IF(latharms%memd.NE.refLatharms%memd) l_same = .FALSE.
      IF(latharms%nlhd.NE.refLatharms%nlhd) l_same = .FALSE.

   END SUBROUTINE compareLatharms

#ifdef CPP_HDF
   SUBROUTINE checkAndWriteMetadataHDF(fileID, input, atoms, cell, vacuum, oneD, stars, latharms, sym,&
                                       currentStarsIndex,currentLatharmsIndex,currentStructureIndex,&
                                       currentStepfunctionIndex,l_storeIndices)

      TYPE(t_input),INTENT(IN)  :: input
      TYPE(t_atoms),INTENT(IN)  :: atoms
      TYPE(t_cell), INTENT(IN)  :: cell
      TYPE(t_vacuum),INTENT(IN) :: vacuum
      TYPE(t_oneD),INTENT(IN)   :: oneD
      TYPE(t_stars),INTENT(IN)  :: stars
      TYPE(t_sphhar),INTENT(IN) :: latharms
      TYPE(t_sym),INTENT(IN)    :: sym

      INTEGER(HID_T), INTENT(IN) :: fileID
      INTEGER, INTENT(INOUT)     :: currentStarsIndex,currentLatharmsIndex
      INTEGER, INTENT(INOUT)     :: currentStructureIndex,currentStepfunctionIndex
      LOGICAL, INTENT(OUT)       :: l_storeIndices

      TYPE(t_stars)        :: starsTemp
      TYPE(t_vacuum)       :: vacuumTemp
      TYPE(t_atoms)        :: atomsTemp
      TYPE(t_sphhar)       :: latharmsTemp
      TYPE(t_input)        :: inputTemp
      TYPE(t_cell)         :: cellTemp
      TYPE(t_oneD)         :: oneDTemp
138
      TYPE(t_sym)          :: symTemp
139

140
      INTEGER                    :: starsIndexTemp, structureIndexTemp
141 142 143 144 145 146 147 148
      LOGICAL                    :: l_same, l_writeAll

      l_storeIndices = .FALSE.
      l_writeAll = .FALSE.

      IF(currentStructureIndex.EQ.0) THEN
         currentStructureIndex = 1
         l_storeIndices = .TRUE.
149
         CALL writeStructureHDF(fileID, input, atoms, cell, vacuum, oneD, sym, currentStructureIndex)
150
      ELSE
151 152
         CALL readStructureHDF(fileID, inputTemp, atomsTemp, cellTemp, vacuumTemp, oneDTemp, symTemp, currentStructureIndex)
         CALL compareStructure(atoms, vacuum, cell, sym, atomsTemp, vacuumTemp, cellTemp, symTemp, l_same)
153 154 155 156 157

         IF(.NOT.l_same) THEN
            currentStructureIndex = currentStructureIndex + 1
            l_storeIndices = .TRUE.
            l_writeAll = .TRUE.
158
            CALL writeStructureHDF(fileID, input, atoms, cell, vacuum, oneD, sym, currentStructureIndex)
159 160 161 162 163
         END IF
      END IF
      IF (currentStarsIndex.EQ.0) THEN
         currentStarsIndex = 1
         l_storeIndices = .TRUE.
164
         CALL writeStarsHDF(fileID, currentStarsIndex, currentStructureIndex, stars)
165
      ELSE
166 167 168 169 170 171
         CALL peekStarsHDF(fileID, currentStarsIndex, structureIndexTemp)
         l_same = structureIndexTemp.EQ.currentStructureIndex
         IF(l_same) THEN
            CALL readStarsHDF(fileID, currentStarsIndex, starsTemp)
            CALL compareStars(stars, starsTemp, l_same)
         END IF
172 173 174
         IF((.NOT.l_same).OR.l_writeAll) THEN
            currentStarsIndex = currentStarsIndex + 1
            l_storeIndices = .TRUE.
175
            CALL writeStarsHDF(fileID, currentStarsIndex, currentStructureIndex, stars)
176 177 178 179 180
         END IF
      END IF
      IF (currentLatharmsIndex.EQ.0) THEN
         currentLatharmsIndex = 1
         l_storeIndices = .TRUE.
181
         CALL writeLatharmsHDF(fileID, currentLatharmsIndex, currentStructureIndex, latharms)
182
      ELSE
183 184 185 186 187 188
         CALL peekLatharmsHDF(fileID, currentLatharmsIndex, structureIndexTemp)
         l_same = structureIndexTemp.EQ.currentStructureIndex
         IF(l_same) THEN
            CALL readLatharmsHDF(fileID, currentLatharmsIndex, latharmsTemp)
            CALL compareLatharms(latharms, latharmsTemp, l_same)
         END IF
189 190 191
         IF((.NOT.l_same).OR.l_writeAll) THEN
            currentLatharmsIndex = currentLatharmsIndex + 1
            l_storeIndices = .TRUE.
192
            CALL writeLatharmsHDF(fileID, currentLatharmsIndex, currentStructureIndex, latharms)
193 194 195 196 197
         END IF
      END IF
      IF(currentStepfunctionIndex.EQ.0) THEN
         currentStepfunctionIndex = 1
         l_storeIndices = .TRUE.
198 199
         CALL writeStepfunctionHDF(fileID, currentStepfunctionIndex, currentStarsIndex,&
                                   currentStructureIndex, stars)
200
      ELSE
201 202 203 204 205 206
         CALL peekStepfunctionHDF(fileID, currentStepfunctionIndex, starsIndexTemp, structureIndexTemp)
         l_same = (starsIndexTemp.EQ.currentStarsIndex).AND.(structureIndexTemp.EQ.currentStructureIndex)
         IF(l_same) THEN
            CALL readStepfunctionHDF(fileID, currentStepfunctionIndex, starsTemp)
            CALL compareStepfunctions(stars, starsTemp, l_same)
         END IF
207 208 209
         IF((.NOT.l_same).OR.l_writeAll) THEN
            currentStepfunctionIndex = currentStepfunctionIndex + 1
            l_storeIndices = .TRUE.
210 211
            CALL writeStepfunctionHDF(fileID, currentStepfunctionIndex, currentStarsIndex,&
                                      currentStructureIndex, stars)
212 213 214 215 216 217 218 219
         END IF
      END IF

   END SUBROUTINE checkAndWriteMetadataHDF
#endif


END MODULE m_cdnpot_io_common