test_hyperbolic_space.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. r'''
  2. unit test describing the hyperbolic half-plane with the Poincare metric. This
  3. is a basic model of hyperbolic geometry on the (positive) half-space
  4. {(x,y) \in R^2 | y > 0}
  5. with the Riemannian metric
  6. ds^2 = (dx^2 + dy^2)/y^2
  7. It has constant negative scalar curvature = -2
  8. https://en.wikipedia.org/wiki/Poincare_half-plane_model
  9. '''
  10. from sympy.matrices.dense import diag
  11. from sympy.diffgeom import (twoform_to_matrix,
  12. metric_to_Christoffel_1st, metric_to_Christoffel_2nd,
  13. metric_to_Riemann_components, metric_to_Ricci_components)
  14. import sympy.diffgeom.rn
  15. from sympy.tensor.array import ImmutableDenseNDimArray
  16. def test_H2():
  17. TP = sympy.diffgeom.TensorProduct
  18. R2 = sympy.diffgeom.rn.R2
  19. y = R2.y
  20. dy = R2.dy
  21. dx = R2.dx
  22. g = (TP(dx, dx) + TP(dy, dy))*y**(-2)
  23. automat = twoform_to_matrix(g)
  24. mat = diag(y**(-2), y**(-2))
  25. assert mat == automat
  26. gamma1 = metric_to_Christoffel_1st(g)
  27. assert gamma1[0, 0, 0] == 0
  28. assert gamma1[0, 0, 1] == -y**(-3)
  29. assert gamma1[0, 1, 0] == -y**(-3)
  30. assert gamma1[0, 1, 1] == 0
  31. assert gamma1[1, 1, 1] == -y**(-3)
  32. assert gamma1[1, 1, 0] == 0
  33. assert gamma1[1, 0, 1] == 0
  34. assert gamma1[1, 0, 0] == y**(-3)
  35. gamma2 = metric_to_Christoffel_2nd(g)
  36. assert gamma2[0, 0, 0] == 0
  37. assert gamma2[0, 0, 1] == -y**(-1)
  38. assert gamma2[0, 1, 0] == -y**(-1)
  39. assert gamma2[0, 1, 1] == 0
  40. assert gamma2[1, 1, 1] == -y**(-1)
  41. assert gamma2[1, 1, 0] == 0
  42. assert gamma2[1, 0, 1] == 0
  43. assert gamma2[1, 0, 0] == y**(-1)
  44. Rm = metric_to_Riemann_components(g)
  45. assert Rm[0, 0, 0, 0] == 0
  46. assert Rm[0, 0, 0, 1] == 0
  47. assert Rm[0, 0, 1, 0] == 0
  48. assert Rm[0, 0, 1, 1] == 0
  49. assert Rm[0, 1, 0, 0] == 0
  50. assert Rm[0, 1, 0, 1] == -y**(-2)
  51. assert Rm[0, 1, 1, 0] == y**(-2)
  52. assert Rm[0, 1, 1, 1] == 0
  53. assert Rm[1, 0, 0, 0] == 0
  54. assert Rm[1, 0, 0, 1] == y**(-2)
  55. assert Rm[1, 0, 1, 0] == -y**(-2)
  56. assert Rm[1, 0, 1, 1] == 0
  57. assert Rm[1, 1, 0, 0] == 0
  58. assert Rm[1, 1, 0, 1] == 0
  59. assert Rm[1, 1, 1, 0] == 0
  60. assert Rm[1, 1, 1, 1] == 0
  61. Ric = metric_to_Ricci_components(g)
  62. assert Ric[0, 0] == -y**(-2)
  63. assert Ric[0, 1] == 0
  64. assert Ric[1, 0] == 0
  65. assert Ric[0, 0] == -y**(-2)
  66. assert Ric == ImmutableDenseNDimArray([-y**(-2), 0, 0, -y**(-2)], (2, 2))
  67. ## scalar curvature is -2
  68. #TODO - it would be nice to have index contraction built-in
  69. R = (Ric[0, 0] + Ric[1, 1])*y**2
  70. assert R == -2
  71. ## Gauss curvature is -1
  72. assert R/2 == -1