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