Generate Meshes#

FElupe provides a simple mesh generation module felupe.mesh. A Mesh instance contains essentially two arrays: one with points and another one containing the cell connectivities, called cells. Only a single cell_type is supported per mesh. Optionally the cell_type is specified which is used if the mesh is saved as a VTK or a XDMF file. These cell types are identical to cell types used in meshio (VTK types): line, quad and hexahedron for linear lagrange elements or triangle and tetra for 2- and 3-simplices or VTK_LAGRANGE_HEXAHEDRON for 3d lagrange-cells with polynomial shape functions of arbitrary order.

import numpy as np
import felupe as fe

points = np.array([
    [ 0, 0], # point 1
    [ 1, 0], # point 2
    [ 0, 1], # point 3
    [ 1, 1], # point 4
], dtype=float)

cells = np.array([
    [ 0, 1, 3, 2], # point-connectivity of first cell
])

mesh = fe.Mesh(points, cells, cell_type="quad")
../_images/quad.png

Generate a cube by hand#

First let’s start with the generation of a line from x=1 to x=3 with n=2 points. Next, the line is expanded into a rectangle. The z argument of felupe.mesh.expand() represents the total expansion. Again, an expansion of our rectangle leads to a hexahedron. Several other useful functions are available beside felupe.mesh.expand(): felupe.mesh.rotate(), felupe.mesh.revolve() and felupe.mesh.sweep(). With these simple tools at hand, rectangles, cubes or cylinders may be constructed with ease.

line = fe.mesh.Line(a=1, b=3, n=7)
rect = fe.mesh.expand(line, n=2, z=5)
hexa = fe.mesh.expand(rect, n=2, z=3)
../_images/cube.png

Lines, rectangles and cubes#

Of course lines, rectangles, cubes and cylinders do not have to be constructed manually each time. Instead, some easier to use classes are povided by FElupe like felupe.mesh.Line, felupe.Rectangle or felupe.Cube.

Triangle and Tetrahedron meshes#

Any quad or tetrahedron mesh may be subdivided (triangulated) to meshes out of Triangle or Tetrahedrons by felupe.mesh.triangulate().

rectangle_quad = fe.Rectangle(n=5)
rectangle_tetra = fe.mesh.triangulate(rect_quad)

cube_hexahedron = fe.Cube(n=5)
cube_tetra = fe.mesh.triangulate(cube_hexahedron)

Meshes with midpoints#

If a mesh with midpoints is required by a region, functions for edge, face and volume midpoint insertions are provided in felupe.mesh.add_midpoints_edges(), felupe.mesh.add_midpoints_faces() and felupe.mesh.add_midpoints_volumes(). A low-order mesh, e.g. a mesh with cell-type quad, can be converted to a quadratic mesh with felupe.mesh.convert(). By default, only midpoints on edges are inserted. Hence, the resulting cell-type is quad8. If midpoints on faces are also calculated, the resulting cell-type is quad9.

rectangle_quad4 = fe.Rectangle(n=6)
rectangle_quad8 = fe.mesh.convert(rectangle_quad4, order=2)
rectangle_quad9 = fe.mesh.convert(rectangle_quad4, order=2, calc_midfaces=True)

The same also applies on meshes with triangles.

rectangle_triangle3 = fe.mesh.triangulate(fe.Rectangle(n=6))
rectangle_triangle6 = fe.mesh.add_midpoints_edges(rectangle_triangle3)