Add 0.8.1 coupling load mode input

This commit is contained in:
Codex
2026-07-04 10:46:05 +08:00
parent 89cce9a974
commit d606be2b75
13 changed files with 580 additions and 40 deletions
@@ -0,0 +1,71 @@
program test_coupling_contact_state_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
use sph_database, only: npart
use sph_coupling_interface, only: sph_coupling_clear_imports, &
coupling_contact_flag, coupling_contact_normal, coupling_contact_gap, &
coupling_contact_penetration, coupling_contact_pressure
implicit none
integer :: ierr
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for contact state cache')
call sph_read_inp('tests/data/coupling_load_mode_081.inp', ierr)
call assert_ok(ierr, 'read failed for contact state cache')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for contact state cache')
if (npart /= 4) call fail('contact cache particle count mismatch')
call assert_contact_cache_zero('build initialized contact cache')
coupling_contact_flag(1) = 1
coupling_contact_normal(:,1) = (/ 0.0_rk, 0.0_rk, 1.0_rk /)
coupling_contact_gap(1) = 1.0e-4_rk
coupling_contact_penetration(1) = 2.0e-4_rk
coupling_contact_pressure(1) = 3.0_rk
call sph_coupling_clear_imports(ierr)
call assert_ok(ierr, 'clear imports failed for contact cache')
call assert_contact_cache_zero('clear imports did not reset contact cache')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for contact state cache')
contains
subroutine assert_contact_cache_zero(message)
character(len=*), intent(in) :: message
if (.not. allocated(coupling_contact_flag)) call fail('contact flag cache not allocated')
if (.not. allocated(coupling_contact_normal)) call fail('contact normal cache not allocated')
if (.not. allocated(coupling_contact_gap)) call fail('contact gap cache not allocated')
if (.not. allocated(coupling_contact_penetration)) call fail('contact penetration cache not allocated')
if (.not. allocated(coupling_contact_pressure)) call fail('contact pressure cache not allocated')
if (size(coupling_contact_flag) /= npart) call fail('contact flag cache size mismatch')
if (size(coupling_contact_normal,1) /= SPH_NDIM .or. &
size(coupling_contact_normal,2) /= npart) then
call fail('contact normal cache size mismatch')
end if
if (maxval(abs(coupling_contact_flag)) /= 0) call fail(message)
if (maxval(abs(coupling_contact_normal)) > 0.0_rk) call fail(message)
if (maxval(abs(coupling_contact_gap)) > 0.0_rk) call fail(message)
if (maxval(abs(coupling_contact_penetration)) > 0.0_rk) call fail(message)
if (maxval(abs(coupling_contact_pressure)) > 0.0_rk) call fail(message)
end subroutine assert_contact_cache_zero
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_contact_state_081
@@ -0,0 +1,43 @@
program test_input_coupling_load_errors_081
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
implicit none
integer :: ierr
call expect_fails('tests/data/coupling_load_bad_mode_081.inp')
call expect_fails('tests/data/coupling_load_bad_distribution_081.inp')
call expect_fails('tests/data/coupling_load_bad_contact_state_081.inp')
call expect_fails('tests/data/coupling_load_missing_facet_081.inp')
contains
subroutine expect_fails(filename)
character(len=*), intent(in) :: filename
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for failing 0.8.1 coupling input')
call sph_read_inp(filename, ierr)
if (ierr == SPH_SUCCESS) then
call sph_build_model(ierr)
if (ierr == SPH_SUCCESS) call fail('0.8.1 coupling input unexpectedly built')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after failing 0.8.1 coupling input')
end subroutine expect_fails
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_input_coupling_load_errors_081
@@ -0,0 +1,140 @@
program test_input_coupling_load_mode_081
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
use sph_database, only: coupling_region_count, coupling_region_name, &
coupling_region_export_mode, coupling_region_import_mode, &
coupling_region_load_mode, coupling_region_distribution_mode, &
coupling_region_contact_state_mode, coupling_region_enabled, &
coupling_region_particle_count, coupling_region_disabled_count, &
SPH_COUPLING_EXPORT_PARTICLE, SPH_COUPLING_EXPORT_FACET, &
SPH_COUPLING_EXPORT_BOTH, SPH_COUPLING_IMPORT_FORCE, &
SPH_COUPLING_IMPORT_FACET_LOAD, SPH_COUPLING_IMPORT_MOTION, &
SPH_COUPLING_LOAD_PARTICLE_FORCE, SPH_COUPLING_LOAD_FACET_FORCE, &
SPH_COUPLING_LOAD_PRESSURE, SPH_COUPLING_LOAD_TRACTION, &
SPH_COUPLING_DISTRIBUTION_UNIFORM, SPH_COUPLING_DISTRIBUTION_AREA, &
SPH_COUPLING_DISTRIBUTION_MASS, SPH_COUPLING_CONTACT_STATE_NONE, &
SPH_COUPLING_CONTACT_STATE_IMPORT
implicit none
integer :: ierr
call check_081_load_modes()
call check_080_defaults()
contains
subroutine check_081_load_modes()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for 0.8.1 load modes')
call sph_read_inp('tests/data/coupling_load_mode_081.inp', ierr)
call assert_ok(ierr, 'read failed for 0.8.1 load modes')
if (coupling_region_count /= 3) call fail('0.8.1 coupling region count mismatch')
call assert_name(1, 'PRESSURE_CONTACT')
call assert_name(2, 'TRACTION_CONTACT')
call assert_name(3, 'DISABLED_PRESSURE')
if (coupling_region_export_mode(1) /= SPH_COUPLING_EXPORT_FACET) then
call fail('pressure export mode mismatch')
end if
if (coupling_region_export_mode(2) /= SPH_COUPLING_EXPORT_BOTH) then
call fail('traction export mode mismatch')
end if
if (coupling_region_export_mode(3) /= SPH_COUPLING_EXPORT_PARTICLE) then
call fail('disabled export mode mismatch')
end if
if (coupling_region_import_mode(1) /= SPH_COUPLING_IMPORT_FACET_LOAD) then
call fail('pressure import mode mismatch')
end if
if (coupling_region_load_mode(1) /= SPH_COUPLING_LOAD_PRESSURE) then
call fail('pressure load mode mismatch')
end if
if (coupling_region_load_mode(2) /= SPH_COUPLING_LOAD_TRACTION) then
call fail('traction load mode mismatch')
end if
if (coupling_region_load_mode(3) /= SPH_COUPLING_LOAD_PRESSURE) then
call fail('disabled load mode was not preserved')
end if
if (coupling_region_distribution_mode(1) /= SPH_COUPLING_DISTRIBUTION_AREA) then
call fail('pressure distribution mismatch')
end if
if (coupling_region_distribution_mode(2) /= SPH_COUPLING_DISTRIBUTION_MASS) then
call fail('traction distribution mismatch')
end if
if (coupling_region_distribution_mode(3) /= SPH_COUPLING_DISTRIBUTION_UNIFORM) then
call fail('disabled distribution mismatch')
end if
if (coupling_region_contact_state_mode(1) /= SPH_COUPLING_CONTACT_STATE_IMPORT) then
call fail('pressure contact state mismatch')
end if
if (coupling_region_contact_state_mode(2) /= SPH_COUPLING_CONTACT_STATE_IMPORT) then
call fail('traction contact state mismatch')
end if
if (coupling_region_enabled(3) /= 0) call fail('disabled flag mismatch')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for 0.8.1 load modes')
if (coupling_region_particle_count(1) /= 3) call fail('pressure runtime count mismatch')
if (coupling_region_particle_count(2) /= 3) call fail('traction runtime count mismatch')
if (coupling_region_particle_count(3) /= 0) call fail('disabled region exported particles')
if (coupling_region_disabled_count /= 1) call fail('disabled count mismatch')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for 0.8.1 load modes')
end subroutine check_081_load_modes
subroutine check_080_defaults()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for 0.8.0 defaults')
call sph_read_inp('tests/data/coupling_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for 0.8.0 defaults')
if (coupling_region_import_mode(1) /= SPH_COUPLING_IMPORT_FORCE) then
call fail('0.8.0 force import mode mismatch')
end if
if (coupling_region_load_mode(1) /= SPH_COUPLING_LOAD_PARTICLE_FORCE) then
call fail('0.8.0 force load default mismatch')
end if
if (coupling_region_import_mode(2) /= SPH_COUPLING_IMPORT_FACET_LOAD) then
call fail('0.8.0 facet import mode mismatch')
end if
if (coupling_region_load_mode(2) /= SPH_COUPLING_LOAD_FACET_FORCE) then
call fail('0.8.0 facet load default mismatch')
end if
if (coupling_region_import_mode(3) /= SPH_COUPLING_IMPORT_MOTION) then
call fail('0.8.0 motion import mode mismatch')
end if
if (coupling_region_load_mode(3) /= SPH_COUPLING_LOAD_PARTICLE_FORCE) then
call fail('0.8.0 motion load default mismatch')
end if
if (maxval(coupling_region_distribution_mode(1:3)) /= &
SPH_COUPLING_DISTRIBUTION_UNIFORM) then
call fail('0.8.0 distribution default mismatch')
end if
if (maxval(coupling_region_contact_state_mode(1:3)) /= &
SPH_COUPLING_CONTACT_STATE_NONE) then
call fail('0.8.0 contact state default mismatch')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for 0.8.0 defaults')
end subroutine check_080_defaults
subroutine assert_name(index, expected)
integer, intent(in) :: index
character(len=*), intent(in) :: expected
if (trim(coupling_region_name(index)) /= trim(expected)) call fail('region name mismatch')
end subroutine assert_name
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_input_coupling_load_mode_081