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

cannot read .med from Gmsh #16

Closed
shipengcheng1230 opened this issue Dec 20, 2018 · 5 comments
Closed

cannot read .med from Gmsh #16

shipengcheng1230 opened this issue Dec 20, 2018 · 5 comments

Comments

@shipengcheng1230
Copy link

Hello, I am trying to read a .med (generated using Gmsh tutorial t1.jl in the tutorial and exported to .med format), but I got the following error:

julia> me = aster_read_mesh("t1.med")
ERROR: ArgumentError: invalid base 10 digit 'D' in "0D"
Stacktrace:
 [1] tryparse_internal(::Type{Int64}, ::SubString{String}, ::Int64, ::Int64, ::Int64, ::Bool) at ./parse.jl:128
 [2] #parse#332(::Nothing, ::Function, ::Type{Int64}, ::SubString{String}) at ./parse.jl:228
 [3] parse(::Type{Int64}, ::SubString{String}) at ./parse.jl:228
 [4] get_element_sets(::AsterReader.MEDFile, ::String) at /Users/spc/.julia/packages/AsterReader/cKdBD/src/read_aster_mesh.jl:102
 [5] aster_read_mesh_(::AsterReader.MEDFile, ::Nothing) at /Users/spc/.julia/packages/AsterReader/cKdBD/src/read_aster_mesh.jl:189
 [6] aster_read_mesh at /Users/spc/.julia/packages/AsterReader/cKdBD/src/read_aster_mesh.jl:167 [inlined] (repeats 2 times)
 [7] top-level scope at none:0

Is it a bug in this package or problem with the export of Gmsh? Thank you!

@ahojukka5
Copy link
Member

Hard to say based on that error. Can you attach the med file?

@shipengcheng1230
Copy link
Author

Here is the file. (Github doesn't allow directly to upload .med)
t1.med.zip

@ahojukka5
Copy link
Member

ahojukka5 commented Jan 30, 2019

Looks that Gmsh is not making a proper med file in order to determine element sets.

med1 = MEDFile("t1.med")
med2 = MEDFile("quad4.med")

Now, we should find element set names and corresponding id number, which is coded in case of med files created by Salome, to key value, i.e.

julia> med2.data["FAS"]["BLOCK"]["ELEME"]
Dict{String,Any} with 5 entries:
  "FAM_-6_BLOCK"  => Dict{String,Any}("GRO"=>Dict{String,Any}("NOM"=>Array{Int8,N} where N[[66, 76, 79, 67, 75, 0, 0, 0, 0, 0    0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]))
  "FAM_-9_LEFT"   => Dict{String,Any}("GRO"=>Dict{String,Any}("NOM"=>Array{Int8,N} where N[[76, 69, 70, 84, 0, 0, 0, 0, 0, 0    0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]))
  "FAM_-8_BOTTOM" => Dict{String,Any}("GRO"=>Dict{String,Any}("NOM"=>Array{Int8,N} where N[[66, 79, 84, 84, 79, 77, 0, 0, 0, 0    0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]))
  "FAM_-10_RIGHT" => Dict{String,Any}("GRO"=>Dict{String,Any}("NOM"=>Array{Int8,N} where N[[82, 73, 71, 72, 84, 0, 0, 0, 0, 0    0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]))
  "FAM_-7_TOP"    => Dict{String,Any}("GRO"=>Dict{String,Any}("NOM"=>Array{Int8,N} where N[[84, 79, 80, 0, 0, 0, 0, 0, 0, 0    0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]))

This id number, -9, -8, etc. is then used to determine what element set particular element belongs to:

julia> med2.data["ENS_MAA"]["BLOCK"]["-0000000000000000001-0000000000000000001"]["MAI"]
Dict{String,Any} with 2 entries:
  "QU4" => Dict{String,Any}("FAM"=>Int32[-6],"NOD"=>Int32[4, 3, 2, 1],"NUM"=>Int32[5])
  "SE2" => Dict{String,Any}("FAM"=>Int32[-8, -10, -7, -9],"NOD"=>Int32[4, 3, 2, 1, 3, 2, 1, 4],"NUM"=>Int32[1, 2, 3, 4])

For example, element set BLOCK is -6, and from here we can see that element of type QU4 belongs to set id -6. Now, in Gmsh exported med file, we still have id numbers assigned to each element:

julia> med1.data["ENS_MAA"]["t1"]["-0000000000000000001-0000000000000000001"]["MAI"]
Dict{String,Any} with 3 entries:
  "SE2" => Dict{String,Any}("FAM"=>Int32[-5, -5, -5, -5, -5, -5, -5, -5, -5, -5    -6, -6, -6, -6, -6, -6, -6, -6, -6, -6],"NOD"=>Int32[1, 5, 6, 7, 8, 9, 10, 11, 12, 13    34, 35, 36, 37,
  "TR3" => Dict{String,Any}("FAM"=>Int32[-9, -9, -9, -9, -9, -9, -9, -9, -9, -9    -9, -9, -9, -9, -9, -9, -9, -9, -9, -9],"NOD"=>Int32[214, 105, 106, 122, 135, 60, 170, 170, 183, 54    3
  "PO1" => Dict{String,Any}("FAM"=>Int32[-1, -2],"NOD"=>Int32[1, 2])

So for example, elements of type TR3 belongs to set id -9. But here's the problem. What is the name of the element set with id -9?

julia> med1.data["FAS"]["t1"]["ELEME"]
Dict{String,Any} with 9 entries:
  "F_0D_3" => Dict{String,Any}()
  "F_1D_3" => Dict{String,Any}()
  "F_2D_1" => Dict{String,Any}("GRO"=>Dict{String,Any}("NOM"=>Array{Int8,N} where N[[77, 121, 32, 115, 117, 114, 102, 97, 99, 101    32, 32, 32, 32, 32, 32, 32, 32, 32, 32]]))
  "F_0D_2" => Dict{String,Any}("GRO"=>Dict{String,Any}("NOM"=>Array{Int8,N} where N[[71, 95, 48, 68, 95, 49, 32, 32, 32, 32    32, 32, 32, 32, 32, 32, 32, 32, 32, 32]]))
  "F_0D_4" => Dict{String,Any}()
  "F_1D_4" => Dict{String,Any}()
  "F_1D_1" => Dict{String,Any}("GRO"=>Dict{String,Any}("NOM"=>Array{Int8,N} where N[[71, 95, 49, 68, 95, 50, 32, 32, 32, 32    32, 32, 32, 32, 32, 32, 32, 32, 32, 32]]))
  "F_0D_1" => Dict{String,Any}("GRO"=>Dict{String,Any}("NOM"=>Array{Int8,N} where N[[71, 95, 48, 68, 95, 49, 32, 32, 32, 32    32, 32, 32, 32, 32, 32, 32, 32, 32, 32]]))
  "F_1D_2" => Dict{String,Any}("GRO"=>Dict{String,Any}("NOM"=>Array{Int8,N} where N[[71, 95, 49, 68, 95, 50, 32, 32, 32, 32    32, 32, 32, 32, 32, 32, 32, 32, 32, 32]]))

Because med file exported from Gmsh does not contain id value in key, it's unclear for me how to actually map element set names to corresponding id-numbers.

@ahojukka5
Copy link
Member

Ok, here's maybe the idea. Looks that the number of element set names matches, so maybe there is some sort of implicit assumption that keys, ordered in alphabetical order or similar, gives id numebrs. So let's test this:

julia> for (i, k) in enumerate(sort(collect(keys(med1.data["FAS"]["t1"]["ELEME"]))))
           v = med1.data["FAS"]["t1"]["ELEME"][k]
           s = ""
           if !isempty(v)
               s = join(to_ascii(v["GRO"]["NOM"][1]))
           end
           println("$k -> -$i $s")
       end
F_0D_1 -> -1 G_0D_1
F_0D_2 -> -2 G_0D_1
F_0D_3 -> -3
F_0D_4 -> -4
F_1D_1 -> -5 G_1D_2
F_1D_2 -> -6 G_1D_2
F_1D_3 -> -7
F_1D_4 -> -8
F_2D_1 -> -9 My surface

julia> med1.data["ENS_MAA"]["t1"]["-0000000000000000001-0000000000000000001"]["MAI"]
Dict{String,Any} with 3 entries:
  "SE2" => Dict{String,Any}("FAM"=>Int32[-5, -5, -5, -5, -5, -5, -5, -5, -5, -5    -6, -6, -6, -6, -6, -6, -6, -6, -6, -6],"NOD"=>Int32[1, 5, 6, 7, 8, 9, 10, 11, 12, 13    34, 35, 36, 37,
  "TR3" => Dict{String,Any}("FAM"=>Int32[-9, -9, -9, -9, -9, -9, -9, -9, -9, -9    -9, -9, -9, -9, -9, -9, -9, -9, -9, -9],"NOD"=>Int32[214, 105, 106, 122, 135, 60, 170, 170, 183, 54    3
  "PO1" => Dict{String,Any}("FAM"=>Int32[-1, -2],"NOD"=>Int32[1, 2])

This actually makes sense. 0D elements POI1 are in groups -1 and -2, 1D elements SEG2 in groups -5 and -6, and finally, TR3 elements in group -9.

ahojukka5 added a commit that referenced this issue Jan 30, 2019
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.
ahojukka5 added a commit that referenced this issue Jan 30, 2019
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.
@ahojukka5
Copy link
Member

This should be now ok. Please open a new issue if you find that reading Gmesh exported med files is not working as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants