Get edges from FEMMeshGmsh object

About the development of the FEM module/workbench.

Moderator: bernd

andrefpf
Posts: 1
Joined: Wed Nov 06, 2019 3:12 pm

Get edges from FEMMeshGmsh object

Postby andrefpf » Wed Nov 06, 2019 3:37 pm

Hello,

I'm very new to freecad and I'm just trying to create an algorithm that get an .STEP file (just a few lines and curves), create a FEM Mesh with Gmsh and finally return all Nodes positions and Edge connectivity.

Most of this are done, I am just having trouble to get the Edges. For example, to get the Nodes i just use this and everything is done:

Code: Select all

>>> mesh.FemMesh.Nodes
{1:Vector(0,0,0), 2:Vector(1,0,0), 3:Vector(2,0,0)}
But when I try to get the edges the same way, it just returns a Tuple?

Code: Select all

>>>mesh.FemMesh.Edges
(11, 12)
I was expecting to receive something like:
{1:(1,2), 2:(2,3)}
or
[<Edge object at 0000018368C93A30>, <Edge object at 0000018368C93A30>]

Can somebody help me with this?

PS.: Excuse-me if i write something out of the forum patterns, I am not used this. And English is not my first language
joha2
Posts: 244
Joined: Tue Oct 11, 2016 9:48 pm

Re: Get edges from FEMMeshGmsh object

Postby joha2 » Fri Nov 08, 2019 6:15 am

andrefpf wrote:
Wed Nov 06, 2019 3:37 pm
Can somebody help me with this?
Dear andrefpf,

Welcome to the FreeCAD forum! Your forum contribution was well written, so no problem there :-)

I just tested myself a bit and came up with the following code:

Code: Select all

>>> mesh.FemMesh.Edges
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72)
>>> mesh.FemMesh.getElementNodes(1)
(2, 9, 14)
The elements different from nodes are numbered in ascending order. Therefore facets start at 73 and tet10s start much later.

Code: Select all

>>> mesh.FemMesh.Faces
(73, ..., 696)
>>> mesh.FemMesh.Volumes
(697, ..., 1849)
The tuple (2, 9, 14) from getElementNodes(1) contains edge nodes (seg3 element), which can be obtained from the Nodes dictionary

Code: Select all

>>> mesh.FemMesh.Nodes[2]
Vector (0.0, 0.0, 0.0)
For the other elements the getElementNodes(...) function returns tuples with another length e.g.

Code: Select all

>>> mesh.FemMesh.getElementNodes(73)
(13, 1, 179, 19, 182, 183)
>>> mesh.FemMesh.getElementNodes(697)
(353, 1256, 1262, 1277, 1305, 1304, 1303, 1306, 1307, 1308)
Hope this helps for understanding the philosophy of mesh handling. :-)

Best wishes
Johannes
User avatar
bernd
Posts: 8724
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Get edges from FEMMeshGmsh object

Postby bernd » Fri Nov 08, 2019 10:19 am

well explained ... just some more code ... edges from 3D Fem example ...

Code: Select all

doc = FreeCAD.open(FreeCAD.ConfigGet("AppHomePath") + "data/examples/FemCalculixCantilever3D.FCStd")
mesh = doc.Box_Mesh.FemMesh
mesh
for e in mesh.Edges:
    print("Edge: {} has Nodes {}".format(e, mesh.getElementNodes(e)))

Code: Select all

Python 3.6.8 (v3.6.8:3c6b436a57, Mar 26 2019, 15:45:44) [MSC v.1916 64 bit (AMD64)] on win32
Type 'help', 'copyright', 'credits' or 'license' for more information.
>>> doc = FreeCAD.open(FreeCAD.ConfigGet("AppHomePath") + "data/examples/FemCalculixCantilever3D.FCStd")
>>> # App.setActiveDocument("FemCalculixCantilever3D")
>>> # App.ActiveDocument=App.getDocument("FemCalculixCantilever3D")
>>> # Gui.ActiveDocument=Gui.getDocument("FemCalculixCantilever3D")
>>> mesh = doc.Box_Mesh.FemMesh
>>> mesh
========================== Dump contents of mesh ==========================

1) Total number of nodes:      	228
2) Total number of edges:      	52
3) Total number of faces:      	96
4) Total number of polygons:   	0
5) Total number of volumes:    	79
6) Total number of polyhedrons:	0

7) Total number of linear edges:	52
8) Total number of linear faces:	0
9) Total number of linear volumes:	0

10) Total number of quadratic edges:	0
11) Total number of quadratic faces:	96
11.1) Number of quadratic triangles:  	96
11.2) Number of quadratic quadrangles:	0
12) Total number of quadratic volumes:	79
12.1) Number of quadratic hexahedrons: 	0
12.2) Number of quadratic tetrahedrons:	79
12.3) Number of quadratic prisms:      	0
12.4) Number of quadratic pyramids:    	0

===========================================================================

>>> for e in mesh.Edges:
...     print("Edge: {} has Nodes {}".format(e, mesh.getElementNodes(e)))
... 
Edge: 1 has Nodes (6, 8)
Edge: 2 has Nodes (9, 6)
Edge: 3 has Nodes (10, 9)
Edge: 4 has Nodes (11, 10)
Edge: 5 has Nodes (12, 11)
Edge: 6 has Nodes (13, 12)
Edge: 7 has Nodes (14, 13)
Edge: 8 has Nodes (15, 14)
Edge: 9 has Nodes (16, 15)
Edge: 10 has Nodes (17, 16)
Edge: 11 has Nodes (18, 17)
Edge: 12 has Nodes (2, 18)
Edge: 13 has Nodes (4, 2)
Edge: 14 has Nodes (8, 19)
Edge: 15 has Nodes (19, 20)
Edge: 16 has Nodes (20, 21)
Edge: 17 has Nodes (21, 22)
Edge: 18 has Nodes (22, 23)
Edge: 19 has Nodes (23, 24)
Edge: 20 has Nodes (24, 25)
Edge: 21 has Nodes (25, 26)
Edge: 22 has Nodes (26, 27)
Edge: 23 has Nodes (27, 28)
Edge: 24 has Nodes (28, 4)
Edge: 25 has Nodes (7, 5)
Edge: 26 has Nodes (5, 29)
Edge: 27 has Nodes (29, 30)
Edge: 28 has Nodes (30, 31)
Edge: 29 has Nodes (31, 32)
Edge: 30 has Nodes (32, 33)
Edge: 31 has Nodes (33, 34)
Edge: 32 has Nodes (34, 35)
Edge: 33 has Nodes (35, 36)
Edge: 34 has Nodes (36, 37)
Edge: 35 has Nodes (37, 38)
Edge: 36 has Nodes (38, 1)
Edge: 37 has Nodes (1, 3)
Edge: 38 has Nodes (39, 7)
Edge: 39 has Nodes (40, 39)
Edge: 40 has Nodes (41, 40)
Edge: 41 has Nodes (42, 41)
Edge: 42 has Nodes (43, 42)
Edge: 43 has Nodes (44, 43)
Edge: 44 has Nodes (45, 44)
Edge: 45 has Nodes (46, 45)
Edge: 46 has Nodes (47, 46)
Edge: 47 has Nodes (48, 47)
Edge: 48 has Nodes (3, 48)
Edge: 49 has Nodes (2, 1)
Edge: 50 has Nodes (5, 6)
Edge: 51 has Nodes (3, 4)
Edge: 52 has Nodes (8, 7)
>>> 
User avatar
bernd
Posts: 8724
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Get edges from FEMMeshGmsh object

Postby bernd » Fri Nov 08, 2019 10:35 am

in your format as you wish ...

Code: Select all

doc = FreeCAD.open(FreeCAD.ConfigGet("AppHomePath") + "data/examples/FemCalculixCantilever3D.FCStd")
mesh = doc.Box_Mesh.FemMesh
edgs = {}
for e in mesh.Edges:
    edgs[e] = mesh.getElementNodes(e)

edgs

Code: Select all

>>> edgs
{1: (6, 8), 2: (9, 6), 3: (10, 9), 4: (11, 10), 5: (12, 11), 6: (13, 12), 7: (14, 13), 8: (15, 14), 9: (16, 15), 10: (17, 16), 11: (18, 17), 12: (2, 18), 13: (4, 2), 14: (8, 19), 15: (19, 20), 16: (20, 21), 17: (21, 22), 18: (22, 23), 19: (23, 24), 20: (24, 25), 21: (25, 26), 22: (26, 27), 23: (27, 28), 24: (28, 4), 25: (7, 5), 26: (5, 29), 27: (29, 30), 28: (30, 31), 29: (31, 32), 30: (32, 33), 31: (33, 34), 32: (34, 35), 33: (35, 36), 34: (36, 37), 35: (37, 38), 36: (38, 1), 37: (1, 3), 38: (39, 7), 39: (40, 39), 40: (41, 40), 41: (42, 41), 42: (43, 42), 43: (44, 43), 44: (45, 44), 45: (46, 45), 46: (47, 46), 47: (48, 47), 48: (3, 48), 49: (2, 1), 50: (5, 6), 51: (3, 4), 52: (8, 7)}
>>>