Add node-based surface parsing

This commit is contained in:
shenw
2026-06-24 18:20:17 +08:00
parent e17c04736b
commit aff82622f0
9 changed files with 182 additions and 22 deletions
+9 -3
View File
@@ -28,23 +28,29 @@ subroutine start_nset(set_index, item_pos, set_name_value)
elset_count(set_index) = 0
end subroutine start_elset
subroutine start_surface(surface_index, item_pos, surface_name_value)
subroutine start_surface(surface_index, item_pos, surface_name_value, &
surface_type_value)
integer, intent(in) :: surface_index
integer, intent(in) :: item_pos
character(len=*), intent(in) :: surface_name_value
character(len=*), intent(in) :: surface_type_value
surface_name(surface_index) = surface_name_value
if (allocated(surface_type)) surface_type(surface_index) = surface_type_value
surface_start(surface_index) = item_pos + 1
surface_count(surface_index) = 0
end subroutine start_surface
subroutine reset_surface(surface_index, item_pos, surface_name_value)
subroutine reset_surface(surface_index, item_pos, surface_name_value, &
surface_type_value)
integer, intent(in) :: surface_index
integer, intent(in) :: item_pos
character(len=*), intent(in) :: surface_name_value
character(len=*), intent(in) :: surface_type_value
integer :: pos
call start_surface(surface_index, item_pos, surface_name_value)
call start_surface(surface_index, item_pos, surface_name_value, &
surface_type_value)
if (.not. allocated(surface_owner)) return
do pos = 1, n_surface_item
if (surface_owner(pos) .eq. surface_index) surface_owner(pos) = 0
+13 -4
View File
@@ -874,8 +874,9 @@ contains
return
end if
call get_keyword_value(line, 'TYPE', type_value)
if (len_trim(type_value) .gt. 0 .and. trim(type_value) .ne. 'ELEMENT') then
call error_set(FEM_ERR_INPUT, 'only *SURFACE TYPE=ELEMENT is supported', ierr)
if (len_trim(type_value) .eq. 0) type_value = 'ELEMENT'
if (trim(type_value) .ne. 'ELEMENT' .and. trim(type_value) .ne. 'NODE') then
call error_set(FEM_ERR_INPUT, 'only *SURFACE TYPE=ELEMENT/NODE is supported', ierr)
return
end if
call get_keyword_value(line, 'OP', op_value)
@@ -887,11 +888,19 @@ contains
existing_surface = database_find_surface(name_value)
if (existing_surface .ne. 0) then
current_surface = existing_surface
if (trim(op_value) .eq. 'NEW') call reset_surface(current_surface, surface_pos, name_value)
if (trim(op_value) .eq. 'NEW') then
call reset_surface(current_surface, surface_pos, name_value, type_value)
else if (allocated(surface_type)) then
if (trim(surface_type(current_surface)) .ne. trim(type_value)) then
call error_set(FEM_ERR_INPUT, &
'*SURFACE OP=ADD cannot change surface TYPE', ierr)
return
end if
end if
else
used_surface_count = used_surface_count + 1
current_surface = used_surface_count
call start_surface(current_surface, surface_pos, name_value)
call start_surface(current_surface, surface_pos, name_value, type_value)
end if
ierr = FEM_SUCCESS
end subroutine fill_surface_keyword
+60 -8
View File
@@ -69,6 +69,7 @@ module fem_database
integer, allocatable :: surface_start(:)
integer, allocatable :: surface_count(:)
integer, allocatable :: surface_owner(:)
character(len=16), allocatable :: surface_type(:)
character(len=NAME_LEN), allocatable :: surface_target(:)
character(len=16), allocatable :: surface_face(:)
@@ -703,6 +704,7 @@ contains
if (allocated(surface_start)) deallocate(surface_start)
if (allocated(surface_count)) deallocate(surface_count)
if (allocated(surface_owner)) deallocate(surface_owner)
if (allocated(surface_type)) deallocate(surface_type)
if (allocated(surface_target)) deallocate(surface_target)
if (allocated(surface_face)) deallocate(surface_face)
@@ -711,7 +713,8 @@ contains
if (num_surfaces .gt. 0) then
allocate(surface_name(num_surfaces), surface_start(num_surfaces), &
surface_count(num_surfaces), stat=stat)
surface_count(num_surfaces), surface_type(num_surfaces), &
stat=stat)
if (stat .ne. 0) then
n_surface = 0
n_surface_item = 0
@@ -721,6 +724,7 @@ contains
surface_name = ' '
surface_start = 0
surface_count = 0
surface_type = 'ELEMENT'
end if
if (num_items .gt. 0) then
@@ -858,6 +862,7 @@ contains
if (allocated(surface_start)) surface_start = 0
if (allocated(surface_count)) surface_count = 0
if (allocated(surface_owner)) surface_owner = 0
if (allocated(surface_type)) surface_type = 'ELEMENT'
if (allocated(surface_target)) surface_target = ' '
if (allocated(surface_face)) surface_face = ' '
if (allocated(mat_name)) mat_name = ' '
@@ -1577,12 +1582,22 @@ contains
ierr)
return
end if
if (contact_target_is_node_surface(contact_pair_slave(item))) then
call error_set(FEM_ERR_INPUT, &
'contact pair slave node-based surface is not yet supported', ierr)
return
end if
if (.not. contact_surface_target_exists(contact_pair_master(item))) then
call error_set(FEM_ERR_INPUT, &
'contact pair master is not ALL, a surface, an element, or an element set', &
ierr)
return
end if
if (contact_target_is_node_surface(contact_pair_master(item))) then
call error_set(FEM_ERR_INPUT, &
'contact pair master node-based surface is not yet supported', ierr)
return
end if
if (contact_pair_penalty(item) .le. ZERO) then
call error_set(FEM_ERR_INPUT, 'contact pair penalty must be positive', ierr)
return
@@ -1623,13 +1638,24 @@ contains
do pos = 1, n_surface_item
if (.not. allocated(surface_owner)) exit
if (surface_owner(pos) .ne. item) cycle
if (.not. elem_or_elset_exists(surface_target(pos))) then
call error_set(FEM_ERR_INPUT, 'surface references unknown element or elset', ierr)
return
end if
if (.not. surface_face_label_valid(surface_face(pos))) then
call error_set(FEM_ERR_INPUT, 'surface has invalid face label', ierr)
return
if (trim(surface_type(item)) .eq. 'NODE') then
if (.not. node_or_nset_or_all_exists(surface_target(pos))) then
call error_set(FEM_ERR_INPUT, 'node surface references unknown node or nset', ierr)
return
end if
if (len_trim(surface_face(pos)) .ne. 0) then
call error_set(FEM_ERR_INPUT, 'node surface data line must not have a face label', ierr)
return
end if
else
if (.not. elem_or_elset_exists(surface_target(pos))) then
call error_set(FEM_ERR_INPUT, 'surface references unknown element or elset', ierr)
return
end if
if (.not. surface_face_label_valid(surface_face(pos))) then
call error_set(FEM_ERR_INPUT, 'surface has invalid face label', ierr)
return
end if
end if
end do
end do
@@ -1637,6 +1663,17 @@ contains
ierr = FEM_SUCCESS
end subroutine validate_surface_data
logical function contact_target_is_node_surface(target)
character(len=*), intent(in) :: target
integer :: surface_id
contact_target_is_node_surface = .false.
surface_id = database_find_surface(adjustl(target))
if (surface_id .le. 0) return
if (.not. allocated(surface_type)) return
contact_target_is_node_surface = trim(surface_type(surface_id)) .eq. 'NODE'
end function contact_target_is_node_surface
logical function contact_surface_target_exists(target)
character(len=*), intent(in) :: target
character(len=NAME_LEN) :: local_target
@@ -1654,6 +1691,20 @@ contains
end if
end function contact_surface_target_exists
logical function node_or_nset_or_all_exists(target)
character(len=*), intent(in) :: target
character(len=NAME_LEN) :: local_target
local_target = adjustl(target)
if (len_trim(local_target) .eq. 0) then
node_or_nset_or_all_exists = .false.
else if (trim(local_target) .eq. 'ALL' .or. trim(local_target) .eq. 'all') then
node_or_nset_or_all_exists = .true.
else
node_or_nset_or_all_exists = node_or_nset_exists(local_target)
end if
end function node_or_nset_or_all_exists
logical function surface_face_label_valid(label)
character(len=*), intent(in) :: label
character(len=16) :: local_label
@@ -1803,6 +1854,7 @@ contains
if (allocated(surface_start)) deallocate(surface_start)
if (allocated(surface_count)) deallocate(surface_count)
if (allocated(surface_owner)) deallocate(surface_owner)
if (allocated(surface_type)) deallocate(surface_type)
if (allocated(surface_target)) deallocate(surface_target)
if (allocated(surface_face)) deallocate(surface_face)
if (allocated(mat_name)) deallocate(mat_name)
+17 -3
View File
@@ -2,9 +2,10 @@ module fem_database_surface
use fem_precision, only: NAME_LEN
use fem_element_topology
use fem_database, only: n_surface, n_surface_item, surface_owner, &
surface_target, surface_face, database_find_surface, &
database_find_elset, database_find_elem, elset_start, &
elset_count, elset_items, elem_type, db_upper, &
surface_target, surface_face, surface_type, &
database_find_surface, database_find_elset, &
database_find_elem, elset_start, elset_count, &
elset_items, elem_type, db_upper, &
surface_face_normal_sign, &
surface_face_has_explicit_side
implicit none
@@ -113,6 +114,7 @@ contains
database_surface_contains_elem = .false.
if (surface_id .le. 0 .or. surface_id .gt. n_surface) return
if (.not. surface_is_element_type(surface_id)) return
if (.not. allocated(surface_owner)) return
if (.not. allocated(surface_target)) return
@@ -133,6 +135,7 @@ contains
db_surface_has_facet = .false.
if (surface_id .le. 0 .or. surface_id .gt. n_surface) return
if (.not. surface_is_element_type(surface_id)) return
if (.not. allocated(surface_owner)) return
if (.not. allocated(surface_target)) return
@@ -155,6 +158,7 @@ contains
surface_facet_normal_sign = 1
if (surface_id .le. 0 .or. surface_id .gt. n_surface) return
if (.not. surface_is_element_type(surface_id)) return
if (.not. allocated(surface_owner)) return
if (.not. allocated(surface_target)) return
@@ -177,6 +181,7 @@ contains
surface_facet_has_explicit_side = .false.
if (surface_id .le. 0 .or. surface_id .gt. n_surface) return
if (.not. surface_is_element_type(surface_id)) return
if (.not. allocated(surface_owner)) return
if (.not. allocated(surface_target)) return
@@ -192,6 +197,15 @@ contains
end do
end function surface_facet_has_explicit_side
logical function surface_is_element_type(surface_id)
integer, intent(in) :: surface_id
surface_is_element_type = .true.
if (.not. allocated(surface_type)) return
if (surface_id .lt. 1 .or. surface_id .gt. size(surface_type)) return
surface_is_element_type = trim(surface_type(surface_id)) .eq. 'ELEMENT'
end function surface_is_element_type
logical function surface_item_matches_elem(elem_ext, target)
integer, intent(in) :: elem_ext
character(len=*), intent(in) :: target