Files
SPHLite/tests/module/test_explosive_restart_no_double_release.f90
2026-07-03 13:52:49 +08:00

70 lines
2.5 KiB
Fortran

program test_explosive_restart_no_double_release
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
use sph_explosive, only: sph_explosive_get_release_balance
implicit none
integer :: ierr
real(rk) :: mass_before(4)
real(rk) :: mass_after(4)
real(rk) :: energy_values(2)
real(rk) :: momentum_values(3)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed')
call sph_read_inp('tests/data/explosive_conversion_phase_040.inp', ierr)
call assert_ok(ierr, 'read failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'advance before restart failed')
call sph_explosive_get_release_balance(mass_before, energy_values, &
momentum_values, ierr)
call assert_ok(ierr, 'balance before restart failed')
call sph_write_restart('build-codex-unix/restart_no_double_release.tmp', ierr)
call assert_ok(ierr, 'write restart failed')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize first session failed')
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize restart session failed')
call sph_read_restart('build-codex-unix/restart_no_double_release.tmp', ierr)
call assert_ok(ierr, 'read restart failed')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'advance after restart failed')
call sph_explosive_get_release_balance(mass_after, energy_values, &
momentum_values, ierr)
call assert_ok(ierr, 'balance after restart failed')
call assert_close(mass_after(2), mass_before(2), 'restart repeated release')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize restart session failed')
contains
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_explosive_restart_no_double_release