numerics 0.1.0
Loading...
Searching...
No Matches
poisson.hpp
Go to the documentation of this file.
1/// @file pde/poisson.hpp
2/// @brief 2D Poisson equation solved via the Discrete Sine Transform.
3///
4/// Solves -Delta u = f on (0,1)^2 with homogeneous Dirichlet BC,
5/// discretised on an N x N interior grid with h = 1/(N+1).
6/// N must equal 2^p - 1 so that the odd-extension length 2(N+1) is a
7/// power of two (required by the radix-2 FFT backend).
8///
9/// Algorithm (Demmel, CS267 Lecture 20):
10/// L_2 = L_1 x I + I x L_1, L_1 = tridiag(-1, 2, -1).
11/// L_1 = F * D * F^T, F_{jk} = sin(j*k*pi/(N+1)).
12/// Transformed system: u_hat_{jk} = h^2 * f_hat_{jk} / (D_j + D_k).
13/// DST-I computed via complex FFT on an odd-extended sequence.
14/// Cost: O(N^2 log N).
15///
16/// Two variants:
17/// poisson2d_fd -- FD eigenvalues D_k = 2(1 - cos(k*pi/(N+1))). Error O(h^2).
18/// poisson2d -- Exact eigenvalues (k*pi)^2. Machine-precision error for
19/// f in the DST eigenbasis; exponential convergence otherwise.
20///
21/// Reference: J. Demmel, CS267 Lecture 20, UC Berkeley, 2025.
22#pragma once
23
24#include "core/matrix.hpp"
25
26namespace num {
27namespace pde {
28
29/// @brief Solve -Delta u = f on (0,1)^2 (Dirichlet) via DST with FD eigenvalues.
30///
31/// @param f N x N matrix of RHS values on the interior grid (row i, col j
32/// corresponds to the grid point ((i+1)*h, (j+1)*h)).
33/// @param N Grid dimension. Must satisfy N = 2^p - 1.
34/// @return N x N solution matrix u.
35[[nodiscard]] Matrix poisson2d_fd(const Matrix& f, int N);
36
37/// @brief Solve -Delta u = f on (0,1)^2 (Dirichlet) via DST with exact eigenvalues.
38///
39/// Replaces the FD eigenvalue D_k = 2(1 - cos(k*pi/(N+1))) with the exact
40/// eigenvalue (k*pi)^2 of the continuous operator -d^2/dx^2. The error is
41/// determined by the quadrature approximation of the DST projection rather
42/// than the FD truncation of the eigenvalue, giving spectral accuracy.
43///
44/// @param f N x N matrix of RHS values.
45/// @param N Grid dimension. Must satisfy N = 2^p - 1.
46/// @return N x N solution matrix u.
47[[nodiscard]] Matrix poisson2d(const Matrix& f, int N);
48
49} // namespace pde
50} // namespace num
Matrix operations.
Matrix poisson2d(const Matrix &f, int N)
Solve -Delta u = f on (0,1)^2 (Dirichlet) via DST with exact eigenvalues.
Definition poisson.cpp:145
Matrix poisson2d_fd(const Matrix &f, int N)
Solve -Delta u = f on (0,1)^2 (Dirichlet) via DST with FD eigenvalues.
Definition poisson.cpp:106