142 lines
5.5 KiB
Fortran
142 lines
5.5 KiB
Fortran
program test_coupling_solver_order_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, mass, SPH_COUPLING_DISTRIBUTION_AREA, &
|
|
SPH_COUPLING_DISTRIBUTION_MASS
|
|
use sph_coupling_interface, only: coupling_external_force, &
|
|
SPH_COUPLING_MOTION_DIRECT, SPH_COUPLING_MOTION_VELOCITY, &
|
|
sph_coupling_import_force_by_external_id, &
|
|
sph_coupling_import_region_facet_load, &
|
|
sph_coupling_apply_facet_pressures, &
|
|
sph_coupling_apply_facet_tractions, sph_coupling_apply_motion_boundary
|
|
implicit none
|
|
|
|
integer :: ierr
|
|
|
|
call check_loads_before_motion()
|
|
call check_disabled_region_noop()
|
|
call check_empty_pressure_traction_noop()
|
|
|
|
contains
|
|
|
|
subroutine check_loads_before_motion()
|
|
integer :: ids(1)
|
|
real(rk) :: pressures(1)
|
|
real(rk) :: tractions(SPH_NDIM,1)
|
|
real(rk) :: particle_force(SPH_NDIM)
|
|
real(rk) :: facet_load(SPH_NDIM)
|
|
real(rk) :: target_velocity(SPH_NDIM)
|
|
|
|
call build_case()
|
|
ids(1) = 1
|
|
pressures(1) = 20.0_rk
|
|
call sph_coupling_apply_facet_pressures(1, 1, ids, pressures, &
|
|
SPH_COUPLING_DISTRIBUTION_AREA, 201, ierr)
|
|
call assert_ok(ierr, 'pressure import failed for solver order')
|
|
ids(1) = 2
|
|
tractions(:,1) = (/ 0.0_rk, 0.0_rk, 30.0_rk /)
|
|
call sph_coupling_apply_facet_tractions(2, 1, ids, tractions, &
|
|
SPH_COUPLING_DISTRIBUTION_MASS, 201, ierr)
|
|
call assert_ok(ierr, 'traction import failed for solver order')
|
|
particle_force = (/ 0.0_rk, 0.0_rk, mass(3) * 1.0e8_rk /)
|
|
call sph_coupling_import_force_by_external_id(3, particle_force, ierr)
|
|
call assert_ok(ierr, 'particle force import failed for solver order')
|
|
facet_load = (/ 0.0_rk, 0.0_rk, mass(2) * 1.0e8_rk /)
|
|
call sph_coupling_import_region_facet_load('TRACTION_CONTACT', 2, &
|
|
facet_load, ierr)
|
|
call assert_ok(ierr, 'facet load import failed for solver order')
|
|
target_velocity = (/ 0.0_rk, -1.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, 'motion import failed for solver order')
|
|
call sph_advance_explicit(1.0e-7_rk, ierr)
|
|
call assert_ok(ierr, 'advance failed for solver order')
|
|
call assert_vector_close(v(:,1), target_velocity, &
|
|
'motion boundary was not applied after loads')
|
|
if (v(3,2) <= 0.0_rk) call fail('facet load did not affect free particle')
|
|
if (v(3,3) <= 0.0_rk) call fail('particle force did not affect particle')
|
|
if (maxval(abs(coupling_external_force)) > 0.0_rk) then
|
|
call fail('coupling force cache was not consumed')
|
|
end if
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed after solver order')
|
|
end subroutine check_loads_before_motion
|
|
|
|
subroutine check_disabled_region_noop()
|
|
call build_case()
|
|
call sph_advance_explicit(1.0e-7_rk, ierr)
|
|
call assert_ok(ierr, 'disabled region affected empty advance')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed after disabled noop')
|
|
end subroutine check_disabled_region_noop
|
|
|
|
subroutine check_empty_pressure_traction_noop()
|
|
integer :: empty_ids(0)
|
|
real(rk) :: empty_pressures(0)
|
|
real(rk) :: empty_tractions(SPH_NDIM,0)
|
|
|
|
call build_case()
|
|
call sph_coupling_apply_facet_pressures(1, 0, empty_ids, empty_pressures, &
|
|
SPH_COUPLING_DISTRIBUTION_AREA, 211, ierr)
|
|
call assert_ok(ierr, 'empty pressure import failed')
|
|
call sph_coupling_apply_facet_tractions(2, 0, empty_ids, empty_tractions, &
|
|
SPH_COUPLING_DISTRIBUTION_MASS, 211, ierr)
|
|
call assert_ok(ierr, 'empty traction import failed')
|
|
call sph_advance_explicit(1.0e-7_rk, ierr)
|
|
call assert_ok(ierr, 'empty load advance failed')
|
|
if (maxval(abs(v)) > 1.0e-12_rk) then
|
|
call fail('empty pressure or traction produced velocity')
|
|
end if
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed after empty pressure traction')
|
|
end subroutine check_empty_pressure_traction_noop
|
|
|
|
subroutine build_case()
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for solver order')
|
|
call sph_read_inp('tests/data/coupling_load_mode_081.inp', ierr)
|
|
call assert_ok(ierr, 'read failed for solver order')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build failed for solver order')
|
|
end subroutine build_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 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_solver_order_081
|