12d8453Intro to surfacefun: interactive numbl example projectJeremy Magland 1% ex_hodge.m — Hodge decomposition of a tangential vector field.
2%
3% Any tangential vector field f on a surface splits into curl-free,
4% divergence-free, and harmonic parts:
5%
6% f = grad(u) + n x grad(v) + w.
7%
8% hodge() computes this by solving two Laplace-Beltrami problems. We use a
9% modest torus here so the demo stays quick (the docs use a finer mesh).
11mip load --install flatironinstitute/flatironinstitute/surfacefun
13p = 8;
14nu = 8;
15nv = 16;
16dom = surfacemesh.torus(p + 1, nu, nv);
18% A smooth random tangential vector field.
19rng(0)
20bb = boundingbox(dom);
21gx = randnfun3(10, bb);
22gy = randnfun3(10, bb);
23gz = randnfun3(10, bb);
24g = cross([0 1 1], surfacefunv(@(x, y, z) gx(x, y, z), ...
25 @(x, y, z) gy(x, y, z), ...
26 @(x, y, z) gz(x, y, z), dom));
27vn = normal(dom);
28f = -cross(vn, vn, g); % project g onto the tangent plane
30% Compute the decomposition.
31[u, v, w] = hodge(f);
33figure(1);
34quiver(f, 0.3, 4)
35title('Tangential field f');
37figure(2);
38quiver(grad(u), 0.3, 4)
39title('Curl-free part grad(u)');
41figure(3);
42quiver(cross(vn, grad(v)), 0.3, 4)
43title('Divergence-free part n x grad(v)');
45figure(4);
46quiver(w, 0.3, 4)
47title('Harmonic part w');
49% The harmonic remainder should be nearly divergence-free.
50fprintf('|| div(w) || = %.3e\n', norm(div(w)));