program test_coupling_mixed_pressure_motion_081 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: v, SPH_COUPLING_DISTRIBUTION_AREA use sph_coupling_interface, only: SPH_COUPLING_MOTION_DIRECT, & SPH_COUPLING_MOTION_VELOCITY, sph_coupling_apply_facet_pressures, & sph_coupling_apply_motion_boundary implicit none integer :: ierr integer :: ids(2) real(rk) :: pressures(2) real(rk) :: target_velocity(SPH_NDIM) call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed for mixed pressure motion') call sph_read_inp('tests/data/coupling_load_mode_081.inp', ierr) call assert_ok(ierr, 'read failed for mixed pressure motion') call sph_build_model(ierr) call assert_ok(ierr, 'build failed for mixed pressure motion') ids = (/ 1, 2 /) pressures = (/ 40.0_rk, 40.0_rk /) call sph_coupling_apply_facet_pressures(1, 2, ids, pressures, & SPH_COUPLING_DISTRIBUTION_AREA, 501, ierr) call assert_ok(ierr, 'mixed pressure import failed') target_velocity = (/ 0.0_rk, 2.0_rk, 0.0_rk /) call sph_coupling_apply_motion_boundary(2, 1, & SPH_COUPLING_MOTION_VELOCITY, SPH_COUPLING_MOTION_DIRECT, & target_velocity, ierr) call assert_ok(ierr, 'mixed motion import failed') call sph_advance_explicit(1.0e-7_rk, ierr) call assert_ok(ierr, 'mixed pressure motion advance failed') call assert_vector_close(v(:,1), target_velocity, & 'motion boundary did not override pressure particle') if (v(3,2) <= 0.0_rk) call fail('free pressure particle did not respond') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for mixed pressure motion') 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) > max(1.0e-10_rk, abs(expected) * 1.0e-8_rk)) then call fail(message) end if end subroutine assert_close subroutine assert_vector_close(actual, expected, message) real(rk), intent(in) :: actual(SPH_NDIM) real(rk), intent(in) :: expected(SPH_NDIM) character(len=*), intent(in) :: message integer :: i do i = 1, SPH_NDIM call assert_close(actual(i), expected(i), message) end do end subroutine assert_vector_close subroutine fail(message) character(len=*), intent(in) :: message write(*, '(A)') trim(message) stop 1 end subroutine fail end program test_coupling_mixed_pressure_motion_081