Files
SPHLite/tests/module/test_blast_smoke.f90
2026-07-03 23:52:46 +08:00

146 lines
5.5 KiB
Fortran

program test_blast_smoke
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: npart, x, v, a, rho, pressure, internal_energy, &
temperature, h
use sph_blast, only: blast_gas_volume, blast_explosive_progress_mean
use sph_blast_load, only: blast_solid_total_force, blast_shell_total_force, &
blast_load_impulse, blast_load_energy_input, &
blast_load_max_acceleration, blast_load_nonfinite_count
implicit none
integer :: ierr
call check_solid_single_step_smoke()
call check_shell_single_step_smoke()
call check_mixed_multi_step_smoke()
contains
subroutine check_solid_single_step_smoke()
call setup_model('tests/data/blast_water_gas_explosive_solid_070.inp')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'Solid Blast smoke step failed')
if (blast_gas_volume(1) <= 0.0_rk) call fail('Solid smoke Gas volume missing')
if (blast_explosive_progress_mean(1) <= 0.0_rk) then
call fail('Solid smoke Explosive progress missing')
end if
if (blast_solid_total_force(1,1) <= 0.0_rk) then
call fail('Solid smoke load direction mismatch')
end if
if (blast_load_impulse(1,1) <= 0.0_rk) call fail('Solid smoke impulse missing')
call assert_energy_finite()
call assert_state_finite()
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize Solid Blast smoke failed')
end subroutine check_solid_single_step_smoke
subroutine check_shell_single_step_smoke()
call setup_model('tests/data/blast_water_gas_explosive_shell_070.inp')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'Shell Blast smoke step failed')
if (blast_shell_total_force(1,1) <= 0.0_rk) then
call fail('Shell smoke load direction mismatch')
end if
if (v(1,5) <= 0.0_rk) call fail('Shell smoke velocity missing')
if (blast_load_max_acceleration(1) <= 0.0_rk) then
call fail('Shell smoke acceleration diagnostic missing')
end if
call assert_energy_finite()
call assert_state_finite()
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize Shell Blast smoke failed')
end subroutine check_shell_single_step_smoke
subroutine check_mixed_multi_step_smoke()
real(rk) :: progress_first
call setup_model('tests/data/blast_water_gas_explosive_solid_shell_070.inp')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'mixed Blast first step failed')
progress_first = blast_explosive_progress_mean(1)
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'mixed Blast second step failed')
if (blast_explosive_progress_mean(1) + 1.0e-12_rk < progress_first) then
call fail('mixed smoke Explosive progress regressed')
end if
if (blast_solid_total_force(1,1) <= 0.0_rk) then
call fail('mixed smoke Solid force missing')
end if
if (blast_shell_total_force(1,1) <= 0.0_rk) then
call fail('mixed smoke Shell force missing')
end if
if (blast_load_nonfinite_count(1) /= 0) call fail('mixed smoke nonfinite load')
call assert_energy_finite()
call assert_state_finite()
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize mixed Blast smoke failed')
end subroutine check_mixed_multi_step_smoke
subroutine setup_model(filename)
character(len=*), intent(in) :: filename
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Blast smoke')
call sph_read_inp(filename, ierr)
call assert_ok(ierr, 'read failed for Blast smoke')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Blast smoke')
end subroutine setup_model
subroutine assert_state_finite()
integer :: i
do i = 1, npart
call assert_vector_finite(x(:,i), 'Blast smoke position not finite')
call assert_vector_finite(v(:,i), 'Blast smoke velocity not finite')
call assert_vector_finite(a(:,i), 'Blast smoke acceleration not finite')
call assert_scalar_finite(rho(i), 'Blast smoke density not finite')
call assert_scalar_finite(pressure(i), 'Blast smoke pressure not finite')
call assert_scalar_finite(internal_energy(i), 'Blast smoke energy not finite')
call assert_scalar_finite(temperature(i), 'Blast smoke temperature not finite')
call assert_scalar_finite(h(i), 'Blast smoke smoothing length not finite')
end do
end subroutine assert_state_finite
subroutine assert_energy_finite()
call assert_scalar_finite(blast_load_energy_input(1), &
'Blast smoke load energy not finite')
end subroutine assert_energy_finite
subroutine assert_vector_finite(values, message)
real(rk), intent(in) :: values(3)
character(len=*), intent(in) :: message
integer :: i
do i = 1, 3
call assert_scalar_finite(values(i), message)
end do
end subroutine assert_vector_finite
subroutine assert_scalar_finite(value, message)
real(rk), intent(in) :: value
character(len=*), intent(in) :: message
if (value /= value) call fail(message)
if (abs(value) > huge(value) * 0.5_rk) call fail(message)
end subroutine assert_scalar_finite
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_blast_smoke