From 29d42802360775fd022f429806db596cc73b2cc1 Mon Sep 17 00:00:00 2001 From: shenw Date: Wed, 24 Jun 2026 19:26:51 +0800 Subject: [PATCH] Add analytical rigid plane contact --- docs/v4_development_plan.md | 8 +- src/boundary/fem_contact.f90 | 338 ++++++++++++++++++ src/input/fem_inp_helpers.f90 | 66 ++++ src/input/fem_inp_reader.f90 | 6 +- src/mesh/fem_database.f90 | 165 +++++---- src/mesh/fem_database_state.f90 | 98 +++++ tests/data/s4_contact_analytical_plane.inp | 26 ++ ...tact_pair_surface_bad_analytical_line.inp} | 2 +- tests/module/test_contact.f90 | 49 +++ tests/module/test_implicit_inp.f90 | 36 +- 10 files changed, 703 insertions(+), 91 deletions(-) create mode 100644 tests/data/s4_contact_analytical_plane.inp rename tests/data/{s4_contact_pair_surface_bad_type.inp => s4_contact_pair_surface_bad_analytical_line.inp} (91%) diff --git a/docs/v4_development_plan.md b/docs/v4_development_plan.md index 213032b..0fb7c2f 100644 --- a/docs/v4_development_plan.md +++ b/docs/v4_development_plan.md @@ -620,6 +620,9 @@ FemLite 0.4.x 定位为: - facet 匹配函数仅对 `ELEMENT` surface 生效,避免把 node surface 的节点号误匹配为单元号。 - 新增 `*SURFACE INTERACTION` / `*CONTACT PROPERTY` 子集,支持法向 penalty、damping、search 和 `*FRICTION` 摩擦系数。 - `*CONTACT PAIR` 支持 `INTERACTION=` / `PROPERTY=` 名称绑定,pair 级显式参数优先,未显式给出的参数从 contact property 继承。 +- 新增 `*SURFACE, TYPE=ANALYTICAL` 的刚性平面子集,数据行为 `PLANE, nx, ny, nz, offset`。 +- 当 analytical surface 作为 contact pair master 时,接触力/切线接入已有刚性平面 penalty 路径;slave 当前支持 `ALL`、节点、节点集或 node-based surface。 +- analytical contact pair 当前不处理摩擦,后续进入 V4.3 摩擦正则化/积分点历史统一处理。 - 数据库全局状态拆出到 `fem_database_state`,主数据库行为模块保持在源文件硬性尺寸限制内。 已补充测试: @@ -627,11 +630,12 @@ FemLite 0.4.x 定位为: - `tests/data/s4_node_surface.inp`:node-based surface 解析和数据库校验。 - `tests/data/s4_contact_property.inp`:contact property 解析、friction 读取和 contact pair 参数继承。 - `tests/data/s4_contact_pair_unknown_property.inp`:未知 `INTERACTION` 名称在模型构建阶段报错。 +- `tests/data/s4_contact_analytical_plane.inp`:analytical rigid plane surface 解析、contact pair 绑定和模型构建。 - `implicit_inp`:检查 `surface_type`、node target、facet 匹配隔离、node surface 查询接口和 `fem_build_model`。 -- `contact`:确认旧 element surface/contact pair 路径不回退。 +- `contact`:确认旧 element surface/contact pair 路径不回退,并验证 analytical plane contact pair 节点力。 - `source_size`:确认数据库状态拆分后源文件不超过硬性行数限制。 后续: - 在节点-面接触或后续 contact pair 扩展中接入 node-based slave surface。 -- 增加 analytic rigid surface 子集。 +- 扩展 analytical surface 到更完整的 Abaqus segments/cylinder/sphere 子集。 diff --git a/src/boundary/fem_contact.f90 b/src/boundary/fem_contact.f90 index 9615d6d..82156ea 100644 --- a/src/boundary/fem_contact.f90 +++ b/src/boundary/fem_contact.f90 @@ -5,6 +5,7 @@ module fem_contact use fem_sparse_csr use fem_coupling use fem_contact_state + use fem_database_surface, only: db_surface_node_count, db_get_surface_nodes use fem_contact_force, only: apply_contact_pair_forces use fem_contact_tangent, only: apply_contact_pair_tangent implicit none @@ -32,6 +33,8 @@ contains call apply_contact_plane(plane, ierr) if (ierr .ne. FEM_SUCCESS) return end do + call apply_analytic_pair_forces(ierr) + if (ierr .ne. FEM_SUCCESS) return call apply_contact_pair_forces(ierr) if (ierr .ne. FEM_SUCCESS) return @@ -48,6 +51,8 @@ contains call apply_contact_plane_tangent(plane, kmat, velocity_scale, ierr) if (ierr .ne. FEM_SUCCESS) return end do + call apply_analytic_pair_tangents(kmat, velocity_scale, ierr) + if (ierr .ne. FEM_SUCCESS) return call apply_contact_pair_tangent(kmat, velocity_scale, ierr) if (ierr .ne. FEM_SUCCESS) return @@ -286,6 +291,339 @@ contains ierr = FEM_SUCCESS end subroutine apply_contact_node_tangent + subroutine apply_analytic_pair_forces(ierr) + integer, intent(out) :: ierr + integer :: pair + real(rk) :: normal(NDIM) + real(rk) :: offset + + do pair = 1, ncontact_pair + if (.not. pair_has_analytic_master(pair)) cycle + call pair_analytic_plane(pair, normal, offset, ierr) + if (ierr .ne. FEM_SUCCESS) return + call apply_analytic_force_target(pair, normal, offset, ierr) + if (ierr .ne. FEM_SUCCESS) return + end do + ierr = FEM_SUCCESS + end subroutine apply_analytic_pair_forces + + subroutine apply_analytic_pair_tangents(kmat, velocity_scale, ierr) + type(csr_matrix), intent(inout) :: kmat + real(rk), intent(in) :: velocity_scale + integer, intent(out) :: ierr + integer :: pair + real(rk) :: normal(NDIM) + real(rk) :: offset + + do pair = 1, ncontact_pair + if (.not. pair_has_analytic_master(pair)) cycle + call pair_analytic_plane(pair, normal, offset, ierr) + if (ierr .ne. FEM_SUCCESS) return + call apply_analytic_tangent_target(pair, normal, offset, kmat, & + velocity_scale, ierr) + if (ierr .ne. FEM_SUCCESS) return + end do + ierr = FEM_SUCCESS + end subroutine apply_analytic_pair_tangents + + logical function pair_has_analytic_master(pair) + integer, intent(in) :: pair + integer :: surface_id + + pair_has_analytic_master = .false. + if (pair .lt. 1 .or. pair .gt. ncontact_pair) return + surface_id = database_find_surface(contact_pair_master(pair)) + if (surface_id .le. 0) return + pair_has_analytic_master = trim(surface_type(surface_id)) .eq. 'ANALYTICAL' + end function pair_has_analytic_master + + subroutine pair_analytic_plane(pair, normal, offset, ierr) + integer, intent(in) :: pair + real(rk), intent(out) :: normal(NDIM) + real(rk), intent(out) :: offset + integer, intent(out) :: ierr + integer :: surface_id + real(rk) :: norm_n + + surface_id = database_find_surface(contact_pair_master(pair)) + if (surface_id .le. 0) then + call error_set(FEM_ERR_INPUT, 'analytical contact pair has unknown master', ierr) + return + end if + normal = surface_plane_normal(:,surface_id) + norm_n = sqrt(sum(normal * normal)) + if (norm_n .le. tiny(ONE)) then + call error_set(FEM_ERR_INPUT, 'analytical contact normal must be non-zero', ierr) + return + end if + normal = normal / norm_n + offset = surface_plane_offset(surface_id) / norm_n + ierr = FEM_SUCCESS + end subroutine pair_analytic_plane + + subroutine apply_analytic_force_target(pair, normal, offset, ierr) + integer, intent(in) :: pair + real(rk), intent(in) :: normal(NDIM) + real(rk), intent(in) :: offset + integer, intent(out) :: ierr + + call apply_analytic_target_nodes(pair, normal, offset, .false., & + 0.0_rk, ierr) + end subroutine apply_analytic_force_target + + subroutine apply_analytic_tangent_target(pair, normal, offset, kmat, & + velocity_scale, ierr) + integer, intent(in) :: pair + real(rk), intent(in) :: normal(NDIM) + real(rk), intent(in) :: offset + type(csr_matrix), intent(inout) :: kmat + real(rk), intent(in) :: velocity_scale + integer, intent(out) :: ierr + + call apply_analytic_target_nodes(pair, normal, offset, .true., & + velocity_scale, ierr, kmat) + end subroutine apply_analytic_tangent_target + + subroutine apply_analytic_target_nodes(pair, normal, offset, tangent_mode, & + velocity_scale, ierr, kmat) + integer, intent(in) :: pair + real(rk), intent(in) :: normal(NDIM) + real(rk), intent(in) :: offset + logical, intent(in) :: tangent_mode + real(rk), intent(in) :: velocity_scale + integer, intent(out) :: ierr + type(csr_matrix), intent(inout), optional :: kmat + character(len=NAME_LEN) :: target + + target = adjustl(contact_pair_slave(pair)) + if (len_trim(target) .eq. 0 .or. trim(target) .eq. 'ALL' .or. & + trim(target) .eq. 'all') then + call apply_analytic_all_nodes(pair, normal, offset, tangent_mode, & + velocity_scale, ierr, kmat) + else + call apply_analytic_named_target(pair, target, normal, offset, & + tangent_mode, velocity_scale, ierr, kmat) + end if + end subroutine apply_analytic_target_nodes + + subroutine apply_analytic_all_nodes(pair, normal, offset, tangent_mode, & + velocity_scale, ierr, kmat) + integer, intent(in) :: pair + real(rk), intent(in) :: normal(NDIM) + real(rk), intent(in) :: offset + logical, intent(in) :: tangent_mode + real(rk), intent(in) :: velocity_scale + integer, intent(out) :: ierr + type(csr_matrix), intent(inout), optional :: kmat + integer :: node + + do node = 1, nnode + call apply_analytic_node(pair, node, normal, offset, tangent_mode, & + velocity_scale, ierr, kmat) + if (ierr .ne. FEM_SUCCESS) return + end do + ierr = FEM_SUCCESS + end subroutine apply_analytic_all_nodes + + subroutine apply_analytic_named_target(pair, target, normal, offset, & + tangent_mode, velocity_scale, ierr, kmat) + integer, intent(in) :: pair + character(len=*), intent(in) :: target + real(rk), intent(in) :: normal(NDIM) + real(rk), intent(in) :: offset + logical, intent(in) :: tangent_mode + real(rk), intent(in) :: velocity_scale + integer, intent(out) :: ierr + type(csr_matrix), intent(inout), optional :: kmat + integer :: external_id + integer :: ios + integer :: node + integer :: set_id + + read(target,*,iostat=ios) external_id + if (ios .eq. 0) then + node = database_find_node(external_id) + if (node .eq. 0) then + call error_set(FEM_ERR_INPUT, 'analytical contact slave node is unknown', ierr) + return + end if + call apply_analytic_node(pair, node, normal, offset, tangent_mode, & + velocity_scale, ierr, kmat) + return + end if + + set_id = database_find_nset(target) + if (set_id .ne. 0) then + call apply_analytic_nset(pair, set_id, normal, offset, tangent_mode, & + velocity_scale, ierr, kmat) + else + call apply_analytic_node_surface(pair, target, normal, offset, & + tangent_mode, velocity_scale, ierr, kmat) + end if + end subroutine apply_analytic_named_target + + subroutine apply_analytic_nset(pair, set_id, normal, offset, tangent_mode, & + velocity_scale, ierr, kmat) + integer, intent(in) :: pair + integer, intent(in) :: set_id + real(rk), intent(in) :: normal(NDIM) + real(rk), intent(in) :: offset + logical, intent(in) :: tangent_mode + real(rk), intent(in) :: velocity_scale + integer, intent(out) :: ierr + type(csr_matrix), intent(inout), optional :: kmat + integer :: pos + integer :: node + + do pos = nset_start(set_id), nset_start(set_id) + nset_count(set_id) - 1 + node = database_find_node(nset_items(pos)) + if (node .eq. 0) then + call error_set(FEM_ERR_INPUT, 'analytical contact nset has unknown node', ierr) + return + end if + call apply_analytic_node(pair, node, normal, offset, tangent_mode, & + velocity_scale, ierr, kmat) + if (ierr .ne. FEM_SUCCESS) return + end do + ierr = FEM_SUCCESS + end subroutine apply_analytic_nset + + subroutine apply_analytic_node_surface(pair, target, normal, offset, & + tangent_mode, velocity_scale, ierr, kmat) + integer, intent(in) :: pair + character(len=*), intent(in) :: target + real(rk), intent(in) :: normal(NDIM) + real(rk), intent(in) :: offset + logical, intent(in) :: tangent_mode + real(rk), intent(in) :: velocity_scale + integer, intent(out) :: ierr + type(csr_matrix), intent(inout), optional :: kmat + integer, allocatable :: node_ids(:) + integer :: count + integer :: out_count + integer :: item + integer :: node + integer :: stat + + call db_surface_node_count(target, count, ierr) + if (ierr .ne. FEM_SUCCESS) return + allocate(node_ids(max(1, count)), stat=stat) + if (stat .ne. 0) then + call error_set(FEM_ERR_INTERNAL, 'failed to allocate analytical contact nodes', ierr) + return + end if + call db_get_surface_nodes(target, count, node_ids, out_count, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 + do item = 1, out_count + node = database_find_node(node_ids(item)) + call apply_analytic_node(pair, node, normal, offset, tangent_mode, & + velocity_scale, ierr, kmat) + if (ierr .ne. FEM_SUCCESS) go to 900 + end do +900 continue + deallocate(node_ids) + end subroutine apply_analytic_node_surface + + subroutine apply_analytic_node(pair, node, normal, offset, tangent_mode, & + velocity_scale, ierr, kmat) + integer, intent(in) :: pair + integer, intent(in) :: node + real(rk), intent(in) :: normal(NDIM) + real(rk), intent(in) :: offset + logical, intent(in) :: tangent_mode + real(rk), intent(in) :: velocity_scale + integer, intent(out) :: ierr + type(csr_matrix), intent(inout), optional :: kmat + real(rk) :: gap + real(rk) :: velocity(NDIM) + real(rk) :: position(NDIM) + integer :: idir + integer :: dof + + position = coord0(:,node) + velocity = ZERO + do idir = 1, NDIM + dof = dof_id(idir,node) + if (dof .gt. 0) then + position(idir) = position(idir) + u(dof) + if (allocated(v)) velocity(idir) = v(dof) + end if + end do + gap = dot_product(normal, position) - offset + if (gap .lt. ZERO) then + if (tangent_mode) then + call add_analytic_node_tangent(pair, node, normal, velocity, & + velocity_scale, kmat, ierr) + else + call add_analytic_node_force(pair, node, normal, velocity, -gap, ierr) + end if + return + end if + ierr = FEM_SUCCESS + end subroutine apply_analytic_node + + subroutine add_analytic_node_force(pair, node, normal, velocity, penetration, ierr) + integer, intent(in) :: pair + integer, intent(in) :: node + real(rk), intent(in) :: normal(NDIM) + real(rk), intent(in) :: velocity(NDIM) + real(rk), intent(in) :: penetration + integer, intent(out) :: ierr + real(rk) :: force_mag + real(rk) :: force_vec(NDIM) + real(rk) :: vn + integer :: idir + integer :: dof + + vn = dot_product(normal, velocity) + force_mag = contact_pair_penalty(pair) * penetration + if (vn .lt. ZERO) force_mag = force_mag + contact_pair_damping(pair) * (-vn) + force_vec = force_mag * normal + do idir = 1, NDIM + dof = dof_id(idir,node) + if (dof .gt. 0) fcontact(dof) = fcontact(dof) + force_vec(idir) + end do + call contact_record_status(pair, penetration, force_vec) + ierr = FEM_SUCCESS + end subroutine add_analytic_node_force + + subroutine add_analytic_node_tangent(pair, node, normal, velocity, & + velocity_scale, kmat, ierr) + integer, intent(in) :: pair + integer, intent(in) :: node + real(rk), intent(in) :: normal(NDIM) + real(rk), intent(in) :: velocity(NDIM) + real(rk), intent(in) :: velocity_scale + type(csr_matrix), intent(inout), optional :: kmat + integer, intent(out) :: ierr + real(rk) :: coeff + integer :: idir + integer :: jdir + integer :: row + integer :: col + + if (.not. present(kmat)) then + ierr = FEM_SUCCESS + return + end if + coeff = contact_pair_penalty(pair) + if (dot_product(normal, velocity) .lt. ZERO) then + coeff = coeff + velocity_scale * contact_pair_damping(pair) + end if + do idir = 1, NDIM + row = dof_id(idir,node) + if (row .le. 0) cycle + do jdir = 1, NDIM + col = dof_id(jdir,node) + if (col .gt. 0) then + call csr_add_value(kmat, row, col, coeff * normal(idir) * normal(jdir), ierr) + if (ierr .ne. FEM_SUCCESS) return + end if + end do + end do + ierr = FEM_SUCCESS + end subroutine add_analytic_node_tangent + diff --git a/src/input/fem_inp_helpers.f90 b/src/input/fem_inp_helpers.f90 index ea4695e..86b89df 100644 --- a/src/input/fem_inp_helpers.f90 +++ b/src/input/fem_inp_helpers.f90 @@ -37,6 +37,8 @@ subroutine start_nset(set_index, item_pos, set_name_value) surface_name(surface_index) = surface_name_value if (allocated(surface_type)) surface_type(surface_index) = surface_type_value + if (allocated(surface_plane_normal)) surface_plane_normal(:,surface_index) = ZERO + if (allocated(surface_plane_offset)) surface_plane_offset(surface_index) = ZERO surface_start(surface_index) = item_pos + 1 surface_count(surface_index) = 0 end subroutine start_surface @@ -84,6 +86,10 @@ subroutine start_nset(set_index, item_pos, set_name_value) call error_set(FEM_ERR_INPUT, '*SURFACE has more data lines than counted', ierr) return end if + if (trim(surface_type(surface_index)) .eq. 'ANALYTICAL') then + call add_analytical_surface_line(line, surface_index, item_pos, ierr) + return + end if call csv_token(line, 1, token) if (len_trim(token) .eq. 0) then @@ -109,6 +115,66 @@ subroutine start_nset(set_index, item_pos, set_name_value) ierr = FEM_SUCCESS end subroutine add_surface_line + subroutine add_analytical_surface_line(line, surface_index, item_pos, ierr) + character(len=*), intent(in) :: line + integer, intent(in) :: surface_index + integer, intent(inout) :: item_pos + integer, intent(out) :: ierr + character(len=LINE_LEN) :: token + character(len=NAME_LEN) :: kind + real(rk) :: normal(NDIM) + real(rk) :: offset + integer :: idir + + if (surface_count(surface_index) .gt. 0) then + call error_set(FEM_ERR_INPUT, 'analytical surface supports one plane line', ierr) + return + end if + call csv_token(line, 1, token) + call strip_keyword_quotes(token) + call to_upper(token, kind) + if (trim(kind) .ne. 'PLANE') then + call error_set(FEM_ERR_INPUT, 'analytical surface line must start with PLANE', ierr) + return + end if + do idir = 1, NDIM + call read_surface_real(line, idir + 1, normal(idir), ierr) + if (ierr .ne. FEM_SUCCESS) return + end do + call read_surface_real(line, 5, offset, ierr) + if (ierr .ne. FEM_SUCCESS) return + + item_pos = item_pos + 1 + if (allocated(surface_owner)) surface_owner(item_pos) = surface_index + surface_target(item_pos) = 'PLANE' + surface_face(item_pos) = ' ' + surface_plane_normal(:,surface_index) = normal + surface_plane_offset(surface_index) = offset + surface_count(surface_index) = surface_count(surface_index) + 1 + ierr = FEM_SUCCESS + end subroutine add_analytical_surface_line + + subroutine read_surface_real(line, field_index, value, ierr) + character(len=*), intent(in) :: line + integer, intent(in) :: field_index + real(rk), intent(out) :: value + integer, intent(out) :: ierr + character(len=LINE_LEN) :: token + integer :: ios + + call csv_token(line, field_index, token) + if (len_trim(token) .eq. 0) then + call error_set(FEM_ERR_INPUT, 'analytical surface plane data is incomplete', ierr) + return + end if + read(token,*,iostat=ios) value + if (ios .ne. 0) then + call error_set(FEM_ERR_INPUT, 'failed to parse analytical surface plane data', ierr) + return + end if + ierr = FEM_SUCCESS + end subroutine read_surface_real + subroutine add_set_line(line, generate_mode, set_index, item_pos, is_node_set, ierr) character(len=*), intent(in) :: line logical, intent(in) :: generate_mode diff --git a/src/input/fem_inp_reader.f90 b/src/input/fem_inp_reader.f90 index 1c8eb01..4b84e0d 100644 --- a/src/input/fem_inp_reader.f90 +++ b/src/input/fem_inp_reader.f90 @@ -924,8 +924,10 @@ contains end if call get_keyword_value(line, 'TYPE', type_value) 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) + if (trim(type_value) .ne. 'ELEMENT' .and. trim(type_value) .ne. 'NODE' .and. & + trim(type_value) .ne. 'ANALYTICAL') then + call error_set(FEM_ERR_INPUT, & + 'only *SURFACE TYPE=ELEMENT/NODE/ANALYTICAL is supported', ierr) return end if call get_keyword_value(line, 'OP', op_value) diff --git a/src/mesh/fem_database.f90 b/src/mesh/fem_database.f90 index 9332868..f400761 100644 --- a/src/mesh/fem_database.f90 +++ b/src/mesh/fem_database.f90 @@ -548,7 +548,7 @@ contains return end if - call db_free_contact_property_arrays() + call db_state_free_contact_props() n_contact_property = num_props if (num_props .gt. 0) then @@ -591,13 +591,7 @@ contains return end if - if (allocated(surface_name)) deallocate(surface_name) - 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) + call db_state_free_surface_arrays() n_surface = num_surfaces n_surface_item = num_items @@ -605,6 +599,8 @@ contains if (num_surfaces .gt. 0) then allocate(surface_name(num_surfaces), surface_start(num_surfaces), & surface_count(num_surfaces), surface_type(num_surfaces), & + surface_plane_normal(NDIM,num_surfaces), & + surface_plane_offset(num_surfaces), & stat=stat) if (stat .ne. 0) then n_surface = 0 @@ -616,6 +612,8 @@ contains surface_start = 0 surface_count = 0 surface_type = 'ELEMENT' + surface_plane_normal = ZERO + surface_plane_offset = ZERO end if if (num_items .gt. 0) then @@ -749,13 +747,7 @@ contains if (allocated(elset_start)) elset_start = 0 if (allocated(elset_count)) elset_count = 0 if (allocated(elset_items)) elset_items = 0 - if (allocated(surface_name)) surface_name = ' ' - 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 = ' ' + call db_state_init_surface_arrays() if (allocated(mat_name)) mat_name = ' ' if (allocated(mat_plastic_model)) mat_plastic_model = 'ELASTIC' if (allocated(mat_rate_model)) mat_rate_model = 'NONE' @@ -1572,7 +1564,19 @@ contains ierr) return end if - if (contact_target_is_node_surface(contact_pair_slave(item))) then + if (contact_target_is_analytic(contact_pair_slave(item))) then + call error_set(FEM_ERR_INPUT, & + 'contact pair slave analytical surface is not supported', ierr) + return + end if + if (contact_target_is_analytic(contact_pair_master(item))) then + if (.not. contact_plane_slave_ok(contact_pair_slave(item))) then + call error_set(FEM_ERR_INPUT, & + 'analytical contact pair slave must be ALL, a node, nset, or node surface', & + ierr) + return + end if + else 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 @@ -1637,7 +1641,11 @@ contains call error_set(FEM_ERR_INPUT, 'node surface data line must not have a face label', ierr) return end if - else + else if (trim(surface_type(item)) .eq. 'ANALYTICAL') then + call validate_analytical_surface(item, ierr) + if (ierr .ne. FEM_SUCCESS) return + exit + else if (trim(surface_type(item)) .eq. 'ELEMENT') then if (.not. elem_or_elset_exists(surface_target(pos))) then call error_set(FEM_ERR_INPUT, 'surface references unknown element or elset', ierr) return @@ -1646,6 +1654,9 @@ contains call error_set(FEM_ERR_INPUT, 'surface has invalid face label', ierr) return end if + else + call error_set(FEM_ERR_INPUT, 'surface has unsupported TYPE', ierr) + return end if end do end do @@ -1653,6 +1664,36 @@ contains ierr = FEM_SUCCESS end subroutine validate_surface_data + subroutine validate_analytical_surface(surface_id, ierr) + integer, intent(in) :: surface_id + integer, intent(out) :: ierr + integer :: pos + real(rk) :: normal_norm + + if (surface_count(surface_id) .ne. 1) then + call error_set(FEM_ERR_INPUT, 'analytical surface requires one PLANE line', ierr) + return + end if + normal_norm = sqrt(sum(surface_plane_normal(:,surface_id) * & + surface_plane_normal(:,surface_id))) + if (normal_norm .le. tiny(ONE)) then + call error_set(FEM_ERR_INPUT, 'analytical surface plane normal must be non-zero', ierr) + return + end if + do pos = 1, n_surface_item + if (surface_owner(pos) .ne. surface_id) cycle + if (trim(surface_target(pos)) .ne. 'PLANE') then + call error_set(FEM_ERR_INPUT, 'analytical surface supports only PLANE', ierr) + return + end if + if (len_trim(surface_face(pos)) .ne. 0) then + call error_set(FEM_ERR_INPUT, 'analytical surface line must not have a face label', ierr) + return + end if + end do + ierr = FEM_SUCCESS + end subroutine validate_analytical_surface + logical function contact_target_is_node_surface(target) character(len=*), intent(in) :: target integer :: surface_id @@ -1664,6 +1705,17 @@ contains contact_target_is_node_surface = trim(surface_type(surface_id)) .eq. 'NODE' end function contact_target_is_node_surface + logical function contact_target_is_analytic(target) + character(len=*), intent(in) :: target + integer :: surface_id + + contact_target_is_analytic = .false. + surface_id = database_find_surface(adjustl(target)) + if (surface_id .le. 0) return + if (.not. allocated(surface_type)) return + contact_target_is_analytic = trim(surface_type(surface_id)) .eq. 'ANALYTICAL' + end function contact_target_is_analytic + logical function contact_surface_target_exists(target) character(len=*), intent(in) :: target character(len=NAME_LEN) :: local_target @@ -1681,6 +1733,13 @@ contains end if end function contact_surface_target_exists + logical function contact_plane_slave_ok(target) + character(len=*), intent(in) :: target + + contact_plane_slave_ok = & + node_or_nset_or_all_exists(target) .or. contact_target_is_node_surface(target) + end function contact_plane_slave_ok + logical function node_or_nset_or_all_exists(target) character(len=*), intent(in) :: target character(len=NAME_LEN) :: local_target @@ -1840,13 +1899,7 @@ contains if (allocated(elset_start)) deallocate(elset_start) if (allocated(elset_count)) deallocate(elset_count) if (allocated(elset_items)) deallocate(elset_items) - if (allocated(surface_name)) deallocate(surface_name) - 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) + call db_state_free_surface_arrays() if (allocated(mat_name)) deallocate(mat_name) if (allocated(mat_plastic_model)) deallocate(mat_plastic_model) if (allocated(mat_rate_model)) deallocate(mat_rate_model) @@ -1918,73 +1971,15 @@ contains end subroutine database_finalize subroutine db_free_contact_arrays() - 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) - if (allocated(contact_pair_slave)) deallocate(contact_pair_slave) - if (allocated(contact_pair_master)) deallocate(contact_pair_master) - if (allocated(contact_pair_property)) deallocate(contact_pair_property) - if (allocated(contact_pair_penalty)) deallocate(contact_pair_penalty) - if (allocated(contact_pair_damping)) deallocate(contact_pair_damping) - if (allocated(contact_pair_search)) deallocate(contact_pair_search) - if (allocated(contact_pair_friction)) deallocate(contact_pair_friction) - if (allocated(contact_pair_penalty_set)) deallocate(contact_pair_penalty_set) - if (allocated(contact_pair_damping_set)) deallocate(contact_pair_damping_set) - if (allocated(contact_pair_search_set)) deallocate(contact_pair_search_set) - if (allocated(contact_pair_friction_set)) deallocate(contact_pair_friction_set) - if (allocated(contact_pair_active)) deallocate(contact_pair_active) - if (allocated(contact_pair_work)) deallocate(contact_pair_work) - if (allocated(contact_pair_max_penetration)) deallocate(contact_pair_max_penetration) - if (allocated(contact_pair_force_norm)) deallocate(contact_pair_force_norm) - if (allocated(contact_pair_tangent_force)) deallocate(contact_pair_tangent_force) - if (allocated(contact_pair_slip)) deallocate(contact_pair_slip) - if (allocated(contact_pair_stick_count)) deallocate(contact_pair_stick_count) - if (allocated(contact_pair_slip_count)) deallocate(contact_pair_slip_count) - call db_free_contact_property_arrays() + call db_state_free_contact_arrays() end subroutine db_free_contact_arrays subroutine db_free_contact_property_arrays() - if (allocated(contact_property_name)) deallocate(contact_property_name) - if (allocated(contact_property_penalty)) deallocate(contact_property_penalty) - if (allocated(contact_property_damping)) deallocate(contact_property_damping) - if (allocated(contact_property_search)) deallocate(contact_property_search) - if (allocated(contact_property_friction)) deallocate(contact_property_friction) - if (allocated(contact_property_penalty_set)) deallocate(contact_property_penalty_set) - if (allocated(contact_property_damping_set)) deallocate(contact_property_damping_set) - if (allocated(contact_property_search_set)) deallocate(contact_property_search_set) - if (allocated(contact_property_friction_set)) deallocate(contact_property_friction_set) + call db_state_free_contact_props() end subroutine db_free_contact_property_arrays subroutine db_reset_counts() - nnode = 0 - nelem = 0 - ndof = 0 - ngauss_total = 0 - n_nset = 0 - n_elset = 0 - n_surface = 0 - n_surface_item = 0 - n_material = 0 - n_section = 0 - n_plastic_item = 0 - n_amp = 0 - n_amp_item = 0 - nbc = 0 - ncload = 0 - ndload = 0 - nrobin = 0 - nmpc = 0 - nmpc_term = 0 - ncontact_plane = 0 - ncontact_pair = 0 - n_contact_property = 0 - contact_active_count = 0 - contact_work_step = ZERO - contact_work_total = ZERO - contact_max_penetration = ZERO - contact_force_norm = ZERO + call db_state_reset_counts() end subroutine db_reset_counts end module fem_database diff --git a/src/mesh/fem_database_state.f90 b/src/mesh/fem_database_state.f90 index 63ebba3..703266a 100644 --- a/src/mesh/fem_database_state.f90 +++ b/src/mesh/fem_database_state.f90 @@ -74,6 +74,8 @@ module fem_database_state character(len=16), allocatable :: surface_type(:) character(len=NAME_LEN_STATE), allocatable :: surface_target(:) character(len=16), allocatable :: surface_face(:) + real(rk_state), allocatable :: surface_plane_normal(:,:) + real(rk_state), allocatable :: surface_plane_offset(:) character(len=NAME_LEN_STATE), allocatable :: mat_name(:) character(len=MAT_MODEL_LEN_STATE), allocatable :: mat_plastic_model(:) @@ -186,4 +188,100 @@ module fem_database_state real(rk_state), allocatable :: contact_pair_slip(:) integer, allocatable :: contact_pair_stick_count(:) integer, allocatable :: contact_pair_slip_count(:) + +contains + + subroutine db_state_free_surface_arrays() + if (allocated(surface_name)) deallocate(surface_name) + 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(surface_plane_normal)) deallocate(surface_plane_normal) + if (allocated(surface_plane_offset)) deallocate(surface_plane_offset) + end subroutine db_state_free_surface_arrays + + subroutine db_state_init_surface_arrays() + if (allocated(surface_name)) surface_name = ' ' + 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(surface_plane_normal)) surface_plane_normal = ZERO_STATE + if (allocated(surface_plane_offset)) surface_plane_offset = ZERO_STATE + end subroutine db_state_init_surface_arrays + + subroutine db_state_free_contact_props() + if (allocated(contact_property_name)) deallocate(contact_property_name) + if (allocated(contact_property_penalty)) deallocate(contact_property_penalty) + if (allocated(contact_property_damping)) deallocate(contact_property_damping) + if (allocated(contact_property_search)) deallocate(contact_property_search) + if (allocated(contact_property_friction)) deallocate(contact_property_friction) + if (allocated(contact_property_penalty_set)) deallocate(contact_property_penalty_set) + if (allocated(contact_property_damping_set)) deallocate(contact_property_damping_set) + if (allocated(contact_property_search_set)) deallocate(contact_property_search_set) + if (allocated(contact_property_friction_set)) deallocate(contact_property_friction_set) + end subroutine db_state_free_contact_props + + subroutine db_state_free_contact_arrays() + 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) + if (allocated(contact_pair_slave)) deallocate(contact_pair_slave) + if (allocated(contact_pair_master)) deallocate(contact_pair_master) + if (allocated(contact_pair_property)) deallocate(contact_pair_property) + if (allocated(contact_pair_penalty)) deallocate(contact_pair_penalty) + if (allocated(contact_pair_damping)) deallocate(contact_pair_damping) + if (allocated(contact_pair_search)) deallocate(contact_pair_search) + if (allocated(contact_pair_friction)) deallocate(contact_pair_friction) + if (allocated(contact_pair_penalty_set)) deallocate(contact_pair_penalty_set) + if (allocated(contact_pair_damping_set)) deallocate(contact_pair_damping_set) + if (allocated(contact_pair_search_set)) deallocate(contact_pair_search_set) + if (allocated(contact_pair_friction_set)) deallocate(contact_pair_friction_set) + if (allocated(contact_pair_active)) deallocate(contact_pair_active) + if (allocated(contact_pair_work)) deallocate(contact_pair_work) + if (allocated(contact_pair_max_penetration)) deallocate(contact_pair_max_penetration) + if (allocated(contact_pair_force_norm)) deallocate(contact_pair_force_norm) + if (allocated(contact_pair_tangent_force)) deallocate(contact_pair_tangent_force) + if (allocated(contact_pair_slip)) deallocate(contact_pair_slip) + if (allocated(contact_pair_stick_count)) deallocate(contact_pair_stick_count) + if (allocated(contact_pair_slip_count)) deallocate(contact_pair_slip_count) + call db_state_free_contact_props() + end subroutine db_state_free_contact_arrays + + subroutine db_state_reset_counts() + nnode = 0 + nelem = 0 + ndof = 0 + ngauss_total = 0 + n_nset = 0 + n_elset = 0 + n_surface = 0 + n_surface_item = 0 + n_material = 0 + n_section = 0 + n_plastic_item = 0 + n_amp = 0 + n_amp_item = 0 + nbc = 0 + ncload = 0 + ndload = 0 + nrobin = 0 + nmpc = 0 + nmpc_term = 0 + ncontact_plane = 0 + ncontact_pair = 0 + n_contact_property = 0 + contact_active_count = 0 + contact_work_step = ZERO_STATE + contact_work_total = ZERO_STATE + contact_max_penetration = ZERO_STATE + contact_force_norm = ZERO_STATE + end subroutine db_state_reset_counts end module fem_database_state diff --git a/tests/data/s4_contact_analytical_plane.inp b/tests/data/s4_contact_analytical_plane.inp new file mode 100644 index 0000000..221e361 --- /dev/null +++ b/tests/data/s4_contact_analytical_plane.inp @@ -0,0 +1,26 @@ +*HEADING +FemLite analytical rigid plane contact parser test +*NODE +1, 0.0, 0.0, -0.01 +2, 1.0, 0.0, -0.01 +3, 1.0, 1.0, -0.01 +4, 0.0, 1.0, -0.01 +*ELEMENT, TYPE=S4, ELSET=PLATE +1, 1, 2, 3, 4 +*MATERIAL, NAME=MAT +*DENSITY +1.0 +*ELASTIC +30.0, 0.25 +*SHELL SECTION, ELSET=PLATE, MATERIAL=MAT +0.1 +*SURFACE, NAME=SLAVE_NODES, TYPE=NODE +1 +*SURFACE, NAME=RIGID_PLANE, TYPE=ANALYTICAL +PLANE, 0.0, 0.0, 1.0, 0.0 +*CONTACT PAIR, PENALTY=1000.0, DAMPING=2.0 +SLAVE_NODES, RIGID_PLANE +*STEP +*DYNAMIC +0.1, 0.1 +*END STEP diff --git a/tests/data/s4_contact_pair_surface_bad_type.inp b/tests/data/s4_contact_pair_surface_bad_analytical_line.inp similarity index 91% rename from tests/data/s4_contact_pair_surface_bad_type.inp rename to tests/data/s4_contact_pair_surface_bad_analytical_line.inp index 5a0f85e..b79dafa 100644 --- a/tests/data/s4_contact_pair_surface_bad_type.inp +++ b/tests/data/s4_contact_pair_surface_bad_analytical_line.inp @@ -1,5 +1,5 @@ *HEADING -FemLite S4 unsupported surface type parser test +FemLite S4 invalid analytical surface line parser test *NODE 1, 0.0, 0.0, 0.0 2, 1.0, 0.0, 0.0 diff --git a/tests/module/test_contact.f90 b/tests/module/test_contact.f90 index 6c76004..2216357 100644 --- a/tests/module/test_contact.f90 +++ b/tests/module/test_contact.f90 @@ -13,6 +13,7 @@ program test_contact call check_plane_force() call check_target_node_only() + call check_analytic_pair_plane_force() call check_explicit_contact_step() call check_surface_pair_force() call check_surface_pair_shell_sides() @@ -85,6 +86,54 @@ contains if (ierr .ne. FEM_SUCCESS) call fail(15) end subroutine check_target_node_only + subroutine check_analytic_pair_plane_force() + integer :: ierr + integer :: dof1 + integer :: dof2 + + call setup_basic_nodes(2, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(16) + call database_allocate_surfaces(2, 2, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(17) + call database_allocate_contact_pair(1, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(18) + + surface_name(1) = 'SLAVE_NODES' + surface_type(1) = 'NODE' + surface_start(1) = 1 + surface_count(1) = 1 + surface_owner(1) = 1 + surface_target(1) = '1' + surface_name(2) = 'RIGID_PLANE' + surface_type(2) = 'ANALYTICAL' + surface_start(2) = 2 + surface_count(2) = 1 + surface_owner(2) = 2 + surface_target(2) = 'PLANE' + surface_plane_normal(:,2) = (/ ZERO, ZERO, ONE /) + surface_plane_offset(2) = ZERO + contact_pair_slave(1) = 'SLAVE_NODES' + contact_pair_master(1) = 'RIGID_PLANE' + contact_pair_penalty(1) = 100.0_rk + contact_pair_damping(1) = 10.0_rk + + dof1 = dof_id(3,1) + dof2 = dof_id(3,2) + u(dof1) = -0.02_rk + v(dof1) = -0.10_rk + u(dof2) = -0.02_rk + + call contact_apply_plane_forces(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(19) + call check_close(fcontact(dof1), 3.0_rk, 120) + call check_close(fcontact(dof2), ZERO, 121) + if (contact_active_count .ne. 1) call fail(122) + call check_close(contact_pair_force_norm(1), 3.0_rk, 123) + + call database_finalize(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(124) + end subroutine check_analytic_pair_plane_force + subroutine check_explicit_contact_step() integer :: ierr integer :: dof diff --git a/tests/module/test_implicit_inp.f90 b/tests/module/test_implicit_inp.f90 index 45c67e4..ed48245 100644 --- a/tests/module/test_implicit_inp.f90 +++ b/tests/module/test_implicit_inp.f90 @@ -8,6 +8,7 @@ program test_implicit_inp contact_pair_friction, n_surface, surface_name, & surface_start, surface_count, surface_target, & surface_face, surface_owner, surface_type, & + surface_plane_normal, surface_plane_offset, & n_contact_property, contact_property_name, & contact_property_penalty, contact_property_damping, & contact_property_search, contact_property_friction, & @@ -462,9 +463,41 @@ contains call check_node_surface_inp() call check_contact_property_inp() + call check_contact_analytical_inp() call check_contact_pair_input_errors() end subroutine check_contact_pair_inp + subroutine check_contact_analytical_inp() + integer :: ierr + integer :: node_count + + call fem_initialize(ierr) + if (ierr .ne. 0) call fail(560) + + call fem_read_inp('tests/data/s4_contact_analytical_plane.inp', ierr) + if (ierr .ne. 0) call fail(561) + if (n_surface .ne. 2) call fail(562) + if (trim(surface_type(1)) .ne. 'NODE') call fail(563) + if (trim(surface_type(2)) .ne. 'ANALYTICAL') call fail(564) + if (trim(surface_target(2)) .ne. 'PLANE') call fail(565) + call check_close(surface_plane_normal(1,2), ZERO, 566) + call check_close(surface_plane_normal(2,2), ZERO, 567) + call check_close(surface_plane_normal(3,2), ONE, 568) + call check_close(surface_plane_offset(2), ZERO, 569) + if (trim(contact_pair_slave(1)) .ne. 'SLAVE_NODES') call fail(570) + if (trim(contact_pair_master(1)) .ne. 'RIGID_PLANE') call fail(571) + + call fem_get_surface_node_count('SLAVE_NODES', node_count, ierr) + if (ierr .ne. 0) call fail(572) + if (node_count .ne. 1) call fail(573) + + call fem_build_model(ierr) + if (ierr .ne. 0) call fail(574) + + call fem_finalize(ierr) + if (ierr .ne. 0) call fail(575) + end subroutine check_contact_analytical_inp + subroutine check_contact_property_inp() integer :: ierr @@ -497,7 +530,8 @@ contains call check_contact_pair_inp_error('tests/data/s4_contact_pair_missing_master.inp', 404) call check_contact_pair_inp_error('tests/data/s4_contact_pair_missing_penalty.inp', 407) call check_contact_pair_build_error('tests/data/s4_contact_pair_surface_bad_face.inp', 415) - call check_contact_pair_inp_error('tests/data/s4_contact_pair_surface_bad_type.inp', 445) + call check_contact_pair_inp_error( & + 'tests/data/s4_contact_pair_surface_bad_analytical_line.inp', 445) call check_contact_pair_build_error('tests/data/s4_contact_pair_unknown_property.inp', 548) end subroutine check_contact_pair_input_errors