110 lines
3.7 KiB
Fortran
110 lines
3.7 KiB
Fortran
program test_coupling_facet_traction_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: SPH_COUPLING_DISTRIBUTION_MASS
|
|
use sph_shell, only: shell_reference_area
|
|
use sph_coupling_interface, only: coupling_external_force, &
|
|
coupling_max_traction, coupling_nonfinite_import_count, &
|
|
sph_coupling_apply_facet_tractions
|
|
implicit none
|
|
|
|
integer :: ierr
|
|
|
|
call check_traction_mapping()
|
|
call check_traction_nonfinite()
|
|
|
|
contains
|
|
|
|
subroutine check_traction_mapping()
|
|
integer :: ids(3)
|
|
integer :: i
|
|
real(rk) :: tractions(SPH_NDIM,3)
|
|
real(rk) :: expected(SPH_NDIM)
|
|
real(rk) :: max_norm
|
|
|
|
call build_case()
|
|
ids = (/ 1, 2, 3 /)
|
|
tractions(:,1) = (/ 1.0_rk, 0.0_rk, 3.0_rk /)
|
|
tractions(:,2) = (/ 0.0_rk, 2.0_rk, 0.0_rk /)
|
|
tractions(:,3) = (/ -1.0_rk, 1.0_rk, 0.5_rk /)
|
|
call sph_coupling_apply_facet_tractions(2, 3, ids, tractions, &
|
|
SPH_COUPLING_DISTRIBUTION_MASS, 21, ierr)
|
|
call assert_ok(ierr, 'facet traction import failed')
|
|
max_norm = 0.0_rk
|
|
do i = 1, 3
|
|
expected = tractions(:,i) * shell_reference_area(ids(i))
|
|
max_norm = max(max_norm, sqrt(sum(tractions(:,i) * tractions(:,i))))
|
|
call assert_vector_close(coupling_external_force(:,ids(i)), &
|
|
expected, 'facet traction force mismatch')
|
|
end do
|
|
call assert_close(coupling_max_traction, max_norm, &
|
|
'traction max diagnostic mismatch')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed after traction mapping')
|
|
end subroutine check_traction_mapping
|
|
|
|
subroutine check_traction_nonfinite()
|
|
integer :: ids(1)
|
|
real(rk) :: tractions(SPH_NDIM,1)
|
|
|
|
call build_case()
|
|
ids(1) = 1
|
|
tractions = 0.0_rk
|
|
tractions(1,1) = huge(tractions(1,1))
|
|
call sph_coupling_apply_facet_tractions(2, 1, ids, tractions, &
|
|
SPH_COUPLING_DISTRIBUTION_MASS, 22, ierr)
|
|
if (ierr == SPH_SUCCESS) call fail('nonfinite traction did not fail')
|
|
if (coupling_nonfinite_import_count <= 0) then
|
|
call fail('nonfinite traction diagnostic missing')
|
|
end if
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed after traction error')
|
|
end subroutine check_traction_nonfinite
|
|
|
|
subroutine build_case()
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for traction test')
|
|
call sph_read_inp('tests/data/coupling_load_mode_081.inp', ierr)
|
|
call assert_ok(ierr, 'read failed for traction test')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build failed for traction test')
|
|
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 assert_vector_close(actual, expected, message)
|
|
real(rk), intent(in) :: actual(SPH_NDIM)
|
|
real(rk), intent(in) :: expected(SPH_NDIM)
|
|
character(len=*), intent(in) :: message
|
|
integer :: i
|
|
|
|
do i = 1, SPH_NDIM
|
|
call assert_close(actual(i), expected(i), message)
|
|
end do
|
|
end subroutine assert_vector_close
|
|
|
|
subroutine fail(message)
|
|
character(len=*), intent(in) :: message
|
|
|
|
write(*, '(A)') trim(message)
|
|
stop 1
|
|
end subroutine fail
|
|
|
|
end program test_coupling_facet_traction_081
|