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 use sph_database, only: particle_id_ext, particle_phase, particle_status, & material_id, section_id, x0, x, v, a, SPH_PHASE_WATER, SPH_STATUS_ACTIVE 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 assert_build_state() 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 assert_restart_identity() 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 assert_build_state() if (particle_id_ext(1) /= 1 .or. particle_id_ext(4) /= 4) then call fail('build particle ids are not stable') end if if (particle_phase(1) /= SPH_PHASE_WATER) call fail('build phase mismatch') if (particle_status(1) /= SPH_STATUS_ACTIVE) call fail('build status mismatch') if (material_id(1) /= 1) call fail('build material id mismatch') if (section_id(1) /= 1) call fail('build section id mismatch') if (maxval(abs(x0(:,2) - (/0.1_rk, 0.0_rk, 0.0_rk/))) > 1.0e-12_rk) then call fail('build x0 initialization mismatch') end if if (maxval(abs(x(:,2) - x0(:,2))) > 1.0e-12_rk) call fail('build x mismatch') if (maxval(abs(v)) > 1.0e-12_rk) call fail('build velocity mismatch') if (maxval(abs(a)) > 1.0e-12_rk) call fail('build acceleration mismatch') end subroutine assert_build_state subroutine assert_restart_identity() if (particle_id_ext(1) /= 1 .or. particle_id_ext(4) /= 4) then call fail('restart particle ids are not stable') end if end subroutine assert_restart_identity subroutine fail(message) character(len=*), intent(in) :: message write(*, '(A)') trim(message) stop 1 end subroutine fail end program test_restart