def test_correct_arguments(): pytest.raises(ValueError, lambda: R2.e_x(R2.e_x)) pytest.raises(ValueError, lambda: R2.e_x(R2.dx)) pytest.raises(ValueError, lambda: Commutator(R2.e_x, R2.x)) pytest.raises(ValueError, lambda: Commutator(R2.dx, R2.e_x)) pytest.raises(ValueError, lambda: Differential(Differential(R2.e_x))) pytest.raises(ValueError, lambda: R2.dx(R2.x)) pytest.raises(ValueError, lambda: TensorProduct(R2.e_x, R2.dx)) pytest.raises(ValueError, lambda: LieDerivative(R2.dx, R2.dx)) pytest.raises(ValueError, lambda: LieDerivative(R2.x, R2.dx)) pytest.raises(ValueError, lambda: CovarDerivativeOp(R2.dx, [])) pytest.raises(ValueError, lambda: CovarDerivativeOp(R2.x, [])) a = Symbol('a') pytest.raises(ValueError, lambda: intcurve_series(R2.dx, a, R2_r.point([1, 2]))) pytest.raises(ValueError, lambda: intcurve_series(R2.x, a, R2_r.point([1, 2]))) pytest.raises(ValueError, lambda: intcurve_diffequ(R2.dx, a, R2_r.point([1, 2]))) pytest.raises(ValueError, lambda: intcurve_diffequ(R2.x, a, R2_r.point([1, 2]))) pytest.raises(ValueError, lambda: contravariant_order(R2.e_x + R2.dx)) pytest.raises(ValueError, lambda: contravariant_order(R2.dx**2)) pytest.raises(ValueError, lambda: covariant_order(R2.e_x + R2.dx)) pytest.raises(ValueError, lambda: contravariant_order(R2.e_x*R2.e_y)) pytest.raises(ValueError, lambda: covariant_order(R2.dx*R2.dy)) assert covariant_order(Integer(0), True) == -1 assert contravariant_order(Integer(0), True) == -1
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 WedgeProduct(R2.dx, R2.dy)(R2.e_x, 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
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 WedgeProduct(R2.dx, R2.dy)(R2.e_x, 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
def test_functional_diffgeom_ch4(): x0, y0, theta0 = symbols('x0, y0, theta0', extended_real=True) x, y, r, theta = symbols('x, y, r, theta', extended_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_ch4(): x0, y0, theta0 = symbols('x0, y0, theta0', extended_real=True) x, y, r, theta = symbols('x, y, r, theta', extended_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