Exemplo n.º 1
0
def test_curvature():
    #For testing curvature conventions
    M = Manifold('Reisner-Nordstrom', 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 = Function('f')
    metric = f(r)**2 * TP(dt, dt) - f(r)**(-2) * TP(dr, dr) - r**2 * TP(
        dtheta, dtheta) - r**2 * sin(theta)**2 * TP(dphi, dphi)
    ch_2nd = metric_to_Christoffel_2nd(metric)
    G = ToArray(metric)
    rm = TensorArray(components=metric_to_Riemann_components(metric),
                     variance=[-1, 1, 1, 1],
                     coordinate_system=cs)
    v = [Function(f) for f in ['v0', 'v1', 'v2', 'v3']]
    V = TensorArray(components=[f(t, r, theta, phi) for f in v],
                    variance=[-1],
                    coordinate_system=cs)
    dV = V.covD(ch_2nd)
    ddV = dV.covD(ch_2nd)
    #Commuted covariant derivative:
    D2V = ddV - ddV.braid(0, 1)
    rm = TensorArray(components=metric_to_Riemann_components(metric),
                     variance=[-1, 1, 1, 1],
                     coordinate_system=cs)
    rmv = rm.TensorProduct(V).contract(1, 4).braid(0, 1).braid(1, 2)
    rmvtensor = [(I, simplify(rmv.tensor[I])) for I in rmv.indices]
    rmvtensor = [(I, coeff) for (I, coeff) in rmvtensor if coeff != 0]
    rmvtensor.sort()
    D2Vtensor = [(I, simplify(D2V.tensor[I])) for I in D2V.indices]
    D2Vtensor = [(I, v) for (I, v) in D2Vtensor if v != 0]
    D2Vtensor.sort()
    for (a, b) in zip(rmvtensor, D2Vtensor):
        assert (a == b)
Exemplo n.º 2
0
def test_expand_tensor():
    M = Manifold('Reisner-Nordstrom', 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 = Function('f')
    metric = f(r)**2 * TP(dt, dt) - f(r)**(-2) * TP(dr, dr) - r**2 * TP(
        dtheta, dtheta) - r**2 * sin(theta)**2 * TP(dphi, dphi)
    assert (expand_tensor(metric) == metric)
Exemplo n.º 3
0
def test_covD():
    M = Manifold('Reisner-Nordstrom', 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 = Function('f')
    metric = f(r)**2 * TP(dt, dt) - f(r)**(-2) * TP(dr, dr) - r**2 * TP(
        dtheta, dtheta) - r**2 * sin(theta)**2 * TP(dphi, dphi)
    ch_2nd = metric_to_Christoffel_2nd(metric)
    G = ToArray(metric)
    assert (G.covD(ch_2nd).to_tensor() == 0)
Exemplo n.º 4
0
def mobius_strip():
    import find_metric as fm
    import tensor as t
    g,diff = fm.mobius_strip()
    R = t.Riemann(g,dim=2,sys_title='mobius_strip',flat_diff = diff)
    #metric=R.metric
    from sympy.diffgeom import TensorProduct, Manifold, Patch, CoordSystem
    manifold = Manifold("M",2)
    patch = Patch("P",manifold)
    system = CoordSystem('mobius_strip', patch, ["u", "v"])
    u, v = system.coord_functions()
    du,dv = system.base_oneforms()
    from sympy import cos
    metric = (cos(u/2)**2*v**2/4 + cos(u/2)*v + v**2/16 + 1)*TensorProduct(du, du) + 0.25*TensorProduct(dv, dv)
    C = Christoffel_2nd(metric=metric)
    return C
Exemplo n.º 5
0
def mobius_strip():
    import find_metric as fm
    import tensor as t
    g, diff = fm.mobius_strip()
    R = t.Riemann(g, dim=2, sys_title='mobius_strip', flat_diff=diff)
    #metric=R.metric
    from sympy.diffgeom import TensorProduct, Manifold, Patch, CoordSystem
    manifold = Manifold("M", 2)
    patch = Patch("P", manifold)
    system = CoordSystem('mobius_strip', patch, ["u", "v"])
    u, v = system.coord_functions()
    du, dv = system.base_oneforms()
    from sympy import cos
    metric = (cos(u / 2)**2 * v**2 / 4 + cos(u / 2) * v + v**2 / 16 +
              1) * TensorProduct(du, du) + 0.25 * TensorProduct(dv, dv)
    C = Christoffel_2nd(metric=metric)
    return C
Exemplo n.º 6
0
def flat_kerr(a=0,G=1,M=0.5):
    import find_metric as fm
    from sympy.diffgeom import CoordSystem, Manifold, Patch, TensorProduct
    
    manifold = Manifold("M",3)
    patch = Patch("P",manifold)
    kerr = CoordSystem("kerr", patch, ["u","v","w"])
    u,v,w = kerr.coord_functions()
    du,dv,dw = kerr.base_oneforms()

    g11 = (a**2*sym.cos(v) + u**2)/(-2*G*M*u + a**2 + u**2)
    g22 = a**2*sym.cos(v) + u**2
    g33 = -(1 - 2*G*M*u/(u**2 + a**2*sym.cos(v)))
    # time independent : unphysical ? 
    #g33 = 2*G*M*a**2*sym.sin(v)**4*u/(a**2*sym.cos(v) + u**2)**2 + a**2*sym.sin(v)**2 + sym.sin(v)**2*u**2
    metric = g11*TensorProduct(du, du) + g22*TensorProduct(dv, dv) + g33*TensorProduct(dw, dw)
    C = Christoffel_2nd(metric=metric)
    return C
Exemplo n.º 7
0
def flat_kerr(a=0, G=1, M=0.5):
    import find_metric as fm
    from sympy.diffgeom import CoordSystem, Manifold, Patch, TensorProduct

    manifold = Manifold("M", 3)
    patch = Patch("P", manifold)
    kerr = CoordSystem("kerr", patch, ["u", "v", "w"])
    u, v, w = kerr.coord_functions()
    du, dv, dw = kerr.base_oneforms()

    g11 = (a**2 * sym.cos(v) + u**2) / (-2 * G * M * u + a**2 + u**2)
    g22 = a**2 * sym.cos(v) + u**2
    g33 = -(1 - 2 * G * M * u / (u**2 + a**2 * sym.cos(v)))
    # time independent : unphysical ?
    #g33 = 2*G*M*a**2*sym.sin(v)**4*u/(a**2*sym.cos(v) + u**2)**2 + a**2*sym.sin(v)**2 + sym.sin(v)**2*u**2
    metric = g11 * TensorProduct(du, du) + g22 * TensorProduct(
        dv, dv) + g33 * TensorProduct(dw, dw)
    C = Christoffel_2nd(metric=metric)
    return C
# Create a patch.
patch = Patch('P', M)

# Basic symbols
c, r_s = symbols('c r_s')

# Coordinate system
schwarzchild_coord = CoordSystem('schwarzchild', patch,
                                 ['t', 'r', 'theta', 'phi'])

# Get the coordinate functions
t, r, theta, phi = schwarzchild_coord.coord_functions()

# Get the base one forms.
dt, dr, dtheta, dphi = schwarzchild_coord.base_oneforms()

# Auxiliar terms for the metric.
dt_2 = TP(dt, dt)
dr_2 = TP(dr, dr)
dtheta_2 = TP(dtheta, dtheta)
dphi_2 = TP(dphi, dphi)
factor = (1 - r_s / r)

# Build the metric
metric = factor * c**2 * dt_2 - 1 / factor * dr_2 - r**2 * (
    dtheta_2 + sin(theta)**2 * dphi_2)
metric = factor * c**2 * dt_2 - 1 / factor * dr_2 - r**2 * (
    dtheta_2 + sin(theta)**2 * dphi_2)
metric = metric / c**2
Exemplo n.º 9
0
from sympy.diffgeom import Manifold, Patch, CoordSystem, Point
from sympy import symbols, Function

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 == set([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)
    assert f1 == f1.func(*f1.args)
Exemplo n.º 10
0
from sympy.diffgeom import Manifold, Patch, CoordSystem, Point
from sympy import symbols, Function

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 == set([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)
    assert f1 == f1.func(*f1.args)

def test_subs():
    assert s1.subs(s1,s2) == s2
Exemplo n.º 11
0
from sympy.diffgeom import Manifold, Patch, CoordSystem
from sympy.diffgeom import TensorProduct as TP
from sympy.diffgeom import metric_to_Riemann_components as Riemann
from sympy.diffgeom import metric_to_Christoffel_2nd as Christoffel
from sympy import Symbol, Function, latex, sin

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()
g = [[1, 0], [0, sin(x[0])**2]]
metric = sum([g[i][j]*TP(dx[i], dx[j]) for i in range(n) for j in range(n)])

C = Christoffel(metric)
R = Riemann(metric)
Exemplo n.º 12
0
from sympy.diffgeom import Manifold, Patch, CoordSystem, TensorProduct
from sympy import sin, trigsimp, simplify
from sympy.abc import r
from sympy.diffgeom import metric_to_Riemann_components

dim = 2
m = Manifold("M", dim)
patch = Patch("P", m)

cartesian = CoordSystem("cartesian", patch, ["x", "y"])
flat_sphere = CoordSystem("flat_sphere", patch, ["theta", "phi"])

x, y = cartesian.coord_functions()
theta, phi = flat_sphere.coord_functions()
dtheta, dphi = flat_sphere.base_oneforms()

metric_diff_form = r**2 * TensorProduct(
    dtheta, dtheta) + r**2 * sin(theta)**2 * TensorProduct(dphi, dphi)
R = metric_to_Riemann_components(metric_diff_form)


def tuple_to_list(t):
    return list(map(tuple_to_list, t)) if isinstance(t, (list, tuple)) else t


simpR = tuple_to_list(R)
for m in range(dim):
    for i in range(dim):
        for j in range(dim):
            for k in range(dim):
                expr = str(R[m][i][j][k])