Validate SPHLite time control and particle state
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
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_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, &
|
||||
@@ -263,7 +264,8 @@ contains
|
||||
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)
|
||||
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
|
||||
@@ -291,6 +293,7 @@ contains
|
||||
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_water_eos(line, ierr)
|
||||
@@ -450,45 +453,6 @@ contains
|
||||
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)
|
||||
character(len=SPH_INPUT_FIELD_LEN) :: item
|
||||
character(len=SPH_INPUT_FIELD_LEN) :: key
|
||||
character(len=SPH_INPUT_FIELD_LEN) :: value
|
||||
integer :: nfields
|
||||
integer :: i
|
||||
integer :: eq_pos
|
||||
integer :: ios
|
||||
real(rk) :: dt
|
||||
real(rk) :: total_time
|
||||
integer :: steps
|
||||
real(rk) :: safety
|
||||
|
||||
dt = -1.0_rk
|
||||
total_time = -1.0_rk
|
||||
steps = -1
|
||||
safety = -1.0_rk
|
||||
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)))
|
||||
value = adjustl(item(eq_pos+1:len_trim(item)))
|
||||
if (index(key, 'DT') == 1) then
|
||||
read(value, *, iostat=ios) dt
|
||||
else if (index(key, 'TIME') == 1 .or. index(key, 'END TIME') == 1) then
|
||||
read(value, *, iostat=ios) total_time
|
||||
else if (index(key, 'STEPS') == 1 .or. index(key, 'MAX STEPS') == 1) then
|
||||
read(value, *, iostat=ios) steps
|
||||
else if (index(key, 'SAFETY') == 1) then
|
||||
read(value, *, iostat=ios) safety
|
||||
end if
|
||||
end do
|
||||
call sph_control_set_time(dt, total_time, steps, safety)
|
||||
end subroutine sph_input_parse_time_control
|
||||
|
||||
subroutine sph_input_parse_node(line, node_index, ierr)
|
||||
character(len=*), intent(in) :: line
|
||||
integer, intent(in) :: node_index
|
||||
@@ -678,4 +642,18 @@ contains
|
||||
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
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
module sph_input_time
|
||||
use sph_precision, only: rk
|
||||
use sph_error, only: SPH_SUCCESS, SPH_ERROR_INPUT, sph_error_set, &
|
||||
sph_error_get
|
||||
use sph_control, only: sph_control_set_time, sph_control_validate_time
|
||||
use sph_inp_defs, only: SPH_INPUT_FIELD_LEN, SPH_INPUT_MAX_FIELDS, &
|
||||
SPH_INPUT_LINE_LEN
|
||||
use sph_inp_helpers, only: sph_inp_split_csv, sph_inp_upper
|
||||
implicit none
|
||||
|
||||
contains
|
||||
|
||||
subroutine sph_input_parse_time_control(line, filename, line_number, ierr)
|
||||
character(len=*), intent(in) :: line
|
||||
character(len=*), intent(in) :: filename
|
||||
integer, intent(in) :: line_number
|
||||
integer, intent(out) :: ierr
|
||||
character(len=SPH_INPUT_FIELD_LEN) :: fields(SPH_INPUT_MAX_FIELDS)
|
||||
character(len=SPH_INPUT_FIELD_LEN) :: key
|
||||
character(len=SPH_INPUT_FIELD_LEN) :: value
|
||||
integer :: nfields
|
||||
integer :: i
|
||||
integer :: eq_pos
|
||||
real(rk) :: dt
|
||||
real(rk) :: total_time
|
||||
integer :: steps
|
||||
real(rk) :: safety
|
||||
logical :: has_dt
|
||||
logical :: has_time
|
||||
logical :: has_steps
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
dt = -1.0_rk
|
||||
total_time = -1.0_rk
|
||||
steps = -1
|
||||
safety = 1.0_rk
|
||||
has_dt = .false.
|
||||
has_time = .false.
|
||||
has_steps = .false.
|
||||
call sph_inp_split_csv(line, fields, nfields)
|
||||
do i = 1, nfields
|
||||
eq_pos = index(fields(i), '=')
|
||||
if (eq_pos <= 0) cycle
|
||||
key = sph_inp_upper(adjustl(fields(i)(1:eq_pos-1)))
|
||||
value = adjustl(fields(i)(eq_pos+1:len_trim(fields(i))))
|
||||
call sph_input_time_parse_item(key, value, dt, total_time, steps, &
|
||||
safety, has_dt, has_time, has_steps, filename, line_number, ierr)
|
||||
if (ierr /= SPH_SUCCESS) return
|
||||
end do
|
||||
if (.not. has_dt .or. .not. has_time .or. .not. has_steps) then
|
||||
call sph_input_time_set_error(filename, line_number, &
|
||||
'missing required SPHLITE TIME CONTROL option', ierr)
|
||||
return
|
||||
end if
|
||||
call sph_control_validate_time(dt, total_time, steps, safety, ierr)
|
||||
if (ierr /= SPH_SUCCESS) then
|
||||
call sph_input_time_prefix_error(filename, line_number, ierr)
|
||||
return
|
||||
end if
|
||||
call sph_control_set_time(dt, total_time, steps, safety)
|
||||
end subroutine sph_input_parse_time_control
|
||||
|
||||
subroutine sph_input_time_parse_item(key, value, dt, total_time, steps, &
|
||||
safety, has_dt, has_time, has_steps, filename, line_number, ierr)
|
||||
character(len=*), intent(in) :: key
|
||||
character(len=*), intent(in) :: value
|
||||
real(rk), intent(inout) :: dt
|
||||
real(rk), intent(inout) :: total_time
|
||||
integer, intent(inout) :: steps
|
||||
real(rk), intent(inout) :: safety
|
||||
logical, intent(inout) :: has_dt
|
||||
logical, intent(inout) :: has_time
|
||||
logical, intent(inout) :: has_steps
|
||||
character(len=*), intent(in) :: filename
|
||||
integer, intent(in) :: line_number
|
||||
integer, intent(out) :: ierr
|
||||
integer :: ios
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
if (index(key, 'DT') == 1) then
|
||||
read(value, *, iostat=ios) dt
|
||||
has_dt = ios == 0
|
||||
if (ios /= 0) call sph_input_time_set_error(filename, line_number, &
|
||||
'invalid SPHLITE TIME CONTROL DT', ierr)
|
||||
else if (index(key, 'TIME') == 1 .or. index(key, 'END TIME') == 1) then
|
||||
read(value, *, iostat=ios) total_time
|
||||
has_time = ios == 0
|
||||
if (ios /= 0) call sph_input_time_set_error(filename, line_number, &
|
||||
'invalid SPHLITE TIME CONTROL TIME', ierr)
|
||||
else if (index(key, 'STEPS') == 1 .or. index(key, 'MAX STEPS') == 1) then
|
||||
read(value, *, iostat=ios) steps
|
||||
has_steps = ios == 0
|
||||
if (ios /= 0) call sph_input_time_set_error(filename, line_number, &
|
||||
'invalid SPHLITE TIME CONTROL STEPS', ierr)
|
||||
else if (index(key, 'SAFETY') == 1) then
|
||||
read(value, *, iostat=ios) safety
|
||||
if (ios /= 0) call sph_input_time_set_error(filename, line_number, &
|
||||
'invalid SPHLITE TIME CONTROL SAFETY', ierr)
|
||||
end if
|
||||
end subroutine sph_input_time_parse_item
|
||||
|
||||
subroutine sph_input_time_set_error(filename, line_number, message, ierr)
|
||||
character(len=*), intent(in) :: filename
|
||||
integer, intent(in) :: line_number
|
||||
character(len=*), intent(in) :: message
|
||||
integer, intent(out) :: ierr
|
||||
character(len=SPH_INPUT_LINE_LEN) :: full_message
|
||||
|
||||
write(full_message, '(A,":",I0,": ",A)') trim(filename), line_number, &
|
||||
trim(message)
|
||||
call sph_error_set(SPH_ERROR_INPUT, trim(full_message))
|
||||
ierr = SPH_ERROR_INPUT
|
||||
end subroutine sph_input_time_set_error
|
||||
|
||||
subroutine sph_input_time_prefix_error(filename, line_number, ierr)
|
||||
character(len=*), intent(in) :: filename
|
||||
integer, intent(in) :: line_number
|
||||
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)
|
||||
write(full_message, '(A,":",I0,": ",A)') trim(filename), line_number, &
|
||||
trim(message)
|
||||
call sph_error_set(code, trim(full_message))
|
||||
end subroutine sph_input_time_prefix_error
|
||||
|
||||
end module sph_input_time
|
||||
Reference in New Issue
Block a user