program test_contact use fem_precision use fem_error use fem_database use fem_contact use fem_api use fem_assembly_csr use fem_sparse_csr implicit none real(rk), parameter :: TOL = 1.0e-10_rk call check_plane_force() call check_target_node_only() call check_explicit_contact_step() call check_surface_pair_force() call check_surface_pair_tangent() call check_surface_pair_friction() call check_surface_pair_multimaster() contains subroutine check_plane_force() integer :: ierr integer :: dof1 integer :: dof2 call setup_basic_nodes(2, ierr) if (ierr .ne. FEM_SUCCESS) call fail(1) call database_allocate_contact(1, ierr) if (ierr .ne. FEM_SUCCESS) call fail(2) contact_target(1) = 'ALL' contact_normal(:,1) = (/ ZERO, ZERO, ONE /) contact_offset(1) = ZERO contact_penalty(1) = 100.0_rk contact_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(3) call check_close(fcontact(dof1), 3.0_rk, 4) call check_close(fcontact(dof2), ZERO, 5) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(6) end subroutine check_plane_force subroutine check_target_node_only() integer :: ierr integer :: dof1 integer :: dof2 call setup_basic_nodes(2, ierr) if (ierr .ne. FEM_SUCCESS) call fail(10) call database_allocate_contact(1, ierr) if (ierr .ne. FEM_SUCCESS) call fail(11) contact_target(1) = '2' contact_normal(:,1) = (/ ZERO, ZERO, 2.0_rk /) contact_offset(1) = ZERO contact_penalty(1) = 100.0_rk contact_damping(1) = ZERO dof1 = dof_id(3,1) dof2 = dof_id(3,2) u(dof1) = -0.02_rk u(dof2) = -0.02_rk call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(12) call check_close(fcontact(dof1), ZERO, 13) call check_close(fcontact(dof2), 2.0_rk, 14) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(15) end subroutine check_target_node_only subroutine check_explicit_contact_step() integer :: ierr integer :: dof call fem_initialize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(20) call setup_basic_nodes(1, ierr) if (ierr .ne. FEM_SUCCESS) call fail(21) mass_diag = ONE call database_allocate_contact(1, ierr) if (ierr .ne. FEM_SUCCESS) call fail(22) contact_target(1) = 'ALL' contact_normal(:,1) = (/ ZERO, ZERO, ONE /) contact_offset(1) = ZERO contact_penalty(1) = 10.0_rk contact_damping(1) = ZERO dof = dof_id(3,1) u(dof) = -0.10_rk call fem_advance_explicit(0.10_rk, ierr) if (ierr .ne. FEM_SUCCESS) call fail(23) call check_close(a(dof), ONE, 24) call check_close(v(dof), 0.10_rk, 25) call check_close(u(dof), -0.095_rk, 26) call fem_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(27) end subroutine check_explicit_contact_step subroutine check_surface_pair_force() integer :: ierr integer :: node integer :: dof call setup_contact_shell_pair(ierr) if (ierr .ne. FEM_SUCCESS) call fail(30) call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(31) do node = 1, 4 dof = dof_id(3,node) call check_close(fcontact(dof), -2.5_rk, 32) end do do node = 5, 8 dof = dof_id(3,node) call check_close(fcontact(dof), 2.5_rk, 33) end do call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(34) end subroutine check_surface_pair_force subroutine check_surface_pair_tangent() type(csr_matrix) :: kmat integer :: ierr integer :: stat integer :: row integer :: col real(rk) :: value call setup_contact_shell_pair(ierr) if (ierr .ne. FEM_SUCCESS) call fail(40) call csr_init(kmat) call assembly_build_csr_pattern(kmat, ierr) if (ierr .ne. FEM_SUCCESS) call fail(41) call contact_apply_plane_tangent(kmat, ZERO, ierr) if (ierr .ne. FEM_SUCCESS) call fail(42) row = dof_id(3,5) col = dof_id(3,5) call csr_get_value(kmat, row, col, value, ierr) if (ierr .ne. FEM_SUCCESS) call fail(43) call check_close(value, 62.5_rk, 44) col = dof_id(3,1) call csr_get_value(kmat, row, col, value, ierr) if (ierr .ne. FEM_SUCCESS) call fail(45) call check_close(value, -62.5_rk, 46) call csr_free(kmat, stat) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(47) end subroutine check_surface_pair_tangent subroutine check_surface_pair_friction() type(csr_matrix) :: kmat integer :: ierr integer :: stat integer :: node integer :: dof integer :: row integer :: col real(rk) :: value call setup_contact_shell_pair(ierr) if (ierr .ne. FEM_SUCCESS) call fail(50) contact_pair_friction(1) = 0.2_rk do node = 5, 8 dof = dof_id(1,node) v(dof) = ONE end do call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(51) do node = 1, 4 dof = dof_id(1,node) call check_close(fcontact(dof), 0.5_rk, 52) end do do node = 5, 8 dof = dof_id(1,node) call check_close(fcontact(dof), -0.5_rk, 53) end do call csr_init(kmat) call assembly_build_csr_pattern(kmat, ierr) if (ierr .ne. FEM_SUCCESS) call fail(54) call contact_apply_plane_tangent(kmat, ZERO, ierr) if (ierr .ne. FEM_SUCCESS) call fail(55) row = dof_id(1,5) col = dof_id(1,5) call csr_get_value(kmat, row, col, value, ierr) if (ierr .ne. FEM_SUCCESS) call fail(56) call check_close(value, 12.5_rk, 57) call csr_free(kmat, stat) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(58) end subroutine check_surface_pair_friction subroutine check_surface_pair_multimaster() integer :: ierr integer :: node integer :: dof call setup_contact_shell_multimaster(ierr) if (ierr .ne. FEM_SUCCESS) call fail(60) call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(61) do node = 5, 8 dof = dof_id(3,node) call check_close(fcontact(dof), 2.5_rk, 62) end do do node = 1, 4 dof = dof_id(3,node) call check_close(fcontact(dof), -1.25_rk, 63) end do do node = 9, 12 dof = dof_id(3,node) call check_close(fcontact(dof), -1.25_rk, 64) end do call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(65) end subroutine check_surface_pair_multimaster subroutine setup_basic_nodes(num_nodes, ierr) integer, intent(in) :: num_nodes integer, intent(out) :: ierr integer :: node integer :: idir integer :: counter call database_allocate_basic(num_nodes, 0, 3 * num_nodes, ierr) if (ierr .ne. FEM_SUCCESS) return counter = 0 do node = 1, num_nodes node_id_ext(node) = node coord0(:,node) = ZERO coord(:,node) = ZERO do idir = 1, NDIM counter = counter + 1 dof_id(idir,node) = counter end do end do ierr = FEM_SUCCESS end subroutine setup_basic_nodes subroutine setup_contact_shell_pair(ierr) integer, intent(out) :: ierr call database_allocate_model(8, 2, 0, 2, 0, 2, 1, 0, 1, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return node_id_ext(1:8) = (/ 1, 2, 3, 4, 5, 6, 7, 8 /) coord0(:,1) = (/ ZERO, ZERO, ZERO /) coord0(:,2) = (/ ONE, ZERO, ZERO /) coord0(:,3) = (/ ONE, ONE, ZERO /) coord0(:,4) = (/ ZERO, ONE, ZERO /) coord0(:,5) = (/ ZERO, ZERO, -0.01_rk /) coord0(:,6) = (/ ONE, ZERO, -0.01_rk /) coord0(:,7) = (/ ONE, ONE, -0.01_rk /) coord0(:,8) = (/ ZERO, ONE, -0.01_rk /) coord = coord0 elem_id_ext(1) = 1 elem_type(1) = 'S4' elem_nnode(1) = 4 elem_conn(:,1) = 0 elem_conn(1:4,1) = (/ 1, 2, 3, 4 /) elem_mat(1) = 1 elem_sec(1) = 1 elem_id_ext(2) = 2 elem_type(2) = 'S4' elem_nnode(2) = 4 elem_conn(:,2) = 0 elem_conn(1:4,2) = (/ 5, 6, 7, 8 /) elem_mat(2) = 1 elem_sec(2) = 1 elset_name(1) = 'MASTER' elset_start(1) = 1 elset_count(1) = 1 elset_items(1) = 1 elset_name(2) = 'SLAVE' elset_start(2) = 2 elset_count(2) = 1 elset_items(2) = 2 mat_name(1) = 'MAT' mat_density(1) = ONE mat_e(1) = 30.0_rk mat_nu(1) = 0.25_rk section_type(1) = 'SHELL' section_elset_name(1) = 'ALL' section_material_name(1) = 'MAT' section_thickness(1) = 0.1_rk call database_assign_dofs(ierr) if (ierr .ne. FEM_SUCCESS) return call database_allocate_contact_pair(1, ierr) if (ierr .ne. FEM_SUCCESS) return contact_pair_slave(1) = 'SLAVE' contact_pair_master(1) = 'MASTER' contact_pair_penalty(1) = 1000.0_rk contact_pair_damping(1) = ZERO contact_pair_search(1) = 0.1_rk contact_pair_friction(1) = ZERO ierr = FEM_SUCCESS end subroutine setup_contact_shell_pair subroutine setup_contact_shell_multimaster(ierr) integer, intent(out) :: ierr call database_allocate_model(12, 3, 0, 2, 0, 3, 1, 0, 1, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return node_id_ext(1:12) = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 /) coord0(:,1) = (/ ZERO, ZERO, ZERO /) coord0(:,2) = (/ ONE, ZERO, ZERO /) coord0(:,3) = (/ ONE, ONE, ZERO /) coord0(:,4) = (/ ZERO, ONE, ZERO /) coord0(:,5) = (/ ZERO, ZERO, -0.01_rk /) coord0(:,6) = (/ ONE, ZERO, -0.01_rk /) coord0(:,7) = (/ ONE, ONE, -0.01_rk /) coord0(:,8) = (/ ZERO, ONE, -0.01_rk /) coord0(:,9) = coord0(:,1) coord0(:,10) = coord0(:,2) coord0(:,11) = coord0(:,3) coord0(:,12) = coord0(:,4) coord = coord0 elem_id_ext(1:3) = (/ 1, 2, 3 /) elem_type(1:3) = 'S4' elem_nnode(1:3) = 4 elem_conn(:,1:3) = 0 elem_conn(1:4,1) = (/ 1, 2, 3, 4 /) elem_conn(1:4,2) = (/ 5, 6, 7, 8 /) elem_conn(1:4,3) = (/ 9, 10, 11, 12 /) elem_mat(1:3) = 1 elem_sec(1:3) = 1 elset_name(1) = 'MASTER' elset_start(1) = 1 elset_count(1) = 2 elset_items(1:2) = (/ 1, 3 /) elset_name(2) = 'SLAVE' elset_start(2) = 3 elset_count(2) = 1 elset_items(3) = 2 mat_name(1) = 'MAT' mat_density(1) = ONE mat_e(1) = 30.0_rk mat_nu(1) = 0.25_rk section_type(1) = 'SHELL' section_elset_name(1) = 'ALL' section_material_name(1) = 'MAT' section_thickness(1) = 0.1_rk call database_assign_dofs(ierr) if (ierr .ne. FEM_SUCCESS) return call database_allocate_contact_pair(1, ierr) if (ierr .ne. FEM_SUCCESS) return contact_pair_slave(1) = 'SLAVE' contact_pair_master(1) = 'MASTER' contact_pair_penalty(1) = 1000.0_rk contact_pair_damping(1) = ZERO contact_pair_search(1) = 0.1_rk contact_pair_friction(1) = ZERO ierr = FEM_SUCCESS end subroutine setup_contact_shell_multimaster subroutine check_close(actual, expected, code) real(rk), intent(in) :: actual real(rk), intent(in) :: expected integer, intent(in) :: code if (abs(actual - expected) .gt. TOL * max(ONE, abs(expected))) call fail(code) end subroutine check_close subroutine fail(code) integer, intent(in) :: code write(*,*) 'test_contact failed:', code stop 1 end subroutine fail end program test_contact