Add Solid input parsing

This commit is contained in:
Codex
2026-07-03 14:40:39 +08:00
parent a5728e021a
commit 56f37dea77
19 changed files with 777 additions and 29 deletions
+8
View File
@@ -452,6 +452,7 @@ contains
integer, intent(in) :: points
integer, intent(out) :: ierr
integer :: mat_index
integer :: set_index
ierr = SPH_SUCCESS
if (section_count >= SPH_MAX_SECTIONS) then
@@ -465,6 +466,13 @@ contains
ierr = SPH_ERROR_DATABASE
return
end if
set_index = sph_db_find_elset(name)
if (set_index <= 0) set_index = sph_db_find_nset(name)
if (set_index <= 0) then
call sph_error_set(SPH_ERROR_DATABASE, 'section references unknown set')
ierr = SPH_ERROR_DATABASE
return
end if
section_count = section_count + 1
section_name(section_count) = name
section_type(section_count) = stype
+3
View File
@@ -14,6 +14,9 @@ module sph_inp_defs
integer, parameter :: SPH_KEY_SECTION = 6
integer, parameter :: SPH_KEY_SPHLITE = 7
integer, parameter :: SPH_KEY_DENSITY = 8
integer, parameter :: SPH_KEY_ELASTIC = 9
integer, parameter :: SPH_KEY_PLASTIC = 10
integer, parameter :: SPH_KEY_DAMAGE_INITIATION = 11
integer, parameter :: SPH_KEY_UNKNOWN = 99
end module sph_inp_defs
+8 -1
View File
@@ -1,7 +1,8 @@
module sph_inp_helpers
use sph_inp_defs, only: SPH_INPUT_LINE_LEN, 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_UNKNOWN
SPH_KEY_SPHLITE, SPH_KEY_DENSITY, SPH_KEY_ELASTIC, &
SPH_KEY_PLASTIC, SPH_KEY_DAMAGE_INITIATION, SPH_KEY_UNKNOWN
implicit none
contains
@@ -85,6 +86,12 @@ contains
key_id = SPH_KEY_SPHLITE
else if (index(upper, '*DENSITY') == 1) then
key_id = SPH_KEY_DENSITY
else if (index(upper, '*ELASTIC') == 1) then
key_id = SPH_KEY_ELASTIC
else if (index(upper, '*PLASTIC') == 1) then
key_id = SPH_KEY_PLASTIC
else if (index(upper, '*DAMAGE INITIATION') == 1) then
key_id = SPH_KEY_DAMAGE_INITIATION
else if (index(upper, 'SECTION') > 0 .and. upper(1:1) == '*') then
key_id = SPH_KEY_SECTION
end if
+140 -2
View File
@@ -19,11 +19,16 @@ module sph_input_reader
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_validate_input, &
sph_solid_count_unbound_materials
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_UNKNOWN
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
@@ -79,6 +84,7 @@ contains
integer, intent(out) :: ierr
integer :: gas_unbound_count
integer :: explosive_unbound_count
integer :: solid_unbound_count
ierr = SPH_SUCCESS
if (npart <= 0) then
@@ -103,6 +109,8 @@ contains
end if
call sph_db_apply_sections_to_particles(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_solid_validate_input(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)
@@ -113,6 +121,8 @@ contains
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_neighbor_rebuild(ierr)
end subroutine sph_input_build_model
@@ -233,6 +243,24 @@ contains
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
@@ -246,6 +274,7 @@ contains
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
@@ -266,6 +295,7 @@ contains
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)
@@ -279,7 +309,9 @@ contains
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, &
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
@@ -302,6 +334,8 @@ contains
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
@@ -497,6 +531,22 @@ contains
call sph_gas_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
@@ -572,6 +622,94 @@ contains
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
+349
View File
@@ -1,15 +1,364 @@
module sph_solid
use sph_precision, only: rk
use sph_error, only: SPH_SUCCESS, SPH_ERROR_ARGUMENT, SPH_ERROR_INPUT, &
sph_error_set
use sph_database, only: SPH_MAX_MATERIALS, SPH_NAME_LEN, material_count, &
material_name, material_type, material_density, npart, particle_phase, &
particle_status, material_id, SPH_PHASE_SOLID, SPH_STATUS_ACTIVE
implicit none
logical :: solid_module_initialized = .false.
logical :: solid_material_seen = .false.
integer :: solid_material_count = 0
integer :: solid_material_ids(SPH_MAX_MATERIALS) = 0
character(len=SPH_NAME_LEN) :: solid_material_names(SPH_MAX_MATERIALS) = ' '
logical :: solid_elastic_defined(SPH_MAX_MATERIALS) = .false.
logical :: solid_johnson_cook_defined(SPH_MAX_MATERIALS) = .false.
logical :: solid_failure_defined(SPH_MAX_MATERIALS) = .false.
logical :: solid_control_defined(SPH_MAX_MATERIALS) = .false.
real(rk) :: solid_elastic_e(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: solid_elastic_nu(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: solid_jc_a(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: solid_jc_b(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: solid_jc_n(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: solid_jc_c(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: solid_jc_m(SPH_MAX_MATERIALS) = 0.0_rk
real(rk) :: solid_jc_epsdot0(SPH_MAX_MATERIALS) = 1.0_rk
real(rk) :: solid_jc_troom(SPH_MAX_MATERIALS) = 293.15_rk
real(rk) :: solid_jc_tmelt(SPH_MAX_MATERIALS) = 1793.0_rk
real(rk) :: solid_failure_d(5,SPH_MAX_MATERIALS) = 0.0_rk
character(len=SPH_NAME_LEN) :: solid_softening_type(SPH_MAX_MATERIALS) = ' '
real(rk) :: solid_softening_width(SPH_MAX_MATERIALS) = 0.0_rk
contains
subroutine sph_solid_initialize()
solid_module_initialized = .true.
call sph_solid_clear_material_table()
end subroutine sph_solid_initialize
subroutine sph_solid_reset()
solid_module_initialized = .false.
call sph_solid_clear_material_table()
end subroutine sph_solid_reset
subroutine sph_solid_clear_material_table()
solid_material_seen = .false.
solid_material_count = 0
solid_material_ids = 0
solid_material_names = ' '
solid_elastic_defined = .false.
solid_johnson_cook_defined = .false.
solid_failure_defined = .false.
solid_control_defined = .false.
solid_elastic_e = 0.0_rk
solid_elastic_nu = 0.0_rk
solid_jc_a = 0.0_rk
solid_jc_b = 0.0_rk
solid_jc_n = 0.0_rk
solid_jc_c = 0.0_rk
solid_jc_m = 0.0_rk
solid_jc_epsdot0 = 1.0_rk
solid_jc_troom = 293.15_rk
solid_jc_tmelt = 1793.0_rk
solid_failure_d = 0.0_rk
solid_softening_type = ' '
solid_softening_width = 0.0_rk
end subroutine sph_solid_clear_material_table
subroutine sph_solid_note_material(name, material_type_in)
character(len=*), intent(in) :: name
character(len=*), intent(in) :: material_type_in
integer :: solid_index
if (index(sph_solid_upper(material_type_in), 'SOLID') > 0) then
solid_material_seen = .true.
solid_index = sph_solid_register_material(name)
end if
end subroutine sph_solid_note_material
subroutine sph_solid_set_elastic(material_name_in, e_value, nu_value, ierr)
character(len=*), intent(in) :: material_name_in
real(rk), intent(in) :: e_value
real(rk), intent(in) :: nu_value
integer, intent(out) :: ierr
integer :: solid_index
ierr = SPH_SUCCESS
if (e_value <= 0.0_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Solid elastic modulus must be positive')
ierr = SPH_ERROR_ARGUMENT
return
end if
if (nu_value <= -1.0_rk .or. nu_value >= 0.5_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Solid Poisson ratio is invalid')
ierr = SPH_ERROR_ARGUMENT
return
end if
call sph_solid_prepare_material(material_name_in, solid_index, ierr)
if (ierr /= SPH_SUCCESS) return
solid_elastic_defined(solid_index) = .true.
solid_elastic_e(solid_index) = e_value
solid_elastic_nu(solid_index) = nu_value
end subroutine sph_solid_set_elastic
subroutine sph_solid_set_johnson_cook(material_name_in, a_value, b_value, &
n_value, c_value, m_value, epsdot0_value, troom_value, tmelt_value, ierr)
character(len=*), intent(in) :: material_name_in
real(rk), intent(in) :: a_value
real(rk), intent(in) :: b_value
real(rk), intent(in) :: n_value
real(rk), intent(in) :: c_value
real(rk), intent(in) :: m_value
real(rk), intent(in) :: epsdot0_value
real(rk), intent(in) :: troom_value
real(rk), intent(in) :: tmelt_value
integer, intent(out) :: ierr
integer :: solid_index
ierr = SPH_SUCCESS
if (a_value < 0.0_rk .or. b_value < 0.0_rk .or. n_value < 0.0_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Solid Johnson-Cook strength is invalid')
ierr = SPH_ERROR_ARGUMENT
return
end if
if (c_value < 0.0_rk .or. m_value < 0.0_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Solid Johnson-Cook rate or thermal exponent is invalid')
ierr = SPH_ERROR_ARGUMENT
return
end if
if (epsdot0_value <= 0.0_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Solid Johnson-Cook reference strain rate must be positive')
ierr = SPH_ERROR_ARGUMENT
return
end if
if (tmelt_value <= troom_value) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Solid Johnson-Cook melt temperature must exceed room temperature')
ierr = SPH_ERROR_ARGUMENT
return
end if
call sph_solid_prepare_material(material_name_in, solid_index, ierr)
if (ierr /= SPH_SUCCESS) return
solid_johnson_cook_defined(solid_index) = .true.
solid_jc_a(solid_index) = a_value
solid_jc_b(solid_index) = b_value
solid_jc_n(solid_index) = n_value
solid_jc_c(solid_index) = c_value
solid_jc_m(solid_index) = m_value
solid_jc_epsdot0(solid_index) = epsdot0_value
solid_jc_troom(solid_index) = troom_value
solid_jc_tmelt(solid_index) = tmelt_value
end subroutine sph_solid_set_johnson_cook
subroutine sph_solid_set_failure(material_name_in, d_values, ierr)
character(len=*), intent(in) :: material_name_in
real(rk), intent(in) :: d_values(5)
integer, intent(out) :: ierr
integer :: solid_index
ierr = SPH_SUCCESS
if (.not. sph_solid_vector_is_finite(d_values)) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Solid Johnson-Cook failure parameter is not finite')
ierr = SPH_ERROR_ARGUMENT
return
end if
call sph_solid_prepare_material(material_name_in, solid_index, ierr)
if (ierr /= SPH_SUCCESS) return
solid_failure_defined(solid_index) = .true.
solid_failure_d(:,solid_index) = d_values(:)
end subroutine sph_solid_set_failure
subroutine sph_solid_set_control(material_name_in, softening_name, &
softening_width_value, ierr)
character(len=*), intent(in) :: material_name_in
character(len=*), intent(in) :: softening_name
real(rk), intent(in) :: softening_width_value
integer, intent(out) :: ierr
integer :: solid_index
character(len=SPH_NAME_LEN) :: upper_softening
ierr = SPH_SUCCESS
upper_softening = sph_solid_upper(softening_name)
if (len_trim(upper_softening) == 0) upper_softening = 'LINEAR'
if (index(upper_softening, 'LINEAR') <= 0) then
call sph_error_set(SPH_ERROR_INPUT, 'Solid SOFTENING must be LINEAR')
ierr = SPH_ERROR_INPUT
return
end if
if (softening_width_value <= 0.0_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Solid softening WIDTH must be positive')
ierr = SPH_ERROR_ARGUMENT
return
end if
call sph_solid_prepare_material(material_name_in, solid_index, ierr)
if (ierr /= SPH_SUCCESS) return
solid_control_defined(solid_index) = .true.
solid_softening_type(solid_index) = upper_softening
solid_softening_width(solid_index) = softening_width_value
end subroutine sph_solid_set_control
subroutine sph_solid_validate_input(ierr)
integer, intent(out) :: ierr
integer :: solid_index
integer :: mat_index
ierr = SPH_SUCCESS
if (.not. solid_material_seen) return
do solid_index = 1, solid_material_count
mat_index = solid_material_ids(solid_index)
if (.not. sph_solid_has_active_particle(mat_index)) cycle
if (material_density(mat_index) <= 0.0_rk) then
call sph_error_set(SPH_ERROR_INPUT, 'active Solid material is missing density')
ierr = SPH_ERROR_INPUT
return
end if
if (.not. solid_elastic_defined(solid_index)) then
call sph_error_set(SPH_ERROR_INPUT, 'active Solid material is missing elastic data')
ierr = SPH_ERROR_INPUT
return
end if
if (solid_failure_defined(solid_index) .and. &
.not. solid_johnson_cook_defined(solid_index)) then
call sph_error_set(SPH_ERROR_INPUT, 'Solid failure requires Johnson-Cook flow data')
ierr = SPH_ERROR_INPUT
return
end if
end do
end subroutine sph_solid_validate_input
subroutine sph_solid_count_unbound_materials(count)
integer, intent(out) :: count
integer :: solid_index
count = 0
do solid_index = 1, solid_material_count
if (.not. sph_solid_has_active_particle(solid_material_ids(solid_index))) then
count = count + 1
end if
end do
end subroutine sph_solid_count_unbound_materials
integer function sph_solid_register_material(name)
character(len=*), intent(in) :: name
integer :: existing
integer :: mat_index
existing = sph_solid_find_solid_material(name)
if (existing > 0) then
sph_solid_register_material = existing
return
end if
if (solid_material_count >= SPH_MAX_MATERIALS) then
sph_solid_register_material = 0
return
end if
mat_index = sph_solid_find_material(name)
if (mat_index <= 0) then
sph_solid_register_material = 0
return
end if
solid_material_count = solid_material_count + 1
solid_material_ids(solid_material_count) = mat_index
solid_material_names(solid_material_count) = material_name(mat_index)
sph_solid_register_material = solid_material_count
end function sph_solid_register_material
subroutine sph_solid_prepare_material(name, solid_index, ierr)
character(len=*), intent(in) :: name
integer, intent(out) :: solid_index
integer, intent(out) :: ierr
integer :: mat_index
ierr = SPH_SUCCESS
solid_index = sph_solid_find_solid_material(name)
if (solid_index <= 0) then
mat_index = sph_solid_find_material(name)
if (mat_index <= 0) then
call sph_error_set(SPH_ERROR_INPUT, 'Solid material is unknown')
ierr = SPH_ERROR_INPUT
return
end if
if (index(sph_solid_upper(material_type(mat_index)), 'SOLID') <= 0) then
call sph_error_set(SPH_ERROR_INPUT, 'Solid data references non-Solid material')
ierr = SPH_ERROR_INPUT
return
end if
solid_index = sph_solid_register_material(name)
end if
if (solid_index <= 0) then
call sph_error_set(SPH_ERROR_INPUT, 'failed to register Solid material')
ierr = SPH_ERROR_INPUT
end if
end subroutine sph_solid_prepare_material
integer function sph_solid_find_solid_material(name)
character(len=*), intent(in) :: name
integer :: i
sph_solid_find_solid_material = 0
do i = 1, solid_material_count
if (trim(sph_solid_upper(solid_material_names(i))) == &
trim(sph_solid_upper(name))) then
sph_solid_find_solid_material = i
return
end if
end do
end function sph_solid_find_solid_material
integer function sph_solid_find_material(name)
character(len=*), intent(in) :: name
integer :: i
sph_solid_find_material = 0
do i = 1, material_count
if (trim(sph_solid_upper(material_name(i))) == trim(sph_solid_upper(name))) then
sph_solid_find_material = i
return
end if
end do
end function sph_solid_find_material
logical function sph_solid_has_active_particle(mat_index)
integer, intent(in) :: mat_index
integer :: i
sph_solid_has_active_particle = .false.
if (mat_index <= 0) return
do i = 1, npart
if (material_id(i) /= mat_index) cycle
if (particle_status(i) /= SPH_STATUS_ACTIVE) cycle
if (particle_phase(i) /= SPH_PHASE_SOLID) cycle
sph_solid_has_active_particle = .true.
return
end do
end function sph_solid_has_active_particle
logical function sph_solid_vector_is_finite(values)
real(rk), intent(in) :: values(:)
integer :: i
sph_solid_vector_is_finite = .true.
do i = 1, size(values)
if (values(i) /= values(i)) sph_solid_vector_is_finite = .false.
if (abs(values(i)) > huge(values(i)) * 0.5_rk) then
sph_solid_vector_is_finite = .false.
end if
end do
end function sph_solid_vector_is_finite
function sph_solid_upper(text) result(out)
character(len=*), intent(in) :: text
character(len=len(text)) :: out
integer :: i
integer :: code
out = text
do i = 1, len(out)
code = ichar(out(i:i))
if (code >= ichar('a') .and. code <= ichar('z')) then
out(i:i) = char(code - ichar('a') + ichar('A'))
end if
end do
end function sph_solid_upper
end module sph_solid