From b5fd7724cc199d21934da1ae2ab2664e628ff71b Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 3 Jul 2026 19:36:28 +0800 Subject: [PATCH] Implement Shell input parsing stage --- CMakeLists.txt | 12 + src/database/sph_database.f90 | 7 +- src/input/sph_input_reader.f90 | 242 ++++++++-- src/shell/sph_shell.f90 | 445 ++++++++++++++++++ tests/data/shell_bad_density_060.inp | 14 + tests/data/shell_bad_elastic_060.inp | 14 + tests/data/shell_bad_failure_060.inp | 18 + tests/data/shell_bad_failure_nan_060.inp | 18 + tests/data/shell_bad_johnson_cook_nan_060.inp | 16 + tests/data/shell_bad_poisson_060.inp | 14 + tests/data/shell_bad_shear_correction_060.inp | 14 + tests/data/shell_bad_softening_060.inp | 15 + tests/data/shell_missing_elastic_060.inp | 12 + tests/data/shell_missing_section_060.inp | 1 + .../shell_section_missing_material_060.inp | 14 + .../shell_section_unknown_material_060.inp | 14 + .../shell_unbound_material_warning_060.inp | 21 + tests/module/test_input_shell_errors.f90 | 55 +++ tests/module/test_input_shell_section.f90 | 123 +++++ todo.md | 68 +-- 20 files changed, 1065 insertions(+), 72 deletions(-) create mode 100644 tests/data/shell_bad_density_060.inp create mode 100644 tests/data/shell_bad_elastic_060.inp create mode 100644 tests/data/shell_bad_failure_060.inp create mode 100644 tests/data/shell_bad_failure_nan_060.inp create mode 100644 tests/data/shell_bad_johnson_cook_nan_060.inp create mode 100644 tests/data/shell_bad_poisson_060.inp create mode 100644 tests/data/shell_bad_shear_correction_060.inp create mode 100644 tests/data/shell_bad_softening_060.inp create mode 100644 tests/data/shell_missing_elastic_060.inp create mode 100644 tests/data/shell_section_missing_material_060.inp create mode 100644 tests/data/shell_section_unknown_material_060.inp create mode 100644 tests/data/shell_unbound_material_warning_060.inp create mode 100644 tests/module/test_input_shell_errors.f90 create mode 100644 tests/module/test_input_shell_section.f90 diff --git a/CMakeLists.txt b/CMakeLists.txt index 803637f..19db9c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,6 +190,18 @@ set_target_properties(test_input_solid_errors PROPERTIES Fortran_MODULE_DIRECTOR add_test(NAME input_solid_errors COMMAND test_input_solid_errors) set_tests_properties(input_solid_errors PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +add_executable(test_input_shell_section tests/module/test_input_shell_section.f90) +target_link_libraries(test_input_shell_section PRIVATE sphlite_core) +set_target_properties(test_input_shell_section PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME input_shell_section COMMAND test_input_shell_section) +set_tests_properties(input_shell_section PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_input_shell_errors tests/module/test_input_shell_errors.f90) +target_link_libraries(test_input_shell_errors PRIVATE sphlite_core) +set_target_properties(test_input_shell_errors PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME input_shell_errors COMMAND test_input_shell_errors) +set_tests_properties(input_shell_errors 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 871cd93..47ffa41 100644 --- a/src/database/sph_database.f90 +++ b/src/database/sph_database.f90 @@ -124,6 +124,7 @@ module sph_database integer :: section_material_id(SPH_MAX_SECTIONS) real(rk) :: section_thickness(SPH_MAX_SECTIONS) integer :: section_integration_points(SPH_MAX_SECTIONS) + real(rk) :: section_shear_correction(SPH_MAX_SECTIONS) integer :: nset_count = 0 character(len=SPH_NAME_LEN) :: nset_name(SPH_MAX_SETS) @@ -270,6 +271,7 @@ contains section_material_id = 0 section_thickness = 0.0_rk section_integration_points = 0 + section_shear_correction = 0.0_rk nset_count = 0 nset_name = ' ' nset_member_count = 0 @@ -500,12 +502,14 @@ contains ierr = SPH_ERROR_DATABASE end subroutine sph_db_set_material_density - subroutine sph_db_add_section(name, stype, mat_name, thickness, points, ierr) + subroutine sph_db_add_section(name, stype, mat_name, thickness, points, & + shear_correction, 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 integer, intent(out) :: ierr integer :: mat_index integer :: set_index @@ -536,6 +540,7 @@ contains section_material_id(section_count) = mat_index section_thickness(section_count) = thickness section_integration_points(section_count) = points + section_shear_correction(section_count) = shear_correction end subroutine sph_db_add_section integer function sph_db_find_material(name) diff --git a/src/input/sph_input_reader.f90 b/src/input/sph_input_reader.f90 index 03aa148..0ad4e4e 100644 --- a/src/input/sph_input_reader.f90 +++ b/src/input/sph_input_reader.f90 @@ -24,6 +24,10 @@ module sph_input_reader sph_solid_set_johnson_cook, sph_solid_set_failure, & sph_solid_set_control, sph_solid_build_state, & sph_solid_count_unbound_materials + 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 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 @@ -88,6 +92,7 @@ contains integer :: gas_unbound_count integer :: explosive_unbound_count integer :: solid_unbound_count + integer :: shell_unbound_count ierr = SPH_SUCCESS if (npart <= 0) then @@ -114,6 +119,8 @@ contains if (ierr /= SPH_SUCCESS) return call sph_solid_build_state(ierr) if (ierr /= SPH_SUCCESS) return + call sph_shell_build_state(ierr) + if (ierr /= SPH_SUCCESS) return call sph_water_apply_initial_conditions(ierr) if (ierr /= SPH_SUCCESS) return call sph_gas_apply_initial_conditions(ierr) @@ -126,6 +133,8 @@ contains input_warning_count = input_warning_count + explosive_unbound_count call sph_solid_count_unbound_materials(solid_unbound_count) 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_solid_build_reference_state(ierr) if (ierr /= SPH_SUCCESS) return call sph_solid_update_diagnostics(ierr) @@ -284,11 +293,13 @@ contains character(len=SPH_INPUT_FIELD_LEN) :: section_type_value character(len=SPH_INPUT_FIELD_LEN) :: type_value real(rk) :: thickness + real(rk) :: shear_correction integer :: points integer :: ios integer :: local_ierr integer :: mat_index logical :: is_solid_section + logical :: is_shell_section character(len=SPH_INPUT_LINE_LEN) :: upper_line ierr = SPH_SUCCESS @@ -305,40 +316,9 @@ contains call sph_gas_note_material(value, type_value) call sph_explosive_note_material(value, type_value) call sph_solid_note_material(value, type_value) + call sph_shell_note_material(value, type_value) else if (key_id == SPH_KEY_SECTION) then - input_has_section = .true. - call sph_input_get_option(line, 'ELSET', section_value) - 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) - thickness = 0.0_rk - points = 3 - call sph_input_get_option(line, 'THICKNESS', value) - if (len_trim(value) > 0) read(value, *, iostat=ios) thickness - call sph_input_get_option(line, 'POINTS', value) - if (len_trim(value) > 0) read(value, *, iostat=ios) points - section_type_value = 'SECTION' - is_solid_section = index(upper_line, '*SOLID SECTION') == 1 - if (is_solid_section) then - section_type_value = 'SOLID' - if (len_trim(material_value) == 0) then - call sph_input_set_error('Solid section is missing MATERIAL option') - ierr = SPH_ERROR_INPUT - return - end if - mat_index = sph_input_find_material(material_value) - if (mat_index > 0) then - if (sph_input_is_explicit_non_solid_type(material_type(mat_index))) then - call sph_input_set_error('Solid section references non-Solid material') - ierr = SPH_ERROR_INPUT - return - end if - end if - else - 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, ierr) + call sph_input_parse_section_keyword(line, upper_line, ierr) else if (key_id == SPH_KEY_SPHLITE) then if (index(upper_line, 'TIME CONTROL') > 0) then input_has_time_control = .true. @@ -360,6 +340,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 CONTROL') > 0) then + call sph_input_parse_shell_control(line, ierr) else if (index(upper_line, 'SOLID CONTROL') > 0) then call sph_input_parse_solid_control(line, ierr) else @@ -380,6 +362,138 @@ contains if (ierr /= SPH_SUCCESS) call sph_input_prefix_current_error(ierr) end subroutine sph_input_record_keyword + subroutine sph_input_parse_section_keyword(line, upper_line, ierr) + character(len=*), intent(in) :: line + character(len=*), intent(in) :: upper_line + integer, intent(out) :: ierr + character(len=SPH_INPUT_FIELD_LEN) :: value + 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 + real(rk) :: thickness + real(rk) :: shear_correction + integer :: points + integer :: ios + integer :: mat_index + logical :: is_solid_section + logical :: is_shell_section + + ierr = SPH_SUCCESS + input_has_section = .true. + call sph_input_get_option(line, 'ELSET', section_value) + 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) + thickness = 0.0_rk + points = 3 + shear_correction = 5.0_rk / 6.0_rk + call sph_input_get_option(line, 'THICKNESS', value) + if (len_trim(value) > 0) then + call sph_input_parse_real_value(value, thickness, & + 'invalid section THICKNESS', ierr) + if (ierr /= SPH_SUCCESS) return + end if + call sph_input_get_option(line, 'POINTS', value) + if (len_trim(value) > 0) then + read(value, *, iostat=ios) points + if (ios /= 0) then + call sph_input_set_error('invalid section POINTS') + ierr = SPH_ERROR_INPUT + return + end if + end if + call sph_input_get_option(line, 'SHEAR_CORRECTION', value) + if (len_trim(value) == 0) call sph_input_get_option(line, 'SHEAR', value) + if (len_trim(value) > 0) then + call sph_input_parse_real_value(value, shear_correction, & + 'invalid section SHEAR_CORRECTION', ierr) + if (ierr /= SPH_SUCCESS) return + end if + section_type_value = 'SECTION' + is_solid_section = index(upper_line, '*SOLID SECTION') == 1 + is_shell_section = index(upper_line, '*SHELL SECTION') == 1 + if (is_solid_section) then + call sph_input_validate_solid_section(material_value, section_type_value, ierr) + if (ierr /= SPH_SUCCESS) return + else if (is_shell_section) then + call sph_input_validate_shell_section(material_value, thickness, & + points, shear_correction, section_type_value, ierr) + if (ierr /= SPH_SUCCESS) return + else + 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) + end subroutine sph_input_parse_section_keyword + + subroutine sph_input_validate_solid_section(material_value, section_type_value, ierr) + character(len=*), intent(in) :: material_value + character(len=*), intent(out) :: section_type_value + integer, intent(out) :: ierr + integer :: mat_index + + ierr = SPH_SUCCESS + section_type_value = 'SOLID' + if (len_trim(material_value) == 0) then + call sph_input_set_error('Solid section is missing MATERIAL option') + ierr = SPH_ERROR_INPUT + return + end if + mat_index = sph_input_find_material(material_value) + if (mat_index > 0) then + if (sph_input_is_explicit_non_solid_type(material_type(mat_index))) then + call sph_input_set_error('Solid section references non-Solid material') + ierr = SPH_ERROR_INPUT + return + end if + end if + end subroutine sph_input_validate_solid_section + + subroutine sph_input_validate_shell_section(material_value, thickness, & + points, shear_correction, section_type_value, ierr) + character(len=*), intent(in) :: material_value + real(rk), intent(in) :: thickness + integer, intent(in) :: points + real(rk), intent(in) :: shear_correction + character(len=*), intent(out) :: section_type_value + integer, intent(out) :: ierr + integer :: mat_index + + ierr = SPH_SUCCESS + section_type_value = 'SHELL' + if (len_trim(material_value) == 0) then + call sph_input_set_error('Shell section is missing MATERIAL option') + ierr = SPH_ERROR_INPUT + return + end if + mat_index = sph_input_find_material(material_value) + if (mat_index <= 0) then + call sph_input_set_error('Shell section references unknown material') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_input_material_type_is_shell(mat_index)) then + call sph_input_set_error('Shell section references non-Shell material') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_input_real_is_finite(thickness) .or. thickness <= 0.0_rk) then + call sph_input_set_error('Shell section THICKNESS must be positive') + ierr = SPH_ERROR_INPUT + return + end if + if (points /= 3 .and. points /= 5) then + call sph_input_set_error('Shell section POINTS must be 3 or 5') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_input_real_is_finite(shear_correction) .or. & + shear_correction <= 0.0_rk .or. shear_correction > 1.0_rk) then + call sph_input_set_error('Shell section SHEAR_CORRECTION is invalid') + ierr = SPH_ERROR_INPUT + end if + end subroutine sph_input_validate_shell_section + subroutine sph_input_parse_eos(line, ierr) character(len=*), intent(in) :: line integer, intent(out) :: ierr @@ -575,6 +689,22 @@ contains call sph_solid_set_control(material_name, softening_name, width, ierr) end subroutine sph_input_parse_solid_control + subroutine sph_input_parse_shell_control(line, ierr) + character(len=*), intent(in) :: line + integer, intent(out) :: ierr + character(len=SPH_INPUT_FIELD_LEN) :: material_name + character(len=SPH_INPUT_FIELD_LEN) :: softening_name + real(rk) :: width + + ierr = SPH_SUCCESS + width = 1.0_rk + call sph_input_get_option(line, 'MATERIAL', material_name) + call sph_input_get_option(line, 'SOFTENING', softening_name) + call sph_input_get_optional_real(line, 'WIDTH', width, ierr) + if (ierr /= SPH_SUCCESS) return + call sph_shell_set_control(material_name, softening_name, width, ierr) + end subroutine sph_input_parse_shell_control + subroutine sph_input_parse_explosive_control(line, ierr) character(len=*), intent(in) :: line integer, intent(out) :: ierr @@ -678,7 +808,11 @@ contains ierr = SPH_ERROR_INPUT return end if - call sph_solid_set_elastic(active_material_name, e_value, nu_value, ierr) + if (sph_input_active_material_is_shell()) then + call sph_shell_set_elastic(active_material_name, e_value, nu_value, ierr) + else + call sph_solid_set_elastic(active_material_name, e_value, nu_value, ierr) + end if end subroutine sph_input_parse_elastic subroutine sph_input_parse_plastic(line, ierr) @@ -706,8 +840,13 @@ contains return end if end do - call sph_solid_set_johnson_cook(active_material_name, values(1), values(2), & - values(3), values(4), values(5), values(6), values(7), values(8), ierr) + if (sph_input_active_material_is_shell()) then + call sph_shell_set_johnson_cook(active_material_name, values(1), values(2), & + values(3), values(4), values(5), values(6), values(7), values(8), ierr) + else + call sph_solid_set_johnson_cook(active_material_name, values(1), values(2), & + values(3), values(4), values(5), values(6), values(7), values(8), ierr) + end if end subroutine sph_input_parse_plastic subroutine sph_input_parse_damage_initiation(line, ierr) @@ -735,7 +874,11 @@ contains return end if end do - call sph_solid_set_failure(active_material_name, d_values, ierr) + if (sph_input_active_material_is_shell()) then + call sph_shell_set_failure(active_material_name, d_values, ierr) + else + call sph_solid_set_failure(active_material_name, d_values, ierr) + end if end subroutine sph_input_parse_damage_initiation subroutine sph_input_parse_output_control(line, ierr) @@ -794,6 +937,31 @@ contains end do end function sph_input_find_material + logical function sph_input_material_type_is_shell(mat_index) + integer, intent(in) :: mat_index + character(len=SPH_INPUT_FIELD_LEN) :: upper_type + + sph_input_material_type_is_shell = .false. + if (mat_index < 1 .or. mat_index > material_count) return + upper_type = sph_inp_upper(material_type(mat_index)) + if (index(upper_type, 'SHELL') > 0) sph_input_material_type_is_shell = .true. + end function sph_input_material_type_is_shell + + logical function sph_input_active_material_is_shell() + integer :: mat_index + + mat_index = sph_input_find_material(active_material_name) + sph_input_active_material_is_shell = sph_input_material_type_is_shell(mat_index) + end function sph_input_active_material_is_shell + + logical function sph_input_real_is_finite(value) + real(rk), intent(in) :: value + + sph_input_real_is_finite = .true. + if (value /= value) sph_input_real_is_finite = .false. + if (abs(value) > huge(value) * 0.5_rk) sph_input_real_is_finite = .false. + end function sph_input_real_is_finite + logical function sph_input_is_explicit_non_solid_type(type_name) character(len=*), intent(in) :: type_name character(len=SPH_INPUT_FIELD_LEN) :: upper_type diff --git a/src/shell/sph_shell.f90 b/src/shell/sph_shell.f90 index 5c0d694..3810660 100644 --- a/src/shell/sph_shell.f90 +++ b/src/shell/sph_shell.f90 @@ -1,15 +1,460 @@ module sph_shell + use sph_precision, only: rk + 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, section_count, section_id, section_type, & + section_material_id, section_thickness, section_integration_points, & + section_shear_correction, SPH_PHASE_SHELL, SPH_STATUS_ACTIVE implicit none + logical :: shell_module_initialized = .false. + logical :: shell_material_seen = .false. + integer :: shell_material_count = 0 + integer :: shell_material_ids(SPH_MAX_MATERIALS) = 0 + character(len=SPH_NAME_LEN) :: shell_material_names(SPH_MAX_MATERIALS) = ' ' + logical :: shell_elastic_defined(SPH_MAX_MATERIALS) = .false. + logical :: shell_johnson_cook_defined(SPH_MAX_MATERIALS) = .false. + logical :: shell_failure_defined(SPH_MAX_MATERIALS) = .false. + logical :: shell_control_defined(SPH_MAX_MATERIALS) = .false. + real(rk) :: shell_elastic_e(SPH_MAX_MATERIALS) = 0.0_rk + real(rk) :: shell_elastic_nu(SPH_MAX_MATERIALS) = 0.0_rk + real(rk) :: shell_jc_a(SPH_MAX_MATERIALS) = 0.0_rk + real(rk) :: shell_jc_b(SPH_MAX_MATERIALS) = 0.0_rk + real(rk) :: shell_jc_n(SPH_MAX_MATERIALS) = 0.0_rk + real(rk) :: shell_jc_c(SPH_MAX_MATERIALS) = 0.0_rk + real(rk) :: shell_jc_m(SPH_MAX_MATERIALS) = 0.0_rk + real(rk) :: shell_jc_epsdot0(SPH_MAX_MATERIALS) = 1.0_rk + real(rk) :: shell_jc_troom(SPH_MAX_MATERIALS) = 293.15_rk + real(rk) :: shell_jc_tmelt(SPH_MAX_MATERIALS) = 1793.0_rk + 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 contains subroutine sph_shell_initialize() shell_module_initialized = .true. + call sph_shell_clear_material_table() end subroutine sph_shell_initialize subroutine sph_shell_reset() shell_module_initialized = .false. + call sph_shell_clear_material_table() end subroutine sph_shell_reset + subroutine sph_shell_clear_material_table() + shell_material_seen = .false. + shell_material_count = 0 + shell_material_ids = 0 + shell_material_names = ' ' + shell_elastic_defined = .false. + shell_johnson_cook_defined = .false. + shell_failure_defined = .false. + shell_control_defined = .false. + shell_elastic_e = 0.0_rk + shell_elastic_nu = 0.0_rk + shell_jc_a = 0.0_rk + shell_jc_b = 0.0_rk + shell_jc_n = 0.0_rk + shell_jc_c = 0.0_rk + shell_jc_m = 0.0_rk + shell_jc_epsdot0 = 1.0_rk + shell_jc_troom = 293.15_rk + shell_jc_tmelt = 1793.0_rk + shell_failure_d = 0.0_rk + shell_softening_type = ' ' + shell_softening_width = 0.0_rk + end subroutine sph_shell_clear_material_table + + subroutine sph_shell_note_material(name, material_type_in) + character(len=*), intent(in) :: name + character(len=*), intent(in) :: material_type_in + integer :: shell_index + + if (index(sph_shell_upper(material_type_in), 'SHELL') > 0) then + shell_material_seen = .true. + shell_index = sph_shell_register_material(name) + end if + end subroutine sph_shell_note_material + + subroutine sph_shell_set_elastic(material_name_in, e_value, nu_value, ierr) + character(len=*), intent(in) :: material_name_in + real(rk), intent(in) :: e_value + real(rk), intent(in) :: nu_value + integer, intent(out) :: ierr + integer :: shell_index + + ierr = SPH_SUCCESS + if (.not. sph_shell_vector_is_finite((/ e_value, nu_value /))) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell elastic parameter is not finite') + ierr = SPH_ERROR_ARGUMENT + return + end if + if (e_value <= 0.0_rk) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell elastic modulus must be positive') + ierr = SPH_ERROR_ARGUMENT + return + end if + if (nu_value <= -1.0_rk .or. nu_value >= 0.5_rk) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell Poisson ratio is invalid') + ierr = SPH_ERROR_ARGUMENT + return + end if + call sph_shell_prepare_material(material_name_in, shell_index, ierr) + if (ierr /= SPH_SUCCESS) return + shell_elastic_defined(shell_index) = .true. + shell_elastic_e(shell_index) = e_value + shell_elastic_nu(shell_index) = nu_value + end subroutine sph_shell_set_elastic + + subroutine sph_shell_set_johnson_cook(material_name_in, a_value, b_value, & + n_value, c_value, m_value, epsdot0_value, troom_value, tmelt_value, ierr) + character(len=*), intent(in) :: material_name_in + real(rk), intent(in) :: a_value + real(rk), intent(in) :: b_value + real(rk), intent(in) :: n_value + real(rk), intent(in) :: c_value + real(rk), intent(in) :: m_value + real(rk), intent(in) :: epsdot0_value + real(rk), intent(in) :: troom_value + real(rk), intent(in) :: tmelt_value + integer, intent(out) :: ierr + integer :: shell_index + real(rk) :: jc_values(8) + + ierr = SPH_SUCCESS + jc_values = (/ a_value, b_value, n_value, c_value, m_value, & + epsdot0_value, troom_value, tmelt_value /) + if (.not. sph_shell_vector_is_finite(jc_values)) then + call sph_error_set(SPH_ERROR_ARGUMENT, & + 'Shell Johnson-Cook flow parameter is not finite') + ierr = SPH_ERROR_ARGUMENT + return + end if + if (a_value < 0.0_rk .or. b_value < 0.0_rk .or. n_value < 0.0_rk) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell Johnson-Cook strength is invalid') + ierr = SPH_ERROR_ARGUMENT + return + end if + if (c_value < 0.0_rk .or. m_value < 0.0_rk) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell Johnson-Cook rate or thermal exponent is invalid') + ierr = SPH_ERROR_ARGUMENT + return + end if + if (epsdot0_value <= 0.0_rk) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell Johnson-Cook reference strain rate must be positive') + ierr = SPH_ERROR_ARGUMENT + return + end if + if (tmelt_value <= troom_value) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell Johnson-Cook melt temperature must exceed room temperature') + ierr = SPH_ERROR_ARGUMENT + return + end if + call sph_shell_prepare_material(material_name_in, shell_index, ierr) + if (ierr /= SPH_SUCCESS) return + shell_johnson_cook_defined(shell_index) = .true. + shell_jc_a(shell_index) = a_value + shell_jc_b(shell_index) = b_value + shell_jc_n(shell_index) = n_value + shell_jc_c(shell_index) = c_value + shell_jc_m(shell_index) = m_value + shell_jc_epsdot0(shell_index) = epsdot0_value + shell_jc_troom(shell_index) = troom_value + shell_jc_tmelt(shell_index) = tmelt_value + end subroutine sph_shell_set_johnson_cook + + subroutine sph_shell_set_failure(material_name_in, d_values, ierr) + character(len=*), intent(in) :: material_name_in + real(rk), intent(in) :: d_values(5) + integer, intent(out) :: ierr + integer :: shell_index + + ierr = SPH_SUCCESS + if (.not. sph_shell_vector_is_finite(d_values)) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell Johnson-Cook failure parameter is not finite') + ierr = SPH_ERROR_ARGUMENT + return + end if + call sph_shell_prepare_material(material_name_in, shell_index, ierr) + if (ierr /= SPH_SUCCESS) return + shell_failure_defined(shell_index) = .true. + shell_failure_d(:,shell_index) = d_values(:) + end subroutine sph_shell_set_failure + + subroutine sph_shell_set_control(material_name_in, softening_name, & + softening_width_value, ierr) + character(len=*), intent(in) :: material_name_in + character(len=*), intent(in) :: softening_name + real(rk), intent(in) :: softening_width_value + integer, intent(out) :: ierr + integer :: shell_index + character(len=SPH_NAME_LEN) :: upper_softening + + ierr = SPH_SUCCESS + upper_softening = sph_shell_upper(softening_name) + if (len_trim(upper_softening) == 0) upper_softening = 'LINEAR' + if (index(upper_softening, 'LINEAR') <= 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell SOFTENING must be LINEAR') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_shell_vector_is_finite((/ softening_width_value /))) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell softening WIDTH is not finite') + ierr = SPH_ERROR_ARGUMENT + return + end if + if (softening_width_value <= 0.0_rk) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Shell softening WIDTH must be positive') + ierr = SPH_ERROR_ARGUMENT + return + end if + call sph_shell_prepare_material(material_name_in, shell_index, ierr) + if (ierr /= SPH_SUCCESS) return + shell_control_defined(shell_index) = .true. + shell_softening_type(shell_index) = upper_softening + shell_softening_width(shell_index) = softening_width_value + end subroutine sph_shell_set_control + + subroutine sph_shell_build_state(ierr) + integer, intent(out) :: ierr + + ierr = SPH_SUCCESS + if (.not. shell_material_seen) return + call sph_shell_validate_input(ierr) + end subroutine sph_shell_build_state + + subroutine sph_shell_validate_input(ierr) + integer, intent(out) :: ierr + integer :: shell_index + integer :: mat_index + + ierr = SPH_SUCCESS + do shell_index = 1, shell_material_count + mat_index = shell_material_ids(shell_index) + if (.not. sph_shell_has_active_particle(mat_index)) cycle + if (material_density(mat_index) <= 0.0_rk) then + call sph_error_set(SPH_ERROR_INPUT, 'active Shell material is missing density') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. shell_elastic_defined(shell_index)) then + call sph_error_set(SPH_ERROR_INPUT, 'active Shell material is missing elastic data') + ierr = SPH_ERROR_INPUT + return + end if + if (shell_failure_defined(shell_index) .and. & + .not. shell_johnson_cook_defined(shell_index)) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell failure requires Johnson-Cook flow data') + ierr = SPH_ERROR_INPUT + return + end if + end do + call sph_shell_validate_particle_sections(ierr) + end subroutine sph_shell_validate_input + + subroutine sph_shell_validate_particle_sections(ierr) + integer, intent(out) :: ierr + integer :: i + integer :: sec + + ierr = SPH_SUCCESS + do i = 1, npart + if (particle_status(i) /= SPH_STATUS_ACTIVE) cycle + if (particle_phase(i) /= SPH_PHASE_SHELL) cycle + sec = section_id(i) + if (sec < 1 .or. sec > section_count) then + call sph_error_set(SPH_ERROR_INPUT, & + 'active Shell particle is missing Shell section') + ierr = SPH_ERROR_INPUT + return + end if + if (index(sph_shell_upper(section_type(sec)), 'SHELL') <= 0) then + call sph_error_set(SPH_ERROR_INPUT, & + 'active Shell particle is not bound to Shell section') + ierr = SPH_ERROR_INPUT + return + end if + if (section_material_id(sec) /= material_id(i)) then + call sph_error_set(SPH_ERROR_INPUT, & + 'active Shell particle section material mismatch') + ierr = SPH_ERROR_INPUT + return + end if + call sph_shell_validate_section_values(sec, ierr) + if (ierr /= SPH_SUCCESS) return + end do + end subroutine sph_shell_validate_particle_sections + + subroutine sph_shell_validate_section_values(sec, ierr) + integer, intent(in) :: sec + integer, intent(out) :: ierr + + ierr = SPH_SUCCESS + if (.not. sph_shell_scalar_is_finite(section_thickness(sec)) .or. & + section_thickness(sec) <= 0.0_rk) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell section thickness must be positive') + ierr = SPH_ERROR_INPUT + return + end if + if (section_integration_points(sec) /= 3 .and. & + section_integration_points(sec) /= 5) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell section POINTS must be 3 or 5') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_shell_scalar_is_finite(section_shear_correction(sec)) .or. & + section_shear_correction(sec) <= 0.0_rk .or. & + section_shear_correction(sec) > 1.0_rk) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell section SHEAR_CORRECTION is invalid') + ierr = SPH_ERROR_INPUT + return + end if + end subroutine sph_shell_validate_section_values + + subroutine sph_shell_count_unbound_materials(count) + integer, intent(out) :: count + integer :: shell_index + + count = 0 + do shell_index = 1, shell_material_count + if (.not. sph_shell_has_active_particle(shell_material_ids(shell_index))) then + count = count + 1 + end if + end do + end subroutine sph_shell_count_unbound_materials + + integer function sph_shell_register_material(name) + character(len=*), intent(in) :: name + integer :: existing + integer :: mat_index + + existing = sph_shell_find_shell_material(name) + if (existing > 0) then + sph_shell_register_material = existing + return + end if + if (shell_material_count >= SPH_MAX_MATERIALS) then + sph_shell_register_material = 0 + return + end if + mat_index = sph_shell_find_material(name) + if (mat_index <= 0) then + sph_shell_register_material = 0 + return + end if + shell_material_count = shell_material_count + 1 + shell_material_ids(shell_material_count) = mat_index + shell_material_names(shell_material_count) = material_name(mat_index) + sph_shell_register_material = shell_material_count + end function sph_shell_register_material + + subroutine sph_shell_prepare_material(name, shell_index, ierr) + character(len=*), intent(in) :: name + integer, intent(out) :: shell_index + integer, intent(out) :: ierr + integer :: mat_index + + ierr = SPH_SUCCESS + shell_index = sph_shell_find_shell_material(name) + if (shell_index <= 0) then + mat_index = sph_shell_find_material(name) + if (mat_index <= 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell material is unknown') + ierr = SPH_ERROR_INPUT + return + end if + if (index(sph_shell_upper(material_type(mat_index)), 'SHELL') <= 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Shell data references non-Shell material') + ierr = SPH_ERROR_INPUT + return + end if + shell_index = sph_shell_register_material(name) + end if + if (shell_index <= 0) then + call sph_error_set(SPH_ERROR_INPUT, 'failed to register Shell material') + ierr = SPH_ERROR_INPUT + end if + end subroutine sph_shell_prepare_material + + integer function sph_shell_find_shell_material(name) + character(len=*), intent(in) :: name + integer :: i + + sph_shell_find_shell_material = 0 + do i = 1, shell_material_count + if (trim(sph_shell_upper(shell_material_names(i))) == & + trim(sph_shell_upper(name))) then + sph_shell_find_shell_material = i + return + end if + end do + end function sph_shell_find_shell_material + + integer function sph_shell_find_material(name) + character(len=*), intent(in) :: name + integer :: i + + sph_shell_find_material = 0 + do i = 1, material_count + if (trim(sph_shell_upper(material_name(i))) == trim(sph_shell_upper(name))) then + sph_shell_find_material = i + return + end if + end do + end function sph_shell_find_material + + logical function sph_shell_has_active_particle(mat_index) + integer, intent(in) :: mat_index + integer :: i + + sph_shell_has_active_particle = .false. + if (mat_index <= 0) return + do i = 1, npart + if (material_id(i) /= mat_index) cycle + if (particle_status(i) /= SPH_STATUS_ACTIVE) cycle + if (particle_phase(i) /= SPH_PHASE_SHELL) cycle + sph_shell_has_active_particle = .true. + return + end do + end function sph_shell_has_active_particle + + logical function sph_shell_vector_is_finite(values) + real(rk), intent(in) :: values(:) + integer :: i + + sph_shell_vector_is_finite = .true. + do i = 1, size(values) + if (.not. sph_shell_scalar_is_finite(values(i))) then + sph_shell_vector_is_finite = .false. + return + end if + end do + end function sph_shell_vector_is_finite + + logical function sph_shell_scalar_is_finite(value) + real(rk), intent(in) :: value + + sph_shell_scalar_is_finite = .true. + if (value /= value) sph_shell_scalar_is_finite = .false. + if (abs(value) > huge(value) * 0.5_rk) sph_shell_scalar_is_finite = .false. + end function sph_shell_scalar_is_finite + + function sph_shell_upper(text) result(out) + character(len=*), intent(in) :: text + character(len=len(text)) :: out + integer :: i + integer :: code + + out = text + do i = 1, len(out) + code = ichar(out(i:i)) + if (code >= ichar('a') .and. code <= ichar('z')) then + out(i:i) = char(code - ichar('a') + ichar('A')) + end if + end do + end function sph_shell_upper + end module sph_shell diff --git a/tests/data/shell_bad_density_060.inp b/tests/data/shell_bad_density_060.inp new file mode 100644 index 0000000..d603f2f --- /dev/null +++ b/tests/data/shell_bad_density_060.inp @@ -0,0 +1,14 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=SHELL_PARTICLES +1 +*MATERIAL, NAME=SHELL_BAD_DENSITY, TYPE=SHELL +*DENSITY +0.0 +*ELASTIC +210.0E9, 0.30 +*SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_BAD_DENSITY, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 +*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_bad_elastic_060.inp b/tests/data/shell_bad_elastic_060.inp new file mode 100644 index 0000000..7f7635b --- /dev/null +++ b/tests/data/shell_bad_elastic_060.inp @@ -0,0 +1,14 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=SHELL_PARTICLES +1 +*MATERIAL, NAME=SHELL_BAD_ELASTIC, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +-1.0, 0.30 +*SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_BAD_ELASTIC, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 +*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_bad_failure_060.inp b/tests/data/shell_bad_failure_060.inp new file mode 100644 index 0000000..c4b25c2 --- /dev/null +++ b/tests/data/shell_bad_failure_060.inp @@ -0,0 +1,18 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=SHELL_PARTICLES +1 +*MATERIAL, NAME=SHELL_BAD_FAILURE, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*PLASTIC, HARDENING=JOHNSON COOK +792.0E6, 510.0E6, 0.26, 0.014, 1.03, 1.0, 293.0, 1793.0 +*DAMAGE INITIATION, CRITERION=JOHNSON COOK +0.05, 3.44, -2.12, 0.002 +*SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_BAD_FAILURE, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 +*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_bad_failure_nan_060.inp b/tests/data/shell_bad_failure_nan_060.inp new file mode 100644 index 0000000..ac2f785 --- /dev/null +++ b/tests/data/shell_bad_failure_nan_060.inp @@ -0,0 +1,18 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=SHELL_PARTICLES +1 +*MATERIAL, NAME=SHELL_BAD_FAILURE_NAN, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*PLASTIC, HARDENING=JOHNSON COOK +792.0E6, 510.0E6, 0.26, 0.014, 1.03, 1.0, 293.0, 1793.0 +*DAMAGE INITIATION, CRITERION=JOHNSON COOK +0.05, NaN, -2.12, 0.002, 0.61 +*SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_BAD_FAILURE_NAN, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 +*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_bad_johnson_cook_nan_060.inp b/tests/data/shell_bad_johnson_cook_nan_060.inp new file mode 100644 index 0000000..45d91b7 --- /dev/null +++ b/tests/data/shell_bad_johnson_cook_nan_060.inp @@ -0,0 +1,16 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=SHELL_PARTICLES +1 +*MATERIAL, NAME=SHELL_BAD_JC_NAN, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*PLASTIC, HARDENING=JOHNSON COOK +NaN, 510.0E6, 0.26, 0.014, 1.03, 1.0, 293.0, 1793.0 +*SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_BAD_JC_NAN, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 +*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_bad_poisson_060.inp b/tests/data/shell_bad_poisson_060.inp new file mode 100644 index 0000000..4b6dd8b --- /dev/null +++ b/tests/data/shell_bad_poisson_060.inp @@ -0,0 +1,14 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=SHELL_PARTICLES +1 +*MATERIAL, NAME=SHELL_BAD_POISSON, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.75 +*SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_BAD_POISSON, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 +*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_bad_shear_correction_060.inp b/tests/data/shell_bad_shear_correction_060.inp new file mode 100644 index 0000000..cc26b71 --- /dev/null +++ b/tests/data/shell_bad_shear_correction_060.inp @@ -0,0 +1,14 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=SHELL_PARTICLES +1 +*MATERIAL, NAME=SHELL_BAD_SHEAR, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_BAD_SHEAR, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.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_bad_softening_060.inp b/tests/data/shell_bad_softening_060.inp new file mode 100644 index 0000000..a197aae --- /dev/null +++ b/tests/data/shell_bad_softening_060.inp @@ -0,0 +1,15 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=SHELL_PARTICLES +1 +*MATERIAL, NAME=SHELL_BAD_SOFTENING, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*SPHLITE SHELL CONTROL, MATERIAL=SHELL_BAD_SOFTENING, SOFTENING=EXPONENTIAL, WIDTH=0.25 +*SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_BAD_SOFTENING, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 +*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_missing_elastic_060.inp b/tests/data/shell_missing_elastic_060.inp new file mode 100644 index 0000000..27351e8 --- /dev/null +++ b/tests/data/shell_missing_elastic_060.inp @@ -0,0 +1,12 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=SHELL_PARTICLES +1 +*MATERIAL, NAME=SHELL_NO_ELASTIC, TYPE=SHELL +*DENSITY +7850.0 +*SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_NO_ELASTIC, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 +*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_missing_section_060.inp b/tests/data/shell_missing_section_060.inp index a2ab574..c29432c 100644 --- a/tests/data/shell_missing_section_060.inp +++ b/tests/data/shell_missing_section_060.inp @@ -9,5 +9,6 @@ 7850.0 *ELASTIC 210.0E9, 0.30 +*SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_MISSING_SECTION *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_section_missing_material_060.inp b/tests/data/shell_section_missing_material_060.inp new file mode 100644 index 0000000..a87491c --- /dev/null +++ b/tests/data/shell_section_missing_material_060.inp @@ -0,0 +1,14 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=SHELL_PARTICLES +1 +*MATERIAL, NAME=SHELL_SECTION_MISSING_MATERIAL, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*SHELL SECTION, ELSET=SHELL_PARTICLES, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 +*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_section_unknown_material_060.inp b/tests/data/shell_section_unknown_material_060.inp new file mode 100644 index 0000000..507165c --- /dev/null +++ b/tests/data/shell_section_unknown_material_060.inp @@ -0,0 +1,14 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=SHELL_PARTICLES +1 +*MATERIAL, NAME=SHELL_SECTION_UNKNOWN_MATERIAL, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=UNKNOWN_SHELL, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 +*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 new file mode 100644 index 0000000..ab68a41 --- /dev/null +++ b/tests/data/shell_unbound_material_warning_060.inp @@ -0,0 +1,21 @@ +*NODE +1, 0.0, 0.0, 0.0 +2, 0.1, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +2, 2 +*ELSET, ELSET=ACTIVE_SHELL +1, 2 +*MATERIAL, NAME=ACTIVE_SHELL_STEEL, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*MATERIAL, NAME=UNUSED_SHELL_STEEL, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*SHELL SECTION, ELSET=ACTIVE_SHELL, MATERIAL=ACTIVE_SHELL_STEEL, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 +*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_input_shell_errors.f90 b/tests/module/test_input_shell_errors.f90 new file mode 100644 index 0000000..7cfc807 --- /dev/null +++ b/tests/module/test_input_shell_errors.f90 @@ -0,0 +1,55 @@ +program test_input_shell_errors + use sph_error, only: SPH_SUCCESS + use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model + implicit none + + integer :: ierr + + call check_bad_input('tests/data/shell_missing_density_060.inp') + call check_bad_input('tests/data/shell_bad_density_060.inp') + call check_bad_input('tests/data/shell_missing_elastic_060.inp') + call check_bad_input('tests/data/shell_bad_elastic_060.inp') + call check_bad_input('tests/data/shell_bad_poisson_060.inp') + call check_bad_input('tests/data/shell_bad_johnson_cook_nan_060.inp') + call check_bad_input('tests/data/shell_bad_failure_060.inp') + call check_bad_input('tests/data/shell_bad_failure_nan_060.inp') + call check_bad_input('tests/data/shell_bad_softening_060.inp') + call check_bad_input('tests/data/shell_section_missing_material_060.inp') + call check_bad_input('tests/data/shell_section_unknown_material_060.inp') + call check_bad_input('tests/data/shell_bad_thickness_060.inp') + call check_bad_input('tests/data/shell_bad_integration_points_060.inp') + call check_bad_input('tests/data/shell_bad_shear_correction_060.inp') + call check_bad_input('tests/data/shell_section_non_shell_060.inp') + call check_bad_input('tests/data/shell_missing_section_060.inp') + +contains + + subroutine check_bad_input(filename) + character(len=*), intent(in) :: filename + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for bad Shell 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 input built successfully') + end if + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed after bad Shell 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_input_shell_errors diff --git a/tests/module/test_input_shell_section.f90 b/tests/module/test_input_shell_section.f90 new file mode 100644 index 0000000..6cc2e9d --- /dev/null +++ b/tests/module/test_input_shell_section.f90 @@ -0,0 +1,123 @@ +program test_input_shell_section + 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_count, particle_phase, particle_status, & + material_id, section_type, section_thickness, section_integration_points, & + section_shear_correction, SPH_PHASE_SHELL, SPH_PHASE_SOLID, & + SPH_STATUS_ACTIVE + use sph_shell, only: shell_material_count, shell_material_ids, & + shell_elastic_defined, shell_johnson_cook_defined, & + shell_failure_defined, shell_control_defined, shell_elastic_e, & + shell_elastic_nu, shell_jc_a, shell_jc_epsdot0, shell_failure_d, & + shell_softening_width + implicit none + + integer :: ierr + integer :: warnings + + call check_minimal_shell_input() + call check_section_points() + call check_johnson_cook_shell_input() + call check_unbound_warning() + call check_existing_solid_phase_path() + +contains + + subroutine check_minimal_shell_input() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for minimal Shell input') + call sph_read_inp('tests/data/shell_minimal_060.inp', ierr) + call assert_ok(ierr, 'read failed for minimal Shell input') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for minimal Shell input') + if (shell_material_count /= 1) call fail('Shell material count mismatch') + if (section_count /= 1) call fail('Shell section count mismatch') + if (.not. shell_elastic_defined(1)) call fail('Shell elastic data missing') + if (abs(shell_elastic_e(1) - 210.0e9_rk) > 1.0e3_rk) call fail('Shell elastic E mismatch') + if (abs(shell_elastic_nu(1) - 0.30_rk) > 1.0e-12_rk) call fail('Shell Poisson mismatch') + if (any(particle_phase(1:4) /= SPH_PHASE_SHELL)) call fail('Shell phase mismatch') + if (any(particle_status(1:4) /= SPH_STATUS_ACTIVE)) call fail('Shell status changed') + if (material_id(1) /= shell_material_ids(1)) call fail('Shell material mapping mismatch') + if (trim(section_type(1)) /= 'SHELL') call fail('Shell section type mismatch') + if (abs(section_thickness(1) - 0.010_rk) > 1.0e-12_rk) call fail('Shell thickness mismatch') + if (section_integration_points(1) /= 3) call fail('Shell section points mismatch') + if (abs(section_shear_correction(1) - 5.0_rk / 6.0_rk) > 1.0e-10_rk) & + call fail('Shell shear correction mismatch') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for minimal Shell input') + end subroutine check_minimal_shell_input + + subroutine check_section_points() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for Shell 5 point input') + call sph_read_inp('tests/data/shell_section_5pt_060.inp', ierr) + call assert_ok(ierr, 'read failed for Shell 5 point input') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for Shell 5 point input') + if (section_integration_points(1) /= 5) call fail('Shell 5 point section not stored') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for Shell 5 point input') + end subroutine check_section_points + + subroutine check_johnson_cook_shell_input() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for Shell Johnson-Cook input') + call sph_read_inp('tests/data/shell_johnson_cook_failure_060.inp', ierr) + call assert_ok(ierr, 'read failed for Shell Johnson-Cook input') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for Shell Johnson-Cook input') + if (.not. shell_johnson_cook_defined(1)) call fail('Shell Johnson-Cook flow missing') + if (.not. shell_failure_defined(1)) call fail('Shell Johnson-Cook failure missing') + if (.not. shell_control_defined(1)) call fail('Shell control missing') + if (shell_jc_a(1) <= 0.0_rk) call fail('Shell Johnson-Cook A mismatch') + if (shell_jc_epsdot0(1) <= 0.0_rk) call fail('Shell Johnson-Cook epsdot0 mismatch') + if (abs(shell_failure_d(1,1) - 0.05_rk) > 1.0e-12_rk) call fail('Shell failure D1 mismatch') + if (abs(shell_softening_width(1) - 0.25_rk) > 1.0e-12_rk) call fail('Shell softening mismatch') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for Shell Johnson-Cook input') + end subroutine check_johnson_cook_shell_input + + subroutine check_unbound_warning() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for unbound Shell input') + call sph_read_inp('tests/data/shell_unbound_material_warning_060.inp', ierr) + call assert_ok(ierr, 'read failed for unbound Shell input') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for unbound Shell input') + call sph_get_input_warning_count(warnings, ierr) + call assert_ok(ierr, 'warning count failed for unbound Shell input') + if (warnings <= 0) call fail('unbound Shell material warning missing') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for unbound Shell input') + end subroutine check_unbound_warning + + subroutine check_existing_solid_phase_path() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for Solid phase regression') + call sph_read_inp('tests/data/solid_elastic_minimal_050.inp', ierr) + call assert_ok(ierr, 'read failed for Solid phase regression') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for Solid phase regression') + if (any(particle_phase(1:4) /= SPH_PHASE_SOLID)) call fail('Solid phase path changed') + if (any(particle_status(1:4) /= SPH_STATUS_ACTIVE)) call fail('Solid status path changed') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for Solid phase regression') + end subroutine check_existing_solid_phase_path + + 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_input_shell_section diff --git a/todo.md b/todo.md index 209cc73..d4d0f85 100644 --- a/todo.md +++ b/todo.md @@ -45,40 +45,40 @@ ## 阶段 B:Shell 输入解析、section 校验与 warning/error 路径 -- [ ] 复核现有 material 解析路径并保持 Water/Gas/Explosive/Solid 兼容。 -- [ ] 支持 `TYPE=SHELL` material 识别。 -- [ ] 支持 Shell material 密度读取和映射。 -- [ ] 支持 Shell material 弹性参数读取和映射。 -- [ ] 支持 Shell material Johnson-Cook flow 参数读取和映射。 -- [ ] 支持 Shell material Johnson-Cook failure 参数读取和映射。 -- [ ] 支持 Shell material softening 控制参数读取和映射。 -- [ ] 对 Shell material 缺失密度路径报 error。 -- [ ] 对 Shell material 非正密度路径报 error。 -- [ ] 对 Shell material 缺失弹性参数路径报 error。 -- [ ] 对 Shell material 非正弹性模量路径报 error。 -- [ ] 对 Shell material 非法泊松比路径报 error。 -- [ ] 对 Shell Johnson-Cook flow 非有限参数路径报 error。 -- [ ] 对 Shell Johnson-Cook failure 非完整或非有限参数路径报 error。 -- [ ] 对 Shell unsupported softening 类型路径报 error。 -- [ ] 对未被 active Shell 粒子使用的 Shell material 保持 warning。 -- [ ] 支持 `*SHELL SECTION` 或等价 section 子集解析。 -- [ ] 解析 Shell section 的 material 参数。 -- [ ] 解析 Shell section 的 thickness 参数。 -- [ ] 解析 Shell section 的 integration point 数量。 -- [ ] 解析 Shell section 的 shear correction 参数。 -- [ ] 对 Shell section 缺失 material 参数路径报 error。 -- [ ] 对 Shell section 指向不存在 material 路径报 error。 -- [ ] 对 Shell section 指向非 Shell material 路径报 error。 -- [ ] 对 Shell section 非正 thickness 路径报 error。 -- [ ] 对 Shell section 非法 integration point 数量路径报 error。 -- [ ] 对 Shell section 非法 shear correction 路径报 error。 -- [ ] 对存在 active Shell 粒子但缺失 Shell section 的模型报 error。 -- [ ] 确认 set 仍只表示集合,不参与 Shell 类型判断。 -- [ ] 确认 phase/status 默认值不改变 Water/Gas/Explosive/Solid 路径。 -- [ ] 新增 `input_shell_section` Fortran 输入测试。 -- [ ] 新增 `input_shell_errors` Fortran 输入测试。 -- [ ] 将 `input_shell_section` 接入 CTest。 -- [ ] 将 `input_shell_errors` 接入 CTest。 +- [x] 复核现有 material 解析路径并保持 Water/Gas/Explosive/Solid 兼容。 +- [x] 支持 `TYPE=SHELL` material 识别。 +- [x] 支持 Shell material 密度读取和映射。 +- [x] 支持 Shell material 弹性参数读取和映射。 +- [x] 支持 Shell material Johnson-Cook flow 参数读取和映射。 +- [x] 支持 Shell material Johnson-Cook failure 参数读取和映射。 +- [x] 支持 Shell material softening 控制参数读取和映射。 +- [x] 对 Shell material 缺失密度路径报 error。 +- [x] 对 Shell material 非正密度路径报 error。 +- [x] 对 Shell material 缺失弹性参数路径报 error。 +- [x] 对 Shell material 非正弹性模量路径报 error。 +- [x] 对 Shell material 非法泊松比路径报 error。 +- [x] 对 Shell Johnson-Cook flow 非有限参数路径报 error。 +- [x] 对 Shell Johnson-Cook failure 非完整或非有限参数路径报 error。 +- [x] 对 Shell unsupported softening 类型路径报 error。 +- [x] 对未被 active Shell 粒子使用的 Shell material 保持 warning。 +- [x] 支持 `*SHELL SECTION` 或等价 section 子集解析。 +- [x] 解析 Shell section 的 material 参数。 +- [x] 解析 Shell section 的 thickness 参数。 +- [x] 解析 Shell section 的 integration point 数量。 +- [x] 解析 Shell section 的 shear correction 参数。 +- [x] 对 Shell section 缺失 material 参数路径报 error。 +- [x] 对 Shell section 指向不存在 material 路径报 error。 +- [x] 对 Shell section 指向非 Shell material 路径报 error。 +- [x] 对 Shell section 非正 thickness 路径报 error。 +- [x] 对 Shell section 非法 integration point 数量路径报 error。 +- [x] 对 Shell section 非法 shear correction 路径报 error。 +- [x] 对存在 active Shell 粒子但缺失 Shell section 的模型报 error。 +- [x] 确认 set 仍只表示集合,不参与 Shell 类型判断。 +- [x] 确认 phase/status 默认值不改变 Water/Gas/Explosive/Solid 路径。 +- [x] 新增 `input_shell_section` Fortran 输入测试。 +- [x] 新增 `input_shell_errors` Fortran 输入测试。 +- [x] 将 `input_shell_section` 接入 CTest。 +- [x] 将 `input_shell_errors` 接入 CTest。 ## 阶段 C:Shell 状态数组、厚度积分点和默认值