Stencil routines are useful both as direct updates and as matrix-free linear operators.
Apply a 2D Laplacian
num::pde::laplacian_stencil_2d(u, Lu, N);
Matrix-Free Operator
num::pde::laplacian_stencil_2d(x, y, N);
},
N * N);
CallableOp< F > make_op(F f, idx rows, idx cols)
void scale(Vector &v, real alpha, Backend b=default_backend)
Compute .
SolverResult cg(const Matrix &A, const Vector &b, Vector &x, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
The operator represents
\[
y = -L_h x .
\]
Periodic Diffusion Step
double coeff = kappa * dt / (h * h);
void diffusion_step_2d(Vector &u, int N, double coeff, Backend b=best_backend)
constexpr Backend best_backend
Fourth-Order Dirichlet Laplacian
num::pde::laplacian_stencil_2d_4th(u, Lu4, N);
Use matrix-free operators when the sparse matrix would be expensive to assemble or when the stencil is applied many times inside a Krylov method.