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)
def test_cbcheck_indeterminate_rb_norm2(): nas = op2.rdnas2cam("tests/nas2cam_csuper/nas2cam") se = 102 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 = n2p.mksetpv(uset, "a", "b") q = ~b b = np.nonzero(b)[0] bref = n2p.mkdofpv(usetb, "b", [[3, 12356], [19, 3]])[0] # write to a string: with StringIO() as f: out = cb.cbcheck(f, maa, kaa, b, bref, usetb, em_filt=2, rb_norm=True) s = f.getvalue() s = s.splitlines() with open("tests/nas2cam_csuper/yeti_outputs/cbcheck_yeti_102_rbnorm.out") as f: sy = f.read().splitlines() assert s[0] == "Mass matrix is symmetric." assert s[1] == "Warning: mass matrix is not positive definite." assert s[2] == "Warning: stiffness matrix is not symmetric." compare_cbcheck_output(s, sy)
def test_cbcheck_determinate(): 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 = n2p.mksetpv(uset, "a", "b") q = ~b b = np.nonzero(b)[0] q = np.nonzero(q)[0] center = np.mean(usetb.iloc[::6, 1:], axis=0) rb = n2p.rbgeom_uset(usetb, center.values) # transform to single pt on centerline: # [b, q]_old = T*[b, q]_new # = [[rb, 0], [0, I]] * [b, q]_new T = np.zeros((len(b) + len(q), 6 + len(q))) T[:len(b), :6] = rb T[len(b):, 6:] = np.eye(len(q)) kaa = T.T @ kaa @ T maa = T.T @ maa @ T b = np.arange(6) # write to a string: with StringIO() as f: out = cb.cbcheck(f, maa, kaa, b, b[:6], em_filt=2) s = f.getvalue() s = s.splitlines() with open("tests/nas2cam_csuper/yeti_outputs/cbcheck_yeti_101_single.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] == "Warning: stiffness matrix is not symmetric." j = [10] jy = [10] assert comptable(s, sy, j, jy, label="KBB =", skip=1) compare_cbcheck_output(s, sy)
def test_cbcheck_unit_convert(): 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 = n2p.mksetpv(uset, "a", "b") q = ~b b = np.nonzero(b)[0] q = np.nonzero(q)[0] # write to a string: with StringIO() as f: out = cb.cbcheck( f, maa, kaa, b, b[:6], uset=usetb, em_filt=2, conv=[1 / 25.4, 0.005710147154735817], uref=[600, 150, 150], rb_norm=False, ) s = f.getvalue() s = s.splitlines() with open("tests/nas2cam_csuper/yeti_outputs/cbcheck_yeti_101_unitconv.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)
def test_cbcheck_determinate(): 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 = n2p.mksetpv(uset, "a", "b") q = ~b b = np.nonzero(b)[0] q = np.nonzero(q)[0] center = np.mean(usetb.iloc[::6, 1:], axis=0) rb = n2p.rbgeom_uset(usetb, center.values) # transform to single pt on centerline: # [b, q]_old = T*[b, q]_new # = [[rb, 0], [0, I]] * [b, q]_new T = np.zeros((len(b) + len(q), 6 + len(q))) T[: len(b), :6] = rb T[len(b) :, 6:] = np.eye(len(q)) kaa = T.T @ kaa @ T maa = T.T @ maa @ T b = np.arange(6) # write to a string: with StringIO() as f: out = cb.cbcheck(f, maa, kaa, b, b[:6], em_filt=2) s = f.getvalue() s = s.splitlines() with open("tests/nas2cam_csuper/yeti_outputs/cbcheck_yeti_101_single.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] == "Warning: stiffness matrix is not symmetric." j = [10] jy = [10] assert comptable(s, sy, j, jy, label="KBB =", skip=1) compare_cbcheck_output(s, sy) # check with no em filter: with StringIO() as f: out2 = cb.cbcheck(f, maa, kaa, b, b[:6]) s2 = f.getvalue() s2 = s2.splitlines() s_unique = [i for i in s if i not in s2] # ['Printing only the modes with at least 2.0% effective mass.', # 'The sum includes all modes.'] s2_unique = [i for i in s2 if i not in s] # [' 5 7.025 0.00 0.00 0.00 0.00 0.88 0.00', # ' 6 7.025 0.00 0.00 0.00 0.00 0.00 0.00', # ' 7 10.913 0.00 0.00 0.00 0.00 0.00 1.52', # ' 11 25.135 0.00 0.00 0.00 0.00 0.00 0.42', # ' 12 25.140 1.03 0.00 0.00 0.00 0.00 0.00', # ' 13 42.173 0.00 0.00 0.00 0.51 0.00 0.00', # ' 14 42.193 0.00 0.00 1.04 0.00 1.02 0.00', # ' 16 46.895 0.00 0.00 0.00 0.00 0.00 0.00', # ' 17 69.173 0.00 0.13 0.00 0.00 0.00 0.99'] assert len(s2) > len(s) assert len(s_unique) == 2 assert len(s2_unique) == 9
def test_cbcheck_indeterminate(): 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 = n2p.mksetpv(uset, "a", "b") q = ~b b = np.nonzero(b)[0] # write and read a file: f = tempfile.NamedTemporaryFile(delete=False) name = f.name f.close() # m, k, bset, rbs, rbg, rbe, usetconv = cb.cbcheck( out = cb.cbcheck(name, maa, kaa, b, b[:6], uset, em_filt=2) with open(name) as f: sfile = f.read() os.remove(name) assert (out.m == maa).all() assert (out.k == kaa).all() assert out.uset.equals(usetb) rbg = n2p.rbgeom_uset(out.uset) assert np.allclose(rbg, out.rbg) rbg_s = np.vstack((la.solve(rbg[:6].T, rbg.T).T, np.zeros((q[q].size, 6)))) assert abs(out.rbs - rbg_s).max() < 1e-5 assert abs(out.rbe - rbg_s).max() < 1e-5 # write to a string: with StringIO() as f: out = cb.cbcheck(f, maa, kaa, b, b[:6], usetb, em_filt=2) s = f.getvalue() assert sfile == s 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) with StringIO() as f: out = cb.cbcheck(f, maa, kaa, b, b[:6], usetb, em_filt=2, conv="e2m") out2 = cb.cbcheck(f, out.m, out.k, b, b[:6], out.uset, em_filt=2, conv="m2e") assert np.allclose(out2.uset, usetb) assert np.allclose(maa, out2.m) assert np.allclose(kaa, out2.k) # check for error catches: with StringIO() as f: assert_raises( ValueError, cb.cbcheck, f, maa, kaa, b, b[:6], usetb.iloc[:-6], em_filt=2 )
# setup CLA parameters: mission = "Micro Space Station" nb = uset.shape[0] nq = maa.shape[0] - nb bset = np.arange(nb) qset = np.arange(nq) + nb ref = [600.0, 150.0, 150.0] g = 9806.65 net = cb.mk_net_drms(maa, kaa, bset, uset=uset, ref=ref, g=g) # run cbcheck: chk = cb.cbcheck("outboard_cbcheck.out", maa, kaa, bset, bref=np.arange(6), uset=uset, uref=ref) # define some defaults for data recovery: defaults = dict(se=se, uf_reds=(1, 1, 1.25, 1), srsfrq=np.arange(0.1, 50.1, 0.1), srsQs=(10, 33)) drdefs = cla.DR_Def(defaults) @cla.DR_Def.addcat def _(): name = "scatm"