Add Gas input parsing and state

This commit is contained in:
Codex
2026-07-03 09:19:28 +08:00
parent 44c0a1e144
commit ffbcad2c44
7 changed files with 1087 additions and 36 deletions
+110 -7
View File
@@ -8,11 +8,14 @@ module sph_input_reader
SPH_REGION_COUPLING_CONTACT, SPH_REGION_COUPLING_CONTINUUM, &
sph_db_allocate, sph_db_free, sph_db_set_node, sph_db_add_material, &
sph_db_add_section, sph_db_add_nset, sph_db_add_elset, &
sph_db_add_element, sph_db_add_coupling_region
sph_db_add_element, sph_db_add_coupling_region, sph_db_apply_sections_to_particles
use sph_database, only: sph_db_set_material_density
use sph_water, only: sph_water_note_material, sph_water_set_eos, &
sph_water_set_viscosity, sph_water_set_particle_control, &
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
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, &
@@ -93,8 +96,12 @@ contains
ierr = SPH_ERROR_INPUT
return
end if
call sph_db_apply_sections_to_particles(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_water_apply_initial_conditions(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_gas_apply_initial_conditions(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_neighbor_rebuild(ierr)
end subroutine sph_input_build_model
@@ -246,6 +253,7 @@ contains
if (len_trim(type_value) == 0) type_value = 'UNSPECIFIED'
call sph_db_add_material(value, type_value, ierr)
call sph_water_note_material(value, type_value)
call sph_gas_note_material(value, type_value)
else if (key_id == SPH_KEY_SECTION) then
input_has_section = .true.
call sph_input_get_option(line, 'ELSET', section_value)
@@ -271,7 +279,7 @@ contains
else if (index(upper_line, 'COUPLING REGION') > 0) then
call sph_input_parse_coupling_region(line, ierr)
else if (index(upper_line, 'EOS') > 0) then
call sph_input_parse_water_eos(line, ierr)
call sph_input_parse_eos(line, ierr)
else if (index(upper_line, 'VISCOSITY') > 0) then
call sph_input_parse_water_viscosity(line, ierr)
else if (index(upper_line, 'PARTICLE CONTROL') > 0) then
@@ -296,6 +304,21 @@ contains
if (ierr /= SPH_SUCCESS) call sph_input_prefix_current_error(ierr)
end subroutine sph_input_record_keyword
subroutine sph_input_parse_eos(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: eos_type
ierr = SPH_SUCCESS
call sph_input_get_option(line, 'TYPE', eos_type)
eos_type = sph_inp_upper(eos_type)
if (index(eos_type, 'TAIT') > 0) then
call sph_input_parse_water_eos(line, ierr)
else
call sph_input_parse_gas_eos(line, ierr)
end if
end subroutine sph_input_parse_eos
subroutine sph_input_parse_water_eos(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
@@ -332,6 +355,74 @@ contains
b_value, has_b, ierr)
end subroutine sph_input_parse_water_eos
subroutine sph_input_parse_gas_eos(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: eos_type
character(len=SPH_INPUT_FIELD_LEN) :: mat_name
real(rk) :: rho0
real(rk) :: gamma
real(rk) :: e0
real(rk) :: p0
real(rk) :: a_value
real(rk) :: b_value
real(rk) :: r1
real(rk) :: r2
real(rk) :: omega
real(rk) :: pinf
character(len=SPH_INPUT_FIELD_LEN) :: upper_type
ierr = SPH_SUCCESS
call sph_input_get_option(line, 'TYPE', eos_type)
call sph_input_get_option(line, 'MATERIAL', mat_name)
upper_type = sph_inp_upper(eos_type)
rho0 = 0.0_rk
gamma = 0.0_rk
e0 = 0.0_rk
p0 = 0.0_rk
a_value = 0.0_rk
b_value = 0.0_rk
r1 = 0.0_rk
r2 = 0.0_rk
omega = 0.0_rk
pinf = 0.0_rk
if (len_trim(eos_type) == 0 .or. index(upper_type, 'IDEAL_GAS') > 0) then
call sph_input_get_required_real(line, 'GAMMA', gamma, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'E0', e0, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_optional_real(line, 'P0', p0, ierr)
if (ierr /= SPH_SUCCESS) return
else if (index(upper_type, 'JWL') > 0) then
call sph_input_get_required_real(line, 'RHO0', rho0, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'A', a_value, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'B', b_value, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'R1', r1, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'R2', r2, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'OMEGA', omega, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'E0', e0, ierr)
if (ierr /= SPH_SUCCESS) return
else if (index(upper_type, 'STIFFENED_GAS') > 0) then
call sph_input_get_required_real(line, 'RHO0', rho0, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'GAMMA', gamma, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'E0', e0, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'PINF', pinf, ierr)
if (ierr /= SPH_SUCCESS) return
end if
call sph_gas_set_eos(eos_type, mat_name, rho0, gamma, e0, p0, &
a_value, b_value, r1, r2, omega, pinf, ierr)
end subroutine sph_input_parse_gas_eos
subroutine sph_input_parse_water_viscosity(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
@@ -368,6 +459,8 @@ contains
call sph_input_get_required_real(line, 'VOLUME', volume_value, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_water_set_particle_control(h_value, mass_value, volume_value, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_gas_set_particle_control(h_value, mass_value, volume_value, ierr)
end subroutine sph_input_parse_particle_control
subroutine sph_input_parse_body_force(line, ierr)
@@ -384,6 +477,8 @@ contains
call sph_input_get_optional_real(line, 'Z', force(3), ierr)
if (ierr /= SPH_SUCCESS) return
call sph_water_set_body_force(force, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_gas_set_body_force(force, ierr)
end subroutine sph_input_parse_body_force
subroutine sph_input_parse_density(line, ierr)
@@ -543,17 +638,25 @@ contains
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: fields(SPH_INPUT_MAX_FIELDS)
integer :: nfields
integer :: first_member
integer :: members(SPH_INPUT_MAX_FIELDS)
integer :: i
integer :: ios
ierr = SPH_SUCCESS
first_member = 0
members = 0
call sph_inp_split_csv(line, fields, nfields)
if (nfields > 0) read(fields(1), *, iostat=ios) first_member
do i = 1, nfields
read(fields(i), *, iostat=ios) members(i)
if (ios /= 0) then
call sph_input_set_error('invalid set member id')
ierr = SPH_ERROR_INPUT
return
end if
end do
if (is_node_set) then
call sph_db_add_nset(set_name, nfields, first_member, ierr)
call sph_db_add_nset(set_name, nfields, members, ierr)
else
call sph_db_add_elset(set_name, nfields, first_member, ierr)
call sph_db_add_elset(set_name, nfields, members, ierr)
end if
end subroutine sph_input_parse_set_members