Apply coupling imports in explicit step

This commit is contained in:
Codex
2026-07-04 09:22:46 +08:00
parent 788508a465
commit 5be6b178bc
11 changed files with 1195 additions and 46 deletions
+49
View File
@@ -0,0 +1,49 @@
*NODE
1, 0.00, 0.0, 0.0
2, 0.08, 0.0, 0.0
3, 0.30, 0.0, 0.0
4, 0.36, 0.0, 0.0
5, 0.52, 0.0, 0.0
6, 0.60, 0.0, 0.0
*ELEMENT, TYPE=SPH3D
1, 1
2, 2
3, 3
4, 4
5, 5
6, 6
*ELSET, ELSET=WATER_PARTICLES
1, 2
*ELSET, ELSET=CHARGE_PARTICLES
3
*ELSET, ELSET=PRODUCT_PARTICLES
4
*ELSET, ELSET=SOLID_TARGET
5, 6
*MATERIAL, NAME=WATER, TYPE=WATER
*DENSITY
1000.0
*SECTION, ELSET=WATER_PARTICLES, MATERIAL=WATER
*MATERIAL, NAME=TNT, TYPE=EXPLOSIVE
*DENSITY
1600.0
*SECTION, ELSET=CHARGE_PARTICLES, MATERIAL=TNT
*MATERIAL, NAME=PRODUCTS, TYPE=GAS
*DENSITY
1600.0
*SECTION, ELSET=PRODUCT_PARTICLES, MATERIAL=PRODUCTS
*MATERIAL, NAME=STEEL_SOLID, TYPE=SOLID
*DENSITY
7850.0
*ELASTIC
210.0E9, 0.30
*SOLID SECTION, ELSET=SOLID_TARGET, MATERIAL=STEEL_SOLID
*SPHLITE EOS, TYPE=TAIT, MATERIAL=WATER, RHO0=1000.0, C0=1480.0, GAMMA=7.0, P0=0.0
*SPHLITE VISCOSITY, TYPE=MONAGHAN, MATERIAL=WATER, ALPHA=0.1, BETA=0.0, ETA2=0.01
*SPHLITE EOS, TYPE=JWL, MATERIAL=PRODUCTS, RHO0=1600.0, A=3.712E11, B=3.231E9, R1=4.15, R2=0.95, OMEGA=0.3, E0=4.2E6
*SPHLITE EXPLOSIVE, MATERIAL=TNT, TYPE=PROGRAMMED_BURN, DETONATION_VELOCITY=6900.0, ENERGY=4.2E6, BURN_TIME=1.0E-7, PRODUCT_MATERIAL=PRODUCTS, CONVERSION=SOURCE
*SPHLITE IGNITION, MATERIAL=TNT, X=0.30, Y=0.0, Z=0.0, TIME=0.0
*SPHLITE BLAST REGION, NAME=LOCAL_BLAST, X=0.30, Y=0.0, Z=0.0, RADIUS=0.45, SOURCE_PHASE=GAS, TARGET_PHASE=SOLID, TARGET_SET=SOLID_TARGET, SCALE=1.0, TIME_WINDOW=2.0E-7, MODE=RADIAL
*SPHLITE PARTICLE CONTROL, H=0.12, MASS=0.02, VOLUME=1.25E-5
*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=2.0E-7, STEPS=2, SAFETY=0.5
*SPHLITE COUPLING REGION, NAME=COUPLED_SOLID, SET=SOLID_TARGET, TYPE=CONTACT, EXPORT=PARTICLE, IMPORT=FORCE, ENABLED=YES, PHASE=SOLID, MATERIAL=STEEL_SOLID, SECTION=SOLID_TARGET
+17
View File
@@ -0,0 +1,17 @@
*NODE
1, 0.0, 0.0, 0.0
2, 0.1, 0.0, 0.0
*ELEMENT, TYPE=SPH3D
1, 1
2, 2
*ELSET, ELSET=SOLID_TARGET
1, 2
*MATERIAL, NAME=STEEL, TYPE=SOLID
*DENSITY
7850.0
*ELASTIC
210.0E9, 0.30
*SOLID SECTION, ELSET=SOLID_TARGET, MATERIAL=STEEL
*SPHLITE PARTICLE CONTROL, H=0.15, MASS=1.0, VOLUME=0.001
*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5
*SPHLITE COUPLING REGION, NAME=DISABLED_ONLY, SET=SOLID_TARGET, TYPE=CONTACT, EXPORT=BOTH, IMPORT=MOTION, ENABLED=NO, PHASE=SOLID, MATERIAL=STEEL, SECTION=SOLID_TARGET
@@ -0,0 +1,236 @@
program test_coupling_diagnostics_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, sph_advance_explicit
use sph_database, only: x, v, mass
use sph_coupling_interface, only: coupling_external_force, &
coupling_motion_flag, SPH_COUPLING_MOTION_DIRECT, &
sph_coupling_import_force_by_region_index, &
sph_coupling_import_force_by_external_id, &
sph_coupling_import_motion_velocity, &
sph_coupling_import_motion_position, &
sph_coupling_get_extended_diagnostics
implicit none
integer :: ierr
call check_structural_diagnostics()
call check_water_force_path()
call check_gas_force_path()
contains
subroutine check_structural_diagnostics()
real(rk), parameter :: dt = 1.0e-7_rk
real(rk) :: force(SPH_NDIM)
real(rk) :: target_velocity(SPH_NDIM)
real(rk) :: target_position(SPH_NDIM)
real(rk) :: total_force(SPH_NDIM)
real(rk) :: total_moment(SPH_NDIM)
real(rk) :: current_impulse(SPH_NDIM)
real(rk) :: cumulative_impulse(SPH_NDIM)
real(rk) :: momentum_exchange(SPH_NDIM)
real(rk) :: current_work
real(rk) :: cumulative_work
real(rk) :: energy_exchange
real(rk) :: max_force
real(rk) :: max_acceleration
real(rk) :: max_velocity_error
real(rk) :: max_position_error
integer :: stale_count
integer :: skipped_count
integer :: nonfinite_count
integer :: imported_force_count
integer :: step_load_consumed
call build_contact_case()
v(:,2) = (/0.0_rk, 0.0_rk, 0.5_rk/)
force = (/0.0_rk, 0.0_rk, 10.0_rk/)
call sph_coupling_import_force_by_region_index('CONTACT_PARTICLES', 2, &
force, ierr)
call assert_ok(ierr, 'diagnostic force import failed')
target_velocity = (/0.0_rk, 1.0_rk, 0.0_rk/)
call sph_coupling_import_motion_velocity('CONTACT_PARTICLES', 1, &
SPH_COUPLING_MOTION_DIRECT, target_velocity, ierr)
call assert_ok(ierr, 'diagnostic velocity import failed')
target_position = (/0.0_rk, 0.0_rk, 0.2_rk/)
call sph_coupling_import_motion_position('CONTACT_PARTICLES', 3, &
SPH_COUPLING_MOTION_DIRECT, target_position, ierr)
call assert_ok(ierr, 'diagnostic position import failed')
call sph_advance_explicit(dt, ierr)
call assert_ok(ierr, 'diagnostic advance failed')
call sph_coupling_get_extended_diagnostics(total_force, total_moment, &
current_impulse, cumulative_impulse, current_work, cumulative_work, &
momentum_exchange, energy_exchange, max_force, max_acceleration, &
max_velocity_error, max_position_error, stale_count, skipped_count, &
nonfinite_count, imported_force_count, step_load_consumed, ierr)
call assert_ok(ierr, 'extended diagnostics failed')
call assert_vector_close(total_force, force, 'current force mismatch')
call assert_close(total_moment(2), -1.0_rk, 'current moment mismatch')
call assert_vector_close(current_impulse, force * dt, &
'current impulse mismatch')
call assert_vector_close(cumulative_impulse, force * dt, &
'cumulative impulse mismatch')
call assert_vector_close(momentum_exchange, force * dt, &
'momentum exchange mismatch')
if (current_work <= 0.0_rk) call fail('current work was not positive')
call assert_close(cumulative_work, current_work, 'cumulative work mismatch')
call assert_close(energy_exchange, current_work, 'energy exchange mismatch')
if (max_force <= 0.0_rk) call fail('max force diagnostic missing')
if (max_acceleration <= 0.0_rk) call fail('max acceleration diagnostic missing')
if (max_velocity_error <= 0.0_rk) call fail('velocity error diagnostic missing')
if (max_position_error <= 0.0_rk) call fail('position error diagnostic missing')
if (stale_count /= 0) call fail('unexpected stale count')
if (skipped_count /= 0) call fail('unexpected skipped count')
if (nonfinite_count /= 0) call fail('unexpected nonfinite count')
if (step_load_consumed /= 1) call fail('step load was not consumed')
if (maxval(abs(coupling_external_force)) > 0.0_rk) then
call fail('force cache was not consumed')
end if
if (maxval(coupling_motion_flag) /= 0) then
call fail('motion cache was not consumed')
end if
call assert_vector_close(v(:,1), target_velocity, &
'target velocity was not enforced')
call assert_vector_close(x(:,3), target_position, &
'target position was not enforced')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after structural diagnostics')
end subroutine check_structural_diagnostics
subroutine check_water_force_path()
real(rk) :: force(SPH_NDIM)
real(rk) :: total_force(SPH_NDIM)
real(rk) :: total_moment(SPH_NDIM)
real(rk) :: current_impulse(SPH_NDIM)
real(rk) :: cumulative_impulse(SPH_NDIM)
real(rk) :: momentum_exchange(SPH_NDIM)
real(rk) :: current_work
real(rk) :: cumulative_work
real(rk) :: energy_exchange
real(rk) :: max_force
real(rk) :: max_acceleration
real(rk) :: max_velocity_error
real(rk) :: max_position_error
integer :: stale_count
integer :: skipped_count
integer :: nonfinite_count
integer :: imported_force_count
integer :: step_load_consumed
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Water force path')
call sph_read_inp('tests/data/water_minimal_021.inp', ierr)
call assert_ok(ierr, 'read failed for Water force path')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Water force path')
force = (/0.0_rk, 0.0_rk, mass(1)/1.0e-6_rk/)
call sph_coupling_import_force_by_external_id(1, force, ierr)
call assert_ok(ierr, 'Water coupling force import failed')
call sph_advance_explicit(1.0e-6_rk, ierr)
call assert_ok(ierr, 'Water force advance failed')
if (v(3,1) <= 0.0_rk) call fail('Water coupling force did not move particle')
call sph_coupling_get_extended_diagnostics(total_force, total_moment, &
current_impulse, cumulative_impulse, current_work, cumulative_work, &
momentum_exchange, energy_exchange, max_force, max_acceleration, &
max_velocity_error, max_position_error, stale_count, skipped_count, &
nonfinite_count, imported_force_count, step_load_consumed, ierr)
call assert_ok(ierr, 'Water diagnostics failed')
call assert_close(total_force(3), force(3), 'Water force diagnostic mismatch')
if (step_load_consumed /= 1) call fail('Water coupling load not consumed')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Water force path')
end subroutine check_water_force_path
subroutine check_gas_force_path()
real(rk) :: force(SPH_NDIM)
real(rk) :: total_force(SPH_NDIM)
real(rk) :: total_moment(SPH_NDIM)
real(rk) :: current_impulse(SPH_NDIM)
real(rk) :: cumulative_impulse(SPH_NDIM)
real(rk) :: momentum_exchange(SPH_NDIM)
real(rk) :: current_work
real(rk) :: cumulative_work
real(rk) :: energy_exchange
real(rk) :: max_force
real(rk) :: max_acceleration
real(rk) :: max_velocity_error
real(rk) :: max_position_error
integer :: stale_count
integer :: skipped_count
integer :: nonfinite_count
integer :: imported_force_count
integer :: step_load_consumed
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Gas force path')
call sph_read_inp('tests/data/gas_air_ideal_031.inp', ierr)
call assert_ok(ierr, 'read failed for Gas force path')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Gas force path')
force = (/0.0_rk, 0.0_rk, mass(1)/1.0e-6_rk/)
call sph_coupling_import_force_by_external_id(1, force, ierr)
call assert_ok(ierr, 'Gas coupling force import failed')
call sph_advance_explicit(1.0e-6_rk, ierr)
call assert_ok(ierr, 'Gas force advance failed')
if (v(3,1) <= 0.0_rk) call fail('Gas coupling force did not move particle')
call sph_coupling_get_extended_diagnostics(total_force, total_moment, &
current_impulse, cumulative_impulse, current_work, cumulative_work, &
momentum_exchange, energy_exchange, max_force, max_acceleration, &
max_velocity_error, max_position_error, stale_count, skipped_count, &
nonfinite_count, imported_force_count, step_load_consumed, ierr)
call assert_ok(ierr, 'Gas diagnostics failed')
call assert_close(total_force(3), force(3), 'Gas force diagnostic mismatch')
if (step_load_consumed /= 1) call fail('Gas coupling load not consumed')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Gas force path')
end subroutine check_gas_force_path
subroutine build_contact_case()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for diagnostics')
call sph_read_inp('tests/data/coupling_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for diagnostics')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for diagnostics')
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) > max(1.0e-10_rk, abs(expected) * 1.0e-8_rk)) then
call fail(message)
end if
end subroutine assert_close
subroutine assert_vector_close(actual, expected, message)
real(rk), intent(in) :: actual(SPH_NDIM)
real(rk), intent(in) :: expected(SPH_NDIM)
character(len=*), intent(in) :: message
integer :: i
do i = 1, SPH_NDIM
call assert_close(actual(i), expected(i), message)
end do
end subroutine assert_vector_close
subroutine fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_coupling_diagnostics_080
@@ -0,0 +1,152 @@
program test_coupling_noop_regression_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, sph_advance_explicit
use sph_database, only: a, v, coupling_region_disabled_count
use sph_coupling_interface, only: coupling_external_force, &
coupling_motion_flag, sph_coupling_get_extended_diagnostics
implicit none
integer :: ierr
call check_single_phase_noop('tests/data/water_minimal_021.inp', 'Water-only')
call check_single_phase_noop('tests/data/gas_air_ideal_031.inp', 'Gas-only')
call check_single_phase_noop('tests/data/explosive_minimal_040.inp', &
'Explosive-only')
call check_single_phase_noop('tests/data/solid_elastic_minimal_050.inp', &
'Solid-only')
call check_single_phase_noop('tests/data/shell_minimal_060.inp', 'Shell-only')
call check_active_region_empty_import()
call check_disabled_region_noop()
contains
subroutine check_single_phase_noop(filename, label)
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: label
call sph_initialize(ierr)
call assert_ok(ierr, trim(label) // ' initialize failed')
call sph_read_inp(filename, ierr)
call assert_ok(ierr, trim(label) // ' read failed')
call sph_build_model(ierr)
call assert_ok(ierr, trim(label) // ' build failed')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, trim(label) // ' advance failed')
call assert_no_coupling_load(trim(label))
call sph_finalize(ierr)
call assert_ok(ierr, trim(label) // ' finalize failed')
end subroutine check_single_phase_noop
subroutine check_active_region_empty_import()
real(rk) :: velocity_before(SPH_NDIM)
call sph_initialize(ierr)
call assert_ok(ierr, 'active empty initialize failed')
call sph_read_inp('tests/data/coupling_region_080.inp', ierr)
call assert_ok(ierr, 'active empty read failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'active empty build failed')
velocity_before = v(:,1)
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'active empty advance failed')
call assert_no_coupling_load('active empty import')
if (maxval(abs(v(:,1) - velocity_before)) > 1.0e-12_rk .and. &
maxval(abs(a(:,1))) > 0.0_rk) then
call fail('empty Coupling import produced structural acceleration')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'active empty finalize failed')
end subroutine check_active_region_empty_import
subroutine check_disabled_region_noop()
call sph_initialize(ierr)
call assert_ok(ierr, 'disabled noop initialize failed')
call sph_read_inp('tests/data/coupling_disabled_only_080.inp', ierr)
call assert_ok(ierr, 'disabled noop read failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'disabled noop build failed')
if (coupling_region_disabled_count <= 0) call fail('disabled region missing')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'disabled noop advance failed')
call assert_no_coupling_load('disabled region')
call sph_finalize(ierr)
call assert_ok(ierr, 'disabled noop finalize failed')
end subroutine check_disabled_region_noop
subroutine assert_no_coupling_load(label)
character(len=*), intent(in) :: label
real(rk) :: total_force(SPH_NDIM)
real(rk) :: total_moment(SPH_NDIM)
real(rk) :: current_impulse(SPH_NDIM)
real(rk) :: cumulative_impulse(SPH_NDIM)
real(rk) :: momentum_exchange(SPH_NDIM)
real(rk) :: current_work
real(rk) :: cumulative_work
real(rk) :: energy_exchange
real(rk) :: max_force
real(rk) :: max_acceleration
real(rk) :: max_velocity_error
real(rk) :: max_position_error
integer :: stale_count
integer :: skipped_count
integer :: nonfinite_count
integer :: imported_force_count
integer :: step_load_consumed
call sph_coupling_get_extended_diagnostics(total_force, total_moment, &
current_impulse, cumulative_impulse, current_work, cumulative_work, &
momentum_exchange, energy_exchange, max_force, max_acceleration, &
max_velocity_error, max_position_error, stale_count, skipped_count, &
nonfinite_count, imported_force_count, step_load_consumed, ierr)
call assert_ok(ierr, trim(label) // ' diagnostics failed')
if (maxval(abs(total_force)) > 0.0_rk) then
call fail(trim(label) // ' reported Coupling force')
end if
if (maxval(abs(total_moment)) > 0.0_rk) then
call fail(trim(label) // ' reported Coupling moment')
end if
if (maxval(abs(current_impulse)) > 0.0_rk) then
call fail(trim(label) // ' reported Coupling impulse')
end if
if (max_force > 0.0_rk .or. max_acceleration > 0.0_rk) then
call fail(trim(label) // ' reported Coupling acceleration')
end if
if (max_velocity_error > 0.0_rk .or. max_position_error > 0.0_rk) then
call fail(trim(label) // ' reported Coupling motion error')
end if
if (stale_count /= 0 .or. skipped_count /= 0 .or. &
nonfinite_count /= 0) then
call fail(trim(label) // ' changed Coupling counters')
end if
if (step_load_consumed /= 0) then
call fail(trim(label) // ' consumed empty Coupling load')
end if
if (allocated(coupling_external_force)) then
if (maxval(abs(coupling_external_force)) > 0.0_rk) then
call fail(trim(label) // ' left Coupling force cache')
end if
end if
if (allocated(coupling_motion_flag)) then
if (maxval(coupling_motion_flag) /= 0) then
call fail(trim(label) // ' left Coupling motion cache')
end if
end if
end subroutine assert_no_coupling_load
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_noop_regression_080
@@ -0,0 +1,99 @@
program test_coupling_shell_response_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, sph_advance_explicit
use sph_database, only: a, v, mass
use sph_shell, only: shell_director, shell_omega
use sph_coupling_interface, only: &
sph_coupling_import_region_facet_load, &
sph_coupling_get_extended_diagnostics
implicit none
integer :: ierr
call check_shell_facet_response()
contains
subroutine check_shell_facet_response()
real(rk) :: load(SPH_NDIM)
real(rk) :: director_before(SPH_NDIM)
real(rk) :: omega_before(SPH_NDIM)
real(rk) :: total_force(SPH_NDIM)
real(rk) :: total_moment(SPH_NDIM)
real(rk) :: current_impulse(SPH_NDIM)
real(rk) :: cumulative_impulse(SPH_NDIM)
real(rk) :: momentum_exchange(SPH_NDIM)
real(rk) :: current_work
real(rk) :: cumulative_work
real(rk) :: energy_exchange
real(rk) :: max_force
real(rk) :: max_acceleration
real(rk) :: max_velocity_error
real(rk) :: max_position_error
integer :: stale_count
integer :: skipped_count
integer :: nonfinite_count
integer :: imported_force_count
integer :: step_load_consumed
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Shell response')
call sph_read_inp('tests/data/coupling_shell_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for Shell response')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Shell response')
director_before = shell_director(:,1)
omega_before = shell_omega(:,1)
load = (/0.0_rk, 0.0_rk, mass(1) * 1.0e8_rk/)
call sph_coupling_import_region_facet_load('SHELL_FACETS', 1, load, ierr)
call assert_ok(ierr, 'Shell facet load import failed')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'Shell force advance failed')
if (a(3,1) <= 0.0_rk) call fail('Shell coupling acceleration missing')
if (v(3,1) <= 0.0_rk) call fail('Shell coupling velocity missing')
if (maxval(abs(shell_director(:,1) - director_before)) > 1.0e-12_rk) then
call fail('Shell director changed through Coupling force path')
end if
if (maxval(abs(shell_omega(:,1) - omega_before)) > 1.0e-12_rk) then
call fail('Shell rotation state changed through Coupling force path')
end if
call sph_coupling_get_extended_diagnostics(total_force, total_moment, &
current_impulse, cumulative_impulse, current_work, cumulative_work, &
momentum_exchange, energy_exchange, max_force, max_acceleration, &
max_velocity_error, max_position_error, stale_count, skipped_count, &
nonfinite_count, imported_force_count, step_load_consumed, ierr)
call assert_ok(ierr, 'Shell diagnostics failed')
call assert_close(total_force(3), load(3), 'Shell force diagnostic mismatch')
if (max_acceleration <= 0.0_rk) call fail('Shell max acceleration missing')
if (step_load_consumed /= 1) call fail('Shell load not consumed')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Shell response')
end subroutine check_shell_facet_response
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) > max(1.0e-10_rk, abs(expected) * 1.0e-8_rk)) then
call fail(message)
end if
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_shell_response_080
@@ -0,0 +1,111 @@
program test_coupling_solid_response_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, sph_advance_explicit
use sph_database, only: a, v, mass, particle_status, SPH_STATUS_INACTIVE
use sph_coupling_interface, only: coupling_skipped_particle_count, &
sph_coupling_import_force_by_region_index, &
sph_coupling_get_extended_diagnostics
implicit none
integer :: ierr
call check_solid_force_response()
call check_apply_skip_after_import()
contains
subroutine check_solid_force_response()
real(rk) :: force(SPH_NDIM)
real(rk) :: total_force(SPH_NDIM)
real(rk) :: total_moment(SPH_NDIM)
real(rk) :: current_impulse(SPH_NDIM)
real(rk) :: cumulative_impulse(SPH_NDIM)
real(rk) :: momentum_exchange(SPH_NDIM)
real(rk) :: current_work
real(rk) :: cumulative_work
real(rk) :: energy_exchange
real(rk) :: max_force
real(rk) :: max_acceleration
real(rk) :: max_velocity_error
real(rk) :: max_position_error
integer :: stale_count
integer :: skipped_count
integer :: nonfinite_count
integer :: imported_force_count
integer :: step_load_consumed
call build_contact_case()
force = (/0.0_rk, 0.0_rk, mass(1) * 1.0e8_rk/)
call sph_coupling_import_force_by_region_index('CONTACT_PARTICLES', 1, &
force, ierr)
call assert_ok(ierr, 'Solid force import failed')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'Solid force advance failed')
if (a(3,1) <= 0.0_rk) call fail('Solid coupling acceleration missing')
if (v(3,1) <= 0.0_rk) call fail('Solid coupling velocity missing')
call sph_coupling_get_extended_diagnostics(total_force, total_moment, &
current_impulse, cumulative_impulse, current_work, cumulative_work, &
momentum_exchange, energy_exchange, max_force, max_acceleration, &
max_velocity_error, max_position_error, stale_count, skipped_count, &
nonfinite_count, imported_force_count, step_load_consumed, ierr)
call assert_ok(ierr, 'Solid diagnostics failed')
call assert_close(total_force(3), force(3), 'Solid force diagnostic mismatch')
if (max_acceleration <= 0.0_rk) call fail('Solid max acceleration missing')
if (step_load_consumed /= 1) call fail('Solid load not consumed')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Solid response')
end subroutine check_solid_force_response
subroutine check_apply_skip_after_import()
real(rk) :: force(SPH_NDIM)
call build_contact_case()
force = (/0.0_rk, mass(1) * 1.0e8_rk, 0.0_rk/)
call sph_coupling_import_force_by_region_index('CONTACT_PARTICLES', 1, &
force, ierr)
call assert_ok(ierr, 'skip force import failed')
particle_status(1) = SPH_STATUS_INACTIVE
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'skip advance failed')
if (abs(v(2,1)) > 1.0e-12_rk) call fail('inactive Solid received force')
if (coupling_skipped_particle_count <= 0) call fail('apply skip count missing')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for apply skip')
end subroutine check_apply_skip_after_import
subroutine build_contact_case()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Solid response')
call sph_read_inp('tests/data/coupling_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for Solid response')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Solid response')
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) > max(1.0e-10_rk, abs(expected) * 1.0e-8_rk)) then
call fail(message)
end if
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_solid_response_080
@@ -0,0 +1,177 @@
program test_coupling_solver_order_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, sph_advance_explicit
use sph_database, only: v, mass
use sph_blast_load, only: blast_solid_external_force
use sph_coupling_interface, only: coupling_external_force, &
coupling_step_load_consumed, sph_coupling_import_force_by_region_index, &
sph_coupling_get_extended_diagnostics
implicit none
integer :: ierr
call check_blast_and_coupling_superpose()
call check_step_local_load_is_single_use()
contains
subroutine check_blast_and_coupling_superpose()
real(rk) :: blast_velocity
real(rk) :: coupled_velocity
real(rk) :: blast_cache_before(SPH_NDIM)
real(rk) :: force(SPH_NDIM)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Blast baseline')
call sph_read_inp('tests/data/blast_water_gas_explosive_solid_070.inp', ierr)
call assert_ok(ierr, 'read failed for Blast baseline')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Blast baseline')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'advance failed for Blast baseline')
blast_velocity = v(1,5)
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Blast baseline')
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for coupled Blast')
call sph_read_inp('tests/data/coupling_blast_solid_080.inp', ierr)
call assert_ok(ierr, 'read failed for coupled Blast')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for coupled Blast')
if (maxval(abs(blast_solid_external_force(:,5))) <= 0.0_rk) then
call fail('Blast cache missing before Coupling import')
end if
blast_cache_before = blast_solid_external_force(:,5)
force = (/mass(5) * 1.0e8_rk, 0.0_rk, 0.0_rk/)
call sph_coupling_import_force_by_region_index('COUPLED_SOLID', 1, &
force, ierr)
call assert_ok(ierr, 'coupled force import failed')
call assert_vector_close(blast_solid_external_force(:,5), &
blast_cache_before, 'Coupling import changed Blast cache')
if (maxval(abs(coupling_external_force(:,5))) <= 0.0_rk) then
call fail('Coupling cache missing before advance')
end if
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'advance failed for coupled Blast')
coupled_velocity = v(1,5)
if (coupled_velocity <= blast_velocity) then
call fail('Coupling and Blast did not superpose in explicit step')
end if
if (maxval(abs(blast_solid_external_force(:,5))) <= 0.0_rk) then
call fail('Blast cache missing after coupled advance')
end if
if (maxval(abs(coupling_external_force)) > 0.0_rk) then
call fail('Coupling force cache was reused after advance')
end if
if (coupling_step_load_consumed /= 1) then
call fail('Coupling step load was not marked consumed')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for coupled Blast')
end subroutine check_blast_and_coupling_superpose
subroutine check_step_local_load_is_single_use()
real(rk) :: force(SPH_NDIM)
real(rk) :: velocity_after_force
real(rk) :: velocity_after_empty_step
real(rk) :: total_force(SPH_NDIM)
real(rk) :: total_moment(SPH_NDIM)
real(rk) :: current_impulse(SPH_NDIM)
real(rk) :: cumulative_impulse(SPH_NDIM)
real(rk) :: momentum_exchange(SPH_NDIM)
real(rk) :: current_work
real(rk) :: cumulative_work
real(rk) :: energy_exchange
real(rk) :: max_force
real(rk) :: max_acceleration
real(rk) :: max_velocity_error
real(rk) :: max_position_error
integer :: stale_count
integer :: skipped_count
integer :: nonfinite_count
integer :: imported_force_count
integer :: step_load_consumed
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for single-use load')
call sph_read_inp('tests/data/coupling_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for single-use load')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for single-use load')
force = (/0.0_rk, mass(1) * 1.0e8_rk, 0.0_rk/)
call sph_coupling_import_force_by_region_index('CONTACT_PARTICLES', 1, &
force, ierr)
call assert_ok(ierr, 'single-use force import failed')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'single-use first advance failed')
velocity_after_force = v(2,1)
if (velocity_after_force <= 0.0_rk) call fail('single-use force missing')
call sph_coupling_get_extended_diagnostics(total_force, total_moment, &
current_impulse, cumulative_impulse, current_work, cumulative_work, &
momentum_exchange, energy_exchange, max_force, max_acceleration, &
max_velocity_error, max_position_error, stale_count, skipped_count, &
nonfinite_count, imported_force_count, step_load_consumed, ierr)
call assert_ok(ierr, 'single-use diagnostics failed')
if (step_load_consumed /= 1) call fail('single-use load not consumed')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'single-use empty advance failed')
velocity_after_empty_step = v(2,1)
if (velocity_after_empty_step - velocity_after_force > &
velocity_after_force * 0.25_rk) then
call fail('Coupling load was applied again without reimport')
end if
call sph_coupling_get_extended_diagnostics(total_force, total_moment, &
current_impulse, cumulative_impulse, current_work, cumulative_work, &
momentum_exchange, energy_exchange, max_force, max_acceleration, &
max_velocity_error, max_position_error, stale_count, skipped_count, &
nonfinite_count, imported_force_count, step_load_consumed, ierr)
call assert_ok(ierr, 'empty-step diagnostics failed')
if (maxval(abs(total_force)) > 0.0_rk) then
call fail('empty step reported Coupling force')
end if
if (step_load_consumed /= 0) call fail('empty step reported consumed load')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for single-use load')
end subroutine check_step_local_load_is_single_use
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) > max(1.0e-10_rk, abs(expected) * 1.0e-8_rk)) then
call fail(message)
end if
end subroutine assert_close
subroutine assert_vector_close(actual, expected, message)
real(rk), intent(in) :: actual(SPH_NDIM)
real(rk), intent(in) :: expected(SPH_NDIM)
character(len=*), intent(in) :: message
integer :: i
do i = 1, SPH_NDIM
call assert_close(actual(i), expected(i), message)
end do
end subroutine assert_vector_close
subroutine fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_coupling_solver_order_080