thanks @koehlerson, I would have not realised that the data needed a cast to become readable at print (weird, I thougth that the difference between Uint64
and Int64
were about the sign).
What still gives problems is that resulting arrays are not of size of number of elements nor of size of number of nodes (in my previous experiences with triangle, element to node arrays are size number of elements * number of node per element
).
Here, if I want to recover the element to node list based, I should do something like this (picked from another discourse post):
# Extract elements
element_types, element_ids, element_connectivity = gmsh.model.mesh.getElements(2,1)
nel = length(element_ids[1]) # number of elements reads from length of number element ids
e2n = zeros(Int16,nel,3) # element to node numbering
for el in 1:nel
node1_id = element_connectivity[1][3*(el-1)+1]
node2_id = element_connectivity[1][3*(el-1)+2]
node3_id = element_connectivity[1][3*(el-1)+3]
e2n[el,1]= Int16(node1_id)
e2n[el,2]= Int16(node2_id)
e2n[el,3]= Int16(node3_id)
end
but what if, a mesh contains both quads and triangles? How could one recover the element to node list?
Below Iāve pasted a MWE that attempts to describe the problem. I try to construct a mesh where the west part contains triangles and the right contains quadrangles. Then, I would like to compute element to node list (node to element list would be next on the to do list ). Here itās clear that the length of element_ids[1]
does not correspond to the total number of elements (maybe one side?) and I have no idea how to recover the element to node list without known the total number of elment and their type (tri/quad). If anyone would have a hint it would be very welcome! cheers
import gmsh_jll
include(gmsh_jll.gmsh_api)
# Start
gmsh.initialize()
gmsh.model.add("MWE_tri_quads")
# outer box
gmsh.model.geo.addPoint(0.0, 0.0, 0.0) # SW
gmsh.model.geo.addPoint(1.5, 0.0, 0.0) # SE
gmsh.model.geo.addPoint(1.5, 1.0, 0.0) # NE
gmsh.model.geo.addPoint(0.0, 1.0, 0.0) # NW
# Inner limit
gmsh.model.geo.addPoint(0.75, 0.0, 0.0) # S
gmsh.model.geo.addPoint(0.75, 1.0, 0.0) # N
# West
gmsh.model.geo.addLine(4, 1)
gmsh.model.geo.addLine(1, 5)
gmsh.model.geo.addLine(6, 4)
gmsh.model.geo.addLine(5, 6)
gmsh.model.geo.addCurveLoop([3, 1, 2, 4], 1)
pl1 = gmsh.model.geo.addPlaneSurface([1])
# East
gmsh.model.geo.addLine(5, 2)
gmsh.model.geo.addLine(2, 3)
gmsh.model.geo.addLine(3, 6)
gmsh.model.geo.addCurveLoop([-4, 5, 6, 7], 2)
pl2 = gmsh.model.geo.addPlaneSurface([2])
# Synchro
gmsh.model.geo.synchronize()
# Make quads in the western part of the domain
gmsh.model.mesh.setRecombine(2, pl2)
gmsh.model.mesh.generate(2)
gmsh.write("MWE_tri_quads.msh")
if !("-nopopup" in ARGS)
gmsh.fltk.run()
end
########## Try to get things out
element_types, element_ids, element_connectivity = gmsh.model.mesh.getElements(2,1)
nel = length(element_ids[1])
println(nel)
# for el in 1:nel
# node1_id = element_connectivity[1][3*(el-1)+1]
# node2_id = element_connectivity[1][3*(el-1)+2]
# node3_id = element_connectivity[1][3*(el-1)+3]
# e2v[el,1]= Int16(node1_id)
# e2v[el,2]= Int16(node2_id)
# e2v[el,3]= Int16(node3_id)
# end