Files
SPHLite/tests/module/test_blast_restart_boundary.f90
T
2026-07-04 10:25:04 +08:00

79 lines
3.3 KiB
Fortran

program test_blast_restart_boundary
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_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 sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Blast restart boundary')
call sph_read_inp('tests/data/blast_water_gas_explosive_solid_070.inp', ierr)
call assert_ok(ierr, 'read failed for Blast restart boundary')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Blast restart boundary')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'advance failed for Blast restart boundary')
call sph_get_blast_summary(1, counts, values, ierr)
call assert_ok(ierr, 'pre-restart Blast summary failed')
if (counts(6) <= 0) call fail('pre-restart Blast load summary missing')
call sph_write_restart('build-codex-unix/restart_blast_boundary.tmp', ierr)
call assert_ok(ierr, 'write failed for Blast restart boundary')
call assert_restart_header('build-codex-unix/restart_blast_boundary.tmp')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize write session failed for Blast restart boundary')
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize read session failed for Blast restart boundary')
call sph_read_restart('build-codex-unix/restart_blast_boundary.tmp', ierr)
call assert_ok(ierr, 'read failed for Blast restart boundary')
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('Blast restart restored non-state counts')
if (maxval(abs(values)) > 0.0_rk) call fail('Blast restart restored diagnostics')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize read session failed for 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=98, file=trim(filename), status='old', action='read', iostat=ios)
if (ios /= 0) call fail('Blast restart header open failed')
read(98, *, iostat=ios) tag, major, minor, patch, state
close(unit=98)
if (ios /= 0) call fail('Blast restart header read failed')
if (trim(tag) /= 'SPHLITE_RESTART') call fail('Blast restart tag mismatch')
if (trim(state) == 'STATE_0_7') call fail('Blast restart state was frozen too early')
if (trim(state) /= 'STATE_0_8') call fail('Blast restart boundary state mismatch')
end subroutine assert_restart_header
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