Files
SPHLite/tests/module/test_explosive_phase_refresh.f90
2026-07-03 13:36:16 +08:00

66 lines
2.5 KiB
Fortran

program test_explosive_phase_refresh
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
use sph_database, only: particle_phase, material_id, mass, rho, volume, &
pressure, internal_energy, gas_particle_count, gas_mass, gas_max_pressure, &
SPH_PHASE_GAS
use sph_explosive_state, only: explosive_converted_count, &
explosive_reaction_progress
implicit none
integer :: ierr
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed')
call sph_read_inp('tests/data/explosive_phase_refresh_041.inp', ierr)
call assert_ok(ierr, 'read phase refresh failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build phase refresh failed')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'advance phase refresh failed')
if (particle_phase(1) /= SPH_PHASE_GAS) call fail('phase did not refresh to Gas')
if (material_id(1) /= 2) call fail('product material did not refresh')
call assert_close(rho(1), 1200.0_rk, 'product Gas density mismatch')
call assert_close(volume(1), mass(1) / rho(1), 'product Gas volume mismatch')
call assert_close(internal_energy(1), 4.2e6_rk, 'product Gas energy mismatch')
if (pressure(1) <= 0.0_rk) call fail('product Gas pressure was not refreshed')
if (gas_particle_count <= 0 .or. gas_mass <= 0.0_rk) then
call fail('Gas summary did not include converted particle')
end if
if (gas_max_pressure <= 0.0_rk) call fail('Gas pressure summary mismatch')
if (explosive_converted_count <= 0) call fail('converted count missing')
call assert_close(explosive_reaction_progress(1), 1.0_rk, &
'Explosive history was not retained')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed')
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 assert_close(actual, expected, message)
real(rk), intent(in) :: actual
real(rk), intent(in) :: expected
character(len=*), intent(in) :: message
if (abs(actual - expected) > 1.0e-10_rk * max(1.0_rk, abs(expected))) then
call fail(message)
end if
end subroutine assert_close
subroutine fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_explosive_phase_refresh