Add explosive source phase diagnostics

This commit is contained in:
Codex
2026-07-03 13:36:16 +08:00
parent d3c3a3359a
commit fbbaab3771
9 changed files with 318 additions and 43 deletions
@@ -0,0 +1,65 @@
program test_explosive_phase_refresh
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, mass, rho, volume, &
pressure, internal_energy, gas_particle_count, gas_mass, gas_max_pressure, &
SPH_PHASE_GAS
use sph_explosive_state, only: explosive_converted_count, &
explosive_reaction_progress
implicit none
integer :: ierr
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed')
call sph_read_inp('tests/data/explosive_phase_refresh_041.inp', ierr)
call assert_ok(ierr, 'read phase refresh failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build phase refresh failed')
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'advance phase refresh failed')
if (particle_phase(1) /= SPH_PHASE_GAS) call fail('phase did not refresh to Gas')
if (material_id(1) /= 2) call fail('product material did not refresh')
call assert_close(rho(1), 1200.0_rk, 'product Gas density mismatch')
call assert_close(volume(1), mass(1) / rho(1), 'product Gas volume mismatch')
call assert_close(internal_energy(1), 4.2e6_rk, 'product Gas energy mismatch')
if (pressure(1) <= 0.0_rk) call fail('product Gas pressure was not refreshed')
if (gas_particle_count <= 0 .or. gas_mass <= 0.0_rk) then
call fail('Gas summary did not include converted particle')
end if
if (gas_max_pressure <= 0.0_rk) call fail('Gas pressure summary mismatch')
if (explosive_converted_count <= 0) call fail('converted count missing')
call assert_close(explosive_reaction_progress(1), 1.0_rk, &
'Explosive history was not retained')
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 * 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_phase_refresh
@@ -0,0 +1,69 @@
program test_explosive_source_targeting
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
use sph_explosive_state, only: explosive_source_target_count, &
explosive_source_mass_total, explosive_source_energy_total, &
explosive_source_momentum_total, explosive_released_mass
implicit none
integer :: ierr
real(rk) :: target_a_before
real(rk) :: target_b_before
real(rk) :: target_a_after
real(rk) :: target_b_after
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed')
call sph_read_inp('tests/data/explosive_source_multi_target_041.inp', ierr)
call assert_ok(ierr, 'read source targeting failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build source targeting failed')
target_a_before = mass(3) + mass(4)
target_b_before = mass(5) + mass(6)
call sph_advance_explicit(1.0e-7_rk, ierr)
call assert_ok(ierr, 'advance source targeting failed')
target_a_after = mass(3) + mass(4)
target_b_after = mass(5) + mass(6)
if (target_a_after <= target_a_before) call fail('matched product Gas did not receive source')
call assert_close(target_b_after, target_b_before, &
'unmatched product Gas received source')
if (explosive_source_target_count /= 2) call fail('source target count mismatch')
call assert_close(explosive_source_mass_total, explosive_released_mass(1), &
'source mass total mismatch')
if (explosive_source_energy_total <= 0.0_rk) call fail('source energy total missing')
if (maxval(abs(explosive_source_momentum_total)) > 1.0e-12_rk) then
call fail('zero velocity source momentum mismatch')
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 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 * 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_source_targeting
@@ -0,0 +1,56 @@
program test_explosive_water_gas_smoke
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_run_explicit
use sph_database, only: water_mass, water_max_pressure, gas_particle_count, &
gas_volume, gas_max_pressure
use sph_explosive, only: sph_explosive_get_release_balance
implicit none
integer :: ierr
real(rk) :: mass_values(4)
real(rk) :: energy_values(2)
real(rk) :: momentum_values(3)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed')
call sph_read_inp('tests/data/explosive_water_gas_mixed_041.inp', ierr)
call assert_ok(ierr, 'read mixed smoke failed')
call sph_build_model(ierr)
call assert_ok(ierr, 'build mixed smoke failed')
call sph_run_explicit(ierr)
call assert_ok(ierr, 'run mixed smoke failed')
if (water_mass <= 0.0_rk) call fail('Water summary vanished in mixed smoke')
if (water_max_pressure /= water_max_pressure) call fail('Water pressure is not finite')
if (gas_particle_count <= 0) call fail('Gas particles missing in mixed smoke')
if (gas_volume <= 0.0_rk) call fail('Gas volume mismatch in mixed smoke')
if (gas_max_pressure /= gas_max_pressure) call fail('Gas pressure is not finite')
call sph_explosive_get_release_balance(mass_values, energy_values, &
momentum_values, ierr)
call assert_ok(ierr, 'release balance query failed')
if (mass_values(2) <= 0.0_rk) call fail('Explosive did not release in mixed smoke')
if (mass_values(4) /= mass_values(4) .or. energy_values(2) /= energy_values(2)) then
call fail('release balance is not finite')
end if
momentum_values = momentum_values
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_water_gas_smoke
+9 -1
View File
@@ -116,7 +116,8 @@ contains
if (ios /= 0) call fail('particle CSV header missing')
if (trim(header) /= 'id,phase,status,material,section,x,y,z,' // &
'vx,vy,vz,rho,pressure,temperature,h,explosive_detonation_time,' // &
'explosive_lambda,explosive_released_mass,explosive_released_energy') then
'explosive_lambda,explosive_initial_mass,explosive_remaining_mass,' // &
'explosive_released_mass,explosive_released_energy') then
call fail('particle CSV header mismatch')
end if
end subroutine check_particle_header
@@ -148,6 +149,13 @@ contains
call assert_summary_metric(filename, 'explosive_particles')
call assert_summary_metric(filename, 'explosive_lambda_mean')
call assert_summary_metric(filename, 'explosive_released_energy')
call assert_summary_metric(filename, 'explosive_initial_mass')
call assert_summary_metric(filename, 'explosive_remaining_mass')
call assert_summary_metric(filename, 'explosive_release_mass_error')
call assert_summary_metric(filename, 'explosive_release_energy_error')
call assert_summary_metric(filename, 'explosive_converted_particles')
call assert_summary_metric(filename, 'explosive_source_particles')
call assert_summary_metric(filename, 'explosive_source_mass_total')
end subroutine check_summary_metrics
subroutine assert_summary_metric(filename, metric)