def test_schwarzschild(): m = Manifold('Schwarzschild', 4) p = Patch('origin', m) cs = CoordSystem('spherical', p, ['t', 'r', 'theta', 'phi']) t, r, theta, phi = cs.coord_functions() dt, dr, dtheta, dphi = cs.base_oneforms() f, g = symbols('f g', cls=Function) metric = (exp(2*f(r))*TP(dt, dt) - exp(2*g(r))*TP(dr, dr) - r**2*TP(dtheta, dtheta) - r**2*sin(theta)**2*TP(dphi, dphi)) ricci = metric_to_Ricci_components(metric) assert all(ricci[i, j] == 0 for i in range(4) for j in range(4) if i != j) R = Symbol('R') eq1 = simplify((ricci[0, 0]/exp(2*f(r) - 2*g(r)) + ricci[1, 1])*r/2).subs(r, R).doit() assert eq1 == f(R).diff(R) + g(R).diff(R) eq2 = simplify(ricci[1, 1].replace(g, lambda x: -f(x)).replace(r, R).doit()) assert eq2 == -2*f(R).diff(R)**2 - f(R).diff(R, 2) - 2*f(R).diff(R)/R
def test_schwarzschild(): m = Manifold('Schwarzschild', 4) p = Patch('origin', m) cs = CoordSystem('spherical', p, ['t', 'r', 'theta', 'phi']) t, r, theta, phi = cs.coord_functions() dt, dr, dtheta, dphi = cs.base_oneforms() f, g = symbols('f g', cls=Function) metric = (exp(2*f(r))*TP(dt, dt) - exp(2*g(r))*TP(dr, dr) - r**2*TP(dtheta, dtheta) - r**2*sin(theta)**2*TP(dphi, dphi)) ricci = metric_to_Ricci_components(metric) assert all(ricci[i, j] == 0 for i in range(4) for j in range(4) if i != j) R = Symbol('R') eq1 = simplify((ricci[0, 0]/exp(2*f(r) - 2*g(r)) + ricci[1, 1])*r/2).subs({r: R}).doit() assert eq1 == f(R).diff(R) + g(R).diff(R) eq2 = simplify(ricci[1, 1].replace(g, lambda x: -f(x)).replace(r, R).doit()) assert eq2 == -2*f(R).diff(R)**2 - f(R).diff(R, 2) - 2*f(R).diff(R)/R
def test_helpers_and_coordinate_dependent(): one_form = R2.dr + R2.dx two_form = Differential(R2.x * R2.dr + R2.r * R2.dx) three_form = Differential(R2.y * two_form) + Differential( R2.x * Differential(R2.r * R2.dr)) metric = TensorProduct(R2.dx, R2.dx) + TensorProduct(R2.dy, R2.dy) metric_ambig = TensorProduct(R2.dx, R2.dx) + TensorProduct(R2.dr, R2.dr) misform_a = TensorProduct(R2.dr, R2.dr) + R2.dr misform_b = R2.dr**4 misform_c = R2.dx * R2.dy twoform_not_sym = TensorProduct(R2.dx, R2.dx) + TensorProduct(R2.dx, R2.dy) twoform_not_TP = WedgeProduct(R2.dx, R2.dy) assert covariant_order(one_form) == 1 assert covariant_order(two_form) == 2 assert covariant_order(three_form) == 3 assert covariant_order(two_form + metric) == 2 assert covariant_order(two_form + metric_ambig) == 2 assert covariant_order(two_form + twoform_not_sym) == 2 assert covariant_order(two_form + twoform_not_TP) == 2 pytest.raises(ValueError, lambda: covariant_order(misform_a)) pytest.raises(ValueError, lambda: covariant_order(misform_b)) pytest.raises(ValueError, lambda: covariant_order(misform_c)) assert twoform_to_matrix(metric) == Matrix([[1, 0], [0, 1]]) assert twoform_to_matrix(twoform_not_sym) == Matrix([[1, 0], [1, 0]]) assert twoform_to_matrix(twoform_not_TP) == Matrix([[0, -1], [1, 0]]) pytest.raises(ValueError, lambda: twoform_to_matrix(one_form)) pytest.raises(ValueError, lambda: twoform_to_matrix(three_form)) pytest.raises(ValueError, lambda: twoform_to_matrix(metric_ambig)) pytest.raises(ValueError, lambda: metric_to_Christoffel_1st(twoform_not_sym)) pytest.raises(ValueError, lambda: metric_to_Christoffel_2nd(twoform_not_sym)) pytest.raises(ValueError, lambda: metric_to_Riemann_components(twoform_not_sym)) pytest.raises(ValueError, lambda: metric_to_Ricci_components(twoform_not_sym))
def test_helpers_and_coordinate_dependent(): one_form = R2.dr + R2.dx two_form = Differential(R2.x*R2.dr + R2.r*R2.dx) three_form = Differential( R2.y*two_form) + Differential(R2.x*Differential(R2.r*R2.dr)) metric = TensorProduct(R2.dx, R2.dx) + TensorProduct(R2.dy, R2.dy) metric_ambig = TensorProduct(R2.dx, R2.dx) + TensorProduct(R2.dr, R2.dr) misform_a = TensorProduct(R2.dr, R2.dr) + R2.dr misform_b = R2.dr**4 misform_c = R2.dx*R2.dy twoform_not_sym = TensorProduct(R2.dx, R2.dx) + TensorProduct(R2.dx, R2.dy) twoform_not_TP = WedgeProduct(R2.dx, R2.dy) assert covariant_order(one_form) == 1 assert covariant_order(two_form) == 2 assert covariant_order(three_form) == 3 assert covariant_order(two_form + metric) == 2 assert covariant_order(two_form + metric_ambig) == 2 assert covariant_order(two_form + twoform_not_sym) == 2 assert covariant_order(two_form + twoform_not_TP) == 2 pytest.raises(ValueError, lambda: covariant_order(misform_a)) pytest.raises(ValueError, lambda: covariant_order(misform_b)) pytest.raises(ValueError, lambda: covariant_order(misform_c)) assert twoform_to_matrix(metric) == Matrix([[1, 0], [0, 1]]) assert twoform_to_matrix(twoform_not_sym) == Matrix([[1, 0], [1, 0]]) assert twoform_to_matrix(twoform_not_TP) == Matrix([[0, -1], [1, 0]]) pytest.raises(ValueError, lambda: twoform_to_matrix(one_form)) pytest.raises(ValueError, lambda: twoform_to_matrix(three_form)) pytest.raises(ValueError, lambda: twoform_to_matrix(metric_ambig)) pytest.raises(ValueError, lambda: metric_to_Christoffel_1st(twoform_not_sym)) pytest.raises(ValueError, lambda: metric_to_Christoffel_2nd(twoform_not_sym)) pytest.raises(ValueError, lambda: metric_to_Riemann_components(twoform_not_sym)) pytest.raises(ValueError, lambda: metric_to_Ricci_components(twoform_not_sym))
def test_H2(): TP = diofant.diffgeom.TensorProduct R2 = diofant.diffgeom.rn.R2 y = R2.y dy = R2.dy dx = R2.dx g = (TP(dx, dx) + TP(dy, dy)) * y**(-2) automat = twoform_to_matrix(g) mat = diag(y**(-2), y**(-2)) assert mat == automat gamma1 = metric_to_Christoffel_1st(g) assert gamma1[0, 0, 0] == 0 assert gamma1[0, 0, 1] == -y**(-3) assert gamma1[0, 1, 0] == -y**(-3) assert gamma1[0, 1, 1] == 0 assert gamma1[1, 1, 1] == -y**(-3) assert gamma1[1, 1, 0] == 0 assert gamma1[1, 0, 1] == 0 assert gamma1[1, 0, 0] == y**(-3) gamma2 = metric_to_Christoffel_2nd(g) assert gamma2[0, 0, 0] == 0 assert gamma2[0, 0, 1] == -y**(-1) assert gamma2[0, 1, 0] == -y**(-1) assert gamma2[0, 1, 1] == 0 assert gamma2[1, 1, 1] == -y**(-1) assert gamma2[1, 1, 0] == 0 assert gamma2[1, 0, 1] == 0 assert gamma2[1, 0, 0] == y**(-1) Rm = metric_to_Riemann_components(g) assert Rm[0, 0, 0, 0] == 0 assert Rm[0, 0, 0, 1] == 0 assert Rm[0, 0, 1, 0] == 0 assert Rm[0, 0, 1, 1] == 0 assert Rm[0, 1, 0, 0] == 0 assert Rm[0, 1, 0, 1] == -y**(-2) assert Rm[0, 1, 1, 0] == y**(-2) assert Rm[0, 1, 1, 1] == 0 assert Rm[1, 0, 0, 0] == 0 assert Rm[1, 0, 0, 1] == y**(-2) assert Rm[1, 0, 1, 0] == -y**(-2) assert Rm[1, 0, 1, 1] == 0 assert Rm[1, 1, 0, 0] == 0 assert Rm[1, 1, 0, 1] == 0 assert Rm[1, 1, 1, 0] == 0 assert Rm[1, 1, 1, 1] == 0 Ric = metric_to_Ricci_components(g) assert Ric[0, 0] == -y**(-2) assert Ric[0, 1] == 0 assert Ric[1, 0] == 0 assert Ric[0, 0] == -y**(-2) assert Ric == ImmutableDenseNDimArray([-y**(-2), 0, 0, -y**(-2)], (2, 2)) # scalar curvature is -2 # TODO - it would be nice to have index contraction built-in R = (Ric[0, 0] + Ric[1, 1]) * y**2 assert R == -2 # Gauss curvature is -1 assert R / 2 == -1
def test_H2(): TP = diofant.diffgeom.TensorProduct R2 = diofant.diffgeom.rn.R2 y = R2.y dy = R2.dy dx = R2.dx g = (TP(dx, dx) + TP(dy, dy))*y**(-2) automat = twoform_to_matrix(g) mat = diag(y**(-2), y**(-2)) assert mat == automat gamma1 = metric_to_Christoffel_1st(g) assert gamma1[0, 0, 0] == 0 assert gamma1[0, 0, 1] == -y**(-3) assert gamma1[0, 1, 0] == -y**(-3) assert gamma1[0, 1, 1] == 0 assert gamma1[1, 1, 1] == -y**(-3) assert gamma1[1, 1, 0] == 0 assert gamma1[1, 0, 1] == 0 assert gamma1[1, 0, 0] == y**(-3) gamma2 = metric_to_Christoffel_2nd(g) assert gamma2[0, 0, 0] == 0 assert gamma2[0, 0, 1] == -y**(-1) assert gamma2[0, 1, 0] == -y**(-1) assert gamma2[0, 1, 1] == 0 assert gamma2[1, 1, 1] == -y**(-1) assert gamma2[1, 1, 0] == 0 assert gamma2[1, 0, 1] == 0 assert gamma2[1, 0, 0] == y**(-1) Rm = metric_to_Riemann_components(g) assert Rm[0, 0, 0, 0] == 0 assert Rm[0, 0, 0, 1] == 0 assert Rm[0, 0, 1, 0] == 0 assert Rm[0, 0, 1, 1] == 0 assert Rm[0, 1, 0, 0] == 0 assert Rm[0, 1, 0, 1] == -y**(-2) assert Rm[0, 1, 1, 0] == y**(-2) assert Rm[0, 1, 1, 1] == 0 assert Rm[1, 0, 0, 0] == 0 assert Rm[1, 0, 0, 1] == y**(-2) assert Rm[1, 0, 1, 0] == -y**(-2) assert Rm[1, 0, 1, 1] == 0 assert Rm[1, 1, 0, 0] == 0 assert Rm[1, 1, 0, 1] == 0 assert Rm[1, 1, 1, 0] == 0 assert Rm[1, 1, 1, 1] == 0 Ric = metric_to_Ricci_components(g) assert Ric[0, 0] == -y**(-2) assert Ric[0, 1] == 0 assert Ric[1, 0] == 0 assert Ric[0, 0] == -y**(-2) assert Ric == ImmutableDenseNDimArray([-y**(-2), 0, 0, -y**(-2)], (2, 2)) # scalar curvature is -2 # TODO - it would be nice to have index contraction built-in R = (Ric[0, 0] + Ric[1, 1])*y**2 assert R == -2 # Gauss curvature is -1 assert R/2 == -1