Add Explosive detonation state

This commit is contained in:
Codex
2026-07-03 12:03:06 +08:00
parent d4e51e4177
commit 4b95609d14
5 changed files with 233 additions and 23 deletions
+142 -1
View File
@@ -4,7 +4,8 @@ module sph_explosive
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
section_material_id, npart, particle_phase, particle_status, &
material_id, x0, SPH_PHASE_EXPLOSIVE, SPH_STATUS_ACTIVE
use sph_gas, only: sph_gas_table_index_by_material_id, &
gas_material_eos_defined
implicit none
@@ -30,6 +31,12 @@ module sph_explosive
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(:,:)
contains
@@ -41,6 +48,7 @@ contains
subroutine sph_explosive_reset()
explosive_module_initialized = .false.
call sph_explosive_clear_material_table()
call sph_explosive_deallocate_state()
end subroutine sph_explosive_reset
subroutine sph_explosive_clear_material_table()
@@ -62,6 +70,65 @@ contains
explosive_ignition_time = 0.0_rk
end subroutine sph_explosive_clear_material_table
subroutine sph_explosive_finalize()
call sph_explosive_reset()
end subroutine sph_explosive_finalize
subroutine sph_explosive_build(ierr)
integer, intent(out) :: ierr
ierr = SPH_SUCCESS
if (.not. explosive_material_seen) return
call sph_explosive_validate_input(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_explosive_allocate_state(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_explosive_clear_particle_state()
call sph_explosive_compute_detonation_times(ierr)
end subroutine sph_explosive_build
subroutine sph_explosive_allocate_state(ierr)
integer, intent(out) :: ierr
integer :: stat
ierr = SPH_SUCCESS
if (npart <= 0) return
if (allocated(explosive_detonation_time)) then
if (size(explosive_detonation_time) == npart) return
call sph_explosive_deallocate_state()
end if
allocate(explosive_ignition_status(npart), &
explosive_detonation_time(npart), &
explosive_reaction_progress(npart), &
explosive_released_mass(npart), &
explosive_released_energy(npart), &
explosive_released_momentum(SPH_NDIM,npart), stat=stat)
if (stat /= 0) then
call sph_error_set(SPH_ERROR_INPUT, 'failed to allocate Explosive state')
ierr = SPH_ERROR_INPUT
return
end if
call sph_explosive_clear_particle_state()
end subroutine sph_explosive_allocate_state
subroutine sph_explosive_deallocate_state()
if (allocated(explosive_ignition_status)) deallocate(explosive_ignition_status)
if (allocated(explosive_detonation_time)) deallocate(explosive_detonation_time)
if (allocated(explosive_reaction_progress)) deallocate(explosive_reaction_progress)
if (allocated(explosive_released_mass)) deallocate(explosive_released_mass)
if (allocated(explosive_released_energy)) deallocate(explosive_released_energy)
if (allocated(explosive_released_momentum)) deallocate(explosive_released_momentum)
end subroutine sph_explosive_deallocate_state
subroutine sph_explosive_clear_particle_state()
if (allocated(explosive_ignition_status)) explosive_ignition_status = 0
if (allocated(explosive_detonation_time)) explosive_detonation_time = 0.0_rk
if (allocated(explosive_reaction_progress)) explosive_reaction_progress = 0.0_rk
if (allocated(explosive_released_mass)) explosive_released_mass = 0.0_rk
if (allocated(explosive_released_energy)) explosive_released_energy = 0.0_rk
if (allocated(explosive_released_momentum)) explosive_released_momentum = 0.0_rk
end subroutine sph_explosive_clear_particle_state
subroutine sph_explosive_note_material(name, material_type_in)
character(len=*), intent(in) :: name
character(len=*), intent(in) :: material_type_in
@@ -242,6 +309,70 @@ contains
end do
end subroutine sph_explosive_count_unbound_materials
subroutine sph_explosive_compute_detonation_times(ierr)
integer, intent(out) :: ierr
integer :: i
integer :: ign
integer :: explosive_index
real(rk) :: best_time
real(rk) :: distance
real(rk) :: arrival
ierr = SPH_SUCCESS
call sph_explosive_allocate_state(ierr)
if (ierr /= SPH_SUCCESS) return
do i = 1, npart
if (.not. sph_explosive_is_active_particle(i)) cycle
explosive_index = sph_explosive_table_index_by_material_id(material_id(i))
if (explosive_index <= 0) then
call sph_error_set(SPH_ERROR_INPUT, 'Explosive particle material has no control')
ierr = SPH_ERROR_INPUT
return
end if
best_time = huge(1.0_rk)
do ign = 1, explosive_ignition_count
if (explosive_ignition_material_id(ign) /= material_id(i)) cycle
distance = sqrt(sum((x0(:,i) - explosive_ignition_x(:,ign)) * &
(x0(:,i) - explosive_ignition_x(:,ign))))
arrival = explosive_ignition_time(ign) + distance / &
explosive_detonation_velocity(explosive_index)
if (arrival < best_time) best_time = arrival
end do
if (best_time == huge(1.0_rk)) then
call sph_error_set(SPH_ERROR_INPUT, 'Explosive particle has no ignition')
ierr = SPH_ERROR_INPUT
return
end if
explosive_detonation_time(i) = best_time
explosive_ignition_status(i) = 1
end do
end subroutine sph_explosive_compute_detonation_times
subroutine sph_explosive_get_detonation_time_range(time_min, time_max, ierr)
real(rk), intent(out) :: time_min
real(rk), intent(out) :: time_max
integer, intent(out) :: ierr
integer :: i
logical :: first_value
ierr = SPH_SUCCESS
time_min = 0.0_rk
time_max = 0.0_rk
first_value = .true.
if (.not. allocated(explosive_detonation_time)) return
do i = 1, npart
if (.not. sph_explosive_is_active_particle(i)) cycle
if (first_value) then
time_min = explosive_detonation_time(i)
time_max = explosive_detonation_time(i)
first_value = .false.
else
if (explosive_detonation_time(i) < time_min) time_min = explosive_detonation_time(i)
if (explosive_detonation_time(i) > time_max) time_max = explosive_detonation_time(i)
end if
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
@@ -379,6 +510,16 @@ contains
end do
end function sph_explosive_has_ignition_for_material
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_finite(value)
real(rk), intent(in) :: value