chore: 添加虚拟环境到仓库
- 添加 backend_service/venv 虚拟环境 - 包含所有Python依赖包 - 注意:虚拟环境约393MB,包含12655个文件
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
from sympy.diffgeom import Manifold, Patch, CoordSystem, Point
|
||||
from sympy.core.function import Function
|
||||
from sympy.core.symbol import symbols
|
||||
from sympy.testing.pytest import warns_deprecated_sympy
|
||||
|
||||
m = Manifold('m', 2)
|
||||
p = Patch('p', m)
|
||||
a, b = symbols('a b')
|
||||
cs = CoordSystem('cs', p, [a, b])
|
||||
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(cs, [2, y])
|
||||
#TODO assert point.subs(x, 2) == Point(cs, [2, y])
|
||||
#TODO assert point.free_symbols == set([x, y])
|
||||
|
||||
def test_subs():
|
||||
assert s1.subs(s1, s2) == s2
|
||||
assert v1.subs(v1, v2) == v2
|
||||
assert f1.subs(f1, f2) == f2
|
||||
assert (x*f(s1) + y).subs(s1, s2) == x*f(s2) + y
|
||||
assert (f(s1)*v1).subs(v1, v2) == f(s1)*v2
|
||||
assert (y*f(s1)*f1).subs(f1, f2) == y*f(s1)*f2
|
||||
|
||||
def test_deprecated():
|
||||
with warns_deprecated_sympy():
|
||||
cs_wname = CoordSystem('cs', p, ['a', 'b'])
|
||||
assert cs_wname == cs_wname.func(*cs_wname.args)
|
||||
@@ -0,0 +1,342 @@
|
||||
from sympy.core import Lambda, Symbol, symbols
|
||||
from sympy.diffgeom.rn import R2, R2_p, R2_r, R3_r, R3_c, R3_s, R2_origin
|
||||
from sympy.diffgeom import (Manifold, Patch, CoordSystem, Commutator, Differential, TensorProduct,
|
||||
WedgeProduct, BaseCovarDerivativeOp, CovarDerivativeOp, LieDerivative,
|
||||
covariant_order, contravariant_order, twoform_to_matrix, metric_to_Christoffel_1st,
|
||||
metric_to_Christoffel_2nd, metric_to_Riemann_components,
|
||||
metric_to_Ricci_components, intcurve_diffequ, intcurve_series)
|
||||
from sympy.simplify import trigsimp, simplify
|
||||
from sympy.functions import sqrt, atan2, sin
|
||||
from sympy.matrices import Matrix
|
||||
from sympy.testing.pytest import raises, nocache_fail
|
||||
from sympy.testing.pytest import warns_deprecated_sympy
|
||||
|
||||
TP = TensorProduct
|
||||
|
||||
|
||||
def test_coordsys_transform():
|
||||
# test inverse transforms
|
||||
p, q, r, s = symbols('p q r s')
|
||||
rel = {('first', 'second'): [(p, q), (q, -p)]}
|
||||
R2_pq = CoordSystem('first', R2_origin, [p, q], rel)
|
||||
R2_rs = CoordSystem('second', R2_origin, [r, s], rel)
|
||||
r, s = R2_rs.symbols
|
||||
assert R2_rs.transform(R2_pq) == Matrix([[-s], [r]])
|
||||
|
||||
# inverse transform impossible case
|
||||
a, b = symbols('a b', positive=True)
|
||||
rel = {('first', 'second'): [(a,), (-a,)]}
|
||||
R2_a = CoordSystem('first', R2_origin, [a], rel)
|
||||
R2_b = CoordSystem('second', R2_origin, [b], rel)
|
||||
# This transformation is uninvertible because there is no positive a, b satisfying a = -b
|
||||
with raises(NotImplementedError):
|
||||
R2_b.transform(R2_a)
|
||||
|
||||
# inverse transform ambiguous case
|
||||
c, d = symbols('c d')
|
||||
rel = {('first', 'second'): [(c,), (c**2,)]}
|
||||
R2_c = CoordSystem('first', R2_origin, [c], rel)
|
||||
R2_d = CoordSystem('second', R2_origin, [d], rel)
|
||||
# The transform method should throw if it finds multiple inverses for a coordinate transformation.
|
||||
with raises(ValueError):
|
||||
R2_d.transform(R2_c)
|
||||
|
||||
# test indirect transformation
|
||||
a, b, c, d, e, f = symbols('a, b, c, d, e, f')
|
||||
rel = {('C1', 'C2'): [(a, b), (2*a, 3*b)],
|
||||
('C2', 'C3'): [(c, d), (3*c, 2*d)]}
|
||||
C1 = CoordSystem('C1', R2_origin, (a, b), rel)
|
||||
C2 = CoordSystem('C2', R2_origin, (c, d), rel)
|
||||
C3 = CoordSystem('C3', R2_origin, (e, f), rel)
|
||||
a, b = C1.symbols
|
||||
c, d = C2.symbols
|
||||
e, f = C3.symbols
|
||||
assert C2.transform(C1) == Matrix([c/2, d/3])
|
||||
assert C1.transform(C3) == Matrix([6*a, 6*b])
|
||||
assert C3.transform(C1) == Matrix([e/6, f/6])
|
||||
assert C3.transform(C2) == Matrix([e/3, f/2])
|
||||
|
||||
a, b, c, d, e, f = symbols('a, b, c, d, e, f')
|
||||
rel = {('C1', 'C2'): [(a, b), (2*a, 3*b + 1)],
|
||||
('C3', 'C2'): [(e, f), (-e - 2, 2*f)]}
|
||||
C1 = CoordSystem('C1', R2_origin, (a, b), rel)
|
||||
C2 = CoordSystem('C2', R2_origin, (c, d), rel)
|
||||
C3 = CoordSystem('C3', R2_origin, (e, f), rel)
|
||||
a, b = C1.symbols
|
||||
c, d = C2.symbols
|
||||
e, f = C3.symbols
|
||||
assert C2.transform(C1) == Matrix([c/2, (d - 1)/3])
|
||||
assert C1.transform(C3) == Matrix([-2*a - 2, (3*b + 1)/2])
|
||||
assert C3.transform(C1) == Matrix([-e/2 - 1, (2*f - 1)/3])
|
||||
assert C3.transform(C2) == Matrix([-e - 2, 2*f])
|
||||
|
||||
# old signature uses Lambda
|
||||
a, b, c, d, e, f = symbols('a, b, c, d, e, f')
|
||||
rel = {('C1', 'C2'): Lambda((a, b), (2*a, 3*b + 1)),
|
||||
('C3', 'C2'): Lambda((e, f), (-e - 2, 2*f))}
|
||||
C1 = CoordSystem('C1', R2_origin, (a, b), rel)
|
||||
C2 = CoordSystem('C2', R2_origin, (c, d), rel)
|
||||
C3 = CoordSystem('C3', R2_origin, (e, f), rel)
|
||||
a, b = C1.symbols
|
||||
c, d = C2.symbols
|
||||
e, f = C3.symbols
|
||||
assert C2.transform(C1) == Matrix([c/2, (d - 1)/3])
|
||||
assert C1.transform(C3) == Matrix([-2*a - 2, (3*b + 1)/2])
|
||||
assert C3.transform(C1) == Matrix([-e/2 - 1, (2*f - 1)/3])
|
||||
assert C3.transform(C2) == Matrix([-e - 2, 2*f])
|
||||
|
||||
|
||||
def test_R2():
|
||||
x0, y0, r0, theta0 = symbols('x0, y0, r0, theta0', real=True)
|
||||
point_r = R2_r.point([x0, y0])
|
||||
point_p = R2_p.point([r0, theta0])
|
||||
|
||||
# r**2 = x**2 + y**2
|
||||
assert (R2.r**2 - R2.x**2 - R2.y**2).rcall(point_r) == 0
|
||||
assert trigsimp( (R2.r**2 - R2.x**2 - R2.y**2).rcall(point_p) ) == 0
|
||||
assert trigsimp(R2.e_r(R2.x**2 + R2.y**2).rcall(point_p).doit()) == 2*r0
|
||||
|
||||
# polar->rect->polar == Id
|
||||
a, b = symbols('a b', positive=True)
|
||||
m = Matrix([[a], [b]])
|
||||
|
||||
#TODO assert m == R2_r.transform(R2_p, R2_p.transform(R2_r, [a, b])).applyfunc(simplify)
|
||||
assert m == R2_p.transform(R2_r, R2_r.transform(R2_p, m)).applyfunc(simplify)
|
||||
|
||||
# deprecated method
|
||||
with warns_deprecated_sympy():
|
||||
assert m == R2_p.coord_tuple_transform_to(
|
||||
R2_r, R2_r.coord_tuple_transform_to(R2_p, m)).applyfunc(simplify)
|
||||
|
||||
|
||||
def test_R3():
|
||||
a, b, c = symbols('a b c', positive=True)
|
||||
m = Matrix([[a], [b], [c]])
|
||||
|
||||
assert m == R3_c.transform(R3_r, R3_r.transform(R3_c, m)).applyfunc(simplify)
|
||||
#TODO assert m == R3_r.transform(R3_c, R3_c.transform(R3_r, m)).applyfunc(simplify)
|
||||
assert m == R3_s.transform(
|
||||
R3_r, R3_r.transform(R3_s, m)).applyfunc(simplify)
|
||||
#TODO assert m == R3_r.transform(R3_s, R3_s.transform(R3_r, m)).applyfunc(simplify)
|
||||
assert m == R3_s.transform(
|
||||
R3_c, R3_c.transform(R3_s, m)).applyfunc(simplify)
|
||||
#TODO assert m == R3_c.transform(R3_s, R3_s.transform(R3_c, m)).applyfunc(simplify)
|
||||
|
||||
with warns_deprecated_sympy():
|
||||
assert m == R3_c.coord_tuple_transform_to(
|
||||
R3_r, R3_r.coord_tuple_transform_to(R3_c, m)).applyfunc(simplify)
|
||||
#TODO assert m == R3_r.coord_tuple_transform_to(R3_c, R3_c.coord_tuple_transform_to(R3_r, m)).applyfunc(simplify)
|
||||
assert m == R3_s.coord_tuple_transform_to(
|
||||
R3_r, R3_r.coord_tuple_transform_to(R3_s, m)).applyfunc(simplify)
|
||||
#TODO assert m == R3_r.coord_tuple_transform_to(R3_s, R3_s.coord_tuple_transform_to(R3_r, m)).applyfunc(simplify)
|
||||
assert m == R3_s.coord_tuple_transform_to(
|
||||
R3_c, R3_c.coord_tuple_transform_to(R3_s, m)).applyfunc(simplify)
|
||||
#TODO assert m == R3_c.coord_tuple_transform_to(R3_s, R3_s.coord_tuple_transform_to(R3_c, m)).applyfunc(simplify)
|
||||
|
||||
|
||||
def test_CoordinateSymbol():
|
||||
x, y = R2_r.symbols
|
||||
r, theta = R2_p.symbols
|
||||
assert y.rewrite(R2_p) == r*sin(theta)
|
||||
|
||||
|
||||
def test_point():
|
||||
x, y = symbols('x, y')
|
||||
p = R2_r.point([x, y])
|
||||
assert p.free_symbols == {x, y}
|
||||
assert p.coords(R2_r) == p.coords() == Matrix([x, y])
|
||||
assert p.coords(R2_p) == Matrix([sqrt(x**2 + y**2), atan2(y, x)])
|
||||
|
||||
|
||||
def test_commutator():
|
||||
assert Commutator(R2.e_x, R2.e_y) == 0
|
||||
assert Commutator(R2.x*R2.e_x, R2.x*R2.e_x) == 0
|
||||
assert Commutator(R2.x*R2.e_x, R2.x*R2.e_y) == R2.x*R2.e_y
|
||||
c = Commutator(R2.e_x, R2.e_r)
|
||||
assert c(R2.x) == R2.y*(R2.x**2 + R2.y**2)**(-1)*sin(R2.theta)
|
||||
|
||||
|
||||
def test_differential():
|
||||
xdy = R2.x*R2.dy
|
||||
dxdy = Differential(xdy)
|
||||
assert xdy.rcall(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
|
||||
|
||||
|
||||
def test_products():
|
||||
assert TensorProduct(
|
||||
R2.dx, R2.dy)(R2.e_x, R2.e_y) == R2.dx(R2.e_x)*R2.dy(R2.e_y) == 1
|
||||
assert TensorProduct(R2.dx, R2.dy)(None, R2.e_y) == R2.dx
|
||||
assert TensorProduct(R2.dx, R2.dy)(R2.e_x, None) == R2.dy
|
||||
assert TensorProduct(R2.dx, R2.dy)(R2.e_x) == R2.dy
|
||||
assert TensorProduct(R2.x, R2.dx) == R2.x*R2.dx
|
||||
assert TensorProduct(
|
||||
R2.e_x, R2.e_y)(R2.x, R2.y) == R2.e_x(R2.x) * R2.e_y(R2.y) == 1
|
||||
assert TensorProduct(R2.e_x, R2.e_y)(None, R2.y) == R2.e_x
|
||||
assert TensorProduct(R2.e_x, R2.e_y)(R2.x, None) == R2.e_y
|
||||
assert TensorProduct(R2.e_x, R2.e_y)(R2.x) == R2.e_y
|
||||
assert TensorProduct(R2.x, R2.e_x) == R2.x * R2.e_x
|
||||
assert TensorProduct(
|
||||
R2.dx, R2.e_y)(R2.e_x, R2.y) == R2.dx(R2.e_x) * R2.e_y(R2.y) == 1
|
||||
assert TensorProduct(R2.dx, R2.e_y)(None, R2.y) == R2.dx
|
||||
assert TensorProduct(R2.dx, R2.e_y)(R2.e_x, None) == R2.e_y
|
||||
assert TensorProduct(R2.dx, R2.e_y)(R2.e_x) == R2.e_y
|
||||
assert TensorProduct(R2.x, R2.e_x) == R2.x * R2.e_x
|
||||
assert TensorProduct(
|
||||
R2.e_x, R2.dy)(R2.x, R2.e_y) == R2.e_x(R2.x) * R2.dy(R2.e_y) == 1
|
||||
assert TensorProduct(R2.e_x, R2.dy)(None, R2.e_y) == R2.e_x
|
||||
assert TensorProduct(R2.e_x, R2.dy)(R2.x, None) == R2.dy
|
||||
assert TensorProduct(R2.e_x, R2.dy)(R2.x) == R2.dy
|
||||
assert TensorProduct(R2.e_y,R2.e_x)(R2.x**2 + R2.y**2,R2.x**2 + R2.y**2) == 4*R2.x*R2.y
|
||||
|
||||
assert WedgeProduct(R2.dx, R2.dy)(R2.e_x, R2.e_y) == 1
|
||||
assert WedgeProduct(R2.e_x, R2.e_y)(R2.x, R2.y) == 1
|
||||
|
||||
|
||||
def test_lie_derivative():
|
||||
assert LieDerivative(R2.e_x, R2.y) == R2.e_x(R2.y) == 0
|
||||
assert LieDerivative(R2.e_x, R2.x) == R2.e_x(R2.x) == 1
|
||||
assert LieDerivative(R2.e_x, R2.e_x) == Commutator(R2.e_x, R2.e_x) == 0
|
||||
assert LieDerivative(R2.e_x, R2.e_r) == Commutator(R2.e_x, R2.e_r)
|
||||
assert LieDerivative(R2.e_x + R2.e_y, R2.x) == 1
|
||||
assert LieDerivative(
|
||||
R2.e_x, TensorProduct(R2.dx, R2.dy))(R2.e_x, R2.e_y) == 0
|
||||
|
||||
|
||||
@nocache_fail
|
||||
def test_covar_deriv():
|
||||
ch = metric_to_Christoffel_2nd(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
|
||||
cvd = BaseCovarDerivativeOp(R2_r, 0, ch)
|
||||
assert cvd(R2.x) == 1
|
||||
# This line fails if the cache is disabled:
|
||||
assert cvd(R2.x*R2.e_x) == R2.e_x
|
||||
cvd = CovarDerivativeOp(R2.x*R2.e_x, ch)
|
||||
assert cvd(R2.x) == R2.x
|
||||
assert cvd(R2.x*R2.e_x) == R2.x*R2.e_x
|
||||
|
||||
|
||||
def test_intcurve_diffequ():
|
||||
t = symbols('t')
|
||||
start_point = R2_r.point([1, 0])
|
||||
vector_field = -R2.y*R2.e_x + R2.x*R2.e_y
|
||||
equations, init_cond = intcurve_diffequ(vector_field, t, start_point)
|
||||
assert str(equations) == '[f_1(t) + Derivative(f_0(t), t), -f_0(t) + Derivative(f_1(t), t)]'
|
||||
assert str(init_cond) == '[f_0(0) - 1, f_1(0)]'
|
||||
equations, init_cond = intcurve_diffequ(vector_field, t, start_point, R2_p)
|
||||
assert str(
|
||||
equations) == '[Derivative(f_0(t), t), Derivative(f_1(t), t) - 1]'
|
||||
assert str(init_cond) == '[f_0(0) - 1, f_1(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_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: 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))
|
||||
|
||||
def test_simplify():
|
||||
x, y = R2_r.coord_functions()
|
||||
dx, dy = R2_r.base_oneforms()
|
||||
ex, ey = R2_r.base_vectors()
|
||||
assert simplify(x) == x
|
||||
assert simplify(x*y) == x*y
|
||||
assert simplify(dx*dy) == dx*dy
|
||||
assert simplify(ex*ey) == ex*ey
|
||||
assert ((1-x)*dx)/(1-x)**2 == dx/(1-x)
|
||||
|
||||
|
||||
def test_issue_17917():
|
||||
X = R2.x*R2.e_x - R2.y*R2.e_y
|
||||
Y = (R2.x**2 + R2.y**2)*R2.e_x - R2.x*R2.y*R2.e_y
|
||||
assert LieDerivative(X, Y).expand() == (
|
||||
R2.x**2*R2.e_x - 3*R2.y**2*R2.e_x - R2.x*R2.y*R2.e_y)
|
||||
|
||||
def test_deprecations():
|
||||
m = Manifold('M', 2)
|
||||
p = Patch('P', m)
|
||||
with warns_deprecated_sympy():
|
||||
CoordSystem('Car2d', p, names=['x', 'y'])
|
||||
|
||||
with warns_deprecated_sympy():
|
||||
c = CoordSystem('Car2d', p, ['x', 'y'])
|
||||
|
||||
with warns_deprecated_sympy():
|
||||
list(m.patches)
|
||||
|
||||
with warns_deprecated_sympy():
|
||||
list(c.transforms)
|
||||
@@ -0,0 +1,145 @@
|
||||
from sympy.diffgeom.rn import R2, R2_p, R2_r, R3_r
|
||||
from sympy.diffgeom import intcurve_series, Differential, WedgeProduct
|
||||
from sympy.core import symbols, Function, Derivative
|
||||
from sympy.simplify import trigsimp, simplify
|
||||
from sympy.functions import sqrt, atan2, sin, cos
|
||||
from sympy.matrices import Matrix
|
||||
|
||||
# Most of the functionality is covered in the
|
||||
# test_functional_diffgeom_ch* tests which are based on the
|
||||
# example from the paper of Sussman and Wisdom.
|
||||
# If they do not cover something, additional tests are added in other test
|
||||
# functions.
|
||||
|
||||
# From "Functional Differential Geometry" as of 2011
|
||||
# by Sussman and Wisdom.
|
||||
|
||||
|
||||
def test_functional_diffgeom_ch2():
|
||||
x0, y0, r0, theta0 = symbols('x0, y0, r0, theta0', real=True)
|
||||
x, y = symbols('x, y', real=True)
|
||||
f = Function('f')
|
||||
|
||||
assert (R2_p.point_to_coords(R2_r.point([x0, y0])) ==
|
||||
Matrix([sqrt(x0**2 + y0**2), atan2(y0, x0)]))
|
||||
assert (R2_r.point_to_coords(R2_p.point([r0, theta0])) ==
|
||||
Matrix([r0*cos(theta0), r0*sin(theta0)]))
|
||||
|
||||
assert R2_p.jacobian(R2_r, [r0, theta0]) == Matrix(
|
||||
[[cos(theta0), -r0*sin(theta0)], [sin(theta0), r0*cos(theta0)]])
|
||||
|
||||
field = f(R2.x, R2.y)
|
||||
p1_in_rect = R2_r.point([x0, y0])
|
||||
p1_in_polar = R2_p.point([sqrt(x0**2 + y0**2), atan2(y0, x0)])
|
||||
assert field.rcall(p1_in_rect) == f(x0, y0)
|
||||
assert field.rcall(p1_in_polar) == f(x0, y0)
|
||||
|
||||
p_r = R2_r.point([x0, y0])
|
||||
p_p = R2_p.point([r0, theta0])
|
||||
assert R2.x(p_r) == x0
|
||||
assert R2.x(p_p) == r0*cos(theta0)
|
||||
assert R2.r(p_p) == r0
|
||||
assert R2.r(p_r) == sqrt(x0**2 + y0**2)
|
||||
assert R2.theta(p_r) == atan2(y0, x0)
|
||||
|
||||
h = R2.x*R2.r**2 + R2.y**3
|
||||
assert h.rcall(p_r) == x0*(x0**2 + y0**2) + y0**3
|
||||
assert h.rcall(p_p) == r0**3*sin(theta0)**3 + r0**3*cos(theta0)
|
||||
|
||||
|
||||
def test_functional_diffgeom_ch3():
|
||||
x0, y0 = symbols('x0, y0', real=True)
|
||||
x, y, t = symbols('x, y, t', real=True)
|
||||
f = Function('f')
|
||||
b1 = Function('b1')
|
||||
b2 = Function('b2')
|
||||
p_r = R2_r.point([x0, y0])
|
||||
|
||||
s_field = f(R2.x, R2.y)
|
||||
v_field = b1(R2.x)*R2.e_x + b2(R2.y)*R2.e_y
|
||||
assert v_field.rcall(s_field).rcall(p_r).doit() == b1(
|
||||
x0)*Derivative(f(x0, y0), x0) + b2(y0)*Derivative(f(x0, y0), y0)
|
||||
|
||||
assert R2.e_x(R2.r**2).rcall(p_r) == 2*x0
|
||||
v = R2.e_x + 2*R2.e_y
|
||||
s = R2.r**2 + 3*R2.x
|
||||
assert v.rcall(s).rcall(p_r).doit() == 2*x0 + 4*y0 + 3
|
||||
|
||||
circ = -R2.y*R2.e_x + R2.x*R2.e_y
|
||||
series = intcurve_series(circ, t, R2_r.point([1, 0]), coeffs=True)
|
||||
series_x, series_y = zip(*series)
|
||||
assert all(
|
||||
term == cos(t).taylor_term(i, t) for i, term in enumerate(series_x))
|
||||
assert all(
|
||||
term == sin(t).taylor_term(i, t) for i, term in enumerate(series_y))
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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.rcall(R3_r.e_x, R3_r.e_y) == 0
|
||||
@@ -0,0 +1,91 @@
|
||||
r'''
|
||||
unit test describing the hyperbolic half-plane with the Poincare metric. This
|
||||
is a basic model of hyperbolic geometry on the (positive) half-space
|
||||
|
||||
{(x,y) \in R^2 | y > 0}
|
||||
|
||||
with the Riemannian metric
|
||||
|
||||
ds^2 = (dx^2 + dy^2)/y^2
|
||||
|
||||
It has constant negative scalar curvature = -2
|
||||
|
||||
https://en.wikipedia.org/wiki/Poincare_half-plane_model
|
||||
'''
|
||||
from sympy.matrices.dense import diag
|
||||
from sympy.diffgeom import (twoform_to_matrix,
|
||||
metric_to_Christoffel_1st, metric_to_Christoffel_2nd,
|
||||
metric_to_Riemann_components, metric_to_Ricci_components)
|
||||
import sympy.diffgeom.rn
|
||||
from sympy.tensor.array import ImmutableDenseNDimArray
|
||||
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user