Add 0.7.1 blast output boundaries

This commit is contained in:
Codex
2026-07-04 00:36:30 +08:00
parent 37891f8c7f
commit 1a9a2e6f3e
4 changed files with 424 additions and 25 deletions
+12
View File
@@ -306,12 +306,24 @@ set_target_properties(test_blast_output PROPERTIES Fortran_MODULE_DIRECTORY "${S
add_test(NAME blast_output COMMAND test_blast_output)
set_tests_properties(blast_output PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_blast_output_071 tests/module/test_blast_output_071.f90)
target_link_libraries(test_blast_output_071 PRIVATE sphlite_core)
set_target_properties(test_blast_output_071 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME blast_output_071 COMMAND test_blast_output_071)
set_tests_properties(blast_output_071 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_blast_restart_boundary tests/module/test_blast_restart_boundary.f90)
target_link_libraries(test_blast_restart_boundary PRIVATE sphlite_core)
set_target_properties(test_blast_restart_boundary PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME blast_restart_boundary COMMAND test_blast_restart_boundary)
set_tests_properties(blast_restart_boundary PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_blast_restart_boundary_071 tests/module/test_blast_restart_boundary_071.f90)
target_link_libraries(test_blast_restart_boundary_071 PRIVATE sphlite_core)
set_target_properties(test_blast_restart_boundary_071 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME blast_restart_boundary_071 COMMAND test_blast_restart_boundary_071)
set_tests_properties(blast_restart_boundary_071 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_blast_smoke tests/module/test_blast_smoke.f90)
target_link_libraries(test_blast_smoke PRIVATE sphlite_core)
set_target_properties(test_blast_smoke PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
+282
View File
@@ -0,0 +1,282 @@
program test_blast_output_071
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, sph_set_output_directory, &
sph_write_output
implicit none
integer :: ierr
call check_default_output_disabled()
call check_multiregion_output()
contains
subroutine check_default_output_disabled()
call delete_output_pair(71)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for default output check')
call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr)
call assert_ok(ierr, 'read failed for default output check')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for default output check')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'advance failed for default output check')
call assert_file_missing('build-codex-unix/sphlite_00000071.csv')
call assert_file_missing('build-codex-unix/sphlite_00000071_summary.csv')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for default output check')
end subroutine check_default_output_disabled
subroutine check_multiregion_output()
call delete_output_pair(71)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for 0.7.1 Blast output')
call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr)
call assert_ok(ierr, 'read failed for 0.7.1 Blast output')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for 0.7.1 Blast output')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'advance failed for 0.7.1 Blast output')
call sph_set_output_directory('build-codex-unix', ierr)
call assert_ok(ierr, 'set output directory failed for 0.7.1 Blast output')
call sph_write_output(71, 1.0e-7_rk, ierr)
call assert_ok(ierr, 'write failed for 0.7.1 Blast output')
call check_particle_csv('build-codex-unix/sphlite_00000071.csv')
call check_summary_csv('build-codex-unix/sphlite_00000071_summary.csv')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for 0.7.1 Blast output')
end subroutine check_multiregion_output
subroutine check_particle_csv(filename)
character(len=*), intent(in) :: filename
character(len=512) :: header
integer :: unit
integer :: ios
unit = 84
open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios)
if (ios /= 0) call fail('0.7.1 Blast particle CSV open failed')
read(unit, '(A)', iostat=ios) header
if (ios /= 0) call fail('0.7.1 Blast particle CSV header missing')
if (index(header, 'blast_solid_fx,blast_solid_fy,blast_solid_fz') <= 0) then
call fail('0.7.1 Blast Solid force columns missing')
end if
if (index(header, 'blast_shell_fx,blast_shell_fy,blast_shell_fz') <= 0) then
call fail('0.7.1 Blast Shell force columns missing')
end if
call check_particle_rows(unit)
close(unit=unit)
end subroutine check_particle_csv
subroutine check_particle_rows(unit)
integer, intent(in) :: unit
integer :: ios
integer :: id
logical :: saw_solid
logical :: saw_shell
real(rk) :: blast_values(9)
saw_solid = .false.
saw_shell = .false.
do
call read_particle_row(unit, id, blast_values, ios)
if (ios /= 0) exit
if (id == 5) then
if (blast_values(1) <= 0.0_rk) call fail('Solid row Blast force missing')
if (maxval(abs(blast_values(4:9))) > 0.0_rk) then
call fail('Solid row polluted Shell Blast columns')
end if
saw_solid = .true.
else if (id == 7) then
if (blast_values(4) <= 0.0_rk) call fail('Shell row Blast x force missing')
if (blast_values(5) <= 0.0_rk) call fail('Shell row Blast y force missing')
if (maxval(abs(blast_values(1:3))) > 0.0_rk) then
call fail('Shell row polluted Solid Blast columns')
end if
if (maxval(abs(blast_values(7:9))) > 0.0_rk) then
call fail('Shell row moment placeholder changed')
end if
saw_shell = .true.
end if
end do
if (.not. saw_solid) call fail('0.7.1 Blast output Solid row missing')
if (.not. saw_shell) call fail('0.7.1 Blast output Shell row missing')
end subroutine check_particle_rows
subroutine read_particle_row(unit, id, blast_values, ios)
integer, intent(in) :: unit
integer, intent(out) :: id
real(rk), intent(out) :: blast_values(9)
integer, intent(out) :: ios
integer :: phase
integer :: status
integer :: mat
integer :: sec
integer :: failure
integer :: reference_neighbors
integer :: correction_status
real(rk) :: pos(3)
real(rk) :: vel(3)
real(rk) :: scalar_values(4)
real(rk) :: explosive_values(6)
real(rk) :: stress_values(6)
real(rk) :: solid_values(5)
read(unit, *, iostat=ios) id, phase, status, mat, sec, pos, vel, &
scalar_values, explosive_values, stress_values, solid_values, &
blast_values, failure, reference_neighbors, correction_status
end subroutine read_particle_row
subroutine check_summary_csv(filename)
character(len=*), intent(in) :: filename
call assert_summary_int(filename, 'blast_regions', 3)
call assert_summary_int(filename, 'blast_source_count_1', 1)
call assert_summary_int(filename, 'blast_source_count_2', 1)
call assert_summary_int(filename, 'blast_source_count_3', 0)
call assert_summary_int(filename, 'blast_load_targets_1', 2)
call assert_summary_int(filename, 'blast_load_targets_2', 2)
call assert_summary_int(filename, 'blast_load_targets_3', 0)
call assert_summary_positive(filename, 'blast_solid_force_x_1')
call assert_summary_zero(filename, 'blast_shell_force_x_1')
call assert_summary_positive(filename, 'blast_shell_force_x_2')
call assert_summary_positive(filename, 'blast_shell_force_y_2')
call assert_summary_zero(filename, 'blast_solid_force_x_2')
call assert_summary_positive(filename, 'blast_total_force_x_1')
call assert_summary_positive(filename, 'blast_total_force_x_2')
call assert_summary_zero(filename, 'blast_total_force_x_3')
call assert_summary_positive(filename, 'blast_energy_input_1')
call assert_summary_positive(filename, 'blast_energy_input_2')
call assert_summary_zero(filename, 'blast_energy_input_3')
call assert_summary_positive(filename, 'blast_max_acceleration_1')
call assert_summary_positive(filename, 'blast_max_acceleration_2')
end subroutine check_summary_csv
subroutine assert_summary_int(filename, metric, expected)
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: metric
integer, intent(in) :: expected
integer :: actual
call read_summary_int(filename, metric, actual)
if (actual /= expected) call fail('0.7.1 Blast summary integer mismatch')
end subroutine assert_summary_int
subroutine assert_summary_positive(filename, metric)
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: metric
real(rk) :: value
call read_summary_real(filename, metric, value)
if (value <= 0.0_rk) call fail('0.7.1 Blast summary positive metric missing')
end subroutine assert_summary_positive
subroutine assert_summary_zero(filename, metric)
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: metric
real(rk) :: value
call read_summary_real(filename, metric, value)
if (abs(value) > 1.0e-18_rk) call fail('0.7.1 Blast summary zero mismatch')
end subroutine assert_summary_zero
subroutine read_summary_int(filename, metric, value)
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: metric
integer, intent(out) :: value
character(len=256) :: line
integer :: unit
integer :: ios
integer :: start
unit = 85
open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios)
if (ios /= 0) call fail('0.7.1 Blast summary integer open failed')
do
read(unit, '(A)', iostat=ios) line
if (ios /= 0) exit
if (index(line, trim(metric) // ',') == 1) then
start = len_trim(metric) + 2
read(line(start:), *, iostat=ios) value
close(unit=unit)
if (ios /= 0) call fail('0.7.1 Blast summary integer parse failed')
return
end if
end do
close(unit=unit)
call fail('0.7.1 Blast summary integer missing')
end subroutine read_summary_int
subroutine read_summary_real(filename, metric, value)
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: metric
real(rk), intent(out) :: value
character(len=256) :: line
integer :: unit
integer :: ios
integer :: start
unit = 86
open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios)
if (ios /= 0) call fail('0.7.1 Blast summary real open failed')
do
read(unit, '(A)', iostat=ios) line
if (ios /= 0) exit
if (index(line, trim(metric) // ',') == 1) then
start = len_trim(metric) + 2
read(line(start:), *, iostat=ios) value
close(unit=unit)
if (ios /= 0) call fail('0.7.1 Blast summary real parse failed')
return
end if
end do
close(unit=unit)
call fail('0.7.1 Blast summary real missing')
end subroutine read_summary_real
subroutine delete_output_pair(step_value)
integer, intent(in) :: step_value
character(len=256) :: filename
write(filename, '("build-codex-unix/sphlite_",I8.8,".csv")') step_value
call delete_file_if_exists(filename)
write(filename, '("build-codex-unix/sphlite_",I8.8,"_summary.csv")') step_value
call delete_file_if_exists(filename)
end subroutine delete_output_pair
subroutine delete_file_if_exists(filename)
character(len=*), intent(in) :: filename
logical :: exists
integer :: ios
inquire(file=trim(filename), exist=exists)
if (.not. exists) return
open(unit=87, file=trim(filename), status='old', iostat=ios)
if (ios == 0) close(unit=87, status='delete')
end subroutine delete_file_if_exists
subroutine assert_file_missing(filename)
character(len=*), intent(in) :: filename
logical :: exists
inquire(file=trim(filename), exist=exists)
if (exists) call fail('default output wrote file unexpectedly')
end subroutine assert_file_missing
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_output_071
@@ -0,0 +1,105 @@
program test_blast_restart_boundary_071
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, sph_write_restart, &
sph_read_restart, sph_get_blast_summary
use sph_blast, only: blast_region_count
use sph_blast_load, only: SPH_BLAST_SUMMARY_COUNT_SIZE, &
SPH_BLAST_SUMMARY_VALUE_SIZE
implicit none
integer :: ierr
integer :: counts(SPH_BLAST_SUMMARY_COUNT_SIZE)
real(rk) :: values(SPH_BLAST_SUMMARY_VALUE_SIZE)
call delete_file_if_exists('build-codex-unix/restart_blast_boundary_071.tmp')
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for 0.7.1 Blast restart boundary')
call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr)
call assert_ok(ierr, 'read failed for 0.7.1 Blast restart boundary')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for 0.7.1 Blast restart boundary')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'advance failed for 0.7.1 Blast restart boundary')
call sph_get_blast_summary(1, counts, values, ierr)
call assert_ok(ierr, 'pre-restart Solid Blast summary failed')
if (counts(6) /= 2) call fail('pre-restart Solid Blast load summary missing')
call sph_get_blast_summary(2, counts, values, ierr)
call assert_ok(ierr, 'pre-restart Shell Blast summary failed')
if (counts(6) /= 2) call fail('pre-restart Shell Blast load summary missing')
call sph_get_blast_summary(3, counts, values, ierr)
call assert_ok(ierr, 'pre-restart disabled Blast summary failed')
if (maxval(abs(counts)) /= 0) call fail('pre-restart disabled Blast summary changed')
call sph_write_restart('build-codex-unix/restart_blast_boundary_071.tmp', ierr)
call assert_ok(ierr, 'write failed for 0.7.1 Blast restart boundary')
call assert_restart_header('build-codex-unix/restart_blast_boundary_071.tmp')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize write session failed for 0.7.1 Blast restart boundary')
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize read session failed for 0.7.1 Blast restart boundary')
call sph_read_restart('build-codex-unix/restart_blast_boundary_071.tmp', ierr)
call assert_ok(ierr, 'read failed for 0.7.1 Blast restart boundary')
if (blast_region_count /= 0) call fail('0.7.1 restart restored Blast regions')
call sph_get_blast_summary(1, counts, values, ierr)
call assert_ok(ierr, 'post-restart Blast summary failed')
if (maxval(abs(counts)) /= 0) call fail('0.7.1 restart restored Blast counts')
if (maxval(abs(values)) > 0.0_rk) call fail('0.7.1 restart restored Blast values')
call sph_advance_explicit(1.0e-8_rk, ierr)
call assert_ok(ierr, 'post-restart continuation failed for 0.7.1 Blast boundary')
call sph_get_blast_summary(1, counts, values, ierr)
call assert_ok(ierr, 'post-continuation Blast summary failed')
if (maxval(abs(counts)) /= 0) call fail('post-continuation Blast counts changed')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize read session failed for 0.7.1 Blast restart boundary')
contains
subroutine assert_restart_header(filename)
character(len=*), intent(in) :: filename
character(len=32) :: tag
character(len=32) :: state
integer :: major
integer :: minor
integer :: patch
integer :: ios
open(unit=88, file=trim(filename), status='old', action='read', iostat=ios)
if (ios /= 0) call fail('0.7.1 Blast restart header open failed')
read(88, *, iostat=ios) tag, major, minor, patch, state
close(unit=88)
if (ios /= 0) call fail('0.7.1 Blast restart header read failed')
if (trim(tag) /= 'SPHLITE_RESTART') call fail('0.7.1 Blast restart tag mismatch')
if (trim(state) == 'STATE_0_7' .or. trim(state) == 'STATE_0_7_1') then
call fail('0.7.1 Blast restart state was frozen too early')
end if
if (trim(state) /= 'STATE_0_5_1') call fail('0.7.1 Blast restart boundary state mismatch')
end subroutine assert_restart_header
subroutine delete_file_if_exists(filename)
character(len=*), intent(in) :: filename
logical :: exists
integer :: ios
inquire(file=trim(filename), exist=exists)
if (.not. exists) return
open(unit=89, file=trim(filename), status='old', iostat=ios)
if (ios == 0) close(unit=89, status='delete')
end subroutine delete_file_if_exists
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_restart_boundary_071
+25 -25
View File
@@ -145,31 +145,31 @@
## 阶段 F:输出、restart 边界和公开接口策略
- [ ] 复核 0.7.0 summary CSV blast 字段。
- [ ] 扩展 summary CSV 的多 region 输出规则。
- [ ] 保持单 region summary CSV 字段兼容。
- [ ] 为多 region 输出记录 region 数量。
- [ ] 为多 region 输出记录每个 region 的源粒子数量。
- [ ] 为多 region 输出记录每个 region 的目标粒子数量。
- [ ] 为多 region 输出记录每个 region 的总力。
- [ ] 为多 region 输出记录每个 region 的能量输入。
- [ ] 为多 region 输出记录每个 region 的跳过计数。
- [ ] 复核 particle CSV blast 外载荷字段。
- [ ] 确认 particle CSV 输出叠加后的粒子外载荷。
- [ ] 确认默认未开启输出时不生成临时结果文件。
- [ ] 明确 0.7.1 是否新增正式 blast restart state。
- [ ] 若不新增正式 state,保持 `STATE_0_7` 未冻结边界并补充测试。
- [ ] 若新增正式 state,保存 blast 控制、诊断和外载荷缓存。
- [ ] 若新增正式 state,验证读回后继续显式步一致。
- [ ] 保持既有 restart 兼容读入路径稳定。
- [ ] 明确 0.7.1 不新增公开 C ABI blast 稳定接口。
- [ ] 明确 0.7.1 不新增 C++ wrapper blast 稳定接口。
- [ ] 明确 0.7.1 不新增 Python blast 稳定接口。
- [ ] 保留 Fortran 内部 blast summary 查询入口。
- [ ] 新增 `blast_output_071` 测试。
- [ ] 新增 `blast_restart_boundary_071` 或 `blast_restart_071` 测试。
- [ ] 将输出和 restart 测试接入 CTest。
- [ ] 准备阶段 F 本地提交说明。
- [x] 复核 0.7.0 summary CSV blast 字段。
- [x] 扩展 summary CSV 的多 region 输出规则。
- [x] 保持单 region summary CSV 字段兼容。
- [x] 为多 region 输出记录 region 数量。
- [x] 为多 region 输出记录每个 region 的源粒子数量。
- [x] 为多 region 输出记录每个 region 的目标粒子数量。
- [x] 为多 region 输出记录每个 region 的总力。
- [x] 为多 region 输出记录每个 region 的能量输入。
- [x] 为多 region 输出记录每个 region 的跳过计数。
- [x] 复核 particle CSV blast 外载荷字段。
- [x] 确认 particle CSV 输出叠加后的粒子外载荷。
- [x] 确认默认未开启输出时不生成临时结果文件。
- [x] 明确 0.7.1 是否新增正式 blast restart state。
- [x] 若不新增正式 state,保持 `STATE_0_7` 未冻结边界并补充测试。
- [x] 若新增正式 state,保存 blast 控制、诊断和外载荷缓存。
- [x] 若新增正式 state,验证读回后继续显式步一致。
- [x] 保持既有 restart 兼容读入路径稳定。
- [x] 明确 0.7.1 不新增公开 C ABI blast 稳定接口。
- [x] 明确 0.7.1 不新增 C++ wrapper blast 稳定接口。
- [x] 明确 0.7.1 不新增 Python blast 稳定接口。
- [x] 保留 Fortran 内部 blast summary 查询入口。
- [x] 新增 `blast_output_071` 测试。
- [x] 新增 `blast_restart_boundary_071` 或 `blast_restart_071` 测试。
- [x] 将输出和 restart 测试接入 CTest。
- [x] 准备阶段 F 本地提交说明。
## 阶段 G:smoke、门禁、文档和发布准备