Cover water stable timestep checks

This commit is contained in:
Codex
2026-07-02 20:55:01 +08:00
parent 4809701068
commit 2c5d33e52f
2 changed files with 80 additions and 22 deletions
+60 -2
View File
@@ -2,8 +2,10 @@ 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
sph_advance_explicit, sph_run_explicit, sph_get_current_time, &
sph_estimate_stable_dt
use sph_database, only: rho, v, h, a
use sph_control, only: dt_default, safety_factor
implicit none
integer :: ierr
integer :: step
@@ -12,6 +14,9 @@ program test_solver_water
call check_unbuilt_error()
call check_single_step()
call check_run_explicit()
call check_dt_limits()
call check_no_water_dt_strategy()
call check_bad_h_dt_error()
contains
@@ -62,6 +67,59 @@ contains
call assert_ok(ierr, 'finalize run failed')
end subroutine check_run_explicit
subroutine check_dt_limits()
real(rk) :: dtcrit
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize dt failed')
call sph_read_inp('tests/data/water_minimal_020.inp', ierr)
call assert_ok(ierr, 'read dt failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build dt failed')
dt_default = 1.0_rk
safety_factor = 0.5_rk
a(:,1) = (/100.0_rk, 0.0_rk, 0.0_rk/)
call sph_estimate_stable_dt(dtcrit, ierr)
call assert_ok(ierr, 'estimate dt failed')
if (dtcrit <= 0.0_rk) call fail('dtcrit is not positive')
if (dtcrit >= 1.0_rk) call fail('dtcrit did not use water limits')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize dt failed')
end subroutine check_dt_limits
subroutine check_no_water_dt_strategy()
real(rk) :: dtcrit
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize no-water dt failed')
call sph_read_inp('tests/data/minimal_particles_011.inp', ierr)
call assert_ok(ierr, 'read no-water dt failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build no-water dt failed')
dt_default = 2.0e-6_rk
call sph_estimate_stable_dt(dtcrit, ierr)
call assert_ok(ierr, 'estimate no-water dt failed')
if (abs(dtcrit - 2.0e-6_rk) > 1.0e-12_rk) call fail('no-water dt did not use default')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize no-water dt failed')
end subroutine check_no_water_dt_strategy
subroutine check_bad_h_dt_error()
real(rk) :: dtcrit
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize bad h failed')
call sph_read_inp('tests/data/water_minimal_020.inp', ierr)
call assert_ok(ierr, 'read bad h failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build bad h failed')
h(1) = 0.0_rk
call sph_estimate_stable_dt(dtcrit, ierr)
if (ierr == SPH_SUCCESS) call fail('bad h dt estimate did not fail')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize bad h failed')
end subroutine check_bad_h_dt_error
subroutine assert_ok(ierr_value, message)
integer, intent(in) :: ierr_value
character(len=*), intent(in) :: message