Add coupling region export APIs

This commit is contained in:
Codex
2026-07-04 08:59:36 +08:00
parent 854b8042b2
commit 9f003dada5
7 changed files with 740 additions and 47 deletions
@@ -0,0 +1,78 @@
program test_coupling_facet_export_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: sph_coupling_get_region_facet_count, &
sph_coupling_export_region_facets, SPH_COUPLING_FACET_VECTOR_COUNT, &
SPH_COUPLING_FACET_VECTOR_CENTER, &
SPH_COUPLING_FACET_VECTOR_VELOCITY, &
SPH_COUPLING_FACET_VECTOR_NORMAL
implicit none
integer :: ierr
integer :: count
integer :: facet_ids(3)
integer :: particle_ids(3)
integer :: materials(3)
integer :: sections(3)
real(rk) :: vectors(SPH_NDIM,SPH_COUPLING_FACET_VECTOR_COUNT,3)
real(rk) :: areas(3)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for facet export')
call sph_read_inp('tests/data/coupling_shell_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for facet export')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for facet export')
call sph_coupling_get_region_facet_count('SHELL_FACETS', count, ierr)
call assert_ok(ierr, 'facet count failed')
if (count /= 3) call fail('facet count mismatch')
call sph_coupling_export_region_facets('SHELL_FACETS', 3, count, &
facet_ids, particle_ids, materials, sections, vectors, areas, ierr)
call assert_ok(ierr, 'facet export failed')
if (count /= 3) call fail('facet export count mismatch')
if (facet_ids(1) /= 1 .or. particle_ids(1) /= 1) call fail('facet id mismatch')
if (minval(materials(1:3)) <= 0) call fail('facet material mismatch')
if (minval(sections(1:3)) <= 0) call fail('facet section mismatch')
call assert_close(vectors(1,SPH_COUPLING_FACET_VECTOR_CENTER,2), 0.1_rk, &
'facet center mismatch')
call assert_close(maxval(abs(vectors(:,SPH_COUPLING_FACET_VECTOR_VELOCITY,1))), &
0.0_rk, 'facet velocity mismatch')
call assert_close(vectors(3,SPH_COUPLING_FACET_VECTOR_NORMAL,1), 1.0_rk, &
'facet normal mismatch')
if (areas(1) <= 0.0_rk) call fail('facet area mismatch')
call sph_coupling_export_region_facets('SHELL_FACETS', 2, count, &
facet_ids(1:2), particle_ids(1:2), materials(1:2), sections(1:2), &
vectors(:,:,1:2), areas(1:2), ierr)
if (ierr == SPH_SUCCESS) call fail('small facet capacity did not fail')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for facet export')
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) > 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_export_080