summaryrefslogtreecommitdiff
path: root/horizon.py
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2018-03-27 11:56:43 +0200
committerAnton Khirnov <anton@khirnov.net>2018-03-27 11:56:43 +0200
commit9d57a574520de022024ea978e2f6b089b7e7331d (patch)
treedea7423bfd77a2d14068c4d275334573dc3d3669 /horizon.py
parent8851f6e78392ee0273c1530e799b0a2e89aea780 (diff)
Add a function for computing expansion.
Diffstat (limited to 'horizon.py')
-rw-r--r--horizon.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/horizon.py b/horizon.py
new file mode 100644
index 0000000..3f74242
--- /dev/null
+++ b/horizon.py
@@ -0,0 +1,85 @@
+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)
+
+ dmetric = np.zeros((3,) + metric.shape)
+ dmetric[0] = diff.fd4(metric, 3, dX[0])
+ dmetric[2] = diff.fd4(metric, 2, dX[2])
+
+ dmetric[1, 0, 0] = 0.0
+ dmetric[1, 1, 1] = 0.0
+ dmetric[1, 2, 2] = 0.0
+ dmetric[1, 0, 1] = np.where(np.abs(X) > 1e-8, (metric[0, 0] - metric[1, 1]) / X, dmetric[0, 0, 0] - dmetric[0, 1, 1])
+ dmetric[1, 1, 0] = dmetric[1, 0, 1]
+ dmetric[1, 0, 2] = 0.0
+ dmetric[1, 2, 0] = 0.0
+ dmetric[1, 1, 2] = np.where(np.abs(X) > 1e-8, metric[0, 2] / X, dmetric[0, 0, 2])
+ dmetric[1, 2, 1] = dmetric[1, 1, 2]
+
+ Gamma = np.empty_like(dmetric)
+ for i in range(3):
+ for j in range(3):
+ for k in range(3):
+ Gamma[i, j, k] = 0.5 * np.einsum('k...,k...', metric_u[i], dmetric[j, k] + dmetric[k, j] - dmetric[:, k, j])
+
+ 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