Files
SPHLite/tests/module/test_blast_response_multiregion.f90
2026-07-04 00:31:47 +08:00

152 lines
5.9 KiB
Fortran

program test_blast_response_multiregion
use sph_precision, only: rk
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, &
sph_build_model, sph_advance_explicit
use sph_database, only: a, v
use sph_shell, only: shell_director
use sph_blast_load, only: blast_solid_external_force, &
blast_shell_external_force, blast_shell_external_moment, &
blast_solid_total_force, blast_shell_total_force, &
blast_load_total_force, blast_load_max_acceleration, &
blast_load_nonfinite_count
implicit none
integer :: ierr
call check_solid_superposition_response()
call check_solid_shell_mixed_response()
contains
subroutine check_solid_superposition_response()
real(rk) :: initial_force(3)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Solid superposition response')
call sph_read_inp('tests/data/blast_solid_superposition_071.inp', ierr)
call assert_ok(ierr, 'read failed for Solid superposition response')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Solid superposition response')
initial_force = blast_solid_external_force(:,5)
if (initial_force(1) <= 0.0_rk) call fail('Solid preload direction missing')
if (maxval(abs(blast_shell_external_force)) > 0.0_rk) then
call fail('Solid superposition polluted Shell cache')
end if
call assert_vector_close(blast_solid_total_force(:,2), &
0.5_rk * blast_solid_total_force(:,1), &
'Solid superposition region scaling mismatch')
call sph_advance_explicit(1.0e-8_rk, ierr)
call assert_ok(ierr, 'advance failed for Solid superposition response')
if (a(1,5) <= 0.0_rk) call fail('Solid acceleration direction missing')
if (v(1,5) <= 0.0_rk) call fail('Solid velocity response missing')
call assert_transverse_small(5, 'Solid transverse response mismatch')
if (blast_load_max_acceleration(1) <= 0.0_rk .or. &
blast_load_max_acceleration(2) <= 0.0_rk) then
call fail('Solid superposition acceleration diagnostic missing')
end if
if (blast_load_nonfinite_count(1) /= 0 .or. &
blast_load_nonfinite_count(2) /= 0) then
call fail('Solid superposition nonfinite diagnostic mismatch')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Solid superposition response')
end subroutine check_solid_superposition_response
subroutine check_solid_shell_mixed_response()
real(rk) :: director_before(3)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for mixed response')
call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr)
call assert_ok(ierr, 'read failed for mixed response')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for mixed response')
director_before = shell_director(:,7)
if (blast_solid_external_force(1,5) <= 0.0_rk) then
call fail('mixed Solid preload missing')
end if
if (blast_shell_external_force(1,7) <= 0.0_rk) then
call fail('mixed Shell preload missing')
end if
if (maxval(abs(blast_solid_external_force(:,7:8))) > 0.0_rk) then
call fail('Shell particles polluted Solid load cache')
end if
if (maxval(abs(blast_shell_external_force(:,5:6))) > 0.0_rk) then
call fail('Solid particles polluted Shell load cache')
end if
if (maxval(abs(blast_shell_total_force(:,1))) > 0.0_rk) then
call fail('Solid region polluted Shell total force')
end if
if (maxval(abs(blast_solid_total_force(:,2))) > 0.0_rk) then
call fail('Shell region polluted Solid total force')
end if
if (maxval(abs(blast_load_total_force(:,3))) > 0.0_rk) then
call fail('disabled region produced mixed response force')
end if
call sph_advance_explicit(1.0e-8_rk, ierr)
call assert_ok(ierr, 'advance failed for mixed response')
if (v(1,5) <= 0.0_rk .or. a(1,5) <= 0.0_rk) then
call fail('mixed Solid response missing')
end if
if (v(1,7) <= 0.0_rk .or. a(1,7) <= 0.0_rk) then
call fail('mixed Shell response missing')
end if
call assert_transverse_small(5, 'mixed Solid transverse mismatch')
if (v(2,7) <= 0.0_rk .or. a(2,7) <= 0.0_rk) then
call fail('mixed Shell radial y response missing')
end if
if (abs(a(3,7)) > max(abs(a(1,7)), abs(a(2,7))) * 1.0e-8_rk) then
call fail('mixed Shell out-of-plane response mismatch')
end if
if (maxval(abs(shell_director(:,7) - director_before)) > 1.0e-12_rk) then
call fail('Shell director changed through mixed Blast load path')
end if
if (maxval(abs(blast_shell_external_moment)) > 0.0_rk) then
call fail('Shell Blast moment placeholder changed')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for mixed response')
end subroutine check_solid_shell_mixed_response
subroutine assert_vector_close(actual, expected, message)
real(rk), intent(in) :: actual(3)
real(rk), intent(in) :: expected(3)
character(len=*), intent(in) :: message
integer :: i
do i = 1, 3
if (abs(actual(i) - expected(i)) > &
max(1.0e-8_rk, abs(expected(i)) * 1.0e-10_rk)) then
call fail(message)
end if
end do
end subroutine assert_vector_close
subroutine assert_transverse_small(index, message)
integer, intent(in) :: index
character(len=*), intent(in) :: message
if (abs(a(2,index)) > abs(a(1,index)) * 1.0e-8_rk) call fail(message)
if (abs(a(3,index)) > abs(a(1,index)) * 1.0e-8_rk) call fail(message)
end subroutine assert_transverse_small
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 fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_blast_response_multiregion