Expose water Fortran diagnostics APIs

This commit is contained in:
Codex
2026-07-02 21:10:04 +08:00
parent cd9a040cad
commit 61b81e9d50
6 changed files with 144 additions and 25 deletions
+6 -1
View File
@@ -6,10 +6,11 @@ program test_output
implicit none
integer :: ierr
logical :: exists
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed')
call sph_read_inp('tests/data/output_control_011.inp', ierr)
call sph_read_inp('tests/data/water_minimal_020.inp', ierr)
call assert_ok(ierr, 'read input failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build model failed')
@@ -19,6 +20,10 @@ program test_output
call assert_ok(ierr, 'set output interval failed')
call sph_write_output(0, 0.0_rk, ierr)
call assert_ok(ierr, 'write output failed')
inquire(file='build-codex-unix/sphlite_00000000.csv', exist=exists)
if (.not. exists) call fail('particle CSV output was not written')
inquire(file='build-codex-unix/sphlite_00000000_summary.csv', exist=exists)
if (.not. exists) call fail('summary CSV output was not written')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed')
+7 -2
View File
@@ -8,23 +8,28 @@ program test_restart
integer :: ierr
integer :: step
integer :: written_step
real(rk) :: time
real(rk) :: written_time
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed')
call sph_read_inp('tests/data/minimal_particles_011.inp', ierr)
call sph_read_inp('tests/data/water_minimal_020.inp', ierr)
call assert_ok(ierr, 'read input failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build model failed')
call sph_run_explicit(ierr)
call assert_ok(ierr, 'run explicit failed')
call sph_get_current_time(written_time, written_step, ierr)
call assert_ok(ierr, 'time before restart failed')
call sph_write_restart('build-codex-unix/restart_test.tmp', ierr)
call assert_ok(ierr, 'write restart failed')
call sph_read_restart('build-codex-unix/restart_test.tmp', ierr)
call assert_ok(ierr, 'read restart failed')
call sph_get_current_time(time, step, ierr)
call assert_ok(ierr, 'time after restart failed')
if (step /= 1) call fail('restart did not restore step')
if (step /= written_step) call fail('restart did not restore step')
if (abs(time - written_time) > 1.0e-12_rk) call fail('restart did not restore time')
call sph_advance_explicit(1.0e-6_rk, ierr)
call assert_ok(ierr, 'advance after restart failed')
call sph_finalize(ierr)
+41 -1
View File
@@ -3,7 +3,8 @@ program test_solver_water
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, &
sph_estimate_stable_dt
sph_estimate_stable_dt, sph_rebuild_neighbors, sph_get_neighbor_stats, &
sph_get_water_summary, sph_get_water_dt_limits
use sph_database, only: rho, v, h, a
use sph_control, only: dt_default, safety_factor
implicit none
@@ -17,6 +18,7 @@ program test_solver_water
call check_dt_limits()
call check_no_water_dt_strategy()
call check_bad_h_dt_error()
call check_fortran_api_paths()
contains
@@ -120,6 +122,44 @@ contains
call assert_ok(ierr, 'finalize bad h failed')
end subroutine check_bad_h_dt_error
subroutine check_fortran_api_paths()
integer :: max_neighbors
real(rk) :: average_neighbors
real(rk) :: total_mass
real(rk) :: momentum(3)
real(rk) :: max_pressure
real(rk) :: min_density
real(rk) :: max_density
real(rk) :: dt_cfl
real(rk) :: dt_accel
real(rk) :: dt_viscous
call sph_rebuild_neighbors(ierr)
if (ierr == SPH_SUCCESS) call fail('uninitialized rebuild did not fail')
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize API paths failed')
call sph_get_neighbor_stats(max_neighbors, average_neighbors, ierr)
if (ierr == SPH_SUCCESS) call fail('unbuilt neighbor stats did not fail')
call sph_read_inp('tests/data/water_minimal_020.inp', ierr)
call assert_ok(ierr, 'read API paths failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build API paths failed')
call sph_rebuild_neighbors(ierr)
call assert_ok(ierr, 'rebuild API failed')
call sph_get_neighbor_stats(max_neighbors, average_neighbors, ierr)
call assert_ok(ierr, 'neighbor stats API failed')
if (max_neighbors <= 0 .or. average_neighbors <= 0.0_rk) call fail('neighbor stats mismatch')
call sph_get_water_summary(total_mass, momentum, max_pressure, &
min_density, max_density, ierr)
call assert_ok(ierr, 'water summary API failed')
if (total_mass <= 0.0_rk) call fail('water summary mass mismatch')
call sph_get_water_dt_limits(dt_cfl, dt_accel, dt_viscous, ierr)
call assert_ok(ierr, 'water dt limits API failed')
if (dt_cfl <= 0.0_rk .or. dt_viscous <= 0.0_rk) call fail('water dt limits mismatch')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize API paths failed')
end subroutine check_fortran_api_paths
subroutine assert_ok(ierr_value, message)
integer, intent(in) :: ierr_value
character(len=*), intent(in) :: message