diff --git a/src/read_aster_mesh.jl b/src/read_aster_mesh.jl index 189586c..f81f2a9 100644 --- a/src/read_aster_mesh.jl +++ b/src/read_aster_mesh.jl @@ -98,9 +98,19 @@ function get_element_sets(med::MEDFile, mesh_name::String)::Dict{Int64, Vector{S if !haskey(mesh, "ELEME") return element_sets end - for (k, v) in mesh["ELEME"] - elset_id = parse(Int, split(k, '_')[2]) - element_sets[elset_id] = collect(to_ascii(d) for d in v["GRO"]["NOM"]) + elset_keys = sort(collect(keys(mesh["ELEME"]))) + for (i, k) in enumerate(elset_keys) + v = mesh["ELEME"][k] + if startswith(k, "FAM") # exported from Salome + elset_id = parse(Int, split(k, '_')[2]) + else # exported from Gmsh + elset_id = -i + end + if !isempty(v) + element_sets[elset_id] = map(strip, collect(to_ascii(d) for d in v["GRO"]["NOM"])) + else + element_sets[elset_id] = [""] + end end return element_sets end @@ -110,9 +120,9 @@ function get_nodes(med::MEDFile, nsets::Dict{Int, Vector{String}}, mesh_name::St @assert length(increments) == 1 increment = first(increments) nodes = med.data["ENS_MAA"][mesh_name][increment]["NOE"] - node_ids = nodes["NUM"] nset_ids = nodes["FAM"] - nnodes = length(node_ids) + nnodes = length(nset_ids) + node_ids = get(nodes, "NUM", collect(1:nnodes)) node_coords = nodes["COO"] dim = round(Int, length(node_coords)/nnodes) node_coords = reshape(node_coords, nnodes, dim)' @@ -136,8 +146,8 @@ function get_connectivity(med::MEDFile, elsets::Dict{Int64, Vector{String}}, mes for eltype in keys(all_elements) elements = all_elements[eltype] elset_ids = elements["FAM"] - element_ids = elements["NUM"] - nelements = length(element_ids) + nelements = length(elset_ids) + element_ids = get(elements, "NUM", collect(1:nelements)) element_connectivity = elements["NOD"] element_dim = round(Int, length(element_connectivity)/nelements) element_connectivity = reshape(element_connectivity, nelements, element_dim)' diff --git a/test/runtests.jl b/test/runtests.jl index 2e49463..a4caa8e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,6 +8,7 @@ include(joinpath("..", "docs", "make.jl")) @testset "AsterReader.jl" begin include("test_read_aster_mesh.jl") include("test_read_aster_results.jl") + include("test_read_gmsh_med.jl") end include(joinpath("..", "docs", "deploy.jl")) diff --git a/test/test_read_gmsh_med.jl b/test/test_read_gmsh_med.jl new file mode 100644 index 0000000..1b8c3c7 --- /dev/null +++ b/test/test_read_gmsh_med.jl @@ -0,0 +1,12 @@ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/AsterReader.jl/blob/master/LICENSE + +using FEMBase, Test, AsterReader +using AsterReader: aster_parse_nodes, aster_read_mesh, MEDFile, get_element_sets + +datadir = first(splitext(basename(@__FILE__))) + +@testset "test med file exported from gmsh, issue #16" begin + mesh_file = joinpath(datadir, "t1.med") + mesh = aster_read_mesh(mesh_file) +end diff --git a/test/test_read_gmsh_med/t1.med b/test/test_read_gmsh_med/t1.med new file mode 100644 index 0000000..b82478d Binary files /dev/null and b/test/test_read_gmsh_med/t1.med differ