Skip to content

Commit

Permalink
Merge pull request #22 from hopr-framework/update.cgns.version.v4.3.0
Browse files Browse the repository at this point in the history
[update.cgns.version.v4.3.0] Updated default CGNS version to v4.3.0
  • Loading branch information
pnizenkov authored Dec 19, 2022
2 parents 65d3a76 + c32e6b1 commit d825e49
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 38 deletions.
33 changes: 27 additions & 6 deletions CMakeListsLib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand All @@ -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})
6 changes: 3 additions & 3 deletions src/globals.f90
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ MODULE MOD_Globals


INTERFACE Abort
MODULE PROCEDURE Abort
MODULE PROCEDURE AbortProg
END INTERFACE

INTERFACE Timer
Expand Down Expand Up @@ -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!).
!===================================================================================================================================
Expand Down Expand Up @@ -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)
!===================================================================================================================================
Expand Down
10 changes: 6 additions & 4 deletions src/mesh/globaluniquenodes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 56 additions & 25 deletions src/readin/readin_CGNS.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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 ! ?
Expand All @@ -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) &
Expand Down Expand Up @@ -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
Expand All @@ -232,23 +237,24 @@ 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'
coordNameCGNS(3) = 'CoordinateZ'
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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d825e49

Please sign in to comment.