2 This example calculates the Ricci tensor from the metric and does this
3 on the example of Schwarzschild solution.
9 from sympy
import exp
, Symbol
, sin
, Rational
, Derivative
, dsolve
, Function
, Matrix
26 return "g_dd =\n" + str(self
.gdd
)
35 def __init__(self
,g
,x
):
44 r
+=g
.uu(i
,m
)/2 * (g
.dd(m
,k
).diff(x
[l
])+g
.dd(m
,l
).diff(x
[k
]) \
45 - g
.dd(k
,l
).diff(x
[m
]))
48 class Riemann(object):
49 def __init__(self
,G
,x
):
53 def uddd(self
,rho
,sigma
,mu
,nu
):
56 r
=G
.udd(rho
,nu
,sigma
).diff(x
[mu
])-G
.udd(rho
,mu
,sigma
).diff(x
[nu
])
58 r
+=G
.udd(rho
,mu
,lam
)*G
.udd(lam
,nu
,sigma
) \
59 -G
.udd(rho
,nu
,lam
)*G
.udd(lam
,mu
,sigma
)
63 def __init__(self
,R
,x
):
73 r
+=R
.uddd(lam
,mu
,lam
,nu
)
79 r
+=self
.g
.uu(mu
,lam
)*self
.dd(lam
,nu
)
83 return Rmn
.ud(0,0)+Rmn
.ud(1,1)+Rmn
.ud(2,2)+Rmn
.ud(3,3)
99 theta
=Symbol(r
"\theta")
102 #general, spherically symmetric metric
105 (0, exp(lam(r
)), 0, 0),
107 (0, 0, 0, r
**2*sin(theta
)**2)
114 # (0, 0, 0, r**2*sin(theta)**2)
123 #polar - on the sphere, on the north pole
127 # (0, 0, r**2*sin(theta)**2, 0),
133 Rmn
=Ricci(Riemann(Gamma
,X
),X
)
139 print "Christoffel symbols:"
140 print Gamma
.udd(0,1,0)
141 print Gamma
.udd(0,0,1)
143 print Gamma
.udd(1,0,0)
144 print Gamma
.udd(1,1,1)
145 print Gamma
.udd(1,2,2)
146 print Gamma
.udd(1,3,3)
148 print Gamma
.udd(2,2,1)
149 print Gamma
.udd(2,1,2)
150 print Gamma
.udd(2,3,3)
152 print Gamma
.udd(3,2,3)
153 print Gamma
.udd(3,3,2)
154 print Gamma
.udd(3,1,3)
155 print Gamma
.udd(3,3,1)
157 print "Ricci tensor:"
164 #print "scalar curvature:"
165 #print curvature(Rmn)
167 print "solve the Einstein's equations:"
168 e
= e
.subs(nu(r
), -lam(r
))
169 l
= dsolve(e
, [lam(r
)])
171 metric
= gdd
.subs(lam(r
), l
).subs(nu(r
),-l
)#.combine()
175 if __name__
== "__main__":