Implement coupling region input tables

This commit is contained in:
Codex
2026-07-04 08:49:35 +08:00
parent 1f5331ae21
commit 854b8042b2
18 changed files with 931 additions and 52 deletions
@@ -0,0 +1,69 @@
program test_coupling_region_build_080
use sph_precision, only: rk
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
use sph_blast, only: blast_region_count
use sph_gas, only: sph_gas_get_source_summary
use sph_database, only: coupling_region_count, coupling_region_internal_id, &
coupling_region_particle_count, coupling_region_disabled_count
implicit none
integer :: ierr
real(rk) :: gas_mass_source
real(rk) :: gas_energy_source
real(rk) :: gas_momentum_source(3)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for coupling region build')
call sph_read_inp('tests/data/coupling_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for coupling region build')
if (blast_region_count /= 0) call fail('coupling input polluted Blast regions')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for coupling region build')
if (coupling_region_count /= 3) call fail('runtime region count mismatch')
if (coupling_region_internal_id(1) /= 1) call fail('first internal id mismatch')
if (coupling_region_internal_id(2) /= 2) call fail('second internal id mismatch')
if (coupling_region_internal_id(3) /= 3) call fail('third internal id mismatch')
if (coupling_region_particle_count(1) /= 3) call fail('first runtime count mismatch')
if (coupling_region_particle_count(2) /= 3) call fail('second runtime count mismatch')
if (coupling_region_particle_count(3) /= 0) call fail('disabled runtime count mismatch')
if (coupling_region_disabled_count /= 1) call fail('runtime disabled count mismatch')
if (blast_region_count /= 0) call fail('coupling build polluted Blast regions')
call sph_gas_get_source_summary(gas_mass_source, gas_momentum_source, &
gas_energy_source, ierr)
call assert_ok(ierr, 'Gas source summary failed after coupling build')
call assert_close(gas_mass_source, 0.0_rk, 'Gas mass source was polluted')
call assert_close(gas_energy_source, 0.0_rk, 'Gas energy source was polluted')
call assert_close(maxval(abs(gas_momentum_source)), 0.0_rk, &
'Gas momentum source was polluted')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for coupling region build')
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_region_build_080
@@ -0,0 +1,49 @@
program test_input_coupling_errors_080
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_region_bad_name_080.inp')
call expect_fails('tests/data/coupling_region_bad_duplicate_080.inp')
call expect_fails('tests/data/coupling_region_bad_type_080.inp')
call expect_fails('tests/data/coupling_region_bad_export_080.inp')
call expect_fails('tests/data/coupling_region_bad_import_080.inp')
call expect_fails('tests/data/coupling_region_bad_enabled_080.inp')
call expect_fails('tests/data/coupling_region_missing_set_080.inp')
call expect_fails('tests/data/coupling_region_unknown_set_080.inp')
call expect_fails('tests/data/coupling_region_empty_active_080.inp')
call expect_fails('tests/data/coupling_region_continuum_active_080.inp')
contains
subroutine expect_fails(filename)
character(len=*), intent(in) :: filename
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for failing coupling input')
call sph_read_inp(filename, ierr)
if (ierr == SPH_SUCCESS) then
call sph_build_model(ierr)
if (ierr == SPH_SUCCESS) call fail('coupling input unexpectedly built')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after failing 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_errors_080
@@ -0,0 +1,152 @@
program test_input_coupling_region_080
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_set_name, coupling_region_surface_name, &
coupling_region_type, coupling_region_export_mode, &
coupling_region_import_mode, coupling_region_enabled, &
coupling_region_phase_filter, coupling_region_material_filter, &
coupling_region_section_filter, coupling_region_particle_count, &
coupling_region_particles, coupling_region_disabled_count, &
SPH_REGION_COUPLING_CONTACT, SPH_REGION_COUPLING_CONTINUUM, &
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_PHASE_SOLID
implicit none
integer :: ierr
call check_contact_regions()
call check_legacy_continuum_compatibility()
contains
subroutine check_contact_regions()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for coupling region input')
call sph_read_inp('tests/data/coupling_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for coupling region input')
if (coupling_region_count /= 3) call fail('coupling region count mismatch')
call assert_region_name(1, 'CONTACT_PARTICLES')
call assert_region_name(2, 'CONTACT_FACETS')
call assert_region_name(3, 'CONTACT_DISABLED')
call assert_string(coupling_region_set_name(1), 'SOLID_A', &
'first coupling set mismatch')
call assert_string(coupling_region_set_name(2), 'SOLID_B', &
'second coupling set mismatch')
call assert_string(coupling_region_surface_name(2), 'PANEL_SURFACE', &
'facet surface placeholder mismatch')
call assert_string(coupling_region_surface_name(3), 'DISABLED_SURFACE', &
'disabled surface placeholder mismatch')
if (coupling_region_type(1) /= SPH_REGION_COUPLING_CONTACT) then
call fail('first coupling type mismatch')
end if
if (coupling_region_export_mode(1) /= SPH_COUPLING_EXPORT_PARTICLE) then
call fail('particle export mode mismatch')
end if
if (coupling_region_export_mode(2) /= SPH_COUPLING_EXPORT_FACET) then
call fail('facet export mode mismatch')
end if
if (coupling_region_export_mode(3) /= SPH_COUPLING_EXPORT_BOTH) then
call fail('combined export mode mismatch')
end if
if (coupling_region_import_mode(1) /= SPH_COUPLING_IMPORT_FORCE) then
call fail('force import mode mismatch')
end if
if (coupling_region_import_mode(2) /= SPH_COUPLING_IMPORT_FACET_LOAD) then
call fail('facet load import mode mismatch')
end if
if (coupling_region_import_mode(3) /= SPH_COUPLING_IMPORT_MOTION) then
call fail('motion import mode mismatch')
end if
if (coupling_region_enabled(1) /= 1) call fail('enabled flag mismatch')
if (coupling_region_enabled(2) /= 1) call fail('second enabled flag mismatch')
if (coupling_region_enabled(3) /= 0) call fail('disabled flag mismatch')
if (coupling_region_phase_filter(1) /= SPH_PHASE_SOLID) then
call fail('phase filter mismatch')
end if
if (coupling_region_material_filter(1) <= 0) then
call fail('material filter was not resolved')
end if
if (coupling_region_section_filter(1) <= 0) then
call fail('section filter was not resolved')
end if
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for coupling region input')
if (coupling_region_disabled_count /= 1) then
call fail('disabled coupling region count mismatch')
end if
if (coupling_region_particle_count(1) /= 3) then
call fail('first active coupling particle count mismatch')
end if
if (coupling_region_particle_count(2) /= 3) then
call fail('second active coupling particle count mismatch')
end if
if (coupling_region_particle_count(3) /= 0) then
call fail('disabled coupling region exported particles')
end if
if (coupling_region_particles(1,1) /= 1) call fail('first particle index mismatch')
if (coupling_region_particles(3,1) /= 3) call fail('third particle index mismatch')
if (coupling_region_particles(1,2) /= 4) call fail('fourth particle index mismatch')
if (coupling_region_particles(3,2) /= 6) call fail('sixth particle index mismatch')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for coupling region input')
end subroutine check_contact_regions
subroutine check_legacy_continuum_compatibility()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for legacy continuum input')
call sph_read_inp('tests/data/coupling_region_011.inp', ierr)
call assert_ok(ierr, 'read failed for legacy continuum input')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for legacy continuum input')
if (coupling_region_count /= 1) call fail('legacy continuum region missing')
if (coupling_region_type(1) /= SPH_REGION_COUPLING_CONTINUUM) then
call fail('legacy continuum type mismatch')
end if
if (coupling_region_enabled(1) /= 0) then
call fail('legacy continuum region should stay disabled')
end if
if (coupling_region_disabled_count /= 1) then
call fail('legacy continuum disabled count mismatch')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for legacy continuum input')
end subroutine check_legacy_continuum_compatibility
subroutine assert_region_name(index, expected)
integer, intent(in) :: index
character(len=*), intent(in) :: expected
call assert_string(coupling_region_name(index), expected, &
'coupling region name mismatch')
end subroutine assert_region_name
subroutine assert_string(actual, expected, message)
character(len=*), intent(in) :: actual
character(len=*), intent(in) :: expected
character(len=*), intent(in) :: message
if (trim(actual) /= trim(expected)) call fail(message)
end subroutine assert_string
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_region_080