diff --git a/tests/module/test_solver_water.f90 b/tests/module/test_solver_water.f90 index 6ea8d9d..7d36740 100644 --- a/tests/module/test_solver_water.f90 +++ b/tests/module/test_solver_water.f90 @@ -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 diff --git a/todo.md b/todo.md index 6efe54a..9e222bc 100644 --- a/todo.md +++ b/todo.md @@ -256,29 +256,29 @@ - [x] 实现加速度约束估计。 - [x] 实现人工黏性约束估计。 - [x] 应用输入安全系数。 -- [ ] 保存 `dt_cfl` 诊断。 -- [ ] 保存 `dt_accel` 诊断。 -- [ ] 保存 `dt_viscous` 诊断。 -- [ ] 将三类约束最小值返回为 `dtcrit`。 -- [ ] 对无 water 粒子时返回明确策略。 -- [ ] 对非法 `h` 或声速返回明确错误。 -- [ ] 增加 CFL 约束测试。 -- [ ] 增加加速度约束测试。 -- [ ] 增加人工黏性约束测试。 -- [ ] 增加安全系数测试。 +- [x] 保存 `dt_cfl` 诊断。 +- [x] 保存 `dt_accel` 诊断。 +- [x] 保存 `dt_viscous` 诊断。 +- [x] 将三类约束最小值返回为 `dtcrit`。 +- [x] 对无 water 粒子时返回明确策略。 +- [x] 对非法 `h` 或声速返回明确错误。 +- [x] 增加 CFL 约束测试。 +- [x] 增加加速度约束测试。 +- [x] 增加人工黏性约束测试。 +- [x] 增加安全系数测试。 ## 阶段 L:Output 和 Restart -- [ ] 确认 CSV 输出包含 id 字段。 -- [ ] 确认 CSV 输出包含 phase 字段。 -- [ ] 确认 CSV 输出包含 status 字段。 -- [ ] 确认 CSV 输出包含 material 字段。 -- [ ] 确认 CSV 输出包含 section 字段。 -- [ ] 确认 CSV 输出包含坐标字段。 -- [ ] 确认 CSV 输出包含速度字段。 -- [ ] 确认 CSV 输出包含 rho 字段。 -- [ ] 确认 CSV 输出包含 pressure 字段。 -- [ ] 确认 CSV 输出包含 temperature 字段。 +- [x] 确认 CSV 输出包含 id 字段。 +- [x] 确认 CSV 输出包含 phase 字段。 +- [x] 确认 CSV 输出包含 status 字段。 +- [x] 确认 CSV 输出包含 material 字段。 +- [x] 确认 CSV 输出包含 section 字段。 +- [x] 确认 CSV 输出包含坐标字段。 +- [x] 确认 CSV 输出包含速度字段。 +- [x] 确认 CSV 输出包含 rho 字段。 +- [x] 确认 CSV 输出包含 pressure 字段。 +- [x] 确认 CSV 输出包含 temperature 字段。 - [ ] 确认 CSV 输出包含 h 字段。 - [ ] 增加 Water summary 输出或诊断写出入口。 - [ ] 输出 step 诊断。