Ejemplo n.º 1
0
def test_cbcheck_reorder():
    nas = op2.rdnas2cam("tests/nas2cam_csuper/nas2cam")
    se = 101
    maa = nas["maa"][se]
    kaa = nas["kaa"][se]
    pv = np.any(maa, axis=0)
    pv = np.ix_(pv, pv)
    maa = maa[pv]
    kaa = kaa[pv]

    uset = nas["uset"][se]
    bset = n2p.mksetpv(uset, "p", "b")
    usetb = nas["uset"][se].iloc[bset]
    b = np.nonzero(n2p.mksetpv(uset, "a", "b"))[0]

    maa = cb.cbreorder(maa, b, last=True)
    kaa = cb.cbreorder(kaa, b, last=True)
    b += maa.shape[0] - len(b)

    # write to a string:
    with StringIO() as f:
        out = cb.cbcheck(f, maa, kaa, b, b[:6], usetb, em_filt=2)
        s = f.getvalue()
    s = s.splitlines()
    with open("tests/nas2cam_csuper/yeti_outputs/cbcheck_yeti_101.out") as f:
        sy = f.read().splitlines()

    assert s[0] == "Mass matrix is symmetric."
    assert s[1] == "Mass matrix is positive definite."
    assert s[2] == "Stiffness matrix is symmetric."
    compare_cbcheck_output(s, sy)
Ejemplo n.º 2
0
def test_cbreorder_m():
    m = np.dot(np.arange(1, 9).reshape(-1, 1), np.arange(2, 10).reshape(1, -1))
    # array([[ 2,  3,  4,  5,  6,  7,  8,  9],
    #        [ 4,  6,  8, 10, 12, 14, 16, 18],
    #        [ 6,  9, 12, 15, 18, 21, 24, 27],
    #        [ 8, 12, 16, 20, 24, 28, 32, 36],
    #        [10, 15, 20, 25, 30, 35, 40, 45],
    #        [12, 18, 24, 30, 36, 42, 48, 54],
    #        [14, 21, 28, 35, 42, 49, 56, 63],
    #        [16, 24, 32, 40, 48, 56, 64, 72]])

    mnew = cb.cbreorder(m, np.arange(7, 1, -1))
    sbe = np.array(
        [
            [72, 64, 56, 48, 40, 32, 16, 24],
            [63, 56, 49, 42, 35, 28, 14, 21],
            [54, 48, 42, 36, 30, 24, 12, 18],
            [45, 40, 35, 30, 25, 20, 10, 15],
            [36, 32, 28, 24, 20, 16, 8, 12],
            [27, 24, 21, 18, 15, 12, 6, 9],
            [9, 8, 7, 6, 5, 4, 2, 3],
            [18, 16, 14, 12, 10, 8, 4, 6],
        ]
    )
    assert np.all(mnew == sbe)

    # without the following, when pandas is imported, we get:
    # ERROR: test_n2p_nose.test_badrbe3_error
    # ----------------------------------------------------------------------
    # Traceback (most recent call last):
    #   File "/home/macro/anaconda3/lib/python3.5/site-packages/nose/case.py", line 198, in runTest
    #     self.test(*self.arg)
    #   File "/home/macro/code/pyyeti/tests/test_n2p_nose.py", line 1380, in test_badrbe3_error
    #     with assert_warns(RuntimeWarning) as cm:
    #   File "/home/macro/anaconda3/lib/python3.5/unittest/case.py", line 225, in __enter__
    #     for v in sys.modules.values():
    # RuntimeError: dictionary changed size during iteration
    #
    # Reported here: https://github.com/pytest-dev/pytest/issues/1288
    import sys

    for v in list(sys.modules.values()):
        if getattr(v, "__warningregistry__", None):
            v.__warningregistry__ = {}

    with assert_warns(RuntimeWarning):
        mnew = cb.cbreorder(m, np.arange(7, -1, -1))
    sbe = np.array(
        [
            [72, 64, 56, 48, 40, 32, 24, 16],
            [63, 56, 49, 42, 35, 28, 21, 14],
            [54, 48, 42, 36, 30, 24, 18, 12],
            [45, 40, 35, 30, 25, 20, 15, 10],
            [36, 32, 28, 24, 20, 16, 12, 8],
            [27, 24, 21, 18, 15, 12, 9, 6],
            [18, 16, 14, 12, 10, 8, 6, 4],
            [9, 8, 7, 6, 5, 4, 3, 2],
        ]
    )
    assert np.all(mnew == sbe)
Ejemplo n.º 3
0
def test_cbconvert_2():
    n = 19
    nb = 12
    mass = np.random.randn(n, n)
    b = np.arange(n - nb, n)
    m1_1 = cb.cbconvert(mass, b, "m2e")
    m1_2 = cb.cbreorder(m1_1, b)

    m2_1 = cb.cbreorder(mass, b)
    bnew = np.arange(nb)
    m2_2 = cb.cbconvert(m2_1, bnew, "m2e")
    assert np.allclose(m1_2, m2_2)
    assert np.allclose(mass[n - nb, n - nb] * 0.005710147154735817, m1_2[0, 0])
Ejemplo n.º 4
0
def test_cbcoordchk2():
    nas = op2.rdnas2cam("tests/nas2cam_csuper/nas2cam")
    se = 101
    maa = nas["maa"][se]
    kaa = nas["kaa"][se]
    pv = np.any(maa, axis=0)
    pv = np.ix_(pv, pv)
    kaa = kaa[pv]

    uset = nas["uset"][se]
    b = n2p.mksetpv(uset, "a", "b")
    b = np.nonzero(b)[0]

    chk0 = cb.cbcoordchk(kaa, b, b[-6:], verbose=False)
    rbmodes0 = chk0.rbmodes[b]

    # maa = cb.cbreorder(maa, b, last=True)
    kaa = cb.cbreorder(kaa, b, last=True)
    b += kaa.shape[0] - len(b)
    bref = b[-6:]

    chk1 = cb.cbcoordchk(kaa, b, bref, verbose=False)
    rbmodes1 = chk1.rbmodes[b]

    assert np.allclose(chk1.coords, chk0.coords)
    assert np.allclose(rbmodes1, rbmodes0)
    assert np.allclose(chk1.maxerr, chk0.maxerr)
    assert chk0.refpoint_chk == chk1.refpoint_chk == "pass"
    assert abs(chk0.maxerr).max() < 1e-5

    # a case where the refpoint_chk should be 'fail':
    chk2 = cb.cbcoordchk(kaa, b, [25, 26, 27, 31, 32, 33], verbose=False)
    assert chk2.refpoint_chk == "fail"
Ejemplo n.º 5
0
def test_cbreorder_drm():
    drm = np.dot(np.arange(1, 7).reshape(-1, 1), np.arange(2, 10).reshape(1, -1))
    # array([[ 2,  3,  4,  5,  6,  7,  8,  9],
    #        [ 4,  6,  8, 10, 12, 14, 16, 18],
    #        [ 6,  9, 12, 15, 18, 21, 24, 27],
    #        [ 8, 12, 16, 20, 24, 28, 32, 36],
    #        [10, 15, 20, 25, 30, 35, 40, 45],
    #        [12, 18, 24, 30, 36, 42, 48, 54]])

    dnew = cb.cbreorder(drm, np.arange(7, 1, -1), drm=True)
    sbe = np.array(
        [
            [9, 8, 7, 6, 5, 4, 2, 3],
            [18, 16, 14, 12, 10, 8, 4, 6],
            [27, 24, 21, 18, 15, 12, 6, 9],
            [36, 32, 28, 24, 20, 16, 8, 12],
            [45, 40, 35, 30, 25, 20, 10, 15],
            [54, 48, 42, 36, 30, 24, 12, 18],
        ]
    )
    assert np.all(dnew == sbe)

    assert_raises(ValueError, cb.cbreorder, drm, np.arange(7, 1, -1))

    with assert_warns(RuntimeWarning):
        dnew = cb.cbreorder(drm, np.arange(7, -1, -1), drm=True)
    assert np.all(drm[:, ::-1] == dnew)

    drm = np.arange(1, 16).reshape(3, 5)
    # array([[ 1,  2,  3,  4,  5],
    #        [ 6,  7,  8,  9, 10],
    #        [11, 12, 13, 14, 15]])
    with assert_warns(RuntimeWarning):
        dnew = cb.cbreorder(drm, [0, 1, 2, 3], drm=True, last=True)
    sbe = np.array([[5, 1, 2, 3, 4], [10, 6, 7, 8, 9], [15, 11, 12, 13, 14]])
    assert np.all(dnew == sbe)