Theory contents

Assembly

On this page

How do element contributions become the global linear system?

Each element knows only its own nodes. Assembly adds every element’s stiffness and load into one global system. Where elements share a node, their contributions add. Units are N, mm and MPa.

Local and global degrees of freedom

A degree of freedom (DOF) is one unknown coefficient: one displacement component of one basis function. An element numbers its DOFs locally, 0 to 3ne−1. The model numbers every DOF once, globally. The element’s connectivity, its list of global node numbers, links the two numberings.

For a solid with nb scalar basis functions, the global coefficient vector d has nd=​3nb entries. At order 1, nb is the number of mesh vertices. Order 2 adds one function per tetrahedral edge; on hexahedra it also adds one per face and one per element. For example, a 10 × 2 × 2 grid of hexahedra has 11×3×3=​99 vertices and 297 DOFs at order 1. At order 2 its nodes form a 21 × 5 × 5 lattice: 525 functions and 1575 DOFs.

Worked example: two bar elements

Use the axial bar from What is FEM?: length L=​1000 mm, area A=​10000 mm2, E=​210000 MPa and end force P=​106 N. Split it into two 500 mm elements with nodes 1, 2 and 3. Each node has one DOF, its axial displacement in mm. Each element is a spring of stiffness:

k=EALe=210000×10000500 N/mm=4.2×106 N/mm.
K(e)=k[1−1−11]

Element 1 connects nodes (1, 2); element 2 connects (2, 3). Add each 2 × 2 block into the rows and columns of its nodes. Node 2 belongs to both elements, so its diagonal receives k twice:

K=k[1−10−11+1−10−11]

The load vector is f=​(R,0,P) N, where R is the unknown support reaction at node 1. As assembled, K is singular: each row sums to zero because a rigid translation costs no energy. Fixing node 1 (d1=​0) leaves two equations for the two unknowns:

k(2d2−d3)=0,k(−d2+d3)=P.

Solving gives d2=​P/k=​5/21 mm≈​0.238 mm and d3=​2P/k=​10/21 mm≈​0.476 mm. This equals the analytical PL/(EA). The first row then gives R=​−kd2=​−106 N, balancing P. Linear elements are exact here because the true displacement of a uniform bar without body load is linear. Supports are treated in detail in Loads and constraints.

A bar fixed at node 1 and pulled at node 3, made of two elements. Each element's two-by-two stiffness matrix is added into the three-by-three global matrix; the entries of the shared node 2 overlap and add to k1 plus k2.
Assembly of the two-element bar. Each element matrix is added into the rows and columns of its nodes; at the shared node 2 both contributions add.

Assembly as gather and scatter

Formally, a Boolean matrix Ae of size 3ne×nd gathers the element’s DOFs from the global vector: d(e)=​Aed. Equating the internal work of the elements with the global work gives:

K=∑eAeTK(e)Ae,f=∑eAeTf(e).

Ae is never built. Implementations keep a list of the element’s global DOF indices and add entry (i,j) of K(e) to entry (gi,gj) of K, where gi is the global index of local DOF i. Elements may be processed in any order. In the bar, element 1 has indices (1, 2) and element 2 has (2, 3).

Two tetrahedra sharing a face

Take five vertices, 0 to 4, and two order-1 tetrahedra: T1=​(0,1,2,3) and T2=​(1,2,3,4). They share the face (1,2,3). With nb=​5, there are 15 global DOFs. Using KoFEM’s interleaved order explained below, component c=​0,1,2 (x,y,z) of vertex v has global index 3v+c:

Global DOF indices per element
Elementx DOFsy DOFsz DOFs
T1 (0, 1, 2, 3)0, 3, 6, 91, 4, 7, 102, 5, 8, 11
T2 (1, 2, 3, 4)3, 6, 9, 124, 7, 10, 135, 8, 11, 14

Each 12 × 12 element matrix lands in a 15 × 15 global matrix. Nine DOFs belong to both elements, so the 9 × 9 block of the shared face receives two contributions. Vertices 0 and 4 share no element, so their 3 × 3 coupling block stays zero. Of the 25 vertex pairs, 23 are coupled: the global matrix has 23×9=​207 structural nonzeros out of 225. In a large mesh each vertex couples only to its neighbours, so almost all entries are zero and K is stored as a sparse matrix.

DOF ordering

Two orders are common for the same coefficients:

KoFEM’s solid solve uses the interleaved order for the global vector and for each element matrix: local index 3a+i for component i of element node a. The two orders differ only by a permutation matrix P: Kblocked=​PKinterleavedPT. Libraries such as MFEM use the component-blocked order. The displacement field and every physical result are unchanged; only array positions differ.

At order 1 the node of a DOF is the input vertex, so the x,y,z displacement of vertex v sits at 3v, 3v+1 and 3v+2. At order 2, nodes added on edges follow all vertices, then hexahedron face nodes, then hexahedron centre nodes. They are numbered from the mesh alone, so the same mesh always gives the same numbering.

Properties of the global matrix

Bodies with different materials still assemble into one K. Each element uses its own body’s λ and μ, and contributions add at shared nodes. The Linear solve page explains how the constrained system is solved.

Left: a triangular mesh with one node and its neighbours highlighted. Right: the sparsity pattern of the plane-elasticity stiffness matrix of that mesh; nonzero entries cluster in a band around the diagonal, and the highlighted node's two rows have nonzeros only for its neighbours.
A small triangular mesh and the nonzero pattern of its plane-elasticity stiffness matrix, two DOFs per node. A node couples only to the nodes of its own elements (highlighted), so most entries are zero. Numbering the nodes from left to right keeps the nonzeros near the diagonal.

KoFEM implementation

KoFEM’s solid solve runs in its Rust finite-element module; the element integrals follow MFEM 4.7, from which they are ported. The app drives the solve from solveSolidInRust.

Textbook step to production code
StepWhereWhat happens
Mesh and connectivityApp, RustThe app packs vertices and tetrahedra/hexahedra with a material index per element (amg.ts); the Rust mesh checks every element and adds the order-2 nodes (mesh.rs).
DOF numberingRustThree DOFs per node, interleaved, 3a+i (mesh.rs).
Material per elementRustλ and μ from each body’s E and ν (material.rs).
Element stiffness and quadratureRustThe isotropic integrand with the rules of the elements page (element.rs).
Scatter-add into KRustA sparse pattern from the node neighbours, then each element matrix added into it (assembly.rs).
Surface loadsApp, RustThe app sends each force, traction or pressure group’s faces; Rust matches them to boundary faces and integrates Nat (surface.rs).
Point loadsAppAdded directly to the load vector at a vertex’s three DOFs (amg.ts).
SupportsApp, RustThe app lists constrained DOFs; Rust extends them to order-2 edge nodes and eliminates them (static_solve.rs).
Mixed solid–shellRustThe same order-1 solid matrix, combined with the shell facets through the coupling equations (coupled_static.rs).

KoFEM-specific decisions are the element order offered, the material mapping, the conversion of face forces to tractions and the treatment of supports. The axial bar example runs this complete path in the browser; open it in the app and run it yourself.

Sources and further reading

  1. MFEM: Finite element methods, finite element spaces, bilinear forms and assembly; KoFEM’s element integrals are ported from MFEM.
  2. Hughes, The Finite Element Method: Linear Static and Dynamic Finite Element Analysis (2000), the assembly operator and global DOF arrays.
  3. Bathe, Finite Element Procedures (1996), direct stiffness assembly and properties of the stiffness matrix.

The worked numbers were checked with exact rational arithmetic. Related pages: stiffness notation and Equilibrium and weak form.