From 099547a43e8e942d144e1a28006dd99f84f8da70 Mon Sep 17 00:00:00 2001 From: Ben Zwick Date: Mon, 13 May 2019 14:42:22 +0800 Subject: [PATCH] Parse lower/mixed case input files Abaqus input files are case insensitive. Previously, the element type (e.g. C3D4 == c3d4) and the NSET and ELSET options were not recognized if lower or mixed case. Note: Boundary conditions and loads are read verbatim (i.e. symbols :P or :p are created for pressure loads depending on the case used in the input file) which may cause confusion. --- src/parse_mesh.jl | 6 +- test/test_parse_model_mixed_case.jl | 39 ++++++++++++ .../cube_tet4_mixed_case.inp | 61 +++++++++++++++++++ 3 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 test/test_parse_model_mixed_case.jl create mode 100644 test/test_parse_model_mixed_case/cube_tet4_mixed_case.inp diff --git a/src/parse_mesh.jl b/src/parse_mesh.jl index 5862cdc..671ab67 100644 --- a/src/parse_mesh.jl +++ b/src/parse_mesh.jl @@ -140,7 +140,7 @@ function parse_section(model, lines, ::Symbol, idx_start, idx_end, ::Type{Val{:E regexp = r"TYPE=([\w\-\_]+)"i m = match(regexp, definition) m == nothing && error("Could not match regexp $regexp to line $definition") - element_type = m[1] + element_type = uppercase(m[1]) eltype_sym = Symbol(element_type) eltype_nodes = element_has_nodes(Val{eltype_sym}) element_type = element_has_type(Val{eltype_sym}) @@ -172,8 +172,8 @@ end function parse_section(model, lines, key, idx_start, idx_end, ::Union{Type{Val{:NSET}}, Type{Val{:ELSET}}}) data = Integer[] - set_regex_string = Dict(:NSET => r"NSET=([\w\-\_]+)", - :ELSET => r"ELSET=([\w\-\_]+)" ) + set_regex_string = Dict(:NSET => r"NSET=([\w\-\_]+)"i, + :ELSET => r"ELSET=([\w\-\_]+)"i) selected_set = key == :NSET ? "node_sets" : "element_sets" definition = lines[idx_start] regex_string = set_regex_string[key] diff --git a/test/test_parse_model_mixed_case.jl b/test/test_parse_model_mixed_case.jl new file mode 100644 index 0000000..13aa0f0 --- /dev/null +++ b/test/test_parse_model_mixed_case.jl @@ -0,0 +1,39 @@ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/AbaqusReader.jl/blob/master/LICENSE + +using AbaqusReader: abaqus_read_model +using AbaqusReader: parse_keyword + +datadir = first(splitext(basename(@__FILE__))) + +@testset "parse abaqus inp file to AbaqusModel" begin + fn = joinpath(datadir, "cube_tet4_mixed_case.inp") + model = abaqus_read_model(fn) + + @test length(model.properties) == 1 + section = first(model.properties) + @test section.element_set == :Cube + @test section.material_name == :Mat + + @test haskey(model.materials, :Mat) + material = model.materials[:Mat] + @test isapprox(first(material.properties).E, 208.0e3) + + @test length(model.steps) == 1 + step = first(model.steps) + @test length(step.boundary_conditions) == 2 + + bc = step.boundary_conditions[1] + @test bc.data[1] == [:Sym23, 1] + @test bc.data[2] == [:Sym13, 2] + + load = step.boundary_conditions[2] + @test load.data[1] == [:Load, :p, 1.00000] +end + +@testset "parse keyword" begin + k = parse_keyword("*SURFACE, NAME=TIE, SURFACE TO SURFACE") + @test k.options[1] == ("NAME" => "TIE") + @test k.options[2] == "SURFACE TO SURFACE" + @test_throws(Exception, parse_keyword("*SURFACE, MOI=HEI=EI")) +end diff --git a/test/test_parse_model_mixed_case/cube_tet4_mixed_case.inp b/test/test_parse_model_mixed_case/cube_tet4_mixed_case.inp new file mode 100644 index 0000000..2e841c1 --- /dev/null +++ b/test/test_parse_model_mixed_case/cube_tet4_mixed_case.inp @@ -0,0 +1,61 @@ +*Node, Nset=Nall +1, 4.07417, 3.51532, 4.43035 +2, 6.24583, 4.69753, 6.40067 +3,1.0e1,10.00000,0.00000 +4, 1.0E1, 0.00000, 0.00000 +5, 0.00000, 0.00000, 0.00000 +6, 0.00000, 10.00000, 0.00000 +7, 0.00000, 10.00000, 10.00000 +8, 0.00000, 0.00000, 10.00000 +9, 100.0e-1,10.00000,10.00000 +10,100.0E-1,0.00000,10.00000 +*Element, Type=C3d4, Elset=Cube + 1, 8, 10, 1, 2 + 2, 4, 1, 10, 2 + 3, 3, 9, 7, 2 + 4, 3, 5, 4, 1 + 5, 8, 7, 2, 1 + 6, 5, 6, 8, 1 + 7, 7, 6, 1, 8 + 8, 7, 9, 8, 2 + 9, 5, 8, 10, 1 + 10, 3, 6, 5, 1 + 11, 4, 10, 9, 2 + 12, 1, 7, 2, 3 + 13, 3, 4, 9, 2 + 14, 3, 1, 4, 2 + 15, 4, 5, 10, 1 + 16, 8, 9, 10, 2 + 17, 3, 6, 1, 7 +*Solid Section, Elset=Cube, Material=Mat +*Material, Name=Mat +*Elastic +2.08000e+005, 3.00000e-001 +*Nset, Nset=Sym12 + 5, 6, 3, 4, +*Nset, Nset=Sym23 + 5, 6, 7, 8, +*Nset, Nset=Sym13 + 5, 10, 8, 4, +*Surface, Type=Element, Name=Load + 16, S1 + 8, S1 +*Surface, Name=Order , Type=Element + 16, S1 + 8, S1 +*Boundary +Sym12, 3 +*Step +*Static +*Boundary +Sym23, 1 +Sym13, 2 +*Dsload +Load, p, 1.00000 +*Node File + Coord + u +*Node Print + Coord + u +*End Step