program test_coupling_motion_boundary_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 use sph_database, only: particle_status, SPH_STATUS_INACTIVE use sph_coupling_interface, only: coupling_motion_velocity, & coupling_motion_position, coupling_motion_flag, coupling_motion_mode, & coupling_skipped_particle_count, coupling_nonfinite_import_count, & SPH_COUPLING_MOTION_VELOCITY, SPH_COUPLING_MOTION_POSITION, & SPH_COUPLING_MOTION_DIRECT, SPH_COUPLING_MOTION_PENALTY, & sph_coupling_import_motion_velocity, & sph_coupling_import_motion_position implicit none integer :: ierr call check_direct_motion_targets() call check_motion_error_paths() call check_motion_inactive_skip() contains subroutine check_direct_motion_targets() real(rk) :: target(SPH_NDIM) call build_contact_case() target = (/1.0_rk, 2.0_rk, 3.0_rk/) call sph_coupling_import_motion_velocity('CONTACT_PARTICLES', 1, & SPH_COUPLING_MOTION_DIRECT, target, ierr) call assert_ok(ierr, 'velocity motion import failed') if (coupling_motion_flag(1) /= SPH_COUPLING_MOTION_VELOCITY) then call fail('velocity motion flag mismatch') end if if (coupling_motion_mode(1) /= SPH_COUPLING_MOTION_DIRECT) then call fail('velocity motion mode mismatch') end if call assert_close(coupling_motion_velocity(2,1), 2.0_rk, & 'velocity target mismatch') target = (/0.1_rk, 0.2_rk, 0.3_rk/) call sph_coupling_import_motion_position('CONTACT_PARTICLES', 2, & SPH_COUPLING_MOTION_DIRECT, target, ierr) call assert_ok(ierr, 'position motion import failed') if (coupling_motion_flag(2) /= SPH_COUPLING_MOTION_POSITION) then call fail('position motion flag mismatch') end if call assert_close(coupling_motion_position(3,2), 0.3_rk, & 'position target mismatch') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed after direct motion') end subroutine check_direct_motion_targets subroutine check_motion_error_paths() real(rk) :: target(SPH_NDIM) call build_contact_case() target = (/1.0_rk, 0.0_rk, 0.0_rk/) call sph_coupling_import_motion_velocity('CONTACT_PARTICLES', 1, 99, & target, ierr) if (ierr == SPH_SUCCESS) call fail('invalid motion mode did not fail') call sph_coupling_import_motion_velocity('CONTACT_PARTICLES', 1, & SPH_COUPLING_MOTION_PENALTY, target, ierr) if (ierr == SPH_SUCCESS) call fail('penalty motion mode did not fail') target(1) = huge(target(1)) call sph_coupling_import_motion_velocity('CONTACT_PARTICLES', 1, & SPH_COUPLING_MOTION_DIRECT, target, ierr) if (ierr == SPH_SUCCESS) call fail('nonfinite motion target did not fail') if (coupling_nonfinite_import_count <= 0) call fail('motion nonfinite count missing') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed after motion errors') end subroutine check_motion_error_paths subroutine check_motion_inactive_skip() real(rk) :: target(SPH_NDIM) call build_contact_case() particle_status(3) = SPH_STATUS_INACTIVE target = (/0.0_rk, 0.0_rk, 1.0_rk/) call sph_coupling_import_motion_position('CONTACT_PARTICLES', 3, & SPH_COUPLING_MOTION_DIRECT, target, ierr) call assert_ok(ierr, 'inactive motion skip should not fail') if (coupling_skipped_particle_count /= 1) call fail('motion skip missing') if (coupling_motion_flag(3) /= 0) call fail('inactive motion flag was set') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed after inactive motion') end subroutine check_motion_inactive_skip subroutine build_contact_case() call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed for motion boundary') call sph_read_inp('tests/data/coupling_region_080.inp', ierr) call assert_ok(ierr, 'read failed for motion boundary') call sph_build_model(ierr) call assert_ok(ierr, 'build failed for motion boundary') 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) > 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_motion_boundary_080