From 58d15da1aeb53b57d9685b22792a88dd22a96ead Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 3 Jul 2026 22:41:19 +0800 Subject: [PATCH] Add 0.7.0 blast region input controls --- CMakeLists.txt | 13 ++ src/blast/sph_blast.f90 | 233 +++++++++++++++++++++++ src/input/sph_input_reader.f90 | 72 +++++++ src/interface/sph_api.f90 | 3 + tests/module/test_input_blast_errors.f90 | 77 ++++++++ tests/module/test_input_blast_region.f90 | 102 ++++++++++ todo.md | 60 +++--- 7 files changed, 530 insertions(+), 30 deletions(-) create mode 100644 src/blast/sph_blast.f90 create mode 100644 tests/module/test_input_blast_errors.f90 create mode 100644 tests/module/test_input_blast_region.f90 diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f0827f..1658036 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,7 @@ set(SPHLITE_CORE_SOURCES src/explosive/sph_explosive_state.f90 src/explosive/sph_explosive_helpers.f90 src/explosive/sph_explosive.f90 + src/blast/sph_blast.f90 src/solid/sph_solid_state.f90 src/solid/sph_solid_material.f90 src/solid/sph_solid.f90 @@ -178,6 +179,18 @@ set_target_properties(test_input_explosive_multimaterial PROPERTIES Fortran_MODU add_test(NAME input_explosive_multimaterial COMMAND test_input_explosive_multimaterial) set_tests_properties(input_explosive_multimaterial PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +add_executable(test_input_blast_region tests/module/test_input_blast_region.f90) +target_link_libraries(test_input_blast_region PRIVATE sphlite_core) +set_target_properties(test_input_blast_region PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME input_blast_region COMMAND test_input_blast_region) +set_tests_properties(input_blast_region PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_input_blast_errors tests/module/test_input_blast_errors.f90) +target_link_libraries(test_input_blast_errors PRIVATE sphlite_core) +set_target_properties(test_input_blast_errors PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME input_blast_errors COMMAND test_input_blast_errors) +set_tests_properties(input_blast_errors PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + add_executable(test_input_solid_material tests/module/test_input_solid_material.f90) target_link_libraries(test_input_solid_material PRIVATE sphlite_core) set_target_properties(test_input_solid_material PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") diff --git a/src/blast/sph_blast.f90 b/src/blast/sph_blast.f90 new file mode 100644 index 0000000..cfb3c0e --- /dev/null +++ b/src/blast/sph_blast.f90 @@ -0,0 +1,233 @@ +module sph_blast + use sph_precision, only: rk, SPH_NDIM + use sph_error, only: SPH_SUCCESS, SPH_ERROR_INPUT, SPH_ERROR_DATABASE, & + sph_error_set + use sph_database, only: SPH_NAME_LEN, SPH_MAX_REGIONS, sph_db_find_elset, & + sph_db_find_nset + implicit none + + integer, parameter :: SPH_BLAST_PHASE_NONE = 0 + integer, parameter :: SPH_BLAST_PHASE_WATER = 1 + integer, parameter :: SPH_BLAST_PHASE_GAS = 2 + integer, parameter :: SPH_BLAST_PHASE_EXPLOSIVE = 3 + integer, parameter :: SPH_BLAST_PHASE_SOLID = 4 + integer, parameter :: SPH_BLAST_PHASE_SHELL = 5 + integer, parameter :: SPH_BLAST_PHASE_STRUCTURE = 6 + integer, parameter :: SPH_BLAST_PHASE_ALL = 7 + + integer, parameter :: SPH_BLAST_MODE_RADIAL = 1 + integer, parameter :: SPH_BLAST_MODE_NORMAL = 2 + integer, parameter :: SPH_BLAST_MODE_DIRECT = 3 + + integer :: blast_region_count = 0 + character(len=SPH_NAME_LEN) :: blast_region_name(SPH_MAX_REGIONS) = ' ' + character(len=SPH_NAME_LEN) :: blast_target_set_name(SPH_MAX_REGIONS) = ' ' + integer :: blast_source_phase(SPH_MAX_REGIONS) = SPH_BLAST_PHASE_NONE + integer :: blast_target_phase(SPH_MAX_REGIONS) = SPH_BLAST_PHASE_NONE + integer :: blast_projection_mode(SPH_MAX_REGIONS) = SPH_BLAST_MODE_RADIAL + logical :: blast_region_enabled(SPH_MAX_REGIONS) = .false. + real(rk) :: blast_center(SPH_NDIM,SPH_MAX_REGIONS) = 0.0_rk + real(rk) :: blast_radius(SPH_MAX_REGIONS) = 0.0_rk + real(rk) :: blast_load_scale(SPH_MAX_REGIONS) = 0.0_rk + real(rk) :: blast_time_window(SPH_MAX_REGIONS) = 0.0_rk + +contains + + subroutine sph_blast_initialize() + call sph_blast_reset() + end subroutine sph_blast_initialize + + subroutine sph_blast_reset() + blast_region_count = 0 + blast_region_name = ' ' + blast_target_set_name = ' ' + blast_source_phase = SPH_BLAST_PHASE_NONE + blast_target_phase = SPH_BLAST_PHASE_NONE + blast_projection_mode = SPH_BLAST_MODE_RADIAL + blast_region_enabled = .false. + blast_center = 0.0_rk + blast_radius = 0.0_rk + blast_load_scale = 0.0_rk + blast_time_window = 0.0_rk + end subroutine sph_blast_reset + + subroutine sph_blast_add_region(name, center, radius, source_phase_name, & + target_phase_name, target_set_name, scale, time_window, mode_name, ierr) + character(len=*), intent(in) :: name + real(rk), intent(in) :: center(SPH_NDIM) + real(rk), intent(in) :: radius + character(len=*), intent(in) :: source_phase_name + character(len=*), intent(in) :: target_phase_name + character(len=*), intent(in) :: target_set_name + real(rk), intent(in) :: scale + real(rk), intent(in) :: time_window + character(len=*), intent(in) :: mode_name + integer, intent(out) :: ierr + integer :: source_phase + integer :: target_phase + integer :: projection_mode + logical :: is_disabled + + ierr = SPH_SUCCESS + if (blast_region_count >= SPH_MAX_REGIONS) then + call sph_error_set(SPH_ERROR_DATABASE, 'too many Blast region records') + ierr = SPH_ERROR_DATABASE + return + end if + if (.not. sph_blast_real_is_finite(radius) .or. radius <= 0.0_rk) then + call sph_error_set(SPH_ERROR_INPUT, 'Blast region RADIUS must be positive') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_blast_real_is_finite(scale)) then + call sph_error_set(SPH_ERROR_INPUT, 'Blast region SCALE must be finite') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_blast_real_is_finite(time_window) .or. & + time_window < 0.0_rk) then + call sph_error_set(SPH_ERROR_INPUT, 'Blast region TIME_WINDOW must be non-negative') + ierr = SPH_ERROR_INPUT + return + end if + if (.not. sph_blast_vector_is_finite(center)) then + call sph_error_set(SPH_ERROR_INPUT, 'Blast region center must be finite') + ierr = SPH_ERROR_INPUT + return + end if + source_phase = sph_blast_phase_id(source_phase_name) + if (source_phase == SPH_BLAST_PHASE_NONE) then + call sph_error_set(SPH_ERROR_INPUT, 'Blast region SOURCE_PHASE is invalid') + ierr = SPH_ERROR_INPUT + return + end if + target_phase = sph_blast_phase_id(target_phase_name) + if (target_phase == SPH_BLAST_PHASE_NONE) then + call sph_error_set(SPH_ERROR_INPUT, 'Blast region TARGET_PHASE is invalid') + ierr = SPH_ERROR_INPUT + return + end if + projection_mode = sph_blast_mode_id(mode_name) + if (projection_mode <= 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Blast region MODE is invalid') + ierr = SPH_ERROR_INPUT + return + end if + if (len_trim(target_set_name) == 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Blast region is missing TARGET_SET') + ierr = SPH_ERROR_INPUT + return + end if + is_disabled = trim(sph_blast_upper(target_set_name)) == 'NONE' + if (.not. is_disabled) then + if (sph_db_find_elset(target_set_name) <= 0 .and. & + sph_db_find_nset(target_set_name) <= 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Blast region TARGET_SET is unknown') + ierr = SPH_ERROR_INPUT + return + end if + end if + + blast_region_count = blast_region_count + 1 + blast_region_name(blast_region_count) = name + if (len_trim(blast_region_name(blast_region_count)) == 0) then + blast_region_name(blast_region_count) = 'BLAST' + end if + blast_center(:,blast_region_count) = center(:) + blast_radius(blast_region_count) = radius + blast_source_phase(blast_region_count) = source_phase + blast_target_phase(blast_region_count) = target_phase + blast_target_set_name(blast_region_count) = target_set_name + blast_load_scale(blast_region_count) = scale + blast_time_window(blast_region_count) = time_window + blast_projection_mode(blast_region_count) = projection_mode + blast_region_enabled(blast_region_count) = .not. is_disabled + end subroutine sph_blast_add_region + + subroutine sph_blast_count_unused_regions(count) + integer, intent(out) :: count + integer :: i + + count = 0 + do i = 1, blast_region_count + if (.not. blast_region_enabled(i)) count = count + 1 + end do + end subroutine sph_blast_count_unused_regions + + integer function sph_blast_phase_id(phase_name) + character(len=*), intent(in) :: phase_name + character(len=SPH_NAME_LEN) :: upper_name + + upper_name = sph_blast_upper(phase_name) + sph_blast_phase_id = SPH_BLAST_PHASE_NONE + if (len_trim(upper_name) == 0) return + if (index(upper_name, 'WATER') > 0) then + sph_blast_phase_id = SPH_BLAST_PHASE_WATER + else if (index(upper_name, 'GAS') > 0) then + sph_blast_phase_id = SPH_BLAST_PHASE_GAS + else if (index(upper_name, 'EXPLOSIVE') > 0) then + sph_blast_phase_id = SPH_BLAST_PHASE_EXPLOSIVE + else if (trim(upper_name) == 'SOLID') then + sph_blast_phase_id = SPH_BLAST_PHASE_SOLID + else if (trim(upper_name) == 'SHELL') then + sph_blast_phase_id = SPH_BLAST_PHASE_SHELL + else if (index(upper_name, 'STRUCTURE') > 0) then + sph_blast_phase_id = SPH_BLAST_PHASE_STRUCTURE + else if (trim(upper_name) == 'ALL' .or. trim(upper_name) == 'ANY') then + sph_blast_phase_id = SPH_BLAST_PHASE_ALL + end if + end function sph_blast_phase_id + + integer function sph_blast_mode_id(mode_name) + character(len=*), intent(in) :: mode_name + character(len=SPH_NAME_LEN) :: upper_name + + upper_name = sph_blast_upper(mode_name) + if (len_trim(upper_name) == 0) upper_name = 'RADIAL' + sph_blast_mode_id = 0 + if (index(upper_name, 'RADIAL') > 0) then + sph_blast_mode_id = SPH_BLAST_MODE_RADIAL + else if (index(upper_name, 'NORMAL') > 0) then + sph_blast_mode_id = SPH_BLAST_MODE_NORMAL + else if (index(upper_name, 'DIRECT') > 0) then + sph_blast_mode_id = SPH_BLAST_MODE_DIRECT + end if + end function sph_blast_mode_id + + logical function sph_blast_real_is_finite(value) + real(rk), intent(in) :: value + + sph_blast_real_is_finite = .true. + if (value /= value) sph_blast_real_is_finite = .false. + if (abs(value) > huge(value) * 0.5_rk) sph_blast_real_is_finite = .false. + end function sph_blast_real_is_finite + + logical function sph_blast_vector_is_finite(values) + real(rk), intent(in) :: values(SPH_NDIM) + integer :: i + + sph_blast_vector_is_finite = .true. + do i = 1, SPH_NDIM + if (.not. sph_blast_real_is_finite(values(i))) then + sph_blast_vector_is_finite = .false. + return + end if + end do + end function sph_blast_vector_is_finite + + function sph_blast_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_blast_upper + +end module sph_blast diff --git a/src/input/sph_input_reader.f90 b/src/input/sph_input_reader.f90 index 6517a1e..42b7ce4 100644 --- a/src/input/sph_input_reader.f90 +++ b/src/input/sph_input_reader.f90 @@ -20,6 +20,8 @@ module sph_input_reader use sph_explosive, only: sph_explosive_note_material, & sph_explosive_set_control, sph_explosive_set_ignition, & sph_explosive_build, sph_explosive_count_unbound_materials + use sph_blast, only: sph_blast_reset, sph_blast_add_region, & + sph_blast_count_unused_regions use sph_solid, only: sph_solid_note_material, sph_solid_set_elastic, & sph_solid_set_johnson_cook, sph_solid_set_failure, & sph_solid_set_control, sph_solid_build_state, & @@ -69,6 +71,7 @@ contains active_elset_name = 'ELSET' active_material_name = 'MATERIAL' active_orientation_name = 'ORIENTATION' + call sph_blast_reset() end subroutine sph_input_reset subroutine sph_input_get_warning_count(count) @@ -98,6 +101,7 @@ contains integer :: solid_unbound_count integer :: shell_unbound_count integer :: shell_unused_orientation_count + integer :: blast_unused_count ierr = SPH_SUCCESS if (npart <= 0) then @@ -142,6 +146,8 @@ contains 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_blast_count_unused_regions(blast_unused_count) + input_warning_count = input_warning_count + blast_unused_count call sph_solid_build_reference_state(ierr) if (ierr /= SPH_SUCCESS) return call sph_solid_update_diagnostics(ierr) @@ -354,6 +360,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, 'BLAST REGION') > 0) then + call sph_input_parse_blast_region(line, ierr) else if (index(upper_line, 'SHELL DIRECTOR') > 0) then call sph_input_parse_shell_director(line, ierr) else if (index(upper_line, 'SHELL ROTATION') > 0) then @@ -731,6 +739,70 @@ contains call sph_shell_set_control(material_name, softening_name, width, ierr) end subroutine sph_input_parse_shell_control + subroutine sph_input_parse_blast_region(line, ierr) + character(len=*), intent(in) :: line + integer, intent(out) :: ierr + character(len=SPH_INPUT_FIELD_LEN) :: name + character(len=SPH_INPUT_FIELD_LEN) :: source_phase + character(len=SPH_INPUT_FIELD_LEN) :: target_phase + character(len=SPH_INPUT_FIELD_LEN) :: target_set + character(len=SPH_INPUT_FIELD_LEN) :: mode_name + character(len=SPH_INPUT_FIELD_LEN) :: value + real(rk) :: center(SPH_NDIM) + real(rk) :: radius + real(rk) :: scale + real(rk) :: time_window + + ierr = SPH_SUCCESS + center = 0.0_rk + radius = 0.0_rk + scale = 1.0_rk + time_window = 0.0_rk + call sph_input_get_option(line, 'NAME', name) + if (len_trim(name) == 0) name = 'BLAST' + call sph_input_get_optional_real(line, 'X', center(1), ierr) + if (ierr /= SPH_SUCCESS) return + call sph_input_get_optional_real(line, 'Y', center(2), ierr) + if (ierr /= SPH_SUCCESS) return + call sph_input_get_optional_real(line, 'Z', center(3), ierr) + if (ierr /= SPH_SUCCESS) return + call sph_input_get_required_real(line, 'RADIUS', radius, ierr) + if (ierr /= SPH_SUCCESS) return + call sph_input_get_option(line, 'SOURCE_PHASE', source_phase) + if (len_trim(source_phase) == 0) call sph_input_get_option(line, 'SOURCE', source_phase) + if (len_trim(source_phase) == 0) source_phase = 'GAS' + call sph_input_get_option(line, 'TARGET_PHASE', target_phase) + if (len_trim(target_phase) == 0) call sph_input_get_option(line, 'TARGET', target_phase) + if (len_trim(target_phase) == 0) target_phase = 'STRUCTURE' + call sph_input_get_option(line, 'TARGET_SET', target_set) + if (len_trim(target_set) == 0) call sph_input_get_option(line, 'SET', target_set) + if (len_trim(target_set) == 0) call sph_input_get_option(line, 'ELSET', target_set) + if (len_trim(target_set) == 0) call sph_input_get_option(line, 'NSET', target_set) + if (len_trim(target_set) == 0) then + call sph_input_set_error('Blast region is missing TARGET_SET option') + ierr = SPH_ERROR_INPUT + return + end if + call sph_input_get_option(line, 'SCALE', value) + if (len_trim(value) == 0) call sph_input_get_option(line, 'FACTOR', value) + if (len_trim(value) > 0) then + call sph_input_parse_real_value(value, scale, 'invalid blast SCALE', ierr) + if (ierr /= SPH_SUCCESS) return + end if + call sph_input_get_option(line, 'TIME_WINDOW', value) + if (len_trim(value) == 0) call sph_input_get_option(line, 'WINDOW', value) + if (len_trim(value) > 0) then + call sph_input_parse_real_value(value, time_window, & + 'invalid blast TIME_WINDOW', ierr) + if (ierr /= SPH_SUCCESS) return + end if + call sph_input_get_option(line, 'MODE', mode_name) + if (len_trim(mode_name) == 0) call sph_input_get_option(line, 'PROJECTION', mode_name) + if (len_trim(mode_name) == 0) mode_name = 'RADIAL' + call sph_blast_add_region(name, center, radius, source_phase, & + target_phase, target_set, scale, time_window, mode_name, ierr) + end subroutine sph_input_parse_blast_region + subroutine sph_input_parse_shell_director(line, ierr) character(len=*), intent(in) :: line integer, intent(out) :: ierr diff --git a/src/interface/sph_api.f90 b/src/interface/sph_api.f90 index 0cad9ef..2ef507e 100644 --- a/src/interface/sph_api.f90 +++ b/src/interface/sph_api.f90 @@ -27,6 +27,7 @@ module sph_api use sph_explosive, only: sph_explosive_initialize, sph_explosive_reset, & sph_explosive_get_summary, sph_explosive_get_release_balance, & sph_explosive_set_default_ignition_point + use sph_blast, only: sph_blast_initialize, sph_blast_reset use sph_solid, only: sph_solid_initialize, sph_solid_reset use sph_solid_dynamics, only: sph_solid_get_counts, sph_solid_get_summary use sph_solid_api, only: sph_solid_get_state, sph_solid_get_diagnostics, & @@ -50,6 +51,7 @@ contains call sph_water_initialize() call sph_gas_initialize() call sph_explosive_initialize() + call sph_blast_initialize() call sph_solid_initialize() call sph_shell_initialize() call sph_api_state_set_initialized(.true.) @@ -68,6 +70,7 @@ contains call sph_water_reset() call sph_gas_reset() call sph_explosive_reset() + call sph_blast_reset() call sph_solid_reset() call sph_shell_reset() call sph_log_close(local_ierr) diff --git a/tests/module/test_input_blast_errors.f90 b/tests/module/test_input_blast_errors.f90 new file mode 100644 index 0000000..29e05d4 --- /dev/null +++ b/tests/module/test_input_blast_errors.f90 @@ -0,0 +1,77 @@ +program test_input_blast_errors + use sph_precision, only: rk, SPH_NDIM + use sph_error, only: SPH_SUCCESS + use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model + use sph_blast, only: sph_blast_reset, sph_blast_add_region + implicit none + + call expect_input_error('tests/data/blast_missing_target_set_070.inp', & + 'unknown Blast target set') + call expect_input_error('tests/data/blast_bad_radius_070.inp', & + 'bad Blast radius') + call expect_input_error('tests/data/blast_bad_scale_070.inp', & + 'bad Blast scale') + call expect_input_error('tests/data/blast_missing_product_gas_070.inp', & + 'missing Explosive product Gas') + call expect_direct_error('bad source phase', 'PLASMA', 'SOLID', & + 0.40_rk, 1.0_rk, 0.0_rk, 'RADIAL') + call expect_direct_error('bad target phase', 'GAS', 'BEAM', & + 0.40_rk, 1.0_rk, 0.0_rk, 'RADIAL') + call expect_direct_error('bad time window', 'GAS', 'SOLID', & + 0.40_rk, 1.0_rk, -1.0e-6_rk, 'RADIAL') + call expect_direct_error('bad mode', 'GAS', 'SOLID', & + 0.40_rk, 1.0_rk, 0.0_rk, 'TANGENTIAL') + +contains + + subroutine expect_input_error(filename, label) + character(len=*), intent(in) :: filename + character(len=*), intent(in) :: label + integer :: ierr + integer :: final_ierr + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for ' // label) + call sph_read_inp(filename, ierr) + if (ierr == SPH_SUCCESS) then + call sph_build_model(ierr) + end if + if (ierr == SPH_SUCCESS) call fail('input unexpectedly passed: ' // label) + call sph_finalize(final_ierr) + call assert_ok(final_ierr, 'finalize failed for ' // label) + end subroutine expect_input_error + + subroutine expect_direct_error(label, source_phase, target_phase, radius, & + scale, time_window, mode_name) + character(len=*), intent(in) :: label + character(len=*), intent(in) :: source_phase + character(len=*), intent(in) :: target_phase + real(rk), intent(in) :: radius + real(rk), intent(in) :: scale + real(rk), intent(in) :: time_window + character(len=*), intent(in) :: mode_name + real(rk) :: center(SPH_NDIM) + integer :: ierr + + center = 0.0_rk + call sph_blast_reset() + call sph_blast_add_region('DIRECT_BAD', center, radius, source_phase, & + target_phase, 'NONE', scale, time_window, mode_name, ierr) + if (ierr == SPH_SUCCESS) call fail('direct check unexpectedly passed: ' // label) + end subroutine expect_direct_error + + 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_blast_errors diff --git a/tests/module/test_input_blast_region.f90 b/tests/module/test_input_blast_region.f90 new file mode 100644 index 0000000..62ae9c5 --- /dev/null +++ b/tests/module/test_input_blast_region.f90 @@ -0,0 +1,102 @@ +program test_input_blast_region + 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_blast, only: blast_region_count, blast_region_name, & + blast_target_set_name, blast_source_phase, blast_target_phase, & + blast_projection_mode, blast_region_enabled, blast_center, & + blast_radius, blast_load_scale, blast_time_window, & + SPH_BLAST_PHASE_GAS, SPH_BLAST_PHASE_SOLID, & + SPH_BLAST_PHASE_SHELL, SPH_BLAST_PHASE_STRUCTURE, & + SPH_BLAST_MODE_RADIAL + implicit none + + call check_region('tests/data/blast_water_gas_explosive_solid_070.inp', & + SPH_BLAST_PHASE_SOLID, 'SOLID_TARGET', 0.45_rk, .true., .false.) + call check_region('tests/data/blast_water_gas_explosive_shell_070.inp', & + SPH_BLAST_PHASE_SHELL, 'SHELL_TARGET', 0.45_rk, .true., .false.) + call check_region('tests/data/blast_water_gas_explosive_solid_shell_070.inp', & + SPH_BLAST_PHASE_STRUCTURE, 'STRUCTURE_TARGET', 0.50_rk, .true., .false.) + call check_region('tests/data/blast_no_structure_smoke_070.inp', & + SPH_BLAST_PHASE_STRUCTURE, 'NONE', 0.30_rk, .false., .true.) + +contains + + subroutine check_region(filename, expected_target_phase, expected_set, & + expected_radius, expected_enabled, expect_warning) + character(len=*), intent(in) :: filename + integer, intent(in) :: expected_target_phase + character(len=*), intent(in) :: expected_set + real(rk), intent(in) :: expected_radius + logical, intent(in) :: expected_enabled + logical, intent(in) :: expect_warning + integer :: ierr + integer :: warnings + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for Blast input') + call sph_read_inp(filename, ierr) + call assert_ok(ierr, 'read failed for Blast input') + if (blast_region_count /= 1) call fail('Blast region count mismatch') + if (trim(blast_region_name(1)) /= 'LOCAL_BLAST') then + call fail('Blast region name mismatch') + end if + if (trim(blast_target_set_name(1)) /= trim(expected_set)) then + call fail('Blast target set mismatch') + end if + if (blast_source_phase(1) /= SPH_BLAST_PHASE_GAS) then + call fail('Blast source phase mismatch') + end if + if (blast_target_phase(1) /= expected_target_phase) then + call fail('Blast target phase mismatch') + end if + if (blast_projection_mode(1) /= SPH_BLAST_MODE_RADIAL) then + call fail('Blast projection mode mismatch') + end if + if (blast_region_enabled(1) .neqv. expected_enabled) then + call fail('Blast enabled flag mismatch') + end if + call assert_close(blast_center(1,1), 0.30_rk, 'Blast center X mismatch') + call assert_close(blast_center(2,1), 0.0_rk, 'Blast center Y mismatch') + call assert_close(blast_center(3,1), 0.0_rk, 'Blast center Z mismatch') + call assert_close(blast_radius(1), expected_radius, 'Blast radius mismatch') + call assert_close(blast_load_scale(1), 1.0_rk, 'Blast scale mismatch') + call assert_close(blast_time_window(1), 2.0e-7_rk, & + 'Blast time window mismatch') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for Blast input') + call sph_get_input_warning_count(warnings, ierr) + call assert_ok(ierr, 'Blast warning count failed') + if (expect_warning) then + if (warnings <= 0) call fail('Blast disabled region warning missing') + else + if (warnings /= 0) call fail('unexpected Blast input warning') + end if + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for Blast input') + end subroutine check_region + + subroutine assert_ok(ierr_value, message) + integer, intent(in) :: ierr_value + character(len=*), intent(in) :: message + + if (ierr_value /= SPH_SUCCESS) call fail(message) + end subroutine assert_ok + + subroutine assert_close(actual, expected, message) + real(rk), intent(in) :: actual + real(rk), intent(in) :: expected + character(len=*), intent(in) :: message + + if (abs(actual - expected) > 1.0e-12_rk) call fail(message) + end subroutine assert_close + + subroutine fail(message) + character(len=*), intent(in) :: message + + write(*, '(A)') trim(message) + stop 1 + end subroutine fail + +end program test_input_blast_region diff --git a/todo.md b/todo.md index 7509d43..34258bd 100644 --- a/todo.md +++ b/todo.md @@ -41,36 +41,36 @@ ## 阶段 B:0.7.0 输入控制、结构目标和局部爆炸区域 -- [ ] 设计 0.7.0 局部爆炸 smoke 的输入关键词边界。 -- [ ] 优先复用既有 Abaqus 子集表达材料、section、set 和 element 信息。 -- [ ] 定义 SPHLite 调试扩展关键词的最小集合。 -- [ ] 设计局部爆炸区域名称、中心和半径字段。 -- [ ] 设计结构载荷目标 set 或 elset 字段。 -- [ ] 设计结构载荷源 phase 过滤字段。 -- [ ] 设计结构载荷目标 phase 过滤字段。 -- [ ] 设计压力载荷比例系数字段。 -- [ ] 设计冲量或时间窗口控制字段。 -- [ ] 设计载荷投影模式字段。 -- [ ] 设计 Solid 和 Shell 目标共用的输入约定。 -- [ ] 支持读取局部爆炸区域控制参数。 -- [ ] 支持读取结构载荷目标集合名称。 -- [ ] 支持读取源相过滤参数。 -- [ ] 支持读取目标相过滤参数。 -- [ ] 支持读取载荷比例系数。 -- [ ] 支持读取载荷时间窗口。 -- [ ] 支持读取载荷投影模式。 -- [ ] 校验局部爆炸区域半径为正有限值。 -- [ ] 校验载荷比例系数为有限值。 -- [ ] 校验时间窗口为非负有限值。 -- [ ] 校验源 phase 名称合法。 -- [ ] 校验目标 phase 名称合法。 -- [ ] 校验目标 set 存在。 -- [ ] 对未被使用的局部爆炸控制项报 warning。 -- [ ] 对 active 结构粒子缺失载荷控制保持 no-op。 -- [ ] 新增 `input_blast_region` 测试。 -- [ ] 新增 `input_blast_errors` 测试。 -- [ ] 将输入控制测试接入 CTest。 -- [ ] 准备阶段 B 本地提交说明。 +- [x] 设计 0.7.0 局部爆炸 smoke 的输入关键词边界。 +- [x] 优先复用既有 Abaqus 子集表达材料、section、set 和 element 信息。 +- [x] 定义 SPHLite 调试扩展关键词的最小集合。 +- [x] 设计局部爆炸区域名称、中心和半径字段。 +- [x] 设计结构载荷目标 set 或 elset 字段。 +- [x] 设计结构载荷源 phase 过滤字段。 +- [x] 设计结构载荷目标 phase 过滤字段。 +- [x] 设计压力载荷比例系数字段。 +- [x] 设计冲量或时间窗口控制字段。 +- [x] 设计载荷投影模式字段。 +- [x] 设计 Solid 和 Shell 目标共用的输入约定。 +- [x] 支持读取局部爆炸区域控制参数。 +- [x] 支持读取结构载荷目标集合名称。 +- [x] 支持读取源相过滤参数。 +- [x] 支持读取目标相过滤参数。 +- [x] 支持读取载荷比例系数。 +- [x] 支持读取载荷时间窗口。 +- [x] 支持读取载荷投影模式。 +- [x] 校验局部爆炸区域半径为正有限值。 +- [x] 校验载荷比例系数为有限值。 +- [x] 校验时间窗口为非负有限值。 +- [x] 校验源 phase 名称合法。 +- [x] 校验目标 phase 名称合法。 +- [x] 校验目标 set 存在。 +- [x] 对未被使用的局部爆炸控制项报 warning。 +- [x] 对 active 结构粒子缺失载荷控制保持 no-op。 +- [x] 新增 `input_blast_region` 测试。 +- [x] 新增 `input_blast_errors` 测试。 +- [x] 将输入控制测试接入 CTest。 +- [x] 准备阶段 B 本地提交说明。 ## 阶段 C:局部爆炸源项快照和载荷候选筛选