summaryrefslogtreecommitdiff
path: root/horizon.py
blob: f1b5123898a2d2b13041718d44aa475a6de35209 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-

from . import curvature
from . import diff
from . import utils

import numpy as np

def calc_expansion(x, z, metric, curv, surf, direction = 1):
    """
    Calculate expansion of null geodesics on a sequence of surfaces [1]. The
    surfaces are specified as level surfaces of F(r, θ) = r - h(θ).

    [1] Alcubierre (2008): Introduction to 3+1 Numerical Relativity, chapter
        6.7, specifically equation (6.7.13).

    :param array_like x: 1D array of x coordinates.
    :param array_like z: 1D array of z-coordinates.
    :param array_like metric: 4D array of spatial metric values at the grid
                              formed by x and z. metric[i, j, k, l] is the ijth
                              component of the metric at the point (X=x[l],
                              Z=z[k]).
    :param array_like curv: values of the extrinsic curvature, otherwise same as
                            metric.
    :param callable surf: A callable that specifies the surfaces. Accepts an
                          array of θ and returns the array of correponding h.
    :param int direction: Values of 1/-1 specify that the expansion of outgoing
                          or ingoing geodesics is to be computed.
    :rtype: array_like, shape (z.shape[0], x.shape[0])
    :return: Expansion values at the grid formed from x and z.
    """
    dX = [x[1] - x[0], 0, z[1] - z[0]]

    X, Z  = np.meshgrid(x, z)
    R     = np.sqrt(X ** 2 + Z ** 2)
    Theta = np.where(R > 1e-8, np.arccos(Z / R), 0.0)

    metric_u = utils.matrix_invert(metric)

    Gamma = curvature.calc_christoffel(x, z, metric)

    trK = np.einsum('ij...,ij...', metric_u, curv)

    F = R[:]
    for i in range(Theta.shape[0]):
        F[i] -= surf.eval(Theta[i])

    dF = np.empty((3,) + F.shape)
    dF[0] = diff.fd4(F, 1, dX[0])
    dF[1] = 0.0
    dF[2] = diff.fd4(F, 0, dX[2])

    s_l  = direction * dF[:]
    s_u  = np.einsum('ij...,j...->i...', metric_u, s_l)
    s_u /= np.sqrt(np.einsum('ij...,i...,j...', metric, s_u, s_u))

    ds_u = np.zeros((3,) + s_u.shape)
    for i in range(3):
        for j in range(3):
            if i == 1 or j == 1:
                continue
            diff_dir = 1 if (i == 0) else 0
            ds_u[i, j] = diff.fd4(s_u[j], diff_dir, dX[i])
    ds_u[1, 1] = np.where(np.abs(X) > 1e-8, s_u[0] / X, ds_u[0, 0])

    Div_s_u = np.einsum('ii...', ds_u) + np.einsum('iki...,k...', Gamma, s_u)

    H = Div_s_u - trK + np.einsum('ij...,i...,j...', curv, s_u, s_u)

    return H