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
+30
View File
@@ -198,6 +198,36 @@ set_target_properties(test_coupling_motion_boundary_080 PROPERTIES Fortran_MODUL
add_test(NAME coupling_motion_boundary_080 COMMAND test_coupling_motion_boundary_080)
set_tests_properties(coupling_motion_boundary_080 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_coupling_diagnostics_080 tests/module/test_coupling_diagnostics_080.f90)
target_link_libraries(test_coupling_diagnostics_080 PRIVATE sphlite_core)
set_target_properties(test_coupling_diagnostics_080 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME coupling_diagnostics_080 COMMAND test_coupling_diagnostics_080)
set_tests_properties(coupling_diagnostics_080 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_coupling_solver_order_080 tests/module/test_coupling_solver_order_080.f90)
target_link_libraries(test_coupling_solver_order_080 PRIVATE sphlite_core)
set_target_properties(test_coupling_solver_order_080 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME coupling_solver_order_080 COMMAND test_coupling_solver_order_080)
set_tests_properties(coupling_solver_order_080 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_coupling_solid_response_080 tests/module/test_coupling_solid_response_080.f90)
target_link_libraries(test_coupling_solid_response_080 PRIVATE sphlite_core)
set_target_properties(test_coupling_solid_response_080 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME coupling_solid_response_080 COMMAND test_coupling_solid_response_080)
set_tests_properties(coupling_solid_response_080 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_coupling_shell_response_080 tests/module/test_coupling_shell_response_080.f90)
target_link_libraries(test_coupling_shell_response_080 PRIVATE sphlite_core)
set_target_properties(test_coupling_shell_response_080 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME coupling_shell_response_080 COMMAND test_coupling_shell_response_080)
set_tests_properties(coupling_shell_response_080 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_coupling_noop_regression_080 tests/module/test_coupling_noop_regression_080.f90)
target_link_libraries(test_coupling_noop_regression_080 PRIVATE sphlite_core)
set_target_properties(test_coupling_noop_regression_080 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME coupling_noop_regression_080 COMMAND test_coupling_noop_regression_080)
set_tests_properties(coupling_noop_regression_080 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_input_gas tests/module/test_input_gas.f90)
target_link_libraries(test_input_gas PRIVATE sphlite_core)
set_target_properties(test_input_gas PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
@@ -59,6 +59,19 @@ module sph_coupling_interface
integer :: coupling_skipped_particle_count = 0
integer :: coupling_nonfinite_import_count = 0
integer :: coupling_imported_force_count = 0
real(rk) :: coupling_current_force(SPH_NDIM) = 0.0_rk
real(rk) :: coupling_current_moment(SPH_NDIM) = 0.0_rk
real(rk) :: coupling_current_impulse(SPH_NDIM) = 0.0_rk
real(rk) :: coupling_cumulative_impulse(SPH_NDIM) = 0.0_rk
real(rk) :: coupling_momentum_exchange(SPH_NDIM) = 0.0_rk
real(rk) :: coupling_current_work = 0.0_rk
real(rk) :: coupling_cumulative_work = 0.0_rk
real(rk) :: coupling_energy_exchange = 0.0_rk
real(rk) :: coupling_max_external_force = 0.0_rk
real(rk) :: coupling_max_acceleration = 0.0_rk
real(rk) :: coupling_max_velocity_error = 0.0_rk
real(rk) :: coupling_max_position_error = 0.0_rk
integer :: coupling_step_load_consumed = 0
contains
@@ -68,6 +81,12 @@ contains
coupling_work = 0.0_rk
coupling_energy = 0.0_rk
coupling_momentum = 0.0_rk
call sph_coupling_reset_step_diagnostics()
coupling_cumulative_impulse = 0.0_rk
coupling_momentum_exchange = 0.0_rk
coupling_cumulative_work = 0.0_rk
coupling_energy_exchange = 0.0_rk
coupling_step_load_consumed = 0
call sph_coupling_release_imports()
end subroutine sph_coupling_reset
@@ -82,8 +101,25 @@ contains
coupling_skipped_particle_count = 0
coupling_nonfinite_import_count = 0
coupling_imported_force_count = 0
call sph_coupling_reset_step_diagnostics()
coupling_cumulative_impulse = 0.0_rk
coupling_momentum_exchange = 0.0_rk
coupling_cumulative_work = 0.0_rk
coupling_energy_exchange = 0.0_rk
coupling_step_load_consumed = 0
end subroutine sph_coupling_release_imports
subroutine sph_coupling_reset_step_diagnostics()
coupling_current_force = 0.0_rk
coupling_current_moment = 0.0_rk
coupling_current_impulse = 0.0_rk
coupling_current_work = 0.0_rk
coupling_max_external_force = 0.0_rk
coupling_max_acceleration = 0.0_rk
coupling_max_velocity_error = 0.0_rk
coupling_max_position_error = 0.0_rk
end subroutine sph_coupling_reset_step_diagnostics
subroutine sph_coupling_allocate_imports(ierr)
integer, intent(out) :: ierr
integer :: stat
@@ -557,6 +593,155 @@ contains
epoch = coupling_epoch
end subroutine sph_coupling_get_import_diagnostics
subroutine sph_coupling_apply_imports_to_acceleration(dt, ierr)
real(rk), intent(in) :: dt
integer, intent(out) :: ierr
integer :: i
real(rk) :: force(SPH_NDIM)
real(rk) :: contribution(SPH_NDIM)
real(rk) :: moment_value(SPH_NDIM)
real(rk) :: work_value
real(rk) :: force_norm
real(rk) :: accel_norm
ierr = SPH_SUCCESS
call sph_coupling_reset_step_diagnostics()
coupling_step_load_consumed = 0
if (.not. sph_coupling_scalar_is_finite(dt) .or. dt < 0.0_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'coupling step dt is invalid')
ierr = SPH_ERROR_ARGUMENT
return
end if
call sph_coupling_allocate_imports(ierr)
if (ierr /= SPH_SUCCESS) return
if (.not. allocated(coupling_external_force)) return
do i = 1, npart
force = coupling_external_force(:,i)
if (maxval(abs(force)) <= 0.0_rk) cycle
if (.not. sph_coupling_vector_is_finite(force)) then
coupling_nonfinite_import_count = coupling_nonfinite_import_count + 1
call sph_error_set(SPH_ERROR_ARGUMENT, 'coupling cached force is not finite')
ierr = SPH_ERROR_ARGUMENT
return
end if
if (sph_coupling_particle_should_skip(i)) then
coupling_skipped_particle_count = coupling_skipped_particle_count + 1
cycle
end if
if (mass(i) <= 0.0_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, &
'coupling force particle mass must be positive')
ierr = SPH_ERROR_ARGUMENT
return
end if
contribution = force / mass(i)
if (.not. sph_coupling_vector_is_finite(contribution)) then
coupling_nonfinite_import_count = coupling_nonfinite_import_count + 1
call sph_error_set(SPH_ERROR_ARGUMENT, &
'coupling acceleration contribution is not finite')
ierr = SPH_ERROR_ARGUMENT
return
end if
a(:,i) = a(:,i) + contribution
coupling_current_force = coupling_current_force + force
call sph_coupling_cross(x(:,i), force, moment_value)
coupling_current_moment = coupling_current_moment + moment_value
coupling_current_impulse = coupling_current_impulse + force * dt
coupling_cumulative_impulse = coupling_cumulative_impulse + force * dt
coupling_momentum_exchange = coupling_momentum_exchange + force * dt
coupling_momentum = coupling_momentum_exchange
work_value = sum(force * v(:,i)) * dt
coupling_current_work = coupling_current_work + work_value
coupling_cumulative_work = coupling_cumulative_work + work_value
coupling_work = coupling_cumulative_work
coupling_energy_exchange = coupling_energy_exchange + work_value
coupling_energy = coupling_energy_exchange
force_norm = sph_coupling_vector_norm(force)
accel_norm = sph_coupling_vector_norm(contribution)
if (force_norm > coupling_max_external_force) then
coupling_max_external_force = force_norm
end if
if (accel_norm > coupling_max_acceleration) then
coupling_max_acceleration = accel_norm
end if
end do
end subroutine sph_coupling_apply_imports_to_acceleration
subroutine sph_coupling_apply_motion_before_step(ierr)
integer, intent(out) :: ierr
call sph_coupling_apply_motion_targets(.true., ierr)
end subroutine sph_coupling_apply_motion_before_step
subroutine sph_coupling_apply_motion_after_step(ierr)
integer, intent(out) :: ierr
call sph_coupling_apply_motion_targets(.true., ierr)
end subroutine sph_coupling_apply_motion_after_step
subroutine sph_coupling_finalize_step_imports(ierr)
integer, intent(out) :: ierr
logical :: has_load
ierr = SPH_SUCCESS
call sph_coupling_allocate_imports(ierr)
if (ierr /= SPH_SUCCESS) return
has_load = .false.
if (allocated(coupling_external_force)) then
if (maxval(abs(coupling_external_force)) > 0.0_rk) has_load = .true.
end if
if (allocated(coupling_motion_flag)) then
if (maxval(coupling_motion_flag) > 0) has_load = .true.
end if
if (has_load) coupling_step_load_consumed = 1
call sph_coupling_zero_import_buffers()
end subroutine sph_coupling_finalize_step_imports
subroutine 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)
real(rk), intent(out) :: total_force(SPH_NDIM)
real(rk), intent(out) :: total_moment(SPH_NDIM)
real(rk), intent(out) :: current_impulse(SPH_NDIM)
real(rk), intent(out) :: cumulative_impulse(SPH_NDIM)
real(rk), intent(out) :: current_work
real(rk), intent(out) :: cumulative_work
real(rk), intent(out) :: momentum_exchange(SPH_NDIM)
real(rk), intent(out) :: energy_exchange
real(rk), intent(out) :: max_force
real(rk), intent(out) :: max_acceleration
real(rk), intent(out) :: max_velocity_error
real(rk), intent(out) :: max_position_error
integer, intent(out) :: stale_count
integer, intent(out) :: skipped_count
integer, intent(out) :: nonfinite_count
integer, intent(out) :: imported_force_count
integer, intent(out) :: step_load_consumed
integer, intent(out) :: ierr
ierr = SPH_SUCCESS
total_force = coupling_current_force
total_moment = coupling_current_moment
current_impulse = coupling_current_impulse
cumulative_impulse = coupling_cumulative_impulse
current_work = coupling_current_work
cumulative_work = coupling_cumulative_work
momentum_exchange = coupling_momentum_exchange
energy_exchange = coupling_energy_exchange
max_force = coupling_max_external_force
max_acceleration = coupling_max_acceleration
max_velocity_error = coupling_max_velocity_error
max_position_error = coupling_max_position_error
stale_count = coupling_stale_load_count
skipped_count = coupling_skipped_particle_count
nonfinite_count = coupling_nonfinite_import_count
imported_force_count = coupling_imported_force_count
step_load_consumed = coupling_step_load_consumed
end subroutine sph_coupling_get_extended_diagnostics
subroutine sph_coupling_import_particle_force(index, force, ierr)
integer, intent(in) :: index
real(rk), intent(in) :: force(SPH_NDIM)
@@ -854,6 +1039,70 @@ contains
coupling_motion_mode(index) = mode
end subroutine sph_coupling_set_motion
subroutine sph_coupling_apply_motion_targets(track_error, ierr)
logical, intent(in) :: track_error
integer, intent(out) :: ierr
integer :: i
real(rk) :: target(SPH_NDIM)
real(rk) :: error_value
ierr = SPH_SUCCESS
call sph_coupling_allocate_imports(ierr)
if (ierr /= SPH_SUCCESS) return
if (.not. allocated(coupling_motion_flag)) return
do i = 1, npart
if (coupling_motion_flag(i) == SPH_COUPLING_MOTION_NONE) cycle
if (coupling_motion_mode(i) /= SPH_COUPLING_MOTION_DIRECT) then
call sph_error_set(SPH_ERROR_ARGUMENT, &
'coupling motion mode is invalid during apply')
ierr = SPH_ERROR_ARGUMENT
return
end if
if (sph_coupling_particle_should_skip(i)) then
coupling_skipped_particle_count = coupling_skipped_particle_count + 1
cycle
end if
if (coupling_motion_flag(i) == SPH_COUPLING_MOTION_VELOCITY) then
target = coupling_motion_velocity(:,i)
if (.not. sph_coupling_vector_is_finite(target)) then
coupling_nonfinite_import_count = coupling_nonfinite_import_count + 1
call sph_error_set(SPH_ERROR_ARGUMENT, &
'coupling velocity target is not finite during apply')
ierr = SPH_ERROR_ARGUMENT
return
end if
if (track_error) then
error_value = sph_coupling_vector_norm(v(:,i) - target)
if (error_value > coupling_max_velocity_error) then
coupling_max_velocity_error = error_value
end if
end if
v(:,i) = target
else if (coupling_motion_flag(i) == SPH_COUPLING_MOTION_POSITION) then
target = coupling_motion_position(:,i)
if (.not. sph_coupling_vector_is_finite(target)) then
coupling_nonfinite_import_count = coupling_nonfinite_import_count + 1
call sph_error_set(SPH_ERROR_ARGUMENT, &
'coupling position target is not finite during apply')
ierr = SPH_ERROR_ARGUMENT
return
end if
if (track_error) then
error_value = sph_coupling_vector_norm(x(:,i) - target)
if (error_value > coupling_max_position_error) then
coupling_max_position_error = error_value
end if
end if
x(:,i) = target
else
call sph_error_set(SPH_ERROR_ARGUMENT, &
'coupling motion target kind is invalid during apply')
ierr = SPH_ERROR_ARGUMENT
return
end if
end do
end subroutine sph_coupling_apply_motion_targets
logical function sph_coupling_particle_should_skip(index)
integer, intent(in) :: index
@@ -879,4 +1128,20 @@ contains
maxval(abs(values)) < huge(values(1))
end function sph_coupling_vector_is_finite
real(rk) function sph_coupling_vector_norm(values)
real(rk), intent(in) :: values(SPH_NDIM)
sph_coupling_vector_norm = sqrt(sum(values * values))
end function sph_coupling_vector_norm
subroutine sph_coupling_cross(left, right, result)
real(rk), intent(in) :: left(SPH_NDIM)
real(rk), intent(in) :: right(SPH_NDIM)
real(rk), intent(out) :: result(SPH_NDIM)
result(1) = left(2) * right(3) - left(3) * right(2)
result(2) = left(3) * right(1) - left(1) * right(3)
result(3) = left(1) * right(2) - left(2) * right(1)
end subroutine sph_coupling_cross
end module sph_coupling_interface
+13
View File
@@ -14,6 +14,11 @@ module sph_solver_explicit
use sph_explosive, only: sph_explosive_advance, sph_explosive_estimate_dt_limit
use sph_blast_load, only: sph_blast_load_clear, sph_blast_load_compute_at, &
sph_blast_load_apply_to_acceleration
use sph_coupling_interface, only: &
sph_coupling_apply_imports_to_acceleration, &
sph_coupling_apply_motion_before_step, &
sph_coupling_apply_motion_after_step, &
sph_coupling_finalize_step_imports
use sph_solid_dynamics, only: sph_solid_compute_acceleration, &
sph_solid_advance_material, sph_solid_update_diagnostics, &
sph_solid_estimate_dt_limits
@@ -70,12 +75,20 @@ contains
if (ierr /= SPH_SUCCESS) return
call sph_blast_load_apply_to_acceleration(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_coupling_apply_imports_to_acceleration(dt, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_coupling_apply_motion_before_step(ierr)
if (ierr /= SPH_SUCCESS) return
do i = 1, npart
vhalf(:,i) = v(:,i) + 0.5_rk * dt * a(:,i)
x(:,i) = x(:,i) + dt * vhalf(:,i)
rho(i) = rho(i) + dt * drho_dt(i)
v(:,i) = vhalf(:,i) + 0.5_rk * dt * a(:,i)
end do
call sph_coupling_apply_motion_after_step(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_coupling_finalize_step_imports(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_explosive_advance(dt, current_time + dt, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_gas_apply_sources_explicit(dt, ierr)
+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
+46 -46
View File
@@ -180,52 +180,52 @@
## 阶段 E:显式求解器接入和耦合诊断
- [ ] 定义 coupling 外部力进入总加速度的位置。
- [ ] 定义 coupling 运动边界进入 Velocity-Verlet 的位置。
- [ ] 确认 coupling 外部力缓存独立于 Blast 外载荷缓存。
- [ ] 确认 coupling 外部力和 Blast 外载荷可叠加。
- [ ] 将 coupling 粒子力转换为加速度贡献。
- [ ] 将 coupling facet load 转换为粒子加速度贡献。
- [ ] 将 coupling 加速度贡献接入 Water 粒子路径。
- [ ] 将 coupling 加速度贡献接入 Gas 粒子路径。
- [ ] 将 coupling 加速度贡献接入 Solid 粒子路径。
- [ ] 将 coupling 加速度贡献接入 Shell 粒子平动路径。
- [ ] 确认 coupling 力不改变 Shell director 和 moment 占位状态。
- [ ] 在显式步中施加目标速度运动边界。
- [ ] 在显式步中施加目标位置运动边界。
- [ ] 计算 coupling 当前步总外部力。
- [ ] 计算 coupling 当前步总外部力矩或等价力矩。
- [ ] 计算 coupling 当前步冲量。
- [ ] 计算 coupling 累计冲量。
- [ ] 计算 coupling 当前步做功。
- [ ] 计算 coupling 累计做功。
- [ ] 计算 coupling 动量交换。
- [ ] 计算 coupling 能量交换。
- [ ] 计算 coupling 最大外部力。
- [ ] 计算 coupling 最大加速度贡献。
- [ ] 计算 coupling 最大目标速度误差。
- [ ] 计算 coupling 最大目标位置误差。
- [ ] 记录 coupling stale load 计数。
- [ ] 记录 coupling skipped particle 计数。
- [ ] 记录 coupling nonfinite import 计数。
- [ ] 在步末标记 step-local coupling 载荷已消费。
- [ ] 确认无 active coupling region 时安全跳过。
- [ ] 确认 disabled coupling region 不影响显式步。
- [ ] 确认空导入不产生虚假加速度。
- [ ] 确认 Water-only 回归不被 coupling 路径污染。
- [ ] 确认 Gas-only 回归不被 coupling 路径污染。
- [ ] 确认 Explosive 回归不被 coupling 路径污染。
- [ ] 确认 Solid-only 回归不被 coupling 路径污染。
- [ ] 确认 Shell-only 回归不被 coupling 路径污染。
- [ ] 新增 `coupling_diagnostics_080` 测试。
- [ ] 新增 `coupling_solver_order_080` 测试。
- [ ] 新增 `coupling_solid_response_080` 测试。
- [ ] 新增 `coupling_shell_response_080` 测试。
- [ ] 新增 `coupling_noop_regression_080` 测试。
- [ ] 将阶段 E 新测试接入 CTest。
- [ ] 运行阶段 E coupling 求解器专项测试。
- [ ] 运行 `git diff --check`。
- [ ] 准备阶段 E 本地提交说明。
- [x] 定义 coupling 外部力进入总加速度的位置。
- [x] 定义 coupling 运动边界进入 Velocity-Verlet 的位置。
- [x] 确认 coupling 外部力缓存独立于 Blast 外载荷缓存。
- [x] 确认 coupling 外部力和 Blast 外载荷可叠加。
- [x] 将 coupling 粒子力转换为加速度贡献。
- [x] 将 coupling facet load 转换为粒子加速度贡献。
- [x] 将 coupling 加速度贡献接入 Water 粒子路径。
- [x] 将 coupling 加速度贡献接入 Gas 粒子路径。
- [x] 将 coupling 加速度贡献接入 Solid 粒子路径。
- [x] 将 coupling 加速度贡献接入 Shell 粒子平动路径。
- [x] 确认 coupling 力不改变 Shell director 和 moment 占位状态。
- [x] 在显式步中施加目标速度运动边界。
- [x] 在显式步中施加目标位置运动边界。
- [x] 计算 coupling 当前步总外部力。
- [x] 计算 coupling 当前步总外部力矩或等价力矩。
- [x] 计算 coupling 当前步冲量。
- [x] 计算 coupling 累计冲量。
- [x] 计算 coupling 当前步做功。
- [x] 计算 coupling 累计做功。
- [x] 计算 coupling 动量交换。
- [x] 计算 coupling 能量交换。
- [x] 计算 coupling 最大外部力。
- [x] 计算 coupling 最大加速度贡献。
- [x] 计算 coupling 最大目标速度误差。
- [x] 计算 coupling 最大目标位置误差。
- [x] 记录 coupling stale load 计数。
- [x] 记录 coupling skipped particle 计数。
- [x] 记录 coupling nonfinite import 计数。
- [x] 在步末标记 step-local coupling 载荷已消费。
- [x] 确认无 active coupling region 时安全跳过。
- [x] 确认 disabled coupling region 不影响显式步。
- [x] 确认空导入不产生虚假加速度。
- [x] 确认 Water-only 回归不被 coupling 路径污染。
- [x] 确认 Gas-only 回归不被 coupling 路径污染。
- [x] 确认 Explosive 回归不被 coupling 路径污染。
- [x] 确认 Solid-only 回归不被 coupling 路径污染。
- [x] 确认 Shell-only 回归不被 coupling 路径污染。
- [x] 新增 `coupling_diagnostics_080` 测试。
- [x] 新增 `coupling_solver_order_080` 测试。
- [x] 新增 `coupling_solid_response_080` 测试。
- [x] 新增 `coupling_shell_response_080` 测试。
- [x] 新增 `coupling_noop_regression_080` 测试。
- [x] 将阶段 E 新测试接入 CTest。
- [x] 运行阶段 E coupling 求解器专项测试。
- [x] 运行 `git diff --check`。
- [x] 准备阶段 E 本地提交说明。
## 阶段 F:Output、Restart、Fortran API 和外部接口层