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

110 lines
3.6 KiB
Fortran

program test_coupling_distribution_mass_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: mass, SPH_COUPLING_DISTRIBUTION_MASS
use sph_shell, only: shell_director
use sph_coupling_interface, only: coupling_external_force, &
sph_coupling_apply_facet_resultants
implicit none
integer :: ierr
call check_mass_distribution()
call check_bad_mass_weight()
call check_nonfinite_normal()
contains
subroutine check_mass_distribution()
integer :: ids(1)
real(rk) :: resultants(SPH_NDIM,1)
call build_case()
ids(1) = 2
resultants(:,1) = (/ -1.0_rk, 3.0_rk, 2.0_rk /)
call sph_coupling_apply_facet_resultants(2, 1, ids, resultants, &
SPH_COUPLING_DISTRIBUTION_MASS, 61, ierr)
call assert_ok(ierr, 'mass distribution failed')
call assert_vector_close(coupling_external_force(:,2), resultants(:,1), &
'mass distribution force mismatch')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after mass distribution')
end subroutine check_mass_distribution
subroutine check_bad_mass_weight()
integer :: ids(1)
real(rk) :: resultants(SPH_NDIM,1)
call build_case()
ids(1) = 2
resultants(:,1) = (/ 1.0_rk, 0.0_rk, 0.0_rk /)
mass(2) = 0.0_rk
call sph_coupling_apply_facet_resultants(2, 1, ids, resultants, &
SPH_COUPLING_DISTRIBUTION_MASS, 62, ierr)
if (ierr == SPH_SUCCESS) call fail('nonpositive mass weight did not fail')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after bad mass')
end subroutine check_bad_mass_weight
subroutine check_nonfinite_normal()
integer :: ids(1)
real(rk) :: resultants(SPH_NDIM,1)
call build_case()
ids(1) = 2
resultants(:,1) = (/ 1.0_rk, 0.0_rk, 0.0_rk /)
shell_director(1,2) = huge(shell_director(1,2))
call sph_coupling_apply_facet_resultants(2, 1, ids, resultants, &
SPH_COUPLING_DISTRIBUTION_MASS, 63, ierr)
if (ierr == SPH_SUCCESS) call fail('nonfinite facet normal did not fail')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after nonfinite normal')
end subroutine check_nonfinite_normal
subroutine build_case()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for mass distribution')
call sph_read_inp('tests/data/coupling_load_mode_081.inp', ierr)
call assert_ok(ierr, 'read failed for mass distribution')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for mass distribution')
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_distribution_mass_081