Skip to content

Commit

Permalink
Merge branch 'fix.piclas.version.variable.2.10.0' into 'master.dev'
Browse files Browse the repository at this point in the history
[fix.piclas.version.variable.2.10.0] Fixed bug in REAL format file version

See merge request piclas/piclas!759
  • Loading branch information
pnizenkov committed Jan 26, 2023
2 parents e2022f5 + 8c22bd9 commit 2b4ae0d
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 112 deletions.
13 changes: 8 additions & 5 deletions src/globals/globals_vars.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ MODULE MOD_Globals_Vars
! GLOBAL VARIABLES
!-----------------------------------------------------------------------------------------------------------------------------------
CHARACTER(LEN=6),PARAMETER :: ProgramName = 'PICLas' !> name of this program
INTEGER,PARAMETER :: MajorVersion = 2 !> FileVersion number saved in each hdf5 file with hdf5 header
INTEGER,PARAMETER :: MinorVersion = 9 !> FileVersion number saved in each hdf5 file with hdf5 header
INTEGER,PARAMETER :: MajorVersion = 3 !> FileVersion number saved in each hdf5 file with hdf5 header
INTEGER,PARAMETER :: MinorVersion = 0 !> FileVersion number saved in each hdf5 file with hdf5 header
INTEGER,PARAMETER :: PatchVersion = 0 !> FileVersion number saved in each hdf5 file with hdf5 header
REAL,PARAMETER :: FileVersion = REAL(MajorVersion,8)+REAL(MinorVersion,8)/10.+REAL(PatchVersion,8)/100. !> FileVersion
!> number saved in each hdf5 file with hdf5 header
REAL,PARAMETER :: FileVersionReal = REAL(MajorVersion,8)+REAL(MinorVersion,8)/10.+REAL(PatchVersion,8)/100.
!> OLD number saved in each hdf5 file with hdf5 header
INTEGER,PARAMETER :: FileVersionInt = PatchVersion+MinorVersion*100+MajorVersion*10000
!> NEWnumber saved in each hdf5 file with hdf5 header
CHARACTER(LEN=10) :: PiclasVersionStr !> PiclasVersionStrnumber saved in each hdf5 file with hdf5 header
REAL :: FileVersionHDF5 !> FileVersion number read from hdf5 restart file
REAL :: FileVersionHDF5Real !> OLD FileVersion number read from hdf5 restart file
REAL :: FileVersionHDF5Int !> NEW FileVersion number read from hdf5 restart file
REAL :: WallTime !> Wall time needed by a simulation (is not reset by
!> performing a load balance step, only by user restart)
REAL :: InitializationWallTime !> Wall time needed to initialize a simulation (or
Expand Down
38 changes: 24 additions & 14 deletions src/io_hdf5/hdf5_input.f90
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ MODULE MOD_HDF5_Input

CONTAINS

FUNCTION ISVALIDHDF5FILE(FileName,FileVersionOpt)
FUNCTION ISVALIDHDF5FILE(FileName,FileVersionRealOpt,FileVersionIntOpt)
!===================================================================================================================================
! Subroutine to check if a file is a valid PICLas HDF5 file
!===================================================================================================================================
Expand All @@ -89,30 +89,31 @@ FUNCTION ISVALIDHDF5FILE(FileName,FileVersionOpt)
!-----------------------------------------------------------------------------------------------------------------------------------
! INPUT VARIABLES
CHARACTER(LEN=*),INTENT(IN) :: FileName
REAL,INTENT(IN),OPTIONAL :: FileVersionOpt
REAL,INTENT(IN),OPTIONAL :: FileVersionRealOpt
INTEGER,INTENT(IN),OPTIONAL :: FileVersionIntOpt
!-----------------------------------------------------------------------------------------------------------------------------------
! OUTPUT VARIABLES
LOGICAL :: isValidHDF5File
!-----------------------------------------------------------------------------------------------------------------------------------
! LOCAL VARIABLES
REAL :: FileVersion,FileVersionRef
REAL :: FileVersionReal,FileVersionRealRef
INTEGER :: FileVersionInt,FileVersionIntRef
INTEGER(HID_T) :: Plist_ID
CHARACTER(LEN=255) :: ProgramName
LOGICAL :: help
!===================================================================================================================================
isValidHDF5File=.TRUE.
iError=0
FileVersionRef=1.0
IF(PRESENT(FileVersionOpt)) FileVersionRef=FileVersionOpt
FileVersionRealRef=-1.0
IF(PRESENT(FileVersionRealOpt)) FileVersionRealRef=FileVersionRealOpt
FileVersionIntRef=-1
IF(PRESENT(FileVersionRealOpt)) FileVersionIntRef=FileVersionIntOpt

! Disable error messages
CALL H5ESET_AUTO_F(0, iError)
! Initialize FORTRAN predefined datatypes
CALL H5OPEN_F(iError)
IF(iError.NE.0)&
CALL Abort(&
__STAMP__&
,'ERROR: COULD NOT OPEN FILE!')
IF(iError.NE.0) CALL Abort(__STAMP__,'ERROR: COULD NOT OPEN FILE!')

! Open HDF5 file
CALL H5FOPEN_F(TRIM(FileName), H5F_ACC_RDONLY_F, File_ID, iError,access_prp = Plist_ID)
Expand All @@ -130,11 +131,20 @@ FUNCTION ISVALIDHDF5FILE(FileName,FileVersionOpt)

! Check file version -------------------------------------------------------------------------------------------------------------
! Open the attribute "File_Version" of root group
CALL ReadAttribute(File_ID,'File_Version',1,RealScalar=FileVersion)
!IF(FileVersion .LT. FileVersionRef)THEN
! isValidHDF5File=.FALSE.
! SWRITE(UNIT_stdOut,'(A)')' ERROR: FILE VERSION TOO OLD! FileName: '//TRIM(FileName)
!END IF
IF(FileVersionRealRef.GT.0.0)THEN
CALL ReadAttribute(File_ID,'File_Version',1,RealScalar=FileVersionReal)
!IF(FileVersionReal .LT. FileVersionRealRef)THEN
! isValidHDF5File=.FALSE.
! SWRITE(UNIT_stdOut,'(A)')' ERROR: FILE VERSION TOO OLD! FileName: '//TRIM(FileName)
!END IF
END IF ! FileVersionRealRef.GT.0.0
IF(FileVersionIntRef.GT.0)THEN
CALL ReadAttribute(File_ID,'Piclas_VersionInt',1,IntScalar=FileVersionInt)
!IF(FileVersionReal .LT. FileVersionIntRef)THEN
! isValidHDF5File=.FALSE.
! SWRITE(UNIT_stdOut,'(A)')' ERROR: FILE VERSION TOO OLD! FileName: '//TRIM(FileName)
!END IF
END IF ! FileVersionIntRef.GT.0.0
! Close the file.
CALL H5FCLOSE_F(File_ID, iError)
! Close FORTRAN predefined datatypes
Expand Down
5 changes: 3 additions & 2 deletions src/io_hdf5/hdf5_output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ SUBROUTINE WriteHDF5Header(FileType_in,File_ID)
! Subroutine to write a distinct file header to each HDF5 file
!===================================================================================================================================
! MODULES
USE MOD_Globals_Vars ,ONLY: ProgramName,FileVersion,ProjectName,PiclasVersionStr
USE MOD_Globals_Vars ,ONLY: ProgramName,FileVersionReal,FileVersionInt,ProjectName,PiclasVersionStr
USE MOD_Globals_Vars ,ONLY: MajorVersion,MinorVersion,PatchVersion
! IMPLICIT VARIABLE HANDLING
IMPLICIT NONE
Expand All @@ -459,10 +459,11 @@ SUBROUTINE WriteHDF5Header(FileType_in,File_ID)
CALL WriteAttributeToHDF5(File_ID,'File_Type' ,1,StrScalar=(/tmp255/))
tmp255=TRIM(ProjectName)
CALL WriteAttributeToHDF5(File_ID,'Project_Name',1,StrScalar=(/tmp255/))
CALL WriteAttributeToHDF5(File_ID,'File_Version',1,RealScalar=FileVersion)
CALL WriteAttributeToHDF5(File_ID,'File_Version',1,RealScalar=FileVersionReal)
WRITE(UNIT=PiclasVersionStr,FMT='(I0,A1,I0,A1,I0)') MajorVersion,".",MinorVersion,".",PatchVersion
tmp255=TRIM(PiclasVersionStr)
CALL WriteAttributeToHDF5(File_ID,'Piclas_Version',1,StrScalar=(/tmp255/))
CALL WriteAttributeToHDF5(File_ID,'Piclas_VersionInt',1,IntegerScalar=FileVersionInt)
END SUBROUTINE WriteHDF5Header


Expand Down
41 changes: 24 additions & 17 deletions src/loadbalance/loaddistribution.f90
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ SUBROUTINE ApplyWeightDistributionMethod(ElemTimeExists)
LOGICAL :: PartIntExists
REAL :: timeWeight(1:nGlobalElems)
LOGICAL :: FileVersionExists
REAL :: FileVersionHDF5
REAL :: FileVersionHDF5Real
INTEGER :: FileVersionHDF5Int
INTEGER(KIND=IK),ALLOCATABLE :: PartIntGlob(:,:)
INTEGER :: ElemPerProc(0:nProcessors-1)
#endif /*PARTICLES*/
Expand Down Expand Up @@ -227,25 +228,31 @@ SUBROUTINE ApplyWeightDistributionMethod(ElemTimeExists)
!check file version
CALL DatasetExists(File_ID,'File_Version',FileVersionExists,attrib=.TRUE.)
IF(FileVersionExists)THEN
CALL ReadAttribute(File_ID,'File_Version',1,RealScalar=FileVersionHDF5)
CALL ReadAttribute(File_ID,'File_Version',1,RealScalar=FileVersionHDF5Real)

! Depending on the file version, PartInt may have switched dimensions
IF(FileVersionHDF5Real.LT.2.8)THEN
ALLOCATE(PartIntTmp(1:nGlobalElems,PartIntSize))
! Check integer KIND=8 possibility
CALL ReadArray('PartInt',2,(/INT(nGlobalElems,IK),INT(PartIntSize,IK)/),0_IK,1,IntegerArray=PartIntTmp)
! Switch dimensions
DO iElem = 1, nGlobalElems
PartIntGlob(:,iElem) = PartIntTmp(iElem,:)
END DO ! iElem = FirstElemInd, LastElemInd
DEALLOCATE(PartIntTmp)
ELSE
! Check integer KIND=8 possibility
CALL ReadArray('PartInt',2,(/INT(PartIntSize,IK),INT(nGlobalElems,IK)/),0_IK,2,IntegerArray=PartIntGlob)
END IF ! FileVersionHDF5Real.LT.2.7
ELSE
CALL abort(__STAMP__,'Error in ApplyWeightDistributionMethod(): Attribute "File_Version" does not exist!')
CALL DatasetExists(File_ID,'Piclas_VersionInt',FileVersionExists,attrib=.TRUE.)
IF (FileVersionExists) THEN
CALL ReadAttribute(File_ID,'Piclas_VersionInt',1,IntScalar=FileVersionHDF5Int)
ELSE
CALL abort(__STAMP__,'Error in ApplyWeightDistributionMethod(): Attribute "Piclas_VersionInt" does not exist!')
END IF
ENDIF

! Depending on the file version, PartInt may have switched dimensions
IF(FileVersionHDF5.LT.2.8)THEN
ALLOCATE(PartIntTmp(1:nGlobalElems,PartIntSize))
! Check integer KIND=8 possibility
CALL ReadArray('PartInt',2,(/INT(nGlobalElems,IK),INT(PartIntSize,IK)/),0_IK,1,IntegerArray=PartIntTmp)
! Switch dimensions
DO iElem = 1, nGlobalElems
PartIntGlob(:,iElem) = PartIntTmp(iElem,:)
END DO ! iElem = FirstElemInd, LastElemInd
DEALLOCATE(PartIntTmp)
ELSE
! Check integer KIND=8 possibility
CALL ReadArray('PartInt',2,(/INT(PartIntSize,IK),INT(nGlobalElems,IK)/),0_IK,2,IntegerArray=PartIntGlob)
END IF ! FileVersionHDF5.LT.2.7
END IF
CALL CloseDataFile()

Expand Down
49 changes: 28 additions & 21 deletions src/particles/restart/particle_readin.f90
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ SUBROUTINE ParticleReadin()
LOGICAL :: VibQuantDataExists,changedVars,DGSourceExists
LOGICAL :: ElecDistriDataExists,AD_DataExists,implemented
LOGICAL :: FileVersionExists
REAL :: FileVersionHDF5
REAL :: FileVersionHDF5Real
INTEGER :: FileVersionHDF5Int
INTEGER :: PartDataSize_HDF5 ! number of entries in each line of PartData
REAL,ALLOCATABLE :: PartSource_HDF5(:,:,:,:,:)
! Temporary arrays
Expand Down Expand Up @@ -549,29 +550,35 @@ SUBROUTINE ParticleReadin()
! Check file version
CALL DatasetExists(File_ID,'File_Version',FileVersionExists,attrib=.TRUE.)
IF(FileVersionExists)THEN
CALL ReadAttribute(File_ID,'File_Version',1,RealScalar=FileVersionHDF5)
CALL ReadAttribute(File_ID,'File_Version',1,RealScalar=FileVersionHDF5Real)

! Associate construct for integer KIND=8 possibility
ASSOCIATE (&
PP_nElems => INT(PP_nElems,IK) ,&
PartIntSize => INT(PartIntSize,IK) ,&
offsetElem => INT(offsetElem,IK) )
! Depending on the file version, PartInt may have switched dimensions
IF(FileVersionHDF5Real.LT.2.8)THEN
ALLOCATE(PartIntTmp(FirstElemInd:LastElemInd,PartIntSize))
CALL ReadArray('PartInt',2,(/PP_nElems,PartIntSize/),offsetElem,1,IntegerArray=PartIntTmp)
! Switch dimensions
DO iElem = FirstElemInd, LastElemInd
PartInt(:,iElem) = PartIntTmp(iElem,:)
END DO ! iElem = FirstElemInd, LastElemInd
DEALLOCATE(PartIntTmp)
ELSE
CALL ReadArray('PartInt',2,(/PartIntSize,PP_nElems/),offsetElem,2,IntegerArray=PartInt)
END IF ! FileVersionHDF5Real.LT.2.7
END ASSOCIATE
ELSE
CALL abort(__STAMP__,'Error in ParticleRestart(): Attribute "File_Version" does not exist!')
CALL DatasetExists(File_ID,'Piclas_VersionInt',FileVersionExists,attrib=.TRUE.)
IF (FileVersionExists) THEN
CALL ReadAttribute(File_ID,'Piclas_VersionInt',1,IntScalar=FileVersionHDF5Int)
ELSE
CALL abort(__STAMP__,'Error in ParticleRestart(): Attribute "Piclas_VersionInt" does not exist!')
END IF
ENDIF

! Associate construct for integer KIND=8 possibility
ASSOCIATE (&
PP_nElems => INT(PP_nElems,IK) ,&
PartIntSize => INT(PartIntSize,IK) ,&
offsetElem => INT(offsetElem,IK) )
! Depending on the file version, PartInt may have switched dimensions
IF(FileVersionHDF5.LT.2.8)THEN
ALLOCATE(PartIntTmp(FirstElemInd:LastElemInd,PartIntSize))
CALL ReadArray('PartInt',2,(/PP_nElems,PartIntSize/),offsetElem,1,IntegerArray=PartIntTmp)
! Switch dimensions
DO iElem = FirstElemInd, LastElemInd
PartInt(:,iElem) = PartIntTmp(iElem,:)
END DO ! iElem = FirstElemInd, LastElemInd
DEALLOCATE(PartIntTmp)
ELSE
CALL ReadArray('PartInt',2,(/PartIntSize,PP_nElems/),offsetElem,2,IntegerArray=PartInt)
END IF ! FileVersionHDF5.LT.2.7
END ASSOCIATE

! ------------------------------------------------
! PartData
Expand Down
61 changes: 34 additions & 27 deletions src/posti/piclas2vtk/piclas2vtk.f90
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,8 @@ SUBROUTINE ConvertPartData(InputStateFile)
CHARACTER(LEN=255),ALLOCATABLE :: VarNamesParticle(:), tmpArray(:)
CHARACTER(LEN=255) :: FileString
REAL, ALLOCATABLE :: PartData(:,:)
REAL :: OutputTime, FileVersionHDF5
REAL :: OutputTime, FileVersionHDFReal
INTEGER :: FileVersionHDF5Int
LOGICAL :: FileVersionExists
!===================================================================================================================================

Expand All @@ -879,34 +880,40 @@ SUBROUTINE ConvertPartData(InputStateFile)
! check file version
CALL DatasetExists(File_ID,'File_Version',FileVersionExists,attrib=.TRUE.)
IF (FileVersionExists) THEN
CALL ReadAttribute(File_ID,'File_Version',1,RealScalar=FileVersionHDF5)
CALL ReadAttribute(File_ID,'File_Version',1,RealScalar=FileVersionHDFReal)

IF(FileVersionHDFReal.LT.1.5)THEN
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% '
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' Restart file is too old! "File_Version" in restart file < 1.5!'
SWRITE(UNIT_StdOut,'(A)')' The format used in the restart file is not compatible with this version of PICLas.'
SWRITE(UNIT_StdOut,'(A)')' Among others, the particle format (PartData) has changed.'
SWRITE(UNIT_StdOut,'(A)')' Run python script '
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' python ./tools/flip_PartState/flip_PartState.py --help'
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' for info regarding the usage and run the script against the restart file, e.g., '
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' python ./tools/flip_PartState/flip_PartState.py ProjectName_State_000.0000xxxxxx.h5'
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' to update the format and file version number.'
SWRITE(UNIT_StdOut,'(A)')' Note that the format can be changed back to the old one by running the script a second time.'
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% '
CALL abort(&
__STAMP__&
,'Error in InitRestart(): "File_Version" in restart file < 1.5. See error message above to fix. File version in restart file =',&
RealInfoOpt=FileVersionHDFReal)
END IF ! FileVersionHDFReal.LT.1.5
ELSE
CALL abort(__STAMP__,'Error in InitRestart(): Attribute "File_Version" does not exist!')
CALL DatasetExists(File_ID,'Piclas_VersionInt',FileVersionExists,attrib=.TRUE.)
IF (FileVersionExists) THEN
CALL ReadAttribute(File_ID,'Piclas_VersionInt',1,IntScalar=FileVersionHDF5Int)
ELSE
CALL abort(__STAMP__,'Error in InitRestart(): Attribute "Piclas_VersionInt" does not exist!')
END IF
END IF
IF(FileVersionHDF5.LT.1.5)THEN
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% '
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' Restart file is too old! "File_Version" in restart file < 1.5!'
SWRITE(UNIT_StdOut,'(A)')' The format used in the restart file is not compatible with this version of PICLas.'
SWRITE(UNIT_StdOut,'(A)')' Among others, the particle format (PartData) has changed.'
SWRITE(UNIT_StdOut,'(A)')' Run python script '
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' python ./tools/flip_PartState/flip_PartState.py --help'
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' for info regarding the usage and run the script against the restart file, e.g., '
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' python ./tools/flip_PartState/flip_PartState.py ProjectName_State_000.0000xxxxxx.h5'
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' to update the format and file version number.'
SWRITE(UNIT_StdOut,'(A)')' Note that the format can be changed back to the old one by running the script a second time.'
SWRITE(UNIT_StdOut,'(A)')' '
SWRITE(UNIT_StdOut,'(A)')' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% '
CALL abort(&
__STAMP__&
,'Error in InitRestart(): "File_Version" in restart file < 1.5. See error message above to fix. File version in restart file =',&
RealInfoOpt=FileVersionHDF5)
END IF ! FileVersionHDF5.LT.1.5

! Read-in of dimensions of the particle array (1: Number of particles, 2: Number of variables)
CALL GetDataSize(File_ID,'PartData',nDims,HSize)
Expand Down
Loading

0 comments on commit 2b4ae0d

Please sign in to comment.