Apply blast loads in explicit response

This commit is contained in:
Codex
2026-07-03 23:25:36 +08:00
parent fc9c955dc7
commit 15abae6341
8 changed files with 458 additions and 37 deletions
+114
View File
@@ -0,0 +1,114 @@
program test_blast_noop_regression
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: particle_status, v, SPH_STATUS_FAILED
use sph_blast_load, only: blast_solid_external_force, &
blast_shell_external_force, blast_load_target_count, &
blast_load_total_force, sph_blast_load_compute_at, &
sph_blast_load_set_enabled
implicit none
integer :: ierr
call check_disabled_path()
call check_time_window_clear()
call check_failed_solid_target()
call check_failed_shell_target()
contains
subroutine check_disabled_path()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for disabled Blast load')
call sph_read_inp('tests/data/blast_water_gas_explosive_solid_070.inp', ierr)
call assert_ok(ierr, 'read failed for disabled Blast load')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for disabled Blast load')
call sph_blast_load_set_enabled(.false.)
call sph_advance_explicit(1.0e-8_rk, ierr)
call assert_ok(ierr, 'advance failed for disabled Blast load')
if (blast_load_target_count(1) /= 0) call fail('disabled Blast load applied')
if (maxval(abs(blast_load_total_force(:,1))) > 0.0_rk) then
call fail('disabled Blast load force not cleared')
end if
if (abs(v(1,5)) > 1.0e-18_rk) call fail('disabled Blast moved Solid target')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for disabled Blast load')
end subroutine check_disabled_path
subroutine check_time_window_clear()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Blast time window')
call sph_read_inp('tests/data/blast_water_gas_explosive_solid_070.inp', ierr)
call assert_ok(ierr, 'read failed for Blast time window')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Blast time window')
call sph_blast_load_compute_at(3.0e-7_rk, ierr)
call assert_ok(ierr, 'Blast time-window recompute failed')
if (blast_load_target_count(1) /= 0) call fail('Blast time window did not clear')
if (maxval(abs(blast_solid_external_force)) > 0.0_rk) then
call fail('Blast time-window force cache not cleared')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Blast time window')
end subroutine check_time_window_clear
subroutine check_failed_solid_target()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for failed Solid target')
call sph_read_inp('tests/data/blast_water_gas_explosive_solid_070.inp', ierr)
call assert_ok(ierr, 'read failed for failed Solid target')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for failed Solid target')
particle_status(5) = SPH_STATUS_FAILED
call sph_blast_load_compute_at(0.0_rk, ierr)
call assert_ok(ierr, 'failed Solid target recompute failed')
if (blast_load_target_count(1) /= 1) call fail('failed Solid target not skipped')
if (maxval(abs(blast_solid_external_force(:,5))) > 0.0_rk) then
call fail('failed Solid target received load')
end if
if (blast_solid_external_force(1,6) <= 0.0_rk) then
call fail('active Solid target lost load')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for failed Solid target')
end subroutine check_failed_solid_target
subroutine check_failed_shell_target()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for failed Shell target')
call sph_read_inp('tests/data/blast_water_gas_explosive_shell_070.inp', ierr)
call assert_ok(ierr, 'read failed for failed Shell target')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for failed Shell target')
particle_status(5) = SPH_STATUS_FAILED
call sph_blast_load_compute_at(0.0_rk, ierr)
call assert_ok(ierr, 'failed Shell target recompute failed')
if (blast_load_target_count(1) /= 1) call fail('failed Shell target not skipped')
if (maxval(abs(blast_shell_external_force(:,5))) > 0.0_rk) then
call fail('failed Shell target received load')
end if
if (blast_shell_external_force(1,6) <= 0.0_rk) then
call fail('active Shell target lost load')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for failed Shell target')
end subroutine check_failed_shell_target
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_noop_regression
@@ -0,0 +1,73 @@
program test_blast_shell_response
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_shell_external_force, &
blast_shell_external_moment, blast_load_max_acceleration, &
blast_load_nonfinite_count
implicit none
integer :: ierr
real(rk) :: director_before(3)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Blast Shell response')
call sph_read_inp('tests/data/blast_water_gas_explosive_shell_070.inp', ierr)
call assert_ok(ierr, 'read failed for Blast Shell response')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Blast Shell response')
director_before = shell_director(:,5)
if (blast_shell_external_force(1,5) <= 0.0_rk) then
call fail('Shell Blast preload direction mismatch')
end if
if (maxval(abs(blast_shell_external_moment)) > 0.0_rk) then
call fail('Shell Blast moment placeholder changed')
end if
call sph_advance_explicit(1.0e-8_rk, ierr)
call assert_ok(ierr, 'advance failed for Blast Shell response')
if (a(1,5) <= 0.0_rk) call fail('Shell Blast acceleration missing')
if (v(1,5) <= 0.0_rk) call fail('Shell Blast velocity missing')
call assert_transverse_small(5, 'Shell transverse acceleration mismatch')
if (maxval(abs(shell_director(:,5) - director_before)) > 1.0e-12_rk) then
call fail('Shell director changed through Blast load path')
end if
if (maxval(abs(blast_shell_external_moment)) > 0.0_rk) then
call fail('Shell Blast moment placeholder changed after advance')
end if
if (blast_load_max_acceleration(1) <= 0.0_rk) then
call fail('Shell Blast acceleration diagnostic missing')
end if
if (blast_load_nonfinite_count(1) /= 0) call fail('Shell Blast nonfinite load')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Blast Shell response')
contains
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_shell_response
@@ -0,0 +1,80 @@
program test_blast_solid_response
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_blast_load, only: blast_solid_external_force, &
blast_load_max_acceleration, blast_load_nonfinite_count
implicit none
integer :: ierr
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Blast Solid response')
call sph_read_inp('tests/data/blast_water_gas_explosive_solid_070.inp', ierr)
call assert_ok(ierr, 'read failed for Blast Solid response')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Blast Solid response')
if (blast_solid_external_force(1,5) <= 0.0_rk) then
call fail('Solid Blast preload direction mismatch')
end if
call sph_advance_explicit(1.0e-8_rk, ierr)
call assert_ok(ierr, 'first advance failed for Blast Solid response')
call assert_positive_x_response('first Solid response missing')
call assert_transverse_small(5, 'first Solid transverse acceleration mismatch')
if (blast_load_max_acceleration(1) <= 0.0_rk) then
call fail('Solid Blast acceleration diagnostic missing')
end if
if (blast_load_nonfinite_count(1) /= 0) call fail('Solid Blast nonfinite load')
call check_second_step_accumulates()
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Blast Solid response')
contains
subroutine check_second_step_accumulates()
real(rk) :: previous_velocity
previous_velocity = v(1,5)
call sph_advance_explicit(1.0e-8_rk, ierr)
call assert_ok(ierr, 'second advance failed for Blast Solid response')
if (v(1,5) <= previous_velocity) then
call fail('Solid Blast velocity did not accumulate')
end if
call assert_positive_x_response('second Solid response missing')
end subroutine check_second_step_accumulates
subroutine assert_positive_x_response(message)
character(len=*), intent(in) :: message
if (a(1,5) <= 0.0_rk) call fail(message)
if (v(1,5) <= 0.0_rk) call fail(message)
end subroutine assert_positive_x_response
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_solid_response
+54
View File
@@ -0,0 +1,54 @@
program test_blast_solver_order
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_blast, only: blast_candidate_pair_count, &
blast_explosive_progress_mean
use sph_blast_load, only: blast_load_target_count, blast_load_pair_count, &
blast_load_energy_input, blast_load_nonfinite_count
implicit none
integer :: ierr
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Blast solver order')
call sph_read_inp('tests/data/blast_water_gas_explosive_solid_shell_070.inp', ierr)
call assert_ok(ierr, 'read failed for Blast solver order')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Blast solver order')
if (blast_load_target_count(1) /= 4) call fail('initial Blast target mismatch')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'advance failed for Blast solver order')
if (blast_explosive_progress_mean(1) < 0.99_rk) then
call fail('Blast snapshot did not refresh after Explosive update')
end if
if (blast_load_pair_count(1) /= blast_candidate_pair_count(1)) then
call fail('Blast post-step pair count mismatch')
end if
if (blast_load_energy_input(1) <= 0.0_rk) then
call fail('Blast energy diagnostic missing after Gas source update')
end if
if (blast_load_nonfinite_count(1) /= 0) call fail('Blast post-step nonfinite load')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Blast solver order')
contains
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_solver_order