Add Solid 0.5.1 input validation

This commit is contained in:
Codex
2026-07-03 17:06:42 +08:00
parent 98d05aa94d
commit f1ad27c5d7
10 changed files with 307 additions and 24 deletions
+6
View File
@@ -181,6 +181,12 @@ 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_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}")
add_test(NAME solid_051_input_validation COMMAND test_solid_051_input_validation)
set_tests_properties(solid_051_input_validation PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_solid_state_build tests/module/test_solid_state_build.f90)
target_link_libraries(test_solid_state_build PRIVATE sphlite_core)
set_target_properties(test_solid_state_build PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
+7 -1
View File
@@ -189,7 +189,7 @@ contains
particle_phase(i) = SPH_PHASE_SOLID
particle_status(i) = SPH_STATUS_ACTIVE
material_id(i) = 1
section_id(i) = 1
section_id(i) = 0
x0(:,i) = 0.0_rk
x(:,i) = 0.0_rk
v(:,i) = 0.0_rk
@@ -467,6 +467,12 @@ contains
integer :: i
ierr = SPH_SUCCESS
if (density_value /= density_value .or. &
abs(density_value) > huge(density_value) * 0.5_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'material density must be finite')
ierr = SPH_ERROR_ARGUMENT
return
end if
if (density_value <= 0.0_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'material density must be positive')
ierr = SPH_ERROR_ARGUMENT
+52 -3
View File
@@ -9,7 +9,8 @@ module sph_input_reader
sph_db_allocate, sph_db_free, sph_db_set_node, sph_db_add_material, &
sph_db_add_section, sph_db_add_nset, sph_db_add_elset, &
sph_db_add_element, sph_db_add_coupling_region, sph_db_apply_sections_to_particles
use sph_database, only: sph_db_set_material_density
use sph_database, only: sph_db_set_material_density, material_count, &
material_name, material_type
use sph_water, only: sph_water_note_material, sph_water_set_eos, &
sph_water_set_viscosity, sph_water_set_particle_control, &
sph_water_set_body_force, sph_water_apply_initial_conditions
@@ -283,6 +284,8 @@ contains
integer :: points
integer :: ios
integer :: local_ierr
integer :: mat_index
logical :: is_solid_section
character(len=SPH_INPUT_LINE_LEN) :: upper_line
ierr = SPH_SUCCESS
@@ -305,7 +308,6 @@ 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)
if (len_trim(material_value) == 0) material_value = 'MATERIAL'
thickness = 0.0_rk
points = 3
call sph_input_get_option(line, 'THICKNESS', value)
@@ -313,7 +315,25 @@ contains
call sph_input_get_option(line, 'POINTS', value)
if (len_trim(value) > 0) read(value, *, iostat=ios) points
section_type_value = 'SECTION'
if (index(upper_line, '*SOLID SECTION') == 1) section_type_value = 'SOLID'
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)
else if (key_id == SPH_KEY_SPHLITE) then
@@ -758,6 +778,35 @@ contains
call sph_db_add_coupling_region(name, set_name, region_type, ierr)
end subroutine sph_input_parse_coupling_region
integer function sph_input_find_material(name)
character(len=*), intent(in) :: name
integer :: i
sph_input_find_material = 0
do i = 1, material_count
if (trim(sph_inp_upper(material_name(i))) == trim(sph_inp_upper(name))) then
sph_input_find_material = i
return
end if
end do
end function sph_input_find_material
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
upper_type = sph_inp_upper(type_name)
sph_input_is_explicit_non_solid_type = .false.
if (len_trim(upper_type) == 0) return
if (index(upper_type, 'UNSPECIFIED') > 0) return
if (index(upper_type, 'SOLID') > 0) return
if (index(upper_type, 'WATER') > 0) sph_input_is_explicit_non_solid_type = .true.
if (index(upper_type, 'GAS') > 0) sph_input_is_explicit_non_solid_type = .true.
if (index(upper_type, 'EXPLOSIVE') > 0) sph_input_is_explicit_non_solid_type = .true.
if (index(upper_type, 'SHELL') > 0) sph_input_is_explicit_non_solid_type = .true.
if (index(upper_type, 'BOUNDARY') > 0) sph_input_is_explicit_non_solid_type = .true.
end function sph_input_is_explicit_non_solid_type
subroutine sph_input_parse_node(line, node_index, ierr)
character(len=*), intent(in) :: line
integer, intent(in) :: node_index
+52
View File
@@ -5,6 +5,7 @@ module sph_solid
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, rho, temperature, internal_energy, &
section_count, section_id, section_type, section_material_id, &
SPH_PHASE_SOLID, SPH_PHASE_SOLID_FAILED, SPH_STATUS_ACTIVE, &
SPH_STATUS_FAILED
use sph_solid_state
@@ -100,6 +101,11 @@ contains
integer :: solid_index
ierr = SPH_SUCCESS
if (.not. sph_solid_vector_is_finite((/ e_value, nu_value /))) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Solid 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, 'Solid elastic modulus must be positive')
ierr = SPH_ERROR_ARGUMENT
@@ -130,8 +136,17 @@ contains
real(rk), intent(in) :: tmelt_value
integer, intent(out) :: ierr
integer :: solid_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_solid_vector_is_finite(jc_values)) then
call sph_error_set(SPH_ERROR_ARGUMENT, &
'Solid 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, 'Solid Johnson-Cook strength is invalid')
ierr = SPH_ERROR_ARGUMENT
@@ -200,6 +215,11 @@ contains
ierr = SPH_ERROR_INPUT
return
end if
if (.not. sph_solid_vector_is_finite((/ softening_width_value /))) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Solid 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, 'Solid softening WIDTH must be positive')
ierr = SPH_ERROR_ARGUMENT
@@ -239,8 +259,40 @@ contains
return
end if
end do
call sph_solid_validate_particle_sections(ierr)
end subroutine sph_solid_validate_input
subroutine sph_solid_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_SOLID) cycle
sec = section_id(i)
if (sec < 1 .or. sec > section_count) then
call sph_error_set(SPH_ERROR_INPUT, &
'active Solid particle is missing Solid section')
ierr = SPH_ERROR_INPUT
return
end if
if (index(sph_solid_upper(section_type(sec)), 'SOLID') <= 0) then
call sph_error_set(SPH_ERROR_INPUT, &
'active Solid particle is not bound to Solid 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 Solid particle section material mismatch')
ierr = SPH_ERROR_INPUT
return
end if
end do
end subroutine sph_solid_validate_particle_sections
subroutine sph_solid_count_unbound_materials(count)
integer, intent(out) :: count
integer :: solid_index
+14
View File
@@ -0,0 +1,14 @@
*NODE
1, 0.0, 0.0, 0.0
*ELEMENT, TYPE=SPH3D
1, 1
*ELSET, ELSET=SOLID_PARTICLES
1
*MATERIAL, NAME=STEEL_BAD_DENSITY, TYPE=SOLID
*DENSITY
-7850.0
*ELASTIC
210.0E9, 0.30
*SOLID SECTION, ELSET=SOLID_PARTICLES, MATERIAL=STEEL_BAD_DENSITY
*SPHLITE PARTICLE CONTROL, H=0.15, MASS=7.85, VOLUME=0.001
*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5
+18
View File
@@ -0,0 +1,18 @@
*NODE
1, 0.0, 0.0, 0.0
*ELEMENT, TYPE=SPH3D
1, 1
*ELSET, ELSET=SOLID_PARTICLES
1
*MATERIAL, NAME=STEEL_BAD_FAILURE_NAN, TYPE=SOLID
*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
*SOLID SECTION, ELSET=SOLID_PARTICLES, MATERIAL=STEEL_BAD_FAILURE_NAN
*SPHLITE PARTICLE CONTROL, H=0.15, MASS=7.85, VOLUME=0.001
*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5
@@ -0,0 +1,14 @@
*NODE
1, 0.0, 0.0, 0.0
*ELEMENT, TYPE=SPH3D
1, 1
*ELSET, ELSET=SOLID_PARTICLES
1
*MATERIAL, NAME=STEEL_SECTION_MISSING_MATERIAL, TYPE=SOLID
*DENSITY
7850.0
*ELASTIC
210.0E9, 0.30
*SOLID SECTION, ELSET=SOLID_PARTICLES
*SPHLITE PARTICLE CONTROL, H=0.15, MASS=7.85, VOLUME=0.001
*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5
@@ -0,0 +1,14 @@
*NODE
1, 0.0, 0.0, 0.0
*ELEMENT, TYPE=SPH3D
1, 1
*ELSET, ELSET=SOLID_PARTICLES
1
*MATERIAL, NAME=STEEL_SECTION_UNKNOWN_MATERIAL, TYPE=SOLID
*DENSITY
7850.0
*ELASTIC
210.0E9, 0.30
*SOLID SECTION, ELSET=SOLID_PARTICLES, MATERIAL=UNKNOWN_STEEL
*SPHLITE PARTICLE CONTROL, H=0.15, MASS=7.85, VOLUME=0.001
*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5
@@ -0,0 +1,110 @@
program test_solid_051_input_validation
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: particle_phase, SPH_PHASE_WATER, SPH_PHASE_GAS, &
SPH_PHASE_EXPLOSIVE
implicit none
integer :: ierr
integer :: warnings
call check_good_input('tests/data/solid_reference_normal_051.inp')
call check_unbound_solid_warning()
call check_first_phase('tests/data/water_set_name_not_type_021.inp', &
SPH_PHASE_WATER)
call check_first_phase('tests/data/gas_ideal_minimal_030.inp', &
SPH_PHASE_GAS)
call check_first_phase('tests/data/explosive_minimal_040.inp', &
SPH_PHASE_EXPLOSIVE)
call check_bad_input('tests/data/solid_missing_density_050.inp')
call check_bad_input('tests/data/solid_bad_density_051.inp')
call check_bad_input('tests/data/solid_missing_elastic_050.inp')
call check_bad_input('tests/data/solid_bad_elastic_050.inp')
call check_bad_input('tests/data/solid_bad_poisson_051.inp')
call check_bad_input('tests/data/solid_bad_johnson_cook_050.inp')
call check_bad_input('tests/data/solid_bad_johnson_cook_nan_051.inp')
call check_bad_input('tests/data/solid_bad_failure_050.inp')
call check_bad_input('tests/data/solid_bad_failure_nan_051.inp')
call check_bad_input('tests/data/solid_bad_softening_051.inp')
call check_bad_input('tests/data/solid_bad_section_050.inp')
call check_bad_input('tests/data/solid_section_missing_material_051.inp')
call check_bad_input('tests/data/solid_section_unknown_material_051.inp')
call check_bad_input('tests/data/solid_section_non_solid_051.inp')
call check_bad_input('tests/data/solid_missing_section_051.inp')
contains
subroutine check_good_input(filename)
character(len=*), intent(in) :: filename
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for good Solid 0.5.1 input')
call sph_read_inp(filename, ierr)
call assert_ok(ierr, 'read failed for good Solid 0.5.1 input')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for good Solid 0.5.1 input')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for good Solid 0.5.1 input')
end subroutine check_good_input
subroutine check_unbound_solid_warning()
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for unbound Solid warning input')
call sph_read_inp('tests/data/solid_unbound_material_warning_050.inp', &
ierr)
call assert_ok(ierr, 'read failed for unbound Solid warning input')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for unbound Solid warning input')
call sph_get_input_warning_count(warnings, ierr)
call assert_ok(ierr, 'warning count failed for unbound Solid input')
if (warnings <= 0) call fail('unbound Solid material warning missing')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for unbound Solid warning input')
end subroutine check_unbound_solid_warning
subroutine check_first_phase(filename, expected_phase)
character(len=*), intent(in) :: filename
integer, intent(in) :: expected_phase
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for phase guard input')
call sph_read_inp(filename, ierr)
call assert_ok(ierr, 'read failed for phase guard input')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for phase guard input')
if (particle_phase(1) /= expected_phase) call fail('phase guard mismatch')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for phase guard input')
end subroutine check_first_phase
subroutine check_bad_input(filename)
character(len=*), intent(in) :: filename
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for bad Solid input')
call sph_read_inp(filename, ierr)
if (ierr == SPH_SUCCESS) then
call sph_build_model(ierr)
if (ierr == SPH_SUCCESS) call fail('bad Solid input built successfully')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed after bad Solid 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_solid_051_input_validation
+20 -20
View File
@@ -38,26 +38,26 @@
## 阶段 B:Solid 输入校验、section 校验与 warning/error 路径
- [ ] 复核 0.5.0 Solid material 解析路径并保持语法兼容。
- [ ] 对 Solid material 缺失密度路径保持 error。
- [ ] 对 Solid material 非正密度路径保持 error。
- [ ] 对 Solid material 缺失弹性参数路径保持 error。
- [ ] 对 Solid material 非正弹性模量路径保持 error。
- [ ] 对 Solid material 非法泊松比路径新增或加固 error。
- [ ] 对 Johnson-Cook flow 参数非有限路径新增或加固 error。
- [ ] 对 Johnson-Cook failure 参数非完整路径保持 error。
- [ ] 对 Johnson-Cook failure 参数非有限路径新增或加固 error。
- [ ] 对 unsupported softening 类型新增或加固 error。
- [ ] 对未被 active Solid 粒子使用的 Solid material 保持 warning。
- [ ] 对 `*SOLID SECTION` 缺失 material 参数路径保持 error。
- [ ] 对 `*SOLID SECTION` 指向不存在 material 路径保持 error。
- [ ] 对 `*SOLID SECTION` 指向非 Solid material 路径新增或加固 error。
- [ ] 对存在 active Solid 粒子但缺失 Solid section 的模型给出 error。
- [ ] 确认 set 仍只表示集合,不参与 Solid 类型判断。
- [ ] 确认 phase/status 默认值不改变 Water/Gas/Explosive 路径。
- [ ] 新增 `solid_051_input_validation` Fortran 输入测试。
- [ ] 将 `solid_051_input_validation` 接入 CTest。
- [ ] 确认 0.5.0 `input_solid_material` 和 `input_solid_errors` 仍通过。
- [x] 复核 0.5.0 Solid material 解析路径并保持语法兼容。
- [x] 对 Solid material 缺失密度路径保持 error。
- [x] 对 Solid material 非正密度路径保持 error。
- [x] 对 Solid material 缺失弹性参数路径保持 error。
- [x] 对 Solid material 非正弹性模量路径保持 error。
- [x] 对 Solid material 非法泊松比路径新增或加固 error。
- [x] 对 Johnson-Cook flow 参数非有限路径新增或加固 error。
- [x] 对 Johnson-Cook failure 参数非完整路径保持 error。
- [x] 对 Johnson-Cook failure 参数非有限路径新增或加固 error。
- [x] 对 unsupported softening 类型新增或加固 error。
- [x] 对未被 active Solid 粒子使用的 Solid material 保持 warning。
- [x] 对 `*SOLID SECTION` 缺失 material 参数路径保持 error。
- [x] 对 `*SOLID SECTION` 指向不存在 material 路径保持 error。
- [x] 对 `*SOLID SECTION` 指向非 Solid material 路径新增或加固 error。
- [x] 对存在 active Solid 粒子但缺失 Solid section 的模型给出 error。
- [x] 确认 set 仍只表示集合,不参与 Solid 类型判断。
- [x] 确认 phase/status 默认值不改变 Water/Gas/Explosive 路径。
- [x] 新增 `solid_051_input_validation` Fortran 输入测试。
- [x] 将 `solid_051_input_validation` 接入 CTest。
- [x] 确认 0.5.0 `input_solid_material` 和 `input_solid_errors` 仍通过。
## 阶段 C:参考邻域、修正矩阵与变形梯度状态