Line data Source code
1 : !--------------------------------------------------------------------------------
2 : ! Copyright (c) 2017 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
3 : ! This file is part of FLEUR and available as free software under the conditions
4 : ! of the MIT license as expressed in the LICENSE file in more detail.
5 : !--------------------------------------------------------------------------------
6 :
7 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8 : !!!
9 : !!! This module is a wrapper for the potential I/O
10 : !!!
11 : !!! GM'17
12 : !!!
13 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14 :
15 : MODULE m_pot_io
16 :
17 : USE m_types
18 : USE m_juDFT
19 : USE m_loddop
20 : USE m_wrtdop
21 : USE m_cdnpot_io_hdf
22 : USE m_cdnpot_io_common
23 : #ifdef CPP_HDF
24 : USE hdf5
25 : #endif
26 : IMPLICIT NONE
27 :
28 : PRIVATE
29 : PUBLIC readPotential, writePotential
30 : PUBLIC POT_ARCHIVE_TYPE_TOT_const, POT_ARCHIVE_TYPE_COUL_const
31 : PUBLIC POT_ARCHIVE_TYPE_X_const
32 :
33 : INTEGER, PARAMETER :: POT_ARCHIVE_TYPE_TOT_const = 1
34 : INTEGER, PARAMETER :: POT_ARCHIVE_TYPE_COUL_const = 2
35 : INTEGER, PARAMETER :: POT_ARCHIVE_TYPE_X_const = 3
36 :
37 : INTEGER, PARAMETER :: POT_DIRECT_MODE = 1
38 : INTEGER, PARAMETER :: POT_STREAM_MODE = 2
39 : INTEGER, PARAMETER :: POT_HDF5_MODE = 3
40 :
41 : CONTAINS
42 :
43 0 : SUBROUTINE readPotential(stars,noco,vacuum,atoms,sphhar,input,sym,archiveType,&
44 0 : iter,fr,fpw,fz,fzxy,fvac)
45 :
46 : TYPE(t_stars),INTENT(IN) :: stars
47 : TYPE(t_noco),INTENT(IN) :: noco
48 : TYPE(t_vacuum),INTENT(IN) :: vacuum
49 : TYPE(t_atoms),INTENT(IN) :: atoms
50 : TYPE(t_sphhar),INTENT(IN) :: sphhar
51 : TYPE(t_input),INTENT(IN) :: input
52 : TYPE(t_sym),INTENT(IN) :: sym
53 :
54 : INTEGER, INTENT (OUT) :: iter
55 : INTEGER, INTENT (IN) :: archiveType
56 :
57 : ! ..
58 : ! .. Array Arguments ..
59 : COMPLEX, INTENT (OUT) :: fpw(stars%ng3,input%jspins), fzxy(vacuum%nmzxyd,stars%ng2-1,2,input%jspins), fvac(vacuum%nmzd,stars%ng2,2,input%jspins)
60 : REAL, INTENT (OUT) :: fr(atoms%jmtd,0:sphhar%nlhd,atoms%ntype,input%jspins), fz(vacuum%nmzd,2,input%jspins)
61 :
62 : ! local variables
63 : INTEGER :: mode, iUnit
64 : LOGICAL :: l_exist
65 : CHARACTER(len=30) :: filename
66 :
67 : #ifdef CPP_HDF
68 : INTEGER(HID_T) :: fileID
69 : #endif
70 : INTEGER :: currentStarsIndex,currentLatharmsIndex
71 : INTEGER :: currentStructureIndex,currentStepfunctionIndex
72 : INTEGER :: potentialType
73 : CHARACTER(LEN=30) :: archiveName
74 :
75 0 : CALL getMode(mode)
76 :
77 : IF(mode.EQ.POT_HDF5_MODE) THEN
78 : #ifdef CPP_HDF
79 0 : INQUIRE(FILE='pot.hdf',EXIST=l_exist)
80 0 : IF (l_exist) THEN
81 : CALL openPOT_HDF(fileID,currentStarsIndex,currentLatharmsIndex,&
82 0 : currentStructureIndex,currentStepfunctionIndex)
83 :
84 0 : archiveName = 'illegalPotentialArchive'
85 0 : IF (archiveType.EQ.POT_ARCHIVE_TYPE_TOT_const) THEN
86 0 : archiveName = 'pottot'
87 : END IF
88 0 : IF (archiveType.EQ.POT_ARCHIVE_TYPE_COUL_const) THEN
89 0 : archiveName = 'potcoul'
90 : END IF
91 0 : IF (archiveType.EQ.POT_ARCHIVE_TYPE_X_const) THEN
92 0 : archiveName = 'potx'
93 : END IF
94 :
95 0 : potentialType = POTENTIAL_TYPE_IN_const
96 :
97 0 : l_exist = isPotentialEntryPresentHDF(fileID,archiveName,potentialType)
98 :
99 0 : CALL closeCDNPOT_HDF(fileID)
100 : END IF
101 :
102 0 : IF(l_exist) THEN
103 : CALL openPOT_HDF(fileID,currentStarsIndex,currentLatharmsIndex,&
104 0 : currentStructureIndex,currentStepfunctionIndex)
105 :
106 : CALL readPotentialHDF(fileID, archiveName, potentialType,&
107 0 : iter,fr,fpw,fz,fzxy,fvac,any(noco%l_unrestrictMT))
108 :
109 0 : CALL closeCDNPOT_HDF(fileID)
110 : ELSE
111 0 : WRITE(*,*) 'Potential entry or pot.hdf file not found.'
112 0 : WRITE(*,*) 'Falling back to stream access file pot.str.'
113 : mode = POT_STREAM_MODE
114 : END IF
115 : #else
116 : WRITE(*,*) 'Not compiled for pot.hdf file usage.'
117 : WRITE(*,*) 'Falling back to stream access file pot.str.'
118 : mode = POT_STREAM_MODE
119 : #endif
120 : END IF
121 :
122 : IF(mode.EQ.POT_STREAM_MODE) THEN
123 0 : INQUIRE(FILE='pot.str',EXIST=l_exist)
124 0 : IF (l_exist) THEN
125 : !load density from cdn.str and exit subroutine
126 :
127 0 : RETURN
128 : ELSE
129 0 : WRITE(*,*) 'pot.str file not found.'
130 0 : WRITE(*,*) 'Falling back to direct access file.'
131 : mode = POT_DIRECT_MODE
132 : END IF
133 : END IF
134 :
135 0 : IF (mode.EQ.POT_DIRECT_MODE) THEN
136 0 : filename = 'illegalPotentialArchive'
137 0 : IF (archiveType.EQ.POT_ARCHIVE_TYPE_TOT_const) THEN
138 0 : filename = 'pottot'
139 : END IF
140 0 : IF (archiveType.EQ.POT_ARCHIVE_TYPE_COUL_const) THEN
141 0 : filename = 'potcoul'
142 : END IF
143 0 : IF (archiveType.EQ.POT_ARCHIVE_TYPE_X_const) THEN
144 0 : filename = 'potx'
145 : END IF
146 :
147 0 : INQUIRE(file=TRIM(ADJUSTL(filename)),EXIST=l_exist)
148 0 : IF(.NOT.l_exist) THEN
149 0 : CALL juDFT_error("potential file "//TRIM(ADJUSTL(filename))//" missing",calledby ="readPotential")
150 : END IF
151 :
152 0 : iUnit = 11
153 0 : OPEN (iUnit,file=TRIM(ADJUSTL(filename)),form='unformatted',status='unknown')
154 :
155 : CALL loddop(stars,vacuum,atoms,sphhar,input,sym,&
156 0 : iUnit,iter,fr,fpw,fvac)
157 :
158 0 : CLOSE(iUnit)
159 : END IF
160 :
161 : END SUBROUTINE readPotential
162 :
163 0 : SUBROUTINE writePotential(stars,noco,vacuum,atoms,cell,sphhar,input,sym ,archiveType,&
164 0 : iter,pot,fpw)
165 :
166 : TYPE(t_stars),INTENT(IN) :: stars
167 : TYPE(t_vacuum),INTENT(IN) :: vacuum
168 : TYPE(t_atoms),INTENT(IN) :: atoms
169 : TYPE(t_cell), INTENT(IN) :: cell
170 : TYPE(t_sphhar),INTENT(IN) :: sphhar
171 : TYPE(t_input),INTENT(IN) :: input
172 : TYPE(t_sym),INTENT(IN) :: sym
173 : TYPE(t_noco),INTENT(IN) :: noco
174 :
175 : TYPE(t_potden), INTENT(INOUT) :: pot
176 :
177 : INTEGER, INTENT (IN) :: iter
178 : INTEGER, INTENT (IN) :: archiveType
179 : ! ..
180 : ! .. Array Arguments ..
181 : COMPLEX, INTENT (IN) :: fpw(:,:)
182 :
183 : ! local variables
184 : INTEGER :: mode, iUnit
185 : LOGICAL :: l_exist, l_storeIndices
186 : CHARACTER(len=30) :: filename
187 :
188 : #ifdef CPP_HDF
189 : INTEGER(HID_T) :: fileID
190 : #endif
191 : INTEGER :: currentStarsIndex,currentLatharmsIndex
192 : INTEGER :: currentStructureIndex,currentStepfunctionIndex
193 : INTEGER :: potentialType
194 : CHARACTER(LEN=30) :: archiveName
195 :
196 0 : CALL getMode(mode)
197 :
198 0 : IF(mode.EQ.POT_HDF5_MODE) THEN
199 : #ifdef CPP_HDF
200 : CALL openPOT_HDF(fileID,currentStarsIndex,currentLatharmsIndex,&
201 0 : currentStructureIndex,currentStepfunctionIndex)
202 :
203 : CALL checkAndWriteMetadataHDF(fileID, input, atoms, cell, vacuum, stars, sphhar, sym,&
204 : currentStarsIndex,currentLatharmsIndex,currentStructureIndex,&
205 0 : currentStepfunctionIndex,l_storeIndices,.TRUE.,.TRUE.)
206 :
207 0 : archiveName = 'illegalPotentialArchive'
208 0 : IF (archiveType.EQ.POT_ARCHIVE_TYPE_TOT_const) THEN
209 0 : archiveName = 'pottot'
210 : END IF
211 0 : IF (archiveType.EQ.POT_ARCHIVE_TYPE_COUL_const) THEN
212 0 : archiveName = 'potcoul'
213 : END IF
214 0 : IF (archiveType.EQ.POT_ARCHIVE_TYPE_X_const) THEN
215 0 : archiveName = 'potx'
216 : END IF
217 :
218 0 : potentialType = POTENTIAL_TYPE_IN_const
219 :
220 0 : IF(vacuum%nvac.EQ.1) THEN
221 : !pot%vacz(:,2,:) = pot%vacz(:,1,:)
222 0 : IF (sym%invs) THEN
223 : !pot%vacxy(:,:,2,:) = CONJG(pot%vacxy(:,:,1,:))
224 0 : pot%vac(:,:,2,:) = CONJG(pot%vac(:,:,1,:))
225 : ELSE
226 : !pot%vacxy(:,:,2,:) = pot%vacxy(:,:,1,:)
227 0 : pot%vac(:,:,2,:) = pot%vac(:,:,1,:)
228 : END IF
229 : END IF
230 : CALL writePotentialHDF(input, fileID, archiveName, potentialType,&
231 : currentStarsIndex, currentLatharmsIndex, currentStructureIndex,&
232 0 : currentStepfunctionIndex,iter,pot,fpw,noco%l_noco,any(noco%l_unrestrictMT))
233 :
234 0 : IF(l_storeIndices) THEN
235 : CALL writePOTHeaderData(fileID,currentStarsIndex,currentLatharmsIndex,&
236 0 : currentStructureIndex,currentStepfunctionIndex)
237 : END IF
238 :
239 0 : CALL closeCDNPOT_HDF(fileID)
240 : #endif
241 : ELSE IF(mode.EQ.POT_STREAM_MODE) THEN
242 : ! Write potential to pot.str file
243 : STOP 'POT_STREAM_MODE not yet implemented!'
244 : ELSE
245 : ! Direct mode
246 0 : filename = 'illegalPotentialArchive'
247 0 : IF (archiveType.EQ.POT_ARCHIVE_TYPE_TOT_const) THEN
248 0 : filename = 'pottot'
249 : END IF
250 0 : IF (archiveType.EQ.POT_ARCHIVE_TYPE_COUL_const) THEN
251 0 : filename = 'potcoul'
252 : END IF
253 0 : IF (archiveType.EQ.POT_ARCHIVE_TYPE_X_const) THEN
254 0 : filename = 'potx'
255 : END IF
256 :
257 0 : iUnit = 11
258 0 : OPEN (iUnit,file=TRIM(ADJUSTL(filename)),form='unformatted',status='unknown')
259 : CALL wrtdop(stars,vacuum,atoms,sphhar,input,sym,&
260 0 : iUnit,iter,pot%mt,fpw,pot%vac(:,:,:,:input%jspins))
261 0 : CLOSE(iUnit)
262 : END IF
263 :
264 0 : END SUBROUTINE writePotential
265 :
266 0 : SUBROUTINE getMode(mode)
267 : INTEGER, INTENT(OUT) :: mode
268 :
269 0 : mode = POT_DIRECT_MODE
270 : !IF (juDFT_was_argument("-stream_cdn")) mode=POT_STREAM_MODE
271 0 : IF (.NOT.juDFT_was_argument("-no_cdn_hdf")) THEN !juDFT_was_argument("-hdf_cdn")) THEN
272 : #ifdef CPP_HDF
273 : mode=POT_HDF5_MODE
274 : #else
275 : ! WRITE(*,*) 'Code not compiled with HDF5 support.'
276 : ! WRITE(*,*) 'Falling back to direct access.'
277 : #endif
278 : END IF
279 : END SUBROUTINE getMode
280 :
281 : END MODULE m_pot_io
|