Add 0.7.1 blast snapshot diagnostics

This commit is contained in:
Codex
2026-07-04 00:15:57 +08:00
parent 6d06fd489a
commit e5ee0f5c3c
5 changed files with 240 additions and 25 deletions
@@ -0,0 +1,118 @@
program test_blast_multiregion_snapshot
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_source_count, blast_target_count, &
blast_candidate_pair_count, blast_skipped_source_count, &
blast_skipped_target_count, blast_gas_count, blast_water_count, &
blast_explosive_count, blast_source_mass, blast_source_energy, &
blast_source_pressure_mean, blast_gas_volume, &
blast_explosive_progress_mean, blast_water_pressure_min, &
blast_water_pressure_max
implicit none
integer :: ierr
real(rk) :: initial_progress
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed')
call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr)
call assert_ok(ierr, 'read multiregion Blast input failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build multiregion Blast input failed')
call assert_region_snapshot(1, 1, 2, 2)
call assert_region_snapshot(2, 1, 2, 2)
if (blast_source_count(3) /= 0 .or. blast_target_count(3) /= 0 .or. &
blast_candidate_pair_count(3) /= 0) then
call fail('disabled region snapshot was not empty')
end if
if (blast_skipped_source_count(1) <= 0) then
call fail('source phase mismatch skip count missing')
end if
if (blast_skipped_target_count(1) /= 0) then
call fail('Solid target region reported unexpected target skip')
end if
if (blast_skipped_target_count(2) /= 0) then
call fail('Shell target region reported unexpected target skip')
end if
initial_progress = blast_explosive_progress_mean(1)
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'advance multiregion Blast input failed')
if (blast_explosive_progress_mean(1) + 1.0e-12_rk < initial_progress) then
call fail('Blast multiregion progress regressed')
end if
if (blast_explosive_progress_mean(1) < 0.99_rk .or. &
blast_explosive_progress_mean(2) < 0.99_rk) then
call fail('Blast multiregion snapshot was not refreshed after advance')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed')
contains
subroutine assert_region_snapshot(region, expected_sources, expected_targets, &
expected_pairs)
integer, intent(in) :: region
integer, intent(in) :: expected_sources
integer, intent(in) :: expected_targets
integer, intent(in) :: expected_pairs
if (blast_source_count(region) /= expected_sources) then
call fail('Blast multiregion source count mismatch')
end if
if (blast_target_count(region) /= expected_targets) then
call fail('Blast multiregion target count mismatch')
end if
if (blast_candidate_pair_count(region) /= expected_pairs) then
call fail('Blast multiregion pair count mismatch')
end if
if (blast_water_count(region) /= 2) then
call fail('Blast multiregion Water count mismatch')
end if
if (blast_gas_count(region) /= 1) then
call fail('Blast multiregion Gas count mismatch')
end if
if (blast_explosive_count(region) /= 1) then
call fail('Blast multiregion Explosive count mismatch')
end if
call assert_close(blast_source_mass(region), 0.02_rk, &
'Blast multiregion source mass mismatch')
if (blast_source_energy(region) <= 0.0_rk) then
call fail('Blast multiregion source energy missing')
end if
if (blast_source_pressure_mean(region) <= 0.0_rk) then
call fail('Blast multiregion source pressure missing')
end if
call assert_close(blast_gas_volume(region), 1.25e-5_rk, &
'Blast multiregion Gas volume mismatch')
call assert_close(blast_water_pressure_min(region), 0.0_rk, &
'Blast multiregion Water pressure min mismatch')
call assert_close(blast_water_pressure_max(region), 0.0_rk, &
'Blast multiregion Water pressure max mismatch')
end subroutine assert_region_snapshot
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) > 1.0e-12_rk) call fail(message)
end subroutine assert_close
subroutine fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_blast_multiregion_snapshot
@@ -0,0 +1,75 @@
program test_blast_multiregion_target_filter
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
use sph_blast, only: sph_blast_refresh_snapshot, blast_target_set_name, &
blast_source_count, blast_target_count, blast_candidate_pair_count, &
blast_skipped_source_count, blast_skipped_target_count
use sph_database, only: particle_status, SPH_STATUS_FAILED
implicit none
integer :: ierr
call check_phase_and_set_filters()
call check_failed_solid_and_shell_targets()
contains
subroutine check_phase_and_set_filters()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for multiregion target filters')
call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr)
call assert_ok(ierr, 'read failed for multiregion target filters')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for multiregion target filters')
blast_target_set_name(2) = 'STRUCTURE_TARGET'
call sph_blast_refresh_snapshot(ierr)
call assert_ok(ierr, 'refresh failed for multiregion target filters')
if (blast_source_count(2) /= 1) call fail('Shell region source changed')
if (blast_target_count(2) /= 2) call fail('Shell phase target filter mismatch')
if (blast_skipped_target_count(2) < 2) then
call fail('Shell phase mismatch target skip missing')
end if
if (blast_candidate_pair_count(2) /= 2) call fail('Shell phase pair mismatch')
if (blast_skipped_source_count(2) <= 0) call fail('source skip diagnostic missing')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for multiregion target filters')
end subroutine check_phase_and_set_filters
subroutine check_failed_solid_and_shell_targets()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for failed target filters')
call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr)
call assert_ok(ierr, 'read failed for failed target filters')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for failed target filters')
particle_status(5) = SPH_STATUS_FAILED
particle_status(7) = SPH_STATUS_FAILED
call sph_blast_refresh_snapshot(ierr)
call assert_ok(ierr, 'refresh failed for failed target filters')
if (blast_target_count(1) /= 1) call fail('failed Solid target was not skipped')
if (blast_target_count(2) /= 1) call fail('failed Shell target was not skipped')
if (blast_skipped_target_count(1) < 1) call fail('failed Solid skip missing')
if (blast_skipped_target_count(2) < 1) call fail('failed Shell skip missing')
if (blast_candidate_pair_count(1) /= 1) call fail('failed Solid pair mismatch')
if (blast_candidate_pair_count(2) /= 1) call fail('failed Shell pair mismatch')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for failed target filters')
end subroutine check_failed_solid_and_shell_targets
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_multiregion_target_filter