Esempio n. 1
0
print '#Tensors on the Unit Sphere'

print 'V =', V
#print 'T =', T
T.Fmt(5,'T')
print '#Tensor Contraction'
print r'T[1,2] =', T.contract(1,2)
print '#Tensor Evaluation'
print r'T(a,b) =', T(a,b)
print r'T(a,b+c) =', T(a,b+c).expand()
print r'T(a,\alpha b) =', T(a,alpha*b)
print '#Geometric Derivative With Respect To Slot'
print r'\nabla_{a_{1}}T =',T.pdiff(1)
print r'\nabla_{a_{2}}T =',T.pdiff(2)
print '#Covariant Derivatives'
print r'\mathcal{D}V =', V.cderiv()
DT = T.cderiv()
#print r'\mathcal{D}T =', DT
DT.Fmt(3,r'\mathcal{D}T')
print r'\mathcal{D}T[1,3](a) =', (DT.contract(1,3))(a)

#Define curve on unit sphere manifold

us = Function('u__s')(s)
vs = Function('v__s')(s)

#Define 1-d submanifold on unit shpere manifold

crv1d = sph2d.sm([us,vs],[s])

(es,) = crv1d.mv()
Esempio n. 2
0
def test_submanifolds():

    #Define spherical coordinate system in 3-d

    coords = (r, th, phi) = symbols('r,theta,phi', real=True)

    sp3d = Ga('e_r e_th e_ph', g=[1, r**2, r**2*sin(th)**2], coords=coords)
    (er, eth, ephi) = sp3d.mv()

    #Define coordinates for 2-d (u,v) and 1-d (s) manifolds

    u,v,s,alpha = symbols('u v s alpha',real=True)

    sub_coords = (u,v)

    smap = [1, u, v]  # Coordinate map for sphere of r = 1 in 3-d

    #Define unit sphere manifold

    sph2d = sp3d.sm(smap,sub_coords)
    (eu,ev) = sph2d.mv()

    #Define vector and vector field on unit sphere tangent space

    a = sph2d.mv('a','vector')
    b = sph2d.mv('b','vector')
    c = sph2d.mv('c','vector')
    f = sph2d.mv('f','vector',f=True)

    #Define directional derivative in direction a for unit sphere manifold

    dd = a|sph2d.grad

    assert str(dd) == 'a__u*D{u} + a__v*D{v}'
    assert str(dd * eu) == 'a__v*e_v/tan(u)'
    assert str(dd * ev) == '-a__v*sin(2*u)*e_u/2 + a__u*e_v/tan(u)'
    assert str(dd * f) == '(a__u*D{u}f__u - a__v*f__v*sin(2*u)/2 + a__v*D{v}f__u)*e_u + (a__u*f__v/tan(u) + a__u*D{u}f__v + a__v*f__u/tan(u) + a__v*D{v}f__v)*e_v'

    V = Mlt('V',sph2d,nargs=1,fct=True)
    T = Mlt('T',sph2d,nargs=2,fct=True)

    assert str(T.contract(1,2)) == 'a_1__u**2*D{u}^2T_uu + a_1__u**2*D{v}^2T_uu/sin(u)**2 + a_1__u*a_1__v*D{u}^2T_uv + a_1__u*a_1__v*D{u}^2T_vu + a_1__u*a_1__v*D{v}^2T_uv/sin(u)**2 + a_1__u*a_1__v*D{v}^2T_vu/sin(u)**2 + a_1__v**2*D{u}^2T_vv + a_1__v**2*D{v}^2T_vv/sin(u)**2'

    #Tensor Evaluation

    assert str(T(a,b)) == 'a__u*b__u*T_uu + a__u*b__v*T_uv + a__v*b__u*T_vu + a__v*b__v*T_vv'
    assert str(T(a,b+c).expand()) == 'a__u*b__u*T_uu + a__u*b__v*T_uv + a__u*c__u*T_uu + a__u*c__v*T_uv + a__v*b__u*T_vu + a__v*b__v*T_vv + a__v*c__u*T_vu + a__v*c__v*T_vv'
    assert str(T(a,alpha*b)) == 'a__u*alpha*b__u*T_uu + a__u*alpha*b__v*T_uv + a__v*alpha*b__u*T_vu + a__v*alpha*b__v*T_vv'

    #Geometric Derivative With Respect To Slot

    assert str(T.pdiff(1)) == '(a_1__u*a_2__u*D{u}T_uu + a_1__u*a_2__v*D{u}T_uv + a_1__v*a_2__u*D{u}T_vu + a_1__v*a_2__v*D{u}T_vv)*e_u + (a_1__u*a_2__u*D{v}T_uu + a_1__u*a_2__v*D{v}T_uv + a_1__v*a_2__u*D{v}T_vu + a_1__v*a_2__v*D{v}T_vv)*e_v/sin(u)**2'
    assert str(T.pdiff(2)) == '(a_1__u*a_2__u*D{u}T_uu + a_1__u*a_2__v*D{u}T_uv + a_1__v*a_2__u*D{u}T_vu + a_1__v*a_2__v*D{u}T_vv)*e_u + (a_1__u*a_2__u*D{v}T_uu + a_1__u*a_2__v*D{v}T_uv + a_1__v*a_2__u*D{v}T_vu + a_1__v*a_2__v*D{v}T_vv)*e_v/sin(u)**2'

    #Covariant Derivatives

    assert str(V.cderiv()) == 'a_2__u*(a_1__u*D{u}V_u + a_1__v*D{u}V_v) + a_2__v*(a_1__u*D{v}V_u + a_1__v*D{v}V_v)'

    DT = T.cderiv()

    assert str(DT) == 'a_3__u*(a_1__u*a_2__u*D{u}T_uu + a_1__u*a_2__v*D{u}T_uv + a_1__v*a_2__u*D{u}T_vu + a_1__v*a_2__v*D{u}T_vv) + a_3__v*(a_1__u*a_2__u*D{v}T_uu + a_1__u*a_2__v*D{v}T_uv + a_1__v*a_2__u*D{v}T_vu + a_1__v*a_2__v*D{v}T_vv)'

    #Define curve on unit sphere manifold

    us = Function('u__s')(s)
    vs = Function('v__s')(s)

    #Define 1-d submanifold on unit shpere manifold

    crv1d = sph2d.sm([us,vs],[s])

    (es,) = crv1d.mv()

    #1-D Manifold On Unit Sphere:

    assert str(crv1d.grad) == 'e_s*1/(sin(u__s)**2*D{s}v__s**2 + D{s}u__s**2)*D{s}'

    #Define scalar and vector fields on 1-d manifold tangent space

    g = crv1d.mv('g','scalar',f=True)
    h = crv1d.mv('h','vector',f=True)

    assert str(crv1d.grad * g) == 'D{s}g*e_s/(sin(u__s)**2*D{s}v__s**2 + D{s}u__s**2)'
    assert str(crv1d.grad | h) == 'D{s}h__s + h__s*sin(u__s)**2*D{s}v__s*D{s}^2v__s/(sin(u__s)**2*D{s}v__s**2 + D{s}u__s**2) + h__s*sin(2*u__s)*D{s}u__s*D{s}v__s**2/(2*(sin(u__s)**2*D{s}v__s**2 + D{s}u__s**2)) + h__s*D{s}u__s*D{s}^2u__s/(sin(u__s)**2*D{s}v__s**2 + D{s}u__s**2)'

    return