Add Gas material EOS table

This commit is contained in:
Codex
2026-07-03 10:40:57 +08:00
parent d9f21a8256
commit 0eaa85196e
5 changed files with 332 additions and 57 deletions
+281 -36
View File
@@ -2,8 +2,9 @@ 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, &
use sph_database, only: npart, SPH_MAX_MATERIALS, 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, &
@@ -42,6 +43,26 @@ module sph_gas
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
integer :: gas_material_count = 0
integer :: gas_material_ids(SPH_MAX_MATERIALS) = 0
character(len=64) :: gas_material_names(SPH_MAX_MATERIALS) = ' '
logical :: gas_material_eos_defined(SPH_MAX_MATERIALS) = .false.
integer :: gas_material_eos_type(SPH_MAX_MATERIALS) = GAS_EOS_NONE
real(rk) :: gas_material_density_default(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: gas_material_energy_default(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: gas_material_temperature_default(SPH_MAX_MATERIALS) = 293.15_rk
real(rk) :: gas_material_rho0(SPH_MAX_MATERIALS) = 1.0_rk
real(rk) :: gas_material_gamma(SPH_MAX_MATERIALS) = 1.4_rk
real(rk) :: gas_material_p0(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: gas_material_jwl_a(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: gas_material_jwl_b(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: gas_material_jwl_r1(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: gas_material_jwl_r2(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: gas_material_jwl_omega(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: gas_material_pinf(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: gas_material_default_h(SPH_MAX_MATERIALS) = 1.0_rk
real(rk) :: gas_material_default_mass(SPH_MAX_MATERIALS) = 1.0_rk
real(rk) :: gas_material_default_volume(SPH_MAX_MATERIALS) = 1.0_rk
contains
@@ -77,6 +98,26 @@ contains
gas_default_mass = 1.0_rk
gas_default_volume = 1.0_rk
gas_body_force = 0.0_rk
gas_material_count = 0
gas_material_ids = 0
gas_material_names = ' '
gas_material_eos_defined = .false.
gas_material_eos_type = GAS_EOS_NONE
gas_material_density_default = 0.0_rk
gas_material_energy_default = 0.0_rk
gas_material_temperature_default = 293.15_rk
gas_material_rho0 = 1.0_rk
gas_material_gamma = 1.4_rk
gas_material_p0 = 0.0_rk
gas_material_jwl_a = 0.0_rk
gas_material_jwl_b = 0.0_rk
gas_material_jwl_r1 = 0.0_rk
gas_material_jwl_r2 = 0.0_rk
gas_material_jwl_omega = 0.0_rk
gas_material_pinf = 0.0_rk
gas_material_default_h = 1.0_rk
gas_material_default_mass = 1.0_rk
gas_material_default_volume = 1.0_rk
gas_previous_equivalent_radius = 0.0_rk
gas_previous_center = 0.0_rk
call sph_db_clear_gas_diagnostics()
@@ -85,11 +126,13 @@ contains
subroutine sph_gas_note_material(name, material_type_in)
character(len=*), intent(in) :: name
character(len=*), intent(in) :: material_type_in
integer :: gas_index
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)
gas_index = sph_gas_register_material(name)
end if
end subroutine sph_gas_note_material
@@ -122,12 +165,6 @@ contains
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
@@ -147,6 +184,7 @@ contains
real(rk), intent(in) :: e0
real(rk), intent(in) :: p0
integer, intent(out) :: ierr
integer :: gas_index
ierr = SPH_SUCCESS
if (gamma <= 1.0_rk) then
@@ -159,6 +197,8 @@ contains
ierr = SPH_ERROR_ARGUMENT
return
end if
call sph_gas_prepare_eos_material(material_name_in, gas_index, ierr)
if (ierr /= SPH_SUCCESS) return
gas_material_seen = .true.
gas_material_name = material_name_in
gas_material_internal_id = sph_gas_find_material(material_name_in)
@@ -167,6 +207,13 @@ contains
gas_e0 = e0
gas_p0 = p0
gas_eos_defined = .true.
gas_material_eos_type(gas_index) = GAS_EOS_IDEAL
gas_material_eos_defined(gas_index) = .true.
gas_material_gamma(gas_index) = gamma
gas_material_energy_default(gas_index) = e0
gas_material_p0(gas_index) = p0
gas_material_rho0(gas_index) = sph_gas_material_density(material_name_in)
gas_material_density_default(gas_index) = sph_gas_material_density(material_name_in)
end subroutine sph_gas_set_ideal
subroutine sph_gas_set_jwl(material_name_in, rho0, a_value, b_value, r1, r2, &
@@ -180,6 +227,7 @@ contains
real(rk), intent(in) :: omega
real(rk), intent(in) :: e0
integer, intent(out) :: ierr
integer :: gas_index
ierr = SPH_SUCCESS
if (rho0 <= 0.0_rk .or. r1 <= 0.0_rk .or. r2 <= 0.0_rk .or. &
@@ -189,6 +237,8 @@ contains
ierr = SPH_ERROR_ARGUMENT
return
end if
call sph_gas_prepare_eos_material(material_name_in, gas_index, ierr)
if (ierr /= SPH_SUCCESS) return
gas_material_seen = .true.
gas_material_name = material_name_in
gas_material_internal_id = sph_gas_find_material(material_name_in)
@@ -201,6 +251,16 @@ contains
gas_jwl_omega = omega
gas_e0 = e0
gas_eos_defined = .true.
gas_material_eos_type(gas_index) = GAS_EOS_JWL
gas_material_eos_defined(gas_index) = .true.
gas_material_rho0(gas_index) = rho0
gas_material_jwl_a(gas_index) = a_value
gas_material_jwl_b(gas_index) = b_value
gas_material_jwl_r1(gas_index) = r1
gas_material_jwl_r2(gas_index) = r2
gas_material_jwl_omega(gas_index) = omega
gas_material_energy_default(gas_index) = e0
gas_material_density_default(gas_index) = sph_gas_material_density(material_name_in)
end subroutine sph_gas_set_jwl
subroutine sph_gas_set_stiffened(material_name_in, rho0, gamma, e0, pinf, ierr)
@@ -210,6 +270,7 @@ contains
real(rk), intent(in) :: e0
real(rk), intent(in) :: pinf
integer, intent(out) :: ierr
integer :: gas_index
ierr = SPH_SUCCESS
if (rho0 <= 0.0_rk .or. gamma <= 1.0_rk .or. e0 < 0.0_rk .or. &
@@ -218,6 +279,8 @@ contains
ierr = SPH_ERROR_ARGUMENT
return
end if
call sph_gas_prepare_eos_material(material_name_in, gas_index, ierr)
if (ierr /= SPH_SUCCESS) return
gas_material_seen = .true.
gas_material_name = material_name_in
gas_material_internal_id = sph_gas_find_material(material_name_in)
@@ -227,6 +290,13 @@ contains
gas_e0 = e0
gas_pinf = pinf
gas_eos_defined = .true.
gas_material_eos_type(gas_index) = GAS_EOS_STIFFENED
gas_material_eos_defined(gas_index) = .true.
gas_material_rho0(gas_index) = rho0
gas_material_gamma(gas_index) = gamma
gas_material_energy_default(gas_index) = e0
gas_material_pinf(gas_index) = pinf
gas_material_density_default(gas_index) = sph_gas_material_density(material_name_in)
end subroutine sph_gas_set_stiffened
subroutine sph_gas_set_particle_control(h_value, mass_value, volume_value, ierr)
@@ -244,6 +314,11 @@ contains
gas_default_h = h_value
gas_default_mass = mass_value
gas_default_volume = volume_value
if (gas_material_count > 0) then
gas_material_default_h(1:gas_material_count) = h_value
gas_material_default_mass(1:gas_material_count) = mass_value
gas_material_default_volume(1:gas_material_count) = volume_value
end if
gas_particle_control_defined = .true.
end subroutine sph_gas_set_particle_control
@@ -261,23 +336,29 @@ contains
subroutine sph_gas_validate_input(ierr)
integer, intent(out) :: ierr
integer :: gas_index
integer :: mat_index
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
do gas_index = 1, gas_material_count
mat_index = gas_material_ids(gas_index)
if (.not. gas_material_eos_defined(gas_index)) then
call sph_error_set(SPH_ERROR_INPUT, 'input is missing *SPHLITE EOS for Gas')
ierr = SPH_ERROR_INPUT
return
end if
if (mat_index < 1 .or. mat_index > material_count) then
call sph_error_set(SPH_ERROR_INPUT, 'Gas 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 Gas material')
ierr = SPH_ERROR_INPUT
return
end if
end do
end subroutine sph_gas_validate_input
logical function sph_gas_has_material_density()
@@ -292,40 +373,52 @@ contains
end do
end function sph_gas_has_material_density
logical function sph_gas_has_section_binding()
logical function sph_gas_has_section_binding_for_id(mat_id)
integer, intent(in) :: mat_id
integer :: i
sph_gas_has_section_binding = .false.
sph_gas_has_section_binding_for_id = .false.
do i = 1, section_count
if (section_material_id(i) == gas_material_internal_id) then
sph_gas_has_section_binding = .true.
if (section_material_id(i) == mat_id) then
sph_gas_has_section_binding_for_id = .true.
return
end if
end do
end function sph_gas_has_section_binding
end function sph_gas_has_section_binding_for_id
subroutine sph_gas_apply_initial_conditions(ierr)
integer, intent(out) :: ierr
integer :: i
integer :: gas_index
integer :: mat_index
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
mat_index = material_id(i)
gas_index = sph_gas_table_index_by_material_id(mat_index)
if (gas_index <= 0) then
call sph_error_set(SPH_ERROR_INPUT, 'Gas particle material has no EOS')
ierr = SPH_ERROR_INPUT
return
end if
density_value = material_density(mat_index)
if (density_value <= 0.0_rk) density_value = gas_material_density_default(gas_index)
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
internal_energy(i) = gas_material_energy_default(gas_index)
temperature(i) = gas_material_temperature_default(gas_index)
mass(i) = gas_material_default_mass(gas_index)
volume(i) = gas_material_default_volume(gas_index)
h(i) = gas_material_default_h(gas_index)
acc_body(:,i) = gas_body_force
call sph_gas_compute_pressure(rho(i), internal_energy(i), pressure(i), ierr)
call sph_gas_compute_pressure_for_material(mat_index, rho(i), &
internal_energy(i), pressure(i), ierr)
if (ierr /= SPH_SUCCESS) return
end do
call sph_gas_update_diagnostics(ierr)
@@ -376,6 +469,64 @@ contains
end if
end subroutine sph_gas_compute_pressure
subroutine sph_gas_compute_pressure_for_material(mat_index, rho_value, &
energy_value, pressure_value, ierr)
integer, intent(in) :: mat_index
real(rk), intent(in) :: rho_value
real(rk), intent(in) :: energy_value
real(rk), intent(out) :: pressure_value
integer, intent(out) :: ierr
integer :: gas_index
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
gas_index = sph_gas_table_index_by_material_id(mat_index)
if (gas_index <= 0 .or. .not. gas_material_eos_defined(gas_index)) then
call sph_error_set(SPH_ERROR_INPUT, 'Gas particle material has no EOS')
ierr = SPH_ERROR_INPUT
return
end if
if (gas_material_eos_type(gas_index) == GAS_EOS_IDEAL) then
pressure_value = (gas_material_gamma(gas_index) - 1.0_rk) * &
rho_value * energy_value + gas_material_p0(gas_index)
else if (gas_material_eos_type(gas_index) == GAS_EOS_JWL) then
if (gas_material_rho0(gas_index) <= 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_material_rho0(gas_index) / rho_value
pressure_value = gas_material_jwl_a(gas_index) * &
exp(-gas_material_jwl_r1(gas_index) * relative_volume) + &
gas_material_jwl_b(gas_index) * &
exp(-gas_material_jwl_r2(gas_index) * relative_volume) + &
gas_material_jwl_omega(gas_index) * energy_value / relative_volume
else if (gas_material_eos_type(gas_index) == GAS_EOS_STIFFENED) then
pressure_value = (gas_material_gamma(gas_index) - 1.0_rk) * &
rho_value * energy_value - &
gas_material_gamma(gas_index) * gas_material_pinf(gas_index)
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_for_material
subroutine sph_gas_update_pressure(ierr)
integer, intent(out) :: ierr
integer :: i
@@ -383,7 +534,8 @@ contains
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)
call sph_gas_compute_pressure_for_material(material_id(i), rho(i), &
internal_energy(i), pressure(i), ierr)
if (ierr /= SPH_SUCCESS) return
end do
end subroutine sph_gas_update_pressure
@@ -596,9 +748,15 @@ contains
real(rk) function sph_gas_sound_speed(i)
integer, intent(in) :: i
integer :: gas_index
real(rk) :: pressure_scale
pressure_scale = abs(pressure(i)) + abs(gas_pinf) + 1.0_rk
gas_index = sph_gas_table_index_by_material_id(material_id(i))
if (gas_index > 0) then
pressure_scale = abs(pressure(i)) + abs(gas_material_pinf(gas_index)) + 1.0_rk
else
pressure_scale = abs(pressure(i)) + abs(gas_pinf) + 1.0_rk
end if
sph_gas_sound_speed = sqrt(max(pressure_scale / rho(i), 1.0e-12_rk))
end function sph_gas_sound_speed
@@ -650,6 +808,93 @@ contains
end do
end function sph_gas_material_density
subroutine sph_gas_prepare_eos_material(name, gas_index, ierr)
character(len=*), intent(in) :: name
integer, intent(out) :: gas_index
integer, intent(out) :: ierr
integer :: mat_index
ierr = SPH_SUCCESS
gas_index = 0
mat_index = sph_gas_find_material(name)
if (mat_index <= 0) then
call sph_error_set(SPH_ERROR_INPUT, 'Gas EOS references unknown material')
ierr = SPH_ERROR_INPUT
return
end if
if (index(sph_gas_upper(material_type(mat_index)), 'GAS') <= 0) then
call sph_error_set(SPH_ERROR_INPUT, 'Gas EOS references non-Gas material')
ierr = SPH_ERROR_INPUT
return
end if
gas_index = sph_gas_register_material(name)
if (gas_index <= 0) then
call sph_error_set(SPH_ERROR_INPUT, 'too many Gas material records')
ierr = SPH_ERROR_INPUT
return
end if
if (gas_material_eos_defined(gas_index)) then
call sph_error_set(SPH_ERROR_INPUT, 'Gas material EOS is already defined')
ierr = SPH_ERROR_INPUT
end if
end subroutine sph_gas_prepare_eos_material
integer function sph_gas_register_material(name)
character(len=*), intent(in) :: name
integer :: mat_index
integer :: gas_index
sph_gas_register_material = 0
mat_index = sph_gas_find_material(name)
if (mat_index <= 0) return
gas_index = sph_gas_table_index_by_material_id(mat_index)
if (gas_index > 0) then
sph_gas_register_material = gas_index
return
end if
if (gas_material_count >= SPH_MAX_MATERIALS) return
gas_material_count = gas_material_count + 1
gas_material_ids(gas_material_count) = mat_index
gas_material_names(gas_material_count) = material_name(mat_index)
gas_material_eos_defined(gas_material_count) = .false.
gas_material_eos_type(gas_material_count) = GAS_EOS_NONE
gas_material_density_default(gas_material_count) = material_density(mat_index)
gas_material_energy_default(gas_material_count) = gas_e0
gas_material_temperature_default(gas_material_count) = 293.15_rk
gas_material_rho0(gas_material_count) = gas_rho0
gas_material_gamma(gas_material_count) = gas_gamma
gas_material_p0(gas_material_count) = gas_p0
gas_material_default_h(gas_material_count) = gas_default_h
gas_material_default_mass(gas_material_count) = gas_default_mass
gas_material_default_volume(gas_material_count) = gas_default_volume
sph_gas_register_material = gas_material_count
end function sph_gas_register_material
integer function sph_gas_table_index_by_material_id(mat_index)
integer, intent(in) :: mat_index
integer :: i
sph_gas_table_index_by_material_id = 0
do i = 1, gas_material_count
if (gas_material_ids(i) == mat_index) then
sph_gas_table_index_by_material_id = i
return
end if
end do
end function sph_gas_table_index_by_material_id
subroutine sph_gas_count_unbound_materials(count)
integer, intent(out) :: count
integer :: i
count = 0
do i = 1, gas_material_count
if (.not. sph_gas_has_section_binding_for_id(gas_material_ids(i))) then
count = count + 1
end if
end do
end subroutine sph_gas_count_unbound_materials
logical function sph_gas_is_finite(value)
real(rk), intent(in) :: value
+4 -1
View File
@@ -15,7 +15,7 @@ module sph_input_reader
sph_water_set_body_force, sph_water_apply_initial_conditions
use sph_gas, only: sph_gas_note_material, sph_gas_set_eos, &
sph_gas_set_particle_control, sph_gas_set_body_force, &
sph_gas_apply_initial_conditions
sph_gas_apply_initial_conditions, sph_gas_count_unbound_materials
use sph_neighbor, only: sph_neighbor_rebuild
use sph_inp_defs, only: SPH_INPUT_LINE_LEN, SPH_INPUT_FIELD_LEN, &
SPH_INPUT_MAX_FIELDS, SPH_KEY_NODE, SPH_KEY_ELEMENT, SPH_KEY_NSET, &
@@ -74,6 +74,7 @@ contains
subroutine sph_input_build_model(ierr)
integer, intent(out) :: ierr
integer :: gas_unbound_count
ierr = SPH_SUCCESS
if (npart <= 0) then
@@ -102,6 +103,8 @@ contains
if (ierr /= SPH_SUCCESS) return
call sph_gas_apply_initial_conditions(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_gas_count_unbound_materials(gas_unbound_count)
input_warning_count = input_warning_count + gas_unbound_count
call sph_neighbor_rebuild(ierr)
end subroutine sph_input_build_model