#!/usr/bin/env python # coding: utf-8 # # Schwarzschild spacetime: basic computations # # This notebook shows how to use SageMath to compute the Christoffel symbols of the Schwarzschild metric with respect to standard coordinates, as well as the Riemann curvature tensor and the Kretschmann scalar. The corresponding tools have been developed within the [SageManifolds](https://sagemanifolds.obspm.fr) project. # # A more advanced notebook about Schwarzschild spacetime, involving many coordinate charts, more tensor calculus and graphical outputs, is available [here](http://nbviewer.jupyter.org/github/sagemanifolds/SageManifolds/blob/master/Worksheets/v1.3/SM_Schwarzschild.ipynb). # # Click [here](https://raw.githubusercontent.com/sagemanifolds/SageManifolds/master/Notebooks/SM_basic_Schwarzschild.ipynb) to download the notebook file (ipynb format). # *NB:* a version of SageMath at least equal to 8.2 is required to run this notebook: # In[1]: version() # First we set up the notebook to display mathematical objects via LaTeX rendering: # In[2]: get_ipython().run_line_magic('display', 'latex') # ## Spacetime manifold # # We declare the spacetime manifold as a 4-dimensional Lorentzian manifold: # In[3]: M = Manifold(4, 'M', structure='Lorentzian') print(M) # ## Standard coordinates # # The standard **Schwarzschild-Droste coordinates** are introduced via the method `chart()` applied to the manifold object `M`. Note that the argument of `chart()` is a raw string (hence the prefix `r` in front of it), which # defines the range of each coordinate, if different from $(-\infty, +\infty)$, as well as its LaTeX symbol, if different from the Python symbol to denote the coordinate. The Python variables for each coordinate are declared within the `<...>` operator on the left-hand side, `X` denoting the Python variable chosen for the coordinate chart. # In[4]: X. = M.chart(r"t r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi") X # In[5]: X[:] # In[6]: X[0], X[3] # ## Metric tensor # # We introduce first the mass parameter $m$ as a symbolic variable, via the function `var()`: # In[7]: m = var('m') assume(m>=0) # The metric tensor of the Lorentzian manifold `M` is returned by the method `metric()`; we initialize its components in the chart `X`, which is the default chart on `M` (the only one defined up to now): # In[8]: g = M.metric() g[0,0] = -(1-2*m/r) g[1,1] = 1/(1-2*m/r) g[2,2] = r^2 g[3,3] = (r*sin(th))^2 g.display() # Viewing the metric components as a matrix: # In[9]: g[:] # Accessing to a specific component: # In[10]: g[0,0] # ## Christoffel symbols # # The Christoffel symbols of $g$ with respect to the Schwarzschild-Droste coordinates are # printed by the method `christoffel_symbols_display()` applied to the metric object `g`. By # default, only the nonzero symbols and the nonredundant ones (taking into account the symmetry of the last two indices) are displayed. Type `g.christoffel_symbols_display?` to see all possible options. # In[11]: g.christoffel_symbols_display() # Accessing to a Christoffel symbol specified by its indices: # In[12]: g.christoffel_symbols()[0,0,1] # Checking the symmetry on the last two indices: # In[13]: g.christoffel_symbols()[0,0,1] == g.christoffel_symbols()[0,1,0] # ## Einstein equation # # Let us check that $g$ is a solution of the vacuum Einstein equation, i.e. that its **Ricci tensor** vanishes identically: # In[14]: g.ricci() # In[15]: g.ricci().display() # In[16]: g.ricci()[:] # ## Curvature tensor # # The **Riemann curvature tensor** is obtained by the method `riemann()`: # In[17]: R = g.riemann() print(R) # Contrary to the Ricci tensor, it is not identically zero: # In[18]: R.display() # The component $R^0_{\ \,101} = R^t_{\ \,rtr}$ of the Riemann tensor: # In[19]: R[0,1,0,1] # All the nonvanishing components of the Riemann tensor, skipping the redundant ones # (i.e. those that can be deduced by antisymmetry of the last two indices): # In[20]: R.display_comp(only_nonredundant=True) # ## Kretschmann scalar # # The Kretschmann scalar is the "square" of the Riemann tensor defined by # $$ K = R_{abcd} R^{abcd}$$ # To compute it, we must first form the tensor fields whose components are $R_{abcd}$ and # $R^{abcd}$. They are obtained by respectively lowering and raising the indices of the components $R^a_{\ \, bcd}$ of the Riemann tensor, via the metric $g$. These two operations are performed by the methods `down()` and `up()`. The contraction is performed by summation on repeated indices, using LaTeX notations: # In[21]: K = R.down(g)['_{abcd}'] * R.up(g)['^{abcd}'] K # In[22]: K.display() # The symbolic expression representing the scalar field $K$ is returned by the method `expr()`: # In[23]: K.expr()