Meshing
Overview
A mesh is geometry made finite. A solid defined by a signed distance field is a smooth, exact object — you can ask it for a distance at any point — but a computer that needs to simulate or draw that solid works with a finite number of points. Meshing is the step that turns the continuous shape into that finite set of points and the cells that connect them.
There are two kinds of mesh, distinguished by what they cover:
- a surface mesh covers only the boundary of a shape with triangles — enough to draw it, to measure its area, or to run a boundary-based method;
- a volume mesh covers the inside too, filling the solid with tetrahedra — which is what a finite-element solver needs to integrate its equations over the whole domain.
This chapter introduces the two mesh types and the two entry points that build them. The chapters that follow go deeper into surface meshing, volume meshing, mesh repair, and rebuilding a mesh from points.
The two mesh types
TriangleMesh
A surface mesh stores its geometry as a list of vertex positions and a list of triangles, each triangle an index triple into the vertex list:
Rasmah.TriangleMesh — Type
TriangleMeshA surface triangle mesh: a $3 \times n$ vertex matrix and a $3 \times m$ face (vertex-index) matrix, with optional attached per-element data.
Theory
A triangle mesh discretizes a surface into flat triangles. Each column of faces is a triple of indices into vertices, so a mesh is fully described by where its vertices sit and how they are connected. Two vertices are shared when several faces reference the same index — that sharing is what makes a mesh one connected surface rather than a loose bag of triangles.
Fields
vertices:3×nvertex coordinates.faces:3×mtriangle vertex indices.data: optional attached mesh data (nothingby default).
Example
julia> using Rasmah
julia> surface_mesh(sphere(2.0)) isa TriangleMesh
truevtk(surface_mesh(sphere(1.0)))TetMesh
A volume mesh stores a list of node positions and a list of tetrahedra (4-node cells):
Rasmah.TetMesh — Type
TetMeshA tetrahedral volume mesh: a $3 \times n$ node matrix and a $4 \times m$ element (node-index) matrix, with optional attached per-element data.
Theory
A tetrahedral mesh partitions a solid's interior into tetrahedra. Each column of elements is a quadruple of indices into nodes, and every pair of adjacent tetrahedra meets along a shared face (the same three node indices). That face-to-face connectivity is the exact input a finite-element assembly consumes, which is why volume meshes are the bridge from geometry to simulation.
Fields
nodes:3×nnode coordinates.elements:4×mtetrahedron node indices.data: optional attached mesh data (nothingby default).
Example
julia> using Rasmah
julia> tetrahedralize(sphere(1.0), 16) isa TetMesh
truevtk(tetrahedralize(sphere(1.0), 8))The canonical workflow
The same shape-first pipeline used everywhere in Rasmah applies to meshing: take a shape, evaluate it, and mesh the result. For a box with a cylindrical hole:
part = difference(box(2.0, 2.0, 2.0), cylinder(0.5, 2.2))Difference{Box{Float64, Float64, Float64}, Cylinder{Float64, Float64}}(Box{Float64, Float64, Float64}(2.0, 2.0, 2.0), Cylinder{Float64, Float64}(0.5, 2.2))The surface mesh is a triangle approximation of the part's boundary:
surf = surface_mesh(part)TriangleMesh{Matrix{Float64}, Matrix{Int64}, Nothing}([-0.9625000000000001 -1.0 … 0.9624999999999999 0.9624999999999999; -1.0 -0.9625000000000001 … 1.0 0.9624999999999999; -0.9625000000000001 -0.9625000000000001 … 0.9624999999999999 1.0], [1 4 … 25786 25790; 2 5 … 25788 25791; 3 7 … 25789 25792], nothing)vtk(surf)and the volume mesh fills it with tetrahedra for simulation:
vol = tetrahedralize(part, 16)TetMesh{Matrix{Float64}, Matrix{Int64}, Nothing}([-1.1 -0.9625000000000001 … 0.9624999999999999 0.9869714080053403; -1.1 -1.1 … 0.9913185273599261 0.9869714080053403; -1.1 -1.1 … 0.9913185273599261 0.9869714080053403], [308 308 … 4606 4606; 4915 4914 … 11192 11195; 4914 4917 … 11195 10444; 4916 4916 … 11225 11225], nothing)vtk(vol)Because both meshes are derived from the same SDF, they are two views of the same geometry — one on the boundary, one on the interior.
Next steps
Surface meshing in detail — icospheres, marching cubes, and the adaptive kernels — is the subject of Surface meshing, and the volume side is covered in Volume meshing.
