101 lines
3.9 KiB
Fortran
101 lines
3.9 KiB
Fortran
program test_coupling_facet_load_import_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_coupling_interface, only: coupling_external_force, &
|
|
coupling_nonfinite_import_count, sph_coupling_import_region_facet_load, &
|
|
sph_coupling_import_facet_particle_forces
|
|
implicit none
|
|
|
|
integer :: ierr
|
|
|
|
call check_facet_load_mapping()
|
|
call check_facet_load_errors()
|
|
|
|
contains
|
|
|
|
subroutine check_facet_load_mapping()
|
|
real(rk) :: load(SPH_NDIM)
|
|
real(rk) :: particle_forces(SPH_NDIM,1)
|
|
integer :: particle_ids(1)
|
|
|
|
call build_shell_case()
|
|
load = (/0.0_rk, 0.0_rk, 5.0_rk/)
|
|
call sph_coupling_import_region_facet_load('SHELL_FACETS', 1, load, ierr)
|
|
call assert_ok(ierr, 'facet load import failed')
|
|
call assert_close(coupling_external_force(3,1), 5.0_rk, &
|
|
'facet load force mismatch')
|
|
particle_ids(1) = 1
|
|
particle_forces(:,1) = (/1.0_rk, 2.0_rk, 3.0_rk/)
|
|
call sph_coupling_import_facet_particle_forces('SHELL_FACETS', 1, 1, &
|
|
particle_ids, particle_forces, ierr)
|
|
call assert_ok(ierr, 'facet particle force import failed')
|
|
call assert_close(coupling_external_force(1,1), 1.0_rk, &
|
|
'facet particle force x mismatch')
|
|
call assert_close(coupling_external_force(2,1), 2.0_rk, &
|
|
'facet particle force y mismatch')
|
|
call assert_close(coupling_external_force(3,1), 8.0_rk, &
|
|
'facet particle force z mismatch')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed after facet load mapping')
|
|
end subroutine check_facet_load_mapping
|
|
|
|
subroutine check_facet_load_errors()
|
|
real(rk) :: load(SPH_NDIM)
|
|
real(rk) :: particle_forces(SPH_NDIM,2)
|
|
integer :: particle_ids(2)
|
|
|
|
call build_shell_case()
|
|
load = (/0.0_rk, 0.0_rk, 1.0_rk/)
|
|
call sph_coupling_import_region_facet_load('SHELL_FACETS', 99, load, ierr)
|
|
if (ierr == SPH_SUCCESS) call fail('invalid facet id did not fail')
|
|
particle_ids = (/1, 2/)
|
|
particle_forces = 0.0_rk
|
|
call sph_coupling_import_facet_particle_forces('SHELL_FACETS', 1, 2, &
|
|
particle_ids, particle_forces, ierr)
|
|
if (ierr == SPH_SUCCESS) call fail('facet particle count mismatch did not fail')
|
|
particle_ids(1) = 2
|
|
call sph_coupling_import_facet_particle_forces('SHELL_FACETS', 1, 1, &
|
|
particle_ids(1:1), particle_forces(:,1:1), ierr)
|
|
if (ierr == SPH_SUCCESS) call fail('facet particle id mismatch did not fail')
|
|
load(1) = huge(load(1))
|
|
call sph_coupling_import_region_facet_load('SHELL_FACETS', 1, load, ierr)
|
|
if (ierr == SPH_SUCCESS) call fail('nonfinite facet load did not fail')
|
|
if (coupling_nonfinite_import_count <= 0) call fail('facet nonfinite count missing')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed after facet load errors')
|
|
end subroutine check_facet_load_errors
|
|
|
|
subroutine build_shell_case()
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for facet load')
|
|
call sph_read_inp('tests/data/coupling_shell_region_080.inp', ierr)
|
|
call assert_ok(ierr, 'read failed for facet load')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build failed for facet load')
|
|
end subroutine build_shell_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_facet_load_import_080
|