Add coupling region export APIs

This commit is contained in:
Codex
2026-07-04 08:59:36 +08:00
parent 854b8042b2
commit 9f003dada5
7 changed files with 740 additions and 47 deletions
+18
View File
@@ -162,6 +162,24 @@ set_target_properties(test_coupling_region_build_080 PROPERTIES Fortran_MODULE_D
add_test(NAME coupling_region_build_080 COMMAND test_coupling_region_build_080)
set_tests_properties(coupling_region_build_080 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_coupling_particle_export_080 tests/module/test_coupling_particle_export_080.f90)
target_link_libraries(test_coupling_particle_export_080 PRIVATE sphlite_core)
set_target_properties(test_coupling_particle_export_080 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME coupling_particle_export_080 COMMAND test_coupling_particle_export_080)
set_tests_properties(coupling_particle_export_080 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_coupling_facet_export_080 tests/module/test_coupling_facet_export_080.f90)
target_link_libraries(test_coupling_facet_export_080 PRIVATE sphlite_core)
set_target_properties(test_coupling_facet_export_080 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME coupling_facet_export_080 COMMAND test_coupling_facet_export_080)
set_tests_properties(coupling_facet_export_080 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_coupling_facet_errors_080 tests/module/test_coupling_facet_errors_080.f90)
target_link_libraries(test_coupling_facet_errors_080 PRIVATE sphlite_core)
set_target_properties(test_coupling_facet_errors_080 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME coupling_facet_errors_080 COMMAND test_coupling_facet_errors_080)
set_tests_properties(coupling_facet_errors_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}")
@@ -2,9 +2,40 @@ module sph_coupling_interface
use sph_precision, only: rk, SPH_NDIM
use sph_error, only: SPH_SUCCESS, SPH_ERROR_ARGUMENT, sph_error_set
use sph_database, only: npart, particle_id_ext, particle_phase, material_id, &
x, v, pressure, mass, acc_body
particle_status, section_id, x, v, a, pressure, mass, volume, rho, &
internal_energy, temperature, h, acc_body, SPH_PHASE_SHELL, &
DB_EXPORT_PARTICLE => SPH_COUPLING_EXPORT_PARTICLE, &
DB_EXPORT_FACET => SPH_COUPLING_EXPORT_FACET, &
DB_EXPORT_BOTH => SPH_COUPLING_EXPORT_BOTH, &
db_coupling_region_count => coupling_region_count, &
db_coupling_region_name => coupling_region_name, &
db_coupling_region_export_mode => coupling_region_export_mode, &
db_coupling_region_enabled => coupling_region_enabled, &
db_coupling_region_particle_count => coupling_region_particle_count, &
db_coupling_region_particles => coupling_region_particles, &
sph_db_name_equal
use sph_shell, only: shell_director, shell_reference_area
implicit none
integer, parameter :: SPH_COUPLING_PARTICLE_SCALAR_COUNT = 7
integer, parameter :: SPH_COUPLING_PARTICLE_SCALAR_MASS = 1
integer, parameter :: SPH_COUPLING_PARTICLE_SCALAR_VOLUME = 2
integer, parameter :: SPH_COUPLING_PARTICLE_SCALAR_DENSITY = 3
integer, parameter :: SPH_COUPLING_PARTICLE_SCALAR_PRESSURE = 4
integer, parameter :: SPH_COUPLING_PARTICLE_SCALAR_ENERGY = 5
integer, parameter :: SPH_COUPLING_PARTICLE_SCALAR_TEMPERATURE = 6
integer, parameter :: SPH_COUPLING_PARTICLE_SCALAR_H = 7
integer, parameter :: SPH_COUPLING_PARTICLE_VECTOR_COUNT = 3
integer, parameter :: SPH_COUPLING_PARTICLE_VECTOR_X = 1
integer, parameter :: SPH_COUPLING_PARTICLE_VECTOR_V = 2
integer, parameter :: SPH_COUPLING_PARTICLE_VECTOR_A = 3
integer, parameter :: SPH_COUPLING_FACET_VECTOR_COUNT = 3
integer, parameter :: SPH_COUPLING_FACET_VECTOR_CENTER = 1
integer, parameter :: SPH_COUPLING_FACET_VECTOR_VELOCITY = 2
integer, parameter :: SPH_COUPLING_FACET_VECTOR_NORMAL = 3
integer :: coupling_region_count = 0
integer :: coupling_type = 0
real(rk) :: coupling_work = 0.0_rk
@@ -29,6 +60,100 @@ contains
ierr = SPH_SUCCESS
end subroutine sph_coupling_get_particle_count
subroutine sph_coupling_get_region_particle_count(region_name, count, ierr)
character(len=*), intent(in) :: region_name
integer, intent(out) :: count
integer, intent(out) :: ierr
integer :: region
count = 0
ierr = SPH_SUCCESS
call sph_coupling_find_region(region_name, region, ierr)
if (ierr /= SPH_SUCCESS) return
if (db_coupling_region_enabled(region) == 0) return
if (db_coupling_region_export_mode(region) == DB_EXPORT_FACET) return
count = db_coupling_region_particle_count(region)
end subroutine sph_coupling_get_region_particle_count
subroutine sph_coupling_export_region_particles(region_name, capacity, count, &
ext_ids, internal_indices, phases, statuses, materials, sections, &
scalar_values, vector_values, ierr)
character(len=*), intent(in) :: region_name
integer, intent(in) :: capacity
integer, intent(out) :: count
integer, intent(out) :: ext_ids(capacity)
integer, intent(out) :: internal_indices(capacity)
integer, intent(out) :: phases(capacity)
integer, intent(out) :: statuses(capacity)
integer, intent(out) :: materials(capacity)
integer, intent(out) :: sections(capacity)
real(rk), intent(out) :: scalar_values(SPH_COUPLING_PARTICLE_SCALAR_COUNT, &
capacity)
real(rk), intent(out) :: vector_values(SPH_NDIM, &
SPH_COUPLING_PARTICLE_VECTOR_COUNT, capacity)
integer, intent(out) :: ierr
integer :: region
integer :: item
integer :: node_index
ierr = SPH_SUCCESS
count = 0
if (capacity > 0) then
ext_ids = 0
internal_indices = 0
phases = 0
statuses = 0
materials = 0
sections = 0
scalar_values = 0.0_rk
vector_values = 0.0_rk
end if
if (capacity < 0) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'coupling export capacity is negative')
ierr = SPH_ERROR_ARGUMENT
return
end if
call sph_coupling_find_region(region_name, region, ierr)
if (ierr /= SPH_SUCCESS) return
if (db_coupling_region_enabled(region) == 0) return
if (db_coupling_region_export_mode(region) == DB_EXPORT_FACET) return
count = db_coupling_region_particle_count(region)
if (capacity < count) then
call sph_error_set(SPH_ERROR_ARGUMENT, &
'coupling particle export capacity is too small')
ierr = SPH_ERROR_ARGUMENT
return
end if
do item = 1, count
node_index = db_coupling_region_particles(item, region)
if (.not. sph_coupling_particle_state_is_finite(node_index)) then
call sph_error_set(SPH_ERROR_ARGUMENT, &
'coupling particle export state is not finite')
ierr = SPH_ERROR_ARGUMENT
return
end if
internal_indices(item) = node_index
ext_ids(item) = particle_id_ext(node_index)
phases(item) = particle_phase(node_index)
statuses(item) = particle_status(node_index)
materials(item) = material_id(node_index)
sections(item) = section_id(node_index)
scalar_values(SPH_COUPLING_PARTICLE_SCALAR_MASS,item) = mass(node_index)
scalar_values(SPH_COUPLING_PARTICLE_SCALAR_VOLUME,item) = volume(node_index)
scalar_values(SPH_COUPLING_PARTICLE_SCALAR_DENSITY,item) = rho(node_index)
scalar_values(SPH_COUPLING_PARTICLE_SCALAR_PRESSURE,item) = pressure(node_index)
scalar_values(SPH_COUPLING_PARTICLE_SCALAR_ENERGY,item) = &
internal_energy(node_index)
scalar_values(SPH_COUPLING_PARTICLE_SCALAR_TEMPERATURE,item) = &
temperature(node_index)
scalar_values(SPH_COUPLING_PARTICLE_SCALAR_H,item) = h(node_index)
vector_values(:,SPH_COUPLING_PARTICLE_VECTOR_X,item) = x(:,node_index)
vector_values(:,SPH_COUPLING_PARTICLE_VECTOR_V,item) = v(:,node_index)
vector_values(:,SPH_COUPLING_PARTICLE_VECTOR_A,item) = a(:,node_index)
end do
end subroutine sph_coupling_export_region_particles
subroutine sph_coupling_export_particle(index, ext_id, position, velocity, ierr)
integer, intent(in) :: index
integer, intent(out) :: ext_id
@@ -89,6 +214,86 @@ contains
ierr = SPH_SUCCESS
end subroutine sph_coupling_get_facet_count
subroutine sph_coupling_get_region_facet_count(region_name, count, ierr)
character(len=*), intent(in) :: region_name
integer, intent(out) :: count
integer, intent(out) :: ierr
integer :: region
count = 0
ierr = SPH_SUCCESS
call sph_coupling_find_region(region_name, region, ierr)
if (ierr /= SPH_SUCCESS) return
if (db_coupling_region_enabled(region) == 0) return
if (db_coupling_region_export_mode(region) == DB_EXPORT_PARTICLE) return
call sph_coupling_count_shell_facets(region, count, ierr)
end subroutine sph_coupling_get_region_facet_count
subroutine sph_coupling_export_region_facets(region_name, capacity, count, &
facet_ids, particle_ids, materials, sections, vector_values, &
area_values, ierr)
character(len=*), intent(in) :: region_name
integer, intent(in) :: capacity
integer, intent(out) :: count
integer, intent(out) :: facet_ids(capacity)
integer, intent(out) :: particle_ids(capacity)
integer, intent(out) :: materials(capacity)
integer, intent(out) :: sections(capacity)
real(rk), intent(out) :: vector_values(SPH_NDIM, &
SPH_COUPLING_FACET_VECTOR_COUNT, capacity)
real(rk), intent(out) :: area_values(capacity)
integer, intent(out) :: ierr
integer :: region
integer :: item
integer :: node_index
ierr = SPH_SUCCESS
count = 0
if (capacity > 0) then
facet_ids = 0
particle_ids = 0
materials = 0
sections = 0
vector_values = 0.0_rk
area_values = 0.0_rk
end if
if (capacity < 0) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'coupling facet export capacity is negative')
ierr = SPH_ERROR_ARGUMENT
return
end if
call sph_coupling_find_region(region_name, region, ierr)
if (ierr /= SPH_SUCCESS) return
if (db_coupling_region_enabled(region) == 0) return
if (db_coupling_region_export_mode(region) == DB_EXPORT_PARTICLE) return
call sph_coupling_count_shell_facets(region, count, ierr)
if (ierr /= SPH_SUCCESS) return
if (capacity < count) then
call sph_error_set(SPH_ERROR_ARGUMENT, &
'coupling facet export capacity is too small')
ierr = SPH_ERROR_ARGUMENT
return
end if
count = 0
do item = 1, db_coupling_region_particle_count(region)
node_index = db_coupling_region_particles(item, region)
if (particle_phase(node_index) /= SPH_PHASE_SHELL) cycle
count = count + 1
call sph_coupling_check_shell_facet(node_index, ierr)
if (ierr /= SPH_SUCCESS) return
facet_ids(count) = node_index
particle_ids(count) = particle_id_ext(node_index)
materials(count) = material_id(node_index)
sections(count) = section_id(node_index)
vector_values(:,SPH_COUPLING_FACET_VECTOR_CENTER,count) = x(:,node_index)
vector_values(:,SPH_COUPLING_FACET_VECTOR_VELOCITY,count) = v(:,node_index)
vector_values(:,SPH_COUPLING_FACET_VECTOR_NORMAL,count) = &
shell_director(:,node_index)
area_values(count) = shell_reference_area(node_index)
end do
end subroutine sph_coupling_export_region_facets
subroutine sph_coupling_export_facet(index, node_ids, ierr)
integer, intent(in) :: index
integer, intent(out) :: node_ids(3)
@@ -148,4 +353,113 @@ contains
momentum(:) = coupling_momentum(:)
end subroutine sph_coupling_get_diagnostics
subroutine sph_coupling_find_region(region_name, region, ierr)
character(len=*), intent(in) :: region_name
integer, intent(out) :: region
integer, intent(out) :: ierr
integer :: i
ierr = SPH_SUCCESS
region = 0
do i = 1, db_coupling_region_count
if (sph_db_name_equal(db_coupling_region_name(i), region_name)) then
region = i
return
end if
end do
call sph_error_set(SPH_ERROR_ARGUMENT, 'coupling region name is invalid')
ierr = SPH_ERROR_ARGUMENT
end subroutine sph_coupling_find_region
logical function sph_coupling_particle_state_is_finite(index)
integer, intent(in) :: index
sph_coupling_particle_state_is_finite = .false.
if (index < 1 .or. index > npart) return
if (.not. sph_coupling_scalar_is_finite(mass(index))) return
if (.not. sph_coupling_scalar_is_finite(volume(index))) return
if (.not. sph_coupling_scalar_is_finite(rho(index))) return
if (.not. sph_coupling_scalar_is_finite(pressure(index))) return
if (.not. sph_coupling_scalar_is_finite(internal_energy(index))) return
if (.not. sph_coupling_scalar_is_finite(temperature(index))) return
if (.not. sph_coupling_scalar_is_finite(h(index))) return
if (.not. sph_coupling_vector_is_finite(x(:,index))) return
if (.not. sph_coupling_vector_is_finite(v(:,index))) return
if (.not. sph_coupling_vector_is_finite(a(:,index))) return
sph_coupling_particle_state_is_finite = .true.
end function sph_coupling_particle_state_is_finite
subroutine sph_coupling_count_shell_facets(region, count, ierr)
integer, intent(in) :: region
integer, intent(out) :: count
integer, intent(out) :: ierr
integer :: item
integer :: node_index
ierr = SPH_SUCCESS
count = 0
do item = 1, db_coupling_region_particle_count(region)
node_index = db_coupling_region_particles(item, region)
if (node_index < 1 .or. node_index > npart) cycle
if (particle_phase(node_index) == SPH_PHASE_SHELL) then
count = count + 1
end if
end do
if (count <= 0) then
call sph_error_set(SPH_ERROR_ARGUMENT, &
'coupling region has no Shell facet proxy')
ierr = SPH_ERROR_ARGUMENT
return
end if
end subroutine sph_coupling_count_shell_facets
subroutine sph_coupling_check_shell_facet(index, ierr)
integer, intent(in) :: index
integer, intent(out) :: ierr
ierr = SPH_SUCCESS
if (index < 1 .or. index > npart) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'coupling facet particle is invalid')
ierr = SPH_ERROR_ARGUMENT
return
end if
if (particle_phase(index) /= SPH_PHASE_SHELL) then
call sph_error_set(SPH_ERROR_ARGUMENT, &
'coupling facet proxy requires Shell particles')
ierr = SPH_ERROR_ARGUMENT
return
end if
if (.not. allocated(shell_director) .or. &
.not. allocated(shell_reference_area)) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell facet proxy state is unavailable')
ierr = SPH_ERROR_ARGUMENT
return
end if
if (.not. sph_coupling_vector_is_finite(shell_director(:,index))) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell facet normal is not finite')
ierr = SPH_ERROR_ARGUMENT
return
end if
if (.not. sph_coupling_scalar_is_finite(shell_reference_area(index)) .or. &
shell_reference_area(index) <= 0.0_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell facet area is invalid')
ierr = SPH_ERROR_ARGUMENT
return
end if
end subroutine sph_coupling_check_shell_facet
logical function sph_coupling_scalar_is_finite(value)
real(rk), intent(in) :: value
sph_coupling_scalar_is_finite = value == value .and. &
abs(value) < huge(value)
end function sph_coupling_scalar_is_finite
logical function sph_coupling_vector_is_finite(values)
real(rk), intent(in) :: values(SPH_NDIM)
sph_coupling_vector_is_finite = all(values == values) .and. &
maxval(abs(values)) < huge(values(1))
end function sph_coupling_vector_is_finite
end module sph_coupling_interface
+21
View File
@@ -0,0 +1,21 @@
*NODE
1, 0.0, 0.0, 0.0
2, 0.1, 0.0, 0.0
3, 0.0, 0.1, 0.0
*ELEMENT, TYPE=SPH3D
1, 1
2, 2
3, 3
*ELSET, ELSET=SHELL_PARTICLES
1, 2, 3
*MATERIAL, NAME=SHELL_DIRECTOR, TYPE=SHELL
*DENSITY
7850.0
*ELASTIC
210.0E9, 0.30
*SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_DIRECTOR, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333
*SPHLITE SHELL DIRECTOR, SET=SHELL_PARTICLES, NX=0.0, NY=0.0, NZ=1.0
*SPHLITE PARTICLE CONTROL, H=0.12, MASS=7.85, VOLUME=0.001
*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5
*SPHLITE COUPLING REGION, NAME=SHELL_FACETS, SET=SHELL_PARTICLES, TYPE=CONTACT, EXPORT=FACET, IMPORT=FACET_LOAD, ENABLED=YES, PHASE=SHELL, MATERIAL=SHELL_DIRECTOR, SECTION=SHELL_PARTICLES, SURFACE=SHELL_SURFACE
*SPHLITE COUPLING REGION, NAME=SHELL_BOTH, SET=SHELL_PARTICLES, TYPE=CONTACT, EXPORT=BOTH, IMPORT=FORCE, ENABLED=YES, PHASE=SHELL, MATERIAL=SHELL_DIRECTOR, SECTION=SHELL_PARTICLES
@@ -0,0 +1,109 @@
program test_coupling_facet_errors_080
use sph_precision, only: rk, SPH_NDIM
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
use sph_shell, only: shell_director, shell_reference_area
use sph_coupling_interface, only: sph_coupling_get_region_facet_count, &
sph_coupling_export_region_facets, SPH_COUPLING_FACET_VECTOR_COUNT
implicit none
integer :: ierr
call check_solid_has_no_facet_proxy()
call check_disabled_facet_region()
call check_zero_area_facet_fails()
call check_nonfinite_normal_fails()
contains
subroutine check_solid_has_no_facet_proxy()
integer :: count
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for solid facet error')
call sph_read_inp('tests/data/coupling_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for solid facet error')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for solid facet error')
call sph_coupling_get_region_facet_count('CONTACT_FACETS', count, ierr)
if (ierr == SPH_SUCCESS) call fail('solid facet proxy count did not fail')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after solid facet error')
end subroutine check_solid_has_no_facet_proxy
subroutine check_disabled_facet_region()
integer :: count
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for disabled facet region')
call sph_read_inp('tests/data/coupling_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for disabled facet region')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for disabled facet region')
call sph_coupling_get_region_facet_count('CONTACT_DISABLED', count, ierr)
call assert_ok(ierr, 'disabled facet count failed')
if (count /= 0) call fail('disabled facet region returned facets')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after disabled facet region')
end subroutine check_disabled_facet_region
subroutine check_zero_area_facet_fails()
integer :: count
integer :: facet_ids(3)
integer :: particle_ids(3)
integer :: materials(3)
integer :: sections(3)
real(rk) :: vectors(SPH_NDIM,SPH_COUPLING_FACET_VECTOR_COUNT,3)
real(rk) :: areas(3)
call build_shell_case()
shell_reference_area(1) = 0.0_rk
call sph_coupling_export_region_facets('SHELL_FACETS', 3, count, &
facet_ids, particle_ids, materials, sections, vectors, areas, ierr)
if (ierr == SPH_SUCCESS) call fail('zero area facet did not fail')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after zero area facet')
end subroutine check_zero_area_facet_fails
subroutine check_nonfinite_normal_fails()
integer :: count
integer :: facet_ids(3)
integer :: particle_ids(3)
integer :: materials(3)
integer :: sections(3)
real(rk) :: vectors(SPH_NDIM,SPH_COUPLING_FACET_VECTOR_COUNT,3)
real(rk) :: areas(3)
call build_shell_case()
shell_director(1,1) = huge(shell_director(1,1))
call sph_coupling_export_region_facets('SHELL_FACETS', 3, count, &
facet_ids, particle_ids, materials, sections, vectors, areas, ierr)
if (ierr == SPH_SUCCESS) call fail('nonfinite facet normal did not fail')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after nonfinite facet normal')
end subroutine check_nonfinite_normal_fails
subroutine build_shell_case()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for shell facet error')
call sph_read_inp('tests/data/coupling_shell_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for shell facet error')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for shell facet error')
end subroutine build_shell_case
subroutine assert_ok(ierr_value, message)
integer, intent(in) :: ierr_value
character(len=*), intent(in) :: message
if (ierr_value /= SPH_SUCCESS) call fail(message)
end subroutine assert_ok
subroutine fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_coupling_facet_errors_080
@@ -0,0 +1,78 @@
program test_coupling_facet_export_080
use sph_precision, only: rk, SPH_NDIM
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
use sph_coupling_interface, only: sph_coupling_get_region_facet_count, &
sph_coupling_export_region_facets, SPH_COUPLING_FACET_VECTOR_COUNT, &
SPH_COUPLING_FACET_VECTOR_CENTER, &
SPH_COUPLING_FACET_VECTOR_VELOCITY, &
SPH_COUPLING_FACET_VECTOR_NORMAL
implicit none
integer :: ierr
integer :: count
integer :: facet_ids(3)
integer :: particle_ids(3)
integer :: materials(3)
integer :: sections(3)
real(rk) :: vectors(SPH_NDIM,SPH_COUPLING_FACET_VECTOR_COUNT,3)
real(rk) :: areas(3)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for facet export')
call sph_read_inp('tests/data/coupling_shell_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for facet export')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for facet export')
call sph_coupling_get_region_facet_count('SHELL_FACETS', count, ierr)
call assert_ok(ierr, 'facet count failed')
if (count /= 3) call fail('facet count mismatch')
call sph_coupling_export_region_facets('SHELL_FACETS', 3, count, &
facet_ids, particle_ids, materials, sections, vectors, areas, ierr)
call assert_ok(ierr, 'facet export failed')
if (count /= 3) call fail('facet export count mismatch')
if (facet_ids(1) /= 1 .or. particle_ids(1) /= 1) call fail('facet id mismatch')
if (minval(materials(1:3)) <= 0) call fail('facet material mismatch')
if (minval(sections(1:3)) <= 0) call fail('facet section mismatch')
call assert_close(vectors(1,SPH_COUPLING_FACET_VECTOR_CENTER,2), 0.1_rk, &
'facet center mismatch')
call assert_close(maxval(abs(vectors(:,SPH_COUPLING_FACET_VECTOR_VELOCITY,1))), &
0.0_rk, 'facet velocity mismatch')
call assert_close(vectors(3,SPH_COUPLING_FACET_VECTOR_NORMAL,1), 1.0_rk, &
'facet normal mismatch')
if (areas(1) <= 0.0_rk) call fail('facet area mismatch')
call sph_coupling_export_region_facets('SHELL_FACETS', 2, count, &
facet_ids(1:2), particle_ids(1:2), materials(1:2), sections(1:2), &
vectors(:,:,1:2), areas(1:2), ierr)
if (ierr == SPH_SUCCESS) call fail('small facet capacity did not fail')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for facet export')
contains
subroutine assert_ok(ierr_value, message)
integer, intent(in) :: ierr_value
character(len=*), intent(in) :: message
if (ierr_value /= SPH_SUCCESS) call fail(message)
end subroutine assert_ok
subroutine assert_close(actual, expected, message)
real(rk), intent(in) :: actual
real(rk), intent(in) :: expected
character(len=*), intent(in) :: message
if (abs(actual - expected) > 1.0e-12_rk) call fail(message)
end subroutine assert_close
subroutine fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_coupling_facet_export_080
@@ -0,0 +1,153 @@
program test_coupling_particle_export_080
use sph_precision, only: rk, SPH_NDIM
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
use sph_database, only: pressure, SPH_PHASE_SOLID, SPH_STATUS_ACTIVE
use sph_coupling_interface, only: sph_coupling_get_region_particle_count, &
sph_coupling_export_region_particles, &
SPH_COUPLING_PARTICLE_SCALAR_COUNT, &
SPH_COUPLING_PARTICLE_SCALAR_MASS, &
SPH_COUPLING_PARTICLE_SCALAR_VOLUME, &
SPH_COUPLING_PARTICLE_SCALAR_DENSITY, &
SPH_COUPLING_PARTICLE_SCALAR_PRESSURE, &
SPH_COUPLING_PARTICLE_SCALAR_ENERGY, &
SPH_COUPLING_PARTICLE_SCALAR_TEMPERATURE, &
SPH_COUPLING_PARTICLE_SCALAR_H, &
SPH_COUPLING_PARTICLE_VECTOR_COUNT, &
SPH_COUPLING_PARTICLE_VECTOR_X, SPH_COUPLING_PARTICLE_VECTOR_V, &
SPH_COUPLING_PARTICLE_VECTOR_A
implicit none
integer :: ierr
call check_particle_export()
call check_particle_export_errors()
contains
subroutine check_particle_export()
integer :: count
integer :: ext_ids(3)
integer :: internal_ids(3)
integer :: phases(3)
integer :: statuses(3)
integer :: materials(3)
integer :: sections(3)
real(rk) :: scalars(SPH_COUPLING_PARTICLE_SCALAR_COUNT,3)
real(rk) :: vectors(SPH_NDIM,SPH_COUPLING_PARTICLE_VECTOR_COUNT,3)
call build_contact_case()
call sph_coupling_get_region_particle_count('CONTACT_PARTICLES', count, ierr)
call assert_ok(ierr, 'particle region count failed')
if (count /= 3) call fail('particle region count mismatch')
call sph_coupling_export_region_particles('CONTACT_PARTICLES', 3, count, &
ext_ids, internal_ids, phases, statuses, materials, sections, &
scalars, vectors, ierr)
call assert_ok(ierr, 'particle region export failed')
if (count /= 3) call fail('particle export count mismatch')
if (ext_ids(1) /= 1 .or. ext_ids(3) /= 3) call fail('external id order mismatch')
if (internal_ids(1) /= 1 .or. internal_ids(3) /= 3) then
call fail('internal id order mismatch')
end if
if (any(phases(1:3) /= SPH_PHASE_SOLID)) call fail('phase export mismatch')
if (any(statuses(1:3) /= SPH_STATUS_ACTIVE)) call fail('status export mismatch')
if (minval(materials(1:3)) <= 0) call fail('material export mismatch')
if (minval(sections(1:3)) <= 0) call fail('section export mismatch')
call assert_close(scalars(SPH_COUPLING_PARTICLE_SCALAR_MASS,1), 1.0_rk, &
'mass scalar mismatch')
if (scalars(SPH_COUPLING_PARTICLE_SCALAR_VOLUME,1) <= 0.0_rk) then
call fail('volume scalar mismatch')
end if
if (scalars(SPH_COUPLING_PARTICLE_SCALAR_DENSITY,1) <= 0.0_rk) then
call fail('density scalar mismatch')
end if
call assert_close(scalars(SPH_COUPLING_PARTICLE_SCALAR_PRESSURE,1), &
0.0_rk, 'pressure scalar mismatch')
if (scalars(SPH_COUPLING_PARTICLE_SCALAR_ENERGY,1) < 0.0_rk) then
call fail('energy scalar mismatch')
end if
if (scalars(SPH_COUPLING_PARTICLE_SCALAR_TEMPERATURE,1) <= 0.0_rk) then
call fail('temperature scalar mismatch')
end if
if (scalars(SPH_COUPLING_PARTICLE_SCALAR_H,1) <= 0.0_rk) then
call fail('h scalar mismatch')
end if
call assert_close(vectors(1,SPH_COUPLING_PARTICLE_VECTOR_X,2), 0.1_rk, &
'position vector mismatch')
call assert_close(maxval(abs(vectors(:,SPH_COUPLING_PARTICLE_VECTOR_V,1))), &
0.0_rk, 'velocity vector mismatch')
call assert_close(maxval(abs(vectors(:,SPH_COUPLING_PARTICLE_VECTOR_A,1))), &
0.0_rk, 'acceleration vector mismatch')
call sph_coupling_get_region_particle_count('CONTACT_DISABLED', count, ierr)
call assert_ok(ierr, 'disabled particle count failed')
if (count /= 0) call fail('disabled region returned particles')
call sph_coupling_export_region_particles('CONTACT_DISABLED', 3, count, &
ext_ids, internal_ids, phases, statuses, materials, sections, &
scalars, vectors, ierr)
call assert_ok(ierr, 'disabled particle export failed')
if (count /= 0) call fail('disabled particle export count mismatch')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after particle export')
end subroutine check_particle_export
subroutine check_particle_export_errors()
integer :: count
integer :: ext_ids(3)
integer :: internal_ids(3)
integer :: phases(3)
integer :: statuses(3)
integer :: materials(3)
integer :: sections(3)
real(rk) :: scalars(SPH_COUPLING_PARTICLE_SCALAR_COUNT,3)
real(rk) :: vectors(SPH_NDIM,SPH_COUPLING_PARTICLE_VECTOR_COUNT,3)
call build_contact_case()
call sph_coupling_get_region_particle_count('NOT_A_REGION', count, ierr)
if (ierr == SPH_SUCCESS) call fail('invalid region count did not fail')
call sph_coupling_export_region_particles('CONTACT_PARTICLES', 2, count, &
ext_ids(1:2), internal_ids(1:2), phases(1:2), statuses(1:2), &
materials(1:2), sections(1:2), scalars(:,1:2), &
vectors(:,:,1:2), ierr)
if (ierr == SPH_SUCCESS) call fail('small particle capacity did not fail')
pressure(1) = huge(pressure(1))
call sph_coupling_export_region_particles('CONTACT_PARTICLES', 3, count, &
ext_ids, internal_ids, phases, statuses, materials, sections, &
scalars, vectors, ierr)
if (ierr == SPH_SUCCESS) call fail('nonfinite particle export did not fail')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after particle export errors')
end subroutine check_particle_export_errors
subroutine build_contact_case()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for contact export')
call sph_read_inp('tests/data/coupling_region_080.inp', ierr)
call assert_ok(ierr, 'read failed for contact export')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for contact export')
end subroutine build_contact_case
subroutine assert_ok(ierr_value, message)
integer, intent(in) :: ierr_value
character(len=*), intent(in) :: message
if (ierr_value /= SPH_SUCCESS) call fail(message)
end subroutine assert_ok
subroutine assert_close(actual, expected, message)
real(rk), intent(in) :: actual
real(rk), intent(in) :: expected
character(len=*), intent(in) :: message
if (abs(actual - expected) > 1.0e-12_rk) call fail(message)
end subroutine assert_close
subroutine fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_coupling_particle_export_080
+46 -46
View File
@@ -87,52 +87,52 @@
## 阶段 C:粒子导出和 Facet Proxy 导出
- [ ] 定义 coupling 粒子导出字段顺序。
- [ ] 定义 coupling 粒子 scalar 缓冲区字段顺序。
- [ ] 定义 coupling 粒子三维数组展开顺序。
- [ ] 实现按 region 查询 coupling 粒子数量。
- [ ] 实现按 region 导出 external particle id。
- [ ] 实现按 region 导出 internal particle index。
- [ ] 实现按 region 导出 particle phase。
- [ ] 实现按 region 导出 particle status。
- [ ] 实现按 region 导出 material id。
- [ ] 实现按 region 导出 section id。
- [ ] 实现按 region 导出 mass。
- [ ] 实现按 region 导出 volume。
- [ ] 实现按 region 导出 density。
- [ ] 实现按 region 导出 pressure。
- [ ] 实现按 region 导出 internal energy。
- [ ] 实现按 region 导出 temperature。
- [ ] 实现按 region 导出 smoothing length `h`。
- [ ] 实现按 region 导出 position `x`。
- [ ] 实现按 region 导出 velocity `v`。
- [ ] 实现按 region 导出 acceleration `a`。
- [ ] 对非法 region 名称返回 error。
- [ ] 对 disabled region 返回 0 个导出粒子。
- [ ] 对调用方容量不足返回 error。
- [ ] 对非有限导出状态记录诊断或返回 error。
- [ ] 定义 facet proxy 导出字段顺序。
- [ ] 定义 facet proxy 三维数组展开顺序。
- [ ] 实现 Shell coupling region 的 facet proxy 计数。
- [ ] 实现 Shell facet proxy 的 facet id。
- [ ] 实现 Shell facet proxy 的关联粒子 id。
- [ ] 实现 Shell facet proxy 的中心坐标。
- [ ] 实现 Shell facet proxy 的平均速度。
- [ ] 实现 Shell facet proxy 的法向。
- [ ] 实现 Shell facet proxy 的面积。
- [ ] 实现 Shell facet proxy 的 material 和 section 信息。
- [ ] 支持受控 surface/facet 输入的 facet proxy 占位导出。
- [ ] 明确 Solid 无 surface 时不自动重构复杂外表面。
- [ ] 对 `EXPORT=FACET` 但无 facet proxy 的 region 报 error。
- [ ] 对零面积 facet proxy 报 error。
- [ ] 对非有限法向或面积报 error。
- [ ] 新增 `coupling_particle_export_080` 测试。
- [ ] 新增 `coupling_facet_export_080` 测试。
- [ ] 新增 `coupling_facet_errors_080` 测试。
- [ ] 将阶段 C 新测试接入 CTest。
- [ ] 运行阶段 C coupling 导出专项测试。
- [ ] 运行 `git diff --check`。
- [ ] 准备阶段 C 本地提交说明。
- [x] 定义 coupling 粒子导出字段顺序。
- [x] 定义 coupling 粒子 scalar 缓冲区字段顺序。
- [x] 定义 coupling 粒子三维数组展开顺序。
- [x] 实现按 region 查询 coupling 粒子数量。
- [x] 实现按 region 导出 external particle id。
- [x] 实现按 region 导出 internal particle index。
- [x] 实现按 region 导出 particle phase。
- [x] 实现按 region 导出 particle status。
- [x] 实现按 region 导出 material id。
- [x] 实现按 region 导出 section id。
- [x] 实现按 region 导出 mass。
- [x] 实现按 region 导出 volume。
- [x] 实现按 region 导出 density。
- [x] 实现按 region 导出 pressure。
- [x] 实现按 region 导出 internal energy。
- [x] 实现按 region 导出 temperature。
- [x] 实现按 region 导出 smoothing length `h`。
- [x] 实现按 region 导出 position `x`。
- [x] 实现按 region 导出 velocity `v`。
- [x] 实现按 region 导出 acceleration `a`。
- [x] 对非法 region 名称返回 error。
- [x] 对 disabled region 返回 0 个导出粒子。
- [x] 对调用方容量不足返回 error。
- [x] 对非有限导出状态记录诊断或返回 error。
- [x] 定义 facet proxy 导出字段顺序。
- [x] 定义 facet proxy 三维数组展开顺序。
- [x] 实现 Shell coupling region 的 facet proxy 计数。
- [x] 实现 Shell facet proxy 的 facet id。
- [x] 实现 Shell facet proxy 的关联粒子 id。
- [x] 实现 Shell facet proxy 的中心坐标。
- [x] 实现 Shell facet proxy 的平均速度。
- [x] 实现 Shell facet proxy 的法向。
- [x] 实现 Shell facet proxy 的面积。
- [x] 实现 Shell facet proxy 的 material 和 section 信息。
- [x] 支持受控 surface/facet 输入的 facet proxy 占位导出。
- [x] 明确 Solid 无 surface 时不自动重构复杂外表面。
- [x] 对 `EXPORT=FACET` 但无 facet proxy 的 region 报 error。
- [x] 对零面积 facet proxy 报 error。
- [x] 对非有限法向或面积报 error。
- [x] 新增 `coupling_particle_export_080` 测试。
- [x] 新增 `coupling_facet_export_080` 测试。
- [x] 新增 `coupling_facet_errors_080` 测试。
- [x] 将阶段 C 新测试接入 CTest。
- [x] 运行阶段 C coupling 导出专项测试。
- [x] 运行 `git diff --check`。
- [x] 准备阶段 C 本地提交说明。
## 阶段 D:外部粒子力、Facet Load 和运动边界导入