From db995ab9785eab571f35037a9aafc734792b6243 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 3 Jul 2026 20:49:03 +0800 Subject: [PATCH] Add Shell director input and reference geometry --- CMakeLists.txt | 12 + src/database/sph_database.f90 | 6 +- src/input/sph_inp_defs.f90 | 1 + src/input/sph_inp_helpers.f90 | 5 +- src/input/sph_input_reader.f90 | 83 ++- src/shell/sph_shell.f90 | 628 +++++++++++++++++- tests/data/shell_johnson_cook_failure_060.inp | 1 + tests/data/shell_solid_mixed_060.inp | 1 + .../shell_unbound_material_warning_060.inp | 1 + .../shell_unused_orientation_warning_061.inp | 19 + tests/module/test_shell_director_input.f90 | 101 +++ .../module/test_shell_reference_geometry.f90 | 105 +++ todo.md | 64 +- 13 files changed, 982 insertions(+), 45 deletions(-) create mode 100644 tests/data/shell_unused_orientation_warning_061.inp create mode 100644 tests/module/test_shell_director_input.f90 create mode 100644 tests/module/test_shell_reference_geometry.f90 diff --git a/CMakeLists.txt b/CMakeLists.txt index 39c27e8..1d295ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -214,6 +214,18 @@ set_target_properties(test_shell_section_integration PROPERTIES Fortran_MODULE_D add_test(NAME shell_section_integration COMMAND test_shell_section_integration) set_tests_properties(shell_section_integration PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +add_executable(test_shell_director_input tests/module/test_shell_director_input.f90) +target_link_libraries(test_shell_director_input PRIVATE sphlite_core) +set_target_properties(test_shell_director_input PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME shell_director_input COMMAND test_shell_director_input) +set_tests_properties(shell_director_input PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_shell_reference_geometry tests/module/test_shell_reference_geometry.f90) +target_link_libraries(test_shell_reference_geometry PRIVATE sphlite_core) +set_target_properties(test_shell_reference_geometry PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +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_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/database/sph_database.f90 b/src/database/sph_database.f90 index 47ffa41..edf24f5 100644 --- a/src/database/sph_database.f90 +++ b/src/database/sph_database.f90 @@ -121,6 +121,7 @@ module sph_database character(len=SPH_NAME_LEN) :: section_name(SPH_MAX_SECTIONS) character(len=SPH_NAME_LEN) :: section_type(SPH_MAX_SECTIONS) character(len=SPH_NAME_LEN) :: section_material_name(SPH_MAX_SECTIONS) + character(len=SPH_NAME_LEN) :: section_orientation_name(SPH_MAX_SECTIONS) integer :: section_material_id(SPH_MAX_SECTIONS) real(rk) :: section_thickness(SPH_MAX_SECTIONS) integer :: section_integration_points(SPH_MAX_SECTIONS) @@ -268,6 +269,7 @@ contains section_name = ' ' section_type = ' ' section_material_name = ' ' + section_orientation_name = ' ' section_material_id = 0 section_thickness = 0.0_rk section_integration_points = 0 @@ -503,13 +505,14 @@ contains end subroutine sph_db_set_material_density subroutine sph_db_add_section(name, stype, mat_name, thickness, points, & - shear_correction, ierr) + shear_correction, orientation_name, ierr) character(len=*), intent(in) :: name character(len=*), intent(in) :: stype character(len=*), intent(in) :: mat_name real(rk), intent(in) :: thickness integer, intent(in) :: points real(rk), intent(in) :: shear_correction + character(len=*), intent(in) :: orientation_name integer, intent(out) :: ierr integer :: mat_index integer :: set_index @@ -537,6 +540,7 @@ contains section_name(section_count) = name section_type(section_count) = stype section_material_name(section_count) = mat_name + section_orientation_name(section_count) = orientation_name section_material_id(section_count) = mat_index section_thickness(section_count) = thickness section_integration_points(section_count) = points diff --git a/src/input/sph_inp_defs.f90 b/src/input/sph_inp_defs.f90 index f01ee9a..493c42a 100644 --- a/src/input/sph_inp_defs.f90 +++ b/src/input/sph_inp_defs.f90 @@ -17,6 +17,7 @@ module sph_inp_defs integer, parameter :: SPH_KEY_ELASTIC = 9 integer, parameter :: SPH_KEY_PLASTIC = 10 integer, parameter :: SPH_KEY_DAMAGE_INITIATION = 11 + integer, parameter :: SPH_KEY_ORIENTATION = 12 integer, parameter :: SPH_KEY_UNKNOWN = 99 end module sph_inp_defs diff --git a/src/input/sph_inp_helpers.f90 b/src/input/sph_inp_helpers.f90 index 1ea4edb..b9ecc91 100644 --- a/src/input/sph_inp_helpers.f90 +++ b/src/input/sph_inp_helpers.f90 @@ -2,7 +2,8 @@ module sph_inp_helpers use sph_inp_defs, only: SPH_INPUT_LINE_LEN, SPH_KEY_NODE, SPH_KEY_ELEMENT, & SPH_KEY_NSET, SPH_KEY_ELSET, SPH_KEY_MATERIAL, SPH_KEY_SECTION, & SPH_KEY_SPHLITE, SPH_KEY_DENSITY, SPH_KEY_ELASTIC, & - SPH_KEY_PLASTIC, SPH_KEY_DAMAGE_INITIATION, SPH_KEY_UNKNOWN + SPH_KEY_PLASTIC, SPH_KEY_DAMAGE_INITIATION, SPH_KEY_ORIENTATION, & + SPH_KEY_UNKNOWN implicit none contains @@ -92,6 +93,8 @@ contains key_id = SPH_KEY_PLASTIC else if (index(upper, '*DAMAGE INITIATION') == 1) then key_id = SPH_KEY_DAMAGE_INITIATION + else if (index(upper, '*ORIENTATION') == 1) then + key_id = SPH_KEY_ORIENTATION else if (index(upper, 'SECTION') > 0 .and. upper(1:1) == '*') then key_id = SPH_KEY_SECTION end if diff --git a/src/input/sph_input_reader.f90 b/src/input/sph_input_reader.f90 index 0ad4e4e..fdb915a 100644 --- a/src/input/sph_input_reader.f90 +++ b/src/input/sph_input_reader.f90 @@ -27,7 +27,8 @@ module sph_input_reader use sph_shell, only: sph_shell_note_material, sph_shell_set_elastic, & sph_shell_set_johnson_cook, sph_shell_set_failure, & sph_shell_set_control, sph_shell_build_state, & - sph_shell_count_unbound_materials + sph_shell_add_orientation, sph_shell_set_director_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 use sph_neighbor, only: sph_neighbor_rebuild @@ -35,7 +36,7 @@ module sph_input_reader SPH_INPUT_MAX_FIELDS, SPH_KEY_NODE, SPH_KEY_ELEMENT, SPH_KEY_NSET, & SPH_KEY_ELSET, SPH_KEY_MATERIAL, SPH_KEY_SECTION, SPH_KEY_SPHLITE, & SPH_KEY_DENSITY, SPH_KEY_ELASTIC, SPH_KEY_PLASTIC, & - SPH_KEY_DAMAGE_INITIATION, SPH_KEY_UNKNOWN + SPH_KEY_DAMAGE_INITIATION, SPH_KEY_ORIENTATION, SPH_KEY_UNKNOWN use sph_inp_helpers, only: sph_inp_clean_line, sph_inp_split_csv, & sph_inp_keyword_id, sph_inp_upper implicit none @@ -51,6 +52,7 @@ module sph_input_reader character(len=SPH_INPUT_FIELD_LEN) :: active_nset_name = 'NSET' character(len=SPH_INPUT_FIELD_LEN) :: active_elset_name = 'ELSET' character(len=SPH_INPUT_FIELD_LEN) :: active_material_name = 'MATERIAL' + character(len=SPH_INPUT_FIELD_LEN) :: active_orientation_name = 'ORIENTATION' contains @@ -65,6 +67,7 @@ contains active_nset_name = 'NSET' active_elset_name = 'ELSET' active_material_name = 'MATERIAL' + active_orientation_name = 'ORIENTATION' end subroutine sph_input_reset subroutine sph_input_get_warning_count(count) @@ -93,6 +96,7 @@ contains integer :: explosive_unbound_count integer :: solid_unbound_count integer :: shell_unbound_count + integer :: shell_unused_orientation_count ierr = SPH_SUCCESS if (npart <= 0) then @@ -135,6 +139,8 @@ contains input_warning_count = input_warning_count + solid_unbound_count call sph_shell_count_unbound_materials(shell_unbound_count) input_warning_count = input_warning_count + shell_unbound_count + call sph_shell_count_unused_orientations(shell_unused_orientation_count) + input_warning_count = input_warning_count + shell_unused_orientation_count call sph_solid_build_reference_state(ierr) if (ierr /= SPH_SUCCESS) return call sph_solid_update_diagnostics(ierr) @@ -277,6 +283,12 @@ contains close(unit=SPH_INPUT_UNIT) return end if + else if (active_key == SPH_KEY_ORIENTATION) then + call sph_input_parse_orientation(line, ierr) + if (ierr /= SPH_SUCCESS) then + close(unit=SPH_INPUT_UNIT) + return + end if end if end do @@ -291,6 +303,7 @@ contains character(len=SPH_INPUT_FIELD_LEN) :: material_value character(len=SPH_INPUT_FIELD_LEN) :: section_value character(len=SPH_INPUT_FIELD_LEN) :: section_type_value + character(len=SPH_INPUT_FIELD_LEN) :: orientation_value character(len=SPH_INPUT_FIELD_LEN) :: type_value real(rk) :: thickness real(rk) :: shear_correction @@ -340,6 +353,8 @@ contains call sph_input_parse_explosive_control(line, ierr) else if (index(upper_line, 'IGNITION') > 0) then 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 CONTROL') > 0) then call sph_input_parse_shell_control(line, ierr) else if (index(upper_line, 'SOLID CONTROL') > 0) then @@ -356,6 +371,12 @@ contains else if (key_id == SPH_KEY_ELSET) then call sph_input_get_option(line, 'ELSET', active_elset_name) if (len_trim(active_elset_name) == 0) active_elset_name = 'ELSET' + else if (key_id == SPH_KEY_ORIENTATION) then + call sph_input_get_option(line, 'NAME', active_orientation_name) + if (len_trim(active_orientation_name) == 0) then + call sph_input_set_error('Orientation is missing NAME option') + ierr = SPH_ERROR_INPUT + end if else if (key_id == SPH_KEY_UNKNOWN) then input_warning_count = input_warning_count + 1 end if @@ -370,6 +391,7 @@ contains character(len=SPH_INPUT_FIELD_LEN) :: material_value character(len=SPH_INPUT_FIELD_LEN) :: section_value character(len=SPH_INPUT_FIELD_LEN) :: section_type_value + character(len=SPH_INPUT_FIELD_LEN) :: orientation_value real(rk) :: thickness real(rk) :: shear_correction integer :: points @@ -384,6 +406,7 @@ contains if (len_trim(section_value) == 0) call sph_input_get_option(line, 'NSET', section_value) if (len_trim(section_value) == 0) section_value = 'SECTION' call sph_input_get_option(line, 'MATERIAL', material_value) + call sph_input_get_option(line, 'ORIENTATION', orientation_value) thickness = 0.0_rk points = 3 shear_correction = 5.0_rk / 6.0_rk @@ -423,7 +446,7 @@ contains if (len_trim(material_value) == 0) material_value = 'MATERIAL' end if call sph_db_add_section(section_value, section_type_value, material_value, & - thickness, points, shear_correction, ierr) + thickness, points, shear_correction, orientation_value, ierr) end subroutine sph_input_parse_section_keyword subroutine sph_input_validate_solid_section(material_value, section_type_value, ierr) @@ -705,6 +728,60 @@ contains call sph_shell_set_control(material_name, softening_name, width, ierr) end subroutine sph_input_parse_shell_control + subroutine sph_input_parse_shell_director(line, ierr) + character(len=*), intent(in) :: line + integer, intent(out) :: ierr + character(len=SPH_INPUT_FIELD_LEN) :: set_name + real(rk) :: director(SPH_NDIM) + + ierr = SPH_SUCCESS + director = 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 director is missing SET option') + ierr = SPH_ERROR_INPUT + return + end if + call sph_input_get_required_real(line, 'NX', director(1), ierr) + if (ierr /= SPH_SUCCESS) return + call sph_input_get_required_real(line, 'NY', director(2), ierr) + if (ierr /= SPH_SUCCESS) return + call sph_input_get_required_real(line, 'NZ', director(3), ierr) + if (ierr /= SPH_SUCCESS) return + call sph_shell_set_director_for_set(set_name, director, ierr) + end subroutine sph_input_parse_shell_director + + subroutine sph_input_parse_orientation(line, ierr) + character(len=*), intent(in) :: line + integer, intent(out) :: ierr + character(len=SPH_INPUT_FIELD_LEN) :: fields(SPH_INPUT_MAX_FIELDS) + integer :: nfields + integer :: i + integer :: ios + real(rk) :: values(6) + + ierr = SPH_SUCCESS + values = 0.0_rk + call sph_inp_split_csv(line, fields, nfields) + if (nfields < 6) then + call sph_input_set_error('invalid *ORIENTATION record') + ierr = SPH_ERROR_INPUT + return + end if + do i = 1, 6 + read(fields(i), *, iostat=ios) values(i) + if (ios /= 0) then + call sph_input_set_error('invalid *ORIENTATION numeric value') + ierr = SPH_ERROR_INPUT + return + end if + end do + call sph_shell_add_orientation(active_orientation_name, values(1:3), & + values(4:6), ierr) + end subroutine sph_input_parse_orientation + subroutine sph_input_parse_explosive_control(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 45225dc..37adeae 100644 --- a/src/shell/sph_shell.f90 +++ b/src/shell/sph_shell.f90 @@ -2,12 +2,19 @@ module sph_shell use sph_precision, only: rk, SPH_NDIM use sph_error, only: SPH_SUCCESS, SPH_ERROR_ARGUMENT, SPH_ERROR_INPUT, & sph_error_set - use sph_database, only: SPH_MAX_MATERIALS, SPH_NAME_LEN, material_count, & - material_name, material_type, material_density, npart, particle_phase, & - particle_status, material_id, internal_energy, temperature, & + use sph_database, only: SPH_MAX_MATERIALS, SPH_MAX_SETS, SPH_MAX_ELEMENTS, & + SPH_MAX_ELEMENT_NODES, SPH_NAME_LEN, material_count, material_name, & + material_type, material_density, npart, particle_id_ext, & + particle_phase, particle_status, material_id, x0, mass, volume, & + internal_energy, temperature, nset_count, nset_name, & + nset_member_count, nset_members, elset_count, elset_name, & + elset_member_count, elset_members, element_id_ext, element_conn_count, & + element_conn, sph_db_find_node, sph_db_find_element, & + sph_db_find_elset, sph_db_find_nset, & section_count, section_id, section_type, section_material_id, & - section_thickness, section_integration_points, & - section_shear_correction, SPH_PHASE_SHELL, SPH_STATUS_ACTIVE + section_name, section_thickness, section_integration_points, & + section_shear_correction, section_orientation_name, SPH_PHASE_SHELL, & + SPH_STATUS_ACTIVE implicit none logical :: shell_module_initialized = .false. @@ -16,6 +23,14 @@ module sph_shell integer, parameter :: SPH_SHELL_SHEAR_COMPONENTS = 2 integer, parameter :: SPH_SHELL_STRESS_COMPONENTS = 6 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_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 + real(rk), parameter :: SPH_SHELL_EPS = 1.0e-12_rk logical :: shell_material_seen = .false. integer :: shell_material_count = 0 integer :: shell_material_ids(SPH_MAX_MATERIALS) = 0 @@ -37,8 +52,24 @@ module sph_shell real(rk) :: shell_failure_d(5,SPH_MAX_MATERIALS) = 0.0_rk character(len=SPH_NAME_LEN) :: shell_softening_type(SPH_MAX_MATERIALS) = ' ' real(rk) :: shell_softening_width(SPH_MAX_MATERIALS) = 0.0_rk + integer :: shell_orientation_count = 0 + character(len=SPH_NAME_LEN) :: shell_orientation_names(SPH_SHELL_MAX_ORIENTATIONS) = ' ' + real(rk) :: shell_orientation_director(SPH_NDIM,SPH_SHELL_MAX_ORIENTATIONS) = 0.0_rk + real(rk) :: shell_orientation_tangent(SPH_NDIM,SPH_SHELL_MAX_ORIENTATIONS) = 0.0_rk + logical :: shell_orientation_used(SPH_SHELL_MAX_ORIENTATIONS) = .false. + integer :: shell_director_set_count = 0 + 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_director_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), 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_omega(:,:) real(rk), allocatable :: shell_membrane_strain(:,:) real(rk), allocatable :: shell_bending_strain(:,:) @@ -62,11 +93,13 @@ contains subroutine sph_shell_initialize() shell_module_initialized = .true. call sph_shell_clear_material_table() + call sph_shell_clear_orientation_table() end subroutine sph_shell_initialize subroutine sph_shell_reset() shell_module_initialized = .false. call sph_shell_clear_material_table() + call sph_shell_clear_orientation_table() call sph_shell_deallocate_state() end subroutine sph_shell_reset @@ -94,6 +127,22 @@ contains shell_softening_width = 0.0_rk end subroutine sph_shell_clear_material_table + subroutine sph_shell_clear_orientation_table() + shell_orientation_count = 0 + shell_orientation_names = ' ' + shell_orientation_director = 0.0_rk + shell_orientation_tangent = 0.0_rk + shell_orientation_used = .false. + shell_director_set_count = 0 + shell_director_set_names = ' ' + shell_director_set_values = 0.0_rk + shell_director_set_used = .false. + shell_director_degenerate_count = 0 + shell_area_degenerate_count = 0 + shell_inertia_degenerate_count = 0 + shell_director_max_length_error = 0.0_rk + end subroutine sph_shell_clear_orientation_table + subroutine sph_shell_note_material(name, material_type_in) character(len=*), intent(in) :: name character(len=*), intent(in) :: material_type_in @@ -244,6 +293,110 @@ contains shell_softening_width(shell_index) = softening_width_value end subroutine sph_shell_set_control + subroutine sph_shell_add_orientation(name, director, tangent, ierr) + character(len=*), intent(in) :: name + real(rk), intent(in) :: director(SPH_NDIM) + real(rk), intent(in) :: tangent(SPH_NDIM) + integer, intent(out) :: ierr + integer :: orientation_index + real(rk) :: director_unit(SPH_NDIM) + real(rk) :: tangent_unit(SPH_NDIM) + real(rk) :: tangent_projected(SPH_NDIM) + real(rk) :: dot_value + + ierr = SPH_SUCCESS + if (len_trim(name) == 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell orientation is missing NAME') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_shell_vector_is_finite(director)) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell orientation director is not finite') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_shell_vector_is_finite(tangent)) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell orientation tangent is not finite') + ierr = SPH_ERROR_INPUT + return + end if + call sph_shell_normalize_vector(director, director_unit, ierr) + if (ierr /= SPH_SUCCESS) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell orientation director is degenerate') + ierr = SPH_ERROR_INPUT + return + end if + call sph_shell_normalize_vector(tangent, tangent_unit, ierr) + if (ierr /= SPH_SUCCESS) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell orientation tangent is degenerate') + ierr = SPH_ERROR_INPUT + return + end if + dot_value = sum(director_unit * tangent_unit) + tangent_projected = tangent_unit - dot_value * director_unit + call sph_shell_normalize_vector(tangent_projected, tangent_unit, ierr) + if (ierr /= SPH_SUCCESS) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell orientation vectors are parallel') + ierr = SPH_ERROR_INPUT + return + end if + + orientation_index = sph_shell_find_orientation(name) + if (orientation_index <= 0) then + if (shell_orientation_count >= SPH_SHELL_MAX_ORIENTATIONS) then + call sph_error_set(SPH_ERROR_INPUT, 'too many Shell orientation records') + ierr = SPH_ERROR_INPUT + return + end if + shell_orientation_count = shell_orientation_count + 1 + orientation_index = shell_orientation_count + end if + shell_orientation_names(orientation_index) = name + shell_orientation_director(:,orientation_index) = director + shell_orientation_tangent(:,orientation_index) = tangent_unit + shell_orientation_used(orientation_index) = .false. + end subroutine sph_shell_add_orientation + + subroutine sph_shell_set_director_for_set(set_name, director, ierr) + character(len=*), intent(in) :: set_name + real(rk), intent(in) :: director(SPH_NDIM) + integer, intent(out) :: ierr + integer :: set_index + real(rk) :: director_unit(SPH_NDIM) + + ierr = SPH_SUCCESS + if (len_trim(set_name) == 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell director is missing SET') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_shell_vector_is_finite(director)) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell director is not finite') + ierr = SPH_ERROR_INPUT + return + end if + call sph_shell_normalize_vector(director, director_unit, ierr) + if (ierr /= SPH_SUCCESS) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell director is degenerate') + ierr = SPH_ERROR_INPUT + return + end if + + set_index = sph_shell_find_director_set(set_name) + if (set_index <= 0) then + if (shell_director_set_count >= SPH_SHELL_MAX_DIRECTOR_SETS) then + call sph_error_set(SPH_ERROR_INPUT, 'too many Shell director set records') + ierr = SPH_ERROR_INPUT + return + end if + shell_director_set_count = shell_director_set_count + 1 + set_index = shell_director_set_count + end if + shell_director_set_names(set_index) = set_name + shell_director_set_values(:,set_index) = director + shell_director_set_used(set_index) = .false. + end subroutine sph_shell_set_director_for_set + subroutine sph_shell_build_state(ierr) integer, intent(out) :: ierr @@ -254,6 +407,7 @@ contains end if call sph_shell_validate_input(ierr) if (ierr /= SPH_SUCCESS) return + call sph_shell_reset_build_diagnostics() call sph_shell_allocate_state(ierr) if (ierr /= SPH_SUCCESS) return call sph_shell_clear_particle_state() @@ -270,11 +424,15 @@ contains return end if if (allocated(shell_thickness)) then - if (size(shell_thickness) == npart) return + if (size(shell_thickness) == npart .and. & + allocated(shell_reference_area) .and. & + allocated(shell_rotational_inertia) .and. & + allocated(shell_director_status)) return call sph_shell_deallocate_state() end if allocate(shell_thickness(npart), shell_director(SPH_NDIM,npart), & - shell_omega(SPH_NDIM,npart), & + shell_reference_area(npart), shell_rotational_inertia(npart), & + shell_director_status(npart), shell_omega(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), & @@ -304,6 +462,9 @@ contains subroutine sph_shell_deallocate_state() if (allocated(shell_thickness)) deallocate(shell_thickness) if (allocated(shell_director)) deallocate(shell_director) + 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_omega)) deallocate(shell_omega) if (allocated(shell_membrane_strain)) deallocate(shell_membrane_strain) if (allocated(shell_bending_strain)) deallocate(shell_bending_strain) @@ -326,6 +487,9 @@ contains subroutine sph_shell_clear_particle_state() if (allocated(shell_thickness)) shell_thickness = 0.0_rk if (allocated(shell_director)) shell_director = 0.0_rk + 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_omega)) shell_omega = 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 @@ -345,6 +509,15 @@ contains if (allocated(shell_ip_softening)) shell_ip_softening = 0.0_rk end subroutine sph_shell_clear_particle_state + subroutine sph_shell_reset_build_diagnostics() + shell_orientation_used = .false. + shell_director_set_used = .false. + shell_director_degenerate_count = 0 + shell_area_degenerate_count = 0 + shell_inertia_degenerate_count = 0 + shell_director_max_length_error = 0.0_rk + end subroutine sph_shell_reset_build_diagnostics + subroutine sph_shell_initialize_particle_state(ierr) integer, intent(out) :: ierr integer :: i @@ -370,7 +543,10 @@ contains ierr = SPH_SUCCESS point_count = section_integration_points(sec) shell_thickness(index) = section_thickness(sec) - shell_director(:,index) = (/0.0_rk, 0.0_rk, 1.0_rk/) + call sph_shell_initialize_director(index, sec, ierr) + if (ierr /= SPH_SUCCESS) return + call sph_shell_initialize_reference_measures(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 @@ -384,6 +560,372 @@ contains end do end subroutine sph_shell_initialize_active_particle + subroutine sph_shell_initialize_director(index, sec, ierr) + integer, intent(in) :: index + integer, intent(in) :: sec + integer, intent(out) :: ierr + real(rk) :: director_value(SPH_NDIM) + real(rk) :: area_value + integer :: source_status + integer :: orientation_index + logical :: found + + ierr = SPH_SUCCESS + director_value = 0.0_rk + area_value = 0.0_rk + source_status = SPH_SHELL_DIRECTOR_NONE + call sph_shell_find_director_for_particle(index, director_value, found) + if (found) then + source_status = SPH_SHELL_DIRECTOR_INPUT + else if (len_trim(section_orientation_name(sec)) > 0) then + orientation_index = sph_shell_find_orientation(section_orientation_name(sec)) + if (orientation_index <= 0) then + call sph_error_set(SPH_ERROR_INPUT, & + 'Shell section references unknown orientation') + ierr = SPH_ERROR_INPUT + return + end if + director_value = shell_orientation_director(:,orientation_index) + shell_orientation_used(orientation_index) = .true. + source_status = SPH_SHELL_DIRECTOR_ORIENTATION + else + call sph_shell_compute_geometry_for_particle(index, sec, director_value, & + area_value, ierr) + if (ierr /= SPH_SUCCESS) return + source_status = SPH_SHELL_DIRECTOR_GEOMETRY + end if + + call sph_shell_apply_director(index, director_value, source_status, ierr) + if (ierr /= SPH_SUCCESS) return + if (area_value <= SPH_SHELL_EPS) then + call sph_shell_estimate_reference_area(index, sec, area_value, ierr) + if (ierr /= SPH_SUCCESS) return + end if + shell_reference_area(index) = area_value + end subroutine sph_shell_initialize_director + + subroutine sph_shell_apply_director(index, director_value, source_status, ierr) + integer, intent(in) :: index + real(rk), intent(in) :: director_value(SPH_NDIM) + integer, intent(in) :: source_status + integer, intent(out) :: ierr + real(rk) :: length + real(rk) :: length_error + + ierr = SPH_SUCCESS + if (.not. sph_shell_vector_is_finite(director_value)) then + shell_director_degenerate_count = shell_director_degenerate_count + 1 + shell_director_status(index) = SPH_SHELL_DIRECTOR_DEGENERATE + call sph_error_set(SPH_ERROR_INPUT, 'Shell director is not finite') + ierr = SPH_ERROR_INPUT + return + end if + length = sph_shell_norm(director_value) + if (length <= SPH_SHELL_EPS) then + shell_director_degenerate_count = shell_director_degenerate_count + 1 + shell_director_status(index) = SPH_SHELL_DIRECTOR_DEGENERATE + call sph_error_set(SPH_ERROR_INPUT, 'Shell director is degenerate') + ierr = SPH_ERROR_INPUT + return + end if + length_error = abs(length - 1.0_rk) + if (length_error > shell_director_max_length_error) then + shell_director_max_length_error = length_error + end if + shell_director(:,index) = director_value / length + shell_director_status(index) = source_status + end subroutine sph_shell_apply_director + + subroutine sph_shell_initialize_reference_measures(index, ierr) + integer, intent(in) :: index + integer, intent(out) :: ierr + + ierr = SPH_SUCCESS + if (.not. sph_shell_scalar_is_finite(shell_reference_area(index)) .or. & + shell_reference_area(index) <= SPH_SHELL_EPS) then + shell_area_degenerate_count = shell_area_degenerate_count + 1 + call sph_error_set(SPH_ERROR_INPUT, 'Shell reference area is degenerate') + ierr = SPH_ERROR_INPUT + return + end if + shell_rotational_inertia(index) = mass(index) * shell_thickness(index) * & + shell_thickness(index) / 12.0_rk + if (.not. sph_shell_scalar_is_finite(shell_rotational_inertia(index)) .or. & + shell_rotational_inertia(index) <= SPH_SHELL_EPS) then + shell_inertia_degenerate_count = shell_inertia_degenerate_count + 1 + call sph_error_set(SPH_ERROR_INPUT, 'Shell rotational inertia is degenerate') + ierr = SPH_ERROR_INPUT + end if + end subroutine sph_shell_initialize_reference_measures + + subroutine sph_shell_find_director_for_particle(index, director_value, found) + integer, intent(in) :: index + real(rk), intent(out) :: director_value(SPH_NDIM) + logical, intent(out) :: found + integer :: set_index + + director_value = 0.0_rk + found = .false. + do set_index = 1, shell_director_set_count + if (.not. sph_shell_particle_in_named_set(index, & + shell_director_set_names(set_index))) cycle + director_value = shell_director_set_values(:,set_index) + shell_director_set_used(set_index) = .true. + found = .true. + return + end do + end subroutine sph_shell_find_director_for_particle + + logical function sph_shell_particle_in_named_set(index, set_name) + integer, intent(in) :: index + character(len=*), intent(in) :: set_name + integer :: set_index + integer :: member_index + integer :: elem_index + + sph_shell_particle_in_named_set = .false. + set_index = sph_db_find_nset(set_name) + if (set_index > 0) then + do member_index = 1, nset_member_count(set_index) + if (sph_db_find_node(nset_members(member_index,set_index)) == index) then + sph_shell_particle_in_named_set = .true. + return + end if + end do + end if + + set_index = sph_db_find_elset(set_name) + if (set_index > 0) then + 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 (sph_shell_element_contains_particle(elem_index, index)) then + sph_shell_particle_in_named_set = .true. + return + end if + end do + end if + end function sph_shell_particle_in_named_set + + logical function sph_shell_element_contains_particle(elem_index, particle_index) + integer, intent(in) :: elem_index + integer, intent(in) :: particle_index + integer :: conn_index + + sph_shell_element_contains_particle = .false. + if (elem_index < 1 .or. elem_index > SPH_MAX_ELEMENTS) return + do conn_index = 1, element_conn_count(elem_index) + if (sph_db_find_node(element_conn(conn_index,elem_index)) == particle_index) then + sph_shell_element_contains_particle = .true. + return + end if + end do + end function sph_shell_element_contains_particle + + subroutine sph_shell_compute_geometry_for_particle(index, sec, director_value, & + area_value, ierr) + integer, intent(in) :: index + integer, intent(in) :: sec + real(rk), intent(out) :: director_value(SPH_NDIM) + real(rk), intent(out) :: area_value + integer, intent(out) :: ierr + real(rk) :: normal_sum(SPH_NDIM) + logical :: has_normal + logical :: has_area + + ierr = SPH_SUCCESS + call sph_shell_compute_element_geometry(index, sec, normal_sum, area_value, & + has_normal, has_area, ierr) + if (ierr /= SPH_SUCCESS) return + if (has_normal) then + director_value = normal_sum + else + call sph_shell_infer_cloud_director(sec, director_value, ierr) + if (ierr /= SPH_SUCCESS) then + shell_director_degenerate_count = shell_director_degenerate_count + 1 + call sph_error_set(SPH_ERROR_INPUT, & + 'active Shell particle director cannot be inferred') + ierr = SPH_ERROR_INPUT + return + end if + end if + if (.not. has_area) then + call sph_shell_estimate_reference_area(index, sec, area_value, ierr) + end if + end subroutine sph_shell_compute_geometry_for_particle + + subroutine sph_shell_compute_element_geometry(index, sec, normal_sum, & + area_value, has_normal, has_area, ierr) + integer, intent(in) :: index + integer, intent(in) :: sec + real(rk), intent(out) :: normal_sum(SPH_NDIM) + real(rk), intent(out) :: area_value + logical, intent(out) :: has_normal + logical, intent(out) :: has_area + integer, intent(out) :: ierr + integer :: set_index + integer :: member_index + integer :: elem_index + real(rk) :: elem_area + real(rk) :: elem_area_vector(SPH_NDIM) + + ierr = SPH_SUCCESS + normal_sum = 0.0_rk + area_value = 0.0_rk + has_normal = .false. + has_area = .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 + call sph_shell_element_area_vector(elem_index, elem_area_vector, & + elem_area, ierr) + if (ierr /= SPH_SUCCESS) return + if (elem_area > SPH_SHELL_EPS) then + normal_sum = normal_sum + elem_area_vector + area_value = area_value + elem_area / & + real(max(1, element_conn_count(elem_index)), rk) + has_normal = .true. + has_area = .true. + else if (element_conn_count(elem_index) >= 3) then + shell_area_degenerate_count = shell_area_degenerate_count + 1 + end if + end do + end subroutine sph_shell_compute_element_geometry + + subroutine sph_shell_estimate_reference_area(index, sec, area_value, ierr) + integer, intent(in) :: index + integer, intent(in) :: sec + real(rk), intent(out) :: area_value + integer, intent(out) :: ierr + real(rk) :: normal_sum(SPH_NDIM) + logical :: has_normal + logical :: has_area + + ierr = SPH_SUCCESS + call sph_shell_compute_element_geometry(index, sec, normal_sum, area_value, & + has_normal, has_area, ierr) + if (ierr /= SPH_SUCCESS) return + if (.not. has_area) then + area_value = 0.0_rk + if (section_thickness(sec) > SPH_SHELL_EPS) then + area_value = volume(index) / section_thickness(sec) + end if + end if + if (.not. sph_shell_scalar_is_finite(area_value) .or. & + area_value <= SPH_SHELL_EPS) then + shell_area_degenerate_count = shell_area_degenerate_count + 1 + call sph_error_set(SPH_ERROR_INPUT, 'Shell reference area is degenerate') + ierr = SPH_ERROR_INPUT + end if + end subroutine sph_shell_estimate_reference_area + + subroutine sph_shell_element_area_vector(elem_index, area_vector, area_value, ierr) + integer, intent(in) :: elem_index + real(rk), intent(out) :: area_vector(SPH_NDIM) + real(rk), intent(out) :: area_value + integer, intent(out) :: ierr + integer :: node1 + integer :: node2 + integer :: node3 + integer :: node4 + real(rk) :: tri_vector(SPH_NDIM) + real(rk) :: tri_area + + ierr = SPH_SUCCESS + area_vector = 0.0_rk + area_value = 0.0_rk + if (elem_index < 1 .or. elem_index > SPH_MAX_ELEMENTS) return + if (element_conn_count(elem_index) < 3) return + + node1 = sph_db_find_node(element_conn(1,elem_index)) + node2 = sph_db_find_node(element_conn(2,elem_index)) + node3 = sph_db_find_node(element_conn(3,elem_index)) + if (node1 <= 0 .or. node2 <= 0 .or. node3 <= 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell element references unknown node') + ierr = SPH_ERROR_INPUT + return + end if + call sph_shell_triangle_area_vector(node1, node2, node3, tri_vector, tri_area) + area_vector = area_vector + tri_vector + area_value = area_value + tri_area + + if (element_conn_count(elem_index) >= 4) then + node4 = sph_db_find_node(element_conn(4,elem_index)) + if (node4 <= 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell element references unknown node') + ierr = SPH_ERROR_INPUT + return + end if + call sph_shell_triangle_area_vector(node1, node3, node4, tri_vector, tri_area) + area_vector = area_vector + tri_vector + area_value = area_value + tri_area + end if + end subroutine sph_shell_element_area_vector + + subroutine sph_shell_triangle_area_vector(node1, node2, node3, area_vector, & + area_value) + integer, intent(in) :: node1 + integer, intent(in) :: node2 + integer, intent(in) :: node3 + real(rk), intent(out) :: area_vector(SPH_NDIM) + real(rk), intent(out) :: area_value + real(rk) :: edge1(SPH_NDIM) + real(rk) :: edge2(SPH_NDIM) + + edge1 = x0(:,node2) - x0(:,node1) + edge2 = x0(:,node3) - x0(:,node1) + area_vector = 0.5_rk * sph_shell_cross(edge1, edge2) + area_value = sph_shell_norm(area_vector) + end subroutine sph_shell_triangle_area_vector + + subroutine sph_shell_infer_cloud_director(sec, director_value, ierr) + integer, intent(in) :: sec + real(rk), intent(out) :: director_value(SPH_NDIM) + integer, intent(out) :: ierr + integer :: i + integer :: j + integer :: k + real(rk) :: edge1(SPH_NDIM) + real(rk) :: edge2(SPH_NDIM) + real(rk) :: normal_value(SPH_NDIM) + + ierr = SPH_SUCCESS + director_value = 0.0_rk + 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 + do k = j + 1, npart + if (.not. sph_shell_particle_is_active_section(k, sec)) cycle + edge1 = x0(:,j) - x0(:,i) + edge2 = x0(:,k) - x0(:,i) + normal_value = sph_shell_cross(edge1, edge2) + if (sph_shell_norm(normal_value) > SPH_SHELL_EPS) then + director_value = normal_value + return + end if + end do + end do + end do + ierr = SPH_ERROR_INPUT + end subroutine sph_shell_infer_cloud_director + + logical function sph_shell_particle_is_active_section(index, sec) + integer, intent(in) :: index + integer, intent(in) :: sec + + sph_shell_particle_is_active_section = .false. + if (index < 1 .or. index > npart) return + if (particle_status(index) /= SPH_STATUS_ACTIVE) return + if (particle_phase(index) /= SPH_PHASE_SHELL) return + if (section_id(index) /= sec) return + sph_shell_particle_is_active_section = .true. + end function sph_shell_particle_is_active_section + subroutine sph_shell_set_integration_rule(point_count, coords, weights, ierr) integer, intent(in) :: point_count real(rk), intent(out) :: coords(SPH_SHELL_MAX_INTEGRATION_POINTS) @@ -517,6 +1059,16 @@ contains end do end subroutine sph_shell_count_unbound_materials + subroutine sph_shell_count_unused_orientations(count) + integer, intent(out) :: count + integer :: orientation_index + + count = 0 + do orientation_index = 1, shell_orientation_count + if (.not. shell_orientation_used(orientation_index)) count = count + 1 + end do + end subroutine sph_shell_count_unused_orientations + integer function sph_shell_register_material(name) character(len=*), intent(in) :: name integer :: existing @@ -584,6 +1136,34 @@ contains end do end function sph_shell_find_shell_material + integer function sph_shell_find_orientation(name) + character(len=*), intent(in) :: name + integer :: i + + sph_shell_find_orientation = 0 + do i = 1, shell_orientation_count + if (trim(sph_shell_upper(shell_orientation_names(i))) == & + trim(sph_shell_upper(name))) then + sph_shell_find_orientation = i + return + end if + end do + end function sph_shell_find_orientation + + integer function sph_shell_find_director_set(name) + character(len=*), intent(in) :: name + integer :: i + + sph_shell_find_director_set = 0 + do i = 1, shell_director_set_count + if (trim(sph_shell_upper(shell_director_set_names(i))) == & + trim(sph_shell_upper(name))) then + sph_shell_find_director_set = i + return + end if + end do + end function sph_shell_find_director_set + integer function sph_shell_find_material(name) character(len=*), intent(in) :: name integer :: i @@ -625,6 +1205,38 @@ contains end do end function sph_shell_vector_is_finite + subroutine sph_shell_normalize_vector(values, normalized, ierr) + real(rk), intent(in) :: values(SPH_NDIM) + real(rk), intent(out) :: normalized(SPH_NDIM) + integer, intent(out) :: ierr + real(rk) :: length + + ierr = SPH_SUCCESS + normalized = 0.0_rk + length = sph_shell_norm(values) + if (length <= SPH_SHELL_EPS) then + ierr = SPH_ERROR_ARGUMENT + return + end if + normalized = values / length + end subroutine sph_shell_normalize_vector + + real(rk) function sph_shell_norm(values) + real(rk), intent(in) :: values(SPH_NDIM) + + sph_shell_norm = sqrt(sum(values * values)) + end function sph_shell_norm + + function sph_shell_cross(left, right) result(out) + real(rk), intent(in) :: left(SPH_NDIM) + real(rk), intent(in) :: right(SPH_NDIM) + real(rk) :: out(SPH_NDIM) + + 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 sph_shell_cross + logical function sph_shell_scalar_is_finite(value) real(rk), intent(in) :: value diff --git a/tests/data/shell_johnson_cook_failure_060.inp b/tests/data/shell_johnson_cook_failure_060.inp index 7cf630b..ef10233 100644 --- a/tests/data/shell_johnson_cook_failure_060.inp +++ b/tests/data/shell_johnson_cook_failure_060.inp @@ -21,5 +21,6 @@ 0.05, 3.44, -2.12, 0.002, 0.61 *SPHLITE SHELL CONTROL, MATERIAL=SHELL_DAMAGE, SOFTENING=LINEAR, WIDTH=0.25 *SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_DAMAGE, THICKNESS=0.010, POINTS=5, 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=2.0E-7, STEPS=2, SAFETY=0.5 diff --git a/tests/data/shell_solid_mixed_060.inp b/tests/data/shell_solid_mixed_060.inp index 9844b81..3a51f6d 100644 --- a/tests/data/shell_solid_mixed_060.inp +++ b/tests/data/shell_solid_mixed_060.inp @@ -24,5 +24,6 @@ 210.0E9, 0.30 *SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_MIXED_STEEL, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 *SOLID SECTION, ELSET=SOLID_PARTICLES, MATERIAL=SOLID_MIXED_STEEL +*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 diff --git a/tests/data/shell_unbound_material_warning_060.inp b/tests/data/shell_unbound_material_warning_060.inp index ab68a41..86c1554 100644 --- a/tests/data/shell_unbound_material_warning_060.inp +++ b/tests/data/shell_unbound_material_warning_060.inp @@ -17,5 +17,6 @@ *ELASTIC 210.0E9, 0.30 *SHELL SECTION, ELSET=ACTIVE_SHELL, MATERIAL=ACTIVE_SHELL_STEEL, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 +*SPHLITE SHELL DIRECTOR, SET=ACTIVE_SHELL, 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 diff --git a/tests/data/shell_unused_orientation_warning_061.inp b/tests/data/shell_unused_orientation_warning_061.inp new file mode 100644 index 0000000..48aa9d8 --- /dev/null +++ b/tests/data/shell_unused_orientation_warning_061.inp @@ -0,0 +1,19 @@ +*NODE +1, 0.0, 0.0, 0.0 +2, 0.1, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +2, 2 +*ELSET, ELSET=SHELL_PARTICLES +1, 2 +*ORIENTATION, NAME=UNUSED_SHELL_Z +0.0, 0.0, 1.0, 1.0, 0.0, 0.0 +*MATERIAL, NAME=SHELL_UNUSED_ORIENT_061, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_UNUSED_ORIENT_061, 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 diff --git a/tests/module/test_shell_director_input.f90 b/tests/module/test_shell_director_input.f90 new file mode 100644 index 0000000..c33bd05 --- /dev/null +++ b/tests/module/test_shell_director_input.f90 @@ -0,0 +1,101 @@ +program test_shell_director_input + 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, sph_get_input_warning_count + use sph_database, only: section_orientation_name + use sph_shell, only: shell_director, shell_director_status, & + shell_director_max_length_error, SPH_SHELL_DIRECTOR_INPUT, & + SPH_SHELL_DIRECTOR_ORIENTATION + implicit none + + integer :: ierr + integer :: warnings + + call check_explicit_director() + call check_section_orientation() + call check_unused_orientation_warning() + call check_bad_input('tests/data/shell_director_zero_061.inp') + call check_bad_input('tests/data/shell_director_nan_061.inp') + call check_bad_input('tests/data/shell_orientation_parallel_061.inp') + call check_bad_input('tests/data/shell_local_frame_degenerate_061.inp') + +contains + + subroutine check_explicit_director() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for explicit Shell director') + call sph_read_inp('tests/data/shell_director_input_061.inp', ierr) + call assert_ok(ierr, 'read failed for explicit Shell director') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for explicit Shell director') + if (any(abs(shell_director(:,1) - (/0.0_rk, 0.0_rk, 1.0_rk/)) > & + 1.0e-12_rk)) call fail('explicit Shell director mismatch') + if (shell_director_status(1) /= SPH_SHELL_DIRECTOR_INPUT) & + call fail('explicit Shell director status mismatch') + if (shell_director_max_length_error < 0.9_rk) & + call fail('explicit Shell director length diagnostic missing') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for explicit Shell director') + end subroutine check_explicit_director + + subroutine check_section_orientation() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for Shell orientation') + call sph_read_inp('tests/data/shell_section_orientation_061.inp', ierr) + call assert_ok(ierr, 'read failed for Shell orientation') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for Shell orientation') + if (trim(section_orientation_name(1)) /= 'SHELL_Z') & + call fail('Shell section orientation name not stored') + if (any(abs(shell_director(:,1) - (/0.0_rk, 0.0_rk, 1.0_rk/)) > & + 1.0e-12_rk)) call fail('Shell orientation director mismatch') + if (shell_director_status(1) /= SPH_SHELL_DIRECTOR_ORIENTATION) & + call fail('Shell orientation director status mismatch') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for Shell orientation') + end subroutine check_section_orientation + + subroutine check_unused_orientation_warning() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for unused Shell orientation') + call sph_read_inp('tests/data/shell_unused_orientation_warning_061.inp', ierr) + call assert_ok(ierr, 'read failed for unused Shell orientation') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for unused Shell orientation') + call sph_get_input_warning_count(warnings, ierr) + call assert_ok(ierr, 'warning count failed for unused Shell orientation') + if (warnings <= 0) call fail('unused Shell orientation warning missing') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for unused Shell orientation') + end subroutine check_unused_orientation_warning + + subroutine check_bad_input(filename) + character(len=*), intent(in) :: filename + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for bad Shell director input') + call sph_read_inp(filename, ierr) + if (ierr == SPH_SUCCESS) then + call sph_build_model(ierr) + if (ierr == SPH_SUCCESS) call fail('bad Shell director input built') + end if + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed after bad Shell director input') + end subroutine check_bad_input + + 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_input diff --git a/tests/module/test_shell_reference_geometry.f90 b/tests/module/test_shell_reference_geometry.f90 new file mode 100644 index 0000000..2cd721b --- /dev/null +++ b/tests/module/test_shell_reference_geometry.f90 @@ -0,0 +1,105 @@ +program test_shell_reference_geometry + 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_director_status, & + shell_reference_area, shell_rotational_inertia, & + SPH_SHELL_DIRECTOR_GEOMETRY, SPH_SHELL_DIRECTOR_INPUT + implicit none + + integer :: ierr + + call check_triangle_reference() + call check_quad_reference() + call check_degenerate_reference() + call check_non_shell_defaults() + +contains + + subroutine check_triangle_reference() + real(rk) :: expected_area + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for triangle Shell reference') + call sph_read_inp('tests/data/shell_reference_triangle_061.inp', ierr) + call assert_ok(ierr, 'read failed for triangle Shell reference') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for triangle Shell reference') + expected_area = 0.5_rk * 0.1_rk * 0.1_rk / 3.0_rk + if (any(abs(shell_director(:,1) - (/0.0_rk, 0.0_rk, 1.0_rk/)) > & + 1.0e-12_rk)) call fail('triangle Shell director mismatch') + if (shell_director_status(1) /= SPH_SHELL_DIRECTOR_GEOMETRY) & + call fail('triangle Shell director status mismatch') + if (abs(shell_reference_area(1) - expected_area) > 1.0e-10_rk) & + call fail('triangle Shell reference area mismatch') + if (shell_rotational_inertia(1) <= 0.0_rk) & + call fail('triangle Shell rotational inertia missing') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for triangle Shell reference') + end subroutine check_triangle_reference + + subroutine check_quad_reference() + real(rk) :: expected_area + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for quad Shell reference') + call sph_read_inp('tests/data/shell_reference_quad_061.inp', ierr) + call assert_ok(ierr, 'read failed for quad Shell reference') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for quad Shell reference') + expected_area = 0.1_rk * 0.1_rk / 4.0_rk + if (any(abs(shell_director(:,1) - (/0.0_rk, 0.0_rk, 1.0_rk/)) > & + 1.0e-12_rk)) call fail('quad Shell director mismatch') + if (shell_director_status(1) /= SPH_SHELL_DIRECTOR_GEOMETRY) & + call fail('quad Shell director status mismatch') + if (abs(shell_reference_area(1) - expected_area) > 1.0e-10_rk) & + call fail('quad Shell reference area mismatch') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for quad Shell reference') + end subroutine check_quad_reference + + subroutine check_degenerate_reference() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for degenerate Shell reference') + call sph_read_inp('tests/data/shell_reference_area_degenerate_061.inp', ierr) + call assert_ok(ierr, 'read failed for degenerate Shell reference') + call sph_build_model(ierr) + if (ierr == SPH_SUCCESS) call fail('degenerate Shell reference built') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed after degenerate Shell reference') + end subroutine check_degenerate_reference + + subroutine check_non_shell_defaults() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for Shell/Solid isolation') + call sph_read_inp('tests/data/shell_solid_kinematics_isolation_061.inp', ierr) + call assert_ok(ierr, 'read failed for Shell/Solid isolation') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for Shell/Solid isolation') + if (shell_director_status(1) /= SPH_SHELL_DIRECTOR_INPUT) & + call fail('Shell isolation director status mismatch') + if (any(abs(shell_director(:,3)) > 1.0e-12_rk)) & + call fail('Solid particle Shell director default changed') + if (abs(shell_reference_area(3)) > 1.0e-12_rk) & + call fail('Solid particle Shell reference area default changed') + if (abs(shell_rotational_inertia(3)) > 1.0e-12_rk) & + call fail('Solid particle Shell inertia default changed') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for Shell/Solid isolation') + end subroutine check_non_shell_defaults + + 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_reference_geometry diff --git a/todo.md b/todo.md index 80cdee4..c322c4e 100644 --- a/todo.md +++ b/todo.md @@ -43,38 +43,38 @@ ## 阶段 B:Director 输入、几何推断和质量诊断 -- [ ] 设计 Shell director 初始化优先级常量或内部约定。 -- [ ] 复核现有 Shell section 数据结构是否可挂接 orientation 信息。 -- [ ] 支持受控 `*ORIENTATION` 名称解析。 -- [ ] 支持 section 引用 orientation 名称。 -- [ ] 支持 orientation 方向向量读取。 -- [ ] 支持 orientation 局部切向向量读取。 -- [ ] 对 orientation 非有限向量路径报 error。 -- [ ] 对 orientation 零向量路径报 error。 -- [ ] 对 orientation 平行退化向量路径报 error。 -- [ ] 对未被 active Shell 使用的 orientation 保持 warning。 -- [ ] 将显式 orientation 映射到 active Shell director。 -- [ ] 将 section orientation 映射到 active Shell director。 -- [ ] 支持由三角形参考面推断 Shell director。 -- [ ] 支持由四边形参考面推断 Shell director。 -- [ ] 对无法安全推断 director 的 active Shell 粒子报 error。 -- [ ] 检查 Shell director 有限性。 -- [ ] 检查 Shell director 非零长度。 -- [ ] 对 Shell director 执行归一化。 -- [ ] 记录 Shell director 初始化来源状态。 -- [ ] 记录 Shell director 最大长度偏差诊断。 -- [ ] 记录 Shell director 退化数量诊断。 -- [ ] 初始化 active Shell 粒子参考面积。 -- [ ] 初始化 active Shell 粒子等效转动惯量。 -- [ ] 对参考面积退化路径报 error 或记录退化诊断。 -- [ ] 对转动惯量退化路径报 error 或记录退化诊断。 -- [ ] 对非 Shell 粒子设置安全 director 默认值。 -- [ ] 对非 Shell 粒子设置安全参考面积默认值。 -- [ ] 对非 Shell 粒子设置安全转动惯量默认值。 -- [ ] 新增 `shell_director_input` 测试。 -- [ ] 新增 `shell_reference_geometry` 测试。 -- [ ] 将 `shell_director_input` 接入 CTest。 -- [ ] 将 `shell_reference_geometry` 接入 CTest。 +- [x] 设计 Shell director 初始化优先级常量或内部约定。 +- [x] 复核现有 Shell section 数据结构是否可挂接 orientation 信息。 +- [x] 支持受控 `*ORIENTATION` 名称解析。 +- [x] 支持 section 引用 orientation 名称。 +- [x] 支持 orientation 方向向量读取。 +- [x] 支持 orientation 局部切向向量读取。 +- [x] 对 orientation 非有限向量路径报 error。 +- [x] 对 orientation 零向量路径报 error。 +- [x] 对 orientation 平行退化向量路径报 error。 +- [x] 对未被 active Shell 使用的 orientation 保持 warning。 +- [x] 将显式 orientation 映射到 active Shell director。 +- [x] 将 section orientation 映射到 active Shell director。 +- [x] 支持由三角形参考面推断 Shell director。 +- [x] 支持由四边形参考面推断 Shell director。 +- [x] 对无法安全推断 director 的 active Shell 粒子报 error。 +- [x] 检查 Shell director 有限性。 +- [x] 检查 Shell director 非零长度。 +- [x] 对 Shell director 执行归一化。 +- [x] 记录 Shell director 初始化来源状态。 +- [x] 记录 Shell director 最大长度偏差诊断。 +- [x] 记录 Shell director 退化数量诊断。 +- [x] 初始化 active Shell 粒子参考面积。 +- [x] 初始化 active Shell 粒子等效转动惯量。 +- [x] 对参考面积退化路径报 error 或记录退化诊断。 +- [x] 对转动惯量退化路径报 error 或记录退化诊断。 +- [x] 对非 Shell 粒子设置安全 director 默认值。 +- [x] 对非 Shell 粒子设置安全参考面积默认值。 +- [x] 对非 Shell 粒子设置安全转动惯量默认值。 +- [x] 新增 `shell_director_input` 测试。 +- [x] 新增 `shell_reference_geometry` 测试。 +- [x] 将 `shell_director_input` 接入 CTest。 +- [x] 将 `shell_reference_geometry` 接入 CTest。 ## 阶段 C:局部坐标系、转动状态和 director 更新