453 lines
16 KiB
Fortran
453 lines
16 KiB
Fortran
program perf_contact_pair
|
|
use fem_precision
|
|
use fem_error
|
|
use fem_database
|
|
use fem_contact
|
|
use fem_contact_state, only: contact_get_search_stats, &
|
|
contact_get_perf_stats, contact_get_cache_stats, CONTACT_PAIR_OPEN, &
|
|
CONTACT_PAIR_ACTIVATED, CONTACT_PAIR_MAINTAINED, CONTACT_PAIR_RELEASED
|
|
use fem_assembly_csr
|
|
use fem_sparse_csr
|
|
implicit none
|
|
|
|
type(csr_matrix) :: kmat
|
|
integer :: ierr
|
|
integer :: nfacet
|
|
integer :: do_tangent
|
|
integer :: step_count
|
|
integer :: step
|
|
integer :: active_count
|
|
integer :: search_facets
|
|
integer :: search_masters
|
|
integer :: search_broad
|
|
integer :: search_active
|
|
integer :: search_bvh_nodes
|
|
integer :: cache_used
|
|
integer :: cache_overflow
|
|
integer :: path_active_total
|
|
integer :: path_bvh_nodes_total
|
|
integer :: path_cache_used_total
|
|
integer :: path_cache_overflow_total
|
|
integer :: path_activated_total
|
|
integer :: path_released_total
|
|
integer :: step_search_facets
|
|
integer :: step_search_masters
|
|
integer :: step_search_broad
|
|
integer :: step_search_active
|
|
integer :: step_search_bvh_nodes
|
|
integer :: step_cache_used
|
|
integer :: step_cache_overflow
|
|
integer :: state_open_count
|
|
integer :: state_activated_count
|
|
integer :: state_maintained_count
|
|
integer :: state_released_count
|
|
integer :: activation_count
|
|
integer :: release_count
|
|
real(rk) :: search_time
|
|
real(rk) :: force_time
|
|
real(rk) :: tangent_time
|
|
real(rk) :: path_force_total
|
|
real(rk) :: path_tangent_matrix_total
|
|
real(rk) :: path_tangent_force_total
|
|
real(rk) :: path_gap_total
|
|
real(rk) :: path_slip_total
|
|
real(rk) :: path_fric_work_total
|
|
real(rk) :: final_force_total
|
|
real(rk) :: final_tangent_force_total
|
|
real(rk) :: final_gap_total
|
|
real(rk) :: final_slip_total
|
|
real(rk) :: final_fric_work_total
|
|
real(rk) :: t0
|
|
real(rk) :: t1
|
|
|
|
nfacet = 64
|
|
do_tangent = 1
|
|
step_count = 1
|
|
call parse_args(nfacet, do_tangent, step_count)
|
|
|
|
call setup_contact_perf_model(nfacet, ierr)
|
|
call exit_if_error(ierr, 'setup_contact_perf_model')
|
|
|
|
path_active_total = 0
|
|
path_bvh_nodes_total = 0
|
|
path_cache_used_total = 0
|
|
path_cache_overflow_total = 0
|
|
path_activated_total = 0
|
|
path_released_total = 0
|
|
path_force_total = ZERO
|
|
path_tangent_matrix_total = ZERO
|
|
path_tangent_force_total = ZERO
|
|
path_gap_total = ZERO
|
|
path_slip_total = ZERO
|
|
path_fric_work_total = ZERO
|
|
call cpu_time(t0)
|
|
do step = 1, step_count
|
|
call update_slave_path(step, step_count)
|
|
call contact_apply_plane_forces(ierr)
|
|
call exit_if_error(ierr, 'contact_apply_plane_forces')
|
|
if (do_tangent .ne. 0) then
|
|
call csr_init(kmat)
|
|
call assembly_build_csr_pattern(kmat, ierr)
|
|
call exit_if_error(ierr, 'assembly_build_csr_pattern')
|
|
call contact_apply_plane_tangent(kmat, ZERO, ierr)
|
|
call exit_if_error(ierr, 'contact_apply_plane_tangent')
|
|
path_tangent_matrix_total = path_tangent_matrix_total + csr_abs_sum(kmat)
|
|
call csr_free(kmat, ierr)
|
|
call exit_if_error(ierr, 'csr_free')
|
|
end if
|
|
path_active_total = path_active_total + contact_active_count
|
|
path_force_total = path_force_total + pair_force_sum()
|
|
path_tangent_force_total = path_tangent_force_total + pair_tan_force_sum()
|
|
path_gap_total = path_gap_total + pair_gap_sum()
|
|
path_slip_total = path_slip_total + pair_slip_sum()
|
|
path_fric_work_total = path_fric_work_total + contact_friction_work_step
|
|
path_activated_total = path_activated_total + &
|
|
count_pair_status(CONTACT_PAIR_ACTIVATED)
|
|
path_released_total = path_released_total + &
|
|
count_pair_status(CONTACT_PAIR_RELEASED)
|
|
call contact_get_search_stats(step_search_facets, step_search_masters, &
|
|
step_search_broad, step_search_active, &
|
|
step_search_bvh_nodes)
|
|
call contact_get_cache_stats(step_cache_used, step_cache_overflow)
|
|
path_bvh_nodes_total = path_bvh_nodes_total + step_search_bvh_nodes
|
|
path_cache_used_total = path_cache_used_total + step_cache_used
|
|
path_cache_overflow_total = path_cache_overflow_total + &
|
|
step_cache_overflow
|
|
end do
|
|
call cpu_time(t1)
|
|
|
|
active_count = contact_active_count
|
|
state_open_count = count_pair_status(CONTACT_PAIR_OPEN)
|
|
state_activated_count = count_pair_status(CONTACT_PAIR_ACTIVATED)
|
|
state_maintained_count = count_pair_status(CONTACT_PAIR_MAINTAINED)
|
|
state_released_count = count_pair_status(CONTACT_PAIR_RELEASED)
|
|
activation_count = pair_activation_sum()
|
|
release_count = pair_release_sum()
|
|
final_force_total = pair_force_sum()
|
|
final_tangent_force_total = pair_tan_force_sum()
|
|
final_gap_total = pair_gap_sum()
|
|
final_slip_total = pair_slip_sum()
|
|
final_fric_work_total = contact_friction_work_total
|
|
call contact_get_search_stats(search_facets, search_masters, search_broad, &
|
|
search_active, search_bvh_nodes)
|
|
call contact_get_cache_stats(cache_used, cache_overflow)
|
|
call contact_get_perf_stats(search_time, force_time, tangent_time)
|
|
|
|
call require_positive(active_count, 'active_count')
|
|
if (step_count .eq. 1) then
|
|
call require_positive(search_bvh_nodes, 'search_bvh_nodes')
|
|
end if
|
|
call require_positive(cache_used, 'cache_used')
|
|
if (cache_overflow .ne. 0) call die('unexpected contact cache overflow')
|
|
call require_positive(path_active_total, 'path_active_total')
|
|
call require_positive(path_bvh_nodes_total, 'path_bvh_nodes_total')
|
|
call require_positive(path_cache_used_total, 'path_cache_used_total')
|
|
if (path_cache_overflow_total .ne. 0) then
|
|
call die('unexpected path contact cache overflow')
|
|
end if
|
|
|
|
write(*,'(A)') 'FemLite contact pair performance'
|
|
write(*,'(A,I8)') ' facets_per_side: ', nfacet
|
|
write(*,'(A,I8)') ' path_steps: ', step_count
|
|
write(*,'(A,I8)') ' path_active: ', path_active_total
|
|
write(*,'(A,I8)') ' path_activated: ', path_activated_total
|
|
write(*,'(A,I8)') ' path_released: ', path_released_total
|
|
write(*,'(A,I8)') ' path_bvh_nodes: ', path_bvh_nodes_total
|
|
write(*,'(A,I8)') ' path_cache_used: ', path_cache_used_total
|
|
write(*,'(A,I8)') ' path_cache_over: ', path_cache_overflow_total
|
|
write(*,'(A,ES16.8)') ' path_force_sum: ', path_force_total
|
|
write(*,'(A,ES16.8)') ' path_tan_mat_sum:', path_tangent_matrix_total
|
|
write(*,'(A,ES16.8)') ' path_tan_f_sum: ', path_tangent_force_total
|
|
write(*,'(A,ES16.8)') ' path_gap_sum: ', path_gap_total
|
|
write(*,'(A,ES16.8)') ' path_slip_sum: ', path_slip_total
|
|
write(*,'(A,ES16.8)') ' path_fric_work: ', path_fric_work_total
|
|
write(*,'(A,I8)') ' active_count: ', active_count
|
|
write(*,'(A,I8)') ' state_open: ', state_open_count
|
|
write(*,'(A,I8)') ' state_activated: ', state_activated_count
|
|
write(*,'(A,I8)') ' state_maintained:', state_maintained_count
|
|
write(*,'(A,I8)') ' state_released: ', state_released_count
|
|
write(*,'(A,I8)') ' activation_count:', activation_count
|
|
write(*,'(A,I8)') ' release_count: ', release_count
|
|
write(*,'(A,I8)') ' search_facets: ', search_facets
|
|
write(*,'(A,I8)') ' search_masters: ', search_masters
|
|
write(*,'(A,I8)') ' search_broad: ', search_broad
|
|
write(*,'(A,I8)') ' search_active: ', search_active
|
|
write(*,'(A,I8)') ' bvh_nodes: ', search_bvh_nodes
|
|
write(*,'(A,I8)') ' cache_used: ', cache_used
|
|
write(*,'(A,I8)') ' cache_overflow: ', cache_overflow
|
|
write(*,'(A,ES16.8)') ' force_sum: ', final_force_total
|
|
write(*,'(A,ES16.8)') ' tan_force_sum: ', final_tangent_force_total
|
|
write(*,'(A,ES16.8)') ' gap_sum: ', final_gap_total
|
|
write(*,'(A,ES16.8)') ' slip_sum: ', final_slip_total
|
|
write(*,'(A,ES16.8)') ' fric_work: ', final_fric_work_total
|
|
write(*,'(A,ES12.5)') ' search_cpu: ', search_time
|
|
write(*,'(A,ES12.5)') ' force_cpu: ', force_time
|
|
write(*,'(A,ES12.5)') ' tangent_cpu: ', tangent_time
|
|
write(*,'(A,F12.6)') ' wall_force_cpu: ', t1 - t0
|
|
write(*,'(A)') ' result: PASS'
|
|
|
|
call database_finalize(ierr)
|
|
call exit_if_error(ierr, 'database_finalize')
|
|
|
|
contains
|
|
|
|
subroutine parse_args(nfacet_out, do_tangent_out, step_count_out)
|
|
integer, intent(inout) :: nfacet_out
|
|
integer, intent(inout) :: do_tangent_out
|
|
integer, intent(inout) :: step_count_out
|
|
character(len=64) :: arg
|
|
integer :: argc
|
|
integer :: ios
|
|
|
|
intrinsic iargc
|
|
intrinsic getarg
|
|
|
|
argc = iargc()
|
|
if (argc .ge. 1) then
|
|
call getarg(1, arg)
|
|
read(arg, *, iostat=ios) nfacet_out
|
|
if (ios .ne. 0) call die('invalid facet count argument')
|
|
end if
|
|
if (argc .ge. 2) then
|
|
call getarg(2, arg)
|
|
read(arg, *, iostat=ios) do_tangent_out
|
|
if (ios .ne. 0) call die('invalid tangent flag argument')
|
|
end if
|
|
if (argc .ge. 3) then
|
|
call getarg(3, arg)
|
|
read(arg, *, iostat=ios) step_count_out
|
|
if (ios .ne. 0) call die('invalid path step count argument')
|
|
end if
|
|
if (nfacet_out .lt. 17) call die('facet count must be at least 17')
|
|
if (step_count_out .lt. 1) call die('path step count must be positive')
|
|
end subroutine parse_args
|
|
|
|
subroutine update_slave_path(step, step_count_in)
|
|
integer, intent(in) :: step
|
|
integer, intent(in) :: step_count_in
|
|
integer :: elem
|
|
integer :: local_node
|
|
integer :: node
|
|
integer :: dof_z
|
|
real(rk) :: phase
|
|
real(rk) :: penetration
|
|
|
|
if (step_count_in .le. 1) then
|
|
phase = ZERO
|
|
else
|
|
phase = real(step - 1, rk) / real(step_count_in - 1, rk)
|
|
end if
|
|
penetration = 0.01_rk + 0.004_rk * phase
|
|
|
|
do elem = nfacet + 1, 2 * nfacet
|
|
do local_node = 1, elem_nnode(elem)
|
|
node = elem_conn(local_node, elem)
|
|
dof_z = dof_id(3, node)
|
|
if (dof_z .gt. 0) then
|
|
u(dof_z) = -penetration
|
|
v(dof_z) = -0.004_rk
|
|
end if
|
|
end do
|
|
end do
|
|
coord = coord0
|
|
end subroutine update_slave_path
|
|
|
|
subroutine setup_contact_perf_model(nfacet_in, ierr)
|
|
integer, intent(in) :: nfacet_in
|
|
integer, intent(out) :: ierr
|
|
integer :: num_nodes
|
|
integer :: num_elems
|
|
integer :: elem
|
|
|
|
num_nodes = 8 * nfacet_in
|
|
num_elems = 2 * nfacet_in
|
|
call database_allocate_model(num_nodes, num_elems, 0, 2, 0, num_elems, &
|
|
1, 0, 1, 0, 0, 0, 0, 0, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
do elem = 1, nfacet_in
|
|
call fill_shell_pair(elem, nfacet_in)
|
|
end do
|
|
coord = coord0
|
|
|
|
call fill_sets_and_material(nfacet_in)
|
|
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.25_rk
|
|
contact_pair_friction(1) = ZERO
|
|
ierr = FEM_SUCCESS
|
|
end subroutine setup_contact_perf_model
|
|
|
|
subroutine fill_shell_pair(index, nfacet_in)
|
|
integer, intent(in) :: index
|
|
integer, intent(in) :: nfacet_in
|
|
integer :: master_node
|
|
integer :: slave_node
|
|
integer :: slave_elem
|
|
real(rk) :: x0
|
|
|
|
master_node = 8 * (index - 1)
|
|
slave_node = master_node + 4
|
|
slave_elem = nfacet_in + index
|
|
x0 = 2.0_rk * real(index - 1, rk)
|
|
|
|
call set_quad_nodes(master_node, x0, ZERO)
|
|
call set_quad_nodes(slave_node, x0, -0.01_rk)
|
|
call set_shell_elem(index, master_node, 'S4')
|
|
call set_shell_elem(slave_elem, slave_node, 'S4')
|
|
end subroutine fill_shell_pair
|
|
|
|
subroutine set_quad_nodes(node_base, x0, z0)
|
|
integer, intent(in) :: node_base
|
|
real(rk), intent(in) :: x0
|
|
real(rk), intent(in) :: z0
|
|
integer :: node
|
|
|
|
do node = 1, 4
|
|
node_id_ext(node_base + node) = node_base + node
|
|
end do
|
|
coord0(:,node_base+1) = (/ x0, ZERO, z0 /)
|
|
coord0(:,node_base+2) = (/ x0 + ONE, ZERO, z0 /)
|
|
coord0(:,node_base+3) = (/ x0 + ONE, ONE, z0 /)
|
|
coord0(:,node_base+4) = (/ x0, ONE, z0 /)
|
|
end subroutine set_quad_nodes
|
|
|
|
subroutine set_shell_elem(elem, node_base, etype)
|
|
integer, intent(in) :: elem
|
|
integer, intent(in) :: node_base
|
|
character(len=*), intent(in) :: etype
|
|
|
|
elem_id_ext(elem) = elem
|
|
elem_type(elem) = etype
|
|
elem_nnode(elem) = 4
|
|
elem_conn(:,elem) = 0
|
|
elem_conn(1:4,elem) = (/ node_base + 1, node_base + 2, &
|
|
node_base + 3, node_base + 4 /)
|
|
elem_mat(elem) = 1
|
|
elem_sec(elem) = 1
|
|
end subroutine set_shell_elem
|
|
|
|
subroutine fill_sets_and_material(nfacet_in)
|
|
integer, intent(in) :: nfacet_in
|
|
integer :: i
|
|
|
|
elset_name(1) = 'MASTER'
|
|
elset_start(1) = 1
|
|
elset_count(1) = nfacet_in
|
|
do i = 1, nfacet_in
|
|
elset_items(i) = i
|
|
end do
|
|
elset_name(2) = 'SLAVE'
|
|
elset_start(2) = nfacet_in + 1
|
|
elset_count(2) = nfacet_in
|
|
do i = 1, nfacet_in
|
|
elset_items(nfacet_in + i) = nfacet_in + i
|
|
end do
|
|
|
|
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
|
|
end subroutine fill_sets_and_material
|
|
|
|
subroutine require_positive(value, label)
|
|
integer, intent(in) :: value
|
|
character(len=*), intent(in) :: label
|
|
|
|
if (value .gt. 0) return
|
|
write(*,'(A,A,A,I8)') 'expected positive ', trim(label), ': ', value
|
|
stop 1
|
|
end subroutine require_positive
|
|
|
|
integer function count_pair_status(status)
|
|
integer, intent(in) :: status
|
|
|
|
count_pair_status = 0
|
|
if (.not. allocated(contact_pair_status)) return
|
|
count_pair_status = count(contact_pair_status .eq. status)
|
|
end function count_pair_status
|
|
|
|
integer function pair_activation_sum()
|
|
pair_activation_sum = 0
|
|
if (allocated(contact_pair_activation_count)) then
|
|
pair_activation_sum = sum(contact_pair_activation_count)
|
|
end if
|
|
end function pair_activation_sum
|
|
|
|
integer function pair_release_sum()
|
|
pair_release_sum = 0
|
|
if (allocated(contact_pair_release_count)) then
|
|
pair_release_sum = sum(contact_pair_release_count)
|
|
end if
|
|
end function pair_release_sum
|
|
|
|
real(rk) function pair_force_sum()
|
|
pair_force_sum = ZERO
|
|
if (allocated(contact_pair_force_norm)) then
|
|
pair_force_sum = sum(contact_pair_force_norm)
|
|
end if
|
|
end function pair_force_sum
|
|
|
|
real(rk) function pair_tan_force_sum()
|
|
pair_tan_force_sum = ZERO
|
|
if (allocated(contact_pair_tangent_force)) then
|
|
pair_tan_force_sum = sum(abs(contact_pair_tangent_force))
|
|
end if
|
|
end function pair_tan_force_sum
|
|
|
|
real(rk) function pair_gap_sum()
|
|
pair_gap_sum = ZERO
|
|
if (allocated(contact_pair_gap_residual)) then
|
|
pair_gap_sum = sum(contact_pair_gap_residual)
|
|
end if
|
|
end function pair_gap_sum
|
|
|
|
real(rk) function pair_slip_sum()
|
|
pair_slip_sum = ZERO
|
|
if (allocated(contact_pair_slip)) then
|
|
pair_slip_sum = sum(contact_pair_slip)
|
|
end if
|
|
end function pair_slip_sum
|
|
|
|
real(rk) function csr_abs_sum(a)
|
|
type(csr_matrix), intent(in) :: a
|
|
|
|
csr_abs_sum = ZERO
|
|
if (associated(a%val)) csr_abs_sum = sum(abs(a%val))
|
|
end function csr_abs_sum
|
|
|
|
subroutine exit_if_error(ierr_in, label)
|
|
integer, intent(in) :: ierr_in
|
|
character(len=*), intent(in) :: label
|
|
integer :: code
|
|
integer :: ierr_local
|
|
character(len=256) :: message
|
|
|
|
if (ierr_in .eq. FEM_SUCCESS) return
|
|
call fem_get_last_error(code, message, ierr_local)
|
|
write(*,'(A,A)') 'failed in ', trim(label)
|
|
write(*,'(A,I8)') 'FemLite error code: ', code
|
|
write(*,'(A,A)') 'FemLite error: ', trim(message)
|
|
stop 1
|
|
end subroutine exit_if_error
|
|
|
|
subroutine die(message)
|
|
character(len=*), intent(in) :: message
|
|
|
|
write(*,'(A,A)') 'perf_contact_pair: ', trim(message)
|
|
stop 2
|
|
end subroutine die
|
|
|
|
end program perf_contact_pair
|