Hodge Laplacian in Spherical Coordinates¶
In $(r,\theta,\phi)$ coordinates, the Euclidean metric is
$$ds^2=dr^2+r^2d\theta^2+r^2\sin^2\theta\,d\phi^2.$$
We build $d$, $\star$, and the codifferential from this metric. With the codifferential convention used below, the scalar result is the negative of the usual positive-coordinate Laplace operator.
Spherical metric¶
The determinant is $r^4\sin^2\theta$, while the inverse metric contains the angular scale factors $r^{-2}$ and $(r^2\sin^2\theta)^{-1}$.
declare symbol r, θ, φ : MathValue
def N : Integer := 3
def x : Vector MathValue := [| r, θ, φ |]
def g_i_j : Matrix MathValue :=
[| [| 1, 0, 0 |]
, [| 0, r ^ 2, 0 |]
, [| 0, 0, r ^ 2 * (sin θ) ^ 2 |] |]_i_j
def g~i~j : Matrix MathValue :=
[| [| 1, 0, 0 |]
, [| 0, 1 / r ^ 2, 0 |]
, [| 0, 0, 1 / (r ^ 2 * (sin θ) ^ 2) |] |]~i~j
g_#_#
Differential-form operators¶
The Hodge star raises the form indices with $g^{ij}$ and contracts them against the three-dimensional Levi-Civita tensor.
def d (A : Tensor MathValue) : Tensor MathValue :=
!(flip ∂/∂) x A
def hodge (A : DiffForm MathValue) : DiffForm MathValue :=
let k := dfOrder A
in withSymbols [i, j]
sqrt (abs (M.det g_#_#)) *
foldl
(.)
((ε' N k)_(i_1)..._(i_N) . A..._(j_1)..._(j_k))
(map (\n -> g~(i_n)~(j_n)) [1..k])
def δ (A : DiffForm MathValue) : DiffForm MathValue :=
let k := dfOrder A
in ((-1) ^ (N * (k + 1) + 1)) * hodge (d (hodge A))
The Hodge Laplacian is $d\delta+\delta d$, with shorter endpoint formulas for scalars and volume forms.
def Δ (A : DiffForm MathValue) : DiffForm MathValue :=
match dfOrder A as integer with
| #0 -> δ (d A)
| #N -> d (δ A)
| _ -> d (δ A) + δ (d A)
def f : MathValue := function (r, θ, φ)
Δ f
After simplification, the output is
$$ \Delta f=-\left( f_{rr}+\frac{2}{r}f_r +\frac1{r^2}f_{\theta\theta} +\frac{\cos\theta}{r^2\sin\theta}f_\theta +\frac1{r^2\sin^2\theta}f_{\phi\phi} \right). $$
Each coordinate-dependent coefficient follows from the metric; the calculation contains no spherical-coordinate Laplacian formula as an input.