program test_blast_multiregion_snapshot 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_source_count, blast_target_count, & blast_candidate_pair_count, blast_skipped_source_count, & blast_skipped_target_count, blast_gas_count, blast_water_count, & blast_explosive_count, blast_source_mass, blast_source_energy, & blast_source_pressure_mean, blast_gas_volume, & blast_explosive_progress_mean, blast_water_pressure_min, & blast_water_pressure_max implicit none integer :: ierr real(rk) :: initial_progress call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed') call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr) call assert_ok(ierr, 'read multiregion Blast input failed') call sph_build_model(ierr) call assert_ok(ierr, 'build multiregion Blast input failed') call assert_region_snapshot(1, 1, 2, 2) call assert_region_snapshot(2, 1, 2, 2) if (blast_source_count(3) /= 0 .or. blast_target_count(3) /= 0 .or. & blast_candidate_pair_count(3) /= 0) then call fail('disabled region snapshot was not empty') end if if (blast_skipped_source_count(1) <= 0) then call fail('source phase mismatch skip count missing') end if if (blast_skipped_target_count(1) /= 0) then call fail('Solid target region reported unexpected target skip') end if if (blast_skipped_target_count(2) /= 0) then call fail('Shell target region reported unexpected target skip') end if initial_progress = blast_explosive_progress_mean(1) call sph_advance_explicit(1.0e-7_rk, ierr) call assert_ok(ierr, 'advance multiregion Blast input failed') if (blast_explosive_progress_mean(1) + 1.0e-12_rk < initial_progress) then call fail('Blast multiregion progress regressed') end if if (blast_explosive_progress_mean(1) < 0.99_rk .or. & blast_explosive_progress_mean(2) < 0.99_rk) then call fail('Blast multiregion snapshot was not refreshed after advance') end if call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed') contains subroutine assert_region_snapshot(region, expected_sources, expected_targets, & expected_pairs) integer, intent(in) :: region integer, intent(in) :: expected_sources integer, intent(in) :: expected_targets integer, intent(in) :: expected_pairs if (blast_source_count(region) /= expected_sources) then call fail('Blast multiregion source count mismatch') end if if (blast_target_count(region) /= expected_targets) then call fail('Blast multiregion target count mismatch') end if if (blast_candidate_pair_count(region) /= expected_pairs) then call fail('Blast multiregion pair count mismatch') end if if (blast_water_count(region) /= 2) then call fail('Blast multiregion Water count mismatch') end if if (blast_gas_count(region) /= 1) then call fail('Blast multiregion Gas count mismatch') end if if (blast_explosive_count(region) /= 1) then call fail('Blast multiregion Explosive count mismatch') end if call assert_close(blast_source_mass(region), 0.02_rk, & 'Blast multiregion source mass mismatch') if (blast_source_energy(region) <= 0.0_rk) then call fail('Blast multiregion source energy missing') end if if (blast_source_pressure_mean(region) <= 0.0_rk) then call fail('Blast multiregion source pressure missing') end if call assert_close(blast_gas_volume(region), 1.25e-5_rk, & 'Blast multiregion Gas volume mismatch') call assert_close(blast_water_pressure_min(region), 0.0_rk, & 'Blast multiregion Water pressure min mismatch') call assert_close(blast_water_pressure_max(region), 0.0_rk, & 'Blast multiregion Water pressure max mismatch') end subroutine assert_region_snapshot 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_blast_multiregion_snapshot