Prepare SPHLite 0.2.0 development baseline

This commit is contained in:
Codex
2026-07-02 19:50:44 +08:00
parent ad31c2d5cc
commit ed1f5a5ab2
36 changed files with 3122 additions and 267 deletions
+237 -13
View File
@@ -2,7 +2,12 @@ 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
use sph_control, only: sph_control_set_time
use sph_database, only: npart, sph_db_allocate, sph_db_free, sph_db_set_node
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
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, &
@@ -16,6 +21,11 @@ module sph_input_reader
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'
contains
@@ -24,6 +34,11 @@ contains
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'
end subroutine sph_input_reset
subroutine sph_input_get_warning_count(count)
@@ -38,11 +53,12 @@ contains
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_nodes(filename, node_count, ierr)
call sph_input_fill_model(filename, node_count, ierr)
end subroutine sph_input_read
subroutine sph_input_build_model(ierr)
@@ -80,10 +96,12 @@ contains
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
@@ -95,13 +113,13 @@ contains
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
call sph_input_record_keyword(key_id, line)
else if (active_key == SPH_KEY_NODE) then
node_count = node_count + 1
end if
@@ -110,7 +128,7 @@ contains
close(unit=SPH_INPUT_UNIT)
end subroutine sph_input_scan
subroutine sph_input_fill_nodes(filename, expected_nodes, ierr)
subroutine sph_input_fill_model(filename, expected_nodes, ierr)
character(len=*), intent(in) :: filename
integer, intent(in) :: expected_nodes
integer, intent(out) :: ierr
@@ -120,10 +138,12 @@ contains
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()
@@ -140,12 +160,19 @@ contains
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)
@@ -153,28 +180,132 @@ contains
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
end if
end do
close(unit=SPH_INPUT_UNIT)
end subroutine sph_input_fill_nodes
end subroutine sph_input_fill_model
subroutine sph_input_record_keyword(key_id, line)
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) :: type_value
real(rk) :: thickness
integer :: points
integer :: ios
integer :: local_ierr
ierr = SPH_SUCCESS
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'
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)
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
call sph_db_add_section(section_value, 'SECTION', material_value, &
thickness, points, ierr)
else if (key_id == SPH_KEY_SPHLITE) then
input_has_time_control = .true.
call sph_input_parse_time_control(line)
if (index(sph_inp_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
call sph_input_parse_output_control(line, ierr)
else if (index(sph_inp_upper(line), 'COUPLING REGION') > 0) then
call sph_input_parse_coupling_region(line, ierr)
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
end subroutine sph_input_record_keyword
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_time_control(line)
character(len=*), intent(in) :: line
character(len=SPH_INPUT_FIELD_LEN) :: fields(SPH_INPUT_MAX_FIELDS)
@@ -223,31 +354,31 @@ contains
ierr = SPH_SUCCESS
call sph_inp_split_csv(line, fields, nfields)
if (nfields < 4) then
call sph_error_set(SPH_ERROR_INPUT, 'invalid *NODE record')
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_error_set(SPH_ERROR_INPUT, 'invalid node id')
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_error_set(SPH_ERROR_INPUT, 'invalid node x coordinate')
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_error_set(SPH_ERROR_INPUT, 'invalid node y coordinate')
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_error_set(SPH_ERROR_INPUT, 'invalid node z coordinate')
call sph_input_set_error('invalid node z coordinate')
ierr = SPH_ERROR_INPUT
return
end if
@@ -255,4 +386,97 @@ contains
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 :: first_member
integer :: ios
ierr = SPH_SUCCESS
first_member = 0
call sph_inp_split_csv(line, fields, nfields)
if (nfields > 0) read(fields(1), *, iostat=ios) first_member
if (is_node_set) then
call sph_db_add_nset(set_name, nfields, first_member, ierr)
else
call sph_db_add_elset(set_name, nfields, first_member, 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_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
end module sph_input_reader