115 lines
4.5 KiB
Fortran
115 lines
4.5 KiB
Fortran
program test_blast_load_conservation
|
|
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_blast, only: blast_candidate_pair_count, blast_time_window
|
|
use sph_blast_load, only: blast_solid_external_force, &
|
|
blast_shell_external_force, blast_load_target_count, &
|
|
blast_load_pair_count, blast_load_total_force, &
|
|
blast_solid_total_force, blast_shell_total_force, blast_load_impulse, &
|
|
blast_load_momentum_input, blast_load_work, blast_load_energy_input, &
|
|
blast_load_zero_weight_count, blast_load_nonfinite_count
|
|
implicit none
|
|
|
|
integer :: ierr
|
|
|
|
call check_force_balance()
|
|
call check_explosive_energy_contribution()
|
|
|
|
contains
|
|
|
|
subroutine check_force_balance()
|
|
real(rk) :: cache_force(3)
|
|
real(rk) :: split_force(3)
|
|
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for Blast force balance')
|
|
call sph_read_inp('tests/data/blast_water_gas_explosive_solid_shell_070.inp', ierr)
|
|
call assert_ok(ierr, 'read failed for Blast force balance')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build failed for Blast force balance')
|
|
if (blast_load_target_count(1) /= 4) call fail('Blast load target count mismatch')
|
|
if (blast_load_pair_count(1) /= blast_candidate_pair_count(1)) then
|
|
call fail('Blast load pair count mismatch')
|
|
end if
|
|
if (blast_load_zero_weight_count(1) /= 0) call fail('Blast zero weight mismatch')
|
|
if (blast_load_nonfinite_count(1) /= 0) call fail('Blast nonfinite load mismatch')
|
|
cache_force = sph_sum_force(blast_solid_external_force) + &
|
|
sph_sum_force(blast_shell_external_force)
|
|
split_force = blast_solid_total_force(:,1) + blast_shell_total_force(:,1)
|
|
call assert_vector_close(cache_force, blast_load_total_force(:,1), &
|
|
'Blast cache force sum mismatch')
|
|
call assert_vector_close(split_force, blast_load_total_force(:,1), &
|
|
'Blast split force sum mismatch')
|
|
call assert_vector_close(blast_load_impulse(:,1), &
|
|
blast_load_total_force(:,1) * blast_time_window(1), &
|
|
'Blast impulse mismatch')
|
|
call assert_vector_close(blast_load_momentum_input(:,1), blast_load_impulse(:,1), &
|
|
'Blast momentum mismatch')
|
|
if (blast_load_work(1) /= blast_load_work(1)) call fail('Blast work is not finite')
|
|
if (blast_load_energy_input(1) /= blast_load_energy_input(1)) then
|
|
call fail('Blast energy input is not finite')
|
|
end if
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed for Blast force balance')
|
|
end subroutine check_force_balance
|
|
|
|
subroutine check_explosive_energy_contribution()
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for Blast energy contribution')
|
|
call sph_read_inp('tests/data/blast_water_gas_explosive_solid_shell_070.inp', ierr)
|
|
call assert_ok(ierr, 'read failed for Blast energy contribution')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build failed for Blast energy contribution')
|
|
call sph_advance_explicit(1.0e-7_rk, ierr)
|
|
call assert_ok(ierr, 'advance failed for Blast energy contribution')
|
|
if (blast_load_energy_input(1) <= 0.0_rk) then
|
|
call fail('Blast explosive energy contribution missing')
|
|
end if
|
|
if (blast_load_nonfinite_count(1) /= 0) call fail('Blast post-step nonfinite load')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed for Blast energy contribution')
|
|
end subroutine check_explosive_energy_contribution
|
|
|
|
function sph_sum_force(values) result(total)
|
|
real(rk), intent(in) :: values(:,:)
|
|
real(rk) :: total(3)
|
|
integer :: i
|
|
|
|
total = 0.0_rk
|
|
do i = 1, size(values, 2)
|
|
total = total + values(:,i)
|
|
end do
|
|
end function sph_sum_force
|
|
|
|
subroutine assert_vector_close(actual, expected, message)
|
|
real(rk), intent(in) :: actual(3)
|
|
real(rk), intent(in) :: expected(3)
|
|
character(len=*), intent(in) :: message
|
|
integer :: i
|
|
|
|
do i = 1, 3
|
|
if (abs(actual(i) - expected(i)) > &
|
|
max(1.0e-8_rk, abs(expected(i)) * 1.0e-10_rk)) then
|
|
call fail(message)
|
|
end if
|
|
end do
|
|
end subroutine assert_vector_close
|
|
|
|
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_load_conservation
|