Skip to content
Permalink
Browse files

FEM: result and mesh, add compact result and mesh, fixes #2873

  • Loading branch information...
berndhahnebach committed Jan 18, 2019
1 parent 50f0289 commit bc705a36072ed337d15073f303414eda24b2085b
@@ -105,6 +105,9 @@ 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)
# compact result object, fixes bug xxxx
from femresult.resulttools import compact_result as rs
results = rs(results)
if analysis:
analysis_object.addObject(results)
else:
@@ -1713,4 +1713,37 @@ def use_correct_fluidinout_ele_def(FluidInletoutlet_ele, fileName, fluid_inout_n
f.close()
inout_nodes_file.close()


def compact_mesh(old_femmesh):
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()

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

# TODO: Edges, Faces
for i, v in enumerate(old_femmesh.Volumes):
# print(i)
# print(v)
# print(old_femmesh.getElementNodes(v))
vid = i + 1
old_elem_nodes = old_femmesh.getElementNodes(v)
new_elemnodes = []
for old_node_id in old_elem_nodes:
new_elemnodes.append(node_map[old_node_id])
# print(new_elemnodes)
new_mesh.addVolume(new_elemnodes, vid)
elem_map[v] = 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,24 @@ def get_stats(resultobj, result_type):
return stats


def compact_result(res_obj):

# 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 bc705a3

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