program test_solid_restart_041_compat 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_write_restart, sph_read_restart, sph_advance_explicit use sph_database, only: solid_particle_count, solid_failed_count use sph_solid, only: solid_material_count use sph_solid_state, only: solid_stress implicit none integer :: ierr call check_041_restart_clears_solid_state() contains subroutine check_041_restart_clears_solid_state() call write_current_water_restart('build-codex-unix/restart_water_for_041.tmp') call write_041_compat_restart('build-codex-unix/restart_water_for_041.tmp', & 'build-codex-unix/restart_solid_041_compat.tmp') call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed for Solid 0.4.1 compat') call sph_read_inp('tests/data/solid_elastic_minimal_050.inp', ierr) call assert_ok(ierr, 'read Solid seed failed for 0.4.1 compat') call sph_build_model(ierr) call assert_ok(ierr, 'build Solid seed failed for 0.4.1 compat') if (.not. allocated(solid_stress)) call fail('Solid seed state was not allocated') call sph_read_restart('build-codex-unix/restart_solid_041_compat.tmp', ierr) call assert_ok(ierr, 'read 0.4.1 restart failed for Solid compat') if (solid_material_count /= 0) call fail('0.4.1 restart left Solid material table') if (allocated(solid_stress)) call fail('0.4.1 restart left Solid particle state') if (solid_particle_count /= 0) call fail('0.4.1 restart left Solid active count') if (solid_failed_count /= 0) call fail('0.4.1 restart left Solid failed count') call sph_advance_explicit(1.0e-7_rk, ierr) call assert_ok(ierr, 'continue 0.4.1 restart failed for Solid compat') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for Solid 0.4.1 compat') end subroutine check_041_restart_clears_solid_state subroutine write_current_water_restart(filename) character(len=*), intent(in) :: filename call sph_initialize(ierr) call assert_ok(ierr, 'initialize water fixture failed') call sph_read_inp('tests/data/water_minimal_020.inp', ierr) call assert_ok(ierr, 'read water fixture failed') call sph_build_model(ierr) call assert_ok(ierr, 'build water fixture failed') call sph_write_restart(filename, ierr) call assert_ok(ierr, 'write water fixture failed') call sph_finalize(ierr) call assert_ok(ierr, 'finalize water fixture failed') end subroutine write_current_water_restart subroutine write_041_compat_restart(source_filename, target_filename) character(len=*), intent(in) :: source_filename character(len=*), intent(in) :: target_filename character(len=512) :: lines(256) character(len=512) :: line integer :: line_count integer :: i integer :: ios line_count = 0 open(unit=94, file=trim(source_filename), status='old', action='read', iostat=ios) if (ios /= 0) call fail('open source restart for 0.4.1 compat failed') do read(94, '(A)', iostat=ios) line if (ios /= 0) exit line_count = line_count + 1 if (line_count > size(lines)) call fail('0.4.1 compat fixture is too large') lines(line_count) = line end do close(unit=94) if (line_count <= 9) call fail('0.4.1 compat fixture is too short') lines(1) = 'SPHLITE_RESTART 0 4 1 STATE_0_4_1' open(unit=95, file=trim(target_filename), status='unknown', action='write', & iostat=ios) if (ios /= 0) call fail('open target restart for 0.4.1 compat failed') do i = 1, line_count - 9 write(95, '(A)') trim(lines(i)) end do close(unit=95) end subroutine write_041_compat_restart 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_solid_restart_041_compat