Files
SPHLite/src/input/sph_input_reader.f90
T
2026-07-03 15:55:37 +08:00

973 lines
36 KiB
Fortran

module sph_input_reader
use sph_precision, only: rk, SPH_NDIM
use sph_error, only: SPH_SUCCESS, SPH_ERROR_IO, SPH_ERROR_INPUT, sph_error_set, &
sph_error_get
use sph_input_time, only: sph_input_parse_time_control
use sph_output_csv, only: sph_output_set_directory, sph_output_set_interval
use sph_database, only: npart, SPH_MAX_ELEMENT_NODES, &
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_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, sph_gas_count_unbound_materials
use sph_explosive, only: sph_explosive_note_material, &
sph_explosive_set_control, sph_explosive_set_ignition, &
sph_explosive_build, sph_explosive_count_unbound_materials
use sph_solid, only: sph_solid_note_material, sph_solid_set_elastic, &
sph_solid_set_johnson_cook, sph_solid_set_failure, &
sph_solid_set_control, sph_solid_build_state, &
sph_solid_count_unbound_materials
use sph_solid_dynamics, only: sph_solid_set_body_force, sph_solid_update_diagnostics
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, &
SPH_KEY_ELSET, SPH_KEY_MATERIAL, SPH_KEY_SECTION, SPH_KEY_SPHLITE, &
SPH_KEY_DENSITY, SPH_KEY_ELASTIC, SPH_KEY_PLASTIC, &
SPH_KEY_DAMAGE_INITIATION, SPH_KEY_UNKNOWN
use sph_inp_helpers, only: sph_inp_clean_line, sph_inp_split_csv, &
sph_inp_keyword_id, sph_inp_upper
implicit none
integer, parameter :: SPH_INPUT_UNIT = 31
integer :: input_warning_count = 0
logical :: input_has_material = .false.
logical :: input_has_section = .false.
logical :: input_has_time_control = .false.
character(len=SPH_INPUT_LINE_LEN) :: input_current_file = ' '
integer :: input_current_line = 0
character(len=SPH_INPUT_FIELD_LEN) :: active_element_type = 'UNKNOWN'
character(len=SPH_INPUT_FIELD_LEN) :: active_nset_name = 'NSET'
character(len=SPH_INPUT_FIELD_LEN) :: active_elset_name = 'ELSET'
character(len=SPH_INPUT_FIELD_LEN) :: active_material_name = 'MATERIAL'
contains
subroutine sph_input_reset()
input_warning_count = 0
input_has_material = .false.
input_has_section = .false.
input_has_time_control = .false.
input_current_file = ' '
input_current_line = 0
active_element_type = 'UNKNOWN'
active_nset_name = 'NSET'
active_elset_name = 'ELSET'
active_material_name = 'MATERIAL'
end subroutine sph_input_reset
subroutine sph_input_get_warning_count(count)
integer, intent(out) :: count
count = input_warning_count
end subroutine sph_input_get_warning_count
subroutine sph_input_read(filename, ierr)
character(len=*), intent(in) :: filename
integer, intent(out) :: ierr
integer :: node_count
call sph_input_reset()
input_current_file = filename
call sph_input_scan(filename, node_count, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_db_allocate(node_count, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_fill_model(filename, node_count, ierr)
end subroutine sph_input_read
subroutine sph_input_build_model(ierr)
integer, intent(out) :: ierr
integer :: gas_unbound_count
integer :: explosive_unbound_count
integer :: solid_unbound_count
ierr = SPH_SUCCESS
if (npart <= 0) then
call sph_error_set(SPH_ERROR_INPUT, 'input is missing *NODE particle data')
ierr = SPH_ERROR_INPUT
return
end if
if (.not. input_has_material) then
call sph_error_set(SPH_ERROR_INPUT, 'input is missing *MATERIAL data')
ierr = SPH_ERROR_INPUT
return
end if
if (.not. input_has_section) then
call sph_error_set(SPH_ERROR_INPUT, 'input is missing *SECTION data')
ierr = SPH_ERROR_INPUT
return
end if
if (.not. input_has_time_control) then
call sph_error_set(SPH_ERROR_INPUT, 'input is missing *SPHLITE time control data')
ierr = SPH_ERROR_INPUT
return
end if
call sph_db_apply_sections_to_particles(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_solid_build_state(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_explosive_build(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_explosive_count_unbound_materials(explosive_unbound_count)
input_warning_count = input_warning_count + explosive_unbound_count
call sph_solid_count_unbound_materials(solid_unbound_count)
input_warning_count = input_warning_count + solid_unbound_count
call sph_solid_update_diagnostics(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_neighbor_rebuild(ierr)
end subroutine sph_input_build_model
subroutine sph_input_scan(filename, node_count, ierr)
character(len=*), intent(in) :: filename
integer, intent(out) :: node_count
integer, intent(out) :: ierr
character(len=SPH_INPUT_LINE_LEN) :: raw_line
character(len=SPH_INPUT_LINE_LEN) :: line
integer :: ios
integer :: active_key
integer :: key_id
integer :: line_number
ierr = SPH_SUCCESS
node_count = 0
active_key = SPH_KEY_UNKNOWN
line_number = 0
open(unit=SPH_INPUT_UNIT, file=trim(filename), status='old', action='read', iostat=ios)
if (ios /= 0) then
call sph_error_set(SPH_ERROR_IO, 'failed to open input file')
ierr = SPH_ERROR_IO
return
end if
do
read(SPH_INPUT_UNIT, '(A)', iostat=ios) raw_line
if (ios /= 0) exit
line_number = line_number + 1
line = sph_inp_clean_line(raw_line)
if (len_trim(line) == 0) cycle
if (line(1:1) == '*') then
key_id = sph_inp_keyword_id(line)
active_key = key_id
else if (active_key == SPH_KEY_NODE) then
node_count = node_count + 1
end if
end do
close(unit=SPH_INPUT_UNIT)
end subroutine sph_input_scan
subroutine sph_input_fill_model(filename, expected_nodes, ierr)
character(len=*), intent(in) :: filename
integer, intent(in) :: expected_nodes
integer, intent(out) :: ierr
character(len=SPH_INPUT_LINE_LEN) :: raw_line
character(len=SPH_INPUT_LINE_LEN) :: line
integer :: ios
integer :: active_key
integer :: key_id
integer :: node_index
integer :: line_number
ierr = SPH_SUCCESS
active_key = SPH_KEY_UNKNOWN
node_index = 0
line_number = 0
if (expected_nodes == 0) then
call sph_db_free()
return
end if
open(unit=SPH_INPUT_UNIT, file=trim(filename), status='old', action='read', iostat=ios)
if (ios /= 0) then
call sph_error_set(SPH_ERROR_IO, 'failed to reopen input file')
ierr = SPH_ERROR_IO
return
end if
do
read(SPH_INPUT_UNIT, '(A)', iostat=ios) raw_line
if (ios /= 0) exit
line_number = line_number + 1
input_current_line = line_number
line = sph_inp_clean_line(raw_line)
if (len_trim(line) == 0) cycle
if (line(1:1) == '*') then
key_id = sph_inp_keyword_id(line)
active_key = key_id
call sph_input_record_keyword(key_id, line, ierr)
if (ierr /= SPH_SUCCESS) then
close(unit=SPH_INPUT_UNIT)
return
end if
else if (active_key == SPH_KEY_NODE) then
node_index = node_index + 1
call sph_input_parse_node(line, node_index, ierr)
if (ierr /= SPH_SUCCESS) then
close(unit=SPH_INPUT_UNIT)
return
end if
else if (active_key == SPH_KEY_ELEMENT) then
call sph_input_parse_element(line, ierr)
if (ierr /= SPH_SUCCESS) then
close(unit=SPH_INPUT_UNIT)
return
end if
else if (active_key == SPH_KEY_NSET) then
call sph_input_parse_set_members(line, active_nset_name, .true., ierr)
if (ierr /= SPH_SUCCESS) then
close(unit=SPH_INPUT_UNIT)
return
end if
else if (active_key == SPH_KEY_ELSET) then
call sph_input_parse_set_members(line, active_elset_name, .false., ierr)
if (ierr /= SPH_SUCCESS) then
close(unit=SPH_INPUT_UNIT)
return
end if
else if (active_key == SPH_KEY_DENSITY) then
call sph_input_parse_density(line, ierr)
if (ierr /= SPH_SUCCESS) then
close(unit=SPH_INPUT_UNIT)
return
end if
else if (active_key == SPH_KEY_ELASTIC) then
call sph_input_parse_elastic(line, ierr)
if (ierr /= SPH_SUCCESS) then
close(unit=SPH_INPUT_UNIT)
return
end if
else if (active_key == SPH_KEY_PLASTIC) then
call sph_input_parse_plastic(line, ierr)
if (ierr /= SPH_SUCCESS) then
close(unit=SPH_INPUT_UNIT)
return
end if
else if (active_key == SPH_KEY_DAMAGE_INITIATION) then
call sph_input_parse_damage_initiation(line, ierr)
if (ierr /= SPH_SUCCESS) then
close(unit=SPH_INPUT_UNIT)
return
end if
end if
end do
close(unit=SPH_INPUT_UNIT)
end subroutine sph_input_fill_model
subroutine sph_input_record_keyword(key_id, line, ierr)
integer, intent(in) :: key_id
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: value
character(len=SPH_INPUT_FIELD_LEN) :: material_value
character(len=SPH_INPUT_FIELD_LEN) :: section_value
character(len=SPH_INPUT_FIELD_LEN) :: section_type_value
character(len=SPH_INPUT_FIELD_LEN) :: type_value
real(rk) :: thickness
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)
if (len_trim(value) == 0) value = 'MATERIAL'
active_material_name = value
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)
call sph_gas_note_material(value, type_value)
call sph_explosive_note_material(value, type_value)
call sph_solid_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)
if (len_trim(section_value) == 0) call sph_input_get_option(line, 'NSET', section_value)
if (len_trim(section_value) == 0) section_value = 'SECTION'
call sph_input_get_option(line, 'MATERIAL', material_value)
if (len_trim(material_value) == 0) material_value = 'MATERIAL'
thickness = 0.0_rk
points = 3
call sph_input_get_option(line, 'THICKNESS', value)
if (len_trim(value) > 0) read(value, *, iostat=ios) thickness
call sph_input_get_option(line, 'POINTS', value)
if (len_trim(value) > 0) read(value, *, iostat=ios) points
section_type_value = 'SECTION'
if (index(upper_line, '*SOLID SECTION') == 1) section_type_value = 'SOLID'
call sph_db_add_section(section_value, section_type_value, material_value, &
thickness, points, ierr)
else if (key_id == SPH_KEY_SPHLITE) then
if (index(upper_line, 'TIME CONTROL') > 0) then
input_has_time_control = .true.
call sph_input_parse_time_control(line, input_current_file, &
input_current_line, ierr)
else if (index(upper_line, 'OUTPUT') > 0) then
call sph_input_parse_output_control(line, ierr)
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_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)
else if (index(upper_line, 'EXPLOSIVE') > 0) then
call sph_input_parse_explosive_control(line, ierr)
else if (index(upper_line, 'IGNITION') > 0) then
call sph_input_parse_ignition(line, ierr)
else if (index(upper_line, 'SOLID CONTROL') > 0) then
call sph_input_parse_solid_control(line, ierr)
else
input_warning_count = input_warning_count + 1
end if
else if (key_id == SPH_KEY_ELEMENT) then
call sph_input_get_option(line, 'TYPE', active_element_type)
if (len_trim(active_element_type) == 0) active_element_type = 'UNKNOWN'
else if (key_id == SPH_KEY_NSET) then
call sph_input_get_option(line, 'NSET', active_nset_name)
if (len_trim(active_nset_name) == 0) active_nset_name = 'NSET'
else if (key_id == SPH_KEY_ELSET) then
call sph_input_get_option(line, 'ELSET', active_elset_name)
if (len_trim(active_elset_name) == 0) active_elset_name = 'ELSET'
else if (key_id == SPH_KEY_UNKNOWN) then
input_warning_count = input_warning_count + 1
end if
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
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
p0 = 0.0_rk
call sph_input_get_optional_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_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
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)
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)
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)
if (ierr /= SPH_SUCCESS) return
call sph_gas_set_body_force(force, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_solid_set_body_force(force, ierr)
end subroutine sph_input_parse_body_force
subroutine sph_input_parse_solid_control(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: material_name
character(len=SPH_INPUT_FIELD_LEN) :: softening_name
real(rk) :: width
ierr = SPH_SUCCESS
width = 1.0_rk
call sph_input_get_option(line, 'MATERIAL', material_name)
call sph_input_get_option(line, 'SOFTENING', softening_name)
call sph_input_get_optional_real(line, 'WIDTH', width, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_solid_set_control(material_name, softening_name, width, ierr)
end subroutine sph_input_parse_solid_control
subroutine sph_input_parse_explosive_control(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: material_name
character(len=SPH_INPUT_FIELD_LEN) :: model_type
character(len=SPH_INPUT_FIELD_LEN) :: product_material
character(len=SPH_INPUT_FIELD_LEN) :: conversion
real(rk) :: detonation_velocity
real(rk) :: energy
real(rk) :: burn_time
ierr = SPH_SUCCESS
call sph_input_get_option(line, 'MATERIAL', material_name)
call sph_input_get_option(line, 'TYPE', model_type)
call sph_input_get_option(line, 'PRODUCT_MATERIAL', product_material)
call sph_input_get_option(line, 'CONVERSION', conversion)
call sph_input_get_required_real(line, 'DETONATION_VELOCITY', &
detonation_velocity, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'ENERGY', energy, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'BURN_TIME', burn_time, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_explosive_set_control(material_name, model_type, &
detonation_velocity, energy, burn_time, product_material, &
conversion, ierr)
end subroutine sph_input_parse_explosive_control
subroutine sph_input_parse_ignition(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: material_name
real(rk) :: ignition_x(SPH_NDIM)
real(rk) :: ignition_time
ierr = SPH_SUCCESS
ignition_x = 0.0_rk
ignition_time = 0.0_rk
call sph_input_get_option(line, 'MATERIAL', material_name)
call sph_input_get_required_real(line, 'X', ignition_x(1), ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'Y', ignition_x(2), ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'Z', ignition_x(3), ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_get_required_real(line, 'TIME', ignition_time, ierr)
if (ierr /= SPH_SUCCESS) return
call sph_explosive_set_ignition(material_name, ignition_x, &
ignition_time, ierr)
end subroutine sph_input_parse_ignition
subroutine sph_input_parse_density(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: fields(SPH_INPUT_MAX_FIELDS)
integer :: nfields
integer :: ios
real(rk) :: density_value
ierr = SPH_SUCCESS
call sph_inp_split_csv(line, fields, nfields)
if (nfields < 1) then
call sph_input_set_error('invalid *DENSITY record')
ierr = SPH_ERROR_INPUT
return
end if
read(fields(1), *, iostat=ios) density_value
if (ios /= 0) then
call sph_input_set_error('invalid density value')
ierr = SPH_ERROR_INPUT
return
end if
call sph_db_set_material_density(active_material_name, density_value, ierr)
end subroutine sph_input_parse_density
subroutine sph_input_parse_elastic(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: fields(SPH_INPUT_MAX_FIELDS)
integer :: nfields
integer :: ios
real(rk) :: e_value
real(rk) :: nu_value
ierr = SPH_SUCCESS
call sph_inp_split_csv(line, fields, nfields)
if (nfields < 2) then
call sph_input_set_error('invalid *ELASTIC record')
ierr = SPH_ERROR_INPUT
return
end if
read(fields(1), *, iostat=ios) e_value
if (ios /= 0) then
call sph_input_set_error('invalid elastic modulus')
ierr = SPH_ERROR_INPUT
return
end if
read(fields(2), *, iostat=ios) nu_value
if (ios /= 0) then
call sph_input_set_error('invalid Poisson ratio')
ierr = SPH_ERROR_INPUT
return
end if
call sph_solid_set_elastic(active_material_name, e_value, nu_value, ierr)
end subroutine sph_input_parse_elastic
subroutine sph_input_parse_plastic(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: fields(SPH_INPUT_MAX_FIELDS)
integer :: nfields
integer :: i
integer :: ios
real(rk) :: values(8)
ierr = SPH_SUCCESS
values = 0.0_rk
call sph_inp_split_csv(line, fields, nfields)
if (nfields < 8) then
call sph_input_set_error('invalid Johnson-Cook plastic record')
ierr = SPH_ERROR_INPUT
return
end if
do i = 1, 8
read(fields(i), *, iostat=ios) values(i)
if (ios /= 0) then
call sph_input_set_error('invalid Johnson-Cook plastic value')
ierr = SPH_ERROR_INPUT
return
end if
end do
call sph_solid_set_johnson_cook(active_material_name, values(1), values(2), &
values(3), values(4), values(5), values(6), values(7), values(8), ierr)
end subroutine sph_input_parse_plastic
subroutine sph_input_parse_damage_initiation(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: fields(SPH_INPUT_MAX_FIELDS)
integer :: nfields
integer :: i
integer :: ios
real(rk) :: d_values(5)
ierr = SPH_SUCCESS
d_values = 0.0_rk
call sph_inp_split_csv(line, fields, nfields)
if (nfields < 5) then
call sph_input_set_error('invalid Johnson-Cook damage record')
ierr = SPH_ERROR_INPUT
return
end if
do i = 1, 5
read(fields(i), *, iostat=ios) d_values(i)
if (ios /= 0) then
call sph_input_set_error('invalid Johnson-Cook damage value')
ierr = SPH_ERROR_INPUT
return
end if
end do
call sph_solid_set_failure(active_material_name, d_values, ierr)
end subroutine sph_input_parse_damage_initiation
subroutine sph_input_parse_output_control(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: value
integer :: interval
integer :: ios
ierr = SPH_SUCCESS
call sph_input_get_option(line, 'DIRECTORY', value)
if (len_trim(value) == 0) call sph_input_get_option(line, 'DIR', value)
if (len_trim(value) > 0) then
call sph_output_set_directory(value, ierr)
if (ierr /= SPH_SUCCESS) return
end if
call sph_input_get_option(line, 'INTERVAL', value)
if (len_trim(value) > 0) then
read(value, *, iostat=ios) interval
if (ios == 0) call sph_output_set_interval(interval, ierr)
end if
end subroutine sph_input_parse_output_control
subroutine sph_input_parse_coupling_region(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: name
character(len=SPH_INPUT_FIELD_LEN) :: set_name
character(len=SPH_INPUT_FIELD_LEN) :: type_name
integer :: region_type
ierr = SPH_SUCCESS
call sph_input_get_option(line, 'NAME', name)
if (len_trim(name) == 0) name = 'COUPLING'
call sph_input_get_option(line, 'SET', set_name)
if (len_trim(set_name) == 0) call sph_input_get_option(line, 'NSET', set_name)
if (len_trim(set_name) == 0) call sph_input_get_option(line, 'ELSET', set_name)
if (len_trim(set_name) == 0) set_name = 'ALL'
call sph_input_get_option(line, 'TYPE', type_name)
type_name = sph_inp_upper(type_name)
region_type = SPH_REGION_COUPLING_CONTACT
if (index(type_name, 'CONTINUUM') > 0) region_type = SPH_REGION_COUPLING_CONTINUUM
call sph_db_add_coupling_region(name, set_name, region_type, ierr)
end subroutine sph_input_parse_coupling_region
subroutine sph_input_parse_node(line, node_index, ierr)
character(len=*), intent(in) :: line
integer, intent(in) :: node_index
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: fields(SPH_INPUT_MAX_FIELDS)
integer :: nfields
integer :: ext_id
integer :: ios
real(rk) :: coords(SPH_NDIM)
ierr = SPH_SUCCESS
call sph_inp_split_csv(line, fields, nfields)
if (nfields < 4) then
call sph_input_set_error('invalid *NODE record')
ierr = SPH_ERROR_INPUT
return
end if
read(fields(1), *, iostat=ios) ext_id
if (ios /= 0) then
call sph_input_set_error('invalid node id')
ierr = SPH_ERROR_INPUT
return
end if
read(fields(2), *, iostat=ios) coords(1)
if (ios /= 0) then
call sph_input_set_error('invalid node x coordinate')
ierr = SPH_ERROR_INPUT
return
end if
read(fields(3), *, iostat=ios) coords(2)
if (ios /= 0) then
call sph_input_set_error('invalid node y coordinate')
ierr = SPH_ERROR_INPUT
return
end if
read(fields(4), *, iostat=ios) coords(3)
if (ios /= 0) then
call sph_input_set_error('invalid node z coordinate')
ierr = SPH_ERROR_INPUT
return
end if
call sph_db_set_node(node_index, ext_id, coords, ierr)
end subroutine sph_input_parse_node
subroutine sph_input_parse_element(line, ierr)
character(len=*), intent(in) :: line
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: fields(SPH_INPUT_MAX_FIELDS)
integer :: nfields
integer :: ext_id
integer :: conn_values(SPH_MAX_ELEMENT_NODES)
integer :: conn_count
integer :: i
integer :: ios
ierr = SPH_SUCCESS
conn_values = 0
call sph_inp_split_csv(line, fields, nfields)
if (nfields < 2) then
call sph_input_set_error('invalid *ELEMENT record')
ierr = SPH_ERROR_INPUT
return
end if
read(fields(1), *, iostat=ios) ext_id
if (ios /= 0) then
call sph_input_set_error('invalid element id')
ierr = SPH_ERROR_INPUT
return
end if
conn_count = nfields - 1
if (conn_count > SPH_MAX_ELEMENT_NODES) conn_count = SPH_MAX_ELEMENT_NODES
do i = 1, conn_count
read(fields(i+1), *, iostat=ios) conn_values(i)
if (ios /= 0) then
call sph_input_set_error('invalid element connectivity')
ierr = SPH_ERROR_INPUT
return
end if
end do
call sph_db_add_element(ext_id, active_element_type, conn_count, conn_values, ierr)
end subroutine sph_input_parse_element
subroutine sph_input_parse_set_members(line, set_name, is_node_set, ierr)
character(len=*), intent(in) :: line
character(len=*), intent(in) :: set_name
logical, intent(in) :: is_node_set
integer, intent(out) :: ierr
character(len=SPH_INPUT_FIELD_LEN) :: fields(SPH_INPUT_MAX_FIELDS)
integer :: nfields
integer :: members(SPH_INPUT_MAX_FIELDS)
integer :: i
integer :: ios
ierr = SPH_SUCCESS
members = 0
call sph_inp_split_csv(line, fields, nfields)
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, members, ierr)
else
call sph_db_add_elset(set_name, nfields, members, ierr)
end if
end subroutine sph_input_parse_set_members
subroutine sph_input_get_option(line, option_name, value)
character(len=*), intent(in) :: line
character(len=*), intent(in) :: option_name
character(len=*), intent(out) :: value
character(len=SPH_INPUT_FIELD_LEN) :: fields(SPH_INPUT_MAX_FIELDS)
character(len=SPH_INPUT_FIELD_LEN) :: item
character(len=SPH_INPUT_FIELD_LEN) :: key
integer :: nfields
integer :: i
integer :: eq_pos
value = ' '
call sph_inp_split_csv(line, fields, nfields)
do i = 1, nfields
item = adjustl(fields(i))
eq_pos = index(item, '=')
if (eq_pos <= 0) cycle
key = sph_inp_upper(adjustl(item(1:eq_pos-1)))
if (trim(key) == trim(sph_inp_upper(option_name))) then
value = adjustl(item(eq_pos+1:len_trim(item)))
return
end if
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
write(full_message, '(A,":",I0,": ",A)') trim(input_current_file), &
input_current_line, trim(message)
call sph_error_set(SPH_ERROR_INPUT, trim(full_message))
end subroutine sph_input_set_error
subroutine sph_input_prefix_current_error(ierr)
integer, intent(in) :: ierr
integer :: code
character(len=SPH_INPUT_LINE_LEN) :: message
character(len=SPH_INPUT_LINE_LEN) :: full_message
if (ierr == SPH_SUCCESS) return
call sph_error_get(code, message)
if (index(trim(message), trim(input_current_file)//':') == 1) return
write(full_message, '(A,":",I0,": ",A)') trim(input_current_file), &
input_current_line, trim(message)
call sph_error_set(code, trim(full_message))
end subroutine sph_input_prefix_current_error
end module sph_input_reader