Add basic rigid plane contact support

This commit is contained in:
shenw
2026-06-22 23:33:51 +08:00
parent 473d97891c
commit 131d7eb0c3
5 changed files with 403 additions and 0 deletions
+102
View File
@@ -21,6 +21,7 @@ module fem_database
integer :: nrobin = 0
integer :: nmpc = 0
integer :: nmpc_term = 0
integer :: ncontact_plane = 0
real(rk), allocatable :: coord0(:,:)
real(rk), allocatable :: coord(:,:)
@@ -133,6 +134,12 @@ module fem_database
integer, allocatable :: mpc_dof(:)
real(rk), allocatable :: mpc_coeff(:)
character(len=NAME_LEN), allocatable :: contact_target(:)
real(rk), allocatable :: contact_normal(:,:)
real(rk), allocatable :: contact_offset(:)
real(rk), allocatable :: contact_penalty(:)
real(rk), allocatable :: contact_damping(:)
contains
subroutine database_allocate_mesh(num_nodes, num_elems, ierr)
@@ -546,6 +553,43 @@ contains
ierr = FEM_SUCCESS
end subroutine database_allocate_mpc
subroutine database_allocate_contact(num_planes, ierr)
integer, intent(in) :: num_planes
integer, intent(out) :: ierr
integer :: stat
if (num_planes .lt. 0) then
call error_set(FEM_ERR_INPUT, 'number of contact planes must be non-negative', ierr)
return
end if
if (allocated(contact_target)) deallocate(contact_target)
if (allocated(contact_normal)) deallocate(contact_normal)
if (allocated(contact_offset)) deallocate(contact_offset)
if (allocated(contact_penalty)) deallocate(contact_penalty)
if (allocated(contact_damping)) deallocate(contact_damping)
ncontact_plane = num_planes
if (num_planes .gt. 0) then
allocate(contact_target(num_planes), contact_normal(NDIM,num_planes), &
contact_offset(num_planes), contact_penalty(num_planes), &
contact_damping(num_planes), stat=stat)
if (stat .ne. 0) then
ncontact_plane = 0
call error_set(FEM_ERR_INTERNAL, 'failed to allocate contact plane arrays', ierr)
return
end if
contact_target = ' '
contact_normal = ZERO
contact_offset = ZERO
contact_penalty = ZERO
contact_damping = ZERO
end if
ierr = FEM_SUCCESS
end subroutine database_allocate_contact
subroutine database_allocate_basic(num_nodes, num_elems, num_dof, ierr)
integer, intent(in) :: num_nodes
integer, intent(in) :: num_elems
@@ -721,6 +765,11 @@ contains
if (allocated(mpc_node)) mpc_node = 0
if (allocated(mpc_dof)) mpc_dof = 0
if (allocated(mpc_coeff)) mpc_coeff = ZERO
if (allocated(contact_target)) contact_target = ' '
if (allocated(contact_normal)) contact_normal = ZERO
if (allocated(contact_offset)) contact_offset = ZERO
if (allocated(contact_penalty)) contact_penalty = ZERO
if (allocated(contact_damping)) contact_damping = ZERO
ierr = FEM_SUCCESS
end subroutine database_initialize
@@ -949,6 +998,9 @@ contains
if (ierr .ne. FEM_SUCCESS) return
call validate_mpc_data(ierr)
if (ierr .ne. FEM_SUCCESS) return
call validate_contact_data(ierr)
end subroutine database_validate_model
subroutine validate_materials(ierr)
@@ -1283,6 +1335,50 @@ contains
ierr = FEM_SUCCESS
end subroutine validate_mpc_data
subroutine validate_contact_data(ierr)
integer, intent(out) :: ierr
integer :: item
real(rk) :: normal_norm
do item = 1, ncontact_plane
if (.not. contact_target_exists(contact_target(item))) then
call error_set(FEM_ERR_INPUT, 'contact target is not ALL, a node, or a node set', ierr)
return
end if
normal_norm = sqrt(sum(contact_normal(:,item) * contact_normal(:,item)))
if (normal_norm .le. tiny(ONE)) then
call error_set(FEM_ERR_INPUT, 'contact plane normal must be non-zero', ierr)
return
end if
if (contact_penalty(item) .le. ZERO) then
call error_set(FEM_ERR_INPUT, 'contact plane penalty must be positive', ierr)
return
end if
if (contact_damping(item) .lt. ZERO) then
call error_set(FEM_ERR_INPUT, 'contact plane damping must be non-negative', ierr)
return
end if
end do
ierr = FEM_SUCCESS
end subroutine validate_contact_data
logical function contact_target_exists(target)
character(len=*), intent(in) :: target
character(len=NAME_LEN) :: local_target
local_target = adjustl(target)
contact_target_exists = .false.
if (len_trim(local_target) .eq. 0) then
contact_target_exists = .true.
else if (trim(local_target) .eq. 'ALL' .or. trim(local_target) .eq. 'all') then
contact_target_exists = .true.
else
contact_target_exists = node_or_nset_exists(local_target)
end if
end function contact_target_exists
logical function node_or_nset_exists(target)
character(len=*), intent(in) :: target
integer :: id
@@ -1410,6 +1506,11 @@ contains
if (allocated(mpc_node)) deallocate(mpc_node)
if (allocated(mpc_dof)) deallocate(mpc_dof)
if (allocated(mpc_coeff)) deallocate(mpc_coeff)
if (allocated(contact_target)) deallocate(contact_target)
if (allocated(contact_normal)) deallocate(contact_normal)
if (allocated(contact_offset)) deallocate(contact_offset)
if (allocated(contact_penalty)) deallocate(contact_penalty)
if (allocated(contact_damping)) deallocate(contact_damping)
nnode = 0
nelem = 0
@@ -1428,6 +1529,7 @@ contains
nrobin = 0
nmpc = 0
nmpc_term = 0
ncontact_plane = 0
ierr = FEM_SUCCESS
end subroutine database_finalize