Beispiel #1
0
def test_CompareWithMatrixDim5_Random():
    Ntests = 1  # 2
    dim = 5
    X = []
    dX = []
    for i in range(dim):
        xi = Variable("x%d" % i)
        X.append(xi)
        dX.append(xi.dt)
    X = np.array(X)
    dX = np.array(dX)
    for i in range(Ntests):
        M = randomSymmetricMatrix(dim)
        V = np.random.rand(dim, dim)
        K = randomSymmetricMatrix(dim)
        A = np.random.rand(dim)
        B = np.random.rand(dim)
        C = np.random.rand()
        totalenergy = C
        totalenergy += np.dot(dX, np.dot(M, dX)) / 2
        totalenergy += np.dot(dX, np.dot(V, X))
        totalenergy += np.dot(X, np.dot(K, X)) / 2
        totalenergy += np.dot(A, dX)
        totalenergy += np.dot(B, X)
        print("z")
        E = Energy(totalenergy)
        print("k")
        assert E == totalenergy
Beispiel #2
0
    def __init__(self, E, IC, G, F, timesteps):
        Validation_Solver.init(self, E, IC, G, F, timesteps)
        if not isinstance(E, Energy):
            E = Energy(E)
        lagrange = Lagrangian(E)
        self.X = E.X

        self.timesteps = timesteps

        self.n = len(self.X)
        self.m = len(G)
        self.__computeG(G)
        self.__computeDG()
        self.__computeDDG()
        self.__computeM(lagrange)
        self.__computeC(lagrange)
        self.__computeK(lagrange)
        self.__computeZ(lagrange)
        self.__computeMvv(lagrange)
        self.__computeMvp(lagrange)
        self.__computeMpp(lagrange)
        self.__resetAllMatrix()
        self.__computeF(F)
        self.__computet0()
        self.__computeX0(IC)
        self.__computedX0(IC)
Beispiel #3
0
def test_QuadPosition():
    Ntests = 1  # 10
    x = Variable("x")
    for i in range(Ntests):
        a = np.random.rand()
        E = Energy(a * x**2)
        assert E == a * x**2
Beispiel #4
0
def test_QuadSpeed():
    Ntests = 1  # 10
    x = Variable("x")
    dx = x.dt
    for i in range(Ntests):
        a = np.random.rand()
        E = Energy(a * dx**2)
        assert E == a * dx**2
Beispiel #5
0
def test_X2():
    x = Variable("x")
    E = Energy(x**2)
    L = Lagrangian(E)
    Lvec = L.get()

    assert Lvec.shape == (1, )
    assert Lvec[0] == -2 * x
Beispiel #6
0
def test_KineticEnergy_Standard():
    x = Variable("x")
    dx = x.dt
    mass = 1
    vector3D = (dx, 0, 0)
    E_good = mass * (dx**2) / 2
    E_test = KineticEnergy(mass, vector3D)
    E_good = Energy(E_good)
    assert E_test == E_good
Beispiel #7
0
def test_XdX():
    x = Variable("x")
    dx = x.dt
    E = Energy(x * dx)
    L = Lagrangian(E)
    Lvec = L.get()

    assert Lvec.shape == (1, )
    assert Lvec[0] == 0
Beispiel #8
0
def test_dX2():
    x = Variable("x")
    dx = x.dt
    ddx = x.ddt
    E = Energy(dx**2)
    L = Lagrangian(E)
    Lvec = L.get()

    assert Lvec.shape == (1, )
    assert Lvec[0] == 2 * ddx
Beispiel #9
0
def test_Linear():
    Ntests = 1  # 10
    x = Variable("x")
    dx = x.dt
    for i in range(Ntests):
        a, b, c = np.random.rand(3)
        totalenergy = c
        totalenergy += b * x
        totalenergy += a * dx
        E = Energy(totalenergy)
        assert E == totalenergy
Beispiel #10
0
def test_cosX():
    x = Variable("x")
    f = cos(x)
    df = -1 * sin(x)

    E = Energy(f)
    L = Lagrangian(E)
    Lvec = L.get()

    assert Lvec.shape == (1, )
    assert Lvec[0] == -1 * df
Beispiel #11
0
def test_AllQuantity():
    Ntests = 1  # 10
    x = Variable("x")
    dx = x.dt
    for i in range(Ntests):
        m, v, k, a, b, c = np.random.rand(6)
        totalenergy = c
        totalenergy += a * dx
        totalenergy += b * x
        totalenergy += k * x**2 / 2
        totalenergy += v * x * dx
        totalenergy += m * dx**2 / 2
        E = Energy(totalenergy)
        assert E == totalenergy
Beispiel #12
0
def test_CompareWithMatrixDim2_Random():
    Ntests = 1  # 10
    x = Variable("x")
    y = Variable("y")
    X = np.array([x, y])
    dX = np.array([x.dt, y.dt])
    for i in range(Ntests):
        M = randomSymmetricMatrix(2)
        V = np.random.rand(2, 2)
        K = randomSymmetricMatrix(2)
        A = np.random.rand(2)
        B = np.random.rand(2)
        C = np.random.rand()
        totalenergy = C
        totalenergy += np.dot(dX, np.dot(M, dX)) / 2
        totalenergy += np.dot(dX, np.dot(V, X))
        totalenergy += np.dot(X, np.dot(K, X)) / 2
        totalenergy += np.dot(A, dX)
        totalenergy += np.dot(B, X)
        E = Energy(totalenergy)
        assert E == totalenergy
Beispiel #13
0
def test_CompareWithMatrixDim2_Standard():
    x = Variable("x")
    y = Variable("y")
    dx = x.dt
    dy = y.dt
    X = (x, y)

    M = np.array([[14, 2], [2, 12]])
    V = np.array([[4, 6], [3, 5]])
    K = np.array([[-6, -3], [-3, -10]])

    A = np.array([1, -7])
    B = np.array([-5, 9])
    C = 80

    ener = 7*(dx**2) + 2*dx*dy + 6*(dy**2) + \
           4*dx*x + 6*dx*y + 3*dy*x + 5*dy*y + \
           (-3)*x**2 + (-3)*x*y + (-5)*y**2 + \
           1*dx + (-7)*dy + (-5)*x + 9*y + 80

    assert Energy(ener) == ener
Beispiel #14
0
def test_SetMatrixDim2_Standard():
    x = Variable("x")
    y = Variable("y")
    dx = x.dt
    dy = y.dt
    X = (x, y)

    M = np.array([[14, 2], [2, 12]])
    V = np.array([[4, 6], [3, 5]])
    K = np.array([[-6, -3], [-3, -10]])

    A = np.array([1, -7])
    B = np.array([-5, 9])
    C = 80

    ener = 7*(dx**2) + 2*dx*dy + 6*(dy**2) + \
           4*dx*x + 6*dx*y + 3*dy*x + 5*dy*y + \
           (-3)*x**2 + (-3)*x*y + (-5)*y**2 + \
           1*dx + (-7)*dy + (-5)*x + 9*y + 80
    E = Energy.frommatrix(X=X, M=M, V=V, K=K, A=A, B=B, C=C)
    ener = Energy(ener)
    assert E == ener
Beispiel #15
0
def test_Constant():
    E = Energy(1)
    L = Lagrangian(E)
    Lvec = L.get()

    assert Lvec is None
Beispiel #16
0
def test_Constant():
    Ntests = 1  # 10
    for i in range(Ntests):
        a = np.random.rand()
        E = Energy(a)
        assert E == a
Beispiel #17
0
def test_Build():
    Energy(0)