예제 #1
0
def test_differential():
    xdy = R2.x*R2.dy
    dxdy = Differential(xdy)
    assert xdy(None) == xdy
    assert dxdy(R2.e_x, R2.e_y) == 1
    assert dxdy(R2.e_x, R2.x*R2.e_y) == R2.x
    assert Differential(dxdy) == 0
예제 #2
0
def test_correct_arguments():
    raises(ValueError, lambda : R2.e_x(R2.e_x))
    raises(ValueError, lambda : R2.e_x(R2.dx))

    raises(ValueError, lambda : Commutator(R2.e_x, R2.x))
    raises(ValueError, lambda : Commutator(R2.dx, R2.e_x))

    raises(ValueError, lambda : Differential(Differential(R2.e_x)))

    raises(ValueError, lambda : R2.dx(R2.x))

    raises(ValueError, lambda : TensorProduct(R2.e_x, R2.dx))

    raises(ValueError, lambda : LieDerivative(R2.dx, R2.dx))
    raises(ValueError, lambda : LieDerivative(R2.x, R2.dx))

    raises(ValueError, lambda : CovarDerivativeOp(R2.dx, []))
    raises(ValueError, lambda : CovarDerivativeOp(R2.x, []))

    a = Symbol('a')
    raises(ValueError, lambda : intcurve_series(R2.dx, a, R2_r.point([1,2])))
    raises(ValueError, lambda : intcurve_series(R2.x, a, R2_r.point([1,2])))

    raises(ValueError, lambda : intcurve_diffequ(R2.dx, a, R2_r.point([1,2])))
    raises(ValueError, lambda : intcurve_diffequ(R2.x, a, R2_r.point([1,2])))

    raises(ValueError, lambda : contravariant_order(R2.e_x + R2.dx))
    raises(ValueError, lambda : covariant_order(R2.e_x + R2.dx))

    raises(ValueError, lambda : contravariant_order(R2.e_x*R2.e_y))
    raises(ValueError, lambda : covariant_order(R2.dx*R2.dy))
예제 #3
0
def test_functional_diffgeom_ch6():
    u0, u1, u2, v0, v1, v2, w0, w1, w2 = symbols('u0:3, v0:3, w0:3', real=True)

    u = u0 * R2.e_x + u1 * R2.e_y
    v = v0 * R2.e_x + v1 * R2.e_y
    wp = WedgeProduct(R2.dx, R2.dy)
    assert wp(u, v) == u0 * v1 - u1 * v0

    u = u0 * R3_r.e_x + u1 * R3_r.e_y + u2 * R3_r.e_z
    v = v0 * R3_r.e_x + v1 * R3_r.e_y + v2 * R3_r.e_z
    w = w0 * R3_r.e_x + w1 * R3_r.e_y + w2 * R3_r.e_z
    wp = WedgeProduct(R3_r.dx, R3_r.dy, R3_r.dz)
    assert wp(u, v, w) == Matrix(3, 3,
                                 [u0, u1, u2, v0, v1, v2, w0, w1, w2]).det()

    a, b, c = symbols('a, b, c', cls=Function)
    a_f = a(R3_r.x, R3_r.y, R3_r.z)
    b_f = b(R3_r.x, R3_r.y, R3_r.z)
    c_f = c(R3_r.x, R3_r.y, R3_r.z)
    theta = a_f * R3_r.dx + b_f * R3_r.dy + c_f * R3_r.dz
    dtheta = Differential(theta)
    da = Differential(a_f)
    db = Differential(b_f)
    dc = Differential(c_f)
    expr = dtheta - WedgeProduct(da, R3_r.dx) - WedgeProduct(
        db, R3_r.dy) - WedgeProduct(dc, R3_r.dz)
    assert expr(R3_r.e_x, R3_r.e_y) == 0
예제 #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))
def test_functional_diffgeom_ch4():
    x0, y0, theta0 = symbols('x0, y0, theta0', real=True)
    x, y, r, theta = symbols('x, y, r, theta', real=True)
    r0 = symbols('r0', positive=True)
    f = Function('f')
    b1 = Function('b1')
    b2 = Function('b2')
    p_r = R2_r.point([x0, y0])
    p_p = R2_p.point([r0, theta0])

    f_field = b1(R2.x, R2.y)*R2.dx + b2(R2.x, R2.y)*R2.dy
    assert f_field.rcall(R2.e_x).rcall(p_r) == b1(x0, y0)
    assert f_field.rcall(R2.e_y).rcall(p_r) == b2(x0, y0)

    s_field_r = f(R2.x, R2.y)
    df = Differential(s_field_r)
    assert df(R2.e_x).rcall(p_r).doit() == Derivative(f(x0, y0), x0)
    assert df(R2.e_y).rcall(p_r).doit() == Derivative(f(x0, y0), y0)

    s_field_p = f(R2.r, R2.theta)
    df = Differential(s_field_p)
    assert trigsimp(df(R2.e_x).rcall(p_p).doit()) == (
        cos(theta0)*Derivative(f(r0, theta0), r0) -
        sin(theta0)*Derivative(f(r0, theta0), theta0)/r0)
    assert trigsimp(df(R2.e_y).rcall(p_p).doit()) == (
        sin(theta0)*Derivative(f(r0, theta0), r0) +
        cos(theta0)*Derivative(f(r0, theta0), theta0)/r0)

    assert R2.dx(R2.e_x).rcall(p_r) == 1
    assert R2.dx(R2.e_x) == 1
    assert R2.dx(R2.e_y).rcall(p_r) == 0
    assert R2.dx(R2.e_y) == 0

    circ = -R2.y*R2.e_x + R2.x*R2.e_y
    assert R2.dx(circ).rcall(p_r).doit() == -y0
    assert R2.dy(circ).rcall(p_r) == x0
    assert R2.dr(circ).rcall(p_r) == 0
    assert simplify(R2.dtheta(circ).rcall(p_r)) == 1

    assert (circ - R2.e_theta).rcall(s_field_r).rcall(p_r) == 0
예제 #6
0
    def exteriorderivative(self, f):
        order = covariant_order(f)

        # Automatically return 0 if f's grade is equal to manifold dimension
        if order == self.dimension:
            return 0

        if order == 0:
            return sum([
                Differential(f)(D_x) * dx
                for (D_x, dx) in zip(self.base_vectors, self.base_oneforms)
            ])

        # If's f's grade is 1 or higher, we still need to implement this
        if order > 0:
            raise NotImplementedError(
                'Exterior derivative of forms higher order than 1 is not implemented.'
            )
예제 #7
0
r, phi, theta = symbols('r, phi, theta')
m = Manifold('M', 3)
patch = Patch('P', m)
rect = CoordSystem('rect', patch, ['x', 'y', 'z'])
polar = CoordSystem('polar', patch, ['r', 'phi', 'theta'])
polar.connect_to(
    rect, [r, phi, theta],
    [r * cos(phi) * sin(theta), r * sin(phi) * sin(theta), r * cos(theta)])
# define coordfuntions
m.x = rect.coord_function(0)
m.y = rect.coord_function(1)
m.z = rect.coord_function(2)
m.e_x = BaseVectorField(rect, 0)
m.e_y = BaseVectorField(rect, 1)
m.e_z = BaseVectorField(rect, 2)
m.dx = Differential(m.x)
m.dy = Differential(m.y)
m.dz = Differential(m.z)
omega_x = Function('omega_x')
omega_y = Function('omega_y')
omega_z = Function('omega_z')

m.r = polar.coord_function(0)
m.phi = polar.coord_function(1)
m.theta = polar.coord_function(2)
m.e_r = BaseVectorField(polar, 0)
m.e_phi = BaseVectorField(polar, 1)
m.e_theta = BaseVectorField(polar, 2)
m.dr = Differential(m.r)
m.dphi = Differential(m.phi)
m.dtheta = Differential(m.theta)
예제 #8
0
v = BaseVectorField(R2_r, 1)
pprint(v(s_field))
pprint(v(s_field).rcall(point_r).doit())
pprint(v(s_field).rcall(point_p).doit())
# Differential Examples
# scalar 0 forms
from sympy import Function
from sympy.diffgeom.rn import R2
from sympy.diffgeom import Differential
from sympy import pprint
g = Function('g')
s_field = g(R2.x, R2.y)
#Vector fields:
e_x, e_y, = R2.e_x, R2.e_y
#Differentials:
dg = Differential(s_field)
dg
pprint(dg(e_x))
pprint(dg(e_y))
# TensorProduct Examples
from sympy import Function
from sympy.diffgeom.rn import R2
from sympy.diffgeom import TensorProduct
from sympy import pprint
TensorProduct(R2.dx, R2.dy)(R2.e_x, R2.e_y)
TensorProduct(R2.dx, R2.dy)(R2.e_y, R2.e_x)
TensorProduct(R2.dx, R2.x*R2.dy)(R2.x*R2.e_x, R2.e_y)
#You can nest tensor products.
tp1 = TensorProduct(R2.dx, R2.dy)
TensorProduct(tp1, R2.dx)(R2.e_x, R2.e_y, R2.e_x)
#You can make partial contraction for instance when ‘raising an index’. Putting None in the second argument of rcall means that the respective position in the tensor product is left as it is.