Expand SPHLite particle state consistency tests

This commit is contained in:
Codex
2026-07-02 23:01:42 +08:00
parent 576a5c09c7
commit 9d1cf2668f
7 changed files with 114 additions and 23 deletions
+22
View File
@@ -63,6 +63,7 @@ program test_input
call check_bad_input('tests/data/missing_section_011.inp')
call check_bad_input('tests/data/missing_time_control_011.inp')
call check_bad_input('tests/data/water_missing_density_021.inp')
call check_repeat_read_replaces_model()
call check_input_fails('tests/data/water_section_unknown_material_021.inp')
call check_input_fails('tests/data/water_missing_eos_type_021.inp')
call check_input_fails('tests/data/water_missing_eos_material_021.inp')
@@ -106,6 +107,27 @@ contains
end if
end subroutine check_good_input
subroutine check_repeat_read_replaces_model()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for repeat read')
call sph_read_inp('tests/data/water_minimal_021.inp', ierr)
call assert_ok(ierr, 'first repeat read failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'first repeat build failed')
call sph_get_particle_count(count, ierr)
call assert_ok(ierr, 'first repeat count failed')
if (count /= 4) call fail('first repeat count mismatch')
call sph_read_inp('tests/data/water_eos_no_p0_021.inp', ierr)
call assert_ok(ierr, 'second repeat read failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'second repeat build failed')
call sph_get_particle_count(count, ierr)
call assert_ok(ierr, 'second repeat count failed')
if (count /= 1) call fail('repeat read did not replace model')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after repeat read')
end subroutine check_repeat_read_replaces_model
subroutine check_first_phase(filename, expected_phase)
character(len=*), intent(in) :: filename
integer, intent(in) :: expected_phase
+49 -2
View File
@@ -3,9 +3,10 @@ program test_restart
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model, &
sph_run_explicit, sph_get_current_time, sph_write_restart, sph_read_restart, &
sph_advance_explicit
sph_advance_explicit, sph_get_water_summary
use sph_database, only: particle_id_ext, particle_phase, particle_status, &
material_id, section_id, x0, x, v, a, SPH_PHASE_WATER, SPH_STATUS_ACTIVE
material_id, section_id, x0, x, v, a, vhalf, mass, rho, volume, pressure, &
temperature, h, acc_body, SPH_PHASE_WATER, SPH_STATUS_ACTIVE
implicit none
integer :: ierr
@@ -21,8 +22,10 @@ program test_restart
call sph_build_model(ierr)
call assert_ok(ierr, 'build model failed')
call assert_build_state()
call assert_repeat_summary()
call sph_run_explicit(ierr)
call assert_ok(ierr, 'run explicit failed')
call assert_repeat_summary()
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)
@@ -30,6 +33,7 @@ program test_restart
call sph_read_restart('build-codex-unix/restart_test.tmp', ierr)
call assert_ok(ierr, 'read restart failed')
call assert_restart_identity()
call assert_repeat_summary()
call sph_get_current_time(time, step, ierr)
call assert_ok(ierr, 'time after restart failed')
if (step /= written_step) call fail('restart did not restore step')
@@ -62,6 +66,16 @@ contains
if (maxval(abs(x(:,2) - x0(:,2))) > 1.0e-12_rk) call fail('build x mismatch')
if (maxval(abs(v)) > 1.0e-12_rk) call fail('build velocity mismatch')
if (maxval(abs(a)) > 1.0e-12_rk) call fail('build acceleration mismatch')
if (maxval(abs(vhalf)) > 1.0e-12_rk) call fail('build vhalf mismatch')
if (abs(mass(1) - 1.0_rk) > 1.0e-12_rk) call fail('build mass mismatch')
if (abs(rho(1) - 1000.0_rk) > 1.0e-12_rk) call fail('build rho mismatch')
if (abs(volume(1) - 0.001_rk) > 1.0e-12_rk) call fail('build volume mismatch')
if (abs(pressure(1)) > 1.0e-12_rk) call fail('build pressure mismatch')
if (abs(temperature(1) - 293.15_rk) > 1.0e-12_rk) then
call fail('build temperature mismatch')
end if
if (abs(h(1) - 0.15_rk) > 1.0e-12_rk) call fail('build h mismatch')
if (maxval(abs(acc_body)) > 1.0e-12_rk) call fail('build body acceleration mismatch')
end subroutine assert_build_state
subroutine assert_restart_identity()
@@ -70,6 +84,39 @@ contains
end if
end subroutine assert_restart_identity
subroutine assert_repeat_summary()
real(rk) :: mass_a
real(rk) :: mass_b
real(rk) :: momentum_a(3)
real(rk) :: momentum_b(3)
real(rk) :: max_pressure_a
real(rk) :: max_pressure_b
real(rk) :: min_density_a
real(rk) :: min_density_b
real(rk) :: max_density_a
real(rk) :: max_density_b
call sph_get_water_summary(mass_a, momentum_a, max_pressure_a, &
min_density_a, max_density_a, ierr)
call assert_ok(ierr, 'first repeated summary failed')
call sph_get_water_summary(mass_b, momentum_b, max_pressure_b, &
min_density_b, max_density_b, ierr)
call assert_ok(ierr, 'second repeated summary failed')
if (abs(mass_a - mass_b) > 1.0e-12_rk) call fail('summary mass is not repeatable')
if (maxval(abs(momentum_a - momentum_b)) > 1.0e-12_rk) then
call fail('summary momentum is not repeatable')
end if
if (abs(max_pressure_a - max_pressure_b) > 1.0e-12_rk) then
call fail('summary pressure is not repeatable')
end if
if (abs(min_density_a - min_density_b) > 1.0e-12_rk) then
call fail('summary min density is not repeatable')
end if
if (abs(max_density_a - max_density_b) > 1.0e-12_rk) then
call fail('summary max density is not repeatable')
end if
end subroutine assert_repeat_summary
subroutine fail(message)
character(len=*), intent(in) :: message
+19 -1
View File
@@ -3,7 +3,7 @@ program test_water_density
use sph_error, only: SPH_SUCCESS
use sph_database, only: sph_db_allocate, sph_db_free, x, v, h, mass, rho, &
drho_dt, particle_phase, particle_status, SPH_PHASE_WATER, SPH_PHASE_SOLID, &
SPH_STATUS_ACTIVE
SPH_STATUS_ACTIVE, SPH_STATUS_INACTIVE
use sph_neighbor, only: sph_neighbor_rebuild
use sph_water, only: sph_water_initialize, sph_water_reset, &
sph_water_compute_density_rate
@@ -15,6 +15,7 @@ program test_water_density
call check_pair_extension()
call check_static_particles()
call check_nonwater_skip()
call check_inactive_skip()
call sph_water_reset()
contains
@@ -58,6 +59,7 @@ contains
subroutine check_static_particles()
call setup_pair()
v = 0.0_rk
drho_dt = 10.0_rk
call sph_neighbor_rebuild(ierr)
call assert_ok(ierr, 'static neighbor failed')
call sph_water_compute_density_rate(ierr)
@@ -81,6 +83,22 @@ contains
call sph_db_free()
end subroutine check_nonwater_skip
subroutine check_inactive_skip()
call setup_pair()
particle_status(2) = SPH_STATUS_INACTIVE
v(:,1) = (/1.0_rk, 0.0_rk, 0.0_rk/)
v(:,2) = (/-1.0_rk, 0.0_rk, 0.0_rk/)
drho_dt = 5.0_rk
call sph_neighbor_rebuild(ierr)
call assert_ok(ierr, 'inactive neighbor failed')
call sph_water_compute_density_rate(ierr)
call assert_ok(ierr, 'inactive density failed')
if (abs(drho_dt(1)) > 1.0e-12_rk .or. abs(drho_dt(2)) > 1.0e-12_rk) then
call fail('inactive particle was not skipped')
end if
call sph_db_free()
end subroutine check_inactive_skip
subroutine assert_ok(ierr_value, message)
integer, intent(in) :: ierr_value
character(len=*), intent(in) :: message
+1
View File
@@ -47,6 +47,7 @@ contains
subroutine check_uniform_pressure()
call setup_pair()
pressure = 0.0_rk
acc_pressure = 3.0_rk
call sph_water_compute_pressure_acceleration(ierr)
call assert_ok(ierr, 'uniform pressure failed')
if (maxval(abs(acc_pressure)) > 1.0e-12_rk) call fail('zero pressure force is not zero')
+1
View File
@@ -53,6 +53,7 @@ contains
call setup_pair()
v(:,1) = (/-1.0_rk, 0.0_rk, 0.0_rk/)
v(:,2) = (/1.0_rk, 0.0_rk, 0.0_rk/)
acc_viscosity = 2.0_rk
call sph_neighbor_rebuild(ierr)
call assert_ok(ierr, 'separating neighbor failed')
call sph_water_compute_viscosity_acceleration(ierr)