예제 #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)
예제 #2
0
    def find_Christoffel_tensor(self, form="simplified"):
        """
        Method determines the Riemann-Christoffel tensor 
        for a given metric(which must be in two-form).
        
        form : default value - "simplified"
        If desired, a simplified form is returned. 

        The returned value is a SymPy Matrix.
        """
        from sympy.diffgeom import metric_to_Riemann_components
        metric = self.metric
        R = metric_to_Riemann_components(metric)
        simpR = self._tuple_to_list(R)
        dim = self.dim
        if form == "simplified":
            print 'Performing simplifications on each component....'
            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])
                            expr = self._symplify_expr(expr)
                            simpR[m][i][j][k] = expr
        self.Christoffel = sympy.Matrix(simpR)
        return self.Christoffel
예제 #3
0
파일: tensor.py 프로젝트: imranal/DiffTens
    def find_Christoffel_tensor(self,form="simplified"):
        """
        Method determines the Riemann-Christoffel tensor 
        for a given metric(which must be in two-form).
        
        form : default value - "simplified"
        If desired, a simplified form is returned. 

        The returned value is a SymPy Matrix.
        """
        from sympy.diffgeom import metric_to_Riemann_components
        metric = self.metric
        R = metric_to_Riemann_components(metric)
        simpR = self._tuple_to_list(R)
        dim = self.dim
        if form=="simplified":
            print 'Performing simplifications on each component....'
            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])
                            expr = self._symplify_expr(expr)
                            simpR[m][i][j][k] = expr
        self.Christoffel = sympy.Matrix(simpR)
        return self.Christoffel
예제 #4
0
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)

    one_vector = R2.e_x + R2.e_y
    two_vector = TensorProduct(R2.e_x, R2.e_y)
    three_vector = TensorProduct(R2.e_x, R2.e_y, R2.e_x)
    two_wp = WedgeProduct(R2.e_x, R2.e_y)

    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

    assert contravariant_order(one_vector) == 1
    assert contravariant_order(two_vector) == 2
    assert contravariant_order(three_vector) == 3
    assert contravariant_order(two_vector + two_wp) == 2

    raises(ValueError, lambda: covariant_order(misform_a))
    raises(ValueError, lambda: covariant_order(misform_b))
    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]])

    raises(ValueError, lambda: twoform_to_matrix(one_form))
    raises(ValueError, lambda: twoform_to_matrix(three_form))
    raises(ValueError, lambda: twoform_to_matrix(metric_ambig))

    raises(ValueError, lambda: metric_to_Christoffel_1st(twoform_not_sym))
    raises(ValueError, lambda: metric_to_Christoffel_2nd(twoform_not_sym))
    raises(ValueError, lambda: metric_to_Riemann_components(twoform_not_sym))
    raises(ValueError, lambda: metric_to_Ricci_components(twoform_not_sym))
예제 #5
0
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)

    one_vector = R2.e_x + R2.e_y
    two_vector = TensorProduct(R2.e_x, R2.e_y)
    three_vector = TensorProduct(R2.e_x, R2.e_y, R2.e_x)
    two_wp = WedgeProduct(R2.e_x,R2.e_y)

    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

    assert contravariant_order(one_vector) == 1
    assert contravariant_order(two_vector) == 2
    assert contravariant_order(three_vector) == 3
    assert contravariant_order(two_vector + two_wp) == 2

    raises(ValueError, lambda: covariant_order(misform_a))
    raises(ValueError, lambda: covariant_order(misform_b))
    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]])

    raises(ValueError, lambda: twoform_to_matrix(one_form))
    raises(ValueError, lambda: twoform_to_matrix(three_form))
    raises(ValueError, lambda: twoform_to_matrix(metric_ambig))

    raises(ValueError, lambda: metric_to_Christoffel_1st(twoform_not_sym))
    raises(ValueError, lambda: metric_to_Christoffel_2nd(twoform_not_sym))
    raises(ValueError, lambda: metric_to_Riemann_components(twoform_not_sym))
    raises(ValueError, lambda: metric_to_Ricci_components(twoform_not_sym))
예제 #6
0
def test_H2():
    TP = sympy.diffgeom.TensorProduct
    R2 = sympy.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)

    ## 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 = sympy.diffgeom.TensorProduct
    R2 = sympy.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
예제 #8
0
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])
                expr = trigsimp(expr)
                expr = simplify(expr)
                simpR[m][i][j][k] = expr
예제 #9
0
TP = TensorProduct
twoform_to_matrix(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
twoform_to_matrix(R2.x*TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
twoform_to_matrix(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy) - TP(R2.dx, R2.dy)/2)
# metric_to_Christoffel_1st(expr) Return the nested list of Christoffel symbols for the given metric.  This returns the Christoffel symbol of first kind that represents the Levi-Civita connection for the given metric.
from sympy.diffgeom.rn import R2
from sympy.diffgeom import metric_to_Christoffel_1st, TensorProduct
TP = TensorProduct
metric_to_Christoffel_1st(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
metric_to_Christoffel_1st(R2.x*TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
# metric_to_Riemann_components(expr) Return the components of the Riemann tensor expressed in a given basis.  Given a metric it calculates the components of the Riemann tensor in the canonical basis of the coordinate system in which the metric expression is given.
from sympy import pprint, exp
from sympy.diffgeom.rn import R2
from sympy.diffgeom import metric_to_Riemann_components, TensorProduct
TP = TensorProduct
metric_to_Riemann_components(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))

non_trivial_metric = exp(2*R2.r)*TP(R2.dr, R2.dr) +         R2.r**2*TP(R2.dtheta, R2.dtheta)
non_trivial_metric
riemann = metric_to_Riemann_components(non_trivial_metric)
riemann[0]
riemann[1]
#metric_to_Ricci_components Return the components of the Ricci tensor expressed in a given basis.  Given a metric it calculates the components of the Ricci tensor in the canonical basis of the coordinate system in which the metric expression is given.
from sympy import pprint, exp
from sympy.diffgeom.rn import R2
from sympy.diffgeom import metric_to_Ricci_components, TensorProduct
TP = TensorProduct
metric_to_Ricci_components(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
non_trivial_metric = exp(2*R2.r)*TP(R2.dr, R2.dr) +                              R2.r**2*TP(R2.dtheta, R2.dtheta)
non_trivial_metric
metric_to_Ricci_components(non_trivial_metric) #TODO why is this not simpler