Пример #1
0
def test_coords():
    r, theta = symbols('r, theta')
    m = Manifold('M', 2)
    patch = Patch('P', m)
    rect = CoordSystem('rect', patch)
    polar = CoordSystem('polar', patch)
    polar.connect_to(rect, [r, theta], [r * cos(theta), r * sin(theta)])
    polar.coord_tuple_transform_to(rect, [0, 2]) == Matrix([[0], [0]])
Пример #2
0
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
Пример #3
0
def test_sympyissue_11799():
    n = 2
    M = Manifold('M', n)
    P = Patch('P', M)

    coord = CoordSystem('coord', P, ['x%s' % i for i in range(n)])
    x = coord.coord_functions()
    dx = coord.base_oneforms()

    f = Function('f')
    g = [[f(x[0], x[1])**2, 0], [0, f(x[0], x[1])**2]]
    metric = sum(g[i][j]*TP(dx[i], dx[j]) for i in range(n) for j in range(n))

    R = metric_to_Riemann_components(metric)
    d = Symbol('d')

    assert (R[0, 1, 0, 1] ==
            -Subs(Derivative(f(d, x[1]), d, d), (d, x[0]))/f(x[0], x[1]) -
            Subs(Derivative(f(x[0], d), d, d), (d, x[1]))/f(x[0], x[1]) +
            Subs(Derivative(f(d, x[1]), d), (d, x[0]))**2/f(x[0], x[1])**2 +
            Subs(Derivative(f(x[0], d), d), (d, x[1]))**2/f(x[0], x[1])**2)
Пример #4
0
from diofant.diffgeom import Manifold, Patch, CoordSystem, Point
from diofant import symbols, Function

__all__ = ()

m = Manifold('m', 2)
p = Patch('p', m)
cs = CoordSystem('cs', p, ['a', 'b'])
cs_noname = CoordSystem('cs', p)
x, y = symbols('x y')
f = Function('f')
s1, s2 = cs.coord_functions()
v1, v2 = cs.base_vectors()
f1, f2 = cs.base_oneforms()


def test_point():
    point = Point(cs, [x, y])
    assert point == point.func(*point.args)
    assert point != Point(cs, [2, y])
    # TODO assert point.subs(x, 2) == Point(cs, [2, y])
    # TODO assert point.free_symbols == {x, y}


def test_rebuild():
    assert m == m.func(*m.args)
    assert p == p.func(*p.args)
    assert cs == cs.func(*cs.args)
    assert cs_noname == cs_noname.func(*cs_noname.args)
    assert s1 == s1.func(*s1.args)
    assert v1 == v1.func(*v1.args)