import numpy as np
doc = App.ActiveDocument
mesh = doc.getObject("FEMMeshGmsh").FemMesh
mesh.NodeCount # returns 63
mesh.VolumeCount # returns 24
for i in range(1,mesh.VolumeCount+1):
print(mesh.getElementNodes(i)) # returns 12 times 3 and 12 times 6
returns 3 nodes for the first 12 elements and 6 for the second 12.
I guess you iterated through the elements with the lowest numbers, i.e. 12 edge elements and 6 face elements. But the mesh contains 6 edge elements, 24 face elements and 24 volume elements.
bernd wrote: ↑Tue Jan 22, 2019 4:01 pm
What would you like to make a macro for?
I am doing a FEM test bench for "in-house" testing of some ideas, like the 6-node curved face interface element and improved (over CCX) beam and shell elements. So far its going quite well. I am impressed what can be done wit the API, although I come across some quirky behaviour that I will report on separately.
for obj in FreeCAD.ActiveDocument.Objects:
if obj.isDerivedFrom('Fem::ConstraintDisplacement'):
if obj.References != []:
if "Vertex" in obj.References[0][1][0]:
print("Vertex constraint")
elif "Edge"in obj.References[0][1][0]:
print("Edge constraint")
else:
print("Face constraint")
else:
print("No constraint references")
How do I get from here to the nodes on a vertex, edge or face?
for obj in FreeCAD.ActiveDocument.Objects:
if obj.isDerivedFrom('Fem::ConstraintDisplacement'):
for part, boundaries in obj.References:
for boundary in boundaries:
ref = part.Shape.getElement(boundary)
if type(ref)==Part.Vertex:
nodes=mesh.getNodesByVertex(ref)
elif type(ref)==Part.Edge:
nodes=mesh.getNodesByEdge(ref)
elif type(ref)==Part.Face:
nodes=mesh.getNodesByFace(ref)
else:
print("No Boundaries Found")
dispfaces=[]
for obj in FreeCAD.ActiveDocument.Objects:
if obj.isDerivedFrom('Fem::ConstraintDisplacement'):
bcnodes= []
bctype=[obj.xFree,obj.yFree,obj.zFree]
bcvalue=[obj.xDisplacement,obj.yDisplacement,obj.zDisplacement]
for part, boundaries in obj.References:
for boundary in boundaries:
ref = part.Shape.getElement(boundary)
if type(ref)==Part.Vertex:
bcnodes.append(mesh.getNodesByVertex(ref))
elif type(ref)==Part.Edge:
bcnodes.append(mesh.getNodesByEdge(ref))
elif type(ref)==Part.Face:
bcnodes.append(mesh.getNodesByFace(ref))
else:
print("No Boundaries Found")
dispfaces.append([[item for sublist in bcnodes for item in sublist],bctype,bcvalue])