Add coupling region export APIs
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
program test_coupling_facet_errors_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_shell, only: shell_director, shell_reference_area
|
||||
use sph_coupling_interface, only: sph_coupling_get_region_facet_count, &
|
||||
sph_coupling_export_region_facets, SPH_COUPLING_FACET_VECTOR_COUNT
|
||||
implicit none
|
||||
|
||||
integer :: ierr
|
||||
|
||||
call check_solid_has_no_facet_proxy()
|
||||
call check_disabled_facet_region()
|
||||
call check_zero_area_facet_fails()
|
||||
call check_nonfinite_normal_fails()
|
||||
|
||||
contains
|
||||
|
||||
subroutine check_solid_has_no_facet_proxy()
|
||||
integer :: count
|
||||
|
||||
call sph_initialize(ierr)
|
||||
call assert_ok(ierr, 'initialize failed for solid facet error')
|
||||
call sph_read_inp('tests/data/coupling_region_080.inp', ierr)
|
||||
call assert_ok(ierr, 'read failed for solid facet error')
|
||||
call sph_build_model(ierr)
|
||||
call assert_ok(ierr, 'build failed for solid facet error')
|
||||
call sph_coupling_get_region_facet_count('CONTACT_FACETS', count, ierr)
|
||||
if (ierr == SPH_SUCCESS) call fail('solid facet proxy count did not fail')
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize failed after solid facet error')
|
||||
end subroutine check_solid_has_no_facet_proxy
|
||||
|
||||
subroutine check_disabled_facet_region()
|
||||
integer :: count
|
||||
|
||||
call sph_initialize(ierr)
|
||||
call assert_ok(ierr, 'initialize failed for disabled facet region')
|
||||
call sph_read_inp('tests/data/coupling_region_080.inp', ierr)
|
||||
call assert_ok(ierr, 'read failed for disabled facet region')
|
||||
call sph_build_model(ierr)
|
||||
call assert_ok(ierr, 'build failed for disabled facet region')
|
||||
call sph_coupling_get_region_facet_count('CONTACT_DISABLED', count, ierr)
|
||||
call assert_ok(ierr, 'disabled facet count failed')
|
||||
if (count /= 0) call fail('disabled facet region returned facets')
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize failed after disabled facet region')
|
||||
end subroutine check_disabled_facet_region
|
||||
|
||||
subroutine check_zero_area_facet_fails()
|
||||
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 build_shell_case()
|
||||
shell_reference_area(1) = 0.0_rk
|
||||
call sph_coupling_export_region_facets('SHELL_FACETS', 3, count, &
|
||||
facet_ids, particle_ids, materials, sections, vectors, areas, ierr)
|
||||
if (ierr == SPH_SUCCESS) call fail('zero area facet did not fail')
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize failed after zero area facet')
|
||||
end subroutine check_zero_area_facet_fails
|
||||
|
||||
subroutine check_nonfinite_normal_fails()
|
||||
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 build_shell_case()
|
||||
shell_director(1,1) = huge(shell_director(1,1))
|
||||
call sph_coupling_export_region_facets('SHELL_FACETS', 3, count, &
|
||||
facet_ids, particle_ids, materials, sections, vectors, areas, ierr)
|
||||
if (ierr == SPH_SUCCESS) call fail('nonfinite facet normal did not fail')
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize failed after nonfinite facet normal')
|
||||
end subroutine check_nonfinite_normal_fails
|
||||
|
||||
subroutine build_shell_case()
|
||||
call sph_initialize(ierr)
|
||||
call assert_ok(ierr, 'initialize failed for shell facet error')
|
||||
call sph_read_inp('tests/data/coupling_shell_region_080.inp', ierr)
|
||||
call assert_ok(ierr, 'read failed for shell facet error')
|
||||
call sph_build_model(ierr)
|
||||
call assert_ok(ierr, 'build failed for shell facet error')
|
||||
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 fail(message)
|
||||
character(len=*), intent(in) :: message
|
||||
|
||||
write(*, '(A)') trim(message)
|
||||
stop 1
|
||||
end subroutine fail
|
||||
|
||||
end program test_coupling_facet_errors_080
|
||||
@@ -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
|
||||
@@ -0,0 +1,153 @@
|
||||
program test_coupling_particle_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_database, only: pressure, SPH_PHASE_SOLID, SPH_STATUS_ACTIVE
|
||||
use sph_coupling_interface, only: sph_coupling_get_region_particle_count, &
|
||||
sph_coupling_export_region_particles, &
|
||||
SPH_COUPLING_PARTICLE_SCALAR_COUNT, &
|
||||
SPH_COUPLING_PARTICLE_SCALAR_MASS, &
|
||||
SPH_COUPLING_PARTICLE_SCALAR_VOLUME, &
|
||||
SPH_COUPLING_PARTICLE_SCALAR_DENSITY, &
|
||||
SPH_COUPLING_PARTICLE_SCALAR_PRESSURE, &
|
||||
SPH_COUPLING_PARTICLE_SCALAR_ENERGY, &
|
||||
SPH_COUPLING_PARTICLE_SCALAR_TEMPERATURE, &
|
||||
SPH_COUPLING_PARTICLE_SCALAR_H, &
|
||||
SPH_COUPLING_PARTICLE_VECTOR_COUNT, &
|
||||
SPH_COUPLING_PARTICLE_VECTOR_X, SPH_COUPLING_PARTICLE_VECTOR_V, &
|
||||
SPH_COUPLING_PARTICLE_VECTOR_A
|
||||
implicit none
|
||||
|
||||
integer :: ierr
|
||||
|
||||
call check_particle_export()
|
||||
call check_particle_export_errors()
|
||||
|
||||
contains
|
||||
|
||||
subroutine check_particle_export()
|
||||
integer :: count
|
||||
integer :: ext_ids(3)
|
||||
integer :: internal_ids(3)
|
||||
integer :: phases(3)
|
||||
integer :: statuses(3)
|
||||
integer :: materials(3)
|
||||
integer :: sections(3)
|
||||
real(rk) :: scalars(SPH_COUPLING_PARTICLE_SCALAR_COUNT,3)
|
||||
real(rk) :: vectors(SPH_NDIM,SPH_COUPLING_PARTICLE_VECTOR_COUNT,3)
|
||||
|
||||
call build_contact_case()
|
||||
call sph_coupling_get_region_particle_count('CONTACT_PARTICLES', count, ierr)
|
||||
call assert_ok(ierr, 'particle region count failed')
|
||||
if (count /= 3) call fail('particle region count mismatch')
|
||||
call sph_coupling_export_region_particles('CONTACT_PARTICLES', 3, count, &
|
||||
ext_ids, internal_ids, phases, statuses, materials, sections, &
|
||||
scalars, vectors, ierr)
|
||||
call assert_ok(ierr, 'particle region export failed')
|
||||
if (count /= 3) call fail('particle export count mismatch')
|
||||
if (ext_ids(1) /= 1 .or. ext_ids(3) /= 3) call fail('external id order mismatch')
|
||||
if (internal_ids(1) /= 1 .or. internal_ids(3) /= 3) then
|
||||
call fail('internal id order mismatch')
|
||||
end if
|
||||
if (any(phases(1:3) /= SPH_PHASE_SOLID)) call fail('phase export mismatch')
|
||||
if (any(statuses(1:3) /= SPH_STATUS_ACTIVE)) call fail('status export mismatch')
|
||||
if (minval(materials(1:3)) <= 0) call fail('material export mismatch')
|
||||
if (minval(sections(1:3)) <= 0) call fail('section export mismatch')
|
||||
call assert_close(scalars(SPH_COUPLING_PARTICLE_SCALAR_MASS,1), 1.0_rk, &
|
||||
'mass scalar mismatch')
|
||||
if (scalars(SPH_COUPLING_PARTICLE_SCALAR_VOLUME,1) <= 0.0_rk) then
|
||||
call fail('volume scalar mismatch')
|
||||
end if
|
||||
if (scalars(SPH_COUPLING_PARTICLE_SCALAR_DENSITY,1) <= 0.0_rk) then
|
||||
call fail('density scalar mismatch')
|
||||
end if
|
||||
call assert_close(scalars(SPH_COUPLING_PARTICLE_SCALAR_PRESSURE,1), &
|
||||
0.0_rk, 'pressure scalar mismatch')
|
||||
if (scalars(SPH_COUPLING_PARTICLE_SCALAR_ENERGY,1) < 0.0_rk) then
|
||||
call fail('energy scalar mismatch')
|
||||
end if
|
||||
if (scalars(SPH_COUPLING_PARTICLE_SCALAR_TEMPERATURE,1) <= 0.0_rk) then
|
||||
call fail('temperature scalar mismatch')
|
||||
end if
|
||||
if (scalars(SPH_COUPLING_PARTICLE_SCALAR_H,1) <= 0.0_rk) then
|
||||
call fail('h scalar mismatch')
|
||||
end if
|
||||
call assert_close(vectors(1,SPH_COUPLING_PARTICLE_VECTOR_X,2), 0.1_rk, &
|
||||
'position vector mismatch')
|
||||
call assert_close(maxval(abs(vectors(:,SPH_COUPLING_PARTICLE_VECTOR_V,1))), &
|
||||
0.0_rk, 'velocity vector mismatch')
|
||||
call assert_close(maxval(abs(vectors(:,SPH_COUPLING_PARTICLE_VECTOR_A,1))), &
|
||||
0.0_rk, 'acceleration vector mismatch')
|
||||
|
||||
call sph_coupling_get_region_particle_count('CONTACT_DISABLED', count, ierr)
|
||||
call assert_ok(ierr, 'disabled particle count failed')
|
||||
if (count /= 0) call fail('disabled region returned particles')
|
||||
call sph_coupling_export_region_particles('CONTACT_DISABLED', 3, count, &
|
||||
ext_ids, internal_ids, phases, statuses, materials, sections, &
|
||||
scalars, vectors, ierr)
|
||||
call assert_ok(ierr, 'disabled particle export failed')
|
||||
if (count /= 0) call fail('disabled particle export count mismatch')
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize failed after particle export')
|
||||
end subroutine check_particle_export
|
||||
|
||||
subroutine check_particle_export_errors()
|
||||
integer :: count
|
||||
integer :: ext_ids(3)
|
||||
integer :: internal_ids(3)
|
||||
integer :: phases(3)
|
||||
integer :: statuses(3)
|
||||
integer :: materials(3)
|
||||
integer :: sections(3)
|
||||
real(rk) :: scalars(SPH_COUPLING_PARTICLE_SCALAR_COUNT,3)
|
||||
real(rk) :: vectors(SPH_NDIM,SPH_COUPLING_PARTICLE_VECTOR_COUNT,3)
|
||||
|
||||
call build_contact_case()
|
||||
call sph_coupling_get_region_particle_count('NOT_A_REGION', count, ierr)
|
||||
if (ierr == SPH_SUCCESS) call fail('invalid region count did not fail')
|
||||
call sph_coupling_export_region_particles('CONTACT_PARTICLES', 2, count, &
|
||||
ext_ids(1:2), internal_ids(1:2), phases(1:2), statuses(1:2), &
|
||||
materials(1:2), sections(1:2), scalars(:,1:2), &
|
||||
vectors(:,:,1:2), ierr)
|
||||
if (ierr == SPH_SUCCESS) call fail('small particle capacity did not fail')
|
||||
pressure(1) = huge(pressure(1))
|
||||
call sph_coupling_export_region_particles('CONTACT_PARTICLES', 3, count, &
|
||||
ext_ids, internal_ids, phases, statuses, materials, sections, &
|
||||
scalars, vectors, ierr)
|
||||
if (ierr == SPH_SUCCESS) call fail('nonfinite particle export did not fail')
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize failed after particle export errors')
|
||||
end subroutine check_particle_export_errors
|
||||
|
||||
subroutine build_contact_case()
|
||||
call sph_initialize(ierr)
|
||||
call assert_ok(ierr, 'initialize failed for contact export')
|
||||
call sph_read_inp('tests/data/coupling_region_080.inp', ierr)
|
||||
call assert_ok(ierr, 'read failed for contact export')
|
||||
call sph_build_model(ierr)
|
||||
call assert_ok(ierr, 'build failed for contact export')
|
||||
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_particle_export_080
|
||||
Reference in New Issue
Block a user