This program is the code in Curvature and the Einstein Equation translated from Mathematica to Python. As such, most texts in the original file has been copied into the README file. Those who are interested can download the original Mathematica file from here.
This is a Python program that translates the Mathematica notebook Curvature and the Einstein Equation to a Python program. As of now, the plan is, from a given metric
- The inverse metric,
$g^{\alpha \beta}$ - The Christoffel symbols,
$\Gamma^{\lambda}_{\mu \nu}$ - The Riemann tensor,
$R^{\lambda}_{\mu \nu \sigma}$ - The Ricci tensor,
$R_{\mu \nu}$ - The scalar curvature,
$R$ - The Einstein tensor,
$G_{\mu \nu}$
You must input the covariant components of the metric tensor providing the relevant input. You may also wish to change the names of the coordinates. All the components computed are in the coordinate basis in which the metric was specified.
As an example, let's consider the Schwarzschild metric. We first setup the coordinate system by specifying the name. This is done using the sympy
module.
import sympy as sym
t, r, theta, phi, m = sym.symbols('t r theta phi m')
coord = [t, r, theta, phi]
You can change the names of the coordinates by choosing different inputs for coord
, for example, to [t, x, y, z]
. when another set of coordinate names is more appropriate. In this program indices range over 0 to
Input the metric as a list of lists, i.e., as a matrix. You can input the components of any metric here, but you must specify them as explicit functions of the coordinates.
metric = [[-1 + 2*m/r, 0, 0, 0], [0, (1 - 2*m/r)**(-1), 0, 0], [0, 0, r**2, 0], [0, 0, 0, r**2 * sym.sin(theta)**2]]
Once the metric and coordinates are defined, we are ready to use the GR solver. Using the solver is as simple as
test = GR(coord, metric)
and we are ready to go.
The contravariant version of the metric
print(np.array(test.inversemetric))
The Christoffel symbols are defined as
$$\Gamma^{\lambda}{\mu \nu} = \frac{1}{2} g^{\lambda \sigma} (\partial\mu g_{\sigma \nu} + \partial_\nu g_{\sigma \mu} - \partial_\sigma g_{\mu \nu}) ;.$$
To calculate the Christoffel symbols, one needs only to call
print(np.array(test.Christ()))
If one is interested in only the non-zero Christoffel symbols, then one can call
test.Christ(True)
In the output the symbol Gamma[1,2,3]
stands for
The components of the Riemann tensor,
$$R^{\lambda}{\mu \nu \sigma} = \partial\nu \Gamma^{\lambda}{\mu \sigma} - \partial\sigma \Gamma^{\lambda}{\mu \nu} + \Gamma^{\eta}{\mu \sigma} \Gamma^{\lambda}{\eta \nu} - \Gamma^{\eta}{\mu \nu} \Gamma^{\lambda}_{\eta \sigma} ;.$$
To calculate the Riemann tensor, one needs only to call
test.Riem()
If one is interested in only the non-zero components of the Riemann tensor, then one can call
test.Riem(True)
In the output, the symbol R[1,2,1,3]
stands for $R^{1}{213}$, and similarly for the other components. You can obtain R[1,2,3,1]
from R[1,2,1,3]
using the antisymmetry of the Riemann tensor under exchange of the last two indices. The antisymmetry under exchange of the first two indices of $R{\lambda \mu \nu \sigma}$ is not evident in the output because the components of
The Ricci tensor
$$R_{\mu \nu} = R^{\lambda}_{\mu \lambda \nu}$$
This can be calculated by calling
test.Ric()
To display the non-zero components of the Ricci tensor, use
test.Ric(True)
Since Ricci tensor is symmetric, only the independent components are displayed. A vanishing table (as with the Schwarzschild metric example) means that the vacuum Einstein equation is satisfied.s
The Ricci scalar
$$R = g^{\mu \nu} R_{\mu \nu} ;.$$
This can be calculated by calling
print(test.RicSca())
The Einstein tensor is
$$ G_{\mu \nu} = R_{\mu \nu} - \frac{1}{2} g_{\mu \nu} R ;,
which is the left hand side of the Einstein field equation
$$G_{\mu \nu} = 8 \pi T_{\mu \nu}$$
This can be calculated by calling
test.Eins()
To display only non-zero components of the Einstein tensor, one can call
test.Eins(True)
to print the non-zero components of the Einstein tensor. A vanishing table meanst that the vacuum Einstein equatoin is satisfied.