Files
SPHLite/tests/module/test_coupling_facet_resultant_081.f90
T
2026-07-04 10:59:25 +08:00

101 lines
3.3 KiB
Fortran

program test_coupling_facet_resultant_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_UNIFORM
use sph_coupling_interface, only: coupling_external_force, &
coupling_nonfinite_import_count, sph_coupling_apply_facet_resultants
implicit none
integer :: ierr
call check_resultant_mapping()
call check_resultant_nonfinite()
contains
subroutine check_resultant_mapping()
integer :: ids(3)
integer :: i
real(rk) :: resultants(SPH_NDIM,3)
call build_case()
ids = (/ 1, 2, 3 /)
resultants(:,1) = (/ 1.0_rk, 2.0_rk, 3.0_rk /)
resultants(:,2) = (/ -2.0_rk, 1.0_rk, 0.0_rk /)
resultants(:,3) = (/ 0.5_rk, -0.5_rk, 4.0_rk /)
call sph_coupling_apply_facet_resultants(1, 3, ids, resultants, &
SPH_COUPLING_DISTRIBUTION_UNIFORM, 31, ierr)
call assert_ok(ierr, 'facet resultant import failed')
do i = 1, 3
call assert_vector_close(coupling_external_force(:,ids(i)), &
resultants(:,i), 'facet resultant force mismatch')
end do
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after resultant mapping')
end subroutine check_resultant_mapping
subroutine check_resultant_nonfinite()
integer :: ids(1)
real(rk) :: resultants(SPH_NDIM,1)
call build_case()
ids(1) = 1
resultants = 0.0_rk
resultants(2,1) = huge(resultants(2,1))
call sph_coupling_apply_facet_resultants(1, 1, ids, resultants, &
SPH_COUPLING_DISTRIBUTION_UNIFORM, 32, ierr)
if (ierr == SPH_SUCCESS) call fail('nonfinite resultant did not fail')
if (coupling_nonfinite_import_count <= 0) then
call fail('nonfinite resultant diagnostic missing')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after resultant error')
end subroutine check_resultant_nonfinite
subroutine build_case()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for resultant test')
call sph_read_inp('tests/data/coupling_load_mode_081.inp', ierr)
call assert_ok(ierr, 'read failed for resultant test')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for resultant 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_resultant_081