Dispatch Gas EOS by material

This commit is contained in:
Codex
2026-07-03 10:45:32 +08:00
parent 0eaa85196e
commit 834b9945e7
4 changed files with 147 additions and 20 deletions
+6
View File
@@ -198,6 +198,12 @@ set_target_properties(test_gas_eos_stiffened PROPERTIES Fortran_MODULE_DIRECTORY
add_test(NAME gas_eos_stiffened COMMAND test_gas_eos_stiffened)
set_tests_properties(gas_eos_stiffened PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_gas_eos_dispatch tests/module/test_gas_eos_dispatch.f90)
target_link_libraries(test_gas_eos_dispatch PRIVATE sphlite_core)
set_target_properties(test_gas_eos_dispatch PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
add_test(NAME gas_eos_dispatch COMMAND test_gas_eos_dispatch)
set_tests_properties(gas_eos_dispatch PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_gas_state tests/module/test_gas_state.f90)
target_link_libraries(test_gas_state PRIVATE sphlite_core)
set_target_properties(test_gas_state PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}")
@@ -23,4 +23,5 @@
*SPHLITE EOS, TYPE=IDEAL_GAS, MATERIAL=AIR, GAMMA=1.4, E0=2.0, P0=0.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 PARTICLE CONTROL, H=0.15, MASS=0.01, VOLUME=0.008
*SPHLITE BODY FORCE, X=1.0, Y=-2.0, Z=3.0
*SPHLITE TIME CONTROL, DT=1.0E-8, TIME=2.0E-8, STEPS=2, SAFETY=0.5
+120
View File
@@ -0,0 +1,120 @@
program test_gas_eos_dispatch
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_gas_dt_limits
use sph_database, only: npart, rho, pressure, internal_energy, &
temperature, h, mass, volume, acc_body
use sph_database, only: gas_dt_cfl, gas_dt_accel, gas_dtcrit
use sph_gas, only: gas_material_count, gas_material_eos_type, &
GAS_EOS_IDEAL, GAS_EOS_JWL, GAS_EOS_STIFFENED
implicit none
integer :: ierr
call check_three_eos_dispatch()
call check_mixed_body_force_and_dt()
contains
subroutine check_three_eos_dispatch()
real(rk) :: expected_jwl
real(rk) :: relative_volume
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Gas dispatch')
call sph_read_inp('tests/data/gas_three_eos_031.inp', ierr)
call assert_ok(ierr, 'read failed for Gas dispatch')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Gas dispatch')
if (npart /= 6) call fail('Gas dispatch particle count mismatch')
if (gas_material_count /= 3) call fail('Gas material count mismatch')
if (gas_material_eos_type(1) /= GAS_EOS_IDEAL) call fail('ideal material EOS mismatch')
if (gas_material_eos_type(2) /= GAS_EOS_JWL) call fail('JWL material EOS mismatch')
if (gas_material_eos_type(3) /= GAS_EOS_STIFFENED) call fail('stiffened material EOS mismatch')
call assert_close(rho(1), 1.2_rk, 'ideal density mismatch')
call assert_close(internal_energy(1), 2.0_rk, 'ideal energy mismatch')
call assert_close(temperature(1), 293.15_rk, 'ideal temperature mismatch')
call assert_close(pressure(1), 0.96_rk, 'ideal pressure mismatch')
relative_volume = 1.0_rk
expected_jwl = 3.712e11_rk * exp(-4.15_rk * relative_volume) + &
3.231e9_rk * exp(-0.95_rk * relative_volume) + &
0.3_rk * 4.2e6_rk / relative_volume
call assert_close(rho(3), 1600.0_rk, 'JWL density mismatch')
call assert_rel_close(pressure(3), expected_jwl, 'JWL pressure mismatch')
call assert_close(rho(5), 5.0_rk, 'stiffened density mismatch')
call assert_close(internal_energy(5), 2000.0_rk, 'stiffened energy mismatch')
call assert_close(pressure(5), 2870.0_rk, 'stiffened pressure mismatch')
if (mass(5) <= 0.0_rk .or. volume(5) <= 0.0_rk .or. h(5) <= 0.0_rk) then
call fail('Gas shared particle control mismatch')
end if
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Gas dispatch')
end subroutine check_three_eos_dispatch
subroutine check_mixed_body_force_and_dt()
real(rk) :: dt_cfl
real(rk) :: dt_accel
real(rk) :: dtcrit
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for mixed Gas dt')
call sph_read_inp('tests/data/gas_air_products_mixed_031.inp', ierr)
call assert_ok(ierr, 'read failed for mixed Gas dt')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for mixed Gas dt')
call assert_close(acc_body(1,1), 1.0_rk, 'Gas body force x mismatch')
call assert_close(acc_body(2,3), -2.0_rk, 'Gas body force y mismatch')
call assert_close(acc_body(3,4), 3.0_rk, 'Gas body force z mismatch')
call sph_get_gas_dt_limits(dt_cfl, dt_accel, dtcrit, ierr)
call assert_ok(ierr, 'Gas dt dispatch failed')
if (dt_cfl <= 0.0_rk .or. dt_accel <= 0.0_rk .or. dtcrit <= 0.0_rk) then
call fail('Gas dt dispatch returned nonpositive value')
end if
call assert_close(gas_dt_cfl, dt_cfl, 'Gas dt CFL diagnostic mismatch')
call assert_close(gas_dt_accel, dt_accel, 'Gas dt accel diagnostic mismatch')
call assert_close(gas_dtcrit, dtcrit, 'Gas dtcrit diagnostic mismatch')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for mixed Gas dt')
end subroutine check_mixed_body_force_and_dt
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 assert_rel_close(actual, expected, message)
real(rk), intent(in) :: actual
real(rk), intent(in) :: expected
character(len=*), intent(in) :: message
if (abs(actual - expected) / max(abs(expected), 1.0_rk) > 1.0e-10_rk) then
call fail(message)
end if
end subroutine assert_rel_close
subroutine fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_gas_eos_dispatch
+20 -20
View File
@@ -56,26 +56,26 @@
## 阶段 C:EOS 分派、状态初始化与时间步
- [ ] 将 Gas 压力更新改为按粒子 `material_id` 分派 EOS。
- [ ] 为理想气体压力更新增加 material 级分派测试。
- [ ] 为 JWL 压力更新增加 material 级分派测试。
- [ ] 为 Stiffened gas 压力更新增加 material 级分派测试。
- [ ] 增加空气和爆轰产物混合输入的逐粒子压力检查。
- [ ] 对 Gas 粒子 material 无 EOS 的状态更新路径报 error。
- [ ] 将 Gas 初始密度设置改为按 material 分派。
- [ ] 将 Gas 初始内能设置改为按 material 分派。
- [ ] 将 Gas 初始温度设置改为按 material 分派。
- [ ] 将 Gas 初始压力设置改为按 material EOS 计算。
- [ ] 将 Gas 默认质量控制策略改为按 material 或共享策略处理。
- [ ] 将 Gas 默认体积控制策略改为按 material 或共享策略处理。
- [ ] 将 Gas 默认光滑长度策略改为按 material 或共享策略处理。
- [ ] 将 Gas 外部体力策略保持为共享路径并补充混合材料测试。
- [ ] 将 Gas 声速估计改为按 material/EOS 分派。
- [ ] 将 Gas CFL 时间步限制改为记录 `gas_dt_cfl`。
- [ ] 将 Gas 加速度时间步限制改为记录 `gas_dt_accel`。
- [ ] 将 Gas 临界时间步取值改为使用各分量最小值。
- [ ] 增加混合 Gas material 的时间步估计测试。
- [ ] 确认 Water 时间步和 pressure wave smoke 行为未被 Gas 改动影响。
- [x] 将 Gas 压力更新改为按粒子 `material_id` 分派 EOS。
- [x] 为理想气体压力更新增加 material 级分派测试。
- [x] 为 JWL 压力更新增加 material 级分派测试。
- [x] 为 Stiffened gas 压力更新增加 material 级分派测试。
- [x] 增加空气和爆轰产物混合输入的逐粒子压力检查。
- [x] 对 Gas 粒子 material 无 EOS 的状态更新路径报 error。
- [x] 将 Gas 初始密度设置改为按 material 分派。
- [x] 将 Gas 初始内能设置改为按 material 分派。
- [x] 将 Gas 初始温度设置改为按 material 分派。
- [x] 将 Gas 初始压力设置改为按 material EOS 计算。
- [x] 将 Gas 默认质量控制策略改为按 material 或共享策略处理。
- [x] 将 Gas 默认体积控制策略改为按 material 或共享策略处理。
- [x] 将 Gas 默认光滑长度策略改为按 material 或共享策略处理。
- [x] 将 Gas 外部体力策略保持为共享路径并补充混合材料测试。
- [x] 将 Gas 声速估计改为按 material/EOS 分派。
- [x] 将 Gas CFL 时间步限制改为记录 `gas_dt_cfl`。
- [x] 将 Gas 加速度时间步限制改为记录 `gas_dt_accel`。
- [x] 将 Gas 临界时间步取值改为使用各分量最小值。
- [x] 增加混合 Gas material 的时间步估计测试。
- [x] 确认 Water 时间步和 pressure wave smoke 行为未被 Gas 改动影响。
## 阶段 D:Gas 源项占位、诊断与输出