MGGSS is a C implementation of a multigrid solver for the 2D Poisson equation using the Gauss-Seidel method. It employs Dirichlet boundary conditions on an equidistant 2D grid.
Version : 0.0
Author : Jannes Klee
Contact : jannes.klee@gmail.com
MGGSS solves the 2D Poisson equation with Dirichlet boundary conditions:
∇²u = f(x,y) on the unit square Ω = [0,1] × [0,1]
With boundary conditions:
- u(x,y) = 0 on ∂Ω (Dirichlet boundary conditions)
The Poisson equation is discretized using finite differences on an equidistant grid with step size h = 1/(n+1), where n is the number of interior grid points in each dimension.
The Laplacian ∇²u is approximated using the 5-point stencil:
∇²u₁ⱼ ≈ (uᵢ₊₁ⱼ + uᵢ₋₁ⱼ + uᵢⱼ₊₁ + uᵢⱼ₋₁ - 4uᵢⱼ) / h² = fᵢⱼ
This leads to the linear system:
4uᵢⱼ - uᵢ₊₁ⱼ - uᵢ₋₁ⱼ - uᵢⱼ₊₁ - uᵢⱼ₋₁ = h²fᵢⱼ
The solver uses the Gauss-Seidel method as a smoother, which iteratively updates the solution:
uᵢⱼ⁽ᵏ⁺¹⁾ = 0.25 * (h²fᵢⱼ + uᵢ₊₁ⱼ⁽ᵏ⁾ + uᵢ₋₁ⱼ⁽ᵏ⁺¹⁾ + uᵢⱼ₊₁⁽ᵏ⁾ + uᵢⱼ₋₁⁽ᵏ⁺¹⁾)
MGGSS implements a recursive multigrid V-cycle with the following components:
- Pre-smoothing: Apply Gauss-Seidel iterations on the fine grid
- Restriction: Compute residuals and restrict to coarser grid using full weighting
- Coarse grid correction: Recursively solve the error equation on coarser grids
- Prolongation: Interpolate corrections back to finer grids using bilinear interpolation
- Post-smoothing: Apply Gauss-Seidel iterations on the fine grid
The multigrid method significantly accelerates convergence compared to single-grid methods by efficiently reducing both high-frequency and low-frequency error components.
The restriction operator uses full weighting to transfer residuals from fine to coarse grids:
v_c[i/2+j/2*(n_c+2)] = 0.25*(v[i+j*(n+2)] + 0.5*(v[(i+1)+j*(n+2)] + v[(i-1)+j*(n+2)] + v[i+(j+1)*(n+2)] + v[i+(j-1)*(n+2)]) + 0.5*(v[(i+1)+(j+1)*(n+2)] + v[(i-1)+(j-1)*(n+2)]))
The prolongation operator uses bilinear interpolation to transfer corrections from coarse to fine grids:
- Even-even points: Direct copy from coarse grid
- Even-odd/odd-even points: Linear interpolation
- Odd-odd points: Bilinear interpolation
- Grid: Contains solution array
u, right-hand side arrayv, grid sizen, and step sizeh - Arrays: Use row-major ordering with ghost points for boundary handling
- n: Number of grid points (must be odd for proper coarsening)
- gamma: Number of multigrid levels (controls recursion depth)
- eps0: Error tolerance for convergence
- k: Problem type selector (1 = constant density circle, 2 = Gaussian distribution)
The solver uses the maximum norm of the residual as the convergence criterion:
||r||_∞ = max |rᵢⱼ| over all grid points
$ make$ make cleanSetup and initialization can be modified in src/init.c:
- Grid size: Change
nvariable (must be odd) - Error tolerance: Modify
eps0 - Problem type: Set
kto 1 (circle) or 2 (Gaussian) - Multigrid levels: Adjust
gammaparameter
The solver supports two built-in right-hand side functions:
-
Constant density circle (k=1):
f(x,y) = 100 if √((x-0.5)² + (y-0.5)²) < 0.1 f(x,y) = 0 otherwise -
Gaussian distribution (k=2):
f(x,y) = exp(-1000 * ((x-0.5)² + (y-0.5)²))
The solver outputs the solution in CSV format:
x, y, u(x,y), f(x,y)
Where:
x, y: Coordinates in [0,1] × [0,1]u(x,y): Computed solutionf(x,y): Right-hand side function
The multigrid method achieves O(n) complexity for solving elliptic PDEs, compared to O(n²) or O(n³) for traditional iterative methods. This is possible because:
- Smoothing property: Gauss-Seidel efficiently reduces high-frequency errors
- Approximation property: Coarse grids provide good approximations to low-frequency errors
- Two-grid convergence: The combination of smoothing and coarse grid correction leads to rapid error reduction
For the Poisson equation with Dirichlet boundary conditions, the multigrid V-cycle typically achieves:
- Convergence rate: ~0.1-0.3 per cycle (depending on γ)
- Asymptotic complexity: O(n) operations for n unknowns
- Memory requirements: O(n) storage
This software is licensed under the GPLv3. See LICENSE for details.
The implementation follows standard multigrid algorithms as described in:
- Briggs, W.L., Henson, V.E., McCormick, S.F. (2000). "A Multigrid Tutorial"
- Hackbusch, W. (1985). "Multi-Grid Methods and Applications"
- Trottenberg, U., Oosterlee, C.W., Schüller, A. (2001). "Multigrid"