Parse water EOS viscosity and particle controls

This commit is contained in:
Codex
2026-07-02 20:12:46 +08:00
parent 2e0de94c36
commit ced4d3f122
4 changed files with 361 additions and 24 deletions
+158 -3
View File
@@ -9,6 +9,9 @@ module sph_input_reader
sph_db_add_section, sph_db_add_nset, sph_db_add_elset, &
sph_db_add_element, sph_db_add_coupling_region
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_validate_input
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, &
SPH_KEY_ELSET, SPH_KEY_MATERIAL, SPH_KEY_SECTION, SPH_KEY_SPHLITE, &
@@ -88,6 +91,7 @@ contains
ierr = SPH_ERROR_INPUT
return
end if
call sph_water_validate_input(ierr)
end subroutine sph_input_build_model
subroutine sph_input_scan(filename, node_count, ierr)
@@ -225,8 +229,10 @@ contains
integer :: points
integer :: ios
integer :: local_ierr
character(len=SPH_INPUT_LINE_LEN) :: upper_line
ierr = SPH_SUCCESS
upper_line = sph_inp_upper(line)
if (key_id == SPH_KEY_MATERIAL) then
input_has_material = .true.
call sph_input_get_option(line, 'NAME', value)
@@ -235,6 +241,7 @@ contains
call sph_input_get_option(line, 'TYPE', type_value)
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)
else if (key_id == SPH_KEY_SECTION) then
input_has_section = .true.
call sph_input_get_option(line, 'ELSET', section_value)
@@ -251,13 +258,21 @@ contains
call sph_db_add_section(section_value, 'SECTION', material_value, &
thickness, points, ierr)
else if (key_id == SPH_KEY_SPHLITE) then
if (index(sph_inp_upper(line), 'TIME CONTROL') > 0) then
if (index(upper_line, 'TIME CONTROL') > 0) then
input_has_time_control = .true.
call sph_input_parse_time_control(line)
else if (index(sph_inp_upper(line), 'OUTPUT') > 0) then
else if (index(upper_line, 'OUTPUT') > 0) then
call sph_input_parse_output_control(line, ierr)
else if (index(sph_inp_upper(line), 'COUPLING REGION') > 0) then
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)
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
call sph_input_parse_particle_control(line, ierr)
else if (index(upper_line, 'BODY FORCE') > 0) then
call sph_input_parse_body_force(line, ierr)
end if
else if (key_id == SPH_KEY_ELEMENT) then
call sph_input_get_option(line, 'TYPE', active_element_type)
@@ -273,6 +288,95 @@ contains
end if
end subroutine sph_input_record_keyword
subroutine sph_input_parse_water_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
character(len=SPH_INPUT_FIELD_LEN) :: value
real(rk) :: rho0
real(rk) :: c0
real(rk) :: gamma
real(rk) :: p0
real(rk) :: b_value
logical :: has_b
ierr = SPH_SUCCESS
call sph_input_get_option(line, 'TYPE', eos_type)
call sph_input_get_option(line, 'MATERIAL', mat_name)
call sph_input_get_required_real(line, 'RHO0', rho0, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'C0', c0, 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, 'P0', p0, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_option(line, 'B', value)
has_b = len_trim(value) > 0
b_value = 0.0_rk
if (has_b) then
call sph_input_parse_real_value(value, b_value, 'invalid SPHLITE EOS B', ierr)
if (ierr /= SPH_SUCCESS) return
end if
call sph_water_set_eos(eos_type, mat_name, rho0, c0, gamma, p0, &
b_value, has_b, ierr)
end subroutine sph_input_parse_water_eos
subroutine sph_input_parse_water_viscosity(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: visc_type
character(len=SPH_INPUT_FIELD_LEN) :: mat_name
real(rk) :: alpha
real(rk) :: beta
real(rk) :: eta2
ierr = SPH_SUCCESS
call sph_input_get_option(line, 'TYPE', visc_type)
call sph_input_get_option(line, 'MATERIAL', mat_name)
call sph_input_get_required_real(line, 'ALPHA', alpha, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'BETA', beta, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'ETA2', eta2, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_water_set_viscosity(visc_type, mat_name, alpha, beta, eta2, ierr)
end subroutine sph_input_parse_water_viscosity
subroutine sph_input_parse_particle_control(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
real(rk) :: h_value
real(rk) :: mass_value
real(rk) :: volume_value
ierr = SPH_SUCCESS
call sph_input_get_required_real(line, 'H', h_value, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'MASS', mass_value, ierr)
if (ierr /= SPH_SUCCESS) return
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)
end subroutine sph_input_parse_particle_control
subroutine sph_input_parse_body_force(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
real(rk) :: force(SPH_NDIM)
ierr = SPH_SUCCESS
force = 0.0_rk
call sph_input_get_optional_real(line, 'X', force(1), ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_optional_real(line, 'Y', force(2), ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_optional_real(line, 'Z', force(3), ierr)
if (ierr /= SPH_SUCCESS) return
call sph_water_set_body_force(force, ierr)
end subroutine sph_input_parse_body_force
subroutine sph_input_parse_density(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
@@ -504,6 +608,57 @@ contains
end do
end subroutine sph_input_get_option
subroutine sph_input_get_required_real(line, option_name, value, ierr)
character(len=*), intent(in) :: line
character(len=*), intent(in) :: option_name
real(rk), intent(out) :: value
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: text
character(len=SPH_INPUT_LINE_LEN) :: message
ierr = SPH_SUCCESS
value = 0.0_rk
call sph_input_get_option(line, option_name, text)
if (len_trim(text) == 0) then
write(message, '(A,A)') 'missing required option ', trim(option_name)
call sph_input_set_error(message)
ierr = SPH_ERROR_INPUT
return
end if
write(message, '(A,A)') 'invalid numeric option ', trim(option_name)
call sph_input_parse_real_value(text, value, message, ierr)
end subroutine sph_input_get_required_real
subroutine sph_input_get_optional_real(line, option_name, value, ierr)
character(len=*), intent(in) :: line
character(len=*), intent(in) :: option_name
real(rk), intent(inout) :: value
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: text
character(len=SPH_INPUT_LINE_LEN) :: message
ierr = SPH_SUCCESS
call sph_input_get_option(line, option_name, text)
if (len_trim(text) == 0) return
write(message, '(A,A)') 'invalid numeric option ', trim(option_name)
call sph_input_parse_real_value(text, value, message, ierr)
end subroutine sph_input_get_optional_real
subroutine sph_input_parse_real_value(text, value, message, ierr)
character(len=*), intent(in) :: text
real(rk), intent(out) :: value
character(len=*), intent(in) :: message
integer, intent(out) :: ierr
integer :: ios
ierr = SPH_SUCCESS
read(text, *, iostat=ios) value
if (ios /= 0) then
call sph_input_set_error(message)
ierr = SPH_ERROR_INPUT
end if
end subroutine sph_input_parse_real_value
subroutine sph_input_set_error(message)
character(len=*), intent(in) :: message
character(len=SPH_INPUT_LINE_LEN) :: full_message