Finite Element from Scratch in Python
Introduction
The best way to learn FEM is to implement it yourself. This tutorial depends on no existing framework - starting from triangular elements, it builds a 2D linear-elastic solver in pure NumPy/SciPy, covering the full pipeline from meshing to post-processing. For engineers and students who want to deeply understand FEM internals.
Path
Chapter 1: Triangular elements & shape functions (2-3 days)
- Understand FEM core: from weak form to element matrix
- Implement shape functions and their Jacobians
import numpy as np
# Linear triangular element shape functions N1, N2, N3,
# expressed in area coordinates (L1, L2, L3)
def shape_functions(xi, eta):
return [1 - xi - eta, xi, eta]
# Shape function derivatives (Jacobian transform)
def dN_dXY(xi, eta, coords):
# coords: 3x2 nodal coordinates
J = np.array([[coords[1,0]-coords[0,0], coords[2,0]-coords[0,0]],
[coords[1,1]-coords[0,1], coords[2,1]-coords[0,1]]])
detJ = np.linalg.det(J)
# ... assemble the B matrix
Chapter 2: Stiffness assembly (2-3 days)
- Global stiffness assembly logic
- Gaussian integration; sparse COO assembly
Chapter 3: Boundary conditions & solve (1-2 days)
- Dirichlet/Neumann handling
- SciPy sparse solver; stress recovery
Chapter 4: Meshing & post-processing (1-2 days)
- Delaunay triangulation; matplotlib contours
Who it's for
- Mech/civil/aero students who know FEM formulas but want to verify by hand
- Programmers wanting first-principles FEM, not just software operation
- A foundation before learning FEniCS / Abaqus
Tags: FEMFinite ElementPythonSolid MechanicsNumerical Method
Related entries
- Physics Simulation & ML Integration Roadmap · Systematic path from classical PDE numerics to data-driven physics AI - FEM, FVM
- FNO (Fourier Neural Operator) Tutorial · Systematic FNO from theory to code - for engineers and researchers wanting neura
- DeepONet Getting Started · Systematic DeepONet theory and DeepXDE implementation - for PINN developers hand
- Operator Learning: A Survey · A systematic survey of operator learning covering the theory, architectures and
- Physics-Based Deep Learning (Online Book) · A free online textbook from TU Munich covering physics + deep learning: differen