FEM FemMesh2Mesh: Difference between revisions

From FreeCAD Documentation
(V1.0 -> V0.21)
(Scripting)
Line 44: Line 44:
</translate>
</translate>
{{Code|code=
{{Code|code=
import femmesh.femmesh2mesh
import FreeCAD as App
mesh_obj = FEMMeshGmsh # the name of your mesh object
scale = 5 # displacement scale factor
out_mesh = femmesh.femmesh2mesh.femmesh_2_mesh(FreeCAD.ActiveDocument.mesh_obj.FemMesh, FreeCAD.ActiveDocument.CCX_Results, scale)
import Mesh
import Mesh
from femmesh import femmesh2mesh

doc = App.ActiveDocument
mesh_obj = doc.FEMMeshGmsh # the name of your mesh object
scale = 5 # displacement scale factor
out_mesh = femmesh2mesh.femmesh_2_mesh(mesh_obj.FemMesh, doc.CCX_Results, scale)
Mesh.show(Mesh.Mesh(out_mesh))
Mesh.show(Mesh.Mesh(out_mesh))
}}
}}
Line 59: Line 62:
{{Code|code=
{{Code|code=
from os.path import join
from os.path import join
import FreeCAD as App
the_file = join(FreeCAD.getResourceDir(), "examples", "FemCalculixCantilever3D.FCStd")
import Mesh
fc_file = FreeCAD.openDocument(the_file)
fem_mesh = fc_file.getObject("Box_Mesh").FemMesh # do not remove the _
result = fc_file.getObject("CCX_Results")
scale = 1 # displacement scale factor
from femmesh import femmesh2mesh
from femmesh import femmesh2mesh

path = join(App.getResourceDir(), "examples", "FemCalculixCantilever3D.FCStd")
doc = App.openDocument(path)
fem_mesh = doc.getObject("Box_Mesh").FemMesh
result = doc.getObject("CCX_Results")
scale = 1 # displacement scale factor
out_mesh = femmesh2mesh.femmesh_2_mesh(fem_mesh, result, scale)
out_mesh = femmesh2mesh.femmesh_2_mesh(fem_mesh, result, scale)
import Mesh
Mesh.show(Mesh.Mesh(out_mesh))
Mesh.show(Mesh.Mesh(out_mesh))
}}
}}

Revision as of 11:08, 10 October 2023

FEM FemMesh2Mesh

Menu location
Mesh → FEM mesh to mesh
Workbenches
FEM
Default shortcut
None
Introduced in version
-
See also
FEM tutorial

Description

This tool converts surfaces of 3D elements of a selected FEM mesh to mesh, or converts 2D FEM mesh to mesh. Internally it picks FEM mesh element faces which are unique (not shared by two elements) and uses them to create faces of a mesh. Optionally it allows to create a deformed mesh caused by the action of the defined forces. This is done by adding the displacement of the FEM results to the mesh nodes (scale of the displacement can be set by Python).

Usage

  1. Select a FEM mesh object.
  2. Optionally also select the FEM results.
  3. There are several ways to invoke the command:
    • Press the FEM mesh to mesh button.
    • Select the Mesh → FEM mesh to mesh option from the menu.

Scripting

Note: The parameter scale was introduced in version 0.21. For older versions of FreeCAD omit it from your code.

When you just require the displacement scale factor, check your mesh object name and the scale factor in the following code:

import FreeCAD as App
import Mesh
from femmesh import femmesh2mesh

doc = App.ActiveDocument
mesh_obj = doc.FEMMeshGmsh  # the name of your mesh object
scale = 5  # displacement scale factor
out_mesh = femmesh2mesh.femmesh_2_mesh(mesh_obj.FemMesh, doc.CCX_Results, scale)
Mesh.show(Mesh.Mesh(out_mesh))

The cantilever example:

from os.path import join
import FreeCAD as App
import Mesh
from femmesh import femmesh2mesh

path = join(App.getResourceDir(), "examples", "FemCalculixCantilever3D.FCStd")
doc = App.openDocument(path)
fem_mesh = doc.getObject("Box_Mesh").FemMesh
result = doc.getObject("CCX_Results")
scale = 1  # displacement scale factor
out_mesh = femmesh2mesh.femmesh_2_mesh(fem_mesh, result, scale)
Mesh.show(Mesh.Mesh(out_mesh))