Example #1
0
def test_locate_misc():
    mat1 = np.array([[7, 3], [6, 8], [4, 0], [9, 2], [1, 5]])
    mat2 = np.array([[9, 2], [1, 5], [7, 3]])
    pv1, pv2 = locate.mat_intersect(mat1, mat2)
    assert np.all(np.array([3, 4, 0]) == pv1)
    assert np.all(np.array([0, 1, 2]) == pv2)
    pv1, pv2 = locate.mat_intersect(mat1, mat2, 1)
    assert np.all(np.array([0, 3, 4]) == pv1)
    assert np.all(np.array([2, 0, 1]) == pv2)
    pv1, pv2 = locate.mat_intersect(mat1, mat2, 2)
    assert np.all(np.array([3, 4, 0]) == pv1)
    assert np.all(np.array([0, 1, 2]) == pv2)
    pv = np.array([0, 3, 5])
    tf = locate.index2bool(pv, 8)
    assert np.all(np.array([True, False, False, True, False, True, False, False]) == tf)
Example #2
0
def test_mat_intersect_2():
    n = 30_000
    haystack = np.random.randn(n, 33)
    needles = haystack[::7]
    pv1, pv2 = locate.mat_intersect(haystack, needles, keep=2)
    assert (pv1 == np.arange(0, n, 7)).all()
    assert (pv2 == np.arange(0, n // 7 + 1)).all()
Example #3
0
def test_rdpostop2():
    post = op2.rdpostop2("tests/nas2cam_extseout/inboard.op2", 1, 1, 1, 1)

    dof = post["mats"]["ougv1"][0]["dof"]
    lam = post["mats"]["ougv1"][0]["lambda"]
    ougv1 = post["mats"]["ougv1"][0]["ougv1"]

    o4 = op4.load("tests/nas2cam_extseout/inboard.op4")
    mug1 = o4["mug1"][0]
    tug1 = nastran.rddtipch("tests/nas2cam_extseout/inboard.pch")
    tef1 = nastran.rddtipch("tests/nas2cam_extseout/inboard.pch", "TEF1")
    tes1 = nastran.rddtipch("tests/nas2cam_extseout/inboard.pch", "TES1")

    # ougv1, oef1, oes1 ... they don't have the constraint modes
    # or the resflex modes! How can they be useful? Anyway, this
    # checks the values present:

    # mug1 has 24 b-set ... get first 3 modes (rest are resflex):
    modes = mug1[:, 24:27]

    pv = locate.mat_intersect(tug1, dof)[0]
    assert np.allclose(modes[pv], ougv1)

    assert np.allclose(o4["mef1"][0][:, 24:27], post["mats"]["oef1"][0][0])
    assert np.all(post["mats"]["oef1"][0][1][:, 0] == tef1[:, 0])
    assert np.all(post["mats"]["oef1"][0][1][:, 1] == 34)

    pv = np.ones(15, bool)
    pv[5:7] = False
    pv[11:15] = False
    pv = np.hstack((pv, pv, pv))

    assert np.allclose(o4["mes1"][0][:, 24:27], post["mats"]["oes1"][0][0][pv])
    assert np.all(post["mats"]["oes1"][0][1][pv, 0] == tes1[:, 0])
    assert np.all(post["mats"]["oes1"][0][1][:, 1] == 34)

    with op2.OP2("tests/nas2cam_extseout/inboard.op2") as o2:
        o2._rowsCutoff = 0
        fpos = o2.dbnames["OUGV1"][0][0][0]
        o2._fileh.seek(fpos)
        name, trailer, dbtype = o2.rdop2nt()
        oug = o2._rdop2ougv1("OUGV1")

    assert np.all(oug["ougv1"] == ougv1)
    assert np.all(oug["dof"] == dof)
    assert np.all(oug["lambda"] == lam)
Example #4
0
def test_mat_intersect():
    a, b = locate.mat_intersect([1, 2, 3, 4, 5], [4, 2, 8])
    assert np.all(a == np.array([3, 1]))
    assert np.all(b == np.array([0, 1]))

    a, b = locate.mat_intersect([1, 2, 3, 4, 5], [4, 2, 8], keep=1)
    assert np.all(a == np.array([1, 3]))
    assert np.all(b == np.array([1, 0]))

    a, b = locate.mat_intersect([1, 2, 3, 4, 5], [4, 2, 8], keep=2)
    assert np.all(a == np.array([3, 1]))
    assert np.all(b == np.array([0, 1]))

    a, b = locate.mat_intersect([1, 2, 3], [1, 2, 3, 1], keep=2)
    assert np.all(a == [0, 1, 2, 0])
    assert np.all(b == [0, 1, 2, 3])

    a, b = locate.mat_intersect([1, 2, 3], [1, 2, 3, 1], keep=1)
    assert np.all(a == [0, 1, 2])
    assert np.all(b == [0, 1, 2])

    a, b = locate.mat_intersect([1, 2, 3], [1, 2, 3, 1])
    assert np.all(a == [0, 1, 2])
    assert np.all(b == [0, 1, 2])

    a, b = locate.mat_intersect([1, 2, 3], [100, 200, 300, 100])
    assert len(a) == len(b) == 0

    # now with floating point:
    a, b = locate.mat_intersect([1.0, 2, 3, 4, 5], [4, 2, 8.0])
    assert np.all(a == np.array([3, 1]))
    assert np.all(b == np.array([0, 1]))

    a, b = locate.mat_intersect([1, 2, 3, 4, 5], [4, 2, 8.0], keep=1)
    assert np.all(a == np.array([1, 3]))
    assert np.all(b == np.array([1, 0]))

    a, b = locate.mat_intersect([1, 2, 3, 4, 5], [4, 2.0, 8], keep=2)
    assert np.all(a == np.array([3, 1]))
    assert np.all(b == np.array([0, 1]))

    a, b = locate.mat_intersect([1, 2, 3], [1, 2, 3, 1.0], keep=2)
    assert np.all(a == [0, 1, 2, 0])
    assert np.all(b == [0, 1, 2, 3])

    a, b = locate.mat_intersect([1, 2, 3], [1, 2, 3, 1.0], keep=1)
    assert np.all(a == [0, 1, 2])
    assert np.all(b == [0, 1, 2])

    a, b = locate.mat_intersect([1, 2, 3], [1, 2, 3, 1.0])
    assert np.all(a == [0, 1, 2])
    assert np.all(b == [0, 1, 2])

    a, b = locate.mat_intersect([1, 2, 3], [100, 200, 300, 100.0])
    assert len(a) == len(b) == 0