Files
SPHLite/tests/module/test_coupling_restart_071_compat.f90
T
2026-07-04 09:59:52 +08:00

89 lines
3.4 KiB
Fortran

program test_coupling_restart_071_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_advance_explicit, sph_write_restart, sph_read_restart
use sph_coupling_interface, only: sph_coupling_get_region_count, &
coupling_external_force
implicit none
integer :: ierr
call check_legacy_restart_clears_coupling()
contains
subroutine check_legacy_restart_clears_coupling()
integer :: region_count
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for coupling compat restart')
call sph_read_inp('tests/data/coupling_shell_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for coupling compat restart')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for coupling compat restart')
call sph_write_restart('build-codex-unix/restart_coupling_080_seed.tmp', ierr)
call assert_ok(ierr, 'coupling compat seed restart write failed')
call write_071_compat_restart('build-codex-unix/restart_coupling_080_seed.tmp', &
'build-codex-unix/restart_coupling_071_compat.tmp')
call sph_read_restart('build-codex-unix/restart_coupling_071_compat.tmp', ierr)
call assert_ok(ierr, 'read coupling legacy restart failed')
call sph_coupling_get_region_count(region_count, ierr)
call assert_ok(ierr, 'legacy restart region count query failed')
if (region_count /= 0) call fail('legacy restart did not clear coupling regions')
if (allocated(coupling_external_force)) then
if (maxval(abs(coupling_external_force)) > 0.0_rk) then
call fail('legacy restart left coupling force cache')
end if
end if
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'legacy restart continuation failed')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for coupling legacy restart')
end subroutine check_legacy_restart_clears_coupling
subroutine write_071_compat_restart(source_filename, target_filename)
character(len=*), intent(in) :: source_filename
character(len=*), intent(in) :: target_filename
character(len=512) :: line
integer :: in_unit
integer :: out_unit
integer :: ios
in_unit = 97
out_unit = 98
open(unit=in_unit, file=trim(source_filename), status='old', action='read', &
iostat=ios)
if (ios /= 0) call fail('open coupling 0.8 restart seed failed')
open(unit=out_unit, file=trim(target_filename), status='unknown', &
action='write', iostat=ios)
if (ios /= 0) call fail('open coupling legacy restart target failed')
read(in_unit, '(A)', iostat=ios) line
if (ios /= 0) call fail('read coupling restart seed header failed')
write(out_unit, '(A)') 'SPHLITE_RESTART 0 5 1 STATE_0_5_1'
do
read(in_unit, '(A)', iostat=ios) line
if (ios /= 0) exit
if (trim(line) == 'SPHLITE_COUPLING_STATE') exit
write(out_unit, '(A)') trim(line)
end do
close(unit=in_unit)
close(unit=out_unit)
end subroutine write_071_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_coupling_restart_071_compat