def test_rdcards(): a = nastran.rdcards( "tests/nas2cam_extseout/assemble.out", "CCC", no_data_return="no CCC" ) assert a == "no CCC" assert_raises( ValueError, nastran.rdcards, "tests/nas2cam_extseout/assemble.out", "grid", return_var="bad option", )
def test_wtrspline_rings(): theta1 = np.arange(0, 359, 360 / 5) * np.pi / 180 rad1 = 50.0 sta1 = 0.0 n1 = len(theta1) ring1 = np.vstack( ( np.arange(1, n1 + 1), # ID sta1 * np.ones(n1), # x rad1 * np.cos(theta1), # y rad1 * np.sin(theta1), ) ).T # z theta2 = np.arange(10, 359, 360 / 7) * np.pi / 180 rad2 = 45.0 sta2 = 1.0 n2 = len(theta2) ring2 = np.vstack( ( np.arange(1, n2 + 1) + 100, # ID sta2 * np.ones(n2), # x rad2 * np.cos(theta2), # y rad2 * np.sin(theta2), ) ).T # z uset1 = ( "Name 1", n2p.addgrid(None, ring1[:, 0].astype(int), "b", 0, ring1[:, 1:], 0), ) uset2 = ( "Name 2", n2p.addgrid(None, ring2[:, 0].astype(int), "b", 0, ring2[:, 1:], 0), ) fig = plt.figure("rspline demo", figsize=(8, 6)) fig.clf() ax = fig.add_subplot(1, 1, 1, projection="3d") with StringIO() as f: nastran.wtrspline_rings( f, ring1, ring2, 1001, 2001, makeplot=ax, independent="ring1" ) u, c = nastran.bulk2uset(f) rsplines1 = nastran.rdcards(f, "RSPLINE") with StringIO() as f: nastran.wtrspline_rings( f, uset1, uset2, 1001, 2001, makeplot=ax, independent="n amE 2" ) u2, c2 = nastran.bulk2uset(f) rsplines2 = nastran.rdcards(f, "RSPLINE") assert np.allclose(u, u2) for k, v in c2.items(): assert np.allclose(c[k], v) # x coord of new grids should be same as ring 2 ... 1.0: assert np.allclose(1, u.loc[(slice(None), 1), "x"]) # y, z coords should be like ring1, but with reduced radius to # match ring 2: assert np.allclose(ring1[:, 2:] * rad2 / rad1, u.loc[(slice(None), 1), "y":"z"]) # the local coord: # z_local is x # x_local points through node 1 ... which is on y to_local = [[0, 1.0, 0], [0, 0, 1], [1.0, 0, 0]] assert np.allclose(c[10010][-3:].T, to_local) # rsplines1 should have the 1001 series of numbers being # independent: assert (rsplines1[:, 2] > 1000).all() # rsplines2 should have the 101 series of numbers being # independent: assert (rsplines2[:, 2] < 1000).all() assert_raises( ValueError, nastran.wtrspline_rings, 1, uset1, uset2, 1001, 2001, makeplot="no", independent="badoption", ) uset1 = uset1[1] assert_raises( ValueError, nastran.wtrspline_rings, 1, uset1[:-1], uset2, 1001, 2001, makeplot="no", ) uset3 = None for row in ring2: uset3 = n2p.addgrid(uset3, int(row[0]), "b", 0, [row[3], row[1], row[2]], 0) assert_raises( ValueError, nastran.wtrspline_rings, 1, uset1, uset3, 1001, 2001, makeplot="no" )
def test_rdcards2(): fs = StringIO( """ $ PARAM,POST,-1 EIGR 1 AHOU 100000 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ TABLED1 1 0.01 1.0 150.0 1.0 ENDT $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$INCLUDE 'outboard.blk' $ GRID 1 0 0. 0. 300. 0 GRID* 1 0 0.00000000 0.00000000 * 300.00000000 0 $GRID 2 0 300. 0. 300. 0 grid, 2, 0, 300., 0., 300., 0 $$$ $111111122222222333333334444444455555555666666667777777788888888 RBE2 1001 330 123456 33 $ last line """ ) lst = nastran.rdcards( fs, r"[a-z]+[*]*", return_var="list", regex=True, keep_name=True, keep_comments=True, ) sbe = [ "$\n", ["PARAM", "POST", -1], ["EIGR", 1, "AHOU", "", "", "", 100000], "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", ["TABLED1", 1, "", "", "", "", "", "", "", 0.01, 1.0, 150.0, 1.0, "ENDT"], "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", "$$$INCLUDE 'outboard.blk'\n", "$ GRID 1 0 0. 0. 300. 0\n", ["GRID*", 1, 0, 0.0, 0.0, 300.0, 0], "$GRID 2 0 300. 0. 300. 0\n", ["grid", 2, 0, 300.0, 0.0, 300.0, 0], "$$$\n", "$111111122222222333333334444444455555555666666667777777788888888\n", ["RBE2", 1001, 330, 123456, 33], "$ last line\n", ] assert lst == sbe fs = StringIO( """ $ starting comment DTI SELOAD 1 2 dti seload 3 4 $ a comment for testing dti,seload,5,6 DTI, SELOAD, , 8.0, 'a' DTI,SETREE,100,0 $ ending comment """ ) lst = nastran.rdcards( fs, r"DTI(,\s*|\s+)SELOAD", regex=True, return_var="list", keep_name=True, keep_comments=True, ) sbe = [ "$ starting comment\n", ["DTI", "SELOAD", 1, 2], ["dti", "seload", 3, 4], "$ a comment for testing\n", ["dti", "seload", 5, 6], ["DTI", "SELOAD", "", 8.0, "'a'"], "$ ending comment\n", ] assert sbe == lst