Add Gas input parsing and state
This commit is contained in:
@@ -1,15 +1,643 @@
|
||||
module sph_gas
|
||||
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: npart, particle_phase, particle_status, material_id, &
|
||||
material_count, material_name, material_type, material_density, &
|
||||
section_count, section_material_id, x, v, a, mass, rho, volume, &
|
||||
pressure, internal_energy, temperature, h, drho_dt, acc_pressure, &
|
||||
acc_body, neighbor_count, neighbor_offset, neighbor_list, &
|
||||
gas_particle_count, gas_mass, gas_volume, gas_momentum, gas_center, &
|
||||
gas_mean_pressure, gas_max_pressure, gas_min_density, gas_max_density, &
|
||||
gas_equivalent_radius, gas_previous_equivalent_radius, gas_radius_rate, &
|
||||
gas_previous_center, gas_center_shift, gas_dt_cfl, gas_dt_accel, &
|
||||
gas_dtcrit, SPH_PHASE_GAS, SPH_STATUS_ACTIVE, sph_db_clear_gas_diagnostics
|
||||
use sph_particle, only: SPH_KERNEL_DEFAULT, sph_kernel_gradient
|
||||
implicit none
|
||||
|
||||
integer, parameter :: GAS_EOS_NONE = 0
|
||||
integer, parameter :: GAS_EOS_IDEAL = 1
|
||||
integer, parameter :: GAS_EOS_JWL = 2
|
||||
integer, parameter :: GAS_EOS_STIFFENED = 3
|
||||
|
||||
logical :: gas_module_initialized = .false.
|
||||
logical :: gas_material_seen = .false.
|
||||
logical :: gas_eos_defined = .false.
|
||||
logical :: gas_particle_control_defined = .false.
|
||||
logical :: gas_bubble_history_valid = .false.
|
||||
character(len=64) :: gas_material_name = 'GAS'
|
||||
integer :: gas_material_internal_id = 0
|
||||
integer :: gas_eos_type = GAS_EOS_NONE
|
||||
real(rk) :: gas_rho0 = 1.0_rk
|
||||
real(rk) :: gas_gamma = 1.4_rk
|
||||
real(rk) :: gas_e0 = 0.0_rk
|
||||
real(rk) :: gas_p0 = 0.0_rk
|
||||
real(rk) :: gas_jwl_a = 0.0_rk
|
||||
real(rk) :: gas_jwl_b = 0.0_rk
|
||||
real(rk) :: gas_jwl_r1 = 0.0_rk
|
||||
real(rk) :: gas_jwl_r2 = 0.0_rk
|
||||
real(rk) :: gas_jwl_omega = 0.0_rk
|
||||
real(rk) :: gas_pinf = 0.0_rk
|
||||
real(rk) :: gas_default_h = 1.0_rk
|
||||
real(rk) :: gas_default_mass = 1.0_rk
|
||||
real(rk) :: gas_default_volume = 1.0_rk
|
||||
real(rk) :: gas_body_force(SPH_NDIM) = 0.0_rk
|
||||
|
||||
contains
|
||||
|
||||
subroutine sph_gas_initialize()
|
||||
gas_module_initialized = .true.
|
||||
call sph_gas_reset_state()
|
||||
end subroutine sph_gas_initialize
|
||||
|
||||
subroutine sph_gas_reset()
|
||||
gas_module_initialized = .false.
|
||||
call sph_gas_reset_state()
|
||||
end subroutine sph_gas_reset
|
||||
|
||||
subroutine sph_gas_reset_state()
|
||||
gas_material_seen = .false.
|
||||
gas_eos_defined = .false.
|
||||
gas_particle_control_defined = .false.
|
||||
gas_bubble_history_valid = .false.
|
||||
gas_material_name = 'GAS'
|
||||
gas_material_internal_id = 0
|
||||
gas_eos_type = GAS_EOS_NONE
|
||||
gas_rho0 = 1.0_rk
|
||||
gas_gamma = 1.4_rk
|
||||
gas_e0 = 0.0_rk
|
||||
gas_p0 = 0.0_rk
|
||||
gas_jwl_a = 0.0_rk
|
||||
gas_jwl_b = 0.0_rk
|
||||
gas_jwl_r1 = 0.0_rk
|
||||
gas_jwl_r2 = 0.0_rk
|
||||
gas_jwl_omega = 0.0_rk
|
||||
gas_pinf = 0.0_rk
|
||||
gas_default_h = 1.0_rk
|
||||
gas_default_mass = 1.0_rk
|
||||
gas_default_volume = 1.0_rk
|
||||
gas_body_force = 0.0_rk
|
||||
gas_previous_equivalent_radius = 0.0_rk
|
||||
gas_previous_center = 0.0_rk
|
||||
call sph_db_clear_gas_diagnostics()
|
||||
end subroutine sph_gas_reset_state
|
||||
|
||||
subroutine sph_gas_note_material(name, material_type_in)
|
||||
character(len=*), intent(in) :: name
|
||||
character(len=*), intent(in) :: material_type_in
|
||||
|
||||
if (index(sph_gas_upper(material_type_in), 'GAS') > 0) then
|
||||
gas_material_seen = .true.
|
||||
gas_material_name = name
|
||||
gas_material_internal_id = sph_gas_find_material(name)
|
||||
end if
|
||||
end subroutine sph_gas_note_material
|
||||
|
||||
subroutine sph_gas_set_eos(eos_type, material_name_in, rho0, gamma, e0, p0, &
|
||||
a_value, b_value, r1, r2, omega, pinf, ierr)
|
||||
character(len=*), intent(in) :: eos_type
|
||||
character(len=*), intent(in) :: material_name_in
|
||||
real(rk), intent(in) :: rho0
|
||||
real(rk), intent(in) :: gamma
|
||||
real(rk), intent(in) :: e0
|
||||
real(rk), intent(in) :: p0
|
||||
real(rk), intent(in) :: a_value
|
||||
real(rk), intent(in) :: b_value
|
||||
real(rk), intent(in) :: r1
|
||||
real(rk), intent(in) :: r2
|
||||
real(rk), intent(in) :: omega
|
||||
real(rk), intent(in) :: pinf
|
||||
integer, intent(out) :: ierr
|
||||
character(len=64) :: upper_type
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
upper_type = sph_gas_upper(eos_type)
|
||||
if (len_trim(eos_type) == 0) then
|
||||
call sph_error_set(SPH_ERROR_INPUT, 'Gas EOS TYPE is required')
|
||||
ierr = SPH_ERROR_INPUT
|
||||
return
|
||||
end if
|
||||
if (len_trim(material_name_in) == 0) then
|
||||
call sph_error_set(SPH_ERROR_INPUT, 'Gas EOS MATERIAL is required')
|
||||
ierr = SPH_ERROR_INPUT
|
||||
return
|
||||
end if
|
||||
if (sph_gas_find_material(material_name_in) <= 0) then
|
||||
call sph_error_set(SPH_ERROR_INPUT, 'Gas EOS references unknown material')
|
||||
ierr = SPH_ERROR_INPUT
|
||||
return
|
||||
end if
|
||||
|
||||
if (index(upper_type, 'IDEAL_GAS') > 0) then
|
||||
call sph_gas_set_ideal(material_name_in, gamma, e0, p0, ierr)
|
||||
else if (index(upper_type, 'JWL') > 0) then
|
||||
call sph_gas_set_jwl(material_name_in, rho0, a_value, b_value, r1, r2, &
|
||||
omega, e0, ierr)
|
||||
else if (index(upper_type, 'STIFFENED_GAS') > 0) then
|
||||
call sph_gas_set_stiffened(material_name_in, rho0, gamma, e0, pinf, ierr)
|
||||
else
|
||||
call sph_error_set(SPH_ERROR_INPUT, 'Gas EOS TYPE is not supported')
|
||||
ierr = SPH_ERROR_INPUT
|
||||
end if
|
||||
end subroutine sph_gas_set_eos
|
||||
|
||||
subroutine sph_gas_set_ideal(material_name_in, gamma, e0, p0, ierr)
|
||||
character(len=*), intent(in) :: material_name_in
|
||||
real(rk), intent(in) :: gamma
|
||||
real(rk), intent(in) :: e0
|
||||
real(rk), intent(in) :: p0
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
if (gamma <= 1.0_rk) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'Ideal gas gamma must be greater than one')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
if (e0 < 0.0_rk) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'Ideal gas internal energy must be non-negative')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
gas_material_seen = .true.
|
||||
gas_material_name = material_name_in
|
||||
gas_material_internal_id = sph_gas_find_material(material_name_in)
|
||||
gas_eos_type = GAS_EOS_IDEAL
|
||||
gas_gamma = gamma
|
||||
gas_e0 = e0
|
||||
gas_p0 = p0
|
||||
gas_eos_defined = .true.
|
||||
end subroutine sph_gas_set_ideal
|
||||
|
||||
subroutine sph_gas_set_jwl(material_name_in, rho0, a_value, b_value, r1, r2, &
|
||||
omega, e0, ierr)
|
||||
character(len=*), intent(in) :: material_name_in
|
||||
real(rk), intent(in) :: rho0
|
||||
real(rk), intent(in) :: a_value
|
||||
real(rk), intent(in) :: b_value
|
||||
real(rk), intent(in) :: r1
|
||||
real(rk), intent(in) :: r2
|
||||
real(rk), intent(in) :: omega
|
||||
real(rk), intent(in) :: e0
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
if (rho0 <= 0.0_rk .or. r1 <= 0.0_rk .or. r2 <= 0.0_rk .or. &
|
||||
omega <= 0.0_rk .or. e0 < 0.0_rk .or. a_value < 0.0_rk .or. &
|
||||
b_value < 0.0_rk) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'JWL gas EOS parameters are invalid')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
gas_material_seen = .true.
|
||||
gas_material_name = material_name_in
|
||||
gas_material_internal_id = sph_gas_find_material(material_name_in)
|
||||
gas_eos_type = GAS_EOS_JWL
|
||||
gas_rho0 = rho0
|
||||
gas_jwl_a = a_value
|
||||
gas_jwl_b = b_value
|
||||
gas_jwl_r1 = r1
|
||||
gas_jwl_r2 = r2
|
||||
gas_jwl_omega = omega
|
||||
gas_e0 = e0
|
||||
gas_eos_defined = .true.
|
||||
end subroutine sph_gas_set_jwl
|
||||
|
||||
subroutine sph_gas_set_stiffened(material_name_in, rho0, gamma, e0, pinf, ierr)
|
||||
character(len=*), intent(in) :: material_name_in
|
||||
real(rk), intent(in) :: rho0
|
||||
real(rk), intent(in) :: gamma
|
||||
real(rk), intent(in) :: e0
|
||||
real(rk), intent(in) :: pinf
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
if (rho0 <= 0.0_rk .or. gamma <= 1.0_rk .or. e0 < 0.0_rk .or. &
|
||||
pinf < 0.0_rk) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'Stiffened gas EOS parameters are invalid')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
gas_material_seen = .true.
|
||||
gas_material_name = material_name_in
|
||||
gas_material_internal_id = sph_gas_find_material(material_name_in)
|
||||
gas_eos_type = GAS_EOS_STIFFENED
|
||||
gas_rho0 = rho0
|
||||
gas_gamma = gamma
|
||||
gas_e0 = e0
|
||||
gas_pinf = pinf
|
||||
gas_eos_defined = .true.
|
||||
end subroutine sph_gas_set_stiffened
|
||||
|
||||
subroutine sph_gas_set_particle_control(h_value, mass_value, volume_value, ierr)
|
||||
real(rk), intent(in) :: h_value
|
||||
real(rk), intent(in) :: mass_value
|
||||
real(rk), intent(in) :: volume_value
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
if (h_value <= 0.0_rk .or. mass_value <= 0.0_rk .or. volume_value <= 0.0_rk) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'Gas particle control values must be positive')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
gas_default_h = h_value
|
||||
gas_default_mass = mass_value
|
||||
gas_default_volume = volume_value
|
||||
gas_particle_control_defined = .true.
|
||||
end subroutine sph_gas_set_particle_control
|
||||
|
||||
subroutine sph_gas_set_body_force(force, ierr)
|
||||
real(rk), intent(in) :: force(SPH_NDIM)
|
||||
integer, intent(out) :: ierr
|
||||
integer :: i
|
||||
|
||||
gas_body_force = force
|
||||
do i = 1, npart
|
||||
if (sph_gas_is_active_particle(i)) acc_body(:,i) = force
|
||||
end do
|
||||
ierr = SPH_SUCCESS
|
||||
end subroutine sph_gas_set_body_force
|
||||
|
||||
subroutine sph_gas_validate_input(ierr)
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
if (.not. gas_material_seen) return
|
||||
if (.not. gas_eos_defined) then
|
||||
call sph_error_set(SPH_ERROR_INPUT, 'input is missing *SPHLITE EOS for Gas')
|
||||
ierr = SPH_ERROR_INPUT
|
||||
return
|
||||
end if
|
||||
if (.not. sph_gas_has_material_density()) then
|
||||
call sph_error_set(SPH_ERROR_INPUT, 'input is missing *DENSITY for Gas material')
|
||||
ierr = SPH_ERROR_INPUT
|
||||
return
|
||||
end if
|
||||
if (.not. sph_gas_has_section_binding()) then
|
||||
call sph_error_set(SPH_ERROR_INPUT, 'input is missing Gas section binding')
|
||||
ierr = SPH_ERROR_INPUT
|
||||
end if
|
||||
end subroutine sph_gas_validate_input
|
||||
|
||||
logical function sph_gas_has_material_density()
|
||||
integer :: i
|
||||
|
||||
sph_gas_has_material_density = .false.
|
||||
do i = 1, material_count
|
||||
if (trim(sph_gas_upper(material_name(i))) == trim(sph_gas_upper(gas_material_name))) then
|
||||
sph_gas_has_material_density = material_density(i) > 0.0_rk
|
||||
return
|
||||
end if
|
||||
end do
|
||||
end function sph_gas_has_material_density
|
||||
|
||||
logical function sph_gas_has_section_binding()
|
||||
integer :: i
|
||||
|
||||
sph_gas_has_section_binding = .false.
|
||||
do i = 1, section_count
|
||||
if (section_material_id(i) == gas_material_internal_id) then
|
||||
sph_gas_has_section_binding = .true.
|
||||
return
|
||||
end if
|
||||
end do
|
||||
end function sph_gas_has_section_binding
|
||||
|
||||
subroutine sph_gas_apply_initial_conditions(ierr)
|
||||
integer, intent(out) :: ierr
|
||||
integer :: i
|
||||
real(rk) :: density_value
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
if (.not. gas_material_seen) return
|
||||
call sph_gas_validate_input(ierr)
|
||||
if (ierr /= SPH_SUCCESS) return
|
||||
density_value = sph_gas_material_density(gas_material_name)
|
||||
do i = 1, npart
|
||||
if (particle_status(i) /= SPH_STATUS_ACTIVE) cycle
|
||||
if (.not. sph_gas_is_material_particle(i)) cycle
|
||||
particle_phase(i) = SPH_PHASE_GAS
|
||||
rho(i) = density_value
|
||||
internal_energy(i) = gas_e0
|
||||
temperature(i) = 293.15_rk
|
||||
mass(i) = gas_default_mass
|
||||
volume(i) = gas_default_volume
|
||||
h(i) = gas_default_h
|
||||
acc_body(:,i) = gas_body_force
|
||||
call sph_gas_compute_pressure(rho(i), internal_energy(i), pressure(i), ierr)
|
||||
if (ierr /= SPH_SUCCESS) return
|
||||
end do
|
||||
call sph_gas_update_diagnostics(ierr)
|
||||
end subroutine sph_gas_apply_initial_conditions
|
||||
|
||||
subroutine sph_gas_compute_pressure(rho_value, energy_value, pressure_value, ierr)
|
||||
real(rk), intent(in) :: rho_value
|
||||
real(rk), intent(in) :: energy_value
|
||||
real(rk), intent(out) :: pressure_value
|
||||
integer, intent(out) :: ierr
|
||||
real(rk) :: relative_volume
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
pressure_value = 0.0_rk
|
||||
if (rho_value <= 0.0_rk) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'Gas density must be positive')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
if (energy_value < 0.0_rk) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'Gas internal energy must be non-negative')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
if (gas_eos_type == GAS_EOS_IDEAL) then
|
||||
pressure_value = (gas_gamma - 1.0_rk) * rho_value * energy_value + gas_p0
|
||||
else if (gas_eos_type == GAS_EOS_JWL) then
|
||||
if (gas_rho0 <= 0.0_rk) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'JWL gas reference density must be positive')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
relative_volume = gas_rho0 / rho_value
|
||||
pressure_value = gas_jwl_a * exp(-gas_jwl_r1 * relative_volume) + &
|
||||
gas_jwl_b * exp(-gas_jwl_r2 * relative_volume) + &
|
||||
gas_jwl_omega * energy_value / relative_volume
|
||||
else if (gas_eos_type == GAS_EOS_STIFFENED) then
|
||||
pressure_value = (gas_gamma - 1.0_rk) * rho_value * energy_value - &
|
||||
gas_gamma * gas_pinf
|
||||
else
|
||||
call sph_error_set(SPH_ERROR_INPUT, 'Gas EOS is not defined')
|
||||
ierr = SPH_ERROR_INPUT
|
||||
return
|
||||
end if
|
||||
if (.not. sph_gas_is_finite(pressure_value)) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'Gas pressure is not finite')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
end if
|
||||
end subroutine sph_gas_compute_pressure
|
||||
|
||||
subroutine sph_gas_update_pressure(ierr)
|
||||
integer, intent(out) :: ierr
|
||||
integer :: i
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
do i = 1, npart
|
||||
if (.not. sph_gas_is_active_particle(i)) cycle
|
||||
call sph_gas_compute_pressure(rho(i), internal_energy(i), pressure(i), ierr)
|
||||
if (ierr /= SPH_SUCCESS) return
|
||||
end do
|
||||
end subroutine sph_gas_update_pressure
|
||||
|
||||
subroutine sph_gas_compute_density_rate(ierr)
|
||||
integer, intent(out) :: ierr
|
||||
integer :: i
|
||||
integer :: n
|
||||
integer :: j
|
||||
integer :: index
|
||||
real(rk) :: grad_w(SPH_NDIM)
|
||||
real(rk) :: rij(SPH_NDIM)
|
||||
real(rk) :: vij(SPH_NDIM)
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
if (npart <= 0) return
|
||||
drho_dt = 0.0_rk
|
||||
do i = 1, npart
|
||||
if (.not. sph_gas_is_active_particle(i)) cycle
|
||||
do n = 1, neighbor_count(i)
|
||||
index = neighbor_offset(i) + n - 1
|
||||
j = neighbor_list(index)
|
||||
if (.not. sph_gas_is_active_particle(j)) cycle
|
||||
rij = x(:,i) - x(:,j)
|
||||
vij = v(:,i) - v(:,j)
|
||||
call sph_kernel_gradient(SPH_KERNEL_DEFAULT, rij, h(i), grad_w, ierr)
|
||||
if (ierr /= SPH_SUCCESS) return
|
||||
drho_dt(i) = drho_dt(i) + mass(j) * sum(vij * grad_w)
|
||||
end do
|
||||
end do
|
||||
end subroutine sph_gas_compute_density_rate
|
||||
|
||||
subroutine sph_gas_compute_pressure_acceleration(ierr)
|
||||
integer, intent(out) :: ierr
|
||||
integer :: i
|
||||
integer :: n
|
||||
integer :: j
|
||||
integer :: index
|
||||
real(rk) :: grad_w(SPH_NDIM)
|
||||
real(rk) :: rij(SPH_NDIM)
|
||||
real(rk) :: pressure_term
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
if (npart <= 0) return
|
||||
acc_pressure = 0.0_rk
|
||||
do i = 1, npart
|
||||
if (.not. sph_gas_is_active_particle(i)) cycle
|
||||
if (rho(i) <= 0.0_rk) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'Gas density must be positive for pressure force')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
do n = 1, neighbor_count(i)
|
||||
index = neighbor_offset(i) + n - 1
|
||||
j = neighbor_list(index)
|
||||
if (.not. sph_gas_is_active_particle(j)) cycle
|
||||
if (rho(j) <= 0.0_rk) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'Gas neighbor density must be positive')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
rij = x(:,i) - x(:,j)
|
||||
call sph_kernel_gradient(SPH_KERNEL_DEFAULT, rij, h(i), grad_w, ierr)
|
||||
if (ierr /= SPH_SUCCESS) return
|
||||
pressure_term = pressure(i) / (rho(i) * rho(i)) + pressure(j) / (rho(j) * rho(j))
|
||||
acc_pressure(:,i) = acc_pressure(:,i) - mass(j) * pressure_term * grad_w
|
||||
end do
|
||||
end do
|
||||
end subroutine sph_gas_compute_pressure_acceleration
|
||||
|
||||
subroutine sph_gas_compute_acceleration(ierr)
|
||||
integer, intent(out) :: ierr
|
||||
integer :: i
|
||||
|
||||
call sph_gas_compute_pressure_acceleration(ierr)
|
||||
if (ierr /= SPH_SUCCESS) return
|
||||
do i = 1, npart
|
||||
if (sph_gas_is_active_particle(i)) a(:,i) = acc_pressure(:,i) + acc_body(:,i)
|
||||
end do
|
||||
ierr = SPH_SUCCESS
|
||||
end subroutine sph_gas_compute_acceleration
|
||||
|
||||
subroutine sph_gas_update_diagnostics(ierr)
|
||||
integer, intent(out) :: ierr
|
||||
integer :: i
|
||||
logical :: first_gas
|
||||
real(rk) :: pressure_integral
|
||||
real(rk) :: current_center(SPH_NDIM)
|
||||
real(rk) :: pi_value
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
current_center = gas_center
|
||||
call sph_db_clear_gas_diagnostics()
|
||||
first_gas = .true.
|
||||
pressure_integral = 0.0_rk
|
||||
do i = 1, npart
|
||||
if (.not. sph_gas_is_active_particle(i)) cycle
|
||||
if (volume(i) <= 0.0_rk) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'Gas volume must be positive')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
gas_particle_count = gas_particle_count + 1
|
||||
gas_mass = gas_mass + mass(i)
|
||||
gas_volume = gas_volume + volume(i)
|
||||
gas_momentum = gas_momentum + mass(i) * v(:,i)
|
||||
gas_center = gas_center + volume(i) * x(:,i)
|
||||
pressure_integral = pressure_integral + volume(i) * pressure(i)
|
||||
if (first_gas) then
|
||||
gas_max_pressure = pressure(i)
|
||||
gas_min_density = rho(i)
|
||||
gas_max_density = rho(i)
|
||||
first_gas = .false.
|
||||
else
|
||||
if (pressure(i) > gas_max_pressure) gas_max_pressure = pressure(i)
|
||||
if (rho(i) < gas_min_density) gas_min_density = rho(i)
|
||||
if (rho(i) > gas_max_density) gas_max_density = rho(i)
|
||||
end if
|
||||
end do
|
||||
if (gas_volume > 0.0_rk) then
|
||||
gas_center = gas_center / gas_volume
|
||||
gas_mean_pressure = pressure_integral / gas_volume
|
||||
pi_value = acos(-1.0_rk)
|
||||
gas_equivalent_radius = (3.0_rk * gas_volume / (4.0_rk * pi_value))**(1.0_rk / 3.0_rk)
|
||||
end if
|
||||
if (gas_bubble_history_valid) then
|
||||
gas_radius_rate = gas_equivalent_radius - gas_previous_equivalent_radius
|
||||
gas_center_shift = sqrt(sum((gas_center - gas_previous_center) * &
|
||||
(gas_center - gas_previous_center)))
|
||||
else
|
||||
gas_radius_rate = 0.0_rk
|
||||
gas_center_shift = 0.0_rk
|
||||
end if
|
||||
gas_previous_equivalent_radius = gas_equivalent_radius
|
||||
gas_previous_center = gas_center
|
||||
gas_bubble_history_valid = gas_particle_count > 0
|
||||
current_center = current_center
|
||||
end subroutine sph_gas_update_diagnostics
|
||||
|
||||
subroutine sph_gas_estimate_dt_limits(dt_cfl, dt_accel, dt_limit, ierr)
|
||||
real(rk), intent(out) :: dt_cfl
|
||||
real(rk), intent(out) :: dt_accel
|
||||
real(rk), intent(out) :: dt_limit
|
||||
integer, intent(out) :: ierr
|
||||
integer :: i
|
||||
real(rk) :: speed
|
||||
real(rk) :: sound_speed
|
||||
real(rk) :: accel_norm
|
||||
real(rk) :: local_dt
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
dt_cfl = huge(1.0_rk)
|
||||
dt_accel = huge(1.0_rk)
|
||||
do i = 1, npart
|
||||
if (.not. sph_gas_is_active_particle(i)) cycle
|
||||
if (h(i) <= 0.0_rk .or. rho(i) <= 0.0_rk) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'invalid Gas state for dt estimate')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
sound_speed = sph_gas_sound_speed(i)
|
||||
speed = sqrt(sum(v(:,i) * v(:,i)))
|
||||
local_dt = h(i) / (sound_speed + speed)
|
||||
if (local_dt < dt_cfl) dt_cfl = local_dt
|
||||
accel_norm = sqrt(sum(a(:,i) * a(:,i)))
|
||||
if (accel_norm > 0.0_rk) then
|
||||
local_dt = sqrt(h(i) / accel_norm)
|
||||
if (local_dt < dt_accel) dt_accel = local_dt
|
||||
end if
|
||||
end do
|
||||
if (dt_cfl == huge(1.0_rk)) dt_cfl = 0.0_rk
|
||||
if (dt_accel == huge(1.0_rk)) dt_accel = dt_cfl
|
||||
dt_limit = dt_cfl
|
||||
if (dt_accel > 0.0_rk .and. dt_accel < dt_limit) dt_limit = dt_accel
|
||||
gas_dt_cfl = dt_cfl
|
||||
gas_dt_accel = dt_accel
|
||||
gas_dtcrit = dt_limit
|
||||
end subroutine sph_gas_estimate_dt_limits
|
||||
|
||||
real(rk) function sph_gas_sound_speed(i)
|
||||
integer, intent(in) :: i
|
||||
real(rk) :: pressure_scale
|
||||
|
||||
pressure_scale = abs(pressure(i)) + abs(gas_pinf) + 1.0_rk
|
||||
sph_gas_sound_speed = sqrt(max(pressure_scale / rho(i), 1.0e-12_rk))
|
||||
end function sph_gas_sound_speed
|
||||
|
||||
logical function sph_gas_is_active_particle(i)
|
||||
integer, intent(in) :: i
|
||||
|
||||
sph_gas_is_active_particle = .false.
|
||||
if (i < 1 .or. i > npart) return
|
||||
if (particle_phase(i) /= SPH_PHASE_GAS) return
|
||||
if (particle_status(i) /= SPH_STATUS_ACTIVE) return
|
||||
sph_gas_is_active_particle = .true.
|
||||
end function sph_gas_is_active_particle
|
||||
|
||||
logical function sph_gas_is_material_particle(i)
|
||||
integer, intent(in) :: i
|
||||
integer :: mat_index
|
||||
|
||||
sph_gas_is_material_particle = .false.
|
||||
if (i < 1 .or. i > npart) return
|
||||
mat_index = material_id(i)
|
||||
if (mat_index < 1 .or. mat_index > material_count) return
|
||||
if (index(sph_gas_upper(material_type(mat_index)), 'GAS') <= 0) return
|
||||
sph_gas_is_material_particle = .true.
|
||||
end function sph_gas_is_material_particle
|
||||
|
||||
integer function sph_gas_find_material(name)
|
||||
character(len=*), intent(in) :: name
|
||||
integer :: i
|
||||
|
||||
sph_gas_find_material = 0
|
||||
do i = 1, material_count
|
||||
if (trim(sph_gas_upper(material_name(i))) == trim(sph_gas_upper(name))) then
|
||||
sph_gas_find_material = i
|
||||
return
|
||||
end if
|
||||
end do
|
||||
end function sph_gas_find_material
|
||||
|
||||
real(rk) function sph_gas_material_density(name)
|
||||
character(len=*), intent(in) :: name
|
||||
integer :: i
|
||||
|
||||
sph_gas_material_density = gas_rho0
|
||||
do i = 1, material_count
|
||||
if (trim(sph_gas_upper(material_name(i))) == trim(sph_gas_upper(name))) then
|
||||
if (material_density(i) > 0.0_rk) sph_gas_material_density = material_density(i)
|
||||
return
|
||||
end if
|
||||
end do
|
||||
end function sph_gas_material_density
|
||||
|
||||
logical function sph_gas_is_finite(value)
|
||||
real(rk), intent(in) :: value
|
||||
|
||||
sph_gas_is_finite = value == value .and. abs(value) < huge(value)
|
||||
end function sph_gas_is_finite
|
||||
|
||||
function sph_gas_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_gas_upper
|
||||
|
||||
end module sph_gas
|
||||
|
||||
Reference in New Issue
Block a user