Contact Us!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: sagemathinc/cocalc-example-files
Path: blob/master/sage/SageManifolds/SM_Friedmann_equations.sagews
Views: 1045
%auto typeset_mode(True, display=False)

Friedmann equations

This worksheet demonstrates a few capabilities of SageManifolds (version 0.8) in computations regarding cosmological spacetimes with Friedmann-Lemaître-Robertson-Walker (FLRW) metrics.

It is released under the GNU General Public License version 3.

(c) Michal Bejger, Eric Gourgoulhon (2015)

The corresponding worksheet file can be downloaded from here.

We declare the spacetime M as a 4-dimensional manifold:

M = Manifold(4, 'M')

We introduce the standard FLRW coordinates:

fr.<t,r,th,ph> = M.chart(r't r:[0,+oo) th:[0,pi]:\theta ph:[0,2*pi):\phi') fr
(M,(t,r,θ,ϕ))\left(M,(t, r, {\theta}, {\phi})\right)

Assuming that the speed of light c=1, let us define a few variables: Newton's constant GG, the cosmological constant Λ\Lambda, the spatial curvature constant kk, the scale factor a(t)a(t), the fluid proper density ρ\rho and the fluid pressure pp:

var('G, Lambda, k') a = M.scalar_field(function('a', t), name='a') rho = M.scalar_field(function('rho', t), name='rho') p = M.scalar_field(function('p', t), name='p')
(GG, Λ\Lambda, kk)

The FLRW metric is defined by its components:

g = M.lorentz_metric('g') g[0,0] = -1 g[1,1] = a*a/(1 - k*r^2) g[2,2] = a*a*r^2 g[3,3] = a*a*(r*sin(th))^2 g.display()
g=dtdt+(a(t)2kr21)drdr+r2a(t)2dθdθ+r2a(t)2sin(θ)2dϕdϕg = -\mathrm{d} t\otimes \mathrm{d} t + \left( -\frac{a\left(t\right)^{2}}{k r^{2} - 1} \right) \mathrm{d} r\otimes \mathrm{d} r + r^{2} a\left(t\right)^{2} \mathrm{d} {\theta}\otimes \mathrm{d} {\theta} + r^{2} a\left(t\right)^{2} \sin\left({\theta}\right)^{2} \mathrm{d} {\phi}\otimes \mathrm{d} {\phi}

A matrix view of the metric components:

g[:]
(10000a(t)2kr210000r2a(t)20000r2a(t)2sin(θ)2)\left(\begin{array}{rrrr} -1 & 0 & 0 & 0 \\ 0 & -\frac{a\left(t\right)^{2}}{k r^{2} - 1} & 0 & 0 \\ 0 & 0 & r^{2} a\left(t\right)^{2} & 0 \\ 0 & 0 & 0 & r^{2} a\left(t\right)^{2} \sin\left({\theta}\right)^{2} \end{array}\right)

The Levi-Civita connection associated with the metric is computed:

nab = g.connection() g.christoffel_symbols_display()
Γtrrtrr=a(t)atkr21Γtθθtθθ=r2a(t)atΓtϕϕtϕϕ=r2a(t)sin(θ)2atΓrtrrtr=ata(t)Γrrrrrr=krkr21Γrθθrθθ=kr3rΓrϕϕrϕϕ=(kr3r)sin(θ)2Γθtθθtθ=ata(t)Γθrθθrθ=1rΓθϕϕθϕϕ=cos(θ)sin(θ)Γϕtϕϕtϕ=ata(t)Γϕrϕϕrϕ=1rΓϕθϕϕθϕ=cos(θ)sin(θ)\begin{array}{lcl} \Gamma_{ \phantom{\, t } \, r \, r }^{ \, t \phantom{\, r } \phantom{\, r } } & = & -\frac{a\left(t\right) \frac{\partial\,a}{\partial t}}{k r^{2} - 1} \\ \Gamma_{ \phantom{\, t } \, {\theta} \, {\theta} }^{ \, t \phantom{\, {\theta} } \phantom{\, {\theta} } } & = & r^{2} a\left(t\right) \frac{\partial\,a}{\partial t} \\ \Gamma_{ \phantom{\, t } \, {\phi} \, {\phi} }^{ \, t \phantom{\, {\phi} } \phantom{\, {\phi} } } & = & r^{2} a\left(t\right) \sin\left({\theta}\right)^{2} \frac{\partial\,a}{\partial t} \\ \Gamma_{ \phantom{\, r } \, t \, r }^{ \, r \phantom{\, t } \phantom{\, r } } & = & \frac{\frac{\partial\,a}{\partial t}}{a\left(t\right)} \\ \Gamma_{ \phantom{\, r } \, r \, r }^{ \, r \phantom{\, r } \phantom{\, r } } & = & -\frac{k r}{k r^{2} - 1} \\ \Gamma_{ \phantom{\, r } \, {\theta} \, {\theta} }^{ \, r \phantom{\, {\theta} } \phantom{\, {\theta} } } & = & k r^{3} - r \\ \Gamma_{ \phantom{\, r } \, {\phi} \, {\phi} }^{ \, r \phantom{\, {\phi} } \phantom{\, {\phi} } } & = & {\left(k r^{3} - r\right)} \sin\left({\theta}\right)^{2} \\ \Gamma_{ \phantom{\, {\theta} } \, t \, {\theta} }^{ \, {\theta} \phantom{\, t } \phantom{\, {\theta} } } & = & \frac{\frac{\partial\,a}{\partial t}}{a\left(t\right)} \\ \Gamma_{ \phantom{\, {\theta} } \, r \, {\theta} }^{ \, {\theta} \phantom{\, r } \phantom{\, {\theta} } } & = & \frac{1}{r} \\ \Gamma_{ \phantom{\, {\theta} } \, {\phi} \, {\phi} }^{ \, {\theta} \phantom{\, {\phi} } \phantom{\, {\phi} } } & = & -\cos\left({\theta}\right) \sin\left({\theta}\right) \\ \Gamma_{ \phantom{\, {\phi} } \, t \, {\phi} }^{ \, {\phi} \phantom{\, t } \phantom{\, {\phi} } } & = & \frac{\frac{\partial\,a}{\partial t}}{a\left(t\right)} \\ \Gamma_{ \phantom{\, {\phi} } \, r \, {\phi} }^{ \, {\phi} \phantom{\, r } \phantom{\, {\phi} } } & = & \frac{1}{r} \\ \Gamma_{ \phantom{\, {\phi} } \, {\theta} \, {\phi} }^{ \, {\phi} \phantom{\, {\theta} } \phantom{\, {\phi} } } & = & \frac{\cos\left({\theta}\right)}{\sin\left({\theta}\right)} \end{array}
Ricci tensor:
Ricci = nab.ricci() Ricci.display()
Ric(g)=32at2a(t)dtdt+(2(at)2+a(t)2at2+2kkr21)drdr+(2r2(at)2+r2a(t)2at2+2kr2)dθdθ+(2r2(at)2+r2a(t)2at2+2kr2)sin(θ)2dϕdϕ\mathrm{Ric}\left(g\right) = -\frac{3 \, \frac{\partial^2\,a}{\partial t^2}}{a\left(t\right)} \mathrm{d} t\otimes \mathrm{d} t + \left( -\frac{2 \, \left(\frac{\partial\,a}{\partial t}\right)^{2} + a\left(t\right) \frac{\partial^2\,a}{\partial t^2} + 2 \, k}{k r^{2} - 1} \right) \mathrm{d} r\otimes \mathrm{d} r + \left( 2 \, r^{2} \left(\frac{\partial\,a}{\partial t}\right)^{2} + r^{2} a\left(t\right) \frac{\partial^2\,a}{\partial t^2} + 2 \, k r^{2} \right) \mathrm{d} {\theta}\otimes \mathrm{d} {\theta} + {\left(2 \, r^{2} \left(\frac{\partial\,a}{\partial t}\right)^{2} + r^{2} a\left(t\right) \frac{\partial^2\,a}{\partial t^2} + 2 \, k r^{2}\right)} \sin\left({\theta}\right)^{2} \mathrm{d} {\phi}\otimes \mathrm{d} {\phi}

Ricci scalar (R μμR^\mu_{\ \, \mu}):

Ricci_scalar = g.ricci_scalar() Ricci_scalar.display()
r(g):MR(t,r,θ,ϕ)6((at)2+a(t)2at2+k)a(t)2\begin{array}{llcl} \mathrm{r}\left(g\right):& M & \longrightarrow & \mathbb{R} \\ & \left(t, r, {\theta}, {\phi}\right) & \longmapsto & \frac{6 \, {\left(\left(\frac{\partial\,a}{\partial t}\right)^{2} + a\left(t\right) \frac{\partial^2\,a}{\partial t^2} + k\right)}}{a\left(t\right)^{2}} \end{array}

The fluid 4-velocity:

u = M.vector_field('u') u[0] = 1 u.display()
u=tu = \frac{\partial}{\partial t }
g(u,u).expr()
1-1

Perfect fluid energy-momentum tensor TT:

u_form = u.down(g) # the 1-form associated to u by metric duality T = (rho+p)*(u_form*u_form) + p*g T.set_name('T') print T T.display()
field of symmetric bilinear forms 'T' on the 4-dimensional manifold 'M'
T=ρ(t)dtdt+(a(t)2p(t)kr21)drdr+r2a(t)2p(t)dθdθ+r2a(t)2p(t)sin(θ)2dϕdϕT = \rho\left(t\right) \mathrm{d} t\otimes \mathrm{d} t + \left( -\frac{a\left(t\right)^{2} p\left(t\right)}{k r^{2} - 1} \right) \mathrm{d} r\otimes \mathrm{d} r + r^{2} a\left(t\right)^{2} p\left(t\right) \mathrm{d} {\theta}\otimes \mathrm{d} {\theta} + r^{2} a\left(t\right)^{2} p\left(t\right) \sin\left({\theta}\right)^{2} \mathrm{d} {\phi}\otimes \mathrm{d} {\phi}

The trace of TT (we use index notation to denote the double contraction gabTabg^{ab} T_{ab}):

Ttrace = g.inverse()['^ab']*T['_ab'] Ttrace.display()
MR(t,r,θ,ϕ)3p(t)ρ(t)\begin{array}{llcl} & M & \longrightarrow & \mathbb{R} \\ & \left(t, r, {\theta}, {\phi}\right) & \longmapsto & 3 \, p\left(t\right) - \rho\left(t\right) \end{array}

Einstein equation: Rμν12Rgμν+ Λgμν=8πGTμνR_{\mu \nu} - {1 \over 2} R g_{\mu \nu} + \Lambda g_{\mu \nu} = {8 \pi G} T_{\mu \nu}

E1 = Ricci - Ricci_scalar/2*g + Lambda*g - (8*pi*G)*T print "First Friedmann equation:\n" E1[0,0].expr().expand() == 0
First Friedmann equation:
8πGρ(t)Λ+3D[0](a)(t)2a(t)2+3ka(t)2=0-8 \, \pi G \rho\left(t\right) - \Lambda + \frac{3 \, D[0]\left(a\right)\left(t\right)^{2}}{a\left(t\right)^{2}} + \frac{3 \, k}{a\left(t\right)^{2}} = 0

Trace-reversed version of the Einstein equation: RμνΛgμν=8πG(Tμν12Tgμν)R_{\mu \nu} - \Lambda g_{\mu \nu} = {8 \pi G} \left(T_{\mu \nu} - {1 \over 2}T\,g_{\mu \nu}\right)

E2 = Ricci - Lambda*g - (8*pi*G)*(T - Ttrace/2*g) print "Second Friedmann equation:\n" E2[0,0].expr().expand() == 0
Second Friedmann equation:
12πGp(t)4πGρ(t)+Λ3D[0,0](a)(t)a(t)=0-12 \, \pi G p\left(t\right) - 4 \, \pi G \rho\left(t\right) + \Lambda - \frac{3 \, D[0, 0]\left(a\right)\left(t\right)}{a\left(t\right)} = 0