module fem_inp_reader use fem_precision use fem_error use fem_log use fem_control use fem_database implicit none integer, parameter :: LINE_LEN = 512 integer, parameter :: MODE_NONE = 0 integer, parameter :: MODE_NODE = 1 integer, parameter :: MODE_ELEMENT = 2 integer, parameter :: MODE_NSET = 3 integer, parameter :: MODE_ELSET = 4 integer, parameter :: MODE_DENSITY = 5 integer, parameter :: MODE_ELASTIC = 6 integer, parameter :: MODE_SHELL_SECTION = 7 integer, parameter :: MODE_BOUNDARY = 8 integer, parameter :: MODE_CLOAD = 9 integer, parameter :: MODE_DLOAD = 10 integer, parameter :: MODE_PLASTIC = 11 integer, parameter :: MODE_DAMAGE_INIT = 12 integer, parameter :: MODE_DYNAMIC = 13 integer, parameter :: MODE_AMPLITUDE = 14 integer, parameter :: MODE_JC_PLASTIC = 15 integer, parameter :: MODE_RATE_DEPENDENT = 16 integer, parameter :: MODE_SPECIFIC_HEAT = 17 integer, parameter :: MODE_INELASTIC_HEAT_FRACTION = 18 integer, parameter :: MODE_STATIC = 19 contains subroutine inp_read_file(filename, ierr) character(len=*), intent(in) :: filename integer, intent(out) :: ierr integer :: node_count integer :: elem_count integer :: nset_count_total integer :: elset_count_total integer :: nset_item_count integer :: elset_item_count integer :: material_count integer :: plastic_item_count integer :: section_count integer :: amplitude_count integer :: amplitude_item_count integer :: bc_count integer :: cload_count integer :: dload_count call inp_count_model(filename, node_count, elem_count, nset_count_total, & elset_count_total, nset_item_count, elset_item_count, & material_count, plastic_item_count, section_count, & amplitude_count, amplitude_item_count, bc_count, & cload_count, dload_count, ierr) if (ierr .ne. FEM_SUCCESS) return call database_allocate_model(node_count, elem_count, nset_count_total, & elset_count_total, nset_item_count, & elset_item_count, material_count, & plastic_item_count, section_count, & amplitude_count, amplitude_item_count, & bc_count, cload_count, dload_count, ierr) if (ierr .ne. FEM_SUCCESS) return call inp_fill_model(filename, ierr) if (ierr .ne. FEM_SUCCESS) return call inp_apply_sections(ierr) if (ierr .ne. FEM_SUCCESS) return call database_assign_dofs(ierr) if (ierr .ne. FEM_SUCCESS) return call log_info('INP model read completed') end subroutine inp_read_file subroutine inp_count_model(filename, node_count, elem_count, nset_count_total, & elset_count_total, nset_item_count, elset_item_count, & material_count, plastic_item_count, section_count, & amplitude_count, amplitude_item_count, bc_count, & cload_count, dload_count, ierr) character(len=*), intent(in) :: filename integer, intent(out) :: node_count integer, intent(out) :: elem_count integer, intent(out) :: nset_count_total integer, intent(out) :: elset_count_total integer, intent(out) :: nset_item_count integer, intent(out) :: elset_item_count integer, intent(out) :: material_count integer, intent(out) :: plastic_item_count integer, intent(out) :: section_count integer, intent(out) :: amplitude_count integer, intent(out) :: amplitude_item_count integer, intent(out) :: bc_count integer, intent(out) :: cload_count integer, intent(out) :: dload_count integer, intent(out) :: ierr integer :: unit_id integer :: ios integer :: mode logical :: generate_mode logical :: element_elset_active character(len=LINE_LEN) :: line character(len=LINE_LEN) :: clean character(len=LINE_LEN) :: set_name node_count = 0 elem_count = 0 nset_count_total = 0 elset_count_total = 0 nset_item_count = 0 elset_item_count = 0 material_count = 0 plastic_item_count = 0 section_count = 0 amplitude_count = 0 amplitude_item_count = 0 bc_count = 0 cload_count = 0 dload_count = 0 mode = MODE_NONE generate_mode = .false. element_elset_active = .false. unit_id = 21 open(unit=unit_id, file=filename, status='old', action='read', iostat=ios) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to open input file: '//trim(filename), ierr) return end if do read(unit_id,'(A)',iostat=ios) line if (ios .ne. 0) exit call clean_line(line, clean) if (len_trim(clean) .eq. 0) cycle if (clean(1:1) .eq. '*') then call count_keyword(clean, mode, generate_mode, element_elset_active, & nset_count_total, elset_count_total, & material_count, section_count, amplitude_count) else if (mode .eq. MODE_NODE) then node_count = node_count + 1 else if (mode .eq. MODE_ELEMENT) then elem_count = elem_count + 1 if (element_elset_active) elset_item_count = elset_item_count + 1 else if (mode .eq. MODE_NSET) then nset_item_count = nset_item_count + count_set_items(clean, generate_mode) else if (mode .eq. MODE_ELSET) then elset_item_count = elset_item_count + count_set_items(clean, generate_mode) else if (mode .eq. MODE_BOUNDARY) then bc_count = bc_count + 1 else if (mode .eq. MODE_CLOAD) then cload_count = cload_count + 1 else if (mode .eq. MODE_DLOAD) then dload_count = dload_count + 1 else if (mode .eq. MODE_PLASTIC) then plastic_item_count = plastic_item_count + 1 else if (mode .eq. MODE_AMPLITUDE) then amplitude_item_count = amplitude_item_count + count_amplitude_items(clean) end if end do close(unit_id) if (node_count .le. 0) then call error_set(FEM_ERR_INPUT, 'input file contains no nodes', ierr) return end if if (elem_count .le. 0) then call error_set(FEM_ERR_INPUT, 'input file contains no elements', ierr) return end if set_name = ' ' ierr = FEM_SUCCESS end subroutine inp_count_model subroutine count_keyword(line, mode, generate_mode, element_elset_active, & nset_count_total, elset_count_total, & material_count, section_count, amplitude_count) character(len=*), intent(in) :: line integer, intent(out) :: mode logical, intent(out) :: generate_mode logical, intent(out) :: element_elset_active integer, intent(inout) :: nset_count_total integer, intent(inout) :: elset_count_total integer, intent(inout) :: material_count integer, intent(inout) :: section_count integer, intent(inout) :: amplitude_count character(len=LINE_LEN) :: upper character(len=NAME_LEN) :: name_value call to_upper(line, upper) mode = MODE_NONE generate_mode = .false. element_elset_active = .false. if (starts_with(upper, '*NODE')) then mode = MODE_NODE else if (starts_with(upper, '*ELEMENT')) then mode = MODE_ELEMENT call get_keyword_value(upper, 'ELSET', name_value) if (len_trim(name_value) .gt. 0) then elset_count_total = elset_count_total + 1 element_elset_active = .true. end if else if (starts_with(upper, '*NSET')) then mode = MODE_NSET generate_mode = has_parameter(upper, 'GENERATE') nset_count_total = nset_count_total + 1 else if (starts_with(upper, '*ELSET')) then mode = MODE_ELSET generate_mode = has_parameter(upper, 'GENERATE') elset_count_total = elset_count_total + 1 else if (starts_with(upper, '*MATERIAL')) then material_count = material_count + 1 else if (starts_with(upper, '*PLASTIC')) then if (is_johnson_cook_plastic_keyword(upper)) then mode = MODE_JC_PLASTIC else mode = MODE_PLASTIC end if else if (starts_with(upper, '*DAMAGE INITIATION')) then mode = MODE_DAMAGE_INIT else if (starts_with(upper, '*RATE DEPENDENT')) then mode = MODE_RATE_DEPENDENT else if (starts_with(upper, '*SPECIFIC HEAT')) then mode = MODE_SPECIFIC_HEAT else if (starts_with(upper, '*INELASTIC HEAT FRACTION')) then mode = MODE_INELASTIC_HEAT_FRACTION else if (starts_with(upper, '*SOLID SECTION')) then section_count = section_count + 1 else if (starts_with(upper, '*SHELL SECTION')) then section_count = section_count + 1 else if (starts_with(upper, '*BOUNDARY')) then mode = MODE_BOUNDARY else if (starts_with(upper, '*CLOAD')) then mode = MODE_CLOAD else if (starts_with(upper, '*DLOAD')) then mode = MODE_DLOAD else if (starts_with(upper, '*DYNAMIC')) then mode = MODE_DYNAMIC else if (starts_with(upper, '*STATIC')) then mode = MODE_STATIC else if (starts_with(upper, '*AMPLITUDE')) then mode = MODE_AMPLITUDE amplitude_count = amplitude_count + 1 end if end subroutine count_keyword subroutine inp_fill_model(filename, ierr) character(len=*), intent(in) :: filename integer, intent(out) :: ierr integer :: unit_id integer :: ios integer :: mode integer :: inode integer :: ielem integer :: current_nset integer :: current_elset integer :: current_material integer :: current_section integer :: current_amp integer :: current_load_amp integer :: current_bc integer :: current_cload integer :: current_dload integer :: plastic_pos integer :: amp_pos integer :: nset_pos integer :: elset_pos integer :: nvals integer :: node_id integer :: elem_id integer :: conn_ext(MAX_NEN) integer :: conn_int integer :: i real(rk) :: x real(rk) :: y real(rk) :: z character(len=LINE_LEN) :: line character(len=LINE_LEN) :: clean character(len=LINE_LEN) :: upper character(len=ELEM_TYPE_LEN) :: current_elem_type logical :: generate_mode logical :: current_element_elset_active unit_id = 22 mode = MODE_NONE inode = 0 ielem = 0 current_nset = 0 current_elset = 0 current_material = 0 current_section = 0 current_amp = 0 current_load_amp = 0 current_bc = 0 current_cload = 0 current_dload = 0 plastic_pos = 0 amp_pos = 0 nset_pos = 0 elset_pos = 0 current_elem_type = ' ' generate_mode = .false. current_element_elset_active = .false. open(unit=unit_id, file=filename, status='old', action='read', iostat=ios) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to open input file: '//trim(filename), ierr) return end if do read(unit_id,'(A)',iostat=ios) line if (ios .ne. 0) exit call clean_line(line, clean) if (len_trim(clean) .eq. 0) cycle if (clean(1:1) .eq. '*') then call to_upper(clean, upper) call fill_keyword(upper, mode, generate_mode, current_element_elset_active, & current_elem_type, current_nset, current_elset, & current_material, current_section, current_amp, & current_load_amp, nset_pos, elset_pos, amp_pos, ierr) if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_NODE) then inode = inode + 1 call parse_node_line(clean, node_id, x, y, z, ierr) if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if node_id_ext(inode) = node_id coord0(1,inode) = x coord0(2,inode) = y coord0(3,inode) = z coord(:,inode) = coord0(:,inode) else if (mode .eq. MODE_ELEMENT) then ielem = ielem + 1 call parse_element_line(clean, elem_id, conn_ext, nvals, ierr) if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if elem_id_ext(ielem) = elem_id elem_type(ielem) = current_elem_type elem_nnode(ielem) = nvals elem_status(ielem) = 0 elem_mat(ielem) = 0 elem_sec(ielem) = 0 do i = 1, nvals conn_int = database_find_node(conn_ext(i)) if (conn_int .eq. 0) then close(unit_id) call error_set(FEM_ERR_INPUT, 'element references unknown node id', ierr) return end if elem_conn(i,ielem) = conn_int end do if (current_element_elset_active) then call add_elset_item(current_elset, elset_pos, elem_id) end if else if (mode .eq. MODE_NSET) then call add_set_line(clean, generate_mode, current_nset, nset_pos, .true., ierr) if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_ELSET) then call add_set_line(clean, generate_mode, current_elset, elset_pos, .false., ierr) if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_DENSITY) then call parse_density_line(clean, current_material, ierr) mode = MODE_NONE if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_ELASTIC) then call parse_elastic_line(clean, current_material, ierr) mode = MODE_NONE if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_PLASTIC) then call parse_plastic_line(clean, current_material, plastic_pos, ierr) if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_JC_PLASTIC) then call parse_jc_plastic_line(clean, current_material, ierr) mode = MODE_NONE if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_DAMAGE_INIT) then call parse_damage_init_line(clean, current_material, ierr) mode = MODE_NONE if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_RATE_DEPENDENT) then call parse_rate_dependent_line(clean, current_material, ierr) mode = MODE_NONE if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_SPECIFIC_HEAT) then call parse_specific_heat_line(clean, current_material, ierr) mode = MODE_NONE if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_INELASTIC_HEAT_FRACTION) then call parse_heat_fraction_line(clean, current_material, ierr) mode = MODE_NONE if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_DYNAMIC) then call parse_dynamic_line(clean, ierr) mode = MODE_NONE if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_STATIC) then call parse_static_line(clean, ierr) mode = MODE_NONE if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_AMPLITUDE) then call parse_amplitude_line(clean, current_amp, amp_pos, ierr) if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_SHELL_SECTION) then call parse_shell_section_line(clean, current_section, ierr) mode = MODE_NONE if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_BOUNDARY) then current_bc = current_bc + 1 call parse_boundary_line(clean, current_bc, current_load_amp, ierr) if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_CLOAD) then current_cload = current_cload + 1 call parse_cload_line(clean, current_cload, current_load_amp, ierr) if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if else if (mode .eq. MODE_DLOAD) then current_dload = current_dload + 1 call parse_dload_line(clean, current_dload, current_load_amp, ierr) if (ierr .ne. FEM_SUCCESS) then close(unit_id) return end if end if end do close(unit_id) ierr = FEM_SUCCESS end subroutine inp_fill_model subroutine fill_keyword(line, mode, generate_mode, element_elset_active, & current_elem_type, current_nset, current_elset, & current_material, current_section, current_amp, & current_load_amp, nset_pos, elset_pos, amp_pos, ierr) character(len=*), intent(in) :: line integer, intent(out) :: mode logical, intent(out) :: generate_mode logical, intent(out) :: element_elset_active character(len=*), intent(out) :: current_elem_type integer, intent(inout) :: current_nset integer, intent(inout) :: current_elset integer, intent(inout) :: current_material integer, intent(inout) :: current_section integer, intent(inout) :: current_amp integer, intent(out) :: current_load_amp integer, intent(inout) :: nset_pos integer, intent(inout) :: elset_pos integer, intent(in) :: amp_pos integer, intent(out) :: ierr character(len=NAME_LEN) :: name_value mode = MODE_NONE generate_mode = .false. element_elset_active = .false. current_load_amp = 0 ierr = FEM_SUCCESS if (starts_with(line, '*NODE')) then mode = MODE_NODE else if (starts_with(line, '*ELEMENT')) then mode = MODE_ELEMENT call get_keyword_value(line, 'TYPE', current_elem_type) if (len_trim(current_elem_type) .eq. 0) then call error_set(FEM_ERR_INPUT, '*ELEMENT is missing TYPE parameter', ierr) return end if call get_keyword_value(line, 'ELSET', name_value) if (len_trim(name_value) .gt. 0) then current_elset = current_elset + 1 call start_elset(current_elset, elset_pos, name_value) element_elset_active = .true. end if else if (starts_with(line, '*NSET')) then mode = MODE_NSET generate_mode = has_parameter(line, 'GENERATE') call get_keyword_value(line, 'NSET', name_value) if (len_trim(name_value) .eq. 0) then call error_set(FEM_ERR_INPUT, '*NSET is missing NSET parameter', ierr) return end if current_nset = current_nset + 1 call start_nset(current_nset, nset_pos, name_value) else if (starts_with(line, '*ELSET')) then mode = MODE_ELSET generate_mode = has_parameter(line, 'GENERATE') call get_keyword_value(line, 'ELSET', name_value) if (len_trim(name_value) .eq. 0) then call error_set(FEM_ERR_INPUT, '*ELSET is missing ELSET parameter', ierr) return end if current_elset = current_elset + 1 call start_elset(current_elset, elset_pos, name_value) else if (starts_with(line, '*MATERIAL')) then current_material = current_material + 1 call get_keyword_value(line, 'NAME', name_value) if (len_trim(name_value) .eq. 0) then call error_set(FEM_ERR_INPUT, '*MATERIAL is missing NAME parameter', ierr) return end if mat_name(current_material) = name_value else if (starts_with(line, '*DENSITY')) then mode = MODE_DENSITY else if (starts_with(line, '*ELASTIC')) then mode = MODE_ELASTIC else if (starts_with(line, '*PLASTIC')) then if (current_material .le. 0) then call error_set(FEM_ERR_INPUT, '*PLASTIC appears before *MATERIAL', ierr) return end if if (is_johnson_cook_plastic_keyword(line)) then mat_plastic_model(current_material) = 'J2_JC' mode = MODE_JC_PLASTIC else mat_plastic_model(current_material) = 'J2' mode = MODE_PLASTIC end if else if (starts_with(line, '*DAMAGE INITIATION')) then if (current_material .le. 0) then call error_set(FEM_ERR_INPUT, '*DAMAGE INITIATION appears before *MATERIAL', ierr) return end if if (is_johnson_cook_damage_keyword(line)) then mat_failure_model(current_material) = 'JOHNSON_COOK' else mat_failure_model(current_material) = 'EQPS' end if mode = MODE_DAMAGE_INIT else if (starts_with(line, '*RATE DEPENDENT')) then if (current_material .le. 0) then call error_set(FEM_ERR_INPUT, '*RATE DEPENDENT appears before *MATERIAL', ierr) return end if if (.not. is_johnson_cook_rate_keyword(line)) then call error_set(FEM_ERR_INPUT, 'only Johnson-Cook rate dependence is supported', ierr) return end if mat_rate_model(current_material) = 'JOHNSON_COOK' mode = MODE_RATE_DEPENDENT else if (starts_with(line, '*SPECIFIC HEAT')) then if (current_material .le. 0) then call error_set(FEM_ERR_INPUT, '*SPECIFIC HEAT appears before *MATERIAL', ierr) return end if mode = MODE_SPECIFIC_HEAT else if (starts_with(line, '*INELASTIC HEAT FRACTION')) then if (current_material .le. 0) then call error_set(FEM_ERR_INPUT, '*INELASTIC HEAT FRACTION appears before *MATERIAL', ierr) return end if mode = MODE_INELASTIC_HEAT_FRACTION else if (starts_with(line, '*SOLID SECTION')) then current_section = current_section + 1 call fill_section_header(line, current_section, 'SOLID', ierr) else if (starts_with(line, '*SHELL SECTION')) then current_section = current_section + 1 call fill_section_header(line, current_section, 'SHELL', ierr) mode = MODE_SHELL_SECTION else if (starts_with(line, '*BOUNDARY')) then mode = MODE_BOUNDARY else if (starts_with(line, '*CLOAD')) then mode = MODE_CLOAD else if (starts_with(line, '*DLOAD')) then mode = MODE_DLOAD else if (starts_with(line, '*DYNAMIC')) then analysis_type = ANALYSIS_EXPLICIT_DYNAMIC mode = MODE_DYNAMIC else if (starts_with(line, '*STATIC')) then call set_static_defaults() mode = MODE_STATIC else if (starts_with(line, '*AMPLITUDE')) then mode = MODE_AMPLITUDE call get_keyword_value(line, 'NAME', name_value) if (len_trim(name_value) .eq. 0) then call error_set(FEM_ERR_INPUT, '*AMPLITUDE is missing NAME parameter', ierr) return end if current_amp = current_amp + 1 amp_name(current_amp) = name_value amp_start(current_amp) = amp_pos + 1 amp_count(current_amp) = 0 end if if (mode .eq. MODE_BOUNDARY .or. mode .eq. MODE_CLOAD .or. & mode .eq. MODE_DLOAD) then call get_keyword_value(line, 'AMPLITUDE', name_value) if (len_trim(name_value) .gt. 0) then current_load_amp = database_find_amplitude(name_value) if (current_load_amp .eq. 0) then call error_set(FEM_ERR_INPUT, 'load references unknown amplitude', ierr) return end if end if end if end subroutine fill_keyword subroutine start_nset(set_index, item_pos, set_name_value) integer, intent(in) :: set_index integer, intent(in) :: item_pos character(len=*), intent(in) :: set_name_value nset_name(set_index) = set_name_value nset_start(set_index) = item_pos + 1 nset_count(set_index) = 0 end subroutine start_nset subroutine start_elset(set_index, item_pos, set_name_value) integer, intent(in) :: set_index integer, intent(in) :: item_pos character(len=*), intent(in) :: set_name_value elset_name(set_index) = set_name_value elset_start(set_index) = item_pos + 1 elset_count(set_index) = 0 end subroutine start_elset subroutine add_elset_item(set_index, item_pos, item_value) integer, intent(in) :: set_index integer, intent(inout) :: item_pos integer, intent(in) :: item_value item_pos = item_pos + 1 elset_items(item_pos) = item_value elset_count(set_index) = elset_count(set_index) + 1 end subroutine add_elset_item subroutine add_set_line(line, generate_mode, set_index, item_pos, is_node_set, ierr) character(len=*), intent(in) :: line logical, intent(in) :: generate_mode integer, intent(in) :: set_index integer, intent(inout) :: item_pos logical, intent(in) :: is_node_set integer, intent(out) :: ierr integer :: start_value integer :: end_value integer :: increment integer :: value integer :: field integer :: ios character(len=LINE_LEN) :: token if (generate_mode) then call parse_generate_line(line, start_value, end_value, increment, ierr) if (ierr .ne. FEM_SUCCESS) return value = start_value do if ((increment .gt. 0 .and. value .gt. end_value) .or. & (increment .lt. 0 .and. value .lt. end_value)) exit call add_set_item(set_index, item_pos, is_node_set, value) value = value + increment end do else do field = 1, MAX_NEN call csv_token(line, field, token) if (len_trim(token) .eq. 0) exit read(token,*,iostat=ios) value if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse set item', ierr) return end if call add_set_item(set_index, item_pos, is_node_set, value) end do end if ierr = FEM_SUCCESS end subroutine add_set_line subroutine add_set_item(set_index, item_pos, is_node_set, item_value) integer, intent(in) :: set_index integer, intent(inout) :: item_pos logical, intent(in) :: is_node_set integer, intent(in) :: item_value item_pos = item_pos + 1 if (is_node_set) then nset_items(item_pos) = item_value nset_count(set_index) = nset_count(set_index) + 1 else elset_items(item_pos) = item_value elset_count(set_index) = elset_count(set_index) + 1 end if end subroutine add_set_item subroutine fill_section_header(line, section_index, type_name, ierr) character(len=*), intent(in) :: line integer, intent(in) :: section_index character(len=*), intent(in) :: type_name integer, intent(out) :: ierr character(len=NAME_LEN) :: name_value section_type(section_index) = type_name call get_keyword_value(line, 'ELSET', name_value) if (len_trim(name_value) .eq. 0) then call error_set(FEM_ERR_INPUT, 'section is missing ELSET parameter', ierr) return end if section_elset_name(section_index) = name_value call get_keyword_value(line, 'MATERIAL', name_value) if (len_trim(name_value) .eq. 0) then call error_set(FEM_ERR_INPUT, 'section is missing MATERIAL parameter', ierr) return end if section_material_name(section_index) = name_value ierr = FEM_SUCCESS end subroutine fill_section_header subroutine parse_density_line(line, material_index, ierr) character(len=*), intent(in) :: line integer, intent(in) :: material_index integer, intent(out) :: ierr character(len=LINE_LEN) :: token integer :: ios if (material_index .le. 0) then call error_set(FEM_ERR_INPUT, '*DENSITY appears before *MATERIAL', ierr) return end if call csv_token(line, 1, token) read(token,*,iostat=ios) mat_density(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse material density', ierr) return end if ierr = FEM_SUCCESS end subroutine parse_density_line subroutine parse_elastic_line(line, material_index, ierr) character(len=*), intent(in) :: line integer, intent(in) :: material_index integer, intent(out) :: ierr character(len=LINE_LEN) :: token integer :: ios if (material_index .le. 0) then call error_set(FEM_ERR_INPUT, '*ELASTIC appears before *MATERIAL', ierr) return end if call csv_token(line, 1, token) read(token,*,iostat=ios) mat_e(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse elastic modulus', ierr) return end if call csv_token(line, 2, token) read(token,*,iostat=ios) mat_nu(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Poisson ratio', ierr) return end if ierr = FEM_SUCCESS end subroutine parse_elastic_line subroutine parse_plastic_line(line, material_index, plastic_pos, ierr) character(len=*), intent(in) :: line integer, intent(in) :: material_index integer, intent(inout) :: plastic_pos integer, intent(out) :: ierr character(len=LINE_LEN) :: token real(rk) :: yield_stress real(rk) :: plastic_strain integer :: ios if (material_index .le. 0) then call error_set(FEM_ERR_INPUT, '*PLASTIC data appears before *MATERIAL', ierr) return end if if (.not. allocated(mat_plastic_stress)) then call error_set(FEM_ERR_INPUT, '*PLASTIC data storage is not allocated', ierr) return end if call csv_token(line, 1, token) read(token,*,iostat=ios) yield_stress if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse plastic yield stress', ierr) return end if call csv_token(line, 2, token) if (len_trim(token) .eq. 0) then plastic_strain = ZERO else read(token,*,iostat=ios) plastic_strain if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse plastic strain', ierr) return end if end if if (yield_stress .le. ZERO) then call error_set(FEM_ERR_INPUT, 'plastic yield stress must be positive', ierr) return end if if (plastic_strain .lt. ZERO) then call error_set(FEM_ERR_INPUT, 'plastic strain must be non-negative', ierr) return end if plastic_pos = plastic_pos + 1 if (plastic_pos .gt. n_plastic_item) then call error_set(FEM_ERR_INTERNAL, 'plastic curve item count overflow', ierr) return end if if (mat_plastic_count(material_index) .eq. 0) then mat_plastic_start(material_index) = plastic_pos mat_yield0(material_index) = yield_stress end if mat_plastic_count(material_index) = mat_plastic_count(material_index) + 1 mat_plastic_stress(plastic_pos) = yield_stress mat_plastic_strain(plastic_pos) = plastic_strain call update_material_hardening(material_index) ierr = FEM_SUCCESS end subroutine parse_plastic_line subroutine update_material_hardening(material_index) integer, intent(in) :: material_index integer :: start_pos integer :: count real(rk) :: deps start_pos = mat_plastic_start(material_index) count = mat_plastic_count(material_index) if (count .le. 1) then mat_hardening_modulus(material_index) = ZERO else deps = mat_plastic_strain(start_pos + 1) - mat_plastic_strain(start_pos) if (deps .gt. ZERO) then mat_hardening_modulus(material_index) = & (mat_plastic_stress(start_pos + 1) - mat_plastic_stress(start_pos)) / deps else mat_hardening_modulus(material_index) = ZERO end if end if end subroutine update_material_hardening subroutine parse_jc_plastic_line(line, material_index, ierr) character(len=*), intent(in) :: line integer, intent(in) :: material_index integer, intent(out) :: ierr character(len=LINE_LEN) :: token integer :: ios if (material_index .le. 0) then call error_set(FEM_ERR_INPUT, 'Johnson-Cook plastic data appears before *MATERIAL', ierr) return end if call csv_token(line, 1, token) read(token,*,iostat=ios) mat_jc_a(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Johnson-Cook A', ierr) return end if call csv_token(line, 2, token) read(token,*,iostat=ios) mat_jc_b(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Johnson-Cook B', ierr) return end if call csv_token(line, 3, token) read(token,*,iostat=ios) mat_jc_n(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Johnson-Cook n', ierr) return end if call csv_token(line, 4, token) if (len_trim(token) .gt. 0) then read(token,*,iostat=ios) mat_jc_m(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Johnson-Cook m', ierr) return end if if (mat_jc_m(material_index) .gt. ZERO) mat_temp_model(material_index) = 'JOHNSON_COOK' end if call csv_token(line, 5, token) if (len_trim(token) .gt. 0) then read(token,*,iostat=ios) mat_jc_tmelt(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Johnson-Cook melt temperature', ierr) return end if end if call csv_token(line, 6, token) if (len_trim(token) .gt. 0) then read(token,*,iostat=ios) mat_jc_troom(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Johnson-Cook room temperature', ierr) return end if end if mat_yield0(material_index) = mat_jc_a(material_index) ierr = FEM_SUCCESS end subroutine parse_jc_plastic_line subroutine parse_rate_dependent_line(line, material_index, ierr) character(len=*), intent(in) :: line integer, intent(in) :: material_index integer, intent(out) :: ierr character(len=LINE_LEN) :: token integer :: ios if (material_index .le. 0) then call error_set(FEM_ERR_INPUT, '*RATE DEPENDENT data appears before *MATERIAL', ierr) return end if call csv_token(line, 1, token) read(token,*,iostat=ios) mat_jc_c(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Johnson-Cook C', ierr) return end if call csv_token(line, 2, token) if (len_trim(token) .eq. 0) then mat_jc_epsdot0(material_index) = ONE else read(token,*,iostat=ios) mat_jc_epsdot0(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Johnson-Cook reference strain rate', ierr) return end if end if ierr = FEM_SUCCESS end subroutine parse_rate_dependent_line subroutine parse_specific_heat_line(line, material_index, ierr) character(len=*), intent(in) :: line integer, intent(in) :: material_index integer, intent(out) :: ierr character(len=LINE_LEN) :: token integer :: ios if (material_index .le. 0) then call error_set(FEM_ERR_INPUT, '*SPECIFIC HEAT data appears before *MATERIAL', ierr) return end if call csv_token(line, 1, token) read(token,*,iostat=ios) mat_jc_cp(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse specific heat', ierr) return end if if (mat_jc_cp(material_index) .le. ZERO) then call error_set(FEM_ERR_INPUT, 'specific heat must be positive', ierr) return end if ierr = FEM_SUCCESS end subroutine parse_specific_heat_line subroutine parse_heat_fraction_line(line, material_index, ierr) character(len=*), intent(in) :: line integer, intent(in) :: material_index integer, intent(out) :: ierr character(len=LINE_LEN) :: token integer :: ios if (material_index .le. 0) then call error_set(FEM_ERR_INPUT, '*INELASTIC HEAT FRACTION data appears before *MATERIAL', ierr) return end if call csv_token(line, 1, token) read(token,*,iostat=ios) mat_jc_chi(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse inelastic heat fraction', ierr) return end if if (mat_jc_chi(material_index) .lt. ZERO .or. mat_jc_chi(material_index) .gt. ONE) then call error_set(FEM_ERR_INPUT, 'inelastic heat fraction must be in [0,1]', ierr) return end if ierr = FEM_SUCCESS end subroutine parse_heat_fraction_line subroutine parse_damage_init_line(line, material_index, ierr) character(len=*), intent(in) :: line integer, intent(in) :: material_index integer, intent(out) :: ierr character(len=LINE_LEN) :: token integer :: ios if (material_index .le. 0) then call error_set(FEM_ERR_INPUT, '*DAMAGE INITIATION data appears before *MATERIAL', ierr) return end if if (trim(mat_failure_model(material_index)) .eq. 'JOHNSON_COOK') then call parse_jc_damage_line(line, material_index, ierr) return end if call csv_token(line, 1, token) read(token,*,iostat=ios) mat_eqps_fail(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse damage initiation threshold', ierr) return end if if (mat_eqps_fail(material_index) .le. ZERO) then call error_set(FEM_ERR_INPUT, 'damage initiation threshold must be positive', ierr) return end if ierr = FEM_SUCCESS end subroutine parse_damage_init_line subroutine parse_jc_damage_line(line, material_index, ierr) character(len=*), intent(in) :: line integer, intent(in) :: material_index integer, intent(out) :: ierr character(len=LINE_LEN) :: token integer :: ios call csv_token(line, 1, token) read(token,*,iostat=ios) mat_jc_d1(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Johnson-Cook damage D1', ierr) return end if call csv_token(line, 2, token) read(token,*,iostat=ios) mat_jc_d2(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Johnson-Cook damage D2', ierr) return end if call csv_token(line, 3, token) read(token,*,iostat=ios) mat_jc_d3(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Johnson-Cook damage D3', ierr) return end if call csv_token(line, 4, token) read(token,*,iostat=ios) mat_jc_d4(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Johnson-Cook damage D4', ierr) return end if call csv_token(line, 5, token) read(token,*,iostat=ios) mat_jc_d5(material_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse Johnson-Cook damage D5', ierr) return end if if (mat_jc_d1(material_index) .le. ZERO .and. & mat_jc_d2(material_index) .le. ZERO) then call error_set(FEM_ERR_INPUT, 'Johnson-Cook damage D1 or D2 must be positive', ierr) return end if ierr = FEM_SUCCESS end subroutine parse_jc_damage_line subroutine parse_dynamic_line(line, ierr) character(len=*), intent(in) :: line integer, intent(out) :: ierr character(len=LINE_LEN) :: token real(rk) :: first_value real(rk) :: second_value real(rk) :: ratio integer :: ios call csv_token(line, 1, token) if (len_trim(token) .eq. 0) then call error_set(FEM_ERR_INPUT, '*DYNAMIC data line is empty', ierr) return end if read(token,*,iostat=ios) first_value if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse *DYNAMIC first value', ierr) return end if if (first_value .le. ZERO) then call error_set(FEM_ERR_INPUT, '*DYNAMIC first value must be positive', ierr) return end if call csv_token(line, 2, token) if (len_trim(token) .eq. 0) then time_end = first_value dt_user = ZERO use_user_dt = .false. nstep_max = 0 else read(token,*,iostat=ios) second_value if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse *DYNAMIC total time', ierr) return end if if (second_value .le. ZERO) then call error_set(FEM_ERR_INPUT, '*DYNAMIC total time must be positive', ierr) return end if dt_user = first_value time_end = second_value use_user_dt = .true. ratio = time_end / dt_user nstep_max = int(ratio) if (real(nstep_max, rk) * dt_user .lt. & time_end * (ONE - 1.0e-10_rk)) nstep_max = nstep_max + 1 end if ierr = FEM_SUCCESS end subroutine parse_dynamic_line subroutine set_static_defaults() analysis_type = ANALYSIS_STATIC_LINEAR static_initial_increment = ONE static_min_increment = ZERO static_max_increment = ONE load_factor = ONE dt_user = ONE time_end = ONE use_user_dt = .true. nstep_max = 1 max_increment = 1 end subroutine set_static_defaults subroutine parse_static_line(line, ierr) character(len=*), intent(in) :: line integer, intent(out) :: ierr character(len=LINE_LEN) :: token real(rk) :: value real(rk) :: ratio integer :: ios call set_static_defaults() call csv_token(line, 1, token) if (len_trim(token) .eq. 0) then ierr = FEM_SUCCESS return end if read(token,*,iostat=ios) value if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse *STATIC initial increment', ierr) return end if if (value .le. ZERO) then call error_set(FEM_ERR_INPUT, '*STATIC initial increment must be positive', ierr) return end if static_initial_increment = value dt_user = value call csv_token(line, 2, token) if (len_trim(token) .gt. 0) then read(token,*,iostat=ios) value if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse *STATIC total time', ierr) return end if if (value .le. ZERO) then call error_set(FEM_ERR_INPUT, '*STATIC total time must be positive', ierr) return end if time_end = value end if call csv_token(line, 3, token) if (len_trim(token) .gt. 0) then read(token,*,iostat=ios) value if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse *STATIC minimum increment', ierr) return end if if (value .lt. ZERO) then call error_set(FEM_ERR_INPUT, '*STATIC minimum increment must be non-negative', ierr) return end if static_min_increment = value end if call csv_token(line, 4, token) if (len_trim(token) .gt. 0) then read(token,*,iostat=ios) value if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse *STATIC maximum increment', ierr) return end if if (value .le. ZERO) then call error_set(FEM_ERR_INPUT, '*STATIC maximum increment must be positive', ierr) return end if static_max_increment = value end if ratio = time_end / static_initial_increment nstep_max = int(ratio) if (real(nstep_max, rk) * static_initial_increment .lt. & time_end * (ONE - 1.0e-10_rk)) nstep_max = nstep_max + 1 if (nstep_max .lt. 1) nstep_max = 1 max_increment = nstep_max ierr = FEM_SUCCESS end subroutine parse_static_line subroutine parse_shell_section_line(line, section_index, ierr) character(len=*), intent(in) :: line integer, intent(in) :: section_index integer, intent(out) :: ierr character(len=LINE_LEN) :: token integer :: ios call csv_token(line, 1, token) read(token,*,iostat=ios) section_thickness(section_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse shell thickness', ierr) return end if ierr = FEM_SUCCESS end subroutine parse_shell_section_line subroutine parse_boundary_line(line, bc_index, amplitude_index, ierr) character(len=*), intent(in) :: line integer, intent(in) :: bc_index integer, intent(in) :: amplitude_index integer, intent(out) :: ierr character(len=LINE_LEN) :: token character(len=NAME_LEN) :: upper_token integer :: ios call csv_token(line, 1, token) if (len_trim(token) .eq. 0) then call error_set(FEM_ERR_INPUT, 'boundary line is missing target', ierr) return end if call to_upper(token, upper_token) bc_target(bc_index) = upper_token call csv_token(line, 2, token) read(token,*,iostat=ios) bc_dof_start(bc_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse boundary first dof', ierr) return end if call csv_token(line, 3, token) if (len_trim(token) .eq. 0) then bc_dof_end(bc_index) = bc_dof_start(bc_index) else read(token,*,iostat=ios) bc_dof_end(bc_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse boundary last dof', ierr) return end if end if call csv_token(line, 4, token) if (len_trim(token) .eq. 0) then bc_value(bc_index) = ZERO else read(token,*,iostat=ios) bc_value(bc_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse boundary value', ierr) return end if end if bc_amp(bc_index) = amplitude_index ierr = FEM_SUCCESS end subroutine parse_boundary_line subroutine parse_cload_line(line, cload_index, amplitude_index, ierr) character(len=*), intent(in) :: line integer, intent(in) :: cload_index integer, intent(in) :: amplitude_index integer, intent(out) :: ierr character(len=LINE_LEN) :: token character(len=NAME_LEN) :: upper_token integer :: ios call csv_token(line, 1, token) if (len_trim(token) .eq. 0) then call error_set(FEM_ERR_INPUT, 'cload line is missing target', ierr) return end if call to_upper(token, upper_token) cload_target(cload_index) = upper_token call csv_token(line, 2, token) read(token,*,iostat=ios) cload_dof(cload_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse cload dof', ierr) return end if call csv_token(line, 3, token) read(token,*,iostat=ios) cload_value(cload_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse cload value', ierr) return end if cload_amp(cload_index) = amplitude_index ierr = FEM_SUCCESS end subroutine parse_cload_line subroutine parse_dload_line(line, dload_index, amplitude_index, ierr) character(len=*), intent(in) :: line integer, intent(in) :: dload_index integer, intent(in) :: amplitude_index integer, intent(out) :: ierr character(len=LINE_LEN) :: token character(len=NAME_LEN) :: upper_target character(len=16) :: upper_label integer :: ios call csv_token(line, 1, token) if (len_trim(token) .eq. 0) then call error_set(FEM_ERR_INPUT, 'dload line is missing target', ierr) return end if call to_upper(token, upper_target) dload_target(dload_index) = upper_target call csv_token(line, 2, token) if (len_trim(token) .eq. 0) then call error_set(FEM_ERR_INPUT, 'dload line is missing label', ierr) return end if call to_upper(token, upper_label) dload_label(dload_index) = upper_label call csv_token(line, 3, token) read(token,*,iostat=ios) dload_value(dload_index) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse dload value', ierr) return end if dload_amp(dload_index) = amplitude_index ierr = FEM_SUCCESS end subroutine parse_dload_line subroutine inp_apply_sections(ierr) integer, intent(out) :: ierr integer :: sec integer :: mat integer :: set_id integer :: item integer :: elem_internal integer :: start_pos integer :: stop_pos do sec = 1, n_section mat = database_find_material(section_material_name(sec)) if (mat .eq. 0) then call error_set(FEM_ERR_INPUT, 'section references unknown material', ierr) return end if set_id = database_find_elset(section_elset_name(sec)) if (set_id .eq. 0) then call error_set(FEM_ERR_INPUT, 'section references unknown elset', ierr) return end if start_pos = elset_start(set_id) stop_pos = start_pos + elset_count(set_id) - 1 do item = start_pos, stop_pos elem_internal = database_find_elem(elset_items(item)) if (elem_internal .eq. 0) then call error_set(FEM_ERR_INPUT, 'elset references unknown element id', ierr) return end if elem_sec(elem_internal) = sec elem_mat(elem_internal) = mat end do end do ierr = FEM_SUCCESS end subroutine inp_apply_sections integer function count_set_items(line, generate_mode) character(len=*), intent(in) :: line logical, intent(in) :: generate_mode integer :: start_value integer :: end_value integer :: increment integer :: ierr_local integer :: field character(len=LINE_LEN) :: token count_set_items = 0 if (generate_mode) then call parse_generate_line(line, start_value, end_value, increment, ierr_local) if (ierr_local .ne. FEM_SUCCESS .or. increment .eq. 0) return count_set_items = ((end_value - start_value) / increment) + 1 if (count_set_items .lt. 0) count_set_items = 0 else do field = 1, MAX_NEN call csv_token(line, field, token) if (len_trim(token) .eq. 0) exit count_set_items = count_set_items + 1 end do end if end function count_set_items integer function count_amplitude_items(line) character(len=*), intent(in) :: line integer :: field character(len=LINE_LEN) :: token count_amplitude_items = 0 field = 1 do call csv_token(line, field, token) if (len_trim(token) .eq. 0) exit call csv_token(line, field + 1, token) if (len_trim(token) .eq. 0) exit count_amplitude_items = count_amplitude_items + 1 field = field + 2 end do end function count_amplitude_items subroutine parse_amplitude_line(line, amplitude_index, amp_pos, ierr) character(len=*), intent(in) :: line integer, intent(in) :: amplitude_index integer, intent(inout) :: amp_pos integer, intent(out) :: ierr integer :: field integer :: ios real(rk) :: time_value real(rk) :: scale_value character(len=LINE_LEN) :: token if (amplitude_index .le. 0) then call error_set(FEM_ERR_INPUT, '*AMPLITUDE data appears before *AMPLITUDE', ierr) return end if if (.not. allocated(amp_time) .or. .not. allocated(amp_value)) then call error_set(FEM_ERR_INPUT, '*AMPLITUDE data storage is not allocated', ierr) return end if field = 1 do call csv_token(line, field, token) if (len_trim(token) .eq. 0) exit read(token,*,iostat=ios) time_value if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse amplitude time', ierr) return end if call csv_token(line, field + 1, token) if (len_trim(token) .eq. 0) then call error_set(FEM_ERR_INPUT, 'amplitude data has unmatched time value', ierr) return end if read(token,*,iostat=ios) scale_value if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse amplitude value', ierr) return end if amp_pos = amp_pos + 1 if (amp_pos .gt. n_amp_item) then call error_set(FEM_ERR_INTERNAL, 'amplitude data count overflow', ierr) return end if amp_time(amp_pos) = time_value amp_value(amp_pos) = scale_value amp_count(amplitude_index) = amp_count(amplitude_index) + 1 field = field + 2 end do ierr = FEM_SUCCESS end subroutine parse_amplitude_line subroutine parse_generate_line(line, start_value, end_value, increment, ierr) character(len=*), intent(in) :: line integer, intent(out) :: start_value integer, intent(out) :: end_value integer, intent(out) :: increment integer, intent(out) :: ierr character(len=LINE_LEN) :: token integer :: ios call csv_token(line, 1, token) read(token,*,iostat=ios) start_value if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse generate start value', ierr) return end if call csv_token(line, 2, token) read(token,*,iostat=ios) end_value if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse generate end value', ierr) return end if call csv_token(line, 3, token) if (len_trim(token) .eq. 0) then increment = 1 else read(token,*,iostat=ios) increment if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse generate increment', ierr) return end if end if if (increment .eq. 0) then call error_set(FEM_ERR_INPUT, 'generate increment must not be zero', ierr) return end if ierr = FEM_SUCCESS end subroutine parse_generate_line subroutine parse_node_line(line, node_id, x, y, z, ierr) character(len=*), intent(in) :: line integer, intent(out) :: node_id real(rk), intent(out) :: x real(rk), intent(out) :: y real(rk), intent(out) :: z integer, intent(out) :: ierr character(len=LINE_LEN) :: token integer :: ios call csv_token(line, 1, token) read(token,*,iostat=ios) node_id if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse node id', ierr) return end if call csv_token(line, 2, token) read(token,*,iostat=ios) x if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse node x coordinate', ierr) return end if call csv_token(line, 3, token) read(token,*,iostat=ios) y if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse node y coordinate', ierr) return end if call csv_token(line, 4, token) read(token,*,iostat=ios) z if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse node z coordinate', ierr) return end if ierr = FEM_SUCCESS end subroutine parse_node_line subroutine parse_element_line(line, elem_id, conn, nconn, ierr) character(len=*), intent(in) :: line integer, intent(out) :: elem_id integer, intent(out) :: conn(MAX_NEN) integer, intent(out) :: nconn integer, intent(out) :: ierr character(len=LINE_LEN) :: token integer :: field integer :: ios integer :: value conn = 0 nconn = 0 call csv_token(line, 1, token) read(token,*,iostat=ios) elem_id if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse element id', ierr) return end if do field = 2, MAX_NEN + 1 call csv_token(line, field, token) if (len_trim(token) .eq. 0) exit read(token,*,iostat=ios) value if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse element connectivity', ierr) return end if nconn = nconn + 1 conn(nconn) = value end do if (nconn .le. 0) then call error_set(FEM_ERR_INPUT, 'element line contains no connectivity', ierr) return end if ierr = FEM_SUCCESS end subroutine parse_element_line subroutine clean_line(line, clean) character(len=*), intent(in) :: line character(len=*), intent(out) :: clean integer :: comment_pos clean = ' ' clean = adjustl(line) comment_pos = index(clean, '**') if (comment_pos .eq. 1) then clean = ' ' else if (comment_pos .gt. 1) then clean = clean(1:comment_pos-1) end if end subroutine clean_line subroutine get_keyword_value(line, key, value) character(len=*), intent(in) :: line character(len=*), intent(in) :: key character(len=*), intent(out) :: value character(len=LINE_LEN) :: upper_line character(len=LINE_LEN) :: upper_key character(len=LINE_LEN) :: upper_value integer :: start_pos integer :: end_pos integer :: comma_pos value = ' ' call to_upper(line, upper_line) call to_upper(key, upper_key) start_pos = index(upper_line, trim(upper_key)//'=') if (start_pos .eq. 0) return start_pos = start_pos + len_trim(upper_key) + 1 comma_pos = index(upper_line(start_pos:), ',') if (comma_pos .eq. 0) then end_pos = len_trim(line) else end_pos = start_pos + comma_pos - 2 end if if (end_pos .ge. start_pos) then value = adjustl(line(start_pos:end_pos)) call to_upper(value, upper_value) value = upper_value end if end subroutine get_keyword_value logical function has_parameter(line, key) character(len=*), intent(in) :: line character(len=*), intent(in) :: key character(len=LINE_LEN) :: upper_line character(len=LINE_LEN) :: upper_key call to_upper(line, upper_line) call to_upper(key, upper_key) has_parameter = index(upper_line, trim(upper_key)) .gt. 0 end function has_parameter logical function is_johnson_cook_plastic_keyword(line) character(len=*), intent(in) :: line is_johnson_cook_plastic_keyword = & has_parameter(line, 'HARDENING=JOHNSON COOK') .or. & has_parameter(line, 'HARDENING=JOHNSON_COOK') end function is_johnson_cook_plastic_keyword logical function is_johnson_cook_rate_keyword(line) character(len=*), intent(in) :: line is_johnson_cook_rate_keyword = & has_parameter(line, 'TYPE=JOHNSON COOK') .or. & has_parameter(line, 'TYPE=JOHNSON_COOK') .or. & has_parameter(line, 'JOHNSON COOK') .or. & has_parameter(line, 'JOHNSON_COOK') end function is_johnson_cook_rate_keyword logical function is_johnson_cook_damage_keyword(line) character(len=*), intent(in) :: line is_johnson_cook_damage_keyword = & has_parameter(line, 'CRITERION=JOHNSON COOK') .or. & has_parameter(line, 'CRITERION=JOHNSON_COOK') .or. & has_parameter(line, 'JOHNSON COOK') .or. & has_parameter(line, 'JOHNSON_COOK') end function is_johnson_cook_damage_keyword subroutine csv_token(line, field_index, token) character(len=*), intent(in) :: line integer, intent(in) :: field_index character(len=*), intent(out) :: token integer :: i integer :: field integer :: start_pos integer :: end_pos integer :: line_len token = ' ' field = 1 start_pos = 1 line_len = len_trim(line) do i = 1, line_len + 1 if (i .gt. line_len .or. line(i:i) .eq. ',') then if (field .eq. field_index) then end_pos = i - 1 if (end_pos .ge. start_pos) token = adjustl(line(start_pos:end_pos)) return end if field = field + 1 start_pos = i + 1 end if end do end subroutine csv_token subroutine to_upper(input, output) character(len=*), intent(in) :: input character(len=*), intent(out) :: output integer :: i integer :: code output = ' ' output = input do i = 1, len(output) code = ichar(output(i:i)) if (code .ge. ichar('a') .and. code .le. ichar('z')) then output(i:i) = char(code - ichar('a') + ichar('A')) end if end do end subroutine to_upper logical function starts_with(text, prefix) character(len=*), intent(in) :: text character(len=*), intent(in) :: prefix integer :: n n = len_trim(prefix) starts_with = .false. if (len_trim(text) .lt. n) return starts_with = text(1:n) .eq. prefix(1:n) end function starts_with end module fem_inp_reader