program test_coupling_solid_response_080 use sph_precision, only: rk, SPH_NDIM 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: a, v, mass, particle_status, SPH_STATUS_INACTIVE use sph_coupling_interface, only: coupling_skipped_particle_count, & sph_coupling_import_force_by_region_index, & sph_coupling_get_extended_diagnostics implicit none integer :: ierr call check_solid_force_response() call check_apply_skip_after_import() contains subroutine check_solid_force_response() real(rk) :: force(SPH_NDIM) real(rk) :: total_force(SPH_NDIM) real(rk) :: total_moment(SPH_NDIM) real(rk) :: current_impulse(SPH_NDIM) real(rk) :: cumulative_impulse(SPH_NDIM) real(rk) :: momentum_exchange(SPH_NDIM) real(rk) :: current_work real(rk) :: cumulative_work real(rk) :: energy_exchange real(rk) :: max_force real(rk) :: max_acceleration real(rk) :: max_velocity_error real(rk) :: max_position_error integer :: stale_count integer :: skipped_count integer :: nonfinite_count integer :: imported_force_count integer :: step_load_consumed call build_contact_case() force = (/0.0_rk, 0.0_rk, mass(1) * 1.0e8_rk/) call sph_coupling_import_force_by_region_index('CONTACT_PARTICLES', 1, & force, ierr) call assert_ok(ierr, 'Solid force import failed') call sph_advance_explicit(1.0e-7_rk, ierr) call assert_ok(ierr, 'Solid force advance failed') if (a(3,1) <= 0.0_rk) call fail('Solid coupling acceleration missing') if (v(3,1) <= 0.0_rk) call fail('Solid coupling velocity missing') call sph_coupling_get_extended_diagnostics(total_force, total_moment, & current_impulse, cumulative_impulse, current_work, cumulative_work, & momentum_exchange, energy_exchange, max_force, max_acceleration, & max_velocity_error, max_position_error, stale_count, skipped_count, & nonfinite_count, imported_force_count, step_load_consumed, ierr) call assert_ok(ierr, 'Solid diagnostics failed') call assert_close(total_force(3), force(3), 'Solid force diagnostic mismatch') if (max_acceleration <= 0.0_rk) call fail('Solid max acceleration missing') if (step_load_consumed /= 1) call fail('Solid load not consumed') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for Solid response') end subroutine check_solid_force_response subroutine check_apply_skip_after_import() real(rk) :: force(SPH_NDIM) call build_contact_case() force = (/0.0_rk, mass(1) * 1.0e8_rk, 0.0_rk/) call sph_coupling_import_force_by_region_index('CONTACT_PARTICLES', 1, & force, ierr) call assert_ok(ierr, 'skip force import failed') particle_status(1) = SPH_STATUS_INACTIVE call sph_advance_explicit(1.0e-7_rk, ierr) call assert_ok(ierr, 'skip advance failed') if (abs(v(2,1)) > 1.0e-12_rk) call fail('inactive Solid received force') if (coupling_skipped_particle_count <= 0) call fail('apply skip count missing') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for apply skip') end subroutine check_apply_skip_after_import subroutine build_contact_case() call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed for Solid response') call sph_read_inp('tests/data/coupling_region_080.inp', ierr) call assert_ok(ierr, 'read failed for Solid response') call sph_build_model(ierr) call assert_ok(ierr, 'build failed for Solid response') end subroutine build_contact_case 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) > max(1.0e-10_rk, abs(expected) * 1.0e-8_rk)) 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_coupling_solid_response_080