768 lines
30 KiB
Fortran
768 lines
30 KiB
Fortran
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
|
|
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()
|
|
explosive_module_initialized = .true.
|
|
call sph_explosive_clear_material_table()
|
|
end subroutine sph_explosive_initialize
|
|
|
|
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()
|
|
explosive_material_seen = .false.
|
|
explosive_material_count = 0
|
|
explosive_material_id = 0
|
|
explosive_material_name = ' '
|
|
explosive_control_defined = .false.
|
|
explosive_product_material_id = 0
|
|
explosive_product_material_name = ' '
|
|
explosive_density0 = 0.0_rk
|
|
explosive_detonation_velocity = 0.0_rk
|
|
explosive_energy_per_mass = 0.0_rk
|
|
explosive_burn_time = 0.0_rk
|
|
explosive_conversion_mode = EXPLOSIVE_CONVERSION_NONE
|
|
explosive_ignition_count = 0
|
|
explosive_ignition_material_id = 0
|
|
explosive_ignition_x = 0.0_rk
|
|
explosive_ignition_time = 0.0_rk
|
|
explosive_dt_reaction = 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_apply_initial_conditions(ierr)
|
|
if (ierr /= SPH_SUCCESS) return
|
|
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
|
|
integer :: explosive_index
|
|
|
|
if (index(sph_explosive_upper(material_type_in), 'EXPLOSIVE') > 0) then
|
|
explosive_material_seen = .true.
|
|
explosive_index = sph_explosive_register_material(name)
|
|
end if
|
|
end subroutine sph_explosive_note_material
|
|
|
|
subroutine sph_explosive_set_control(material_name_in, model_type, &
|
|
detonation_velocity, energy_per_mass, burn_time, &
|
|
product_material_name_in, conversion_name, ierr)
|
|
character(len=*), intent(in) :: material_name_in
|
|
character(len=*), intent(in) :: model_type
|
|
real(rk), intent(in) :: detonation_velocity
|
|
real(rk), intent(in) :: energy_per_mass
|
|
real(rk), intent(in) :: burn_time
|
|
character(len=*), intent(in) :: product_material_name_in
|
|
character(len=*), intent(in) :: conversion_name
|
|
integer, intent(out) :: ierr
|
|
integer :: explosive_index
|
|
integer :: product_index
|
|
integer :: conversion_mode
|
|
character(len=64) :: upper_model
|
|
|
|
ierr = SPH_SUCCESS
|
|
upper_model = sph_explosive_upper(model_type)
|
|
if (len_trim(material_name_in) == 0) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'Explosive control MATERIAL is required')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
if (index(upper_model, 'PROGRAMMED_BURN') <= 0) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'Explosive TYPE must be PROGRAMMED_BURN')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
if (detonation_velocity <= 0.0_rk) then
|
|
call sph_error_set(SPH_ERROR_ARGUMENT, 'Explosive detonation velocity must be positive')
|
|
ierr = SPH_ERROR_ARGUMENT
|
|
return
|
|
end if
|
|
if (energy_per_mass < 0.0_rk) then
|
|
call sph_error_set(SPH_ERROR_ARGUMENT, 'Explosive energy must be non-negative')
|
|
ierr = SPH_ERROR_ARGUMENT
|
|
return
|
|
end if
|
|
if (burn_time < 0.0_rk) then
|
|
call sph_error_set(SPH_ERROR_ARGUMENT, 'Explosive burn time must be non-negative')
|
|
ierr = SPH_ERROR_ARGUMENT
|
|
return
|
|
end if
|
|
if (len_trim(product_material_name_in) == 0) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'Explosive PRODUCT_MATERIAL is required')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
call sph_explosive_prepare_material(material_name_in, explosive_index, ierr)
|
|
if (ierr /= SPH_SUCCESS) return
|
|
if (explosive_control_defined(explosive_index)) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'Explosive material control is already defined')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
product_index = sph_explosive_find_material(product_material_name_in)
|
|
if (product_index <= 0) 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
|
|
call sph_explosive_validate_product_gas(product_index, ierr)
|
|
if (ierr /= SPH_SUCCESS) return
|
|
conversion_mode = sph_explosive_conversion_id(conversion_name)
|
|
if (conversion_mode == EXPLOSIVE_CONVERSION_NONE) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'Explosive CONVERSION must be PHASE or SOURCE')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
explosive_control_defined(explosive_index) = .true.
|
|
explosive_product_material_id(explosive_index) = product_index
|
|
explosive_product_material_name(explosive_index) = material_name(product_index)
|
|
explosive_density0(explosive_index) = material_density(explosive_material_id(explosive_index))
|
|
explosive_detonation_velocity(explosive_index) = detonation_velocity
|
|
explosive_energy_per_mass(explosive_index) = energy_per_mass
|
|
explosive_burn_time(explosive_index) = burn_time
|
|
explosive_conversion_mode(explosive_index) = conversion_mode
|
|
end subroutine sph_explosive_set_control
|
|
|
|
subroutine sph_explosive_set_ignition(material_name_in, ignition_x, &
|
|
ignition_time, ierr)
|
|
character(len=*), intent(in) :: material_name_in
|
|
real(rk), intent(in) :: ignition_x(SPH_NDIM)
|
|
real(rk), intent(in) :: ignition_time
|
|
integer, intent(out) :: ierr
|
|
integer :: explosive_index
|
|
|
|
ierr = SPH_SUCCESS
|
|
if (len_trim(material_name_in) == 0) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'Explosive ignition MATERIAL is required')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
if (ignition_time < 0.0_rk) then
|
|
call sph_error_set(SPH_ERROR_ARGUMENT, 'Explosive ignition time must be non-negative')
|
|
ierr = SPH_ERROR_ARGUMENT
|
|
return
|
|
end if
|
|
if (.not. sph_explosive_vector_is_finite(ignition_x)) then
|
|
call sph_error_set(SPH_ERROR_ARGUMENT, 'Explosive ignition coordinate is not finite')
|
|
ierr = SPH_ERROR_ARGUMENT
|
|
return
|
|
end if
|
|
call sph_explosive_prepare_material(material_name_in, explosive_index, ierr)
|
|
if (ierr /= SPH_SUCCESS) return
|
|
if (explosive_ignition_count >= SPH_MAX_MATERIALS) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'too many Explosive ignition records')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
explosive_ignition_count = explosive_ignition_count + 1
|
|
explosive_ignition_material_id(explosive_ignition_count) = &
|
|
explosive_material_id(explosive_index)
|
|
explosive_ignition_x(:,explosive_ignition_count) = ignition_x
|
|
explosive_ignition_time(explosive_ignition_count) = ignition_time
|
|
end subroutine sph_explosive_set_ignition
|
|
|
|
subroutine sph_explosive_validate_input(ierr)
|
|
integer, intent(out) :: ierr
|
|
integer :: explosive_index
|
|
integer :: mat_index
|
|
|
|
ierr = SPH_SUCCESS
|
|
if (.not. explosive_material_seen) return
|
|
do explosive_index = 1, explosive_material_count
|
|
mat_index = explosive_material_id(explosive_index)
|
|
if (mat_index < 1 .or. mat_index > material_count) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'Explosive material table is invalid')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
if (material_density(mat_index) <= 0.0_rk) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'input is missing *DENSITY for Explosive material')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
if (.not. explosive_control_defined(explosive_index)) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'input is missing *SPHLITE EXPLOSIVE for Explosive material')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
call sph_explosive_validate_product_gas( &
|
|
explosive_product_material_id(explosive_index), ierr)
|
|
if (ierr /= SPH_SUCCESS) return
|
|
if (.not. sph_explosive_has_ignition_for_material(mat_index)) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'input is missing *SPHLITE IGNITION for Explosive material')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
end do
|
|
end subroutine sph_explosive_validate_input
|
|
|
|
subroutine sph_explosive_count_unbound_materials(count)
|
|
integer, intent(out) :: count
|
|
integer :: i
|
|
|
|
count = 0
|
|
do i = 1, explosive_material_count
|
|
if (.not. sph_explosive_has_section_binding_for_id(explosive_material_id(i))) then
|
|
count = count + 1
|
|
end if
|
|
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_apply_initial_conditions(ierr)
|
|
integer, intent(out) :: ierr
|
|
integer :: i
|
|
integer :: mat_index
|
|
|
|
ierr = SPH_SUCCESS
|
|
do i = 1, npart
|
|
if (.not. sph_explosive_is_active_particle(i)) cycle
|
|
mat_index = material_id(i)
|
|
if (mat_index < 1 .or. mat_index > material_count) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'Explosive particle material is invalid')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
if (material_density(mat_index) <= 0.0_rk) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'Explosive particle density is invalid')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
rho(i) = material_density(mat_index)
|
|
if (mass(i) <= 0.0_rk) mass(i) = 1.0_rk
|
|
volume(i) = mass(i) / rho(i)
|
|
end do
|
|
end subroutine sph_explosive_apply_initial_conditions
|
|
|
|
subroutine sph_explosive_advance(dt, time, ierr)
|
|
real(rk), intent(in) :: dt
|
|
real(rk), intent(in) :: time
|
|
integer, intent(out) :: ierr
|
|
integer :: i
|
|
integer :: explosive_index
|
|
real(rk) :: lambda_old
|
|
real(rk) :: lambda_target
|
|
real(rk) :: delta_lambda
|
|
real(rk) :: release_mass
|
|
real(rk) :: release_energy
|
|
real(rk) :: release_momentum(SPH_NDIM)
|
|
|
|
ierr = SPH_SUCCESS
|
|
if (.not. explosive_material_seen) return
|
|
if (dt <= 0.0_rk) then
|
|
call sph_error_set(SPH_ERROR_ARGUMENT, 'Explosive time step must be positive')
|
|
ierr = SPH_ERROR_ARGUMENT
|
|
return
|
|
end if
|
|
call sph_explosive_allocate_state(ierr)
|
|
if (ierr /= SPH_SUCCESS) return
|
|
call sph_gas_clear_sources(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
|
|
lambda_old = explosive_reaction_progress(i)
|
|
lambda_target = sph_explosive_reaction_target(i, explosive_index, time)
|
|
if (lambda_target < lambda_old) lambda_target = lambda_old
|
|
if (lambda_target > 1.0_rk) lambda_target = 1.0_rk
|
|
delta_lambda = lambda_target - lambda_old
|
|
if (delta_lambda <= 0.0_rk) cycle
|
|
release_mass = delta_lambda * mass(i)
|
|
release_energy = release_mass * explosive_energy_per_mass(explosive_index)
|
|
release_momentum = release_mass * v(:,i)
|
|
explosive_reaction_progress(i) = lambda_target
|
|
explosive_released_mass(i) = explosive_released_mass(i) + release_mass
|
|
explosive_released_energy(i) = explosive_released_energy(i) + release_energy
|
|
explosive_released_momentum(:,i) = explosive_released_momentum(:,i) + &
|
|
release_momentum
|
|
if (explosive_conversion_mode(explosive_index) == EXPLOSIVE_CONVERSION_SOURCE) then
|
|
call sph_explosive_apply_source_release(explosive_index, release_mass, &
|
|
release_momentum, release_energy, dt, ierr)
|
|
if (ierr /= SPH_SUCCESS) return
|
|
else if (lambda_target >= 1.0_rk) then
|
|
call sph_explosive_convert_particle_to_gas(i, explosive_index, ierr)
|
|
if (ierr /= SPH_SUCCESS) return
|
|
end if
|
|
end do
|
|
end subroutine sph_explosive_advance
|
|
|
|
real(rk) function sph_explosive_reaction_target(index, explosive_index, time)
|
|
integer, intent(in) :: index
|
|
integer, intent(in) :: explosive_index
|
|
real(rk), intent(in) :: time
|
|
real(rk) :: burn_window
|
|
|
|
sph_explosive_reaction_target = explosive_reaction_progress(index)
|
|
if (time < explosive_detonation_time(index)) return
|
|
burn_window = explosive_burn_time(explosive_index)
|
|
if (burn_window <= 0.0_rk) then
|
|
sph_explosive_reaction_target = 1.0_rk
|
|
else
|
|
sph_explosive_reaction_target = &
|
|
(time - explosive_detonation_time(index)) / burn_window
|
|
if (sph_explosive_reaction_target < 0.0_rk) then
|
|
sph_explosive_reaction_target = 0.0_rk
|
|
end if
|
|
if (sph_explosive_reaction_target > 1.0_rk) then
|
|
sph_explosive_reaction_target = 1.0_rk
|
|
end if
|
|
end if
|
|
end function sph_explosive_reaction_target
|
|
|
|
subroutine sph_explosive_apply_source_release(explosive_index, release_mass, &
|
|
release_momentum, release_energy, dt, ierr)
|
|
integer, intent(in) :: explosive_index
|
|
real(rk), intent(in) :: release_mass
|
|
real(rk), intent(in) :: release_momentum(SPH_NDIM)
|
|
real(rk), intent(in) :: release_energy
|
|
real(rk), intent(in) :: dt
|
|
integer, intent(out) :: ierr
|
|
integer :: product_id
|
|
integer :: target_count
|
|
integer :: i
|
|
real(rk) :: mass_rate
|
|
real(rk) :: energy_rate
|
|
real(rk) :: momentum_rate(SPH_NDIM)
|
|
|
|
ierr = SPH_SUCCESS
|
|
product_id = explosive_product_material_id(explosive_index)
|
|
target_count = sph_explosive_count_active_gas(product_id)
|
|
if (target_count <= 0) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'Explosive SOURCE conversion has no active product Gas target')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
mass_rate = release_mass / (dt * real(target_count, rk))
|
|
energy_rate = release_energy / (dt * real(target_count, rk))
|
|
momentum_rate = release_momentum / (dt * real(target_count, rk))
|
|
do i = 1, npart
|
|
if (.not. sph_explosive_is_active_gas_target(i, product_id)) cycle
|
|
call sph_gas_add_source_by_particle(i, mass_rate, momentum_rate, &
|
|
energy_rate, ierr)
|
|
if (ierr /= SPH_SUCCESS) return
|
|
end do
|
|
end subroutine sph_explosive_apply_source_release
|
|
|
|
subroutine sph_explosive_convert_particle_to_gas(index, explosive_index, ierr)
|
|
integer, intent(in) :: index
|
|
integer, intent(in) :: explosive_index
|
|
integer, intent(out) :: ierr
|
|
integer :: product_id
|
|
|
|
ierr = SPH_SUCCESS
|
|
product_id = explosive_product_material_id(explosive_index)
|
|
if (product_id < 1 .or. product_id > material_count) then
|
|
call sph_error_set(SPH_ERROR_INPUT, 'Explosive product material is invalid')
|
|
ierr = SPH_ERROR_INPUT
|
|
return
|
|
end if
|
|
particle_phase(index) = SPH_PHASE_GAS
|
|
material_id(index) = product_id
|
|
if (material_density(product_id) > 0.0_rk) rho(index) = material_density(product_id)
|
|
if (rho(index) > 0.0_rk) volume(index) = mass(index) / rho(index)
|
|
internal_energy(index) = explosive_energy_per_mass(explosive_index)
|
|
end subroutine sph_explosive_convert_particle_to_gas
|
|
|
|
subroutine sph_explosive_estimate_dt_limit(dt_reaction, ierr)
|
|
real(rk), intent(out) :: dt_reaction
|
|
integer, intent(out) :: ierr
|
|
integer :: i
|
|
real(rk) :: burn_window
|
|
|
|
ierr = SPH_SUCCESS
|
|
dt_reaction = 0.0_rk
|
|
if (.not. explosive_material_seen) then
|
|
explosive_dt_reaction = 0.0_rk
|
|
return
|
|
end if
|
|
do i = 1, explosive_material_count
|
|
burn_window = explosive_burn_time(i)
|
|
if (burn_window <= 0.0_rk) cycle
|
|
if (dt_reaction <= 0.0_rk .or. burn_window / 4.0_rk < dt_reaction) then
|
|
dt_reaction = burn_window / 4.0_rk
|
|
end if
|
|
end do
|
|
explosive_dt_reaction = dt_reaction
|
|
end subroutine sph_explosive_estimate_dt_limit
|
|
|
|
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
|
|
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_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
|