As a small tutorial on generalrepytivity1, this blogpost explains how to create a metric tensor in generalrepytivity and, with it, how to get all the usual geometric invariants one is interested in (such as the Riemann tensor, the Ricci tensor and the scalar curvature). You can find all the code in this article in this jupyter notebook.
generalrepytivity is now on pypi, so installing it is easy using pip
:
pip install generalrepytivity
We heavily recommend importing it along with sympy (the symbolic computation library of python):
import generalrepytivity as gr
import sympy
Tensors come with a fancy LaTeX printing function, so if you're working on a jupyter notebook I recommend setting the printing function of sympy to use latex:
sympy.init_printing(use_latex=True)
To create a Tensor object, one must specify three things:
(p,q)
.For example, say you want to create the following tensor in with coordinates :
in this case, we would need the sympy symbols t, x, y, z
for the coordinates,
the _type would be (2,2) (because is a (2,2)-tensor) and for the values
note that the components of in these coordinates are the following:
so the dictionary of values should look like this:
values = {
((0, 1), (1, 3)): x**2 + y**2,
((1, 2), (0, 0)): sympy.sin(t)
}
In summary:
t, x, y, z = sympy.symbols('t x y z')
values = {
((0,1), (1, 3)): x**2 + y**2,
((1,2), (0, 0)): sympy.sin(t)
}
Gamma = gr.Tensor([t, x, y, z], (2,2), values)
and you can access the components of the tensor by indexing:
Gamma[(0,1), (1,3)] == x**2 + y**2
True
A metric is just a (0,2)-tensor, so we could create it using a values dict
just like we did above but, because (0,2)-tensors are so important (and because
they can be represented by matrices), generalrepytivity has a simpler way of
creating them. The function to use is gr.get_tensor_from_matrix
, which has the
following syntax:
gr.get_tensor_from_matrix(matrix, coordinates)
where matrix
is a square sympy matrix and the coordinates
are just like above
(i.e. a list of sympy symbols).
In this blogpost we will deal with three different solutions to Einstein's equations: Gödel's metric, Schwarzschild's metric and FRLW.
In 1949, Gödel proposed a solution to Einstein's Field Equations which described a rotating universe in which closed world-lines are possible (that is, you could in some way influence the past). Because of this violation of causality, Gödel's metric is just interesting from a theoretical perspective, not from a modeling one.
Gödel's metric is
To enter it into generalrepytivity, we could use the matrix representation:
x0, x1, x2, x3 = sympy.symbols('x_0 x_1 x_2 x_3')
a = sympy.Symbol('a')
A = a**2 * sympy.Matrix([
[1, 0, sympy.exp(x1), 0],
[0, -1, 0, 0],
[sympy.exp(x1), 0, sympy.exp(2*x1)/2, 0],
[0,0,0,-1]])
g_godel = gr.get_tensor_from_matrix(A, [x0, x1, x2, x3])
Schwarzschild metric is generally used when it comes to modeling spherical objects and their influence in the geometry of spacetime. It comes after assuming a static and spherically symmetrical spacetime.
Schwarzschild metric is (in units such that and )
where is the mass of the spherical object. To review the canon way of creating tensors, lets use a values dictionary:
t, r, theta, phi = sympy.symbols('t r \\theta \\phi')
m = sympy.Symbol('m')
values = {
((), (0,0)): -(1-2*m/r),
((), (1,1)): 1/(1-2*m/r),
((), (2,2)): r**2,
((), (3,3)): r**2*sympy.sin(theta)**2
}
g_sch = gr.Tensor([t, r, theta, phi], (0, 2), values)
The FRLW metric (which stands for Friedmann-Lemaître-Robertson-Walker) models a homogenous, isotropic and either expanding or contracting (depending on a constant) universe.
Its tensor representation in coordinates is
where with and . Using matrices:
x0, x1, x2, x3 = sympy.symbols('x_0 x_1 x_2 x_3')
epsilon, q = sympy.symbols('\\epsilon q')
A = epsilon * (x0 ** q)
g_matrix = sympy.diag(-1, A**2, A**2, A**2)
g_FRLW = gr.get_tensor_from_matrix(g_matrix, [x0, x1, x2, x3])
A good way of making a summary of the usual geometric invariants one computes using
a metric is by using the Spacetime
object in generalrepytivity. It takes just
one argument: the metric.
Godel_spacetime = gr.Spacetime(g_godel)
Sch_spacetime = gr.Spacetime(g_sch)
FRLW_spacetime = gr.Spacetime(g_FRLW)
Each object now holds:
christoffel_symbols
.Riem
.Ric
.R
.For example, Schwarzschild's metric was created in order to be Ricci flat (i.e. ). Let's verify this:
Sch_spacetime.Ric == 0
True
Lastly, the Spacetime
object comes with a print-to-file function which accepts
two format options: tex or txt. Running the command
Godel_spacetime.print_summary('godel.tex', _format='tex')
generates a .tex file with a summary of all the values of the christoffel_symbols
,
Riem
, Ric
and R
.