Skip to content

Commit

Permalink
Read med file exported from Gmsh
Browse files Browse the repository at this point in the history
Now the package can also read med files exported from Gmsh. There is
some small differences how element sets are internally written to .h5
file and also looks that node / element id numbers are not explicitly
defined by Gmesh. Closes issue #16.
  • Loading branch information
ahojukka5 committed Jan 30, 2019
1 parent 143f159 commit 91a0a36
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/read_aster_mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)'
Expand All @@ -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)'
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
12 changes: 12 additions & 0 deletions test/test_read_gmsh_med.jl
Original file line number Diff line number Diff line change
@@ -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
Binary file added test/test_read_gmsh_med/t1.med
Binary file not shown.

0 comments on commit 91a0a36

Please sign in to comment.