Skip to content
Permalink
Browse files

FEM: result and mesh, add compact result and mesh, workaround for iss…

…ue #2873
  • Loading branch information...
berndhahnebach authored and wwmayer committed Jan 18, 2019
1 parent e385ed7 commit 82d92280af74223dfc2f0c190413df6725b4b62c
@@ -105,6 +105,11 @@ def importFrd(filename, analysis=None, result_name_prefix=None):
results = ObjectsFem.makeResultMechanical(FreeCAD.ActiveDocument, results_name)
results.Mesh = result_mesh_object
results = importToolsFem.fill_femresult_mechanical(results, result_set, span)
if not results.MassFlowRate:
# only compact result if not Flow 1D results
# compact result object, workaround for bug 2873, https://www.freecadweb.org/tracker/view.php?id=2873
from femresult.resulttools import compact_result as rs
results = rs(results)
if analysis:
analysis_object.addObject(results)
else:
@@ -1713,4 +1713,55 @@ def use_correct_fluidinout_ele_def(FluidInletoutlet_ele, fileName, fluid_inout_n
f.close()
inout_nodes_file.close()


def compact_mesh(old_femmesh):
'''
removes all gaps in node and element ids, start ids with 1
returns a tuple (FemMesh, node_assignment_map, element_assignment_map)
'''
node_map = {} # {old_node_id: new_node_id, ...}
elem_map = {} # {old_elem_id: new_elem_id, ...}
old_nodes = old_femmesh.Nodes
import Fem
new_mesh = Fem.FemMesh()

if old_nodes:
for i, n in enumerate(old_nodes):
nid = i + 1
new_mesh.addNode(old_nodes[n].x, old_nodes[n].y, old_nodes[n].z, nid)
node_map[n] = nid

if old_femmesh.Edges:
for i, ed in enumerate(old_femmesh.Edges):
eid = i + 1
old_elem_nodes = old_femmesh.getElementNodes(ed)
new_elemnodes = []
for old_node_id in old_elem_nodes:
new_elemnodes.append(node_map[old_node_id])
new_mesh.addEdge(new_elemnodes, eid)
elem_map[ed] = eid

if old_femmesh.Faces:
for i, fa in enumerate(old_femmesh.Faces):
fid = i + 1
old_elem_nodes = old_femmesh.getElementNodes(fa)
new_elemnodes = []
for old_node_id in old_elem_nodes:
new_elemnodes.append(node_map[old_node_id])
new_mesh.addFace(new_elemnodes, fid)
elem_map[fa] = fid

if old_femmesh.Volumes:
for i, vo in enumerate(old_femmesh.Volumes):
vid = i + 1
old_elem_nodes = old_femmesh.getElementNodes(vo)
new_elemnodes = []
for old_node_id in old_elem_nodes:
new_elemnodes.append(node_map[old_node_id])
new_mesh.addVolume(new_elemnodes, vid)
elem_map[vo] = vid

# may be return another value if the mesh was compacted, just check last map entries
return (new_mesh, node_map, elem_map)

## @}
@@ -153,4 +153,28 @@ def get_stats(resultobj, result_type):
return stats


def compact_result(res_obj):
'''
compacts result.Mesh and appropriate result.NodeNumbers
'''
# as workaround for https://www.freecadweb.org/tracker/view.php?id=2873

# get compact mesh data
from femmesh.meshtools import compact_mesh as cm
compact_femmesh_data = cm(res_obj.Mesh.FemMesh)
compact_femmesh = compact_femmesh_data[0]
node_map = compact_femmesh_data[1]
# elem_map = compact_femmesh_data[2] # FreeCAD result obj does not support elem results ATM

# set result mesh
res_obj.Mesh.FemMesh = compact_femmesh

# set result node numbers
new_node_numbers = []
for old_node_id in res_obj.NodeNumbers:
new_node_numbers.append(node_map[old_node_id])
res_obj.NodeNumbers = new_node_numbers

return res_obj

## @}

0 comments on commit 82d9228

Please sign in to comment.
You can’t perform that action at this time.