program test_contact use fem_precision use fem_error use fem_database use fem_contact use fem_contact_state, only: CONTACT_PAIR_ACTIVATED, & CONTACT_PAIR_MAINTAINED, CONTACT_PAIR_RELEASED, & contact_get_search_stats, contact_get_perf_stats, contact_get_cache_stats, & contact_get_pair_stats, CONTACT_STATE_OPEN, CONTACT_STATE_CLOSED_STICK, & CONTACT_STATE_CLOSED_SLIP, CONTACT_STATE_CLOSED_RESTICK, & CONTACT_STATE_SEPARATING, CONTACT_STATE_FAILED_PROJECTION, & contact_state_name, contact_get_state_summary use fem_contact_candidate_cache, only: contact_candidate_cache_stats use fem_contact_history, only: contact_history_stats, & contact_history_state_stats use fem_contact_multiplier, only: contact_multiplier_reset, & contact_multiplier_begin_trial, contact_multiplier_store_trial, & contact_multiplier_commit, contact_multiplier_rollback, & contact_multiplier_old, contact_multiplier_stats use fem_nonlinear_lifecycle, only: NLC_AUDIT_ROLLBACK_OK, & nl_lifecycle_get_audit, nl_lifecycle_reset use fem_api use fem_assembly_csr use fem_sparse_csr use fem_output_csv implicit none real(rk), parameter :: TOL = 1.0e-10_rk call check_contact_state_names() call check_plane_force() call check_target_node_only() call check_analytic_pair_plane_force() call check_pair_active_set_augmented() call check_explicit_contact_step() call check_surface_pair_force() call check_surface_pair_shell_sides() call check_surface_pair_tangent() call check_surface_pair_friction() call check_pair_friction_reg() call check_surface_pair_multimaster() call check_pair_clipped() call check_pair_grid() call check_multiplier_history() contains subroutine check_contact_state_names() character(len=64) :: name call contact_state_name(CONTACT_STATE_OPEN, name) if (trim(name) .ne. 'open') call fail(9100) call contact_state_name(CONTACT_STATE_CLOSED_STICK, name) if (trim(name) .ne. 'closed-stick') call fail(9101) call contact_state_name(CONTACT_STATE_CLOSED_SLIP, name) if (trim(name) .ne. 'closed-slip') call fail(9102) call contact_state_name(CONTACT_STATE_CLOSED_RESTICK, name) if (trim(name) .ne. 'closed-restick') call fail(9103) call contact_state_name(CONTACT_STATE_SEPARATING, name) if (trim(name) .ne. 'separating') call fail(9104) call contact_state_name(CONTACT_STATE_FAILED_PROJECTION, name) if (trim(name) .ne. 'failed-projection') call fail(9105) call contact_state_name(-999, name) if (trim(name) .ne. 'unknown') call fail(9106) end subroutine check_contact_state_names subroutine check_multiplier_history() integer :: ierr integer :: slot_count integer :: active_count integer :: audit_status integer :: begin_trial_count integer :: rollback_requested_count integer :: rollback_ok_count integer :: rollback_failed_count integer :: commit_ok_count real(rk) :: old_lambda real(rk) :: max_lambda real(rk) :: max_gap character(len=64) :: audit_name call nl_lifecycle_reset() call contact_multiplier_reset() call contact_multiplier_begin_trial() call contact_multiplier_store_trial(1, 10, 2, 20, 3, 1, 5.0_rk, & 0.02_rk, .true., ierr) if (ierr .ne. FEM_SUCCESS) call fail(9001) call contact_multiplier_old(1, 10, 2, 20, 3, 1, old_lambda) call check_close(old_lambda, ZERO, 9002) call contact_multiplier_stats(slot_count, active_count, max_lambda, max_gap) if (slot_count .ne. 1) call fail(9003) if (active_count .ne. 1) call fail(9004) call check_close(max_gap, 0.02_rk, 9005) call contact_multiplier_commit() call contact_multiplier_old(1, 10, 2, 20, 3, 1, old_lambda) call check_close(old_lambda, 5.0_rk, 9006) call contact_multiplier_begin_trial() call contact_multiplier_store_trial(1, 10, 2, 20, 3, 1, 8.0_rk, & 0.01_rk, .true., ierr) if (ierr .ne. FEM_SUCCESS) call fail(9007) call contact_multiplier_rollback() call contact_multiplier_old(1, 10, 2, 20, 3, 1, old_lambda) call check_close(old_lambda, 5.0_rk, 9008) call nl_lifecycle_get_audit(audit_status, audit_name, & begin_trial_count, rollback_requested_count, rollback_ok_count, & rollback_failed_count, commit_ok_count) if (audit_status .ne. NLC_AUDIT_ROLLBACK_OK) call fail(9009) if (begin_trial_count .lt. 2) call fail(9010) if (rollback_requested_count .ne. 1) call fail(9011) if (rollback_ok_count .ne. 1) call fail(9012) if (rollback_failed_count .ne. 0) call fail(9013) if (commit_ok_count .lt. 1) call fail(9014) call contact_multiplier_reset() end subroutine check_multiplier_history 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_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_pair_active_set_augmented() integer :: ierr integer :: dof integer :: active_pair_count integer :: activated_pair_count integer :: maintained_pair_count integer :: released_pair_count real(rk) :: max_gap_residual real(rk) :: max_aug_lambda real(rk) :: conv_relative_residual real(rk) :: conv_contact_gap real(rk) :: conv_combined_norm real(rk) :: gap_max real(rk) :: gap_mean real(rk) :: gap_l2 real(rk) :: slip_increment real(rk) :: slip_residual real(rk) :: friction_residual integer :: open_count integer :: closed_stick_count integer :: closed_slip_count integer :: closed_restick_count integer :: separating_count integer :: failed_projection_count integer :: active_set_flip_count call fem_initialize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(145) call setup_basic_nodes(1, ierr) if (ierr .ne. FEM_SUCCESS) call fail(125) call database_allocate_surfaces(2, 2, ierr) if (ierr .ne. FEM_SUCCESS) call fail(126) call database_allocate_contact_pair(1, ierr) if (ierr .ne. FEM_SUCCESS) call fail(127) 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) = ZERO contact_pair_aug_factor(1) = 0.5_rk dof = dof_id(3,1) u(dof) = -0.01_rk call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(128) call check_close(fcontact(dof), ONE, 129) if (contact_pair_status(1) .ne. CONTACT_PAIR_ACTIVATED) call fail(130) if (contact_pair_activation_count(1) .ne. 1) call fail(131) call check_close(contact_pair_gap_residual(1), 0.01_rk, 132) call check_close(contact_pair_aug_lambda(1), 0.5_rk, 133) call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(134) call check_close(fcontact(dof), 1.5_rk, 135) if (contact_pair_status(1) .ne. CONTACT_PAIR_MAINTAINED) call fail(136) if (contact_pair_activation_count(1) .ne. 1) call fail(137) call check_close(contact_pair_aug_lambda(1), ONE, 138) call fem_get_contact_diagnostics(active_pair_count, & activated_pair_count, maintained_pair_count, released_pair_count, & max_gap_residual, max_aug_lambda, ierr) if (ierr .ne. FEM_SUCCESS) call fail(146) if (active_pair_count .ne. 1) call fail(147) if (activated_pair_count .ne. 0) call fail(148) if (maintained_pair_count .ne. 1) call fail(149) if (released_pair_count .ne. 0) call fail(150) call check_close(max_gap_residual, 0.01_rk, 151) call check_close(max_aug_lambda, ONE, 152) call fem_get_convergence_metrics(conv_relative_residual, & conv_contact_gap, conv_combined_norm, ierr) if (ierr .ne. FEM_SUCCESS) call fail(153) call check_close(conv_relative_residual, ZERO, 154) call check_close(conv_contact_gap, 0.01_rk, 155) call check_close(conv_combined_norm, 0.01_rk, 156) call fem_get_contact_state_summary(open_count, closed_stick_count, & closed_slip_count, closed_restick_count, separating_count, & failed_projection_count, gap_max, gap_mean, gap_l2, slip_increment, & slip_residual, friction_residual, active_set_flip_count, ierr) if (ierr .ne. FEM_SUCCESS) call fail(157) if (open_count .ne. 0) call fail(158) if (closed_stick_count .ne. 1) call fail(159) if (closed_slip_count .ne. 0) call fail(160) if (closed_restick_count .ne. 0) call fail(161) if (separating_count .ne. 0) call fail(162) if (failed_projection_count .ne. 0) call fail(163) call check_close(gap_max, 0.01_rk, 164) call check_close(gap_mean, 0.01_rk, 165) call check_close(gap_l2, 0.01_rk, 166) call check_close(slip_increment, ZERO, 167) call check_close(slip_residual, ZERO, 168) call check_close(friction_residual, ZERO, 169) if (active_set_flip_count .ne. 1) call fail(170) u(dof) = 0.01_rk call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(139) call check_close(fcontact(dof), ZERO, 140) if (contact_pair_status(1) .ne. CONTACT_PAIR_RELEASED) call fail(141) if (contact_pair_release_count(1) .ne. 1) call fail(142) call check_close(contact_pair_aug_lambda(1), ZERO, 143) call fem_get_contact_state_summary(open_count, closed_stick_count, & closed_slip_count, closed_restick_count, separating_count, & failed_projection_count, gap_max, gap_mean, gap_l2, slip_increment, & slip_residual, friction_residual, active_set_flip_count, ierr) if (ierr .ne. FEM_SUCCESS) call fail(171) if (separating_count .ne. 1) call fail(172) if (active_set_flip_count .ne. 2) call fail(173) call fem_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(144) end subroutine check_pair_active_set_augmented subroutine check_explicit_contact_step() integer :: ierr integer :: dof integer :: active_count real(rk) :: work_step real(rk) :: work_total real(rk) :: max_penetration real(rk) :: force_norm 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_get_contact_summary(active_count, work_step, work_total, & max_penetration, force_norm, ierr) if (ierr .ne. FEM_SUCCESS) call fail(27) if (active_count .ne. 1) call fail(28) call check_close(max_penetration, 0.10_rk, 29) call check_close(force_norm, ONE, 30) call check_close(work_step, 0.05_rk, 31) call fem_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(32) 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_shell_sides() integer :: ierr integer :: node integer :: dof call setup_contact_shell_pair(ierr) if (ierr .ne. FEM_SUCCESS) call fail(35) call set_shell_surfaces('SLAVE_POS', 'SPOS', & 'MASTER_POS', 'SPOS', ierr) if (ierr .ne. FEM_SUCCESS) call fail(36) call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(37) do node = 1, 4 dof = dof_id(3,node) call check_close(fcontact(dof), -2.5_rk, 38) end do do node = 5, 8 dof = dof_id(3,node) call check_close(fcontact(dof), 2.5_rk, 39) end do call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(3400) call setup_contact_shell_pair(ierr) if (ierr .ne. FEM_SUCCESS) call fail(3401) call set_shell_surfaces('SLAVE_NEG', 'SNEG', & 'MASTER_POS', 'SPOS', ierr) if (ierr .ne. FEM_SUCCESS) call fail(3402) call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(3403) do node = 1, 8 dof = dof_id(3,node) call check_close(fcontact(dof), ZERO, 3404) end do if (contact_active_count .ne. 0) call fail(3405) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(3406) call setup_contact_shell_pair(ierr) if (ierr .ne. FEM_SUCCESS) call fail(3407) 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 call set_shell_surfaces('SLAVE_NEG', 'SNEG', & 'MASTER_NEG', 'SNEG', ierr) if (ierr .ne. FEM_SUCCESS) call fail(3408) call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(3409) do node = 1, 4 dof = dof_id(3,node) call check_close(fcontact(dof), 2.5_rk, 3410) end do do node = 5, 8 dof = dof_id(3,node) call check_close(fcontact(dof), -2.5_rk, 3411) end do call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(3412) end subroutine check_surface_pair_shell_sides 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, 1000.0_rk / 9.0_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, -1000.0_rk / 9.0_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 integer :: open_count integer :: closed_stick_count integer :: closed_slip_count integer :: closed_restick_count integer :: separating_count integer :: failed_projection_count integer :: active_set_flip_count real(rk) :: gap_max real(rk) :: gap_mean real(rk) :: gap_l2 real(rk) :: slip_increment real(rk) :: slip_residual real(rk) :: friction_residual 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 if (contact_pair_stick_count(1) .ne. 0) call fail(500) if (contact_pair_slip_count(1) .ne. 1) call fail(501) call check_close(contact_pair_slip(1), 0.998_rk, 502) call check_close(contact_pair_tangent_force(1,1), -2.0_rk, 503) call check_close(contact_friction_work_step, 2.0_rk, 504) call check_close(contact_friction_work_total, 2.0_rk, 505) call check_close(contact_pair_friction_work(1), 2.0_rk, 506) call check_close(contact_pair_fric_work_total(1), 2.0_rk, 507) call contact_get_state_summary(open_count, closed_stick_count, & closed_slip_count, closed_restick_count, separating_count, & failed_projection_count, gap_max, gap_mean, gap_l2, slip_increment, & slip_residual, friction_residual, active_set_flip_count) if (closed_slip_count .ne. 1) call fail(508) if (closed_stick_count .ne. 0) call fail(509) if (failed_projection_count .ne. 0) call fail(5140) if (slip_increment .le. ZERO) call fail(5141) if (slip_residual .le. ZERO) call fail(5142) if (friction_residual .le. ZERO) call fail(5143) 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, 200.0_rk / 9.0_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_pair_friction_reg() type(csr_matrix) :: kmat integer :: ierr integer :: node integer :: dof integer :: row integer :: col integer :: stat integer :: slot_count integer :: stick_slots integer :: slip_slots real(rk) :: expected_force real(rk) :: expected_node_force real(rk) :: expected_slip real(rk) :: expected_tangent real(rk) :: max_slot_slip real(rk) :: max_slot_work real(rk) :: max_tangent_force real(rk) :: value call setup_contact_shell_pair(ierr) if (ierr .ne. FEM_SUCCESS) call fail(520) contact_pair_friction(1) = 0.2_rk contact_pair_friction_reg(1) = ONE 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(521) expected_force = 2.0_rk * tanh(ONE) expected_node_force = expected_force / 4.0_rk expected_slip = (1000.0_rk - expected_force) / 1000.0_rk do node = 1, 4 dof = dof_id(1,node) call check_close(fcontact(dof), expected_node_force, 522) end do do node = 5, 8 dof = dof_id(1,node) call check_close(fcontact(dof), -expected_node_force, 523) end do if (contact_pair_slip_count(1) .ne. 1) call fail(524) call check_close(contact_pair_slip(1), expected_slip, 525) call check_close(contact_pair_tangent_force(1,1), -expected_force, 526) call check_close(contact_friction_work_step, expected_force, 527) call check_close(contact_pair_friction_work(1), expected_force, 528) call contact_history_stats(slot_count, max_slot_slip, max_slot_work, & max_tangent_force) if (slot_count .le. 1) call fail(535) call check_close(max_slot_slip, expected_slip, 536) if (max_slot_work .le. ZERO .or. max_slot_work .gt. expected_force) & call fail(537) if (max_tangent_force .le. ZERO .or. & max_tangent_force .gt. expected_force) call fail(538) call contact_history_state_stats(slot_count, stick_slots, slip_slots) if (stick_slots .ne. 0) call fail(539) if (slip_slots .ne. slot_count) call fail(534) call csr_init(kmat) call assembly_build_csr_pattern(kmat, ierr) if (ierr .ne. FEM_SUCCESS) call fail(529) call contact_apply_plane_tangent(kmat, ZERO, ierr) if (ierr .ne. FEM_SUCCESS) call fail(530) 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(531) expected_tangent = 200.0_rk * tanh(ONE) / 9.0_rk call check_close(value, expected_tangent, 532) call csr_free(kmat, stat) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(533) end subroutine check_pair_friction_reg 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 check_pair_clipped() integer :: ierr integer :: node integer :: search_facets integer :: search_masters integer :: search_broad integer :: search_active integer :: search_bvh_nodes real(rk) :: search_time real(rk) :: force_time real(rk) :: tangent_time call setup_contact_shell_pair(ierr) if (ierr .ne. FEM_SUCCESS) call fail(70) do node = 5, 8 coord0(1,node) = coord0(1,node) + 0.5_rk end do coord = coord0 call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(71) call check_close(fcontact(dof_id(3,5)), 1.875_rk, 72) call check_close(fcontact(dof_id(3,6)), 0.625_rk, 73) call check_close(fcontact(dof_id(3,7)), 0.625_rk, 74) call check_close(fcontact(dof_id(3,8)), 1.875_rk, 75) call check_close(fcontact(dof_id(3,1)), -0.625_rk, 76) call check_close(fcontact(dof_id(3,2)), -1.875_rk, 77) call check_close(fcontact(dof_id(3,3)), -1.875_rk, 78) call check_close(fcontact(dof_id(3,4)), -0.625_rk, 79) if (contact_active_count .ne. 1) call fail(80) if (contact_pair_active(1) .ne. 1) call fail(81) call check_close(contact_max_penetration, 0.01_rk, 82) call check_close(contact_pair_max_penetration(1), 0.01_rk, 83) call check_close(contact_force_norm, 5.0_rk, 84) call check_close(contact_pair_force_norm(1), 5.0_rk, 85) call check_close(contact_work_step, 0.025_rk, 86) call check_close(contact_pair_work(1), 0.025_rk, 87) call contact_get_search_stats(search_facets, search_masters, & search_broad, search_active, & search_bvh_nodes) if (search_facets .le. 0) call fail(602) if (search_masters .le. 0) call fail(603) if (search_broad .le. 0) call fail(604) if (search_active .le. 0) call fail(605) if (search_bvh_nodes .ne. 0) call fail(606) call contact_get_perf_stats(search_time, force_time, tangent_time) if (search_time .lt. ZERO) call fail(608) if (force_time .lt. ZERO) call fail(609) if (tangent_time .lt. ZERO) call fail(610) call output_csv_write(910, ZERO, ierr) if (ierr .ne. FEM_SUCCESS) call fail(600) call require_contains('contact_00000910.csv', & 'kind,pair_id,active_count,max_penetration,force_norm,work_estimate,'// & 'cumulative_work,stick_count,slip_count,accumulated_slip,'// & 'slip_increment_norm,slip_residual,friction_residual,'// & 'friction_work,friction_work_total,friction_regularization,ftx,fty,ftz,'// & 'status,activation_count,release_count,gap_residual,gap_mean,'// & 'gap_l2,failed_projection_count,active_set_flip_count,'// & 'open_count,closed_stick_count,closed_slip_count,'// & 'closed_restick_count,separating_count,state_failed_projection_count,'// & 'aug_factor,aug_lambda', 601) call require_contains('contact_00000910.csv', & 'search_facets,search_masters,search_candidates,search_active,'// & 'search_bvh_nodes', 607) call require_contains('contact_00000910.csv', & 'search_cache_used,search_cache_overflow', 612) call require_contains('contact_00000910.csv', & 'search_cpu_time,contact_force_cpu_time,contact_tangent_cpu_time', 611) call require_contains('contact_00000910.csv', 'PAIR', 613) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(88) end subroutine check_pair_clipped subroutine check_pair_grid() type(csr_matrix) :: kmat integer :: ierr integer :: stat integer :: node integer :: dof integer :: row integer :: col integer :: search_facets integer :: search_masters integer :: search_broad integer :: search_active integer :: search_bvh_nodes integer :: cache_used integer :: cache_overflow integer :: pair_facets integer :: pair_masters integer :: pair_broad integer :: pair_active integer :: pair_bvh_nodes integer :: pair_cache_used integer :: pair_cache_overflow integer :: cache_hits integer :: cache_misses integer :: cache_invalid integer :: cache_stores integer :: cache_broad_overflow real(rk) :: pair_search_time real(rk) :: pair_force_time real(rk) :: pair_tangent_time real(rk) :: value call setup_contact_grid_pair(ierr) if (ierr .ne. FEM_SUCCESS) call fail(90) call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(91) do node = 73, 76 dof = dof_id(3,node) call check_close(fcontact(dof), 2.5_rk, 92) end do do node = 1, 4 dof = dof_id(3,node) call check_close(fcontact(dof), -2.5_rk, 93) end do do node = 5, 72 dof = dof_id(3,node) call check_close(fcontact(dof), ZERO, 94) end do if (contact_active_count .ne. 1) call fail(95) call check_close(contact_force_norm, 10.0_rk, 96) call contact_get_search_stats(search_facets, search_masters, & search_broad, search_active, & search_bvh_nodes) if (search_bvh_nodes .le. 0) call fail(620) call contact_get_cache_stats(cache_used, cache_overflow) if (cache_used .le. 0) call fail(621) if (cache_overflow .ne. 0) call fail(622) call contact_get_pair_stats(1, pair_facets, pair_masters, pair_broad, & pair_active, pair_bvh_nodes, pair_cache_used, pair_cache_overflow, & pair_search_time, pair_force_time, pair_tangent_time) if (pair_facets .le. 0) call fail(623) if (pair_masters .le. 0) call fail(624) if (pair_broad .le. 0) call fail(625) if (pair_active .le. 0) call fail(626) if (pair_bvh_nodes .le. 0) call fail(627) if (pair_cache_used .le. 0) call fail(628) if (pair_cache_overflow .ne. 0) call fail(629) if (pair_search_time .lt. ZERO) call fail(630) if (pair_force_time .lt. ZERO) call fail(631) call contact_candidate_cache_stats(cache_hits, cache_misses, & cache_invalid, cache_stores, cache_broad_overflow) if (cache_stores .le. 0) call fail(633) if (cache_hits .ne. 0) call fail(634) call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(635) call contact_get_search_stats(search_facets, search_masters, & search_broad, search_active, & search_bvh_nodes) if (search_bvh_nodes .ne. 0) call fail(636) call contact_candidate_cache_stats(cache_hits, cache_misses, & cache_invalid, cache_stores, cache_broad_overflow) if (cache_hits .le. 0) call fail(637) if (cache_invalid .ne. 0) call fail(638) call csr_init(kmat) call assembly_build_csr_pattern(kmat, ierr) if (ierr .ne. FEM_SUCCESS) call fail(510) call contact_apply_plane_tangent(kmat, ZERO, ierr) if (ierr .ne. FEM_SUCCESS) call fail(511) call require_candidate_cache_hit(cache_hits, 642) call contact_get_pair_stats(1, pair_facets, pair_masters, pair_broad, & pair_active, pair_bvh_nodes, pair_cache_used, pair_cache_overflow, & pair_search_time, pair_force_time, pair_tangent_time) if (pair_tangent_time .lt. ZERO) call fail(632) row = dof_id(3,73) col = dof_id(3,73) call csr_get_value(kmat, row, col, value, ierr) if (ierr .ne. FEM_SUCCESS) call fail(512) call check_close(value, 1000.0_rk / 9.0_rk, 513) col = dof_id(3,1) call csr_get_value(kmat, row, col, value, ierr) if (ierr .ne. FEM_SUCCESS) call fail(514) call check_close(value, -1000.0_rk / 9.0_rk, 515) call csr_free(kmat, stat) do node = 73, 76 coord0(1,node) = coord0(1,node) + ONE end do coord = coord0 call contact_apply_plane_forces(ierr) if (ierr .ne. FEM_SUCCESS) call fail(639) call contact_get_search_stats(search_facets, search_masters, & search_broad, search_active, & search_bvh_nodes) if (search_bvh_nodes .le. 0) call fail(640) call contact_candidate_cache_stats(cache_hits, cache_misses, & cache_invalid, cache_stores, cache_broad_overflow) if (cache_invalid .le. 0) call fail(641) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(97) end subroutine check_pair_grid subroutine require_candidate_cache_hit(previous_hits, code) integer, intent(in) :: previous_hits integer, intent(in) :: code integer :: hits, misses, invalid, stores, overflow call contact_candidate_cache_stats(hits, misses, invalid, stores, overflow) if (hits .le. previous_hits) call fail(code) end subroutine require_candidate_cache_hit 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 set_shell_surfaces(slave_name, slave_face, & master_name, master_face, ierr) character(len=*), intent(in) :: slave_name character(len=*), intent(in) :: slave_face character(len=*), intent(in) :: master_name character(len=*), intent(in) :: master_face integer, intent(out) :: ierr call database_allocate_surfaces(2, 2, ierr) if (ierr .ne. FEM_SUCCESS) return surface_name(1) = master_name surface_start(1) = 1 surface_count(1) = 1 surface_owner(1) = 1 surface_target(1) = 'MASTER' surface_face(1) = master_face surface_name(2) = slave_name surface_start(2) = 2 surface_count(2) = 1 surface_owner(2) = 2 surface_target(2) = 'SLAVE' surface_face(2) = slave_face contact_pair_slave(1) = slave_name contact_pair_master(1) = master_name ierr = FEM_SUCCESS end subroutine set_shell_surfaces 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 setup_contact_grid_pair(ierr) integer, intent(out) :: ierr integer :: master integer :: node_base integer :: xshift call database_allocate_model(76, 19, 0, 2, 0, 19, 1, 0, 1, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return do master = 1, 18 node_base = 4 * (master - 1) xshift = 10 * (master - 1) node_id_ext(node_base+1:node_base+4) = & (/ node_base + 1, node_base + 2, node_base + 3, node_base + 4 /) coord0(:,node_base+1) = (/ real(xshift, rk), ZERO, ZERO /) coord0(:,node_base+2) = (/ real(xshift, rk) + ONE, ZERO, ZERO /) coord0(:,node_base+3) = (/ real(xshift, rk) + ONE, ONE, ZERO /) coord0(:,node_base+4) = (/ real(xshift, rk), ONE, ZERO /) elem_id_ext(master) = master elem_type(master) = 'S4' elem_nnode(master) = 4 elem_conn(:,master) = 0 elem_conn(1:4,master) = & (/ node_base + 1, node_base + 2, node_base + 3, node_base + 4 /) elem_mat(master) = 1 elem_sec(master) = 1 end do node_id_ext(73:76) = (/ 73, 74, 75, 76 /) coord0(:,73) = (/ ZERO, ZERO, -0.01_rk /) coord0(:,74) = (/ ONE, ZERO, -0.01_rk /) coord0(:,75) = (/ ONE, ONE, -0.01_rk /) coord0(:,76) = (/ ZERO, ONE, -0.01_rk /) coord = coord0 elem_id_ext(19) = 19 elem_type(19) = 'S4' elem_nnode(19) = 4 elem_conn(:,19) = 0 elem_conn(1:4,19) = (/ 73, 74, 75, 76 /) elem_mat(19) = 1 elem_sec(19) = 1 elset_name(1) = 'MASTER' elset_start(1) = 1 elset_count(1) = 18 do master = 1, 18 elset_items(master) = master end do elset_name(2) = 'SLAVE' elset_start(2) = 19 elset_count(2) = 1 elset_items(19) = 19 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_grid_pair 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))) then write(*,*) 'check_close actual expected:', actual, expected call fail(code) end if end subroutine check_close subroutine require_contains(filename, pattern, code) character(len=*), intent(in) :: filename character(len=*), intent(in) :: pattern integer, intent(in) :: code character(len=1024) :: line integer :: unit_id integer :: ios logical :: found found = .false. unit_id = 72 open(unit=unit_id, file=trim(filename), status='old', action='read', iostat=ios) if (ios .ne. 0) call fail(code) do read(unit_id,'(A)',iostat=ios) line if (ios .ne. 0) exit if (index(line, trim(pattern)) .gt. 0) then found = .true. exit end if end do close(unit_id) if (.not. found) call fail(code) end subroutine require_contains subroutine fail(code) integer, intent(in) :: code write(*,*) 'test_contact failed:', code stop 1 end subroutine fail end program test_contact