Integrate water explicit stepping and dt limits

This commit is contained in:
Codex
2026-07-02 20:52:05 +08:00
parent 662129d2bb
commit 4809701068
10 changed files with 226 additions and 33 deletions
+71 -3
View File
@@ -1,11 +1,79 @@
program test_solver_water
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_run_explicit, sph_get_current_time
use sph_database, only: rho, v
implicit none
integer :: ierr
integer :: step
real(rk) :: time
call pass()
call check_unbuilt_error()
call check_single_step()
call check_run_explicit()
contains
subroutine pass()
end subroutine pass
subroutine check_unbuilt_error()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize unbuilt failed')
call sph_advance_explicit(1.0e-6_rk, ierr)
if (ierr == SPH_SUCCESS) call fail('unbuilt explicit step did not fail')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize unbuilt failed')
end subroutine check_unbuilt_error
subroutine check_single_step()
real(rk) :: rho_before
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize single failed')
call sph_read_inp('tests/data/water_body_force_020.inp', ierr)
call assert_ok(ierr, 'read single failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build single failed')
rho_before = rho(1)
call sph_advance_explicit(1.0e-6_rk, ierr)
call assert_ok(ierr, 'advance single failed')
call sph_get_current_time(time, step, ierr)
call assert_ok(ierr, 'time single failed')
if (step /= 1) call fail('single step count mismatch')
if (abs(time - 1.0e-6_rk) > 1.0e-12_rk) call fail('single step time mismatch')
if (abs(rho(1) - rho_before) > 1.0e-6_rk) call fail('unexpected density drift')
if (v(3,1) >= 0.0_rk) call fail('body force did not change velocity direction')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize single failed')
end subroutine check_single_step
subroutine check_run_explicit()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize run failed')
call sph_read_inp('tests/data/water_minimal_020.inp', ierr)
call assert_ok(ierr, 'read run failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build run failed')
call sph_run_explicit(ierr)
call assert_ok(ierr, 'run explicit failed')
call sph_get_current_time(time, step, ierr)
call assert_ok(ierr, 'time run failed')
if (step <= 0) call fail('run did not advance')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize run failed')
end subroutine check_run_explicit
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_solver_water