Finite element mesher#
Finite element mesher of B-Rep models, written in Python.
It meshes volume models and 2D surfaces, and writes the mesh in the gmsh .msh 4.1 ASCII format, that can be read
back with design3d.gmsh_vm.GmshParser. The meshing follows the same steps as gmsh:
the curves of the model are meshed first, with a uniform element size along each curve,
each face is then meshed in its parametric domain with a constrained Delaunay triangulation (triangle library). Its boundary nodes are taken from the meshed curves, so adjacent faces share their nodes,
each closed shell is finally meshed with tetrahedra, by a Delaunay tetrahedralization (scipy) of the surface nodes and of interior nodes placed on a lattice. The diagonals of the surface triangles are flipped, and the surface mesh is refined, until each surface triangle is a face of the tetrahedralization: the volume mesh then conforms to the surface mesh. Its quality is improved by smoothing the interior nodes, by optimizing the position of the nodes of flat tetrahedra and by flipping flat tetrahedra.
Second order meshes get their middle nodes placed on the geometry: on the curves, on the surfaces, and at the middle of the edges inside the volumes.
- class design3d.fem_mesher.FEMMesher(shells: list, sizes: list[float], curvature_mesh_size: int = 0, min_points: int | None = None, seed: int = 0)[source]#
Bases:
objectFinite element mesher of shells, that writes the mesh in the gmsh .msh format.
- Parameters:
shells (list[design3d.shells.Shell3D]) – The shells to mesh. Closed shells are meshed with tetrahedra up to mesh dimension 3, open shells are meshed with triangles only. Faces and edges shared by shells are meshed once, so the meshes of the shells are conformal
sizes (list[float]) – The target size of the elements of each shell
curvature_mesh_size (int, optional) – The minimal number of elements per 2*pi radians along curved edges and surfaces. 0 disables the refinement from curvature, defaults to 0
min_points (int, optional) – The minimal number of nodes on the edges shorter than min_points times the mesh size, defaults to None
seed (int, optional) – The seed of the small random perturbations of the nodes, for reproducible meshes, defaults to 0
- static element_size(factor: float, length: float, initial_mesh_size: float = 5) float[source]#
Computes the element size from a characteristic length, like the gmsh .geo files written by design3d.
- Parameters:
factor – A float, between 0 and 1, that describes the mesh quality (1 for coarse mesh - 0 for fine mesh)
length – The characteristic length of the meshed object
initial_mesh_size – If factor=1, there will be initial_mesh_size elements per dimension
- classmethod from_surface2d(surface2d, factor: float, curvature_mesh_size: int = 0, min_points: int | None = None, initial_mesh_size: float = 5)[source]#
Defines a mesher of a 2D surface, in the plane z=0.
The element size is the square root of the surface area, divided by initial_mesh_size and multiplied by factor.
- Parameters:
surface2d (design3d.surfaces.Surface2D) – The surface to mesh
factor (float) – A float, between 0 and 1, that describes the mesh quality (1 for coarse mesh - 0 for fine mesh)
curvature_mesh_size (int, optional) – The minimal number of elements per 2*pi radians, defaults to 0
min_points (int, optional) – The minimal number of nodes on the edges shorter than min_points times the mesh size, defaults to None
initial_mesh_size (float, optional) – If factor=1, there will be initial_mesh_size elements per dimension, defaults to 5
- classmethod from_volume_model(volume_model, factor: float, curvature_mesh_size: int = 0, min_points: int | None = None, initial_mesh_size: float = 5)[source]#
Defines a mesher of the shells of a volume model.
The element size of a closed shell is the cubic root of the volume of its bounding box, divided by initial_mesh_size and multiplied by factor. For an open shell, the square root of its area is used.
- Parameters:
volume_model (design3d.core.VolumeModel) – The volume model to mesh
factor (float) – A float, between 0 and 1, that describes the mesh quality (1 for coarse mesh - 0 for fine mesh)
curvature_mesh_size (int, optional) – The minimal number of elements per 2*pi radians, defaults to 0
min_points (int, optional) – The minimal number of nodes on the edges shorter than min_points times the mesh size, defaults to None
initial_mesh_size (float, optional) – If factor=1, there will be initial_mesh_size elements per dimension, defaults to 5
- generate(mesh_dimension: int, mesh_order: int = 1)[source]#
Generates the mesh.
- Parameters:
mesh_dimension (int) – The mesh dimension (1: edges, 2: triangles, 3: tetrahedra)
mesh_order (int, optional) – The mesh order (1: linear, 2: second order), defaults to 1
- Returns:
The mesher itself
- to_msh(file_name: str)[source]#
Writes the generated mesh in a file, in the gmsh .msh format (version 4.1, ASCII).
- Parameters:
file_name (str) – The file name, with the .msh extension added if missing