GetMaxTotalConnectivity
Interface
MODULE FUNCTION obj_GetMaxTotalConnectivity(obj) RESULT(ans)
CLASS(FEDOF_), INTENT(IN) :: obj
INTEGER(I4B) :: ans
END FUNCTION obj_GetMaxTotalConnectivity
Description
The GetMaxTotalConnectivity
method determines the maximum number of degrees of freedom (DOF) associated with any single element in the mesh. This value represents the largest connectivity array size needed to store all DOFs for any element, which is crucial for pre-allocating arrays in finite element assembly operations.
Parameters
obj
- Input,CLASS(FEDOF_)
, FEDOF object instanceans
- Output,INTEGER(I4B)
, maximum connectivity size across all elements
Implementation Details
The implementation iterates through all elements in the mesh, calculates the total DOF for each element, and keeps track of the maximum value:
ans = 0
telems = obj%mesh%GetTotalElements()
DO ii = 1, telems
tdof = obj%GetTotalDOF(globalElement=ii, isLocal=.TRUE.)
ans = MAX(ans, tdof)
END DO
This efficient approach ensures that the returned value is large enough to accommodate the connectivity of any element in the mesh.
Usage Example
! Example to get the maximum connectivity size
INTEGER(I4B) :: maxConnSize
TYPE(FEDOF_) :: myDOF
! Get maximum connectivity size
maxConnSize = myDOF%GetMaxTotalConnectivity()
! Use this value to allocate arrays for element operations
INTEGER(I4B), ALLOCATABLE :: elemDOFs(:)
ALLOCATE (elemDOFs(maxConnSize))
! Now elemDOFs is guaranteed to be large enough for any element
! in the mesh, regardless of element type or polynomial order
Important Notes
- This method is particularly valuable in heterogeneous meshes where different element types or polynomial orders are used
- The returned value is often cached in the
maxTotalConnectivity
member variable to avoid recalculation - This method can be computationally expensive for large meshes as it loops through all elements
Related Methods
GetTotalDOF
- Used internally to calculate the DOF count for each elementGetConnectivity
- Returns the actual connectivity for a specific elementGetConnectivity_
- Lower-level method for retrieving element connectivity
The GetMaxTotalConnectivity
method is an important utility function for memory management in finite element codes, ensuring that sufficient memory is allocated for element-wise operations without excessive over-allocation.
Example 1
!> author: Vikas Sharma, Ph. D.
! date: 2025-06-08
! summary: Testing GetMaxTotalConnectivity method of FEDOF class
PROGRAM main
USE BaseType, ONLY: TypeQuadratureOpt
USE FEDOF_Class
USE FEDomain_Class
USE AbstractMesh_Class
USE HDF5File_Class
USE Display_Method
USE GlobalData
USE Test_Method
USE ExceptionHandler_Class, ONLY: e, EXCEPTION_INFORMATION
IMPLICIT NONE
TYPE(FEDOF_) :: obj
TYPE(FEDomain_) :: dom
CLASS(AbstractMesh_), POINTER :: meshptr => NULL()
CHARACTER(*), PARAMETER :: &
filename = "../../FEMesh/examples/meshdata/small_tri3_mesh.h5", &
baseContinuity = "H1", &
baseInterpolation = "Heirarchical", &
testname = baseContinuity//" "//baseInterpolation// &
" GetMaxTotalConnectivity test"
INTEGER(I4B) :: order = 1
TYPE(HDF5File_) :: meshfile
LOGICAL(LGT) :: isok
CALL e%setQuietMode(EXCEPTION_INFORMATION, .TRUE.)
CALL meshfile%Initiate(filename, mode="READ")
CALL meshfile%OPEN()
CALL dom%Initiate(meshfile, '')
meshptr => dom%GetMeshPointer()
CALL test1
CALL test2
CALL test3
CALL dom%DEALLOCATE()
CALL meshfile%DEALLOCATE()
CONTAINS
SUBROUTINE test1
INTEGER(I4B) :: found, want
order = 1
CALL obj%Initiate(baseContinuity=baseContinuity, &
baseInterpolation=baseInterpolation, &
order=order, mesh=meshptr, &
ipType=TypeQuadratureOpt%equidistance)
found = obj%GetMaxTotalConnectivity()
want = 3
isok = found .EQ. want
CALL IS(found, want, testname//" test 1")
END SUBROUTINE test1
SUBROUTINE test2
INTEGER(I4B) :: found, want
order = 2
CALL obj%Initiate(baseContinuity=baseContinuity, &
baseInterpolation=baseInterpolation, &
order=order, mesh=meshptr, &
ipType=TypeQuadratureOpt%equidistance)
found = obj%GetMaxTotalConnectivity()
want = 6
isok = found .EQ. want
CALL IS(found, want, testname//" test 2")
END SUBROUTINE test2
SUBROUTINE test3
INTEGER(I4B) :: found, want
order = 3
CALL obj%Initiate(baseContinuity=baseContinuity, &
baseInterpolation=baseInterpolation, &
order=order, mesh=meshptr, &
ipType=TypeQuadratureOpt%equidistance)
found = obj%GetMaxTotalConnectivity()
want = 10
isok = found .EQ. want
CALL IS(found, want, testname//" test 3")
END SUBROUTINE test3
END PROGRAM main
Example 2
!> author: Vikas Sharma, Ph. D.
! date: 2025-06-08
! summary: Testing GetMaxTotalConnectivity method of FEDOF class
PROGRAM main
USE BaseType, ONLY: TypeQuadratureOpt
USE FEDOF_Class
USE FEDomain_Class
USE AbstractMesh_Class
USE HDF5File_Class
USE Display_Method
USE GlobalData
USE Test_Method
USE ExceptionHandler_Class, ONLY: e, EXCEPTION_INFORMATION
IMPLICIT NONE
TYPE(FEDOF_) :: obj
TYPE(FEDomain_) :: dom
CLASS(AbstractMesh_), POINTER :: meshptr => NULL()
CHARACTER(*), PARAMETER :: &
filename = "../../FEMesh/examples/meshdata/small_tri6_mesh.h5", &
baseContinuity = "H1", &
baseInterpolation = "Heirarchical", &
testname = baseContinuity//" "//baseInterpolation// &
" GetMaxTotalConnectivity test"
INTEGER(I4B) :: order = 1
TYPE(HDF5File_) :: meshfile
LOGICAL(LGT) :: isok
CALL e%setQuietMode(EXCEPTION_INFORMATION, .TRUE.)
CALL meshfile%Initiate(filename, mode="READ")
CALL meshfile%OPEN()
CALL dom%Initiate(meshfile, '')
meshptr => dom%GetMeshPointer()
CALL test1
CALL test2
CALL test3
CALL dom%DEALLOCATE()
CALL meshfile%DEALLOCATE()
CONTAINS
SUBROUTINE test1
INTEGER(I4B) :: found, want
order = 1
CALL obj%Initiate(baseContinuity=baseContinuity, &
baseInterpolation=baseInterpolation, &
order=order, mesh=meshptr, &
ipType=TypeQuadratureOpt%equidistance)
found = obj%GetMaxTotalConnectivity()
want = 3
isok = found .EQ. want
CALL IS(found, want, testname//" test 1")
END SUBROUTINE test1
SUBROUTINE test2
INTEGER(I4B) :: found, want
order = 2
CALL obj%Initiate(baseContinuity=baseContinuity, &
baseInterpolation=baseInterpolation, &
order=order, mesh=meshptr, &
ipType=TypeQuadratureOpt%equidistance)
found = obj%GetMaxTotalConnectivity()
want = 6
isok = found .EQ. want
CALL IS(found, want, testname//" test 2")
END SUBROUTINE test2
SUBROUTINE test3
INTEGER(I4B) :: found, want
order = 3
CALL obj%Initiate(baseContinuity=baseContinuity, &
baseInterpolation=baseInterpolation, &
order=order, mesh=meshptr, &
ipType=TypeQuadratureOpt%equidistance)
found = obj%GetMaxTotalConnectivity()
want = 10
isok = found .EQ. want
CALL IS(found, want, testname//" test 3")
END SUBROUTINE test3
END PROGRAM main