program test_coupling_region_build_080 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_region_count use sph_gas, only: sph_gas_get_source_summary use sph_database, only: coupling_region_count, coupling_region_internal_id, & coupling_region_particle_count, coupling_region_disabled_count implicit none integer :: ierr real(rk) :: gas_mass_source real(rk) :: gas_energy_source real(rk) :: gas_momentum_source(3) call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed for coupling region build') call sph_read_inp('tests/data/coupling_region_080.inp', ierr) call assert_ok(ierr, 'read failed for coupling region build') if (blast_region_count /= 0) call fail('coupling input polluted Blast regions') call sph_build_model(ierr) call assert_ok(ierr, 'build failed for coupling region build') if (coupling_region_count /= 3) call fail('runtime region count mismatch') if (coupling_region_internal_id(1) /= 1) call fail('first internal id mismatch') if (coupling_region_internal_id(2) /= 2) call fail('second internal id mismatch') if (coupling_region_internal_id(3) /= 3) call fail('third internal id mismatch') if (coupling_region_particle_count(1) /= 3) call fail('first runtime count mismatch') if (coupling_region_particle_count(2) /= 3) call fail('second runtime count mismatch') if (coupling_region_particle_count(3) /= 0) call fail('disabled runtime count mismatch') if (coupling_region_disabled_count /= 1) call fail('runtime disabled count mismatch') if (blast_region_count /= 0) call fail('coupling build polluted Blast regions') call sph_gas_get_source_summary(gas_mass_source, gas_momentum_source, & gas_energy_source, ierr) call assert_ok(ierr, 'Gas source summary failed after coupling build') call assert_close(gas_mass_source, 0.0_rk, 'Gas mass source was polluted') call assert_close(gas_energy_source, 0.0_rk, 'Gas energy source was polluted') call assert_close(maxval(abs(gas_momentum_source)), 0.0_rk, & 'Gas momentum source was polluted') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for coupling region build') 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) 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_coupling_region_build_080