diff --git a/CMakeLists.txt b/CMakeLists.txt index 795a144..6d77ab2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,8 @@ set(SPHLITE_CORE_SOURCES src/water/sph_water.f90 src/gas/sph_gas_source.f90 src/gas/sph_gas.f90 + src/explosive/sph_explosive_state.f90 + src/explosive/sph_explosive_helpers.f90 src/explosive/sph_explosive.f90 src/solid/sph_solid.f90 src/shell/sph_shell.f90 @@ -136,6 +138,18 @@ set_target_properties(test_input_gas_multimaterial PROPERTIES Fortran_MODULE_DIR add_test(NAME input_gas_multimaterial COMMAND test_input_gas_multimaterial) set_tests_properties(input_gas_multimaterial PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +add_executable(test_input_explosive tests/module/test_input_explosive.f90) +target_link_libraries(test_input_explosive PRIVATE sphlite_core) +set_target_properties(test_input_explosive PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME input_explosive COMMAND test_input_explosive) +set_tests_properties(input_explosive PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_input_explosive_errors tests/module/test_input_explosive_errors.f90) +target_link_libraries(test_input_explosive_errors PRIVATE sphlite_core) +set_target_properties(test_input_explosive_errors PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME input_explosive_errors COMMAND test_input_explosive_errors) +set_tests_properties(input_explosive_errors PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + add_executable(test_c_api tests/interface/test_c_api.c) target_include_directories(test_c_api PRIVATE include) target_compile_definitions(test_c_api PRIVATE @@ -145,6 +159,8 @@ target_compile_definitions(test_c_api PRIVATE target_link_libraries(test_c_api PRIVATE sphlite_c) add_test(NAME c_api COMMAND test_c_api) set_tests_properties(c_api PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +add_test(NAME explosive_c_api COMMAND test_c_api) +set_tests_properties(explosive_c_api PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") add_executable(test_cpp_api tests/interface/test_cpp_api.cpp) target_include_directories(test_cpp_api PRIVATE include) @@ -277,6 +293,48 @@ set_target_properties(test_explosive_detonation_time PROPERTIES Fortran_MODULE_D add_test(NAME explosive_detonation_time COMMAND test_explosive_detonation_time) set_tests_properties(explosive_detonation_time PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +add_executable(test_explosive_reaction_progress tests/module/test_explosive_reaction_progress.f90) +target_link_libraries(test_explosive_reaction_progress PRIVATE sphlite_core) +set_target_properties(test_explosive_reaction_progress PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME explosive_reaction_progress COMMAND test_explosive_reaction_progress) +set_tests_properties(explosive_reaction_progress PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_explosive_release_source tests/module/test_explosive_release_source.f90) +target_link_libraries(test_explosive_release_source PRIVATE sphlite_core) +set_target_properties(test_explosive_release_source PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME explosive_release_source COMMAND test_explosive_release_source) +set_tests_properties(explosive_release_source PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_explosive_to_gas_phase tests/module/test_explosive_to_gas_phase.f90) +target_link_libraries(test_explosive_to_gas_phase PRIVATE sphlite_core) +set_target_properties(test_explosive_to_gas_phase PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME explosive_to_gas_phase COMMAND test_explosive_to_gas_phase) +set_tests_properties(explosive_to_gas_phase PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_explosive_gas_coupling tests/module/test_explosive_gas_coupling.f90) +target_link_libraries(test_explosive_gas_coupling PRIVATE sphlite_core) +set_target_properties(test_explosive_gas_coupling PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME explosive_gas_coupling COMMAND test_explosive_gas_coupling) +set_tests_properties(explosive_gas_coupling PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_explosive_summary tests/module/test_explosive_summary.f90) +target_link_libraries(test_explosive_summary PRIVATE sphlite_core) +set_target_properties(test_explosive_summary PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME explosive_summary COMMAND test_explosive_summary) +set_tests_properties(explosive_summary PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_explosive_restart_040 tests/module/test_explosive_restart_040.f90) +target_link_libraries(test_explosive_restart_040 PRIVATE sphlite_core) +set_target_properties(test_explosive_restart_040 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME explosive_restart_040 COMMAND test_explosive_restart_040) +set_tests_properties(explosive_restart_040 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_explosive_restart_031_compat tests/module/test_explosive_restart_031_compat.f90) +target_link_libraries(test_explosive_restart_031_compat PRIVATE sphlite_core) +set_target_properties(test_explosive_restart_031_compat PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME explosive_restart_031_compat COMMAND test_explosive_restart_031_compat) +set_tests_properties(explosive_restart_031_compat PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + add_executable(test_water_density tests/module/test_water_density.f90) target_link_libraries(test_water_density PRIVATE sphlite_core) set_target_properties(test_water_density PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") @@ -317,6 +375,15 @@ add_test( ) set_tests_properties(python_debug PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +add_test( + NAME explosive_python + COMMAND "${Python3_EXECUTABLE}" + "${CMAKE_CURRENT_SOURCE_DIR}/tools/testing/test_python_debug.py" + --library "$" + --input "${CMAKE_CURRENT_SOURCE_DIR}/tests/data/minimal_particles.inp" +) +set_tests_properties(explosive_python PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + add_test( NAME gas_python_extended COMMAND "${Python3_EXECUTABLE}" @@ -337,6 +404,17 @@ add_test( ) set_tests_properties(cli PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +add_test( + NAME explosive_cli + COMMAND "${Python3_EXECUTABLE}" + "${CMAKE_CURRENT_SOURCE_DIR}/tools/testing/test_cli.py" + --exe "$" + --input "${CMAKE_CURRENT_SOURCE_DIR}/tests/data/water_minimal_021.inp" + --bad-input "${CMAKE_CURRENT_SOURCE_DIR}/tests/data/water_missing_eos_020.inp" + --output-dir "${CMAKE_BINARY_DIR}" +) +set_tests_properties(explosive_cli PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + add_test( NAME gas_cli_extended COMMAND "${Python3_EXECUTABLE}" @@ -357,6 +435,15 @@ add_test( ) set_tests_properties(source_size PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +add_test( + NAME explosive_source_size + COMMAND "${Python3_EXECUTABLE}" + "${CMAKE_CURRENT_SOURCE_DIR}/tools/testing/check_source_size.py" + --root "${CMAKE_CURRENT_SOURCE_DIR}" + --exceptions "${CMAKE_CURRENT_SOURCE_DIR}/tests/source_size_exceptions.txt" +) +set_tests_properties(explosive_source_size PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + add_test( NAME gas_source_size_cleanup COMMAND "${Python3_EXECUTABLE}" diff --git a/README.md b/README.md index 1f7735f..54be0f8 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ SPHLite 的编译和测试要求应与 FEMLite 保持一致风格: ## 当前状态 -0.4.0 当前开发重点包括: +0.4.0 当前已完成 `Explosive` 起步闭环,主要包括: - CMake/CTest 工程骨架和 Fortran 95 核心库。 - C ABI、C++ 头文件薄包装和 Python `ctypes` 调试入口。 @@ -71,7 +71,8 @@ SPHLite 的编译和测试要求应与 FEMLite 保持一致风格: - 3D Water 粒子的 Wendland/Cubic 核函数、uniform cell 邻域搜索、Tait EOS、Monaghan 人工黏性、连续性方程和 Velocity-Verlet 显式推进。 - Water summary、稳定时间步诊断、CSV output、restart 和双 pressure wave smoke 小算例。 - Gas material、三类 Gas EOS、Gas 状态初始化、单相显式推进、气体 summary、bubble metrics、Gas CSV/restart、Gas 源项缓存和公开诊断接口。 -- `Explosive` 的解析点火、爆轰到达时间、反应进度、释放量统计、Gas 源项注入和 phase 转化最小闭环。 +- `Explosive` 的解析点火、爆轰到达时间、programmed burn 反应进度、释放量统计、Gas 源项注入和 phase 转化最小闭环。 +- `Explosive` summary、CSV 输出字段、`STATE_0_4` restart、0.3.1 restart 兼容读入、Fortran API、C ABI、C++ wrapper、Python ctypes 和 CLI 字段。 - CouplingInterface 的中立数据导出、外部粒子力导入和诊断占位;0.2.2 不暴露 CouplingInterface C ABI,真实 FEM-SPH 联合运行仍由外部 CouplingModule 后续实现。 - `Solid`、`Shell` 仍为后续阶段,不在 0.4.0 交付生产计算路径。 -- 0.4.0 release gate 与 source size 门禁。 +- 0.4.0 本地 gate 已通过:完整 CTest 51/51,Explosive 专项 gate 14/14,`source_size` 通过。 diff --git a/docs/06_test_and_verification_plan.md b/docs/06_test_and_verification_plan.md index 4e24430..23ca692 100644 --- a/docs/06_test_and_verification_plan.md +++ b/docs/06_test_and_verification_plan.md @@ -142,6 +142,36 @@ git diff --check 2026-07-03 本地结果:默认 gate 37/37 通过,`source_size` 1/1 通过,`git diff --check` 通过。 +## 7.2 0.4.0 Release Gate + +0.4.0 在 0.3.1 Gas 稳定化 gate 基础上新增 `Explosive` 起步闭环测试。默认 gate 继续覆盖既有 Water/Gas/接口/restart/output/source-size 路径,并新增以下 Explosive 专项 gate: + +- `input_explosive` +- `input_explosive_errors` +- `explosive_detonation_time` +- `explosive_reaction_progress` +- `explosive_release_source` +- `explosive_to_gas_phase` +- `explosive_gas_coupling` +- `explosive_summary` +- `explosive_restart_040` +- `explosive_restart_031_compat` +- `explosive_c_api` +- `explosive_python` +- `explosive_cli` +- `explosive_source_size` + +0.4.0 本地 release gate: +```powershell +cmake --build build-codex-unix --parallel +ctest --test-dir build-codex-unix --output-on-failure +ctest --test-dir build-codex-unix -R "^(input_explosive|input_explosive_errors|explosive_detonation_time|explosive_reaction_progress|explosive_release_source|explosive_to_gas_phase|explosive_gas_coupling|explosive_summary|explosive_restart_040|explosive_restart_031_compat|explosive_c_api|explosive_python|explosive_cli|explosive_source_size)$" --output-on-failure +ctest --test-dir build-codex-unix -R "^source_size$" --output-on-failure +git diff --check +``` + +2026-07-03 本地结果:完整 CTest 51/51 通过,Explosive 专项 gate 14/14 通过,`source_size` 1/1 通过,`git diff --check` 通过。 + ## 8. Source Size 门禁 从第一版开始设置 source size 门禁。建议沿用 FEMLite 风格: diff --git a/docs/09_release_history.md b/docs/09_release_history.md index 011f27d..070eabf 100644 --- a/docs/09_release_history.md +++ b/docs/09_release_history.md @@ -1,10 +1,10 @@ # 09 版本历史与验收记录 -文档状态:0.3.1 待发布记录 +文档状态:0.4.0 待发布记录 ## 1. 当前状态 -SPHLite 当前进入 0.3.1 `Gas` 稳定化版本。本版本在 0.3.0 `Gas` 最小闭环基础上补强多 Gas material/EOS 分派、Gas 源项占位、扩展诊断、restart 0.3.1 状态和 0.3.0 restart 兼容读入;`Explosive`、`Solid`、`Shell` 生产路径和真实 FEM-SPH 联合运行仍不在本版本交付范围内。 +SPHLite 当前进入 0.4.0 `Explosive` 起步版本。本版本在 0.3.1 `Gas` 稳定化基础上新增炸药解析点火、爆轰到达时间、programmed burn 反应进度、向 Gas 源项注入质量/动量/能量、完全反应后 phase 转化、summary/output/restart/API/CLI/Python 验收;`Solid`、`Shell` 生产路径和真实 FEM-SPH 联合运行仍不在本版本交付范围内。 ## 2. 规划版本线 @@ -216,6 +216,40 @@ cmake --build build-codex-unix - 建议发布 0.3.1 作为 Gas 稳定化版本。 - 0.3.1 发布后,后续主线可进入 0.4.0 `Explosive`,使用 0.3.1 已建立的 Gas 源项缓存作为质量/动量/能量注入入口。 +### 0.4.0 本地验收记录 + +记录日期:2026-07-03 + +本地构建目录:`build-codex-unix` + +版本定位: + +- 0.4.0 是 `Explosive` 模块的起步闭环版本。 +- 0.4.0 支持 `TYPE=EXPLOSIVE` material、`*SPHLITE EXPLOSIVE` programmed burn 控制和 `*SPHLITE IGNITION` 单点点火。 +- 0.4.0 使用解析爆轰到达时间,不引入球面经验载荷主模型。 +- 0.4.0 支持炸药反应进度、释放质量/动量/能量统计、`CONVERSION=SOURCE` 注入 Gas 源项,以及 `CONVERSION=PHASE` 完全反应后转为 Gas。 +- 0.4.0 restart 写入 `STATE_0_4`,保存 Explosive material 表、点火记录和每粒子反应状态,并兼容 0.3.1 restart 读入时初始化空 Explosive 状态。 +- 0.4.0 追加 Explosive summary 的 Fortran API、C ABI、C++ wrapper、Python ctypes、CLI、CSV output 和专项 CTest gate。 + +验收结果: + +- `cmake --build build-codex-unix --parallel` 通过。 +- `ctest --test-dir build-codex-unix --output-on-failure` 通过:51/51。 +- Explosive 专项 gate 通过:14/14。 +- `ctest --test-dir build-codex-unix -R "^source_size$" --output-on-failure` 通过:1/1。 +- `git diff --check` 通过。 + +不交付范围: + +- 0.4.0 不交付 `Solid`、`Shell` 生产路径。 +- 0.4.0 不交付真实 FEM-SPH 接触耦合或连续体耦合。 +- 0.4.0 不交付工程级水下爆炸 benchmark、完整化学反应爆轰模型或气泡长周期脉动模型。 + +发布建议: + +- 建议发布 0.4.0 作为 Explosive 起步闭环版本。 +- 0.4.0 发布后,后续主线可进入 `Solid`/`Shell` 前置能力或继续加固 Explosive-Gas-Water 链路。 + 后续每个版本应记录: - 完成能力。 diff --git a/docs/11_benchmark_matrix.md b/docs/11_benchmark_matrix.md index 5d724f7..416391f 100644 --- a/docs/11_benchmark_matrix.md +++ b/docs/11_benchmark_matrix.md @@ -1,10 +1,10 @@ # 11 Benchmark 与验收矩阵 -文档状态:0.3.1 gate 记录 +文档状态:0.4.0 gate 记录 ## 1. 当前状态 -0.3.1 在 0.3.0 `Gas` 最小闭环基础上新增 Gas 多材料、material/EOS 分派、Gas 源项占位、扩展诊断和 restart 兼容 gate,并继续保留工程 benchmark 矩阵作为长期规划。本版本的 pressure wave smoke、Gas bubble metrics 和 Gas 源项测试只用于小规模数值链路检查,不作为工程精度 benchmark。 +0.4.0 在 0.3.1 `Gas` 稳定化基础上新增 `Explosive` 起步闭环 gate,并继续保留工程 benchmark 矩阵作为长期规划。本版本的 Explosive programmed burn、Gas 源项注入、phase 转化、pressure wave smoke 和 Gas bubble metrics 只用于小规模数值链路检查,不作为工程精度 benchmark。 ## 2. 0.1.0 Release Gate @@ -207,6 +207,35 @@ |---|---|---| | 2026-07-03 | `build-codex-unix` | 0.3.1 gate 37/37 通过,`source_size` 1/1 通过,`git diff --check` 通过 | +## 2.7 0.4.0 Release Gate + +0.4.0 默认 gate 在 0.3.1 Gas gate 基础上新增 Explosive 输入、反应、Gas 源项/phase 转化、summary、restart 和接口层验收。 + +| 测试名 | 类型 | 验收点 | +|---|---|---| +| `input_explosive` | Fortran input | Explosive material、section、control、ignition、product Gas/JWL EOS | +| `input_explosive_errors` | Fortran input | 非法爆速、非法 product、非法 ignition、缺密度、非法 burn time、非法能量、product Gas 缺 EOS | +| `explosive_detonation_time` | Fortran module | 按初始坐标和爆速计算爆轰到达时间范围 | +| `explosive_reaction_progress` | Fortran module | programmed burn 下 `lambda` 单调增加并限制在 `[0,1]` | +| `explosive_release_source` | Fortran module | `CONVERSION=SOURCE` 向 Gas 源项注入质量、动量和能量 | +| `explosive_to_gas_phase` | Fortran module | `CONVERSION=PHASE` 完全反应后不可逆转为 Gas | +| `explosive_gas_coupling` | Fortran module | 产物 Gas material 使用 JWL EOS 并刷新 Gas summary | +| `explosive_summary` | Fortran API | Explosive 粒子数、反应粒子数、`lambda` 范围和释放量一致性 | +| `explosive_restart_040` | Fortran restart | `STATE_0_4` 写入读回并继续显式步 | +| `explosive_restart_031_compat` | Fortran restart | 0.3.1 restart 兼容读入并初始化空 Explosive 状态 | +| `explosive_c_api` | C ABI | 点火点设置和 Explosive summary 查询 | +| `explosive_python` | Python `ctypes` | Explosive summary 和点火接口薄包装 | +| `explosive_cli` | CLI | inspect/run 输出 Explosive 字段 | +| `explosive_source_size` | 工具门禁 | Explosive 模块拆分、source size 和 stale exception 检查 | + +0.4.0 不验收 `Solid`、`Shell` 的生产级物理结果,也不验收真实 FEM-SPH 联合运行。Explosive-Gas 链路仍是小规模数值闭环,不代表工程级水下爆炸 benchmark。 + +本地验收记录: + +| 日期 | 构建目录 | 结果 | +|---|---|---| +| 2026-07-03 | `build-codex-unix` | 完整 CTest 51/51 通过,Explosive gate 14/14 通过,`source_size` 1/1 通过,`git diff --check` 通过 | + ## 3. 基础数值矩阵 | 领域 | 测试或 benchmark | 验收点 | diff --git a/src/explosive/sph_explosive.f90 b/src/explosive/sph_explosive.f90 index 20c5245..61112b2 100644 --- a/src/explosive/sph_explosive.f90 +++ b/src/explosive/sph_explosive.f90 @@ -2,45 +2,14 @@ module sph_explosive use sph_precision, only: rk, SPH_NDIM use sph_error, only: SPH_SUCCESS, SPH_ERROR_ARGUMENT, SPH_ERROR_INPUT, & sph_error_set - use sph_database, only: SPH_MAX_MATERIALS, SPH_MAX_SECTIONS, material_count, & - material_name, material_type, material_density, section_count, & - section_material_id, npart, particle_phase, particle_status, & - material_id, x0, v, mass, rho, volume, internal_energy, & - SPH_PHASE_EXPLOSIVE, SPH_PHASE_GAS, SPH_STATUS_ACTIVE - use sph_gas, only: sph_gas_table_index_by_material_id, & - gas_material_eos_defined, sph_gas_clear_sources, & - sph_gas_add_source_by_particle + use sph_database, only: SPH_MAX_MATERIALS, material_count, material_name, & + material_density, npart, particle_phase, material_id, x0, v, mass, rho, & + volume, internal_energy, SPH_PHASE_GAS + use sph_gas, only: sph_gas_clear_sources, sph_gas_add_source_by_particle + use sph_explosive_state + use sph_explosive_helpers implicit none - integer, parameter :: EXPLOSIVE_CONVERSION_NONE = 0 - integer, parameter :: EXPLOSIVE_CONVERSION_PHASE = 1 - integer, parameter :: EXPLOSIVE_CONVERSION_SOURCE = 2 - - logical :: explosive_module_initialized = .false. - logical :: explosive_material_seen = .false. - integer :: explosive_material_count = 0 - integer :: explosive_material_id(SPH_MAX_MATERIALS) = 0 - character(len=64) :: explosive_material_name(SPH_MAX_MATERIALS) = ' ' - logical :: explosive_control_defined(SPH_MAX_MATERIALS) = .false. - integer :: explosive_product_material_id(SPH_MAX_MATERIALS) = 0 - character(len=64) :: explosive_product_material_name(SPH_MAX_MATERIALS) = ' ' - real(rk) :: explosive_density0(SPH_MAX_MATERIALS) = 0.0_rk - real(rk) :: explosive_detonation_velocity(SPH_MAX_MATERIALS) = 0.0_rk - real(rk) :: explosive_energy_per_mass(SPH_MAX_MATERIALS) = 0.0_rk - real(rk) :: explosive_burn_time(SPH_MAX_MATERIALS) = 0.0_rk - integer :: explosive_conversion_mode(SPH_MAX_MATERIALS) = EXPLOSIVE_CONVERSION_NONE - integer :: explosive_ignition_count = 0 - integer :: explosive_ignition_material_id(SPH_MAX_MATERIALS) = 0 - real(rk) :: explosive_ignition_x(SPH_NDIM,SPH_MAX_MATERIALS) = 0.0_rk - real(rk) :: explosive_ignition_time(SPH_MAX_MATERIALS) = 0.0_rk - integer, allocatable :: explosive_ignition_status(:) - real(rk), allocatable :: explosive_detonation_time(:) - real(rk), allocatable :: explosive_reaction_progress(:) - real(rk), allocatable :: explosive_released_mass(:) - real(rk), allocatable :: explosive_released_energy(:) - real(rk), allocatable :: explosive_released_momentum(:,:) - real(rk) :: explosive_dt_reaction = 0.0_rk - contains subroutine sph_explosive_initialize() @@ -637,223 +606,4 @@ contains end do end subroutine sph_explosive_get_detonation_time_range - subroutine sph_explosive_prepare_material(name, explosive_index, ierr) - character(len=*), intent(in) :: name - integer, intent(out) :: explosive_index - integer, intent(out) :: ierr - integer :: mat_index - - ierr = SPH_SUCCESS - explosive_index = 0 - mat_index = sph_explosive_find_material(name) - if (mat_index <= 0) then - call sph_error_set(SPH_ERROR_INPUT, 'Explosive control references unknown material') - ierr = SPH_ERROR_INPUT - return - end if - if (index(sph_explosive_upper(material_type(mat_index)), 'EXPLOSIVE') <= 0) then - call sph_error_set(SPH_ERROR_INPUT, 'Explosive control references non-Explosive material') - ierr = SPH_ERROR_INPUT - return - end if - explosive_index = sph_explosive_register_material(name) - if (explosive_index <= 0) then - call sph_error_set(SPH_ERROR_INPUT, 'too many Explosive material records') - ierr = SPH_ERROR_INPUT - end if - end subroutine sph_explosive_prepare_material - - integer function sph_explosive_register_material(name) - character(len=*), intent(in) :: name - integer :: mat_index - integer :: explosive_index - - sph_explosive_register_material = 0 - mat_index = sph_explosive_find_material(name) - if (mat_index <= 0) return - explosive_index = sph_explosive_table_index_by_material_id(mat_index) - if (explosive_index > 0) then - sph_explosive_register_material = explosive_index - return - end if - if (explosive_material_count >= SPH_MAX_MATERIALS) return - explosive_material_count = explosive_material_count + 1 - explosive_material_id(explosive_material_count) = mat_index - explosive_material_name(explosive_material_count) = material_name(mat_index) - explosive_density0(explosive_material_count) = material_density(mat_index) - sph_explosive_register_material = explosive_material_count - end function sph_explosive_register_material - - integer function sph_explosive_table_index_by_material_id(mat_index) - integer, intent(in) :: mat_index - integer :: i - - sph_explosive_table_index_by_material_id = 0 - do i = 1, explosive_material_count - if (explosive_material_id(i) == mat_index) then - sph_explosive_table_index_by_material_id = i - return - end if - end do - end function sph_explosive_table_index_by_material_id - - integer function sph_explosive_find_material(name) - character(len=*), intent(in) :: name - integer :: i - - sph_explosive_find_material = 0 - do i = 1, material_count - if (trim(sph_explosive_upper(material_name(i))) == & - trim(sph_explosive_upper(name))) then - sph_explosive_find_material = i - return - end if - end do - end function sph_explosive_find_material - - integer function sph_explosive_conversion_id(conversion_name) - character(len=*), intent(in) :: conversion_name - character(len=64) :: upper_name - - upper_name = sph_explosive_upper(conversion_name) - if (len_trim(conversion_name) == 0 .or. index(upper_name, 'PHASE') > 0) then - sph_explosive_conversion_id = EXPLOSIVE_CONVERSION_PHASE - else if (index(upper_name, 'SOURCE') > 0) then - sph_explosive_conversion_id = EXPLOSIVE_CONVERSION_SOURCE - else - sph_explosive_conversion_id = EXPLOSIVE_CONVERSION_NONE - end if - end function sph_explosive_conversion_id - - subroutine sph_explosive_validate_product_gas(product_index, ierr) - integer, intent(in) :: product_index - integer, intent(out) :: ierr - integer :: gas_index - - ierr = SPH_SUCCESS - if (product_index < 1 .or. product_index > material_count) then - call sph_error_set(SPH_ERROR_INPUT, 'Explosive product material is unknown') - ierr = SPH_ERROR_INPUT - return - end if - if (index(sph_explosive_upper(material_type(product_index)), 'GAS') <= 0) then - call sph_error_set(SPH_ERROR_INPUT, 'Explosive product material must be Gas') - ierr = SPH_ERROR_INPUT - return - end if - gas_index = sph_gas_table_index_by_material_id(product_index) - if (gas_index <= 0 .or. .not. gas_material_eos_defined(gas_index)) then - call sph_error_set(SPH_ERROR_INPUT, 'Explosive product Gas material has no EOS') - ierr = SPH_ERROR_INPUT - end if - end subroutine sph_explosive_validate_product_gas - - logical function sph_explosive_has_section_binding_for_id(mat_index) - integer, intent(in) :: mat_index - integer :: i - - sph_explosive_has_section_binding_for_id = .false. - do i = 1, section_count - if (section_material_id(i) == mat_index) then - sph_explosive_has_section_binding_for_id = .true. - return - end if - end do - end function sph_explosive_has_section_binding_for_id - - logical function sph_explosive_has_ignition_for_material(mat_index) - integer, intent(in) :: mat_index - integer :: i - - sph_explosive_has_ignition_for_material = .false. - do i = 1, explosive_ignition_count - if (explosive_ignition_material_id(i) == mat_index) then - sph_explosive_has_ignition_for_material = .true. - return - end if - end do - end function sph_explosive_has_ignition_for_material - - integer function sph_explosive_count_active_gas(product_id) - integer, intent(in) :: product_id - integer :: i - - sph_explosive_count_active_gas = 0 - do i = 1, npart - if (sph_explosive_is_active_gas_target(i, product_id)) then - sph_explosive_count_active_gas = sph_explosive_count_active_gas + 1 - end if - end do - end function sph_explosive_count_active_gas - - logical function sph_explosive_is_active_gas_target(index, product_id) - integer, intent(in) :: index - integer, intent(in) :: product_id - - sph_explosive_is_active_gas_target = .false. - if (index < 1 .or. index > npart) return - if (particle_phase(index) /= SPH_PHASE_GAS) return - if (particle_status(index) /= SPH_STATUS_ACTIVE) return - if (material_id(index) /= product_id) return - sph_explosive_is_active_gas_target = .true. - end function sph_explosive_is_active_gas_target - - logical function sph_explosive_is_active_particle(index) - integer, intent(in) :: index - - sph_explosive_is_active_particle = .false. - if (index < 1 .or. index > npart) return - if (particle_phase(index) /= SPH_PHASE_EXPLOSIVE) return - if (particle_status(index) /= SPH_STATUS_ACTIVE) return - sph_explosive_is_active_particle = .true. - end function sph_explosive_is_active_particle - - logical function sph_explosive_is_tracked_particle(index) - integer, intent(in) :: index - - sph_explosive_is_tracked_particle = .false. - if (index < 1 .or. index > npart) return - if (.not. allocated(explosive_ignition_status)) return - if (explosive_ignition_status(index) == 1) then - sph_explosive_is_tracked_particle = .true. - else if (allocated(explosive_reaction_progress)) then - if (explosive_reaction_progress(index) > 0.0_rk) then - sph_explosive_is_tracked_particle = .true. - end if - end if - end function sph_explosive_is_tracked_particle - - logical function sph_explosive_is_finite(value) - real(rk), intent(in) :: value - - sph_explosive_is_finite = value == value .and. abs(value) < huge(value) - end function sph_explosive_is_finite - - logical function sph_explosive_vector_is_finite(values) - real(rk), intent(in) :: values(SPH_NDIM) - integer :: i - - sph_explosive_vector_is_finite = .true. - do i = 1, SPH_NDIM - if (.not. sph_explosive_is_finite(values(i))) then - sph_explosive_vector_is_finite = .false. - end if - end do - end function sph_explosive_vector_is_finite - - function sph_explosive_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_explosive_upper - end module sph_explosive diff --git a/src/explosive/sph_explosive_helpers.f90 b/src/explosive/sph_explosive_helpers.f90 new file mode 100644 index 0000000..ababd3d --- /dev/null +++ b/src/explosive/sph_explosive_helpers.f90 @@ -0,0 +1,234 @@ +module sph_explosive_helpers + use sph_precision, only: rk, SPH_NDIM + use sph_error, only: SPH_SUCCESS, SPH_ERROR_INPUT, sph_error_set + use sph_database, only: SPH_MAX_MATERIALS, material_count, material_name, & + material_type, material_density, section_count, section_material_id, & + npart, particle_phase, particle_status, material_id, SPH_PHASE_EXPLOSIVE, & + SPH_PHASE_GAS, SPH_STATUS_ACTIVE + use sph_gas, only: sph_gas_table_index_by_material_id, & + gas_material_eos_defined + use sph_explosive_state + implicit none + +contains + + subroutine sph_explosive_prepare_material(name, explosive_index, ierr) + character(len=*), intent(in) :: name + integer, intent(out) :: explosive_index + integer, intent(out) :: ierr + integer :: mat_index + + ierr = SPH_SUCCESS + explosive_index = 0 + mat_index = sph_explosive_find_material(name) + if (mat_index <= 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Explosive control references unknown material') + ierr = SPH_ERROR_INPUT + return + end if + if (index(sph_explosive_upper(material_type(mat_index)), 'EXPLOSIVE') <= 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Explosive control references non-Explosive material') + ierr = SPH_ERROR_INPUT + return + end if + explosive_index = sph_explosive_register_material(name) + if (explosive_index <= 0) then + call sph_error_set(SPH_ERROR_INPUT, 'too many Explosive material records') + ierr = SPH_ERROR_INPUT + end if + end subroutine sph_explosive_prepare_material + + integer function sph_explosive_register_material(name) + character(len=*), intent(in) :: name + integer :: mat_index + integer :: explosive_index + + sph_explosive_register_material = 0 + mat_index = sph_explosive_find_material(name) + if (mat_index <= 0) return + explosive_index = sph_explosive_table_index_by_material_id(mat_index) + if (explosive_index > 0) then + sph_explosive_register_material = explosive_index + return + end if + if (explosive_material_count >= SPH_MAX_MATERIALS) return + explosive_material_count = explosive_material_count + 1 + explosive_material_id(explosive_material_count) = mat_index + explosive_material_name(explosive_material_count) = material_name(mat_index) + explosive_density0(explosive_material_count) = material_density(mat_index) + sph_explosive_register_material = explosive_material_count + end function sph_explosive_register_material + + integer function sph_explosive_table_index_by_material_id(mat_index) + integer, intent(in) :: mat_index + integer :: i + + sph_explosive_table_index_by_material_id = 0 + do i = 1, explosive_material_count + if (explosive_material_id(i) == mat_index) then + sph_explosive_table_index_by_material_id = i + return + end if + end do + end function sph_explosive_table_index_by_material_id + + integer function sph_explosive_find_material(name) + character(len=*), intent(in) :: name + integer :: i + + sph_explosive_find_material = 0 + do i = 1, material_count + if (trim(sph_explosive_upper(material_name(i))) == & + trim(sph_explosive_upper(name))) then + sph_explosive_find_material = i + return + end if + end do + end function sph_explosive_find_material + + integer function sph_explosive_conversion_id(conversion_name) + character(len=*), intent(in) :: conversion_name + character(len=64) :: upper_name + + upper_name = sph_explosive_upper(conversion_name) + if (len_trim(conversion_name) == 0 .or. index(upper_name, 'PHASE') > 0) then + sph_explosive_conversion_id = EXPLOSIVE_CONVERSION_PHASE + else if (index(upper_name, 'SOURCE') > 0) then + sph_explosive_conversion_id = EXPLOSIVE_CONVERSION_SOURCE + else + sph_explosive_conversion_id = EXPLOSIVE_CONVERSION_NONE + end if + end function sph_explosive_conversion_id + + subroutine sph_explosive_validate_product_gas(product_index, ierr) + integer, intent(in) :: product_index + integer, intent(out) :: ierr + integer :: gas_index + + ierr = SPH_SUCCESS + if (product_index < 1 .or. product_index > material_count) then + call sph_error_set(SPH_ERROR_INPUT, 'Explosive product material is unknown') + ierr = SPH_ERROR_INPUT + return + end if + if (index(sph_explosive_upper(material_type(product_index)), 'GAS') <= 0) then + call sph_error_set(SPH_ERROR_INPUT, 'Explosive product material must be Gas') + ierr = SPH_ERROR_INPUT + return + end if + gas_index = sph_gas_table_index_by_material_id(product_index) + if (gas_index <= 0 .or. .not. gas_material_eos_defined(gas_index)) then + call sph_error_set(SPH_ERROR_INPUT, 'Explosive product Gas material has no EOS') + ierr = SPH_ERROR_INPUT + end if + end subroutine sph_explosive_validate_product_gas + + logical function sph_explosive_has_section_binding_for_id(mat_index) + integer, intent(in) :: mat_index + integer :: i + + sph_explosive_has_section_binding_for_id = .false. + do i = 1, section_count + if (section_material_id(i) == mat_index) then + sph_explosive_has_section_binding_for_id = .true. + return + end if + end do + end function sph_explosive_has_section_binding_for_id + + logical function sph_explosive_has_ignition_for_material(mat_index) + integer, intent(in) :: mat_index + integer :: i + + sph_explosive_has_ignition_for_material = .false. + do i = 1, explosive_ignition_count + if (explosive_ignition_material_id(i) == mat_index) then + sph_explosive_has_ignition_for_material = .true. + return + end if + end do + end function sph_explosive_has_ignition_for_material + + integer function sph_explosive_count_active_gas(product_id) + integer, intent(in) :: product_id + integer :: i + + sph_explosive_count_active_gas = 0 + do i = 1, npart + if (sph_explosive_is_active_gas_target(i, product_id)) then + sph_explosive_count_active_gas = sph_explosive_count_active_gas + 1 + end if + end do + end function sph_explosive_count_active_gas + + logical function sph_explosive_is_active_gas_target(index, product_id) + integer, intent(in) :: index + integer, intent(in) :: product_id + + sph_explosive_is_active_gas_target = .false. + if (index < 1 .or. index > npart) return + if (particle_phase(index) /= SPH_PHASE_GAS) return + if (particle_status(index) /= SPH_STATUS_ACTIVE) return + if (material_id(index) /= product_id) return + sph_explosive_is_active_gas_target = .true. + end function sph_explosive_is_active_gas_target + + logical function sph_explosive_is_active_particle(index) + integer, intent(in) :: index + + sph_explosive_is_active_particle = .false. + if (index < 1 .or. index > npart) return + if (particle_phase(index) /= SPH_PHASE_EXPLOSIVE) return + if (particle_status(index) /= SPH_STATUS_ACTIVE) return + sph_explosive_is_active_particle = .true. + end function sph_explosive_is_active_particle + + logical function sph_explosive_is_tracked_particle(index) + integer, intent(in) :: index + + sph_explosive_is_tracked_particle = .false. + if (index < 1 .or. index > npart) return + if (.not. allocated(explosive_ignition_status)) return + if (explosive_ignition_status(index) == 1) then + sph_explosive_is_tracked_particle = .true. + else if (allocated(explosive_reaction_progress)) then + if (explosive_reaction_progress(index) > 0.0_rk) then + sph_explosive_is_tracked_particle = .true. + end if + end if + end function sph_explosive_is_tracked_particle + + logical function sph_explosive_is_finite(value) + real(rk), intent(in) :: value + + sph_explosive_is_finite = value == value .and. abs(value) < huge(value) + end function sph_explosive_is_finite + + logical function sph_explosive_vector_is_finite(values) + real(rk), intent(in) :: values(SPH_NDIM) + integer :: i + + sph_explosive_vector_is_finite = .true. + do i = 1, SPH_NDIM + if (.not. sph_explosive_is_finite(values(i))) then + sph_explosive_vector_is_finite = .false. + end if + end do + end function sph_explosive_vector_is_finite + + function sph_explosive_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_explosive_upper + +end module sph_explosive_helpers diff --git a/src/explosive/sph_explosive_state.f90 b/src/explosive/sph_explosive_state.f90 new file mode 100644 index 0000000..c88d4dc --- /dev/null +++ b/src/explosive/sph_explosive_state.f90 @@ -0,0 +1,35 @@ +module sph_explosive_state + use sph_precision, only: rk, SPH_NDIM + use sph_database, only: SPH_MAX_MATERIALS + implicit none + + integer, parameter :: EXPLOSIVE_CONVERSION_NONE = 0 + integer, parameter :: EXPLOSIVE_CONVERSION_PHASE = 1 + integer, parameter :: EXPLOSIVE_CONVERSION_SOURCE = 2 + + logical :: explosive_module_initialized = .false. + logical :: explosive_material_seen = .false. + integer :: explosive_material_count = 0 + integer :: explosive_material_id(SPH_MAX_MATERIALS) = 0 + character(len=64) :: explosive_material_name(SPH_MAX_MATERIALS) = ' ' + logical :: explosive_control_defined(SPH_MAX_MATERIALS) = .false. + integer :: explosive_product_material_id(SPH_MAX_MATERIALS) = 0 + character(len=64) :: explosive_product_material_name(SPH_MAX_MATERIALS) = ' ' + real(rk) :: explosive_density0(SPH_MAX_MATERIALS) = 0.0_rk + real(rk) :: explosive_detonation_velocity(SPH_MAX_MATERIALS) = 0.0_rk + real(rk) :: explosive_energy_per_mass(SPH_MAX_MATERIALS) = 0.0_rk + real(rk) :: explosive_burn_time(SPH_MAX_MATERIALS) = 0.0_rk + integer :: explosive_conversion_mode(SPH_MAX_MATERIALS) = EXPLOSIVE_CONVERSION_NONE + integer :: explosive_ignition_count = 0 + integer :: explosive_ignition_material_id(SPH_MAX_MATERIALS) = 0 + real(rk) :: explosive_ignition_x(SPH_NDIM,SPH_MAX_MATERIALS) = 0.0_rk + real(rk) :: explosive_ignition_time(SPH_MAX_MATERIALS) = 0.0_rk + integer, allocatable :: explosive_ignition_status(:) + real(rk), allocatable :: explosive_detonation_time(:) + real(rk), allocatable :: explosive_reaction_progress(:) + real(rk), allocatable :: explosive_released_mass(:) + real(rk), allocatable :: explosive_released_energy(:) + real(rk), allocatable :: explosive_released_momentum(:,:) + real(rk) :: explosive_dt_reaction = 0.0_rk + +end module sph_explosive_state diff --git a/src/output/sph_output_csv.f90 b/src/output/sph_output_csv.f90 index 7fc40b5..f37f0bb 100644 --- a/src/output/sph_output_csv.f90 +++ b/src/output/sph_output_csv.f90 @@ -11,9 +11,10 @@ module sph_output_csv gas_equivalent_radius, gas_radius_rate, gas_dt_cfl, gas_dt_accel, & gas_dtcrit use sph_gas, only: sph_gas_get_source_summary - use sph_explosive, only: sph_explosive_get_summary, & + use sph_explosive_state, only: & explosive_detonation_time, explosive_reaction_progress, & explosive_released_mass, explosive_released_energy + use sph_explosive, only: sph_explosive_get_summary implicit none integer, parameter :: SPH_OUTPUT_UNIT = 41 diff --git a/src/output/sph_restart.f90 b/src/output/sph_restart.f90 index 2ee380b..84e6f1f 100644 --- a/src/output/sph_restart.f90 +++ b/src/output/sph_restart.f90 @@ -33,7 +33,7 @@ module sph_restart sph_gas_rebuild_legacy_restart_state, sph_gas_update_diagnostics use sph_gas_source, only: gas_mass_source, gas_energy_source, & gas_momentum_source - use sph_explosive, only: explosive_material_count, explosive_material_id, & + use sph_explosive_state, only: explosive_material_count, explosive_material_id, & explosive_material_seen, explosive_material_name, explosive_control_defined, & explosive_product_material_id, explosive_product_material_name, & explosive_density0, explosive_detonation_velocity, & @@ -43,7 +43,8 @@ module sph_restart explosive_ignition_time, explosive_ignition_status, & explosive_detonation_time, explosive_reaction_progress, & explosive_released_mass, explosive_released_energy, & - explosive_released_momentum, explosive_dt_reaction, & + explosive_released_momentum, explosive_dt_reaction + use sph_explosive, only: & sph_explosive_allocate_state, sph_explosive_clear_material_table use sph_neighbor, only: neighbor_cell_size, neighbor_cell_dims, neighbor_num_cells, & sph_neighbor_rebuild diff --git a/tests/data/explosive_bad_burn_time_040.inp b/tests/data/explosive_bad_burn_time_040.inp new file mode 100644 index 0000000..68c6642 --- /dev/null +++ b/tests/data/explosive_bad_burn_time_040.inp @@ -0,0 +1,18 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=CHARGE_PARTICLES +1 +*MATERIAL, NAME=TNT, TYPE=EXPLOSIVE +*DENSITY +1600.0 +*SECTION, ELSET=CHARGE_PARTICLES, MATERIAL=TNT +*MATERIAL, NAME=PRODUCTS, TYPE=GAS +*DENSITY +1600.0 +*SPHLITE EOS, TYPE=JWL, MATERIAL=PRODUCTS, RHO0=1600.0, A=3.712E11, B=3.231E9, R1=4.15, R2=0.95, OMEGA=0.3, E0=4.2E6 +*SPHLITE EXPLOSIVE, MATERIAL=TNT, TYPE=PROGRAMMED_BURN, DETONATION_VELOCITY=6900.0, ENERGY=4.2E6, BURN_TIME=-1.0E-7, PRODUCT_MATERIAL=PRODUCTS, CONVERSION=PHASE +*SPHLITE IGNITION, MATERIAL=TNT, X=0.0, Y=0.0, Z=0.0, TIME=0.0 +*SPHLITE PARTICLE CONTROL, H=0.10, MASS=0.02, VOLUME=1.25E-5 +*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5 diff --git a/tests/data/explosive_bad_energy_040.inp b/tests/data/explosive_bad_energy_040.inp new file mode 100644 index 0000000..2c1b233 --- /dev/null +++ b/tests/data/explosive_bad_energy_040.inp @@ -0,0 +1,18 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=CHARGE_PARTICLES +1 +*MATERIAL, NAME=TNT, TYPE=EXPLOSIVE +*DENSITY +1600.0 +*SECTION, ELSET=CHARGE_PARTICLES, MATERIAL=TNT +*MATERIAL, NAME=PRODUCTS, TYPE=GAS +*DENSITY +1600.0 +*SPHLITE EOS, TYPE=JWL, MATERIAL=PRODUCTS, RHO0=1600.0, A=3.712E11, B=3.231E9, R1=4.15, R2=0.95, OMEGA=0.3, E0=4.2E6 +*SPHLITE EXPLOSIVE, MATERIAL=TNT, TYPE=PROGRAMMED_BURN, DETONATION_VELOCITY=6900.0, ENERGY=-1.0, BURN_TIME=1.0E-7, PRODUCT_MATERIAL=PRODUCTS, CONVERSION=PHASE +*SPHLITE IGNITION, MATERIAL=TNT, X=0.0, Y=0.0, Z=0.0, TIME=0.0 +*SPHLITE PARTICLE CONTROL, H=0.10, MASS=0.02, VOLUME=1.25E-5 +*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5 diff --git a/tests/data/explosive_missing_density_040.inp b/tests/data/explosive_missing_density_040.inp new file mode 100644 index 0000000..39aefd3 --- /dev/null +++ b/tests/data/explosive_missing_density_040.inp @@ -0,0 +1,16 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=CHARGE_PARTICLES +1 +*MATERIAL, NAME=TNT, TYPE=EXPLOSIVE +*SECTION, ELSET=CHARGE_PARTICLES, MATERIAL=TNT +*MATERIAL, NAME=PRODUCTS, TYPE=GAS +*DENSITY +1600.0 +*SPHLITE EOS, TYPE=JWL, MATERIAL=PRODUCTS, RHO0=1600.0, A=3.712E11, B=3.231E9, R1=4.15, R2=0.95, OMEGA=0.3, E0=4.2E6 +*SPHLITE EXPLOSIVE, MATERIAL=TNT, TYPE=PROGRAMMED_BURN, DETONATION_VELOCITY=6900.0, ENERGY=4.2E6, BURN_TIME=1.0E-7, PRODUCT_MATERIAL=PRODUCTS, CONVERSION=PHASE +*SPHLITE IGNITION, MATERIAL=TNT, X=0.0, Y=0.0, Z=0.0, TIME=0.0 +*SPHLITE PARTICLE CONTROL, H=0.10, MASS=0.02, VOLUME=1.25E-5 +*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5 diff --git a/tests/data/explosive_product_missing_eos_040.inp b/tests/data/explosive_product_missing_eos_040.inp new file mode 100644 index 0000000..3969c95 --- /dev/null +++ b/tests/data/explosive_product_missing_eos_040.inp @@ -0,0 +1,17 @@ +*NODE +1, 0.0, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +*ELSET, ELSET=CHARGE_PARTICLES +1 +*MATERIAL, NAME=TNT, TYPE=EXPLOSIVE +*DENSITY +1600.0 +*SECTION, ELSET=CHARGE_PARTICLES, MATERIAL=TNT +*MATERIAL, NAME=PRODUCTS, TYPE=GAS +*DENSITY +1600.0 +*SPHLITE EXPLOSIVE, MATERIAL=TNT, TYPE=PROGRAMMED_BURN, DETONATION_VELOCITY=6900.0, ENERGY=4.2E6, BURN_TIME=1.0E-7, PRODUCT_MATERIAL=PRODUCTS, CONVERSION=PHASE +*SPHLITE IGNITION, MATERIAL=TNT, X=0.0, Y=0.0, Z=0.0, TIME=0.0 +*SPHLITE PARTICLE CONTROL, H=0.10, MASS=0.02, VOLUME=1.25E-5 +*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5 diff --git a/tests/module/test_explosive_detonation_time.f90 b/tests/module/test_explosive_detonation_time.f90 index e321b7c..6ad1f2b 100644 --- a/tests/module/test_explosive_detonation_time.f90 +++ b/tests/module/test_explosive_detonation_time.f90 @@ -3,8 +3,9 @@ program test_explosive_detonation_time 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_explosive, only: explosive_detonation_time, & - explosive_ignition_status, sph_explosive_get_detonation_time_range + use sph_explosive_state, only: explosive_detonation_time, & + explosive_ignition_status + use sph_explosive, only: sph_explosive_get_detonation_time_range implicit none integer :: ierr diff --git a/tests/module/test_explosive_gas_coupling.f90 b/tests/module/test_explosive_gas_coupling.f90 new file mode 100644 index 0000000..ffea4e5 --- /dev/null +++ b/tests/module/test_explosive_gas_coupling.f90 @@ -0,0 +1,45 @@ +program test_explosive_gas_coupling + 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_advance_explicit + use sph_database, only: gas_particle_count, gas_volume, gas_max_pressure + use sph_gas, only: gas_material_count, gas_material_eos_defined + implicit none + + integer :: ierr + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed') + call sph_read_inp('tests/data/explosive_conversion_phase_040.inp', ierr) + call assert_ok(ierr, 'read Explosive Gas coupling failed') + call sph_build_model(ierr) + call assert_ok(ierr, 'build Explosive Gas coupling failed') + if (gas_material_count /= 1 .or. .not. gas_material_eos_defined(1)) then + call fail('Explosive product Gas material was not registered') + end if + call sph_advance_explicit(1.0e-7_rk, ierr) + call assert_ok(ierr, 'Explosive Gas coupling advance failed') + if (gas_particle_count <= 0) call fail('Explosive conversion did not create Gas count') + if (gas_volume <= 0.0_rk) call fail('Explosive product Gas volume mismatch') + if (gas_max_pressure <= 0.0_rk) call fail('Explosive product Gas pressure mismatch') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed') + +contains + + 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_explosive_gas_coupling diff --git a/tests/module/test_explosive_reaction_progress.f90 b/tests/module/test_explosive_reaction_progress.f90 new file mode 100644 index 0000000..686f92a --- /dev/null +++ b/tests/module/test_explosive_reaction_progress.f90 @@ -0,0 +1,49 @@ +program test_explosive_reaction_progress + 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_advance_explicit + use sph_explosive_state, only: explosive_reaction_progress + implicit none + + integer :: ierr + real(rk) :: lambda_mid + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed') + call sph_read_inp('tests/data/explosive_programmed_burn_040.inp', ierr) + call assert_ok(ierr, 'read programmed burn failed') + call sph_build_model(ierr) + call assert_ok(ierr, 'build programmed burn failed') + call sph_advance_explicit(2.0e-7_rk, ierr) + call assert_ok(ierr, 'first programmed burn step failed') + lambda_mid = explosive_reaction_progress(1) + if (lambda_mid <= 0.0_rk .or. lambda_mid >= 1.0_rk) then + call fail('programmed burn lambda did not enter partial range') + end if + call sph_advance_explicit(1.0e-6_rk, ierr) + call assert_ok(ierr, 'second programmed burn step failed') + if (explosive_reaction_progress(1) < lambda_mid) call fail('lambda is not monotonic') + if (explosive_reaction_progress(1) > 1.0_rk + 1.0e-12_rk) then + call fail('lambda exceeded one') + end if + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed') + +contains + + 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_explosive_reaction_progress diff --git a/tests/module/test_explosive_release_source.f90 b/tests/module/test_explosive_release_source.f90 new file mode 100644 index 0000000..7b4ff95 --- /dev/null +++ b/tests/module/test_explosive_release_source.f90 @@ -0,0 +1,54 @@ +program test_explosive_release_source + 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_advance_explicit + use sph_database, only: mass, particle_phase, SPH_PHASE_EXPLOSIVE + use sph_gas, only: sph_gas_get_source_summary + use sph_explosive_state, only: explosive_released_mass, explosive_released_energy + implicit none + + integer :: ierr + real(rk) :: gas_mass_before + real(rk) :: source_mass + real(rk) :: source_energy + real(rk) :: source_momentum(3) + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed') + call sph_read_inp('tests/data/explosive_conversion_source_040.inp', ierr) + call assert_ok(ierr, 'read source conversion failed') + call sph_build_model(ierr) + call assert_ok(ierr, 'build source conversion failed') + gas_mass_before = mass(4) + call sph_advance_explicit(1.0e-7_rk, ierr) + call assert_ok(ierr, 'source conversion advance failed') + if (particle_phase(1) /= SPH_PHASE_EXPLOSIVE) call fail('SOURCE conversion changed phase') + if (explosive_released_mass(1) <= 0.0_rk) call fail('Explosive source mass not released') + if (explosive_released_energy(1) <= 0.0_rk) call fail('Explosive source energy not released') + call sph_gas_get_source_summary(source_mass, source_momentum, source_energy, ierr) + call assert_ok(ierr, 'Gas source summary failed') + if (source_mass <= 0.0_rk .or. source_energy <= 0.0_rk) then + call fail('Explosive source was not injected into Gas') + end if + if (mass(4) <= gas_mass_before) call fail('Gas mass did not receive source update') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed') + +contains + + 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_explosive_release_source diff --git a/tests/module/test_explosive_restart_031_compat.f90 b/tests/module/test_explosive_restart_031_compat.f90 new file mode 100644 index 0000000..6c69d87 --- /dev/null +++ b/tests/module/test_explosive_restart_031_compat.f90 @@ -0,0 +1,89 @@ +program test_explosive_restart_031_compat + use sph_precision, only: rk + use sph_error, only: SPH_SUCCESS + use sph_api, only: sph_initialize, sph_finalize, sph_read_restart, & + sph_advance_explicit, sph_get_explosive_summary + use sph_explosive_state, only: explosive_material_count, explosive_material_seen + implicit none + + integer :: ierr + integer :: particle_count + integer :: reacted_count + real(rk) :: lambda_range(3) + real(rk) :: released_totals(5) + real(rk) :: detonation_range(2) + + call write_legacy_restart('build-codex-unix/restart_explosive_031.tmp') + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for legacy restart') + call sph_read_restart('build-codex-unix/restart_explosive_031.tmp', ierr) + call assert_ok(ierr, 'legacy restart read failed') + if (explosive_material_count /= 0 .or. explosive_material_seen) then + call fail('legacy restart did not clear Explosive material state') + end if + call sph_get_explosive_summary(particle_count, reacted_count, lambda_range, & + released_totals, detonation_range, ierr) + call assert_ok(ierr, 'legacy restart Explosive summary failed') + if (particle_count /= 0 .or. reacted_count /= 0) then + call fail('legacy restart Explosive summary is not empty') + end if + if (maxval(abs(released_totals)) > 1.0e-12_rk) then + call fail('legacy restart Explosive release is not empty') + end if + call sph_advance_explicit(1.0e-7_rk, ierr) + call assert_ok(ierr, 'legacy restart continue step failed') + call sph_finalize(ierr) + call assert_ok(ierr, 'legacy restart finalize failed') + +contains + + subroutine write_legacy_restart(filename) + character(len=*), intent(in) :: filename + + open(unit=92, file=trim(filename), status='unknown', action='write') + write(92, '(A)') 'SPHLITE_RESTART 0 3 1 STATE_0_3_1' + write(92, *) 0.0_rk, 0, 1 + write(92, *) 1, .false., 0.5_rk + write(92, '(A)') 'build-codex-unix' + write(92, *) 1000.0_rk, 1500.0_rk, 7.0_rk, 0.0_rk, 0.0_rk + write(92, *) 1.0_rk, 2.0_rk, 0.01_rk + write(92, *) 0.0_rk, 0.0_rk, 0.0_rk + write(92, *) 0.15_rk, 1, 1, 1, 1 + write(92, *) 1, 0.01_rk + write(92, *) 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, 1000.0_rk, 1000.0_rk, 0.0_rk + write(92, *) 1.0e-4_rk, 1.0e30_rk, 1.0e30_rk + write(92, *) 0, 0.0_rk, 1.4_rk, 0.0_rk, 0.0_rk, 0.0_rk, & + 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk + write(92, *) 0.15_rk, 0.01_rk, 1.0e-5_rk + write(92, *) 0.0_rk, 0.0_rk, 0.0_rk + write(92, *) 0, 0.0_rk, 0.0_rk + write(92, *) 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, & + 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk + write(92, *) 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, & + 0.0_rk, 0.0_rk + write(92, *) 1.0e-4_rk, 1.0e30_rk, 1.0e-4_rk + write(92, *) 0 + write(92, *) 1, 1, 0, 1, 1 + write(92, *) 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, & + 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, & + 0.0_rk, 0.0_rk, 0.0_rk + write(92, *) 0.01_rk, 1000.0_rk, 1.0e-5_rk, 0.0_rk, 0.0_rk, 293.15_rk, 0.15_rk + write(92, *) 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk, 0.0_rk + close(92) + end subroutine write_legacy_restart + + 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_explosive_restart_031_compat diff --git a/tests/module/test_explosive_restart_040.f90 b/tests/module/test_explosive_restart_040.f90 new file mode 100644 index 0000000..76e557f --- /dev/null +++ b/tests/module/test_explosive_restart_040.f90 @@ -0,0 +1,77 @@ +program test_explosive_restart_040 + 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_advance_explicit, sph_write_restart, & + sph_read_restart, sph_get_explosive_summary + use sph_database, only: particle_phase, SPH_PHASE_GAS + use sph_explosive_state, only: explosive_material_count + implicit none + + integer :: ierr + integer :: particle_count + integer :: reacted_count + real(rk) :: lambda_before(3) + real(rk) :: lambda_after(3) + real(rk) :: released_before(5) + real(rk) :: released_after(5) + real(rk) :: detonation_range(2) + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed') + call sph_read_inp('tests/data/explosive_conversion_phase_040.inp', ierr) + call assert_ok(ierr, 'read restart input failed') + call sph_build_model(ierr) + call assert_ok(ierr, 'build restart input failed') + call sph_advance_explicit(1.0e-7_rk, ierr) + call assert_ok(ierr, 'advance before restart failed') + call sph_get_explosive_summary(particle_count, reacted_count, lambda_before, & + released_before, detonation_range, ierr) + call assert_ok(ierr, 'summary before restart failed') + call sph_write_restart('build-codex-unix/restart_explosive_040.tmp', ierr) + call assert_ok(ierr, 'write Explosive restart failed') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize first session failed') + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize restart session failed') + call sph_read_restart('build-codex-unix/restart_explosive_040.tmp', ierr) + call assert_ok(ierr, 'read Explosive restart failed') + if (explosive_material_count /= 1) call fail('Explosive restart material count mismatch') + if (particle_phase(1) /= SPH_PHASE_GAS) call fail('Explosive restart phase mismatch') + call sph_get_explosive_summary(particle_count, reacted_count, lambda_after, & + released_after, detonation_range, ierr) + call assert_ok(ierr, 'summary after restart failed') + if (reacted_count <= 0) call fail('Explosive restart reacted count mismatch') + call assert_close(lambda_after(2), lambda_before(2), 'Explosive restart lambda mismatch') + call assert_close(released_after(2), released_before(2), 'Explosive restart release mismatch') + call sph_advance_explicit(1.0e-7_rk, ierr) + call assert_ok(ierr, 'continue after Explosive restart failed') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize restart session failed') + +contains + + 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_explosive_restart_040 diff --git a/tests/module/test_explosive_summary.f90 b/tests/module/test_explosive_summary.f90 new file mode 100644 index 0000000..a7aee65 --- /dev/null +++ b/tests/module/test_explosive_summary.f90 @@ -0,0 +1,70 @@ +program test_explosive_summary + 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_advance_explicit, sph_get_explosive_summary + implicit none + + integer :: ierr + integer :: particle_count + integer :: reacted_count + real(rk) :: lambda_range(3) + real(rk) :: released_totals(5) + real(rk) :: detonation_range(2) + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed') + call sph_read_inp('tests/data/explosive_conversion_phase_040.inp', ierr) + call assert_ok(ierr, 'read summary input failed') + call sph_build_model(ierr) + call assert_ok(ierr, 'build summary input failed') + call sph_get_explosive_summary(particle_count, reacted_count, lambda_range, & + released_totals, detonation_range, ierr) + call assert_ok(ierr, 'initial Explosive summary failed') + if (particle_count /= 4 .or. reacted_count /= 0) call fail('initial summary count mismatch') + if (maxval(abs(lambda_range)) > 1.0e-12_rk) call fail('initial lambda mismatch') + if (detonation_range(2) <= detonation_range(1)) call fail('detonation range mismatch') + call sph_advance_explicit(1.0e-7_rk, ierr) + call assert_ok(ierr, 'summary advance failed') + call sph_get_explosive_summary(particle_count, reacted_count, lambda_range, & + released_totals, detonation_range, ierr) + call assert_ok(ierr, 'advanced Explosive summary failed') + if (particle_count /= 4 .or. reacted_count <= 0) call fail('advanced summary count mismatch') + if (lambda_range(2) <= 0.0_rk .or. lambda_range(3) <= 0.0_rk) then + call fail('advanced lambda summary mismatch') + end if + if (released_totals(1) <= 0.0_rk .or. released_totals(2) <= 0.0_rk) then + call fail('advanced release summary mismatch') + end if + call assert_close(released_totals(2) / released_totals(1), 4.2e6_rk, & + 'release energy ratio mismatch') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed') + +contains + + 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-6_rk * max(1.0_rk, abs(expected))) then + call fail(message) + end if + end subroutine assert_close + + subroutine fail(message) + character(len=*), intent(in) :: message + + write(*, '(A)') trim(message) + stop 1 + end subroutine fail + +end program test_explosive_summary diff --git a/tests/module/test_explosive_to_gas_phase.f90 b/tests/module/test_explosive_to_gas_phase.f90 new file mode 100644 index 0000000..9b8db13 --- /dev/null +++ b/tests/module/test_explosive_to_gas_phase.f90 @@ -0,0 +1,49 @@ +program test_explosive_to_gas_phase + 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_advance_explicit + use sph_database, only: particle_phase, material_id, internal_energy, & + SPH_PHASE_GAS + use sph_explosive_state, only: explosive_reaction_progress + implicit none + + integer :: ierr + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed') + call sph_read_inp('tests/data/explosive_conversion_phase_040.inp', ierr) + call assert_ok(ierr, 'read phase conversion failed') + call sph_build_model(ierr) + call assert_ok(ierr, 'build phase conversion failed') + call sph_advance_explicit(1.0e-7_rk, ierr) + call assert_ok(ierr, 'phase conversion advance failed') + if (particle_phase(1) /= SPH_PHASE_GAS) call fail('Explosive particle did not become Gas') + if (material_id(1) /= 2) call fail('Explosive product material mismatch') + if (internal_energy(1) <= 0.0_rk) call fail('Explosive product energy missing') + if (abs(explosive_reaction_progress(1) - 1.0_rk) > 1.0e-12_rk) then + call fail('Explosive lambda not complete') + end if + call sph_advance_explicit(1.0e-7_rk, ierr) + call assert_ok(ierr, 'phase conversion second advance failed') + if (particle_phase(1) /= SPH_PHASE_GAS) call fail('Explosive phase conversion reversed') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed') + +contains + + 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_explosive_to_gas_phase diff --git a/tests/module/test_input_explosive.f90 b/tests/module/test_input_explosive.f90 new file mode 100644 index 0000000..f190cd9 --- /dev/null +++ b/tests/module/test_input_explosive.f90 @@ -0,0 +1,78 @@ +program test_input_explosive + 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: npart, particle_phase, rho, volume, mass, & + SPH_PHASE_EXPLOSIVE + use sph_gas, only: gas_material_count, gas_material_eos_defined + use sph_explosive_state, only: EXPLOSIVE_CONVERSION_PHASE, & + explosive_material_count, explosive_material_name, & + explosive_control_defined, explosive_product_material_id, & + explosive_density0, explosive_detonation_velocity, & + explosive_energy_per_mass, explosive_burn_time, & + explosive_conversion_mode, explosive_ignition_count, explosive_ignition_x + implicit none + + integer :: ierr + integer :: warnings + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed') + call sph_read_inp('tests/data/explosive_section_040.inp', ierr) + call assert_ok(ierr, 'read Explosive input failed') + call sph_build_model(ierr) + call assert_ok(ierr, 'build Explosive input failed') + call sph_get_input_warning_count(warnings, ierr) + call assert_ok(ierr, 'warning count failed') + if (warnings > 1) call fail('unexpected Explosive input warning count') + if (npart /= 4) call fail('Explosive particle count mismatch') + if (any(particle_phase(1:4) /= SPH_PHASE_EXPLOSIVE)) then + call fail('Explosive particle phase mismatch') + end if + if (explosive_material_count /= 1) call fail('Explosive material count mismatch') + if (trim(explosive_material_name(1)) /= 'PBX') call fail('Explosive material name mismatch') + if (.not. explosive_control_defined(1)) call fail('Explosive control missing') + if (explosive_product_material_id(1) /= 2) call fail('Explosive product material mismatch') + if (explosive_conversion_mode(1) /= EXPLOSIVE_CONVERSION_PHASE) then + call fail('Explosive conversion mode mismatch') + end if + call assert_close(explosive_density0(1), 1750.0_rk, 'Explosive density mismatch') + call assert_close(explosive_detonation_velocity(1), 7600.0_rk, 'Explosive D mismatch') + call assert_close(explosive_energy_per_mass(1), 5.0e6_rk, 'Explosive energy mismatch') + call assert_close(explosive_burn_time(1), 5.0e-7_rk, 'Explosive burn mismatch') + if (explosive_ignition_count /= 1) call fail('Explosive ignition count mismatch') + call assert_close(explosive_ignition_x(1,1), 0.0_rk, 'Explosive ignition mismatch') + if (gas_material_count /= 1 .or. .not. gas_material_eos_defined(1)) then + call fail('Explosive product Gas EOS missing') + end if + call assert_close(rho(1), 1750.0_rk, 'Explosive rho initialization mismatch') + call assert_close(volume(1), mass(1) / rho(1), 'Explosive volume mismatch') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed') + +contains + + 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-10_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_explosive diff --git a/tests/module/test_input_explosive_errors.f90 b/tests/module/test_input_explosive_errors.f90 new file mode 100644 index 0000000..d6fa14a --- /dev/null +++ b/tests/module/test_input_explosive_errors.f90 @@ -0,0 +1,47 @@ +program test_input_explosive_errors + use sph_error, only: SPH_SUCCESS + use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model + implicit none + + call expect_error('tests/data/explosive_bad_velocity_040.inp', 'bad velocity') + call expect_error('tests/data/explosive_bad_product_040.inp', 'bad product') + call expect_error('tests/data/explosive_bad_ignition_040.inp', 'bad ignition') + call expect_error('tests/data/explosive_missing_density_040.inp', 'missing density') + call expect_error('tests/data/explosive_bad_burn_time_040.inp', 'bad burn time') + call expect_error('tests/data/explosive_bad_energy_040.inp', 'bad energy') + call expect_error('tests/data/explosive_product_missing_eos_040.inp', 'missing product EOS') + +contains + + subroutine expect_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_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_explosive_errors diff --git a/todo.md b/todo.md index dc293cb..84fbcd8 100644 --- a/todo.md +++ b/todo.md @@ -125,23 +125,23 @@ ## 阶段 F:测试接入、回归、文档同步与发布门禁 -- [ ] 新增 `input_explosive` 测试并接入 CTest。 -- [ ] 新增 `input_explosive_errors` 测试并接入 CTest。 -- [ ] 新增 `explosive_detonation_time` 测试并接入 CTest。 -- [ ] 新增 `explosive_reaction_progress` 测试并接入 CTest。 -- [ ] 新增 `explosive_release_source` 测试并接入 CTest。 -- [ ] 新增 `explosive_to_gas_phase` 测试并接入 CTest。 -- [ ] 新增 `explosive_gas_coupling` 测试并接入 CTest。 -- [ ] 新增 `explosive_summary` 测试并接入 CTest。 -- [ ] 新增 `explosive_restart_040` 测试并接入 CTest。 -- [ ] 新增 `explosive_restart_031_compat` 测试并接入 CTest。 -- [ ] 新增 `explosive_c_api` 测试并接入 CTest。 -- [ ] 新增 `explosive_python` 测试并接入 CTest。 -- [ ] 新增 `explosive_cli` 测试并接入 CTest。 -- [ ] 新增 `explosive_source_size` 测试或检查项并接入 CTest。 -- [ ] 复核 `tests/source_size_exceptions.txt` 中 stale 例外。 -- [ ] 保持 0.3.1 默认 gate 全部通过。 -- [ ] 单独运行 0.4.0 新增 Explosive gate。 -- [ ] 运行 `source_size` 检查并确认无新增无理由例外。 -- [ ] 运行 `git diff --check` 并清理空白问题。 -- [ ] 更新 README、06、09 和 11 号文档的 0.4.0 测试和验收记录。 +- [x] 新增 `input_explosive` 测试并接入 CTest。 +- [x] 新增 `input_explosive_errors` 测试并接入 CTest。 +- [x] 新增 `explosive_detonation_time` 测试并接入 CTest。 +- [x] 新增 `explosive_reaction_progress` 测试并接入 CTest。 +- [x] 新增 `explosive_release_source` 测试并接入 CTest。 +- [x] 新增 `explosive_to_gas_phase` 测试并接入 CTest。 +- [x] 新增 `explosive_gas_coupling` 测试并接入 CTest。 +- [x] 新增 `explosive_summary` 测试并接入 CTest。 +- [x] 新增 `explosive_restart_040` 测试并接入 CTest。 +- [x] 新增 `explosive_restart_031_compat` 测试并接入 CTest。 +- [x] 新增 `explosive_c_api` 测试并接入 CTest。 +- [x] 新增 `explosive_python` 测试并接入 CTest。 +- [x] 新增 `explosive_cli` 测试并接入 CTest。 +- [x] 新增 `explosive_source_size` 测试或检查项并接入 CTest。 +- [x] 复核 `tests/source_size_exceptions.txt` 中 stale 例外。 +- [x] 保持 0.3.1 默认 gate 全部通过。 +- [x] 单独运行 0.4.0 新增 Explosive gate。 +- [x] 运行 `source_size` 检查并确认无新增无理由例外。 +- [x] 运行 `git diff --check` 并清理空白问题。 +- [x] 更新 README、06、09 和 11 号文档的 0.4.0 测试和验收记录。