Add 0.7.1 blast region input stabilization

This commit is contained in:
Codex
2026-07-04 00:11:54 +08:00
parent 2bc527179e
commit 6d06fd489a
10 changed files with 428 additions and 29 deletions
@@ -0,0 +1,95 @@
program test_input_blast_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_get_input_warning_count
use sph_blast, only: blast_region_count, blast_region_name, &
blast_target_set_name, blast_source_phase, blast_target_phase, &
blast_region_enabled, blast_radius, blast_load_scale, blast_time_window, &
SPH_BLAST_PHASE_GAS, SPH_BLAST_PHASE_SOLID, SPH_BLAST_PHASE_SHELL, &
SPH_BLAST_PHASE_STRUCTURE
implicit none
integer :: ierr
integer :: warnings
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')
if (blast_region_count /= 3) call fail('Blast multiregion count mismatch')
call assert_region(1, 'SOLID_REGION', 'SOLID_TARGET', SPH_BLAST_PHASE_SOLID, &
.true., 1.0_rk, 2.0e-7_rk)
call assert_region(2, 'SHELL_REGION', 'SHELL_TARGET', SPH_BLAST_PHASE_SHELL, &
.true., 0.50_rk, 1.0e-7_rk)
call assert_region(3, 'DISABLED_REGION', 'STRUCTURE_TARGET', &
SPH_BLAST_PHASE_STRUCTURE, .false., 1.0_rk, 2.0e-7_rk)
call sph_build_model(ierr)
call assert_ok(ierr, 'build multiregion Blast input failed')
call sph_get_input_warning_count(warnings, ierr)
call assert_ok(ierr, 'Blast warning count failed')
if (warnings <= 0) call fail('disabled Blast region warning missing')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed')
contains
subroutine assert_region(region, expected_name, expected_set, &
expected_target_phase, expected_enabled, expected_scale, &
expected_time_window)
integer, intent(in) :: region
character(len=*), intent(in) :: expected_name
character(len=*), intent(in) :: expected_set
integer, intent(in) :: expected_target_phase
logical, intent(in) :: expected_enabled
real(rk), intent(in) :: expected_scale
real(rk), intent(in) :: expected_time_window
if (trim(blast_region_name(region)) /= trim(expected_name)) then
call fail('Blast region name mismatch')
end if
if (trim(blast_target_set_name(region)) /= trim(expected_set)) then
call fail('Blast region target set mismatch')
end if
if (blast_source_phase(region) /= SPH_BLAST_PHASE_GAS) then
call fail('Blast region source phase mismatch')
end if
if (blast_target_phase(region) /= expected_target_phase) then
call fail('Blast region target phase mismatch')
end if
if (blast_region_enabled(region) .neqv. expected_enabled) then
call fail('Blast region enabled flag mismatch')
end if
call assert_close(blast_radius(region), 0.50_rk, &
'Blast region radius mismatch')
call assert_close(blast_load_scale(region), expected_scale, &
'Blast region scale mismatch')
call assert_close(blast_time_window(region), expected_time_window, &
'Blast region time window mismatch')
end subroutine assert_region
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_input_blast_multiregion
@@ -0,0 +1,94 @@
program test_input_blast_region_errors_071
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_blast, only: sph_blast_reset, sph_blast_add_region
use sph_database, only: SPH_MAX_REGIONS
implicit none
call expect_input_error('tests/data/blast_duplicate_region_071.inp', &
'duplicate Blast region')
call expect_input_error('tests/data/blast_bad_center_071.inp', &
'bad Blast center')
call expect_input_error('tests/data/blast_bad_enabled_071.inp', &
'bad Blast enabled flag')
call expect_direct_error('bad source phase', 'PLASMA', 'SOLID', &
0.40_rk, 1.0_rk, 0.0_rk, 'RADIAL')
call expect_direct_error('bad target phase', 'GAS', 'BEAM', &
0.40_rk, 1.0_rk, 0.0_rk, 'RADIAL')
call expect_direct_error('bad time window', 'GAS', 'SOLID', &
0.40_rk, 1.0_rk, -1.0e-6_rk, 'RADIAL')
call expect_direct_error('bad mode', 'GAS', 'SOLID', &
0.40_rk, 1.0_rk, 0.0_rk, 'TANGENTIAL')
call expect_too_many_regions()
contains
subroutine expect_input_error(filename, label)
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: label
integer :: ierr
integer :: final_ierr
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for ' // label)
call sph_read_inp(filename, ierr)
if (ierr == SPH_SUCCESS) call sph_build_model(ierr)
if (ierr == SPH_SUCCESS) call fail('input unexpectedly passed: ' // label)
call sph_finalize(final_ierr)
call assert_ok(final_ierr, 'finalize failed for ' // label)
end subroutine expect_input_error
subroutine expect_direct_error(label, source_phase, target_phase, radius, &
scale, time_window, mode_name)
character(len=*), intent(in) :: label
character(len=*), intent(in) :: source_phase
character(len=*), intent(in) :: target_phase
real(rk), intent(in) :: radius
real(rk), intent(in) :: scale
real(rk), intent(in) :: time_window
character(len=*), intent(in) :: mode_name
real(rk) :: center(SPH_NDIM)
integer :: ierr
center = 0.0_rk
call sph_blast_reset()
call sph_blast_add_region('DIRECT_BAD', center, radius, source_phase, &
target_phase, 'NONE', scale, time_window, mode_name, ierr)
if (ierr == SPH_SUCCESS) call fail('direct check unexpectedly passed: ' // label)
end subroutine expect_direct_error
subroutine expect_too_many_regions()
real(rk) :: center(SPH_NDIM)
character(len=16) :: name
integer :: i
integer :: ierr
center = 0.0_rk
call sph_blast_reset()
do i = 1, SPH_MAX_REGIONS
write(name, '(A,I0)') 'REGION_', i
call sph_blast_add_region(name, center, 0.40_rk, 'GAS', &
'SOLID', 'NONE', 1.0_rk, 0.0_rk, 'RADIAL', ierr)
call assert_ok(ierr, 'failed before Blast region limit')
end do
call sph_blast_add_region('REGION_OVERFLOW', center, 0.40_rk, 'GAS', &
'SOLID', 'NONE', 1.0_rk, 0.0_rk, 'RADIAL', ierr)
if (ierr == SPH_SUCCESS) call fail('Blast region overflow unexpectedly passed')
end subroutine expect_too_many_regions
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_input_blast_region_errors_071