Get info from a FemMesh object

About the development of the FEM module/workbench.

Moderator: bernd

Post Reply
User avatar
johnwang
Veteran
Posts: 1382
Joined: Sun Jan 27, 2019 12:41 am

Get info from a FemMesh object

Post by johnwang »

Hi,

Try to use this code to get info of a FemMesh obj. Nodes is good. Edges only have edge num, but no edge node number. Where is it stored? or it is not stored?

Code: Select all

import Fem
femmesh = Fem.FemMesh()

femmesh.addNode(0, 0, 0, 1)
femmesh.addNode(1, 0, 0, 2)
femmesh.addNode(0.5, 1, 0, 3)

femmesh.addEdge([1,2], 1)
femmesh.addEdge([2,3], 2)
femmesh.addEdge([3,1], 3)

Fem.show(femmesh)

print (femmesh.Nodes)
print (femmesh.Edges)


Result

Code: Select all

{1: Vector (0.0, 0.0, 0.0), 2: Vector (1.0, 0.0, 0.0), 3: Vector (0.5, 1.0, 0.0)}
(1, 2, 3)
Regards,

John
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Get info from a FemMesh object

Post by wmayer »

Code: Select all

femmesh.getElementNodes(1) # (1, 2)
femmesh.getElementNodes(2) # (2, 3)
femmesh.getElementNodes(3) # (3, 1)
User avatar
johnwang
Veteran
Posts: 1382
Joined: Sun Jan 27, 2019 12:41 am

Re: Get info from a FemMesh object

Post by johnwang »

wmayer wrote: Wed Jul 29, 2020 6:04 am femmesh.getElementNodes(1) # (1, 2)
Interesting. Edge and Face all called element in FemMesh.

Thank you very much.
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Get info from a FemMesh object

Post by bernd »

johnwang wrote: Wed Jul 29, 2020 8:06 am
wmayer wrote: Wed Jul 29, 2020 6:04 am femmesh.getElementNodes(1) # (1, 2)
Interesting. Edge and Face all called element in FemMesh.
and Volumes too.
User avatar
johnwang
Veteran
Posts: 1382
Joined: Sun Jan 27, 2019 12:41 am

Re: Get info from a FemMesh object

Post by johnwang »

bernd wrote: Wed Jul 29, 2020 10:36 am and Volumes too.
Is there Element Type? I use the node length of a FemMesh element to decide how to add a Face. If 2d & 3d mixed, maybe there is problem.

Code: Select all

import Fem

femmeshOrg = Fem.FemMesh()
femmeshOrg.addNode(0, 0, 0, 1)
femmeshOrg.addNode(1, 0, 0, 2)
femmeshOrg.addNode(0.5, 1, 0, 3)
femmeshOrg.addFace([1,2,3])
#Fem.show(femmeshOrg)

nodes=femmeshOrg.Nodes
faces=femmeshOrg.Faces

femmeshNew = Fem.FemMesh()
for id in range(len(nodes)):
	femmeshNew.addNode(nodes[id+1].x,nodes[id+1].y,nodes[id+1].z,id+1)

for id in range(len(faces)):
	nd=femmeshOrg.getElementNodes(id+1)
	#femmesh.addFace([nd])
	nlen=len(nd)
	if nlen==3:
		femmeshNew.addFace([nd[0],nd[1],nd[2]])
	elif nlen==4:
		femmeshNew.addFace([nd[0],nd[1],nd[2],nd[3]])

Fem.show(femmeshNew)
vol.jpg
vol.jpg (21.96 KiB) Viewed 1173 times
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Get info from a FemMesh object

Post by bernd »

ATM no there is no problem. All edge elemnts have different node lengths, all face elements have different node lengths and all volume elements have different node lengths.

But mainly you are right. If there where some elements with same node length we would be in trouble.


https://github.com/berndhahnebach/FreeC ... p.cpp#L277
https://github.com/berndhahnebach/FreeC ... p.cpp#L367
https://github.com/berndhahnebach/FreeC ... p.cpp#L500

FEM_Mesh
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Get info from a FemMesh object

Post by wmayer »

johnwang wrote: Wed Jul 29, 2020 12:01 pm Is there Element Type? I use the node length of a FemMesh element to decide how to add a Face. If 2d & 3d mixed, maybe there is problem.
To figure out of what type an element is use the method getElementType(Id). It returns a string like, "Node", "Edge", "Face", "Volume", "0DElement" or "Ball".

Unless it's intended your code has some flaws because you won't copy over all nodes. The Nodes attribute already returns a dict with Id+Vector and can be easily copied with:

Code: Select all

for i in femmesh.Nodes.items():
    femmeshNew.addNode(*i[1], i[0])
Then when adding the faces there is no need to explicitly check for the number of nodes. Just use the * operator and you are done:

Code: Select all

for id in faces:
    nd = femmesh.getElementNodes(id)
    femmeshNew.addFace([*nd])
Full example:

Code: Select all

import Fem
femmesh = Fem.FemMesh()

femmesh.addNode(0, 0, 0, 1)
femmesh.addNode(2, 0, 0, 2)
femmesh.addNode(2, 2, 0, 3)
femmesh.addNode(0, 2, 0, 4)
femmesh.addNode(1, 1, 1, 5)

femmesh.addEdge([1,2], 1)
femmesh.addEdge([2,3], 2)
femmesh.addEdge([3,4], 3)
femmesh.addEdge([4,1], 4)

femmesh.addEdge([1,5], 5)
femmesh.addEdge([2,5], 6)
femmesh.addEdge([3,5], 7)
femmesh.addEdge([4,5], 8)

femmesh.addFace([1,4,3,2], 9)
femmesh.addFace([1,2,5], 10)
femmesh.addFace([2,3,5], 11)
femmesh.addFace([3,4,5], 12)
femmesh.addFace([4,1,5], 13)

Fem.show(femmesh)

nodes = femmesh.Nodes
faces = femmesh.Faces

femmeshNew = Fem.FemMesh()
for i in femmesh.Nodes.items():
    femmeshNew.addNode(*i[1], i[0])

for id in faces:
    nd = femmesh.getElementNodes(id)
    femmeshNew.addFace([*nd])

Fem.show(femmeshNew)
User avatar
johnwang
Veteran
Posts: 1382
Joined: Sun Jan 27, 2019 12:41 am

Re: Get info from a FemMesh object

Post by johnwang »

wmayer wrote: Thu Jul 30, 2020 12:09 pm
Then when adding the faces there is no need to explicitly check for the number of nodes. Just use the * operator and you are done:

Code: Select all

for id in faces:
    nd = femmesh.getElementNodes(id)
    femmeshNew.addFace([*nd])
I thought of this, but haven't figured it out. So I comment this line out.

Code: Select all

#femmesh.addFace([nd])
Yeah, I need that * operator.

Thank you very much again.
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
Post Reply