diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d295ce..b2dbb61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,6 +226,24 @@ set_target_properties(test_shell_reference_geometry PROPERTIES Fortran_MODULE_DI add_test(NAME shell_reference_geometry COMMAND test_shell_reference_geometry) set_tests_properties(shell_reference_geometry PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +add_executable(test_shell_director_step tests/module/test_shell_director_update.f90) +target_link_libraries(test_shell_director_step PRIVATE sphlite_core) +set_target_properties(test_shell_director_step PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME shell_director_update COMMAND test_shell_director_step) +set_tests_properties(shell_director_update PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_shell_rotation_kinematics tests/module/test_shell_rotation_kinematics.f90) +target_link_libraries(test_shell_rotation_kinematics PRIVATE sphlite_core) +set_target_properties(test_shell_rotation_kinematics PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME shell_rotation_kinematics COMMAND test_shell_rotation_kinematics) +set_tests_properties(shell_rotation_kinematics PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_shell_local_frame tests/module/test_shell_local_frame.f90) +target_link_libraries(test_shell_local_frame PRIVATE sphlite_core) +set_target_properties(test_shell_local_frame PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME shell_local_frame COMMAND test_shell_local_frame) +set_tests_properties(shell_local_frame PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + add_executable(test_solid_051_input_validation tests/module/test_solid_051_input_validation.f90) target_link_libraries(test_solid_051_input_validation PRIVATE sphlite_core) set_target_properties(test_solid_051_input_validation PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") diff --git a/src/input/sph_input_reader.f90 b/src/input/sph_input_reader.f90 index fdb915a..6517a1e 100644 --- a/src/input/sph_input_reader.f90 +++ b/src/input/sph_input_reader.f90 @@ -28,6 +28,7 @@ module sph_input_reader sph_shell_set_johnson_cook, sph_shell_set_failure, & sph_shell_set_control, sph_shell_build_state, & sph_shell_add_orientation, sph_shell_set_director_for_set, & + sph_shell_set_rotation_for_set, & sph_shell_count_unbound_materials, sph_shell_count_unused_orientations use sph_solid_dynamics, only: sph_solid_set_body_force, & sph_solid_build_reference_state, sph_solid_update_diagnostics @@ -355,6 +356,8 @@ contains call sph_input_parse_ignition(line, ierr) else if (index(upper_line, 'SHELL DIRECTOR') > 0) then call sph_input_parse_shell_director(line, ierr) + else if (index(upper_line, 'SHELL ROTATION') > 0) then + call sph_input_parse_shell_rotation(line, ierr) else if (index(upper_line, 'SHELL CONTROL') > 0) then call sph_input_parse_shell_control(line, ierr) else if (index(upper_line, 'SOLID CONTROL') > 0) then @@ -753,6 +756,39 @@ contains call sph_shell_set_director_for_set(set_name, director, ierr) end subroutine sph_input_parse_shell_director + subroutine sph_input_parse_shell_rotation(line, ierr) + character(len=*), intent(in) :: line + integer, intent(out) :: ierr + character(len=SPH_INPUT_FIELD_LEN) :: set_name + real(rk) :: omega_value(SPH_NDIM) + real(rk) :: alpha_value(SPH_NDIM) + + ierr = SPH_SUCCESS + omega_value = 0.0_rk + alpha_value = 0.0_rk + call sph_input_get_option(line, 'SET', set_name) + if (len_trim(set_name) == 0) call sph_input_get_option(line, 'NSET', set_name) + if (len_trim(set_name) == 0) call sph_input_get_option(line, 'ELSET', set_name) + if (len_trim(set_name) == 0) then + call sph_input_set_error('Shell rotation is missing SET option') + ierr = SPH_ERROR_INPUT + return + end if + call sph_input_get_required_real(line, 'OX', omega_value(1), ierr) + if (ierr /= SPH_SUCCESS) return + call sph_input_get_required_real(line, 'OY', omega_value(2), ierr) + if (ierr /= SPH_SUCCESS) return + call sph_input_get_required_real(line, 'OZ', omega_value(3), ierr) + if (ierr /= SPH_SUCCESS) return + call sph_input_get_optional_real(line, 'AX', alpha_value(1), ierr) + if (ierr /= SPH_SUCCESS) return + call sph_input_get_optional_real(line, 'AY', alpha_value(2), ierr) + if (ierr /= SPH_SUCCESS) return + call sph_input_get_optional_real(line, 'AZ', alpha_value(3), ierr) + if (ierr /= SPH_SUCCESS) return + call sph_shell_set_rotation_for_set(set_name, omega_value, alpha_value, ierr) + end subroutine sph_input_parse_shell_rotation + subroutine sph_input_parse_orientation(line, ierr) character(len=*), intent(in) :: line integer, intent(out) :: ierr diff --git a/src/shell/sph_shell.f90 b/src/shell/sph_shell.f90 index 37adeae..36b6a99 100644 --- a/src/shell/sph_shell.f90 +++ b/src/shell/sph_shell.f90 @@ -25,11 +25,15 @@ module sph_shell integer, parameter :: SPH_SHELL_MAX_INTEGRATION_POINTS = 5 integer, parameter :: SPH_SHELL_MAX_ORIENTATIONS = 32 integer, parameter :: SPH_SHELL_MAX_DIRECTOR_SETS = 32 + integer, parameter :: SPH_SHELL_MAX_ROTATION_SETS = 32 integer, parameter :: SPH_SHELL_DIRECTOR_NONE = 0 integer, parameter :: SPH_SHELL_DIRECTOR_INPUT = 1 integer, parameter :: SPH_SHELL_DIRECTOR_ORIENTATION = 2 integer, parameter :: SPH_SHELL_DIRECTOR_GEOMETRY = 3 integer, parameter :: SPH_SHELL_DIRECTOR_DEGENERATE = -1 + integer, parameter :: SPH_SHELL_FRAME_NONE = 0 + integer, parameter :: SPH_SHELL_FRAME_OK = 1 + integer, parameter :: SPH_SHELL_FRAME_DEGENERATE = -1 real(rk), parameter :: SPH_SHELL_EPS = 1.0e-12_rk logical :: shell_material_seen = .false. integer :: shell_material_count = 0 @@ -61,16 +65,28 @@ module sph_shell character(len=SPH_NAME_LEN) :: shell_director_set_names(SPH_SHELL_MAX_DIRECTOR_SETS) = ' ' real(rk) :: shell_director_set_values(SPH_NDIM,SPH_SHELL_MAX_DIRECTOR_SETS) = 0.0_rk logical :: shell_director_set_used(SPH_SHELL_MAX_DIRECTOR_SETS) = .false. + integer :: shell_rotation_set_count = 0 + character(len=SPH_NAME_LEN) :: shell_rotation_set_names(SPH_SHELL_MAX_ROTATION_SETS) = ' ' + real(rk) :: shell_rotation_set_omega(SPH_NDIM,SPH_SHELL_MAX_ROTATION_SETS) = 0.0_rk + real(rk) :: shell_rotation_set_alpha(SPH_NDIM,SPH_SHELL_MAX_ROTATION_SETS) = 0.0_rk + logical :: shell_rotation_set_used(SPH_SHELL_MAX_ROTATION_SETS) = .false. integer :: shell_director_degenerate_count = 0 + integer :: shell_local_frame_degenerate_count = 0 integer :: shell_area_degenerate_count = 0 integer :: shell_inertia_degenerate_count = 0 real(rk) :: shell_director_max_length_error = 0.0_rk + real(rk) :: shell_max_angular_velocity = 0.0_rk real(rk), allocatable :: shell_thickness(:) real(rk), allocatable :: shell_director(:,:) real(rk), allocatable :: shell_reference_area(:) real(rk), allocatable :: shell_rotational_inertia(:) integer, allocatable :: shell_director_status(:) + real(rk), allocatable :: shell_local_e1(:,:) + real(rk), allocatable :: shell_local_e2(:,:) + real(rk), allocatable :: shell_local_e3(:,:) + integer, allocatable :: shell_local_frame_status(:) real(rk), allocatable :: shell_omega(:,:) + real(rk), allocatable :: shell_alpha(:,:) real(rk), allocatable :: shell_membrane_strain(:,:) real(rk), allocatable :: shell_bending_strain(:,:) real(rk), allocatable :: shell_shear_strain(:,:) @@ -137,10 +153,17 @@ contains shell_director_set_names = ' ' shell_director_set_values = 0.0_rk shell_director_set_used = .false. + shell_rotation_set_count = 0 + shell_rotation_set_names = ' ' + shell_rotation_set_omega = 0.0_rk + shell_rotation_set_alpha = 0.0_rk + shell_rotation_set_used = .false. shell_director_degenerate_count = 0 + shell_local_frame_degenerate_count = 0 shell_area_degenerate_count = 0 shell_inertia_degenerate_count = 0 shell_director_max_length_error = 0.0_rk + shell_max_angular_velocity = 0.0_rk end subroutine sph_shell_clear_orientation_table subroutine sph_shell_note_material(name, material_type_in) @@ -397,6 +420,66 @@ contains shell_director_set_used(set_index) = .false. end subroutine sph_shell_set_director_for_set + subroutine sph_shell_set_rotation_for_set(set_name, omega_value, alpha_value, ierr) + character(len=*), intent(in) :: set_name + real(rk), intent(in) :: omega_value(SPH_NDIM) + real(rk), intent(in) :: alpha_value(SPH_NDIM) + integer, intent(out) :: ierr + integer :: set_index + + ierr = SPH_SUCCESS + if (len_trim(set_name) == 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell rotation is missing SET') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_shell_vector_is_finite(omega_value)) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell angular velocity is not finite') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_shell_vector_is_finite(alpha_value)) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell angular acceleration is not finite') + ierr = SPH_ERROR_INPUT + return + end if + + set_index = sph_shell_find_rotation_set(set_name) + if (set_index <= 0) then + if (shell_rotation_set_count >= SPH_SHELL_MAX_ROTATION_SETS) then + call sph_error_set(SPH_ERROR_INPUT, 'too many Shell rotation set records') + ierr = SPH_ERROR_INPUT + return + end if + shell_rotation_set_count = shell_rotation_set_count + 1 + set_index = shell_rotation_set_count + end if + shell_rotation_set_names(set_index) = set_name + shell_rotation_set_omega(:,set_index) = omega_value + shell_rotation_set_alpha(:,set_index) = alpha_value + shell_rotation_set_used(set_index) = .false. + end subroutine sph_shell_set_rotation_for_set + + subroutine sph_shell_set_particle_angular_velocity(index, omega_value, ierr) + integer, intent(in) :: index + real(rk), intent(in) :: omega_value(SPH_NDIM) + integer, intent(out) :: ierr + + ierr = SPH_SUCCESS + if (index < 1 .or. index > npart .or. .not. allocated(shell_omega)) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell angular velocity index is invalid') + ierr = SPH_ERROR_ARGUMENT + return + end if + if (.not. sph_shell_vector_is_finite(omega_value)) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell angular velocity is not finite') + ierr = SPH_ERROR_ARGUMENT + return + end if + shell_omega(:,index) = omega_value + call sph_shell_update_max_angular_velocity() + end subroutine sph_shell_set_particle_angular_velocity + subroutine sph_shell_build_state(ierr) integer, intent(out) :: ierr @@ -427,12 +510,20 @@ contains if (size(shell_thickness) == npart .and. & allocated(shell_reference_area) .and. & allocated(shell_rotational_inertia) .and. & - allocated(shell_director_status)) return + allocated(shell_director_status) .and. & + allocated(shell_local_e1) .and. & + allocated(shell_local_e2) .and. & + allocated(shell_local_e3) .and. & + allocated(shell_local_frame_status) .and. & + allocated(shell_alpha)) return call sph_shell_deallocate_state() end if allocate(shell_thickness(npart), shell_director(SPH_NDIM,npart), & shell_reference_area(npart), shell_rotational_inertia(npart), & - shell_director_status(npart), shell_omega(SPH_NDIM,npart), & + shell_director_status(npart), shell_local_e1(SPH_NDIM,npart), & + shell_local_e2(SPH_NDIM,npart), shell_local_e3(SPH_NDIM,npart), & + shell_local_frame_status(npart), shell_omega(SPH_NDIM,npart), & + shell_alpha(SPH_NDIM,npart), & shell_membrane_strain(SPH_SHELL_MEMBRANE_COMPONENTS,npart), & shell_bending_strain(SPH_SHELL_BENDING_COMPONENTS,npart), & shell_shear_strain(SPH_SHELL_SHEAR_COMPONENTS,npart), & @@ -465,7 +556,12 @@ contains if (allocated(shell_reference_area)) deallocate(shell_reference_area) if (allocated(shell_rotational_inertia)) deallocate(shell_rotational_inertia) if (allocated(shell_director_status)) deallocate(shell_director_status) + if (allocated(shell_local_e1)) deallocate(shell_local_e1) + if (allocated(shell_local_e2)) deallocate(shell_local_e2) + if (allocated(shell_local_e3)) deallocate(shell_local_e3) + if (allocated(shell_local_frame_status)) deallocate(shell_local_frame_status) if (allocated(shell_omega)) deallocate(shell_omega) + if (allocated(shell_alpha)) deallocate(shell_alpha) if (allocated(shell_membrane_strain)) deallocate(shell_membrane_strain) if (allocated(shell_bending_strain)) deallocate(shell_bending_strain) if (allocated(shell_shear_strain)) deallocate(shell_shear_strain) @@ -490,7 +586,12 @@ contains if (allocated(shell_reference_area)) shell_reference_area = 0.0_rk if (allocated(shell_rotational_inertia)) shell_rotational_inertia = 0.0_rk if (allocated(shell_director_status)) shell_director_status = SPH_SHELL_DIRECTOR_NONE + if (allocated(shell_local_e1)) shell_local_e1 = 0.0_rk + if (allocated(shell_local_e2)) shell_local_e2 = 0.0_rk + if (allocated(shell_local_e3)) shell_local_e3 = 0.0_rk + if (allocated(shell_local_frame_status)) shell_local_frame_status = SPH_SHELL_FRAME_NONE if (allocated(shell_omega)) shell_omega = 0.0_rk + if (allocated(shell_alpha)) shell_alpha = 0.0_rk if (allocated(shell_membrane_strain)) shell_membrane_strain = 0.0_rk if (allocated(shell_bending_strain)) shell_bending_strain = 0.0_rk if (allocated(shell_shear_strain)) shell_shear_strain = 0.0_rk @@ -512,10 +613,13 @@ contains subroutine sph_shell_reset_build_diagnostics() shell_orientation_used = .false. shell_director_set_used = .false. + shell_rotation_set_used = .false. shell_director_degenerate_count = 0 + shell_local_frame_degenerate_count = 0 shell_area_degenerate_count = 0 shell_inertia_degenerate_count = 0 shell_director_max_length_error = 0.0_rk + shell_max_angular_velocity = 0.0_rk end subroutine sph_shell_reset_build_diagnostics subroutine sph_shell_initialize_particle_state(ierr) @@ -547,6 +651,10 @@ contains if (ierr /= SPH_SUCCESS) return call sph_shell_initialize_reference_measures(index, ierr) if (ierr /= SPH_SUCCESS) return + call sph_shell_initialize_local_frame(index, sec, ierr) + if (ierr /= SPH_SUCCESS) return + call sph_shell_initialize_rotation(index, ierr) + if (ierr /= SPH_SUCCESS) return shell_internal_energy(index) = internal_energy(index) shell_softening(index) = 1.0_rk shell_failure_status(index) = SPH_STATUS_ACTIVE @@ -658,6 +766,237 @@ contains end if end subroutine sph_shell_initialize_reference_measures + subroutine sph_shell_initialize_local_frame(index, sec, ierr) + integer, intent(in) :: index + integer, intent(in) :: sec + integer, intent(out) :: ierr + real(rk) :: e1(SPH_NDIM) + real(rk) :: e2(SPH_NDIM) + real(rk) :: e3(SPH_NDIM) + real(rk) :: tangent(SPH_NDIM) + real(rk) :: normalized(SPH_NDIM) + logical :: found + + ierr = SPH_SUCCESS + call sph_shell_normalize_vector(shell_director(:,index), e3, ierr) + if (ierr /= SPH_SUCCESS) then + call sph_shell_mark_local_frame_degenerate(index, & + 'Shell local frame director is degenerate', ierr) + return + end if + call sph_shell_find_frame_tangent(index, sec, tangent, found) + if (.not. found) call sph_shell_choose_fallback_tangent(e3, tangent) + e1 = tangent - sum(tangent * e3) * e3 + call sph_shell_normalize_vector(e1, normalized, ierr) + if (ierr /= SPH_SUCCESS) then + call sph_shell_mark_local_frame_degenerate(index, & + 'Shell local frame tangent is degenerate', ierr) + return + end if + e1 = normalized + e2 = sph_shell_cross(e3, e1) + call sph_shell_normalize_vector(e2, normalized, ierr) + if (ierr /= SPH_SUCCESS) then + call sph_shell_mark_local_frame_degenerate(index, & + 'Shell local frame normal is degenerate', ierr) + return + end if + e2 = normalized + call sph_shell_validate_local_frame(e1, e2, e3, ierr) + if (ierr /= SPH_SUCCESS) then + call sph_shell_mark_local_frame_degenerate(index, & + 'Shell local frame is not orthonormal', ierr) + return + end if + shell_local_e1(:,index) = e1 + shell_local_e2(:,index) = e2 + shell_local_e3(:,index) = e3 + shell_local_frame_status(index) = SPH_SHELL_FRAME_OK + end subroutine sph_shell_initialize_local_frame + + subroutine sph_shell_mark_local_frame_degenerate(index, message, ierr) + integer, intent(in) :: index + character(len=*), intent(in) :: message + integer, intent(out) :: ierr + + shell_local_frame_degenerate_count = shell_local_frame_degenerate_count + 1 + if (allocated(shell_local_frame_status)) then + shell_local_frame_status(index) = SPH_SHELL_FRAME_DEGENERATE + end if + call sph_error_set(SPH_ERROR_INPUT, message) + ierr = SPH_ERROR_INPUT + end subroutine sph_shell_mark_local_frame_degenerate + + subroutine sph_shell_find_frame_tangent(index, sec, tangent, found) + integer, intent(in) :: index + integer, intent(in) :: sec + real(rk), intent(out) :: tangent(SPH_NDIM) + logical, intent(out) :: found + integer :: orientation_index + + tangent = 0.0_rk + found = .false. + if (len_trim(section_orientation_name(sec)) > 0) then + orientation_index = sph_shell_find_orientation(section_orientation_name(sec)) + if (orientation_index > 0) then + tangent = shell_orientation_tangent(:,orientation_index) + found = .true. + return + end if + end if + call sph_shell_find_element_tangent(index, sec, tangent, found) + if (found) return + call sph_shell_find_cloud_tangent(sec, tangent, found) + end subroutine sph_shell_find_frame_tangent + + subroutine sph_shell_find_element_tangent(index, sec, tangent, found) + integer, intent(in) :: index + integer, intent(in) :: sec + real(rk), intent(out) :: tangent(SPH_NDIM) + logical, intent(out) :: found + integer :: set_index + integer :: member_index + integer :: elem_index + integer :: node1 + integer :: node2 + + tangent = 0.0_rk + found = .false. + set_index = sph_db_find_elset(section_name(sec)) + if (set_index <= 0) return + do member_index = 1, elset_member_count(set_index) + elem_index = sph_db_find_element(elset_members(member_index,set_index)) + if (elem_index <= 0) cycle + if (.not. sph_shell_element_contains_particle(elem_index, index)) cycle + if (element_conn_count(elem_index) < 2) cycle + node1 = sph_db_find_node(element_conn(1,elem_index)) + node2 = sph_db_find_node(element_conn(2,elem_index)) + if (node1 <= 0 .or. node2 <= 0) cycle + tangent = x0(:,node2) - x0(:,node1) + if (sph_shell_norm(tangent) > SPH_SHELL_EPS) then + found = .true. + return + end if + end do + end subroutine sph_shell_find_element_tangent + + subroutine sph_shell_find_cloud_tangent(sec, tangent, found) + integer, intent(in) :: sec + real(rk), intent(out) :: tangent(SPH_NDIM) + logical, intent(out) :: found + integer :: i + integer :: j + + tangent = 0.0_rk + found = .false. + do i = 1, npart + if (.not. sph_shell_particle_is_active_section(i, sec)) cycle + do j = i + 1, npart + if (.not. sph_shell_particle_is_active_section(j, sec)) cycle + tangent = x0(:,j) - x0(:,i) + if (sph_shell_norm(tangent) > SPH_SHELL_EPS) then + found = .true. + return + end if + end do + end do + end subroutine sph_shell_find_cloud_tangent + + subroutine sph_shell_choose_fallback_tangent(e3, tangent) + real(rk), intent(in) :: e3(SPH_NDIM) + real(rk), intent(out) :: tangent(SPH_NDIM) + + tangent = (/1.0_rk, 0.0_rk, 0.0_rk/) + if (abs(sum(tangent * e3)) > 0.90_rk) then + tangent = (/0.0_rk, 1.0_rk, 0.0_rk/) + end if + end subroutine sph_shell_choose_fallback_tangent + + subroutine sph_shell_validate_local_frame(e1, e2, e3, ierr) + real(rk), intent(in) :: e1(SPH_NDIM) + real(rk), intent(in) :: e2(SPH_NDIM) + real(rk), intent(in) :: e3(SPH_NDIM) + integer, intent(out) :: ierr + real(rk) :: handedness + + ierr = SPH_SUCCESS + if (.not. sph_shell_vector_is_finite(e1) .or. & + .not. sph_shell_vector_is_finite(e2) .or. & + .not. sph_shell_vector_is_finite(e3)) then + ierr = SPH_ERROR_INPUT + return + end if + if (abs(sph_shell_norm(e1) - 1.0_rk) > 1.0e-8_rk) ierr = SPH_ERROR_INPUT + if (abs(sph_shell_norm(e2) - 1.0_rk) > 1.0e-8_rk) ierr = SPH_ERROR_INPUT + if (abs(sph_shell_norm(e3) - 1.0_rk) > 1.0e-8_rk) ierr = SPH_ERROR_INPUT + if (abs(sum(e1 * e2)) > 1.0e-8_rk) ierr = SPH_ERROR_INPUT + if (abs(sum(e1 * e3)) > 1.0e-8_rk) ierr = SPH_ERROR_INPUT + if (abs(sum(e2 * e3)) > 1.0e-8_rk) ierr = SPH_ERROR_INPUT + handedness = sum(sph_shell_cross(e1, e2) * e3) + if (handedness < 1.0_rk - 1.0e-8_rk) ierr = SPH_ERROR_INPUT + end subroutine sph_shell_validate_local_frame + + subroutine sph_shell_initialize_rotation(index, ierr) + integer, intent(in) :: index + integer, intent(out) :: ierr + integer :: set_index + + ierr = SPH_SUCCESS + shell_omega(:,index) = 0.0_rk + shell_alpha(:,index) = 0.0_rk + do set_index = 1, shell_rotation_set_count + if (.not. sph_shell_particle_in_named_set(index, & + shell_rotation_set_names(set_index))) cycle + shell_omega(:,index) = shell_rotation_set_omega(:,set_index) + shell_alpha(:,index) = shell_rotation_set_alpha(:,set_index) + shell_rotation_set_used(set_index) = .true. + exit + end do + if (.not. sph_shell_vector_is_finite(shell_omega(:,index))) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell angular velocity is not finite') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_shell_vector_is_finite(shell_alpha(:,index))) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell angular acceleration is not finite') + ierr = SPH_ERROR_INPUT + return + end if + if (sph_shell_norm(shell_omega(:,index)) > shell_max_angular_velocity) then + shell_max_angular_velocity = sph_shell_norm(shell_omega(:,index)) + end if + end subroutine sph_shell_initialize_rotation + + subroutine sph_shell_update_directors(dt, ierr) + real(rk), intent(in) :: dt + integer, intent(out) :: ierr + integer :: i + real(rk) :: updated_director(SPH_NDIM) + + ierr = SPH_SUCCESS + if (.not. allocated(shell_director)) return + if (.not. sph_shell_scalar_is_finite(dt) .or. dt < 0.0_rk) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell director update dt is invalid') + ierr = SPH_ERROR_ARGUMENT + return + end if + do i = 1, npart + if (.not. sph_shell_particle_is_active_section(i, section_id(i))) cycle + if (.not. sph_shell_vector_is_finite(shell_omega(:,i))) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell angular velocity is not finite') + ierr = SPH_ERROR_INPUT + return + end if + updated_director = shell_director(:,i) + & + dt * sph_shell_cross(shell_omega(:,i), shell_director(:,i)) + call sph_shell_apply_director(i, updated_director, shell_director_status(i), ierr) + if (ierr /= SPH_SUCCESS) return + call sph_shell_initialize_local_frame(i, section_id(i), ierr) + if (ierr /= SPH_SUCCESS) return + end do + call sph_shell_update_max_angular_velocity() + end subroutine sph_shell_update_directors + subroutine sph_shell_find_director_for_particle(index, director_value, found) integer, intent(in) :: index real(rk), intent(out) :: director_value(SPH_NDIM) @@ -1164,6 +1503,35 @@ contains end do end function sph_shell_find_director_set + integer function sph_shell_find_rotation_set(name) + character(len=*), intent(in) :: name + integer :: i + + sph_shell_find_rotation_set = 0 + do i = 1, shell_rotation_set_count + if (trim(sph_shell_upper(shell_rotation_set_names(i))) == & + trim(sph_shell_upper(name))) then + sph_shell_find_rotation_set = i + return + end if + end do + end function sph_shell_find_rotation_set + + subroutine sph_shell_update_max_angular_velocity() + integer :: i + real(rk) :: omega_norm + + shell_max_angular_velocity = 0.0_rk + if (.not. allocated(shell_omega)) return + do i = 1, npart + if (.not. sph_shell_particle_is_active_section(i, section_id(i))) cycle + omega_norm = sph_shell_norm(shell_omega(:,i)) + if (omega_norm > shell_max_angular_velocity) then + shell_max_angular_velocity = omega_norm + end if + end do + end subroutine sph_shell_update_max_angular_velocity + integer function sph_shell_find_material(name) character(len=*), intent(in) :: name integer :: i diff --git a/tests/module/test_shell_director_update.f90 b/tests/module/test_shell_director_update.f90 new file mode 100644 index 0000000..b27adda --- /dev/null +++ b/tests/module/test_shell_director_update.f90 @@ -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 diff --git a/tests/module/test_shell_local_frame.f90 b/tests/module/test_shell_local_frame.f90 new file mode 100644 index 0000000..3291434 --- /dev/null +++ b/tests/module/test_shell_local_frame.f90 @@ -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 diff --git a/tests/module/test_shell_rotation_kinematics.f90 b/tests/module/test_shell_rotation_kinematics.f90 new file mode 100644 index 0000000..13ebb7e --- /dev/null +++ b/tests/module/test_shell_rotation_kinematics.f90 @@ -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 diff --git a/todo.md b/todo.md index c322c4e..d4c09b2 100644 --- a/todo.md +++ b/todo.md @@ -78,39 +78,39 @@ ## 阶段 C:局部坐标系、转动状态和 director 更新 -- [ ] 设计 Shell 局部基向量数组布局。 -- [ ] 新增或补齐 `shell_local_e1` 状态或工作数组。 -- [ ] 新增或补齐 `shell_local_e2` 状态或工作数组。 -- [ ] 新增或补齐 `shell_local_e3` 状态或工作数组。 -- [ ] 新增 Shell local frame status 状态数组。 -- [ ] 在 Shell allocate/build 路径分配局部基状态。 -- [ ] 在 Shell reset 路径初始化局部基状态。 -- [ ] 在 Shell clear/finalize 路径释放局部基状态。 -- [ ] 由 director 构造 Shell 局部 `e3`。 -- [ ] 由 orientation 或参考面构造 Shell 局部 `e1`。 -- [ ] 由 `e3 cross e1` 构造 Shell 局部 `e2`。 -- [ ] 对 Shell 局部基执行有限性检查。 -- [ ] 对 Shell 局部基执行正交性检查。 -- [ ] 对 Shell 局部基执行右手性检查。 -- [ ] 记录局部基退化数量诊断。 -- [ ] 新增或补齐 Shell angular acceleration 工作数组。 -- [ ] 在 Shell reset 路径初始化 angular velocity 默认值。 -- [ ] 在 Shell reset 路径初始化 angular acceleration 默认值。 -- [ ] 对非 Shell 粒子设置安全转动状态默认值。 -- [ ] 新增 Shell 内部测试辅助过程以设置角速度。 -- [ ] 实现 Shell director 小转动更新入口。 -- [ ] 在 director 更新后执行归一化保护。 -- [ ] 在 director 更新后刷新局部基。 -- [ ] 对 Shell 转动状态执行有限性检查。 -- [ ] 计算 Shell 最大角速度诊断。 -- [ ] 确认无 active Shell 粒子时跳过局部基和转动更新。 -- [ ] 确认局部基和转动状态不污染 Solid 粒子。 -- [ ] 新增 `shell_director_update` 测试。 -- [ ] 新增 `shell_rotation_kinematics` 测试。 -- [ ] 新增 `shell_local_frame` 测试。 -- [ ] 将 `shell_director_update` 接入 CTest。 -- [ ] 将 `shell_rotation_kinematics` 接入 CTest。 -- [ ] 将 `shell_local_frame` 接入 CTest。 +- [x] 设计 Shell 局部基向量数组布局。 +- [x] 新增或补齐 `shell_local_e1` 状态或工作数组。 +- [x] 新增或补齐 `shell_local_e2` 状态或工作数组。 +- [x] 新增或补齐 `shell_local_e3` 状态或工作数组。 +- [x] 新增 Shell local frame status 状态数组。 +- [x] 在 Shell allocate/build 路径分配局部基状态。 +- [x] 在 Shell reset 路径初始化局部基状态。 +- [x] 在 Shell clear/finalize 路径释放局部基状态。 +- [x] 由 director 构造 Shell 局部 `e3`。 +- [x] 由 orientation 或参考面构造 Shell 局部 `e1`。 +- [x] 由 `e3 cross e1` 构造 Shell 局部 `e2`。 +- [x] 对 Shell 局部基执行有限性检查。 +- [x] 对 Shell 局部基执行正交性检查。 +- [x] 对 Shell 局部基执行右手性检查。 +- [x] 记录局部基退化数量诊断。 +- [x] 新增或补齐 Shell angular acceleration 工作数组。 +- [x] 在 Shell reset 路径初始化 angular velocity 默认值。 +- [x] 在 Shell reset 路径初始化 angular acceleration 默认值。 +- [x] 对非 Shell 粒子设置安全转动状态默认值。 +- [x] 新增 Shell 内部测试辅助过程以设置角速度。 +- [x] 实现 Shell director 小转动更新入口。 +- [x] 在 director 更新后执行归一化保护。 +- [x] 在 director 更新后刷新局部基。 +- [x] 对 Shell 转动状态执行有限性检查。 +- [x] 计算 Shell 最大角速度诊断。 +- [x] 确认无 active Shell 粒子时跳过局部基和转动更新。 +- [x] 确认局部基和转动状态不污染 Solid 粒子。 +- [x] 新增 `shell_director_update` 测试。 +- [x] 新增 `shell_rotation_kinematics` 测试。 +- [x] 新增 `shell_local_frame` 测试。 +- [x] 将 `shell_director_update` 接入 CTest。 +- [x] 将 `shell_rotation_kinematics` 接入 CTest。 +- [x] 将 `shell_local_frame` 接入 CTest。 ## 阶段 D:Mindlin-Reissner 小变形膜、弯曲和剪切应变