11  Differential Operators

Differential operators (gradient, divergence, curl, Hessian, Laplacian).

IPPL provides a set of differential operators that act on fields. The differential operators use the spacing obtained from the UniformCartesian mesh. For example, laplace has a pre-factor of 1 / h[d]^2 in each dimension d.

Operation Example
gradient efield = grad(phi);
divergence rho = div(efield);
curl result = curl(vectorField);
Hessian matrixField = hess(rho);
Laplacian lap = laplace(rho);

11.1 Laplacian example

test/field/TestLaplace.cpp is the compact example for differential field operators. It builds a 3-dimensinal periodic scalar field on [-1, 1]^3,

\[ u(x,y,z) = \sin(\pi x)\sin(\pi y)\sin(\pi z), \]

then compares laplace(field) with the exact form

\[ \nabla^2 u = -3\pi^2 \sin(\pi x)\sin(\pi y)\sin(\pi z). \]

The relevant operator call is deliberately simple:

Lap = laplace(field);

// Error computation
Lap = Lap - Lap_exact;
Lap = pow(Lap, 2);
double error = sqrt(Lap.sum()) / sqrt(Lap_exact.sum());

To run the test, we pass the number of grid-points (indicating the mesh spacing), and the number of times we want to repeat the operation:

srun ./TestLaplace <points-per-dimension> <iterations>