Files
SPHLite/tests/module/test_blast_smoke_071.f90
T
2026-07-04 00:49:18 +08:00

246 lines
9.6 KiB
Fortran

program test_blast_smoke_071
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_source_count, blast_gas_volume, &
blast_source_pressure_mean, blast_explosive_progress_mean
use sph_blast_load, only: blast_solid_total_force, blast_shell_total_force, &
blast_load_target_count, blast_load_total_force, blast_load_impulse, &
blast_load_energy_input, blast_load_max_acceleration, &
blast_load_nonfinite_count, sph_blast_load_set_enabled
implicit none
integer :: ierr
call check_solid_multiregion_smoke()
call check_shell_multiregion_smoke()
call check_mixed_multiregion_smoke()
call check_disabled_load_smoke()
call check_no_active_target_smoke()
contains
subroutine check_solid_multiregion_smoke()
real(rk) :: progress_before
call setup_model('tests/data/blast_solid_superposition_071.inp')
progress_before = blast_explosive_progress_mean(1)
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, '0.7.1 Solid multiregion smoke step failed')
call assert_progress_controlled(1, progress_before)
call assert_positive_gas_source(1)
if (blast_solid_total_force(1,1) <= 0.0_rk) then
call fail('0.7.1 Solid primary load direction mismatch')
end if
if (blast_solid_total_force(1,2) <= 0.0_rk) then
call fail('0.7.1 Solid secondary load direction mismatch')
end if
if (maxval(abs(blast_shell_total_force(:,1:2))) > 0.0_rk) then
call fail('0.7.1 Solid smoke polluted Shell force')
end if
call assert_region_diagnostics_finite(1)
call assert_region_diagnostics_finite(2)
call assert_state_finite()
call finish_model('0.7.1 Solid multiregion smoke finalize failed')
end subroutine check_solid_multiregion_smoke
subroutine check_shell_multiregion_smoke()
real(rk) :: progress_before
call setup_model('tests/data/blast_shell_superposition_071.inp')
progress_before = blast_explosive_progress_mean(1)
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, '0.7.1 Shell multiregion smoke step failed')
call assert_progress_controlled(1, progress_before)
call assert_positive_gas_source(1)
if (blast_shell_total_force(1,1) <= 0.0_rk) then
call fail('0.7.1 Shell primary load direction mismatch')
end if
if (blast_shell_total_force(1,2) <= 0.0_rk) then
call fail('0.7.1 Shell secondary load direction mismatch')
end if
if (maxval(abs(blast_solid_total_force(:,1:2))) > 0.0_rk) then
call fail('0.7.1 Shell smoke polluted Solid force')
end if
call assert_region_diagnostics_finite(1)
call assert_region_diagnostics_finite(2)
call assert_state_finite()
call finish_model('0.7.1 Shell multiregion smoke finalize failed')
end subroutine check_shell_multiregion_smoke
subroutine check_mixed_multiregion_smoke()
real(rk) :: progress_before
call setup_model('tests/data/blast_multiregion_071.inp')
progress_before = blast_explosive_progress_mean(1)
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, '0.7.1 mixed multiregion smoke step failed')
call assert_progress_controlled(1, progress_before)
call assert_progress_controlled(2, progress_before)
call assert_positive_gas_source(1)
call assert_positive_gas_source(2)
if (blast_solid_total_force(1,1) <= 0.0_rk) then
call fail('0.7.1 mixed Solid load direction mismatch')
end if
if (blast_shell_total_force(1,2) <= 0.0_rk) then
call fail('0.7.1 mixed Shell x load missing')
end if
if (blast_shell_total_force(2,2) <= 0.0_rk) then
call fail('0.7.1 mixed Shell y load missing')
end if
if (blast_load_target_count(3) /= 0) call fail('disabled smoke target changed')
if (maxval(abs(blast_load_total_force(:,3))) > 0.0_rk) then
call fail('disabled smoke region produced load')
end if
call assert_region_diagnostics_finite(1)
call assert_region_diagnostics_finite(2)
call assert_state_finite()
call finish_model('0.7.1 mixed multiregion smoke finalize failed')
end subroutine check_mixed_multiregion_smoke
subroutine check_disabled_load_smoke()
call setup_model('tests/data/blast_multiregion_071.inp')
call sph_blast_load_set_enabled(.false.)
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, '0.7.1 disabled load smoke step failed')
if (maxval(abs(blast_load_target_count)) /= 0) then
call fail('0.7.1 disabled load smoke target count changed')
end if
if (maxval(abs(blast_load_total_force)) > 0.0_rk) then
call fail('0.7.1 disabled load smoke produced force')
end if
call assert_state_finite()
call finish_model('0.7.1 disabled load smoke finalize failed')
end subroutine check_disabled_load_smoke
subroutine check_no_active_target_smoke()
call check_no_active_target_file('tests/data/blast_water_only_noop_071.inp')
call check_no_active_target_file('tests/data/blast_gas_only_noop_071.inp')
call check_no_active_target_file('tests/data/blast_explosive_only_noop_071.inp')
end subroutine check_no_active_target_smoke
subroutine check_no_active_target_file(filename)
character(len=*), intent(in) :: filename
call setup_model(filename)
call sph_advance_explicit(1.0e-8_rk, ierr)
call assert_ok(ierr, '0.7.1 no-active-target smoke step failed')
if (blast_source_count(1) <= 0) call fail('no-active-target source missing')
if (blast_load_target_count(1) /= 0) then
call fail('no-active-target smoke produced structural target')
end if
if (maxval(abs(blast_load_total_force(:,1))) > 0.0_rk) then
call fail('no-active-target smoke produced structural force')
end if
if (blast_load_nonfinite_count(1) /= 0) then
call fail('no-active-target smoke nonfinite load')
end if
call assert_state_finite()
call finish_model('0.7.1 no-active-target smoke finalize failed')
end subroutine check_no_active_target_file
subroutine setup_model(filename)
character(len=*), intent(in) :: filename
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for 0.7.1 Blast smoke')
call sph_read_inp(filename, ierr)
call assert_ok(ierr, 'read failed for 0.7.1 Blast smoke')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for 0.7.1 Blast smoke')
end subroutine setup_model
subroutine finish_model(message)
character(len=*), intent(in) :: message
call sph_finalize(ierr)
call assert_ok(ierr, message)
end subroutine finish_model
subroutine assert_positive_gas_source(region)
integer, intent(in) :: region
if (blast_gas_volume(region) <= 0.0_rk) call fail('Blast Gas volume missing')
if (blast_source_pressure_mean(region) <= 0.0_rk) then
call fail('Blast source pressure missing')
end if
end subroutine assert_positive_gas_source
subroutine assert_progress_controlled(region, previous)
integer, intent(in) :: region
real(rk), intent(in) :: previous
if (blast_explosive_progress_mean(region) + 1.0e-12_rk < previous) then
call fail('Blast explosive progress regressed')
end if
if (blast_explosive_progress_mean(region) > 1.0_rk + 1.0e-12_rk) then
call fail('Blast explosive progress exceeded one')
end if
end subroutine assert_progress_controlled
subroutine assert_region_diagnostics_finite(region)
integer, intent(in) :: region
call assert_vector_finite(blast_load_impulse(:,region), &
'Blast smoke impulse not finite')
call assert_scalar_finite(blast_load_energy_input(region), &
'Blast smoke energy input not finite')
call assert_scalar_finite(blast_load_max_acceleration(region), &
'Blast smoke acceleration diagnostic not finite')
if (blast_load_nonfinite_count(region) /= 0) then
call fail('Blast smoke nonfinite load')
end if
end subroutine assert_region_diagnostics_finite
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_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_071