Пример #1
0
    def test_pickle_full_dump_and_load3(self):
        """
        Test for correct handling of assumptions
        """

        xx = st.symb_vector("x1, x2, x3")
        xdot1, xdot2, xdot3 = xxd = st.time_deriv(xx, xx)

        y1, y2, y3 = yy = st.symb_vector("y1, y2, y3")
        yyd = st.time_deriv(yy, yy)
        yydd = st.time_deriv(yy, yy, order=2)
        s_nc = sp.Symbol('s', commutative=False)
        sk_nc = sp.Symbol('sk', commutative=False)
        s_c = sp.Symbol('s')

        pdata1 = st.Container()
        pdata1.s1 = sk_nc  # different names
        pdata1.s2 = s_c
        pdata1.xx = xx

        pdata2 = st.Container()
        pdata2.s1 = s_nc  # same names
        pdata2.s2 = s_c
        pdata2.xx = xx

        pfname = "tmp_dump_test.pcl"

        # this should pass
        st.pickle_full_dump(pdata1, pfname)

        with self.assertRaises(ValueError) as cm:
            st.pickle_full_dump(pdata2, pfname)

        os.remove(pfname)
Пример #2
0
    def test_pickle_full_dump_and_load2(self):
        """
        Test with non-sympy object
        """

        xx = st.symb_vector("x1, x2, x3")
        xdot1, xdot2, xdot3 = xxd = st.time_deriv(xx, xx)

        y1, y2, y3 = yy = st.symb_vector("y1, y2, y3")
        yyd = st.time_deriv(yy, yy)
        yydd = st.time_deriv(yy, yy, order=2)

        pdata = st.Container()

        pdata.z1 = yy
        pdata.z2 = sin(yyd[2])
        pdata.z3 = yydd
        pdata.abc = xxd

        pfname = "tmp_dump_test.pcl"
        st.pickle_full_dump(pdata, pfname)

        self.assertEqual(xdot1.difforder, 1)
        self.assertEqual(yydd[1].difforder, 2)

        # forget all difforder attributes
        st.init_attribute_store(reinit=True)

        self.assertEqual(xdot1.difforder, 0)
        self.assertEqual(yydd[1].difforder, 0)
        del xdot1, xdot2, xdot3, xxd, yydd, pdata

        pdata = st.pickle_full_load(pfname)
        xdot1, xdot2, xdot3 = xxd = pdata.abc
        yydd_new = pdata.z3

        self.assertEqual(xdot1.difforder, 1)
        self.assertEqual(yydd_new[1].difforder, 2)

        with self.assertRaises(TypeError) as cm:
            st.pickle_full_dump([], pfname)
        with self.assertRaises(TypeError) as cm:
            st.pickle_full_dump(xdot1, pfname)
        with self.assertRaises(TypeError) as cm:
            st.pickle_full_dump(st.Container, pfname)

        os.remove(pfname)
Пример #3
0
    def test_pickle_full_dump_and_load(self):

        xx = st.symb_vector("x1, x2, x3")
        xdot1, xdot2, xdot3 = xxd = st.time_deriv(xx, xx)

        y1, y2, y3 = yy = st.symb_vector("y1, y2, y3")
        yyd = st.time_deriv(yy, yy)
        yydd = st.time_deriv(yy, yy, order=2)

        # add custom information to data container
        xxd.data = st.Container()

        xxd.data.z1 = yy
        xxd.data.z2 = sin(yyd[2])
        xxd.data.z3 = yydd

        pfname = "tmp_dump_test.pcl"
        st.pickle_full_dump(xxd, pfname)

        self.assertEqual(xdot1.difforder, 1)
        self.assertEqual(yydd[1].difforder, 2)

        # store assumptions to compare them later
        y1_assumptions = y1.assumptions0

        # forget all difforder attributes
        st.init_attribute_store(reinit=True)

        self.assertEqual(xdot1.difforder, 0)
        self.assertEqual(yydd[1].difforder, 0)
        del xdot1, xdot2, xdot3, xxd, yydd

        xdot1, xdot2, xdot3 = xxd = st.pickle_full_load(pfname)
        yydd_new = xxd.data.z3

        self.assertEqual(xdot1.difforder, 1)
        self.assertEqual(yydd_new[1].difforder, 2)

        new_y1_assumptions = xxd.data.z1[0].assumptions0
        self.assertEqual(new_y1_assumptions, y1_assumptions)

        os.remove(pfname)
Пример #4
0
# -*- coding: utf-8 -*-

from functools import partial
import sympy as sp
import symbtools as st
from symbtools import lzip
"""
Collection of Code for noncommutative calculations ("s = d/dt")
"""

gC = st.Container()  # global Container
t = gC.t = sp.Symbol('t', commutative=False)  # time
s = gC.s = sp.Symbol('s', commutative=False)  # "Laplace-Variable" (d/dt)


def apply_deriv(term, power, s, t, func_symbols=[]):
    res = 0
    assert int(power) == power
    if power == 0:
        return term

    if isinstance(term, sp.Add):
        res = sum(apply_deriv(a, power, s, t, func_symbols) for a in term.args)

        return res

    tmp = st.time_deriv(term, func_symbols) + term * s
    res = apply_deriv(tmp, power - 1, s, t, func_symbols).expand()

    return res
BB[:, 3] *= 0

CC[:, 2] *= 0

CC[:, 3] = CC[:, 0]
CC[0, 1] = CC[1, 0]
CC[1, 1] = CC[1, 0]

# definitorische Gleichungen
eq_defin = thetadot - mu

#eq_mech = AA*theta + BB*mu + CC*mudot
eq_mech = AA * theta + BB * thetadot + CC * mudot

# Container um zusätzliche Information über das Beispiel zu speichern
data = st.Container()
data.P0 = AA
data.P1 = BB
data.P2 = CC
data.eq_mech = eq_mech
data.time_dep_symbols = diff_symbols

F_eq_orig = F_eq = st.row_stack(eq_defin, eq_mech)

sys_name = "mechanik_ph_RTtt_seriell"

#~ from ipHelp import IPS
#~ IPS()

#F_eq = sp.Matrix([
#[ xdot1 - x4 ],
Пример #6
0
def main():
    P1i, P0i = tangent_system()

    global mode

    # raw_input was removed in python3
    if sys.version_info[0] == 2:
        mode = raw_input("Enter \"manual\" for manual mode or hit enter:\n")
    elif sys.version_info[0] == 3:
        mode = input("Enter \"manual\" for manual mode or hit enter:\n")
    #####################################################################

    i = 0

    while 1:
        # new iteration_stack
        myIteration = mc.IterationStack(i, P1i, P0i)

        assert al.has_full_row_rank(
            P1i), "P10 does not have full row rank. There \
                                        must be algebraic equations."

        Bi = reduction(myIteration)

        assert not al.is_zero_matrix(Bi), "System ist not flat!"

        if is_special_case(Bi):
            # special case
            Bi = fourseven(myIteration)

        if end_condition(Bi):
            # flag
            myIteration.last_iter_step = True

            # add to system stack + print
            myStack.add_iteration(myIteration)
            break

        P1i, P0i = elimination(myIteration)

        if mode == "manual": pc.print_line()

        # add to system stack + print iteration
        myStack.add_iteration(myIteration)

        i += 1

    # create transformation and calculate H and G(d/dt)
    myStack.transformation = tr.Transformation(myStack)

    # store results of the algorithm in pickled data container
    data = st.Container()
    data.F_eq = nct.make_all_symbols_noncommutative(example.F_eq, "")[0]
    data.vec_x = nct.make_all_symbols_noncommutative(example.vec_x, "")[0]
    data.vec_xdot = nct.make_all_symbols_noncommutative(example.vec_xdot,
                                                        "")[0]

    if hasattr(example, 'diff_symbols'):
        data.diff_symbols = nct.make_all_symbols_noncommutative(
            example.diff_symbols, "")[0]

    if hasattr(example, 'user_data'):
        data.user_data = example.user_data

    # add data to be stored here:
    # make symbols in P10 and P00 noncommutative
    P1 = nct.make_all_symbols_noncommutative(myStack.transformation.P10, "")[0]
    P0 = nct.make_all_symbols_noncommutative(myStack.transformation.P00, "")[0]
    s = sp.Symbol('s', commutative=False)
    data.P = P1 * s + P0
    data.P1 = P1
    data.P0 = P0
    data.H = nct.make_all_symbols_noncommutative(myStack.transformation.H,
                                                 "")[0]

    fname = path.replace(".py", ".pcl")
    st.pickle_full_dump(data, fname)

    # for testing
    try:
        import pycartan as ct
        import core.integrability as ic
        global w
        myIntegrabilityCheck = ic.IntegrabilityCheck(myStack)
        w = myStack.transformation.w
    except Exception as exc:
        print(exc)

    print("Data saved to ", fname, "\n")
    pc.print_line()