Beispiel #1
0
    def test_left_mul_by_2(self):
        x1, x2, x3 = xx = st.symb_vector('x1:4', commutative=False)
        xdot1, xdot2, xdot3 = xxdot = st.time_deriv(xx, xx)
        xddot1, xddot2, xddot3 = xxddot = st.time_deriv(xxdot, xxdot)

        XX = st.row_stack(xx, xxdot, xxddot)

        C = sp.Symbol('C', commutative=False)

        Q = sp.Matrix([[x3 / sin(x1), 1, 0], [-tan(x1), 0, x3]])
        Q_ = st.col_stack(Q, sp.zeros(2, 6))

        # matrix independent of s
        M2 = sp.Matrix([[1, 0], [-C, 1]])

        # 1-forms
        w1 = pc.DifferentialForm(1, XX, coeff=Q_[0, :])
        w2 = pc.DifferentialForm(1, XX, coeff=Q_[1, :])

        # vector 1-form
        w = pc.VectorDifferentialForm(1, XX, coeff=Q_)

        t = w.left_mul_by(M2, additional_symbols=[C])
        # object to compare with:
        t2 = -C * w1 + w2

        self.assertEqual(t2.coeff, t.coeff.row(1).T)
Beispiel #2
0
    def test_left_mul_by_1(self):
        x1, x2, x3 = xx = st.symb_vector('x1:4', commutative=False)
        xdot1, xdot2, xdot3 = xxdot = st.time_deriv(xx, xx)
        xddot1, xddot2, xddot3 = xxddot = st.time_deriv(xxdot, xxdot)

        XX = st.row_stack(xx, xxdot, xxddot)

        s = sp.Symbol('s', commutative=False)
        C = sp.Symbol('C', commutative=False)

        Q = sp.Matrix([[x3 / sin(x1), 1, 0], [-tan(x1), 0, x3]])
        Q_ = st.col_stack(Q, sp.zeros(2, 6))

        # s-dependent matrix
        M1 = sp.Matrix([[1, 0], [-C * s, 1]])

        # 1-forms
        w1 = pc.DifferentialForm(1, XX, coeff=Q_[0, :])
        w2 = pc.DifferentialForm(1, XX, coeff=Q_[1, :])

        # vector 1-form
        w = pc.VectorDifferentialForm(1, XX, coeff=Q_)

        t = w.left_mul_by(M1, s, [C])
        t2 = -C * w1.dot() + w2

        self.assertEqual(t2.coeff, t.coeff.row(1).T)
Beispiel #3
0
    def test_mul(self):
        x1, x2, x3 = xx = st.symb_vector('x1:4', commutative=False)

        s = sp.Symbol('s', commutative=False)
        C = sp.Symbol('C', commutative=False)

        Q = sp.Matrix([[x3 / sin(x1), 1, 0], [-tan(x1), 0, x3]])

        W = pc.VectorDifferentialForm(1, xx, coeff=Q)

        W1 = s * W

        W2 = W * C

        self.assertEqual(W1.coeff, nct.nc_mul(s, W.coeff))
        self.assertNotEqual(W1.coeff, nct.nc_mul(W.coeff, s))

        self.assertEqual(W2.coeff, nct.nc_mul(W.coeff, C))
        self.assertNotEqual(W2.coeff, nct.nc_mul(C, W.coeff))

        alpha = pc.DifferentialForm(1, xx)
        with self.assertRaises(TypeError) as cm:
            alpha * W1
        with self.assertRaises(TypeError) as cm:
            W1 * alpha

        M = sp.eye(2)
        with self.assertRaises(sp.SympifyError) as cm:
            M * W1
        with self.assertRaises(TypeError) as cm:
            W1 * M
Beispiel #4
0
    def test_vector_form_append(self):
        x1, x2, x3 = xx = st.symb_vector('x1:4', commutative=False)
        xdot1, xdot2, xdot3 = xxdot = st.time_deriv(xx, xx)
        xddot1, xddot2, xddot3 = xxddot = st.time_deriv(xxdot, xxdot)

        XX = st.row_stack(xx, xxdot, xxddot)

        s = sp.Symbol('s', commutative=False)
        C = sp.Symbol('C', commutative=False)

        # vector 1-form
        Q = sp.Matrix([[x3 / sin(x1), 1, 0], [-tan(x1), 0, x3]])

        Q_ = st.col_stack(Q, sp.zeros(2, 6))
        w = pc.VectorDifferentialForm(1, XX, coeff=Q_)

        # 1-forms
        Q2 = sp.Matrix([[x1, x2, x3]])

        Q2_ = st.col_stack(Q2, sp.zeros(1, 6))
        w2 = pc.DifferentialForm(1, XX, coeff=Q2_[0, :])

        w.append(w2)

        # vector form to compare with:
        B = sp.Matrix([[x3 / sin(x1), 1, 0], [-tan(x1), 0, x3], [x1, x2, x3]])

        B_ = st.col_stack(B, sp.zeros(3, 6))
        b = pc.VectorDifferentialForm(1, XX, coeff=B_)

        self.assertEqual(w.coeff, b.coeff)
Beispiel #5
0
    def test_wedge_product1(self):

        dx1, dx2, dx3, dx4, dx5 = self.dx
        self.assertEqual(dx1 ^ dx2, dx1.wp(dx2))
        self.assertEqual(dx5 ^ dx2, -dx2 ^ dx5)
        self.assertEqual((dx5 ^ dx2 ^ dx1).degree, 3)
        zero4_form = pc.DifferentialForm(4, self.xx)
        self.assertEqual((dx5 ^ dx2 ^ dx1 ^ dx5), zero4_form)
        self.assertFalse(any((dx4 ^ dx4).coeff))
Beispiel #6
0
    def test_stack_to_vector_form(self):
        x1, x2, x3 = xx = st.symb_vector('x1:4', commutative=False)
        xdot1, xdot2, xdot3 = xxdot = st.time_deriv(xx, xx)
        xddot1, xddot2, xddot3 = xxddot = st.time_deriv(xxdot, xxdot)

        XX = st.row_stack(xx, xxdot, xxddot)

        Q = sp.Matrix([[x3 / sin(x1), 1, 0], [-tan(x1), 0, x3]])
        Q_ = st.col_stack(Q, sp.zeros(2, 6))

        # 1-forms
        w1 = pc.DifferentialForm(1, XX, coeff=Q_[0, :])
        w2 = pc.DifferentialForm(1, XX, coeff=Q_[1, :])
        w_stacked = pc.stack_to_vector_form(w1, w2)

        # vector 1-form
        w = pc.VectorDifferentialForm(1, XX, coeff=Q_)

        self.assertEqual(w.coeff, w_stacked.coeff)
Beispiel #7
0
    def test_vector_k_form(self):
        x1, x2, x3 = xx = st.symb_vector('x1:4')
        xdot1, xdot2, xdot3 = xxdot = st.time_deriv(xx, xx)
        xddot1, xddot2, xddot3 = xxddot = st.time_deriv(xxdot, xxdot)

        XX = st.row_stack(xx, xxdot, xxddot)

        Q = sp.Matrix([[x3 / sin(x1), 1, 0], [-tan(x1), 0, x3]])
        Q_ = st.col_stack(Q, sp.zeros(2, 6))

        w1 = pc.DifferentialForm(1, XX, coeff=Q_[0, :])
        w2 = pc.DifferentialForm(1, XX, coeff=Q_[1, :])

        w = pc.VectorDifferentialForm(1, XX, coeff=Q_)
        w1_tilde = w.get_differential_form(0)
        self.assertEqual(w1.coeff, w1_tilde.coeff)

        w2_tilde = w.get_differential_form(1)
        self.assertEqual(w2.coeff, w2_tilde.coeff)
Beispiel #8
0
    def test_wedge_product2(self):
        # here we test the `*` operator which was extended to DifferentialForms
        # after `^`

        x1, x2, x3, x4, x5 = self.xx
        dx1, dx2, dx3, dx4, dx5 = self.dx
        self.assertEqual(dx1 * dx2, dx1.wp(dx2))
        self.assertEqual(dx5 * dx2, -dx2 ^ dx5)
        self.assertEqual((dx5 * dx2 * dx1).degree, 3)

        # commutativity with scalar functions
        self.assertEqual(dx5 * x2 * x3 * 10 * dx2 * dx1 * x1,
                         x2 * x3 * 10 * x1 * dx5 ^ dx2 ^ dx1)

        zero4_form = pc.DifferentialForm(4, self.xx)
        self.assertEqual((dx5 * dx2 * dx1 * dx5), zero4_form)
        self.assertFalse(any((dx4 * dx4).coeff))
Beispiel #9
0
    def test_dot(self):
        x1, x2, x3 = xx = sp.Matrix(sp.symbols("x1, x2, x3"))
        xdot1, xdot2, xdot3 = xxd = pc.st.time_deriv(xx, xx)
        xx_tmp, ddx = pc.setup_objects(xx)
        dx1, dx2, dx3 = ddx

        full_basis = list(xx) + list(xxd)
        dxdot2 = pc.DifferentialForm(1, full_basis, [0, 0, 0, 0, 1, 0])

        w1 = x3 * dx2
        with self.assertRaises(ValueError) as cm:
            w1.dot()

        w1.jet_extend_basis()
        dx2.jet_extend_basis()
        wdot1 = w1.dot()

        self.assertEqual(wdot1, xdot3 * dx2 + x3 * dxdot2)
Beispiel #10
0
    def test_calculation_a(self):
        xx = st.symb_vector('x1:6')

        dx1 = pc.DifferentialForm(1, xx, coeff=[1, 0, 0, 0, 0])