Advertisement
Guest User

Riemann tensor for a Sphere in 2D

a guest
Oct 17th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. from sympy.diffgeom import Manifold, Patch, CoordSystem, TensorProduct
  2. from sympy import sin, trigsimp, simplify
  3. from sympy.abc import r
  4. from sympy.diffgeom import metric_to_Riemann_components
  5.  
  6. dim = 2
  7. m = Manifold("M",dim)
  8. patch = Patch("P",m)
  9.  
  10. cartesian = CoordSystem("cartesian",patch, ["x", "y"])
  11. flat_sphere = CoordSystem("flat_sphere", patch, ["theta", "phi"])
  12.  
  13. x, y = cartesian.coord_functions()
  14. theta, phi = flat_sphere.coord_functions()
  15. dtheta,dphi = flat_sphere.base_oneforms()
  16.  
  17. metric_diff_form = r**2*TensorProduct(dtheta, dtheta) + r**2*sin(theta)**2*TensorProduct(dphi, dphi)
  18. R = metric_to_Riemann_components(metric_diff_form)
  19.  
  20. def tuple_to_list(t):
  21.     return list(map(tuple_to_list, t)) if isinstance(t, (list, tuple)) else t
  22. simpR = tuple_to_list(R)
  23. for m in range(dim):
  24.     for i in range(dim):
  25.         for j in range(dim):
  26.             for k in range(dim):
  27.                 expr = str(R[m][i][j][k])
  28.                 expr = trigsimp(expr)
  29.                 expr = simplify(expr)
  30.                 simpR[m][i][j][k] = expr
  31.  
  32. # Find the Ricci tensor
  33. from sympy.diffgeom import metric_to_Ricci_components
  34. RR = metric_to_Ricci_components(metric_diff_form)
  35. simpRR = tuple_to_list(RR)
  36. for m in range(dim):
  37.     for i in range(dim):
  38.         expr = str(RR[m][i])
  39.         expr = trigsimp(expr)
  40.         expr = simplify(expr)
  41.         simpRR[m][i] = expr
  42. print simpR, simpRR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement