Add Shell local frame and rotation kinematics

This commit is contained in:
Codex
2026-07-03 21:17:45 +08:00
parent db995ab978
commit 4619fdf4ac
7 changed files with 710 additions and 35 deletions
@@ -0,0 +1,73 @@
program test_shell_director_step
use sph_precision, only: rk
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
use sph_shell, only: shell_director, shell_local_e3, shell_local_frame_status, &
shell_max_angular_velocity, SPH_SHELL_FRAME_OK, &
sph_shell_set_particle_angular_velocity, sph_shell_update_directors
implicit none
integer :: ierr
call check_director_update()
call check_no_active_shell_update()
contains
subroutine check_director_update()
real(rk) :: omega_value(3)
real(rk) :: expected(3)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Shell director update')
call sph_read_inp('tests/data/shell_director_input_061.inp', ierr)
call assert_ok(ierr, 'read failed for Shell director update')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Shell director update')
omega_value = (/0.0_rk, 10.0_rk, 0.0_rk/)
call sph_shell_set_particle_angular_velocity(1, omega_value, ierr)
call assert_ok(ierr, 'set Shell angular velocity failed')
call sph_shell_update_directors(0.01_rk, ierr)
call assert_ok(ierr, 'Shell director update failed')
expected = (/0.1_rk, 0.0_rk, 1.0_rk/)
expected = expected / sqrt(sum(expected * expected))
if (any(abs(shell_director(:,1) - expected) > 1.0e-10_rk)) &
call fail('Shell director update mismatch')
if (any(abs(shell_local_e3(:,1) - shell_director(:,1)) > 1.0e-12_rk)) &
call fail('Shell local e3 not refreshed')
if (shell_local_frame_status(1) /= SPH_SHELL_FRAME_OK) &
call fail('Shell local frame status not OK after update')
if (abs(shell_max_angular_velocity - 10.0_rk) > 1.0e-12_rk) &
call fail('Shell max angular velocity mismatch after update')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Shell director update')
end subroutine check_director_update
subroutine check_no_active_shell_update()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for no-Shell update')
call sph_read_inp('tests/data/solid_elastic_minimal_050.inp', ierr)
call assert_ok(ierr, 'read failed for no-Shell update')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for no-Shell update')
call sph_shell_update_directors(0.01_rk, ierr)
call assert_ok(ierr, 'no-Shell update should be a no-op')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for no-Shell update')
end subroutine check_no_active_shell_update
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_shell_director_step
+111
View File
@@ -0,0 +1,111 @@
program test_shell_local_frame
use sph_precision, only: rk
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
use sph_shell, only: shell_local_e1, shell_local_e2, shell_local_e3, &
shell_local_frame_status, SPH_SHELL_FRAME_OK, SPH_SHELL_FRAME_NONE
implicit none
integer :: ierr
call check_orientation_frame()
call check_reference_frame()
call check_non_shell_frame_defaults()
contains
subroutine check_orientation_frame()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Shell orientation frame')
call sph_read_inp('tests/data/shell_section_orientation_061.inp', ierr)
call assert_ok(ierr, 'read failed for Shell orientation frame')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Shell orientation frame')
call assert_frame(1, 'orientation Shell frame')
if (any(abs(shell_local_e1(:,1) - (/1.0_rk, 0.0_rk, 0.0_rk/)) > &
1.0e-12_rk)) call fail('orientation Shell e1 mismatch')
if (any(abs(shell_local_e2(:,1) - (/0.0_rk, 1.0_rk, 0.0_rk/)) > &
1.0e-12_rk)) call fail('orientation Shell e2 mismatch')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Shell orientation frame')
end subroutine check_orientation_frame
subroutine check_reference_frame()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Shell reference frame')
call sph_read_inp('tests/data/shell_reference_triangle_061.inp', ierr)
call assert_ok(ierr, 'read failed for Shell reference frame')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Shell reference frame')
call assert_frame(1, 'reference Shell frame')
if (any(abs(shell_local_e3(:,1) - (/0.0_rk, 0.0_rk, 1.0_rk/)) > &
1.0e-12_rk)) call fail('reference Shell e3 mismatch')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Shell reference frame')
end subroutine check_reference_frame
subroutine check_non_shell_frame_defaults()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Shell frame isolation')
call sph_read_inp('tests/data/shell_solid_kinematics_isolation_061.inp', ierr)
call assert_ok(ierr, 'read failed for Shell frame isolation')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Shell frame isolation')
if (any(abs(shell_local_e1(:,3)) > 1.0e-12_rk)) &
call fail('Solid particle Shell e1 default changed')
if (any(abs(shell_local_e2(:,3)) > 1.0e-12_rk)) &
call fail('Solid particle Shell e2 default changed')
if (any(abs(shell_local_e3(:,3)) > 1.0e-12_rk)) &
call fail('Solid particle Shell e3 default changed')
if (shell_local_frame_status(3) /= SPH_SHELL_FRAME_NONE) &
call fail('Solid particle Shell frame status default changed')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Shell frame isolation')
end subroutine check_non_shell_frame_defaults
subroutine assert_frame(index, label)
integer, intent(in) :: index
character(len=*), intent(in) :: label
real(rk) :: handedness
if (shell_local_frame_status(index) /= SPH_SHELL_FRAME_OK) &
call fail(trim(label) // ' status mismatch')
if (abs(sqrt(sum(shell_local_e1(:,index) * shell_local_e1(:,index))) - &
1.0_rk) > 1.0e-12_rk) call fail(trim(label) // ' e1 norm mismatch')
if (abs(sqrt(sum(shell_local_e2(:,index) * shell_local_e2(:,index))) - &
1.0_rk) > 1.0e-12_rk) call fail(trim(label) // ' e2 norm mismatch')
if (abs(sqrt(sum(shell_local_e3(:,index) * shell_local_e3(:,index))) - &
1.0_rk) > 1.0e-12_rk) call fail(trim(label) // ' e3 norm mismatch')
if (abs(sum(shell_local_e1(:,index) * shell_local_e2(:,index))) > &
1.0e-12_rk) call fail(trim(label) // ' e1/e2 not orthogonal')
handedness = sum(cross(shell_local_e1(:,index), shell_local_e2(:,index)) * &
shell_local_e3(:,index))
if (abs(handedness - 1.0_rk) > 1.0e-12_rk) &
call fail(trim(label) // ' handedness mismatch')
end subroutine assert_frame
function cross(left, right) result(out)
real(rk), intent(in) :: left(3)
real(rk), intent(in) :: right(3)
real(rk) :: out(3)
out(1) = left(2) * right(3) - left(3) * right(2)
out(2) = left(3) * right(1) - left(1) * right(3)
out(3) = left(1) * right(2) - left(2) * right(1)
end function cross
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_shell_local_frame
@@ -0,0 +1,69 @@
program test_shell_rotation_kinematics
use sph_precision, only: rk
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
use sph_shell, only: shell_omega, shell_alpha, shell_director, &
shell_max_angular_velocity, sph_shell_update_directors
implicit none
integer :: ierr
call check_rotation_input()
call check_solid_isolation()
contains
subroutine check_rotation_input()
real(rk) :: before(3)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Shell rotation input')
call sph_read_inp('tests/data/shell_angular_velocity_update_061.inp', ierr)
call assert_ok(ierr, 'read failed for Shell rotation input')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Shell rotation input')
before = shell_director(:,1)
if (any(abs(shell_omega(:,1) - (/0.0_rk, 10.0_rk, 0.0_rk/)) > &
1.0e-12_rk)) call fail('Shell angular velocity input mismatch')
if (any(abs(shell_alpha(:,1)) > 1.0e-12_rk)) &
call fail('Shell angular acceleration default mismatch')
if (abs(shell_max_angular_velocity - 10.0_rk) > 1.0e-12_rk) &
call fail('Shell max angular velocity input mismatch')
call sph_shell_update_directors(0.01_rk, ierr)
call assert_ok(ierr, 'Shell rotation input update failed')
if (abs(shell_director(1,1) - before(1)) < 1.0e-6_rk) &
call fail('Shell input rotation did not move director')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Shell rotation input')
end subroutine check_rotation_input
subroutine check_solid_isolation()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Shell rotation isolation')
call sph_read_inp('tests/data/shell_solid_kinematics_isolation_061.inp', ierr)
call assert_ok(ierr, 'read failed for Shell rotation isolation')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Shell rotation isolation')
if (any(abs(shell_omega(:,3)) > 1.0e-12_rk)) &
call fail('Solid particle Shell omega default changed')
if (any(abs(shell_alpha(:,3)) > 1.0e-12_rk)) &
call fail('Solid particle Shell alpha default changed')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Shell rotation isolation')
end subroutine check_solid_isolation
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_shell_rotation_kinematics