diff --git a/CMakeListsLib.txt b/CMakeListsLib.txt index d40244b..ce08bd2 100644 --- a/CMakeListsLib.txt +++ b/CMakeListsLib.txt @@ -385,14 +385,35 @@ IF (NOT LIBS_BUILD_CGNS) MESSAGE(STATUS "CGNS include dir: " ${CGNS_INCLUDE_DIR}) LIST(INSERT linkedlibs 0 ${CGNS_LIBRARIES}) INCLUDE_DIRECTORIES (${CGNS_INCLUDE_DIR}) + + # Find "^#define CGNS_VERSION" and get only the numbers and remove trailing line breaks + EXECUTE_PROCESS(COMMAND cat "${CGNS_INCLUDE_DIR}/cgnslib.h" COMMAND grep "^#define CGNS_VERSION" COMMAND grep -o "[[:digit:]]*" COMMAND tr -d '\n' OUTPUT_VARIABLE CGNS_VERSION) + MESSAGE(STATUS "Found CGNS version in cgnslib.h [${CGNS_VERSION}]") + ELSE() MESSAGE(ERROR "CGNS not found") ENDIF() ELSE() - SET(LIBS_CGNS_DLDIR ${LIBS_EXTERNAL_LIB_DIR}/CGNS) - SET(LIBS_CGNS_DIR ${LIBS_CGNS_DLDIR}/build) - IF (NOT EXISTS "${LIBS_CGNS_DIR}/lib/libcgns.a") + # Set CGNS_Tag + SET (LIBS_BUILD_CGNS_TAG "v4.3.0" CACHE STRING "CGNS version tag from ${CGNSDOWNLOAD}") + SET_PROPERTY(CACHE LIBS_BUILD_CGNS_TAG PROPERTY STRINGS "v3.4.1" "v4.0.0" "v4.3.0") + MESSAGE(STATUS "Compiling CGNS version tag: " ${LIBS_BUILD_CGNS_TAG}) + + IF("${LIBS_BUILD_CGNS_TAG}" MATCHES "v4.3.0") + SET(CGNS_VERSION 4300) + ELSEIF("${LIBS_BUILD_CGNS_TAG}" MATCHES "v4.0.0") + SET(CGNS_VERSION 4000) + ELSEIF("${LIBS_BUILD_CGNS_TAG}" MATCHES "v3.4.1") + SET(CGNS_VERSION 3401) + ELSE() + SET(CGNS_VERSION -1) + ENDIF() + + SET(LIBS_CGNS_DLDIR ${LIBS_EXTERNAL_LIB_DIR}/CGNS${LIBS_BUILD_CGNS_TAG}) + SET(LIBS_CGNS_DIR ${LIBS_CGNS_DLDIR}) + + IF (NOT EXISTS "${LIBS_CGNS_DIR}/build/lib/libcgns.a") STRING(COMPARE EQUAL ${LIBS_BUILD_CGNS_INT} "64" LIBS_CGNS_64BIT) # Origin pointing to Github @@ -402,9 +423,6 @@ ELSE() SET (CGNSDOWNLOAD ${LIBS_DLPATH}libs/cgns.git ) ENDIF() - # Set CGNS_Tag - SET (LIBS_BUILD_CGNS_TAG "v3.4.1" CACHE STRING "CGNS version tag") - # Build CGNS with HDF5 support EXTERNALPROJECT_ADD(cgns GIT_REPOSITORY ${CGNSDOWNLOAD} @@ -428,3 +446,6 @@ ELSE() LIST(INSERT linkedlibs 0 ${LIBS_CGNS_DIR}/build/lib/libcgns.a) INCLUDE_DIRECTORIES( ${LIBS_CGNS_DIR}/build/include) ENDIF() + +# set pre-processor flag for CGNS version +ADD_DEFINITIONS(-DPP_CGNS_VERSION=${CGNS_VERSION}) diff --git a/src/globals.f90 b/src/globals.f90 index bf1cf32..3b218c9 100644 --- a/src/globals.f90 +++ b/src/globals.f90 @@ -62,7 +62,7 @@ MODULE MOD_Globals INTERFACE Abort - MODULE PROCEDURE Abort + MODULE PROCEDURE AbortProg END INTERFACE INTERFACE Timer @@ -101,7 +101,7 @@ END SUBROUTINE setstacksizeunlimited !=================================================================================================================================== CONTAINS -SUBROUTINE Abort(SourceFile,SourceLine,CompDate,CompTime,ErrorMessage,IntInfoOpt,RealInfoOpt) +SUBROUTINE AbortProg(SourceFile,SourceLine,CompDate,CompTime,ErrorMessage,IntInfoOpt,RealInfoOpt) !=================================================================================================================================== ! Terminate program correctly if an error has occurred (important in MPI mode!). !=================================================================================================================================== @@ -138,7 +138,7 @@ SUBROUTINE Abort(SourceFile,SourceLine,CompDate,CompTime,ErrorMessage,IntInfoOpt WRITE(UNIT_stdOut,'(A,A,A,I6.6,A)')'See ',TRIM(ProjectName),'_ERRORS.out for more details' WRITE(UNIT_stdOut,*) STOP 0001 -END SUBROUTINE Abort +END SUBROUTINE AbortProg SUBROUTINE Timer(start,unit_in) !=================================================================================================================================== diff --git a/src/mesh/globaluniquenodes.f90 b/src/mesh/globaluniquenodes.f90 index 6a8deff..41dcf08 100644 --- a/src/mesh/globaluniquenodes.f90 +++ b/src/mesh/globaluniquenodes.f90 @@ -298,10 +298,12 @@ SUBROUTINE GlobalUniqueNodes(withOrientedOpt) nextNode=1 DO iNode=1,nTotalNodes ! output of progress in % - IF((nTotalNodes.GT.100000).AND.(MOD(iNode,(nTotalNodes/100)).EQ.0)) THEN - percent=percent+1 - WRITE(0,'(I4,A23,A1)',ADVANCE='NO')percent, ' % of nodes evaluated...',ACHAR(13) - END IF + IF(nTotalNodes.GT.100000)THEN + IF(MOD(iNode,(nTotalNodes/100)).EQ.0)THEN + percent=percent+1 + WRITE(0,'(I4,A23,A1)',ADVANCE='NO')percent, ' % of nodes evaluated...',ACHAR(13) + END IF ! MOD(iNode,(nTotalNodes/100)).EQ.0 + END IF ! nTotalNodes.GT.100000) Node=>Nodes(iNode)%np IF(Node%tmp.GT.0) CYCLE ! node already checked Node%tmp=iNode !check this node diff --git a/src/readin/readin_CGNS.f90 b/src/readin/readin_CGNS.f90 index f555a60..0c71450 100644 --- a/src/readin/readin_CGNS.f90 +++ b/src/readin/readin_CGNS.f90 @@ -88,6 +88,7 @@ SUBROUTINE ReadCGNSmesh() INTEGER :: md ! ? INTEGER :: file_type ! ? REAL(KIND=4) :: version ! ? +INTEGER :: precision CHARACTER(LEN=32) :: CGName ! necessary data for CGNS INTEGER :: ZoneType ! ? @@ -102,23 +103,27 @@ SUBROUTINE ReadCGNSmesh() DO iFile=1,nMeshFiles ! Check CGNS file (CG_IS_CGNS_F must NOT be performed after CG_OPEN_F (in OpenBase), leads to an error in the read-in of HDF5-based CGNS files) CALL CG_IS_CGNS_F(TRIM(MeshFileName(iFile)), file_type, iError) - IF (iError .NE. CG_OK) & - CALL abortCGNS(__STAMP__,CGNSFile) - ! Open CGNS file - CALL OpenBase(TRIM(MeshFileName(iFile)),MODE_READ,md,md,CGNSFile,CGNSBase,.TRUE.) - CALL CG_VERSION_F(CGNSFile, version, iError) - WRITE(UNIT_stdOut,*)'CGNS version:',version + IF (iError .NE. CG_OK) CALL abort(__STAMP__,'ERROR: Given CGNS file is not supported!') + ! Check CGNS file type (ADF/HDF5) SELECT CASE(file_type) CASE(CG_FILE_ADF) WRITE(UNIT_stdOut,*)'CGNS file type: ADF' CASE(CG_FILE_HDF5) WRITE(UNIT_stdOut,*)'CGNS file type: HDF5' CASE DEFAULT - CALL closeFile(CGNSFile) - CALL abort(__STAMP__,'CGNS file type is unknown!') + CALL abort(__STAMP__,'ERROR: CGNS file type is unknown!') END SELECT + ! CALL CG_SET_FILE_TYPE_F(CG_FILE_ADF2, iError); + + ! Open CGNS file + CALL OpenBase(TRIM(MeshFileName(iFile)),MODE_READ,md,md,CGNSFile,CGNSBase,.TRUE.) + ! Output CGNS version and precision + CALL CG_VERSION_F(CGNSFile, version, iError) + CALL CG_PRECISION_F(CGNSFile,precision,iError) + WRITE(UNIT_stdOut,*)'CGNS version:', version, ' CGNS precision:', precision, 'Bit' + ! Get number of bases in CGNS file CALL CG_NBASES_F(CGNSfile,nBases,iError) IF (iError .NE. CG_OK) & @@ -210,9 +215,9 @@ SUBROUTINE ReadCGNSMeshUnstruct(FirstElem_in,CGNSFile,CGNSBase,iZone,nZonesGlob, PP_CGNS_INT_TYPE :: nBCElems ! ? INTEGER :: BCTypeIndex ! Index of boundary condition defined in parameter file PP_CGNS_INT_TYPE :: LocDim ! Dimension, type, number of nodes of local=section elements -INTEGER :: LocType, nNodesLoc ! Dimension, type, number of nodes of local=section elements +INTEGER :: nNodesLoc ! Dimension, type, number of nodes of local=section elements PP_CGNS_INT_TYPE :: SizeZone(3) ! CGNS datastructure variables -INTEGER :: SectionElemType ! Type of elements in CGNS file +INTEGER(CGENUM_T) :: SectionElemType, LocType ! Type of elements in CGNS file INTEGER :: ParentDataFlag ! 0=no parent data for elems available, 1=parent data available INTEGER :: PntSetType ! BC data format (points or surface elemnents) PP_CGNS_INT_TYPE :: NormalListFlag ! CGNS datastructure variables @@ -232,6 +237,9 @@ SUBROUTINE ReadCGNSMeshUnstruct(FirstElem_in,CGNSFile,CGNSBase,iZone,nZonesGlob, INTEGER :: locInds(4),nUnique LOGICAL,ALLOCATABLE :: BCFound(:) INTEGER :: GridLoc +#if PP_CGNS_VERSION>=4000 +INTEGER(CGSIZE_T),ALLOCATABLE:: connect_offsets(:) +#endif /*PP_CGNS_VERSION>=4000*/ !=================================================================================================================================== coordNameCGNS(1) = 'CoordinateX' coordNameCGNS(2) = 'CoordinateY' @@ -239,16 +247,14 @@ SUBROUTINE ReadCGNSMeshUnstruct(FirstElem_in,CGNSFile,CGNSBase,iZone,nZonesGlob, one=1 ! Check dimensions of CGNS base CALL CG_BASE_READ_F(CGNSfile,CGNSBase,CGname,CellDim,PhysDim,iError) -IF(iError .NE. CG_OK) & - CALL abortCGNS(__STAMP__,CGNSFile) +IF(iError .NE. CG_OK) CALL abortCGNS(__STAMP__,CGNSFile) IF((INT(CellDim) .NE. MeshDim) .OR. (INT(PhysDim) .NE. MeshDim))THEN WRITE(UNIT_stdOut,*)'ERROR-Invalid dimensions in CGNS file: CellDim=',CellDim,', PhysDim=',PhysDim,'(MeshDim=',MeshDim,')' - STOP + CALL abortCGNS(__STAMP__,CGNSFile) END IF ! Start with reading zones: total number of Nodes and Elems CALL CG_ZONE_READ_F(CGNSfile,CGNSBase,iZone,CGname,SizeZone,iError) -IF (iError .NE. CG_OK) & - CALL abortCGNS(__STAMP__,CGNSFile) +IF (iError .NE. CG_OK) CALL abortCGNS(__STAMP__,CGNSFile) WRITE(UNIT_stdOut,*)'Read Zone ',TRIM(CGname) ! Read node coordinates @@ -285,7 +291,6 @@ SUBROUTINE ReadCGNSMeshUnstruct(FirstElem_in,CGNSFile,CGNSBase,iZone,nZonesGlob, ElemMapping(:)=0 nElems=SizeZone(2) - ! Read element connectivity ALLOCATE(Elems(nElems)) ALLOCATE(ElemConnect(13,nElems)) ! max 8 + 1 schalter @@ -306,7 +311,16 @@ SUBROUTINE ReadCGNSMeshUnstruct(FirstElem_in,CGNSFile,CGNSBase,iZone,nZonesGlob, ! (nSectElems, Parent1 | Parent2 | ParentSide1 | ParentSide2)...but we don't use it ALLOCATE(ParentData(nSectElems,4)) ! Read in local connectivity data +#if (PP_CGNS_VERSION>=4000) + IF(SectionElemType .EQ. MIXED) THEN + ALLOCATE(connect_offsets(nSectElems*9)) + CALL CG_POLY_ELEMENTS_READ_F(CGNSfile, CGNSBase, iZone, iSect, LocalConnect, connect_offsets, ParentData, iError) + ELSE + CALL CG_ELEMENTS_READ_F(CGNSfile,CGNSBase,iZone,iSect,LocalConnect,ParentData,iError) + END IF +#else CALL CG_ELEMENTS_READ_F(CGNSfile,CGNSBase,iZone,iSect,LocalConnect,ParentData,iError) +#endif /*(PP_CGNS_VERSION>=4000)*/ ! Check if 2D element is not oriented in z+, check only first element# IF(MeshDim .EQ. 2)THEN @@ -338,14 +352,13 @@ SUBROUTINE ReadCGNSMeshUnstruct(FirstElem_in,CGNSFile,CGNSBase,iZone,nZonesGlob, iEnd =iEnd-1 ! Only nElemNodes values END IF CALL CG_NPE_F(LocType,nNodesLoc,iError) ! Get number of nodes for iElem + IF (iError .NE. CG_OK) CALL abortCGNS(__STAMP__,CGNSFile) iEnd=iEnd+nNodesLoc ! Check if the number of nodes is above the allocated and display the element type IF(nNodesLoc.GT.12) THEN CALL closeFile(CGNSFile) - CALL abort(__STAMP__,& - 'ERROR: Number of nodes is greater than expected. Following element type (per CGNS standard) might not be supported: '& - &//TRIM(ElementTypeName(LocType))) + CALL abort(__STAMP__,'ERROR: Number of nodes is greater than expected. The element type is not supported!') END IF LocDim=1 @@ -358,8 +371,7 @@ SUBROUTINE ReadCGNSMeshUnstruct(FirstElem_in,CGNSFile,CGNSBase,iZone,nZonesGlob, IF(iVolElem.EQ.1) FirstElemInd=IndMin+iElem-1 !start of volume zone, only possible fro ONE VOLUME ZONE! IF(iVolElem .GT. nElems)THEN CALL closeFile(CGNSFile) - CALL abort(__STAMP__,& - 'Something wrong with element numbers in CGNS File zone :',INT(iZone)) + CALL abort(__STAMP__, 'Something wrong with element numbers in CGNS File zone :',INT(iZone)) END IF ElemConnect(1 ,iVolElem)=LocType @@ -382,8 +394,7 @@ SUBROUTINE ReadCGNSMeshUnstruct(FirstElem_in,CGNSFile,CGNSBase,iZone,nZonesGlob, iSurfElem=iSurfElem+1 IF(iSurfElem.GT.nSurfElems)THEN CALL closeFile(CGNSFile) - CALL abort(__STAMP__,& - 'Something wrong with surf element numbers in CGNS File zone :',INT(iZone)) + CALL abort(__STAMP__,'Something wrong with surf element numbers in CGNS File zone :',INT(iZone)) END IF SurfElemConnect(1 ,iSurfElem)=LocType @@ -393,7 +404,11 @@ SUBROUTINE ReadCGNSMeshUnstruct(FirstElem_in,CGNSFile,CGNSBase,iZone,nZonesGlob, END IF ! LocDim .EQ. MeshDim iStart=iEnd+1 END DO ! elements in section - DEALLOCATE(LocalConnect,ParentData) + DEALLOCATE(LocalConnect) + DEALLOCATE(ParentData) +#if (PP_CGNS_VERSION>=4000) + DEALLOCATE(connect_offsets) +#endif /*(PP_CGNS_VERSION>=4000)*/ END DO !sections ! Rebuild the elements of zone iZone @@ -1101,6 +1116,9 @@ SUBROUTINE ReadCGNSSurfaceMesh(FirstElem_in,FileName) INTEGER :: iError ! Error flag CHARACTER(LEN=30) :: coordNameCGNS(3) ! List of CGNS names for the coordinates PP_CGNS_INT_TYPE :: one(1) ! ? +#if PP_CGNS_VERSION>=4000 +INTEGER(CGSIZE_T),ALLOCATABLE:: connect_offsets(:) +#endif /*PP_CGNS_VERSION>=4000*/ !=================================================================================================================================== WRITE(UNIT_stdOut,*)'Read CGNS Surface File: ',TRIM(FileName) ! Open CGNS file @@ -1193,7 +1211,16 @@ SUBROUTINE ReadCGNSSurfaceMesh(FirstElem_in,FileName) ALLOCATE(LocalConnect(nSectElems)) ALLOCATE(ParentData(nSectElems,4)) ! Read in local connectivity data +#if (PP_CGNS_VERSION>=4000) + IF(SectionElemType .EQ. MIXED) THEN + ALLOCATE(connect_offsets(nSectElems*9)) + CALL CG_POLY_ELEMENTS_READ_F(CGNSfile, CGNSBase, iZone, iSect, LocalConnect, connect_offsets, ParentData, iError) + ELSE + CALL CG_ELEMENTS_READ_F(CGNSfile,CGNSBase,iZone,iSect,LocalConnect,ParentData,iError) + END IF +#else CALL CG_ELEMENTS_READ_F(CGNSfile,CGNSBase,iZone,iSect,LocalConnect,ParentData,iError) +#endif /*(PP_CGNS_VERSION>=4000)*/ nSectElems=1+IndMax-IndMin ! Important for surface elements only ! (nSectElems, Parent1 | Parent2 | ParentSide1 | ParentSide2)...but we don't use it @@ -1229,7 +1256,11 @@ SUBROUTINE ReadCGNSSurfaceMesh(FirstElem_in,FileName) END IF iStart=iEnd+1 END DO ! elements in section - DEALLOCATE(LocalConnect,ParentData) + DEALLOCATE(LocalConnect) + DEALLOCATE(ParentData) +#if PP_CGNS_VERSION>=4000 + DEALLOCATE(connect_offsets) +#endif /*PP_CGNS_VERSION>=4000*/ END DO !sections ! Rebuild the elements of zone iZone