Files
SPHLite/tests/module/test_restart.f90
T
2026-07-02 21:10:04 +08:00

55 lines
1.8 KiB
Fortran

program test_restart
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_run_explicit, sph_get_current_time, sph_write_restart, sph_read_restart, &
sph_advance_explicit
implicit none
integer :: ierr
integer :: step
integer :: written_step
real(rk) :: time
real(rk) :: written_time
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed')
call sph_read_inp('tests/data/water_minimal_020.inp', ierr)
call assert_ok(ierr, 'read input failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build model failed')
call sph_run_explicit(ierr)
call assert_ok(ierr, 'run explicit failed')
call sph_get_current_time(written_time, written_step, ierr)
call assert_ok(ierr, 'time before restart failed')
call sph_write_restart('build-codex-unix/restart_test.tmp', ierr)
call assert_ok(ierr, 'write restart failed')
call sph_read_restart('build-codex-unix/restart_test.tmp', ierr)
call assert_ok(ierr, 'read restart failed')
call sph_get_current_time(time, step, ierr)
call assert_ok(ierr, 'time after restart failed')
if (step /= written_step) call fail('restart did not restore step')
if (abs(time - written_time) > 1.0e-12_rk) call fail('restart did not restore time')
call sph_advance_explicit(1.0e-6_rk, ierr)
call assert_ok(ierr, 'advance after restart failed')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize 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 fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_restart