{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Pseudo-Riemannian manifolds in SageMath\n", "## The Schwarzschild spacetime example" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook demonstrates some SageMath tools for pseudo-Riemannian geometry, developed through the [SageManifolds project](https://sagemanifolds.obspm.fr/), by these [authors](https://sagemanifolds.obspm.fr/authors.html). " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook requires a version of SageMath at least equal to 9.0:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sage.version.banner" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First we set up the notebook to display outputs via LaTeX rendering:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%display latex " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since some computations are quite heavy, we ask for running them in parallel on 8 \n", "threads:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Parallelism().set(nproc=8)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We introduce the **Schwarzschild spacetime**, which is the spacetime of a **static black hole** in general relativity, as a **4-dimensional Lorentzian manifold** $M$:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "M = Manifold(4, 'M', structure='Lorentzian')\n", "M" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(M)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$M$ is in the category of smooth manifolds over the real field:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "M.category()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "M.base_field()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "At the moment, the real field is modeled by 53-bit floating-point approximations, but this plays no role in the manifold implementation:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(M.base_field())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Coordinate charts" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The function `Manifold` generates a manifold with no-predefined coordinate chart; hence the manifold (user) atlas is empty:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "M.atlas()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We introduce the standard **Schwarzchild-Droste coordinates** $(t,r,\\theta,\\phi)$ on $M$, via the method `chart`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "SD. = M.chart(r\"t r:(0,+oo) th:(0,pi):\\theta ph:(0,2*pi):\\phi:periodic\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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, `SD` denoting the Python variable chosen for the coordinate chart." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "SD" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(SD)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "SD.coord_range()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Thanks to the SageMath operator `<...>` used in the chart declaration, the coordinates are immediately available as Python variables:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "th" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "They are SageMath's symbolic expressions (`SR` is SageMath's *Symbolic Ring*):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "th.parent()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The coordinates are also accessible as items of the chart:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "SD[0], SD[3]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "SD[:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The manifold (user) atlas is no longer empty: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "M.atlas()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us introduce a second chart on the manifold, namely that of **Eddington-Finkelstein coordinates** $(T,r,\\theta,\\phi)$:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "EF. = M.chart(r\"T r:(0,+oo) th:(0,pi):\\theta ph:(0,2*pi):\\phi:periodic\")\n", "EF" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The transition map from Schwarzschild-Droste coordinates (chart `SD`) to Eddington-Finkelstein ones (chart `EF`) depends on a parameter $m$ --- the black hole mass:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = var('m')\n", "assume(m > 0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We provide the explicit coordinate transformation via the method `transition_map`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "SD_to_EF = SD.transition_map(EF, [t +2*m*ln(abs(r/(2*m)-1)), r, th, ph])\n", "SD_to_EF.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and ask SageMath to compute the inverse transition map:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "SD_to_EF.inverse().display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are now two charts in the manifold atlas:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "M.atlas()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One of them is the so-called *default chart*: it is the chart used by any function that requires a chart as argument while none is provided by the user. At this stage, the default chart is the first chart defined on the manifold, but this can be changed by the manifold method `set_default_chart`. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "M.default_chart()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One can plot the `SD` chart in terms of `EF` one:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot1 = SD.plot(EF, ranges={t:(0, 8), r:(2.1, 10)}, fixed_coords={th:pi/2, ph:0}, \n", " ambient_coords=(r,T), style={t:'--', r:'-'}, parameters={m: 1}) \\\n", " + SD.plot(EF, ranges={t:(0, 8), r:(0.1, 1.9)}, fixed_coords={th:pi/2, ph:0}, \n", " ambient_coords=(r,T), number_values={t: 9, r: 3},\n", " style={t:'--', r:'-'}, parameters={m: 1})\n", "plot1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Manifold points" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To create a point on $M$, we use SageMath's *parent/element* syntax, i.e. the call operator `M(...)` acting on the parent `M`, with the point's coordinates in some chart as argument: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p = M((m, 8*m, pi/2, 0), name='p')\n", "print(p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since the chart has not been specified, the default chart (i.e. `SD`) is meant:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "SD(p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Thanks to the transition map declared above, the coordinates of $p$ in the Eddington-Finkelstein chart can computed:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "EF(p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Manifold points have a `plot` method:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot1 += p.plot(EF, color='blue', ambient_coords=(r,T), \n", " parameters={m: 1}, label_offset=0.4, fontsize=14)\n", "plot1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Vector fields" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When a chart is declared, the manifold is automatically endowed with some vector fields, namely those of the **coordinate vector frame**:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "SD.frame()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "EF.frame()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "M.frames()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As for charts, there is a *default frame*, i.e. a vector frame that is used by default in functions having a vector frame in their arguments. The default frame can be changed by the method `set_default_frame`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "M.default_frame()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The first vector of the Schwarzschild-Droste coordinate frame:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vt = SD.frame()[0]\n", "vt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vt.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vt.display(EF.frame())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The second vector of the Schwarzschild-Droste coordinate frame:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vr = SD.frame()[1]\n", "vr" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vr.display(EF.frame())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Creating a vector field from scratch, by providing its components with respect to a given vector frame:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "k = M.vector_field(1, -1, 0, 0, frame=EF.frame(), name='k')\n", "k.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "k.display(EF.frame())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot with respect to Schwarzschild-Droste coordinates (default chart):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "k.plot(ambient_coords=(r,t), fixed_coords={th: pi/2, ph: 0}, \n", " ranges={t: (0, 6), r: (0.1, 6)}, number_values=9,\n", " parameters={m: 1}, color='green', scale=0.3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot with respect to Eddington-Finkelstein coordinates:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "k.plot(chart=EF, ambient_coords=(r,T), chart_domain=EF,\n", " fixed_coords={th: pi/2, ph: 0}, ranges={T: (0, 8), r: (0.1, 10)}, \n", " number_values=5, parameters={m: 1}, color='green')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Vector fields as sections of the tangent bundle" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "TM = M.tangent_bundle()\n", "print(TM)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "k1 = TM.section({EF.frame(): [1, -1, 0, 0]})\n", "print(k1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "k1 == k" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### The set of all vector fields on $M$ as a $C^\\infty(M)$-module:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "XM = M.vector_field_module()\n", "print(XM)\n", "XM" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "XM.base_ring()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(XM.base_ring())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "XM.base_ring().an_element().display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Vectors at a point" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The value of a vector field, and more generally of any tensor field, at a given point is obtained by the method `at`: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "kp = k.at(p)\n", "print(kp)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "kp.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The parent of `kp` is the tangent space at `p`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "kp.parent()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(kp.parent())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is accessible from the manifold via the method `tangent_space`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "kp.parent() is M.tangent_space(p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$T_p M$ is the fiber over $p$ in the tangent bundle $TM$:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "kp.parent() is TM.fiber(p) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Tangent vectors have a method `plot`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot1 += kp.plot(EF, color='green', ambient_coords=(r,T), \n", " parameters={m: 1}, scale=2, label_offset=0.5, \n", " fontsize=16)\n", "plot1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Vector field defined on an open subset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us introduce the exterior $E$ of the black hole as an open subset of the spacetime manifold $M$:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "E = M.open_subset('E', coord_def = {SD: r>2*m})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "SD.restrict(E).coord_range()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p in E" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A vector field defined on $E$ only:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "u = E.vector_field(name='u')\n", "u[0] = 1/sqrt(1-2*m/r)\n", "u.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "SD_to_EF.restrict(E)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "E.atlas()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "u.display(EF.frame().restrict(E))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "u.plot(ambient_coords=(r, t), fixed_coords={th: pi/2, ph: 0}, \n", " ranges={t: (0, 6), r: (2.1, 6)}, number_values=5, \n", " parameters={m: 1}, scale=0.3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "u.at(p).display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Metric tensor\n", "\n", "We next define the **metric tensor** $g$ from its non-vanishing components in the manifold's default frame, namely the coordinate frame associated to Schwarzschild-Droste coordinates:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "g = M.metric()\n", "g[0, 0] = - (1 - 2*m/r)\n", "g[1, 1] = 1/(1 - 2*m/r)\n", "g[2, 2] = r^2\n", "g[3, 3] = r^2*sin(th)^2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "g.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "SD.coframe()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "g[:]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "g[1,1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$g_{rr}$ is diverging at $r=2m$: this is a singularity of the Schwarszchild-Droste coordinates." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "g.display_comp()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The components of $g$ with respect to the Eddington-Finkelstein frame are evaluated via the methods `comp` or `display`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "g.display(EF.frame())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "g[EF.frame(),:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that these components are regular at $r=2m$, contrary to the components with respect to Schwarzschild-Droste coordinates." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The metric tensor is a twice-covariant tensor (actually a field of symmetric bilinear forms):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "g.tensor_type()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It can be thus be applied to a pair of vector fields, for instance $u$ and $k$:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s = g(u, k)\n", "s" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(s)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s.expr()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$k$ is a null vector:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "g(k, k).display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "while $u$ is a unit timelike vector:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "g(u, u).display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Scalar products returned by the method `dot` are actually those formed with $g$:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "u.dot(u)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "u.dot(u).display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Levi-Civita connection" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nabla = g.connection()\n", "print(nabla)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nabla.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Dk = nabla(k)\n", "Dk" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(Dk)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Dk.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Dk.display_comp()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The acceleration $\\nabla_k k$ of the vector field $k$:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Ak = Dk.contract(k)\n", "print(Ak)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Ak.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Hence $k$ is a geodesic vector. The field lines of $k$ are actually the ingoing radial null geodesics of Schwarzschild spacetime." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Instead of the method contract, one can use index notations to compute $\\nabla_k k$ as $k^b \\nabla_b k^a$:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Ak == Dk['^a_b']*k['^b']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The acceleration $\\nabla_u u$ of the vector field $u$:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Au = nabla(u).contract(u)\n", "Au.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$\\nabla g$ is identically zero, since the connection $\\nabla$ is compatible with $g$:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Dg = nabla(g)\n", "print(Dg)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Dg.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Curvature" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The **Riemann curvature tensor** is computed as" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Riem = g.riemann()\n", "print(Riem)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Riem.display_comp(only_nonredundant=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The component $\\mathrm{Riem}(g)^t_{\\ \\, rtr} = \\mathrm{Riem}(g)^0_{\\ \\, 101}$ is returned by " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Riem[0,1,0,1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Riem.display_comp(EF.frame(), only_nonredundant=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The **Kretschmann scalar** is the \"square\" of the Riemann tensor defined by \n", "$$K = R_{abcd} \\, R^{abcd}, \\qquad R := \\mathrm{Riem}(g)$$\n", "To compute it, we must first form the tensor fields whose components are $R_{abcd}$ and \n", "$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:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "K = Riem.down(g)['_{abcd}'] * Riem.up(g)['^{abcd}']\n", "print(K)\n", "K.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "K.expr()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since $\\lim_{r\\to 0} K = +\\infty$, we may say that $r=0$ is a **curvature singularity** of Schwarzschild spacetime." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*NB:* **Since SageMath 10.10**, the Kretschmann scalar can be obtained directly by invoking the method `kretschmann_scalar` on the metric: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "g.kretschmann_scalar().expr()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Ricci tensor" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Ric = g.ricci()\n", "print(Ric)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We check that the Schwarzschild metric is a solution of the vacuum **Einstein equation**:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Ric.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Geodesics" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, for graphical purposes, we introduce the **Euclidean space** $\\mathbb{E}^3$ and some map $M\\to \\mathbb{E}^3$:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "E3. = EuclideanSpace()\n", "X3 = E3.cartesian_coordinates()\n", "to_E3 = M.diff_map(E3, {(SD, X3): \n", " [r*sin(th)*cos(ph), r*sin(th)*sin(ph), r*cos(th)]})\n", "to_E3.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A timelike geodesic" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us consider the geodesic starting at point $p$ and having the following tangent vector at $p$ (note that the tangent vector $v_0$ is constructed by means of the call operator `()` acting of the parent, which is the tangent space to $M$ at $p$): " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "v0 = M.tangent_space(p)((1.3, 0, 0, 0.064/m), name='v_0')\n", "v0.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We declare the geodesic with such initial conditions, denoting by $s$ the affine parameter (proper time), with $(s_{\\rm min}, s_{\\rm max})=(0, 2000\\,m)$:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s = var('s')\n", "geod = M.integrated_geodesic(g, (s, 0, 2000), v0)\n", "geod" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that the initial point `p` is not explicitely passed in the argument list of `integrated_geodesic`, because this piece of information is contained in `v0`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p is v0.parent().base_point()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sol = geod.solve(parameters_values={m: 1}) # numerical integration\n", "interp = geod.interpolate() # interpolation of the solution for the plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geod.plot_integrated(chart=X3, mapping=to_E3, plot_points=1000, \n", " thickness=2, label_axes=False) \\\n", "+ p.plot(chart=X3, mapping=to_E3, size=4, parameters={m: 1}) \\\n", "+ sphere(size=2, color='grey')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A 2D view by suppressing $z$ from the ambient coordinates:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bh_plot = circle((0, 0), 2, edgecolor='black', fill=True, facecolor='grey', alpha=0.5)\n", "geod.plot_integrated(chart=X3, mapping=to_E3, ambient_coords=(x,y), plot_points=1000, \n", " thickness=2) \\\n", "+ p.plot(chart=X3, mapping=to_E3, ambient_coords=(x,y), size=4, parameters={m: 1}) \\\n", "+ bh_plot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Null geodesics" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us consider a null geodesique $\\mathscr{L}$ in the equatorial plane ($\\theta = \\pi/2$). \n", "The null vector $v$ tangent to $\\mathscr{L}$ and associated to some affine parameter $\\lambda$ is given by the following first integrals of the geodesic equation:\n", "$$\n", " v^t = \\frac{\\mathrm{d}t}{\\mathrm{d}\\lambda} = \\left(1 - \\frac{2m}{r} \\right)^{-1}\n", "$$\n", "$$\n", " v^r = \\frac{\\mathrm{d}r}{\\mathrm{d}\\lambda} = \\pm \\sqrt{1 - \\frac{b^2}{r^2} \\left(1 - \\frac{2m}{r} \\right) }\n", "$$\n", "$$\n", " v^\\theta = \\frac{\\mathrm{d}\\theta}{\\mathrm{d}\\lambda} = 0\n", "$$\n", "$$\n", " v^\\varphi = \\frac{\\mathrm{d}\\varphi}{\\mathrm{d}\\lambda} = \\frac{b}{r^2}\n", "$$\n", "where the constant $b$ is related to the conserved energy $E$ and conserved angular momentum $L$ along the geodesic by \n", "$$\n", " b = \\frac{L}{E} . \n", "$$\n", "For a geodesic arising from infinity, $b$ is the **impact parameter**." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To set up the initial vector for the computation of a null geodesic, let us define a function that takes $b$ and some initial radius $r_0$ as input and returns the initial vector $v_0$. We take advantage that SageMath is built atop Python to construct this function as a pure Python function:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def initial_vector(r0, b, phi0=0, inward=True):\n", " r\"\"\"\n", " Evaluate the initial tangent vector along a null geodesic. \n", " \n", " INPUT:\n", " \n", " - r0: radial SD coordinate of the initial point\n", " - b: impact parameter\n", " - phi0: azimuthal SD coordinate of the initial point (default: 0)\n", " - inward: determines whether the geodesic has initially v^r < 0 (default: True)\n", " \n", " \"\"\"\n", " vt0 = 1/(1 - 2*m/r0)\n", " vr0 = sqrt(1 - b^2/r0^2*(1 - 2*m/r0))\n", " if inward:\n", " vr0 = - vr0\n", " vth0 = 0\n", " vph0 = b / r0^2\n", " p0 = M((0, r0, pi/2, phi0), name='p_0') # initial point\n", " return M.tangent_space(p0)((vt0, vr0, vth0, vph0), name='v_0')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us use this function to construct the initial vector for $r_0 = 10m$ and $b=7m$:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "v0 = initial_vector(10*m, 7*m)\n", "v0.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us check that $v_0$ is a null vector:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p0 = v0.parent().base_point()\n", "g.at(p0)(v0, v0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geod = M.integrated_geodesic(g, (s, 0, 40), v0)\n", "sol = geod.solve(step=0.01, parameters_values={m: 1}) \n", "interp = geod.interpolate() \n", "plot2 = geod.plot_integrated(chart=X3, mapping=to_E3, ambient_coords=(x,y), \n", " plot_points=500, color='green', thickness=1.5, display_tangent=True, \n", " color_tangent='green', plot_points_tangent=4, scale=1) \n", "plot2 += bh_plot\n", "plot2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A null geodesic plunging into the black hole:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "v0 = initial_vector(10*m, 5*m)\n", "v0.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geod = M.integrated_geodesic(g, (s, 0, 13), v0)\n", "sol = geod.solve(step=0.01, parameters_values={m: 1}) \n", "interp = geod.interpolate() \n", "plot2 += geod.plot_integrated(chart=X3, mapping=to_E3, ambient_coords=(x,y), \n", " plot_points=500, color='green', thickness=1.5, display_tangent=True, \n", " color_tangent='green', plot_points_tangent=3, scale=0.2)\n", "plot2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### The photon orbit" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The photon orbit corresponds to $r_0=3m$ with the following critical value of the impact parameter: \n", "$$\n", " b_{\\rm c} = 3\\sqrt{3}\\, m\n", "$$" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bc = 3*sqrt(3)*m\n", "n(bc/m)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "v0 = initial_vector(3*m, bc)\n", "v0.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geod = M.integrated_geodesic(g, (s, 0, 100), v0)\n", "sol = geod.solve(step=0.01, parameters_values={m: 1}) \n", "interp = geod.interpolate() \n", "plot2 += geod.plot_integrated(chart=X3, mapping=to_E3, ambient_coords=(x,y), \n", " plot_points=500, color='green', thickness=1.5)\n", "plot2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A geodesic with $b$ close to $b_{\\rm c}$ wraps around the circular orbit: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "v0 = initial_vector(10*m, 5.2025*m)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geod = M.integrated_geodesic(g, (s, 0, 40), v0)\n", "sol = geod.solve(step=0.01, parameters_values={m: 1}) \n", "interp = geod.interpolate() \n", "plot2 += geod.plot_integrated(chart=X3, mapping=to_E3, ambient_coords=(x,y), \n", " plot_points=500, color='orange', thickness=1.5,\n", " display_tangent=True, color_tangent='orange', \n", " plot_points_tangent=4, scale=1)\n", "plot2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Using SymPy as the symbolic backend\n", "\n", "By default, the symbolic backend used in tensor calculus is SageMath's one (Pynac + Maxima), implemented via the symbolic ring `SR`. We can choose to use SymPy instead:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "M.set_calculus_method('sympy')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "v = 2*k" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "v.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "v[0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "v[0].expr()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(v[0].expr())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Back to SageMath's default:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "M.set_calculus_method('SR')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(v[0].expr())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Going further\n", "\n", "\n", "Visit the [SageManifolds examples](http://sagemanifolds.obspm.fr/examples.html) and take a look at the [video tutorials](https://www.youtube.com/playlist?list=PLnrOCYZpQUuJlnQbQ48zgGk-Ks1t145Yw)." ] } ], "metadata": { "kernelspec": { "display_name": "SageMath 10.10", "language": "sage", "name": "sagemath" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.18" } }, "nbformat": 4, "nbformat_minor": 4 }