General Theory of Relativity in Python: Introduction

In this article, using Python, what is needed in general relativity ・ ** Calculation of various tensors including weighing $ g_ {\ mu \ nu} $ ** ・ ** Simple calculation of Einstein equation ** Introduce how to do.

** [Reference] ** For computing related to tensor analysis and algebra in general relativity,  Heinicke, C., et.al.- Computer Algebra in Gravity  Korolkova, A., et.al.- Tensor computations in computer algebra systems There are some affordable Review papers such as, so please refer to them as appropriate. Also, for a similar study using SageMath,  Gourgoulhon, E., et.al. - Symbolic tensor calculus on manifolds Etc. are known.

Introducing the GraviPy module

GraviPy is a module for tensor calculation that runs on Python3.

By collaborating with SymPy, which specializes in algebraic symbol processing, a stress-free tensor calculation environment is realized on Python.

Download the GraviPy module including SymPy according to the following GraviPy, Tensor Calculus Package for General Relativity (Version 0.1.0) (2014) (Access date: November 26, 2019)

You can actually use pip,

python


$ pip install GraviPy

If there is no problem, it will be installed. SymPy should be installed at the same time if the Python environment is ver.3.7 or higher.

I calculated the Schwarzschild metric

Use GraviPy to derive the Schwarzschild solution from the Schwarzschild metric.

Introduction of Schwarzschild weighing

The sign of the metric is $ (+,-,-,-) $ according to MTW, and the line element is determined as follows. $ds^2=g_{\mu\nu}dx^\mu dx^\nu .$ For the gravitational constant and the speed of light, if $ G = c = 1 $, the Schwarzschild metric is written as follows.

g_{\mu\nu}=\left[\begin{array}{cccc}
\Big( 1- \frac{2M}{r} \Big) & 0 & 0 & 0	\\
0 & -\Big( 1- \frac{2M}{r} \Big)^{-1} & 0 & 0	\\
0 & 0 & -r^2 & 0	\\
0 & 0 & 0 & -r^2sin^2\theta
\end{array}\right]. 

Here, the four-dimensional coordinate $ (t, r, \ theta, \ phi) $ is taken as the coordinate system, and $ M $ is defined as the black hole mass. The Schwarzschild metric shows a singularity at $ r = 2M $ in the radial direction, which is known as the so-called "event horizon".

How to derive using GraviPy

Let's derive the Schwarzschild solution from the above $ g_ {\ mu \ nu} $. Use GraviPy to calculate according to the following process.

  1. Definition of space-time (determination of metric): $ g_ {\ mu \ nu} $
  2. Calculation of Christoffel symbol: $ \ Gamma {} ^ \ mu {} _ {\ nu \ rho} $
  3. Ricci curvature calculation: $ R_ {\ mu \ nu} $
  4. Einstein tensor calculation: $ G_ {\ mu \ nu} $

Definition of space-time

First, let's define space-time. Take $ x = x ^ \ mu = (t, r, \ theta, \ phi) $ as the four-dimensional space-time coordinates. In GraviPy, it is defined as follows.

GR.py


#!/usr/bin/env python3
from gravipy import *
from gravipy import tensorial as ten  
from sympy   import *
import inspect 

# Coordinates (\ chi is the four - vector of coordinates )
t, r, theta, phi, M = symbols('t , r , theta , phi , M ')
x = ten.Coordinates('\chi',[t, r, theta, phi])

Here, the first argument '\ chi' often.Coordinates ()specifies that the second argument is a four-vector. Also, the reason why it is set to ten. ~ Is that this Coordinates () does not work unless it explicitly refers to the tensorial.

After that, the tensors that appear will be referred to by ten. ~.

Definition of Schwarzschild metric

Next, let's define the metric $ g_ {\ mu \ nu} $. The Schwarzschild metric described above may be described as follows.

GR.py


#Continued
# Metric tensor
Metric = diag((1 -2* M / r ) , -1/(1 -2* M / r ) , -r **2 , -r **2* sin( theta ) **2)
g = ten.MetricTensor('g', x , Metric )

Here, the output result of g = ten.MetricTensor ('g', x, Metric) is

Metric
#Or
g(ten.All,ten.All)

It can be displayed with, and it becomes as follows.

g_{\mu\nu}=
\displaystyle \left[\begin{matrix}- 2M/r + 1 & 0 & 0 & 0\\0 & \displaystyle- \frac{1}{- 2M/r + 1} & 0 & 0\\0 & 0 & - r^{2} & 0\\0 & 0 & 0 & - r^{2} \sin^{2}{\left(\theta \right)}\end{matrix}\right] 

Although there are some differences in the expression, the previous definition is accurately reflected. For example, when referring to the radial component $ g_ {rr} = g_ {11} $

g(1,1)

Then, it can be obtained for each element as follows.

g_{11}=- \frac{1}{\displaystyle- \frac{2M}{r} + 1} 

Christoffel's calculation

Next, let's calculate the Christoffel symbol $ \ Gamma ^ \ mu {} _ {\ nu \ rho} $ based on $ g_ {\ mu \ nu} $.

GR.py


#Continued
# Christoffel symbol
Ga = ten.Christoffel('Ga', g )

Ga is the Christoffel symbol for $ g_ {\ mu \ nu} $. Christoffel is a tensor on the 3rd floor, so if you limit it to $ \ mu = 0 $, you will get the following tensor on the 2nd floor.

\Gamma^{ 0}{}_{\nu\rho}=
\left[
\begin{matrix}
0 & \frac{M}{r^{2}} & 0 & 0 \\
\frac{M}{r^{2}} & 0 & 0 & 0 \\
0 & 0 & 0 & 0\\
0 & 0 & 0 & 0
\end{matrix}\right]

To get all the ingredients

Ga(ten.All,ten.All,ten.All)

You can do it as

\displaystyle
\Gamma^\mu{}_{\nu\rho}=
 \left[\begin{matrix}\left[\begin{matrix}0 & \frac{M}{r^{2}} & 0 & 0\\\frac{M}{r^{2}} & 0 & 0 & 0\\0 & 0 & 0 & 0\\0 & 0 & 0 & 0\end{matrix}\right] & \left[\begin{matrix}- \frac{M}{r^{2}} & 0 & 0 & 0\\0 & \frac{M}{\left(2 M - r\right)^{2}} & 0 & 0\\0 & 0 & r & 0\\0 & 0 & 0 & r \sin^{2}{\left(\theta \right)}\end{matrix}\right] & \left[\begin{matrix}0 & 0 & 0 & 0\\0 & 0 & - r & 0\\0 & - r & 0 & 0\\0 & 0 & 0 & \frac{r^{2} \sin{\left(2 \theta \right)}}{2}\end{matrix}\right] & \left[\begin{matrix}0 & 0 & 0 & 0\\0 & 0 & 0 & - r \sin^{2}{\left(\theta \right)}\\0 & 0 & 0 & - \frac{r^{2} \sin{\left(2 \theta \right)}}{2}\\0 & - r \sin^{2}{\left(\theta \right)} & - \frac{r^{2} \sin{\left(2 \theta \right)}}{2} & 0\end{matrix}\right]\end{matrix}\right]

Will be. Since it is a third-order tensor, it can be formally obtained as a "one-dimensional array of two-dimensional array" (= a form in which the elements of the one-dimensional array are two-dimensional arrays).

Ricci curvature calculation

Next, calculate the Ricci curvature. (This name comes from the mathematician Ricci.)

# Ricci tensor
Ri = ten.Ricci ('Ri ', g )
# Display all compon
Ri(ten.All,ten.All)

The Ricci tensor in the Schwarzschild metric drops all components to zero.

R_{\mu\nu}=
\displaystyle \left[\begin{matrix}0 & 0 & 0 & 0\\0 & 0 & 0 & 0\\0 & 0 & 0 & 0\\0 & 0 & 0 & 0\end{matrix}\right]

Of course, this is a special thing, in the Schwarzschild metric formula. $r \longrightarrow r^{3.5}$ If you try to calculate the Ricci curvature by substituting with, etc., the values will be completely different, so you should experiment.

Einstein tensor calculation

Finally, let's output the Einstein tensor using the Ricci tensor.

# Einstein tensor
G = ten.Einstein ('G', Ri )
G(ten.All,ten.All)

Result is,

G_{\mu\nu}=
\displaystyle \left[\begin{matrix}0 & 0 & 0 & 0\\0 & 0 & 0 & 0\\0 & 0 & 0 & 0\\0 & 0 & 0 & 0\end{matrix}\right]

It has become. This result is the assumption of the Schwarzschild solution, ** vacuum condition ** $T_{\mu\nu}=0$ Also conforms to the Einstein equation $G_{\mu\nu}=8\pi T_{\mu\nu}$ Meet.

References

The GraviPy tutorial has been released, and I referred to the following.

https://github.com/wojciechczaja/GraviPy

Also, the SymPy support page is below.

[https://docs.sympy.org/dev/index.html] (https://docs.sympy.org/dev/index.html)

Recommended Posts

General Theory of Relativity in Python: Introduction
Introduction of Python
Introduction of Python
Operate mongoDB from python in ubuntu environment ① Introduction of mongoDB
Equivalence of objects in Python
Introduction of activities applying Python
Design Patterns in Python: Introduction
Exercises-Probability Theory (Econometrics in Python)
Implementation of quicksort in Python
Explanation of NoReverseMatch error in "python django super introduction"
Pixel manipulation of images in Python
Division of timedelta in Python 2.7 series
MySQL-automatic escape of parameters in python
Handling of JSON files in Python
Implementation of life game in Python
Waveform display of audio in Python
General Gaussian state-space model in Python
Introduction of python drawing package pygal
Law of large numbers in python
Implementation of original sorting in Python
Reversible scrambling of integers in Python
[Introduction] Insert line breaks in Python 3
Record of Python introduction for newcomers
[Python] PCA scratch in the example of "Introduction to multivariate analysis"
Conversion of string <-> date (date, datetime) in Python
[Introduction to Python] How to use class in Python?
Check the behavior of destructor in Python
(Bad) practice of using this in Python
Output tree structure of files in Python
Display a list of alphabets in Python 3
Comparison of Japanese conversion module in Python3
Summary of various for statements in Python
Easy introduction of speech recognition with Python
The result of installing python in Anaconda
Gang of Four (GoF) Patterns in Python
The basics of running NoxPlayer in Python
Bulk replacement of strings in Python arrays
Project Euler # 16 "Sum of Powers" in Python
Traffic Safety-kun: Recognition of traffic signs in Python
Summary of built-in methods in Python list
Non-logical operator usage of or in python
In search of the fastest FizzBuzz in Python
Easy introduction of python3 series and OpenCV3
Practical example of Hexagonal Architecture in Python
Project Euler # 17 "Number of Characters" in Python
Double pendulum equation of motion in python
Introduction to Vectors: Linear Algebra in Python <1>
Get rid of DICOM images in Python
Introduction to Effectiveness Verification Chapter 1 in Python
Status of each Python processing system in 2020
Project Euler # 1 "Multiples of 3 and 5" in Python
[Introduction to Data Scientists] Basics of Python ♬
Meaning of using DI framework in Python
[Introduction to Python] Thorough explanation of the character string type used in Python!
Quadtree in Python --2
Python in optimization
CURL in python
Output the number of CPU cores in Python
Draw a graph of a quadratic function in Python
Geocoding in python
SendKeys in Python