Complete Explosive 0.4.0 gate

This commit is contained in:
Codex
2026-07-03 12:53:34 +08:00
parent 187af844d1
commit d4c8c39253
25 changed files with 1118 additions and 288 deletions
+6 -256
View File
@@ -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
+234
View File
@@ -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
+35
View File
@@ -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
+2 -1
View File
@@ -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
+3 -2
View File
@@ -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