Harden explosive input coverage

This commit is contained in:
Codex
2026-07-03 13:22:54 +08:00
parent 843646d4b3
commit c4c5214c6a
11 changed files with 357 additions and 22 deletions
+12
View File
@@ -150,6 +150,18 @@ set_target_properties(test_input_explosive_errors PROPERTIES Fortran_MODULE_DIRE
add_test(NAME input_explosive_errors COMMAND test_input_explosive_errors)
set_tests_properties(input_explosive_errors PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_input_explosive_multi_ignition tests/module/test_input_explosive_multi_ignition.f90)
target_link_libraries(test_input_explosive_multi_ignition PRIVATE sphlite_core)
set_target_properties(test_input_explosive_multi_ignition PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME input_explosive_multi_ignition COMMAND test_input_explosive_multi_ignition)
set_tests_properties(input_explosive_multi_ignition PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_input_explosive_multimaterial tests/module/test_input_explosive_multimaterial.f90)
target_link_libraries(test_input_explosive_multimaterial PRIVATE sphlite_core)
set_target_properties(test_input_explosive_multimaterial PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME input_explosive_multimaterial COMMAND test_input_explosive_multimaterial)
set_tests_properties(input_explosive_multimaterial PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_c_api tests/interface/test_c_api.c)
target_include_directories(test_c_api PRIVATE include)
target_compile_definitions(test_c_api PRIVATE
+1
View File
@@ -251,6 +251,7 @@ contains
ierr = SPH_ERROR_INPUT
return
end if
if (.not. sph_explosive_has_active_particle_for_id(mat_index)) cycle
if (material_density(mat_index) <= 0.0_rk) then
call sph_error_set(SPH_ERROR_INPUT, 'input is missing *DENSITY for Explosive material')
ierr = SPH_ERROR_INPUT
+14
View File
@@ -149,6 +149,20 @@ contains
end do
end function sph_explosive_has_ignition_for_material
logical function sph_explosive_has_active_particle_for_id(mat_index)
integer, intent(in) :: mat_index
integer :: i
sph_explosive_has_active_particle_for_id = .false.
do i = 1, npart
if (material_id(i) /= mat_index) cycle
if (sph_explosive_is_active_particle(i)) then
sph_explosive_has_active_particle_for_id = .true.
return
end if
end do
end function sph_explosive_has_active_particle_for_id
integer function sph_explosive_count_active_gas(product_id)
integer, intent(in) :: product_id
integer :: i
@@ -0,0 +1,18 @@
*NODE
1, 0.0, 0.0, 0.0
*ELEMENT, TYPE=SPH3D
1, 1
*ELSET, ELSET=CHARGE_PARTICLES
1
*MATERIAL, NAME=TNT, TYPE=EXPLOSIVE
*DENSITY
1600.0
*SECTION, ELSET=CHARGE_PARTICLES, MATERIAL=TNT
*MATERIAL, NAME=PRODUCTS, TYPE=GAS
*DENSITY
1600.0
*SPHLITE EOS, TYPE=JWL, MATERIAL=PRODUCTS, RHO0=1600.0, A=3.712E11, B=3.231E9, R1=4.15, R2=0.95, OMEGA=0.3, E0=4.2E6
*SPHLITE EXPLOSIVE, MATERIAL=TNT, TYPE=PROGRAMMED_BURN, DETONATION_VELOCITY=6900.0, ENERGY=4.2E6, BURN_TIME=1.0E-7, PRODUCT_MATERIAL=PRODUCTS, CONVERSION=PHASE
*SPHLITE IGNITION, MATERIAL=TNT, X=0.0, Y=0.0, Z=0.0, TIME=-1.0E-7
*SPHLITE PARTICLE CONTROL, H=0.10, MASS=0.02, VOLUME=1.25E-5
*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5
@@ -20,6 +20,6 @@
*SPHLITE EOS, TYPE=JWL, MATERIAL=PRODUCTS, RHO0=1600.0, A=3.712E11, B=3.231E9, R1=4.15, R2=0.95, OMEGA=0.3, E0=4.2E6
*SPHLITE EXPLOSIVE, MATERIAL=TNT, TYPE=PROGRAMMED_BURN, DETONATION_VELOCITY=6900.0, ENERGY=4.2E6, BURN_TIME=0.0, PRODUCT_MATERIAL=PRODUCTS, CONVERSION=PHASE
*SPHLITE IGNITION, MATERIAL=TNT, X=0.00, Y=0.0, Z=0.0, TIME=0.0
*SPHLITE IGNITION, MATERIAL=TNT, X=0.30, Y=0.0, Z=0.0, TIME=1.0E-6
*SPHLITE IGNITION, MATERIAL=TNT, X=0.30, Y=0.0, Z=0.0, TIME=0.0
*SPHLITE PARTICLE CONTROL, H=0.10, MASS=0.02, VOLUME=1.25E-5
*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5
@@ -19,7 +19,7 @@
1600.0
*SPHLITE EOS, TYPE=JWL, MATERIAL=PRODUCTS, RHO0=1600.0, A=3.712E11, B=3.231E9, R1=4.15, R2=0.95, OMEGA=0.3, E0=4.2E6
*SPHLITE EXPLOSIVE, MATERIAL=TNT, TYPE=PROGRAMMED_BURN, DETONATION_VELOCITY=6900.0, ENERGY=4.2E6, BURN_TIME=0.0, PRODUCT_MATERIAL=PRODUCTS, CONVERSION=PHASE
*SPHLITE IGNITION, MATERIAL=TNT, X=0.30, Y=0.0, Z=0.0, TIME=1.0E-6
*SPHLITE IGNITION, MATERIAL=TNT, X=0.30, Y=0.0, Z=0.0, TIME=0.0
*SPHLITE IGNITION, MATERIAL=TNT, X=0.00, Y=0.0, Z=0.0, TIME=0.0
*SPHLITE PARTICLE CONTROL, H=0.10, MASS=0.02, VOLUME=1.25E-5
*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5
@@ -0,0 +1,23 @@
*NODE
1, 0.0, 0.0, 0.0
2, 0.1, 0.0, 0.0
*ELEMENT, TYPE=SPH3D
1, 1
2, 2
*ELSET, ELSET=CHARGE_PARTICLES
1, 2
*MATERIAL, NAME=TNT, TYPE=EXPLOSIVE
*DENSITY
1600.0
*SECTION, ELSET=CHARGE_PARTICLES, MATERIAL=TNT
*MATERIAL, NAME=PBX, TYPE=EXPLOSIVE
*DENSITY
1750.0
*MATERIAL, NAME=PRODUCTS, TYPE=GAS
*DENSITY
1600.0
*SPHLITE EOS, TYPE=JWL, MATERIAL=PRODUCTS, RHO0=1600.0, A=3.712E11, B=3.231E9, R1=4.15, R2=0.95, OMEGA=0.3, E0=4.2E6
*SPHLITE EXPLOSIVE, MATERIAL=TNT, TYPE=PROGRAMMED_BURN, DETONATION_VELOCITY=6900.0, ENERGY=4.2E6, BURN_TIME=0.0, PRODUCT_MATERIAL=PRODUCTS, CONVERSION=PHASE
*SPHLITE IGNITION, MATERIAL=TNT, X=0.0, Y=0.0, Z=0.0, TIME=0.0
*SPHLITE PARTICLE CONTROL, H=0.10, MASS=0.02, VOLUME=1.25E-5
*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5
@@ -6,6 +6,8 @@ program test_input_explosive_errors
call expect_error('tests/data/explosive_bad_velocity_040.inp', 'bad velocity')
call expect_error('tests/data/explosive_bad_product_040.inp', 'bad product')
call expect_error('tests/data/explosive_bad_ignition_040.inp', 'bad ignition')
call expect_error('tests/data/explosive_bad_ignition_time_041.inp', &
'bad ignition time')
call expect_error('tests/data/explosive_missing_density_040.inp', 'missing density')
call expect_error('tests/data/explosive_bad_burn_time_040.inp', 'bad burn time')
call expect_error('tests/data/explosive_bad_energy_040.inp', 'bad energy')
@@ -0,0 +1,138 @@
program test_input_explosive_multi_ignition
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
use sph_explosive_state, only: explosive_detonation_time, &
explosive_ignition_count, explosive_ignition_material_id
implicit none
real(rk) :: forward_times(4)
real(rk) :: reversed_times(4)
call read_times('tests/data/explosive_multi_ignition_forward_041.inp', &
forward_times)
call read_times('tests/data/explosive_multi_ignition_reversed_041.inp', &
reversed_times)
call assert_close_array(forward_times, reversed_times, &
'multi ignition order changed detonation times')
call assert_close(forward_times(1), 0.0_rk, 'first particle arrival mismatch')
call assert_close(forward_times(2), 0.10_rk / 6900.0_rk, &
'second particle minimum arrival mismatch')
call assert_close(forward_times(3), 0.10_rk / 6900.0_rk, &
'third particle minimum arrival mismatch')
call assert_close(forward_times(4), 0.0_rk, 'fourth particle arrival mismatch')
call assert_cross_material()
call assert_missing_matching_ignition()
call assert_reinitialize_clears_ignitions()
contains
subroutine read_times(filename, values)
character(len=*), intent(in) :: filename
real(rk), intent(out) :: values(4)
integer :: ierr
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed')
call sph_read_inp(filename, ierr)
call assert_ok(ierr, 'read multi ignition input failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build multi ignition input failed')
if (explosive_ignition_count /= 2) call fail('multi ignition count mismatch')
if (explosive_ignition_material_id(1) /= explosive_ignition_material_id(2)) then
call fail('multi ignition material mismatch')
end if
values = explosive_detonation_time(1:4)
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed')
end subroutine read_times
subroutine assert_cross_material()
integer :: ierr
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize cross material failed')
call sph_read_inp('tests/data/explosive_multi_ignition_cross_material_041.inp', &
ierr)
call assert_ok(ierr, 'read cross material ignition failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build cross material ignition failed')
call assert_close(explosive_detonation_time(1), 0.0_rk, &
'TNT ignition mismatch')
call assert_close(explosive_detonation_time(2), 0.10_rk / 6900.0_rk, &
'TNT material filter mismatch')
call assert_close(explosive_detonation_time(3), 0.10_rk / 7600.0_rk, &
'PBX material filter mismatch')
call assert_close(explosive_detonation_time(4), 0.0_rk, &
'PBX ignition mismatch')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize cross material failed')
end subroutine assert_cross_material
subroutine assert_missing_matching_ignition()
integer :: ierr
integer :: final_ierr
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize missing ignition failed')
call sph_read_inp('tests/data/explosive_missing_matching_ignition_041.inp', &
ierr)
if (ierr == SPH_SUCCESS) call sph_build_model(ierr)
if (ierr == SPH_SUCCESS) call fail('missing matching ignition passed')
call sph_finalize(final_ierr)
call assert_ok(final_ierr, 'finalize missing ignition failed')
end subroutine assert_missing_matching_ignition
subroutine assert_reinitialize_clears_ignitions()
integer :: ierr
integer :: final_ierr
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize stale ignition case failed')
call sph_read_inp('tests/data/explosive_multi_ignition_forward_041.inp', ierr)
call assert_ok(ierr, 'read stale ignition seed failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build stale ignition seed failed')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize stale ignition seed failed')
call sph_initialize(ierr)
call assert_ok(ierr, 'reinitialize stale ignition case failed')
call sph_read_inp('tests/data/explosive_missing_matching_ignition_041.inp', &
ierr)
if (ierr == SPH_SUCCESS) call sph_build_model(ierr)
if (ierr == SPH_SUCCESS) call fail('stale ignition record was retained')
call sph_finalize(final_ierr)
call assert_ok(final_ierr, 'finalize stale ignition case failed')
end subroutine assert_reinitialize_clears_ignitions
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_array(actual, expected, message)
real(rk), intent(in) :: actual(4)
real(rk), intent(in) :: expected(4)
character(len=*), intent(in) :: message
if (maxval(abs(actual - expected)) > 1.0e-12_rk) call fail(message)
end subroutine assert_close_array
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_explosive_multi_ignition
@@ -0,0 +1,127 @@
program test_input_explosive_multimaterial
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_explosive_state, only: EXPLOSIVE_CONVERSION_PHASE, &
EXPLOSIVE_CONVERSION_SOURCE, explosive_material_count, &
explosive_product_material_id, explosive_detonation_velocity, &
explosive_energy_per_mass, explosive_burn_time, &
explosive_conversion_mode
implicit none
call assert_multimaterial_controls()
call assert_shared_product_material()
call assert_product_missing_eos_error()
call assert_unbound_material_warning()
contains
subroutine assert_multimaterial_controls()
integer :: ierr
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize multimaterial failed')
call sph_read_inp('tests/data/explosive_multimaterial_041.inp', ierr)
call assert_ok(ierr, 'read multimaterial failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build multimaterial failed')
if (explosive_material_count /= 2) call fail('explosive material count mismatch')
call assert_close(explosive_detonation_velocity(1), 6900.0_rk, &
'first detonation velocity mismatch')
call assert_close(explosive_detonation_velocity(2), 7600.0_rk, &
'second detonation velocity mismatch')
call assert_close(explosive_energy_per_mass(1), 4.2e6_rk, &
'first energy mismatch')
call assert_close(explosive_energy_per_mass(2), 5.0e6_rk, &
'second energy mismatch')
call assert_close(explosive_burn_time(1), 1.0e-7_rk, &
'first burn time mismatch')
call assert_close(explosive_burn_time(2), 2.0e-7_rk, &
'second burn time mismatch')
if (explosive_conversion_mode(1) /= EXPLOSIVE_CONVERSION_SOURCE) then
call fail('first conversion mode mismatch')
end if
if (explosive_conversion_mode(2) /= EXPLOSIVE_CONVERSION_PHASE) then
call fail('second conversion mode mismatch')
end if
if (explosive_product_material_id(1) == explosive_product_material_id(2)) then
call fail('different product material mapping mismatch')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize multimaterial failed')
end subroutine assert_multimaterial_controls
subroutine assert_shared_product_material()
integer :: ierr
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize shared product failed')
call sph_read_inp('tests/data/explosive_multi_ignition_cross_material_041.inp', &
ierr)
call assert_ok(ierr, 'read shared product failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build shared product failed')
if (explosive_material_count /= 2) call fail('shared product material count mismatch')
if (explosive_product_material_id(1) /= explosive_product_material_id(2)) then
call fail('same product material mapping mismatch')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize shared product failed')
end subroutine assert_shared_product_material
subroutine assert_product_missing_eos_error()
integer :: ierr
integer :: final_ierr
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize missing EOS failed')
call sph_read_inp('tests/data/explosive_product_missing_eos_040.inp', ierr)
if (ierr == SPH_SUCCESS) call sph_build_model(ierr)
if (ierr == SPH_SUCCESS) call fail('product Gas missing EOS passed')
call sph_finalize(final_ierr)
call assert_ok(final_ierr, 'finalize missing EOS failed')
end subroutine assert_product_missing_eos_error
subroutine assert_unbound_material_warning()
integer :: ierr
integer :: warnings
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize unbound material failed')
call sph_read_inp('tests/data/explosive_unbound_material_warning_041.inp', ierr)
call assert_ok(ierr, 'read unbound material failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build unbound material failed')
call sph_get_input_warning_count(warnings, ierr)
call assert_ok(ierr, 'warning query failed')
if (warnings < 1) call fail('unbound Explosive material warning mismatch')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize unbound material failed')
end subroutine assert_unbound_material_warning
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-10_rk * max(1.0_rk, abs(expected))) then
call fail(message)
end if
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_explosive_multimaterial
+20 -20
View File
@@ -33,26 +33,26 @@
## 阶段 B:多点点火、多材料输入与校验
- [ ] 复核 0.4.0 点火记录存储结构是否支持同一 material 多条记录。
- [ ] 加固点火记录清理过程,确保重复初始化不会残留旧记录。
- [ ] 加固点火记录 material 匹配逻辑。
- [ ] 加固点火记录输入顺序无关逻辑。
- [ ] 实现多点点火到达时间取最小值的显式测试路径。
- [ ] 对缺少匹配点火记录的 explosive 粒子报 error。
- [ ] 对点火时间为负值的输入保持 error。
- [ ] 对点火坐标非法或缺失的输入保持 error。
- [ ] 复核 Explosive material 注册过程支持多个炸药材料。
- [ ] 复核 Explosive control 表支持每个 material 独立参数。
- [ ] 复核 product Gas material 映射支持多个目标材料。
- [ ] 校验不同 Explosive material 可使用不同爆速。
- [ ] 校验不同 Explosive material 可使用不同单位质量能量。
- [ ] 校验不同 Explosive material 可使用不同 burn time。
- [ ] 校验不同 Explosive material 可使用不同 conversion mode。
- [ ] 校验不同 Explosive material 可映射到相同 product Gas。
- [ ] 校验不同 Explosive material 可映射到不同 product Gas。
- [ ] 对 product Gas material 缺失 EOS 的多材料输入报 error。
- [ ] 对无 active 粒子的 Explosive material 继续报 warning 而不阻止运行。
- [ ] 新增多点点火和多材料输入模块测试并接入 CTest。
- [x] 复核 0.4.0 点火记录存储结构是否支持同一 material 多条记录。
- [x] 加固点火记录清理过程,确保重复初始化不会残留旧记录。
- [x] 加固点火记录 material 匹配逻辑。
- [x] 加固点火记录输入顺序无关逻辑。
- [x] 实现多点点火到达时间取最小值的显式测试路径。
- [x] 对缺少匹配点火记录的 explosive 粒子报 error。
- [x] 对点火时间为负值的输入保持 error。
- [x] 对点火坐标非法或缺失的输入保持 error。
- [x] 复核 Explosive material 注册过程支持多个炸药材料。
- [x] 复核 Explosive control 表支持每个 material 独立参数。
- [x] 复核 product Gas material 映射支持多个目标材料。
- [x] 校验不同 Explosive material 可使用不同爆速。
- [x] 校验不同 Explosive material 可使用不同单位质量能量。
- [x] 校验不同 Explosive material 可使用不同 burn time。
- [x] 校验不同 Explosive material 可使用不同 conversion mode。
- [x] 校验不同 Explosive material 可映射到相同 product Gas。
- [x] 校验不同 Explosive material 可映射到不同 product Gas。
- [x] 对 product Gas material 缺失 EOS 的多材料输入报 error。
- [x] 对无 active 粒子的 Explosive material 继续报 warning 而不阻止运行。
- [x] 新增多点点火和多材料输入模块测试并接入 CTest。
## 阶段 C:反应质量基准与释放量一致性