161 lines
6.3 KiB
Fortran
161 lines
6.3 KiB
Fortran
program test_coupling_contact_diagnostics_081
|
|
use sph_precision, only: rk, SPH_NDIM
|
|
use sph_error, only: SPH_SUCCESS
|
|
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
|
|
use sph_database, only: particle_status, SPH_STATUS_INACTIVE
|
|
use sph_coupling_interface, only: coupling_contact_flag, &
|
|
coupling_contact_normal, coupling_contact_gap, &
|
|
coupling_contact_penetration, coupling_contact_pressure, &
|
|
sph_coupling_apply_contact_state, sph_coupling_get_contact_diagnostics
|
|
implicit none
|
|
|
|
integer :: ierr
|
|
|
|
call check_contact_state_values()
|
|
call check_contact_state_errors()
|
|
|
|
contains
|
|
|
|
subroutine check_contact_state_values()
|
|
integer :: ids(2)
|
|
integer :: one_id(1)
|
|
integer :: empty_ids(0)
|
|
real(rk) :: normals(SPH_NDIM,2)
|
|
real(rk) :: one_normal(SPH_NDIM,1)
|
|
real(rk) :: empty_normals(SPH_NDIM,0)
|
|
real(rk) :: gaps(2)
|
|
real(rk) :: penetrations(2)
|
|
real(rk) :: contact_pressures(2)
|
|
real(rk) :: one_gap(1)
|
|
real(rk) :: one_penetration(1)
|
|
real(rk) :: one_pressure(1)
|
|
real(rk) :: empty_scalars(0)
|
|
integer :: active_count
|
|
integer :: skipped_count
|
|
integer :: stale_count
|
|
integer :: repeated_count
|
|
integer :: nonfinite_count
|
|
integer :: bad_area_count
|
|
integer :: invalid_weight_count
|
|
real(rk) :: max_penetration
|
|
|
|
call build_case()
|
|
ids = (/ 1, 2 /)
|
|
normals(:,1) = (/ 0.0_rk, 0.0_rk, 2.0_rk /)
|
|
normals(:,2) = (/ 0.0_rk, 0.0_rk, 1.0_rk /)
|
|
gaps = (/ 1.0e-4_rk, 2.0e-4_rk /)
|
|
penetrations = (/ 2.0e-3_rk, 4.0e-3_rk /)
|
|
contact_pressures = (/ 8.0_rk, 6.0_rk /)
|
|
call sph_coupling_apply_contact_state(1, 2, ids, normals, gaps, &
|
|
penetrations, contact_pressures, 101, ierr)
|
|
call assert_ok(ierr, 'contact state import failed')
|
|
if (coupling_contact_flag(1) /= 1) call fail('contact flag missing')
|
|
call assert_close(coupling_contact_normal(3,1), 1.0_rk, &
|
|
'contact normal was not normalized')
|
|
call assert_close(coupling_contact_gap(2), gaps(2), 'contact gap mismatch')
|
|
call assert_close(coupling_contact_penetration(2), penetrations(2), &
|
|
'contact penetration mismatch')
|
|
call assert_close(coupling_contact_pressure(1), contact_pressures(1), &
|
|
'contact pressure mismatch')
|
|
|
|
one_id(1) = 3
|
|
one_normal(:,1) = (/ 0.0_rk, 0.0_rk, 1.0_rk /)
|
|
one_gap(1) = 0.0_rk
|
|
one_penetration(1) = 1.0e-3_rk
|
|
one_pressure(1) = 1.0_rk
|
|
particle_status(3) = SPH_STATUS_INACTIVE
|
|
call sph_coupling_apply_contact_state(1, 1, one_id, one_normal, one_gap, &
|
|
one_penetration, one_pressure, 101, ierr)
|
|
call assert_ok(ierr, 'skipped contact import failed')
|
|
|
|
call sph_coupling_get_contact_diagnostics(active_count, skipped_count, &
|
|
max_penetration, stale_count, repeated_count, nonfinite_count, &
|
|
bad_area_count, invalid_weight_count, ierr)
|
|
call assert_ok(ierr, 'contact diagnostics failed')
|
|
if (active_count /= 2) call fail('active contact count mismatch')
|
|
if (skipped_count /= 1) call fail('skipped contact count mismatch')
|
|
if (repeated_count <= 0) call fail('repeated contact diagnostic missing')
|
|
call assert_close(max_penetration, 4.0e-3_rk, &
|
|
'max penetration mismatch')
|
|
if (nonfinite_count /= 0) call fail('unexpected nonfinite contact count')
|
|
|
|
call sph_coupling_apply_contact_state(1, 0, empty_ids, empty_normals, &
|
|
empty_scalars, empty_scalars, empty_scalars, 102, ierr)
|
|
call assert_ok(ierr, 'empty contact import failed')
|
|
call sph_coupling_get_contact_diagnostics(active_count, skipped_count, &
|
|
max_penetration, stale_count, repeated_count, nonfinite_count, &
|
|
bad_area_count, invalid_weight_count, ierr)
|
|
call assert_ok(ierr, 'empty contact diagnostics failed')
|
|
if (active_count /= 0) call fail('empty contact import left active state')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed after contact values')
|
|
end subroutine check_contact_state_values
|
|
|
|
subroutine check_contact_state_errors()
|
|
integer :: ids(1)
|
|
real(rk) :: normals(SPH_NDIM,1)
|
|
real(rk) :: gaps(1)
|
|
real(rk) :: penetrations(1)
|
|
real(rk) :: contact_pressures(1)
|
|
integer :: active_count
|
|
integer :: skipped_count
|
|
integer :: stale_count
|
|
integer :: repeated_count
|
|
integer :: nonfinite_count
|
|
integer :: bad_area_count
|
|
integer :: invalid_weight_count
|
|
real(rk) :: max_penetration
|
|
|
|
call build_case()
|
|
ids(1) = 1
|
|
normals(:,1) = (/ 0.0_rk, 0.0_rk, 1.0_rk /)
|
|
gaps(1) = 0.0_rk
|
|
penetrations(1) = 0.0_rk
|
|
contact_pressures(1) = huge(contact_pressures(1))
|
|
call sph_coupling_apply_contact_state(1, 1, ids, normals, gaps, &
|
|
penetrations, contact_pressures, 111, ierr)
|
|
if (ierr == SPH_SUCCESS) call fail('nonfinite contact state did not fail')
|
|
call sph_coupling_get_contact_diagnostics(active_count, skipped_count, &
|
|
max_penetration, stale_count, repeated_count, nonfinite_count, &
|
|
bad_area_count, invalid_weight_count, ierr)
|
|
call assert_ok(ierr, 'contact error diagnostics failed')
|
|
if (nonfinite_count <= 0) call fail('nonfinite contact diagnostic missing')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed after contact errors')
|
|
end subroutine check_contact_state_errors
|
|
|
|
subroutine build_case()
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for contact diagnostics')
|
|
call sph_read_inp('tests/data/coupling_load_mode_081.inp', ierr)
|
|
call assert_ok(ierr, 'read failed for contact diagnostics')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build failed for contact diagnostics')
|
|
end subroutine build_case
|
|
|
|
subroutine assert_ok(ierr_value, message)
|
|
integer, intent(in) :: ierr_value
|
|
character(len=*), intent(in) :: message
|
|
|
|
if (ierr_value /= SPH_SUCCESS) call fail(message)
|
|
end subroutine assert_ok
|
|
|
|
subroutine assert_close(actual, expected, message)
|
|
real(rk), intent(in) :: actual
|
|
real(rk), intent(in) :: expected
|
|
character(len=*), intent(in) :: message
|
|
|
|
if (abs(actual - expected) > max(1.0e-10_rk, abs(expected) * 1.0e-8_rk)) then
|
|
call fail(message)
|
|
end if
|
|
end subroutine assert_close
|
|
|
|
subroutine fail(message)
|
|
character(len=*), intent(in) :: message
|
|
|
|
write(*, '(A)') trim(message)
|
|
stop 1
|
|
end subroutine fail
|
|
|
|
end program test_coupling_contact_diagnostics_081
|