70 lines
2.5 KiB
Fortran
70 lines
2.5 KiB
Fortran
|
|
program test_explosive_source_targeting
|
||
|
|
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: mass
|
||
|
|
use sph_explosive_state, only: explosive_source_target_count, &
|
||
|
|
explosive_source_mass_total, explosive_source_energy_total, &
|
||
|
|
explosive_source_momentum_total, explosive_released_mass
|
||
|
|
implicit none
|
||
|
|
|
||
|
|
integer :: ierr
|
||
|
|
real(rk) :: target_a_before
|
||
|
|
real(rk) :: target_b_before
|
||
|
|
real(rk) :: target_a_after
|
||
|
|
real(rk) :: target_b_after
|
||
|
|
|
||
|
|
call sph_initialize(ierr)
|
||
|
|
call assert_ok(ierr, 'initialize failed')
|
||
|
|
call sph_read_inp('tests/data/explosive_source_multi_target_041.inp', ierr)
|
||
|
|
call assert_ok(ierr, 'read source targeting failed')
|
||
|
|
call sph_build_model(ierr)
|
||
|
|
call assert_ok(ierr, 'build source targeting failed')
|
||
|
|
target_a_before = mass(3) + mass(4)
|
||
|
|
target_b_before = mass(5) + mass(6)
|
||
|
|
call sph_advance_explicit(1.0e-7_rk, ierr)
|
||
|
|
call assert_ok(ierr, 'advance source targeting failed')
|
||
|
|
target_a_after = mass(3) + mass(4)
|
||
|
|
target_b_after = mass(5) + mass(6)
|
||
|
|
if (target_a_after <= target_a_before) call fail('matched product Gas did not receive source')
|
||
|
|
call assert_close(target_b_after, target_b_before, &
|
||
|
|
'unmatched product Gas received source')
|
||
|
|
if (explosive_source_target_count /= 2) call fail('source target count mismatch')
|
||
|
|
call assert_close(explosive_source_mass_total, explosive_released_mass(1), &
|
||
|
|
'source mass total mismatch')
|
||
|
|
if (explosive_source_energy_total <= 0.0_rk) call fail('source energy total missing')
|
||
|
|
if (maxval(abs(explosive_source_momentum_total)) > 1.0e-12_rk) then
|
||
|
|
call fail('zero velocity source momentum mismatch')
|
||
|
|
end if
|
||
|
|
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-12_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_source_targeting
|