Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kam/caseinsensitive #9

Merged
merged 3 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FerriteMeshParser"
uuid = "0f8c756f-80dd-4a75-85c6-b0a5ab9d4620"
authors = ["Knut Andreas Meyer and contributors"]
version = "0.1.0"
version = "0.1.1"

[deps]
Ferrite = "c061ca5d-56c9-439f-9c0e-210fe06d3992"
Expand Down
16 changes: 8 additions & 8 deletions src/abaqusreader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,29 @@ function read_mesh(filename, ::AbaqusMeshFormat)
continue
end
DEBUG_PARSE && println("H: $header")
if startswith(header, "*Node")
if startswith(lowercase(header), "*node")
DEBUG_PARSE && println("Reading nodes")
read_dim = read_abaqus_nodes!(f, node_numbers, coord_vec)
dim == 0 && (dim = read_dim) # Set dim if not yet set
read_dim != dim && throw(DimensionMismatch("Not allowed to mix nodes in different dimensions"))
elseif startswith(header, "*Element")
if ((m = match(r"\*Element, type=(.*), ELSET=(.*)", header)) !== nothing)
elseif startswith(lowercase(header), "*element")
if ((m = match(r"\*Element, type=(.*), ELSET=(.*)"i, header)) !== nothing)
DEBUG_PARSE && println("Reading elements with elset")
read_abaqus_elements!(f, topology_vectors, element_number_vectors, m.captures[1], m.captures[2], element_sets)
elseif ((m = match(r"\*Element, type=(.*)", header)) !== nothing)
elseif ((m = match(r"\*Element, type=(.*)"i, header)) !== nothing)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the i do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes the regular expressions case insensitive, see end of this section: https://docs.julialang.org/en/v1/manual/strings/#man-regex-literals

DEBUG_PARSE && println("Reading elements without elset")
read_abaqus_elements!(f, topology_vectors, element_number_vectors, m.captures[1])
end
elseif ((m = match(r"\*Elset, elset=(.*)", header)) !== nothing)
elseif ((m = match(r"\*Elset, elset=(.*)"i, header)) !== nothing)
DEBUG_PARSE && println("Reading elementset")
read_abaqus_set!(f, elementsets, m.captures[1])
elseif ((m = match(r"\*Nset, nset=(.*)", header)) !== nothing)
elseif ((m = match(r"\*Nset, nset=(.*)"i, header)) !== nothing)
DEBUG_PARSE && println("Reading nodeset")
read_abaqus_set!(f, nodesets, m.captures[1])
elseif startswith(header, "*Part")
elseif startswith(lowercase(header), "*part")
DEBUG_PARSE && println("Increment part counter")
part_counter += 1
elseif startswith(header, "*Instance")
elseif startswith(lowercase(header), "*instance")
DEBUG_PARSE && println("Increment instance counter")
instance_counter += 1
discardlinesuntil(f, stopsign='*') # Instances contain translations, or start with *Node if independent mesh
Expand Down
10 changes: 9 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,12 @@ end
@test getfield(grid0, key) == getfield(grid1, key)
@test getfield(grid0, key) == getfield(grid2, key)
end
end
end

@testset "caseinsensitive" begin
filename = joinpath(@__DIR__, "test_files", "uppercase_test.inp")
grid = get_ferrite_grid(filename)
@test getncells(grid) == 2
@test getnnodes(grid) == 6
end

29 changes: 29 additions & 0 deletions test/test_files/uppercase_test.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
*Heading
** Job name: Job-1 Model name: Model-1
** Generated by: Abaqus/CAE 2019
*Preprint, echo=NO, model=NO, history=NO, contact=NO
**
** PARTS
**
*Part, name=Part-1
*End Part
**
**
** ASSEMBLY
**
*Assembly, name=Assembly
**
*Instance, name=Part-1-1, part=Part-1
*NODE
1, 1., 0.
2, 1., 1.
3, 0., 1.
4, 0., 0.
5, -1., 0.
6, -1., 1.
*ELEMENT, type=CPS4R
1, 1, 2, 3, 4
2, 4, 3, 6, 5
*End Instance
**
*End Assembly