diff options
author | Anton Khirnov <anton@khirnov.net> | 2018-03-31 13:48:26 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2018-03-31 13:48:26 +0200 |
commit | 870b37944c3513cdf10bd26f7e6dcc3fabf6557d (patch) | |
tree | 3597a4abbe692808eb907b5f55806d0b83876ddf /curvature.py | |
parent | 9d57a574520de022024ea978e2f6b089b7e7331d (diff) |
horizon: split off the Christoffel symbol calculation
Diffstat (limited to 'curvature.py')
-rw-r--r-- | curvature.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/curvature.py b/curvature.py new file mode 100644 index 0000000..e9d8e17 --- /dev/null +++ b/curvature.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- + +import numpy as np + +from . import diff +from . import utils + +def calc_christoffel(x, z, metric): + """ + Calculate Christoffel symbols + + i 1 il / \ + Γ = -γ | ∂ γ + ∂ γ - ∂ γ | + jk 2 \ j kl k jl l jk / + + using finite differences. + + :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]). + :rtype: array_like, shape (3, 3, 3, z.shape[0], x.shape[0]) + :return: Christoffel symbols, first axis is the upper index, following two + axes are the two lower indices, final two axes correspond to the z + and x grid points respectively. + """ + X, Z = np.meshgrid(x, z) + + dmetric = np.zeros((3,) + metric.shape) + dmetric[0] = diff.fd4(metric, 3, x[1] - x[0]) + dmetric[2] = diff.fd4(metric, 2, z[1] - z[0]) + + 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] + + metric_u = utils.matrix_invert(metric) + + 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]) + + return Gamma |