103 lines
4.2 KiB
Fortran
103 lines
4.2 KiB
Fortran
program test_input_blast_region
|
|
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_get_input_warning_count
|
|
use sph_blast, only: blast_region_count, blast_region_name, &
|
|
blast_target_set_name, blast_source_phase, blast_target_phase, &
|
|
blast_projection_mode, blast_region_enabled, blast_center, &
|
|
blast_radius, blast_load_scale, blast_time_window, &
|
|
SPH_BLAST_PHASE_GAS, SPH_BLAST_PHASE_SOLID, &
|
|
SPH_BLAST_PHASE_SHELL, SPH_BLAST_PHASE_STRUCTURE, &
|
|
SPH_BLAST_MODE_RADIAL
|
|
implicit none
|
|
|
|
call check_region('tests/data/blast_water_gas_explosive_solid_070.inp', &
|
|
SPH_BLAST_PHASE_SOLID, 'SOLID_TARGET', 0.45_rk, .true., .false.)
|
|
call check_region('tests/data/blast_water_gas_explosive_shell_070.inp', &
|
|
SPH_BLAST_PHASE_SHELL, 'SHELL_TARGET', 0.45_rk, .true., .false.)
|
|
call check_region('tests/data/blast_water_gas_explosive_solid_shell_070.inp', &
|
|
SPH_BLAST_PHASE_STRUCTURE, 'STRUCTURE_TARGET', 0.50_rk, .true., .false.)
|
|
call check_region('tests/data/blast_no_structure_smoke_070.inp', &
|
|
SPH_BLAST_PHASE_STRUCTURE, 'NONE', 0.30_rk, .false., .true.)
|
|
|
|
contains
|
|
|
|
subroutine check_region(filename, expected_target_phase, expected_set, &
|
|
expected_radius, expected_enabled, expect_warning)
|
|
character(len=*), intent(in) :: filename
|
|
integer, intent(in) :: expected_target_phase
|
|
character(len=*), intent(in) :: expected_set
|
|
real(rk), intent(in) :: expected_radius
|
|
logical, intent(in) :: expected_enabled
|
|
logical, intent(in) :: expect_warning
|
|
integer :: ierr
|
|
integer :: warnings
|
|
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for Blast input')
|
|
call sph_read_inp(filename, ierr)
|
|
call assert_ok(ierr, 'read failed for Blast input')
|
|
if (blast_region_count /= 1) call fail('Blast region count mismatch')
|
|
if (trim(blast_region_name(1)) /= 'LOCAL_BLAST') then
|
|
call fail('Blast region name mismatch')
|
|
end if
|
|
if (trim(blast_target_set_name(1)) /= trim(expected_set)) then
|
|
call fail('Blast target set mismatch')
|
|
end if
|
|
if (blast_source_phase(1) /= SPH_BLAST_PHASE_GAS) then
|
|
call fail('Blast source phase mismatch')
|
|
end if
|
|
if (blast_target_phase(1) /= expected_target_phase) then
|
|
call fail('Blast target phase mismatch')
|
|
end if
|
|
if (blast_projection_mode(1) /= SPH_BLAST_MODE_RADIAL) then
|
|
call fail('Blast projection mode mismatch')
|
|
end if
|
|
if (blast_region_enabled(1) .neqv. expected_enabled) then
|
|
call fail('Blast enabled flag mismatch')
|
|
end if
|
|
call assert_close(blast_center(1,1), 0.30_rk, 'Blast center X mismatch')
|
|
call assert_close(blast_center(2,1), 0.0_rk, 'Blast center Y mismatch')
|
|
call assert_close(blast_center(3,1), 0.0_rk, 'Blast center Z mismatch')
|
|
call assert_close(blast_radius(1), expected_radius, 'Blast radius mismatch')
|
|
call assert_close(blast_load_scale(1), 1.0_rk, 'Blast scale mismatch')
|
|
call assert_close(blast_time_window(1), 2.0e-7_rk, &
|
|
'Blast time window mismatch')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build failed for Blast input')
|
|
call sph_get_input_warning_count(warnings, ierr)
|
|
call assert_ok(ierr, 'Blast warning count failed')
|
|
if (expect_warning) then
|
|
if (warnings <= 0) call fail('Blast disabled region warning missing')
|
|
else
|
|
if (warnings /= 0) call fail('unexpected Blast input warning')
|
|
end if
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed for Blast input')
|
|
end subroutine check_region
|
|
|
|
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-12_rk) call fail(message)
|
|
end subroutine assert_close
|
|
|
|
subroutine fail(message)
|
|
character(len=*), intent(in) :: message
|
|
|
|
write(*, '(A)') trim(message)
|
|
stop 1
|
|
end subroutine fail
|
|
|
|
end program test_input_blast_region
|