program test_blast_load_diagnostics_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 use sph_blast, only: blast_load_scale use sph_blast_load, only: blast_solid_external_force, & blast_shell_external_force, blast_shell_external_moment, & blast_load_target_count, blast_load_pair_count, & blast_load_zero_weight_count, blast_load_nonfinite_count, & blast_load_total_force, blast_solid_total_force, & blast_shell_total_force, blast_load_impulse, blast_load_work, & blast_load_energy_input, blast_load_max_particle_force, & sph_blast_load_compute_at, sph_blast_load_set_enabled use sph_database, only: volume implicit none integer :: ierr call check_multiregion_diagnostics() call check_zero_weight_diagnostic() call check_nonfinite_diagnostic() call check_disabled_load_clear() contains subroutine check_multiregion_diagnostics() call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed for multiregion load diagnostics') call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr) call assert_ok(ierr, 'read failed for multiregion load diagnostics') call sph_build_model(ierr) call assert_ok(ierr, 'build failed for multiregion load diagnostics') if (blast_load_target_count(1) /= 2) call fail('Solid target load count mismatch') if (blast_load_target_count(2) /= 2) call fail('Shell target load count mismatch') if (blast_load_target_count(3) /= 0) call fail('disabled target load count mismatch') if (blast_load_pair_count(1) /= 2) call fail('Solid load pair count mismatch') if (blast_load_pair_count(2) /= 2) call fail('Shell load pair count mismatch') if (blast_load_zero_weight_count(1) /= 0 .or. & blast_load_zero_weight_count(2) /= 0) call fail('unexpected zero weight') if (blast_load_nonfinite_count(1) /= 0 .or. & blast_load_nonfinite_count(2) /= 0) call fail('unexpected nonfinite load') if (maxval(abs(blast_load_total_force(:,1))) <= 0.0_rk) then call fail('Solid total load force missing') end if if (maxval(abs(blast_load_total_force(:,2))) <= 0.0_rk) then call fail('Shell total load force missing') end if if (maxval(abs(blast_solid_total_force(:,1))) <= 0.0_rk) then call fail('Solid split force missing') end if if (maxval(abs(blast_shell_total_force(:,2))) <= 0.0_rk) then call fail('Shell split force missing') end if if (maxval(abs(blast_shell_total_force(:,1))) > 0.0_rk) then call fail('Solid region polluted Shell force summary') end if if (maxval(abs(blast_solid_total_force(:,2))) > 0.0_rk) then call fail('Shell region polluted Solid force summary') end if if (maxval(abs(blast_load_impulse(:,1))) <= 0.0_rk .or. & maxval(abs(blast_load_impulse(:,2))) <= 0.0_rk) then call fail('load impulse diagnostic missing') end if if (blast_load_work(1) /= blast_load_work(1) .or. & blast_load_work(2) /= blast_load_work(2)) then call fail('load work diagnostic not finite') end if if (blast_load_energy_input(1) /= blast_load_energy_input(1) .or. & blast_load_energy_input(2) /= blast_load_energy_input(2)) then call fail('load energy diagnostic not finite') end if if (blast_load_max_particle_force(1) <= 0.0_rk .or. & blast_load_max_particle_force(2) <= 0.0_rk) then call fail('max particle force missing') end if call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for multiregion load diagnostics') end subroutine check_multiregion_diagnostics subroutine check_zero_weight_diagnostic() call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed for zero-weight diagnostic') call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr) call assert_ok(ierr, 'read failed for zero-weight diagnostic') call sph_build_model(ierr) call assert_ok(ierr, 'build failed for zero-weight diagnostic') volume(5:8) = 0.0_rk call sph_blast_load_compute_at(0.0_rk, ierr) call assert_ok(ierr, 'recompute failed for zero-weight diagnostic') if (blast_load_zero_weight_count(1) <= 0) call fail('Solid zero-weight missing') if (blast_load_zero_weight_count(2) <= 0) call fail('Shell zero-weight missing') if (blast_load_target_count(1) /= 0) call fail('Solid zero-weight target applied') if (blast_load_target_count(2) /= 0) call fail('Shell zero-weight target applied') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for zero-weight diagnostic') end subroutine check_zero_weight_diagnostic subroutine check_nonfinite_diagnostic() call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed for nonfinite diagnostic') call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr) call assert_ok(ierr, 'read failed for nonfinite diagnostic') call sph_build_model(ierr) call assert_ok(ierr, 'build failed for nonfinite diagnostic') blast_load_scale(1) = huge(blast_load_scale(1)) call sph_blast_load_compute_at(0.0_rk, ierr) call assert_ok(ierr, 'recompute failed for nonfinite diagnostic') if (blast_load_nonfinite_count(1) <= 0) call fail('nonfinite load missing') if (blast_load_target_count(1) /= 0) call fail('nonfinite Solid load applied') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for nonfinite diagnostic') end subroutine check_nonfinite_diagnostic subroutine check_disabled_load_clear() call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed for disabled load clear') call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr) call assert_ok(ierr, 'read failed for disabled load clear') call sph_build_model(ierr) call assert_ok(ierr, 'build failed for disabled load clear') call sph_blast_load_set_enabled(.false.) call sph_blast_load_compute_at(0.0_rk, ierr) call assert_ok(ierr, 'disabled load recompute failed') if (maxval(abs(blast_solid_external_force)) > 0.0_rk) then call fail('disabled load left Solid cache') end if if (maxval(abs(blast_shell_external_force)) > 0.0_rk) then call fail('disabled load left Shell cache') end if if (maxval(abs(blast_shell_external_moment)) > 0.0_rk) then call fail('disabled load left Shell moment cache') end if if (blast_load_target_count(1) /= 0 .or. blast_load_target_count(2) /= 0) then call fail('disabled load target diagnostic not cleared') end if call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for disabled load clear') end subroutine check_disabled_load_clear 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_diagnostics_071