Add Gas restart and C ABI diagnostics

This commit is contained in:
Codex
2026-07-03 09:47:27 +08:00
parent c2081e2d78
commit bb0248ba80
11 changed files with 490 additions and 27 deletions
+96
View File
@@ -0,0 +1,96 @@
program test_gas_restart
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, &
sph_get_gas_summary, sph_get_gas_bubble_metrics, sph_get_gas_dt_limits
use sph_database, only: particle_phase, gas_volume, gas_center, &
gas_equivalent_radius, gas_previous_equivalent_radius, gas_radius_rate, &
gas_dtcrit, SPH_PHASE_GAS
use sph_gas, only: gas_eos_type, gas_default_h, gas_default_mass, &
gas_default_volume, gas_body_force
implicit none
integer :: ierr
integer :: eos_type_before
real(rk) :: volume_before
real(rk) :: center_before(3)
real(rk) :: radius_before
real(rk) :: previous_radius_before
real(rk) :: radius_rate_before
real(rk) :: dtcrit_before
real(rk) :: api_volume
real(rk) :: api_center(3)
real(rk) :: api_mean_pressure
real(rk) :: api_max_pressure
real(rk) :: api_radius
real(rk) :: api_radius_rate
real(rk) :: api_dt_cfl
real(rk) :: api_dt_accel
real(rk) :: api_dtcrit
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Gas restart')
call sph_read_inp('tests/data/gas_ideal_minimal_030.inp', ierr)
call assert_ok(ierr, 'Gas restart input read failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'Gas restart build failed')
call sph_advance_explicit(1.0e-6_rk, ierr)
call assert_ok(ierr, 'Gas restart advance failed')
eos_type_before = gas_eos_type
volume_before = gas_volume
center_before = gas_center
radius_before = gas_equivalent_radius
previous_radius_before = gas_previous_equivalent_radius
radius_rate_before = gas_radius_rate
dtcrit_before = gas_dtcrit
if (gas_default_h <= 0.0_rk .or. gas_default_mass <= 0.0_rk .or. &
gas_default_volume <= 0.0_rk) call fail('Gas restart defaults missing')
if (maxval(abs(gas_body_force)) > 1.0e-12_rk) call fail('Gas body force restart mismatch')
call sph_write_restart('build-codex-unix/restart_gas.tmp', ierr)
call assert_ok(ierr, 'Gas restart write failed')
call sph_read_restart('build-codex-unix/restart_gas.tmp', ierr)
call assert_ok(ierr, 'Gas restart read failed')
if (particle_phase(1) /= SPH_PHASE_GAS) call fail('Gas restart phase mismatch')
if (gas_eos_type /= eos_type_before) call fail('Gas restart EOS type mismatch')
if (abs(gas_volume - volume_before) > 1.0e-12_rk) call fail('Gas restart volume mismatch')
if (maxval(abs(gas_center - center_before)) > 1.0e-12_rk) call fail('Gas restart center mismatch')
if (abs(gas_equivalent_radius - radius_before) > 1.0e-12_rk) then
call fail('Gas restart equivalent radius mismatch')
end if
if (abs(gas_previous_equivalent_radius - previous_radius_before) > 1.0e-12_rk) then
call fail('Gas restart previous radius mismatch')
end if
if (abs(gas_radius_rate - radius_rate_before) > 1.0e-12_rk) call fail('Gas restart radius rate mismatch')
if (abs(gas_dtcrit - dtcrit_before) > 1.0e-12_rk) call fail('Gas restart dtcrit mismatch')
call sph_get_gas_summary(api_volume, api_center, api_mean_pressure, api_max_pressure, ierr)
call assert_ok(ierr, 'Gas summary API after restart failed')
if (api_volume <= 0.0_rk .or. api_max_pressure <= 0.0_rk) call fail('Gas API summary mismatch')
call sph_get_gas_bubble_metrics(api_radius, api_radius_rate, api_center, ierr)
call assert_ok(ierr, 'Gas bubble API after restart failed')
if (api_radius <= 0.0_rk) call fail('Gas API bubble mismatch')
call sph_get_gas_dt_limits(api_dt_cfl, api_dt_accel, api_dtcrit, ierr)
call assert_ok(ierr, 'Gas dt API after restart failed')
if (api_dt_cfl <= 0.0_rk .or. api_dtcrit <= 0.0_rk) call fail('Gas API dt mismatch')
call sph_advance_explicit(1.0e-6_rk, ierr)
call assert_ok(ierr, 'Gas restart continue step failed')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Gas restart')
contains
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_gas_restart
+24 -1
View File
@@ -141,6 +141,15 @@ contains
real(rk) :: water_mass_value
real(rk) :: water_diag_values(7)
real(rk) :: dt_values(3)
integer :: gas_eos_type_value
integer :: gas_count_value
real(rk) :: gas_eos_values(10)
real(rk) :: gas_control_values(3)
real(rk) :: gas_body_values(3)
real(rk) :: gas_summary_values(2)
real(rk) :: gas_diag_values(10)
real(rk) :: gas_bubble_values(6)
real(rk) :: gas_dt_values(3)
real(rk) :: rx0(3)
real(rk) :: rx(3)
real(rk) :: rv(3)
@@ -158,7 +167,7 @@ contains
call fail('restart version mismatch')
end if
if (patch /= SPH_VERSION_PATCH) call fail('restart patch mismatch')
if (trim(state_version) /= 'STATE_0_2') call fail('restart state version mismatch')
if (trim(state_version) /= 'STATE_0_3') call fail('restart state version mismatch')
read(74, *, iostat=ios) file_time, file_step, count
if (ios /= 0) call fail('restart time state read failed')
if (abs(file_time - expected_time) > 1.0e-12_rk) call fail('restart time write mismatch')
@@ -213,6 +222,20 @@ contains
if (abs(dt_values(1) - water_dt_cfl) > 1.0e-12_rk) call fail('restart dt cfl mismatch')
if (abs(dt_values(2) - water_dt_accel) > 1.0e-12_rk) call fail('restart dt accel mismatch')
if (abs(dt_values(3) - water_dt_viscous) > 1.0e-12_rk) call fail('restart dt viscous mismatch')
read(74, *, iostat=ios) gas_eos_type_value, gas_eos_values
if (ios /= 0) call fail('restart Gas EOS read failed')
read(74, *, iostat=ios) gas_control_values
if (ios /= 0) call fail('restart Gas control read failed')
read(74, *, iostat=ios) gas_body_values
if (ios /= 0) call fail('restart Gas body force read failed')
read(74, *, iostat=ios) gas_count_value, gas_summary_values
if (ios /= 0) call fail('restart Gas summary read failed')
read(74, *, iostat=ios) gas_diag_values
if (ios /= 0) call fail('restart Gas diagnostics read failed')
read(74, *, iostat=ios) gas_bubble_values
if (ios /= 0) call fail('restart Gas bubble read failed')
read(74, *, iostat=ios) gas_dt_values
if (ios /= 0) call fail('restart Gas dt read failed')
read(74, *, iostat=ios) pid, phase, status, mat, sec
if (ios /= 0) call fail('restart particle ids read failed')
if (pid /= particle_id_ext(1)) call fail('restart particle id mismatch')
+20 -1
View File
@@ -2,7 +2,8 @@ program test_solver_gas
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_estimate_stable_dt, sph_get_current_time
sph_advance_explicit, sph_estimate_stable_dt, sph_get_current_time, &
sph_get_gas_summary, sph_get_gas_bubble_metrics, sph_get_gas_dt_limits
use sph_database, only: x, v, a, rho, pressure, gas_dtcrit, gas_particle_count, &
water_mass
implicit none
@@ -19,6 +20,15 @@ contains
subroutine check_gas_single_step()
real(rk) :: dtcrit
real(rk) :: x_before(3)
real(rk) :: api_volume
real(rk) :: api_center(3)
real(rk) :: api_mean_pressure
real(rk) :: api_max_pressure
real(rk) :: api_radius
real(rk) :: api_radius_rate
real(rk) :: api_dt_cfl
real(rk) :: api_dt_accel
real(rk) :: api_dtcrit
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Gas solver')
@@ -32,6 +42,15 @@ contains
call assert_ok(ierr, 'Gas dt estimate failed')
if (dtcrit <= 0.0_rk) call fail('Gas dtcrit is not positive')
if (gas_dtcrit <= 0.0_rk) call fail('Gas dt diagnostic is not positive')
call sph_get_gas_summary(api_volume, api_center, api_mean_pressure, api_max_pressure, ierr)
call assert_ok(ierr, 'Gas summary API failed')
if (api_volume <= 0.0_rk .or. api_max_pressure <= 0.0_rk) call fail('Gas summary API mismatch')
call sph_get_gas_bubble_metrics(api_radius, api_radius_rate, api_center, ierr)
call assert_ok(ierr, 'Gas bubble API failed')
if (api_radius <= 0.0_rk) call fail('Gas bubble API mismatch')
call sph_get_gas_dt_limits(api_dt_cfl, api_dt_accel, api_dtcrit, ierr)
call assert_ok(ierr, 'Gas dt API failed')
if (api_dt_cfl <= 0.0_rk .or. api_dtcrit <= 0.0_rk) call fail('Gas dt API mismatch')
call sph_advance_explicit(1.0e-6_rk, ierr)
call assert_ok(ierr, 'Gas explicit advance failed')
call sph_get_current_time(time, step, ierr)