Esempio n. 1
0
def _update_grid(node1: GRID, node2: GRID):
    """helper method for _eq_nodes_final"""
    node2.nid = node1.nid
    node2.xyz = node1.xyz
    node2.cp = node1.cp
    assert node2.cd == node1.cd
    assert node2.ps == node1.ps
    assert node2.seid == node1.seid
Esempio n. 2
0
def build():
    from pyNastran.bdf.bdf import BDF, GRID, CQUAD4, PSHELL, PROD, MAT1
    model = BDF(debug=False)
    xyz1 = [0., 0., 0.]
    xyz2 = [0., 1., 0.]
    xyz3 = [1., 1., 0.]
    xyz4 = [1., 0., 0.]
    model.nodes[1] = GRID(nid=1, cp=0, xyz=xyz1)
    model.nodes[2] = GRID(nid=2, cp=0, xyz=xyz2)
    model.nodes[3] = GRID(nid=3, cp=0, xyz=xyz3)
    model.nodes[4] = GRID(nid=4, cp=0, xyz=xyz4)
    model.elements[1] = CQUAD4(eid=1, pid=100, nids=[1, 2, 3, 4])
    model.properties[100] = PSHELL(pid=100, mid1=1000, t=0.1)
    model.materials[1000] = MAT1(mid=1000, E=1e7, G=None, nu=0.3)
Esempio n. 3
0
    def test_loads_sum_radial_01(self):
        model = BDF(debug=False)
        model.nodes[1] = GRID(1, cp=1, xyz=[0., 0., 0.], cd=0, ps='', seid=0,
                              comment='')
        cid = 1
        origin = [0., 0., 0.]
        zaxis = [0., 0., 1.]
        xaxis = [1., 0., 0.]
        model.coords[1] = CORD2C(cid, rid=0, origin=origin, zaxis=zaxis,
                                 xzplane=xaxis, comment='')
        sid = 1
        node = 1
        cid = 1
        mag = 1.1
        xyz = [1., 0., 0.]
        radial_force = FORCE(sid, node, mag, cid=cid, xyz=xyz, comment='')
        model.add_card_class(radial_force)

        sid = 2
        xyz = [1., 90., 0.]
        mag = 2.2
        theta_force = FORCE(sid, node, mag, cid=cid, xyz=xyz, comment='')
        model.add_card_class(theta_force)
        model.cross_reference()

        p0 = 1
        eids = None
        nids = None

        loadcase_id = 1
        F, M = model.sum_forces_moments(p0, loadcase_id, include_grav=False,
                                        xyz_cid0=None)
        F2, M2 = model.sum_forces_moments_elements(p0, loadcase_id, eids, nids,
                                                   include_grav=False,
                                                   xyz_cid0=None)
        assert np.allclose(F, F2), 'F=%s F2=%s' % (F, F2)
        assert np.allclose(M, M2), 'M=%s M2=%s' % (M, M2)

        F1_expected = np.array([1.1, 0., 0.])
        M1_expected = np.array([0., 0., 0.])
        self.assertTrue(allclose(F1_expected, F), 'loadcase_id=%s F_expected=%s F=%s' % (loadcase_id, F1_expected, F))
        self.assertTrue(allclose(M1_expected, M), 'loadcase_id=%s M_expected=%s M=%s' % (loadcase_id, M1_expected, M))

        loadcase_id = 2
        F, M = model.sum_forces_moments(p0, loadcase_id, include_grav=False,
                                        xyz_cid0=None)
        F2, M2 = model.sum_forces_moments_elements(p0, loadcase_id, eids, nids,
                                                   include_grav=False,
                                                   xyz_cid0=None)
        assert np.allclose(F, F2), 'F=%s F2=%s' % (F, F2)
        assert np.allclose(M, M2), 'M=%s M2=%s' % (M, M2)
        F2_expected = np.array([0., 2.2, 0.])
        M2_expected = np.array([0., 0., 0.])
        self.assertTrue(allclose(F2_expected, F), 'loadcase_id=%s F_expected=%s F=%s' % (loadcase_id, F2_expected, F))
        self.assertTrue(allclose(M2_expected, M), 'loadcase_id=%s M_expected=%s M=%s' % (loadcase_id, M2_expected, M))
Esempio n. 4
0
 def __getitem__(self, i):
     """this works on index"""
     self.make_current()
     nid = self.nid[i]
     return GRID(nid,
                 self.xyz[i],
                 cp=self.cp[i],
                 cd=self.cd[i],
                 ps=self.ps[i],
                 seid=self.seid[i],
                 comment=self.comment[nid])
Esempio n. 5
0
 def test_openmdao_field_1(self):
     model = BDF(debug=False)
     node = GRID(57, cp=10, xyz=[1., 2., 3.], cd=7, ps='', seid=0, comment='')
     model.nodes[57] = node
     #print()
     str(node)
     model.update_card('GRID', 57, 2, 11) # cp
     str(node)
     model.update_card('GRID', 57, 2, 12) # cp
     str(node)
     model.update_card('GRID', 57, 3, 13.) # x
     str(node)
     model.update_card('GRID', 57, 4, 14.) # y
     str(node)
     model.update_card('GRID', 57, 4, 14.) # y
     str(node)
Esempio n. 6
0
    def test_grid_01(self):
        nid = 1
        cp = 2
        cd = 0
        ps = ''
        seid = 0
        datai = [nid, cp, 0., 0., 0., cd, ps, seid]
        n1 = GRID.add_op2_data(datai)
        #print(n1)

        msg = n1.write_card(size=8)
        #print(msg)
        msg = n1.write_card(size=16)
        #print(msg)
        msg = n1.write_card(size=16, is_double=True)
        #print(msg)
        if 0:
            msg = n1.write_card(size=8)
            #print('%r' % msg)
            # small field
            self.assertEqual(
                msg,
                'GRID           1       2      0.      0.      0.                        \n'
            )
            msg = n1.write_card(size=16)

            # large field
            card = (
                'GRID*                  1               2             .-0             .-0\n'
                '*                    .-0                                                \n'
            )
            print('%r' % msg)
            ref = 'ERROR\n'
            if card != msg:
                scard = card.split('\n')
                smsg = msg.split('\n')
                i = 0
                print(scard)
                print(smsg)
                for sc, sm in zip(scard, smsg):
                    if sc != sm:
                        ref += 'i=%s\ncard=%r\nmsg =%r\n' % (i, sc, sm)
                    i += 1
            print(ref)
            self.assertEqual(msg, card), ref
Esempio n. 7
0
def read_delaunay(points, tri, silent=True):
    msg('Reading Delaunay ouptut...', silent=silent)
    mesh = BDF()
    nodes = []
    nid = 0
    for pt in points:
        if len(pt) == 2:
            pt = np.array([pt[0], pt[1], 0.])
        nid += 1
        node = GRID(nid, 0, pt)
        node.trias = set()
        node.edges = set()
        node.index = set()
        node.prop = None
        nodes.append(node)
        mesh.nodes[nid] = node
    eid = 0
    trias = []
    for i1, i2, i3 in tri.simplices:
        n1 = nodes[i1]
        n2 = nodes[i2]
        n3 = nodes[i3]
        eid += 1
        tria = CTRIA3(eid, 0, (n1.nid, n2.nid, n3.nid))
        tria.nodes = [n1, n2, n3]
        tria.nodes_ref = tria.nodes
        tria.edges = []
        tria.prop = None
        trias.append(tria)
        mesh.elements[eid] = tria
    edges = {}
    edges_ids = defaultdict(list)
    for tria in trias:
        for edge_id in tria.get_edge_ids():
            edges_ids[edge_id].append(tria)
    for (n1, n2), e_trias in edges_ids.items():
        edge = Edge(mesh.nodes[n1], mesh.nodes[n2])
        edge.trias = e_trias
        edges[(n1, n2)] = edge
    for edge in edges.values():
        for tria in edge.trias:
            tria.edges.append(edge)
    for tria in trias:
        for node in tria.nodes:
            node.trias.add(tria)
        for edge in tria.edges:
            node.edges.add(edge)
    mesh.edges = edges
    msg('finished!', silent=silent)
    return mesh
Esempio n. 8
0
    def test_grid_01(self):
        nid = 1
        cp = 2
        cd = 0
        ps = ''
        seid = 0
        datai = [nid, cp, 0., 0., 0., cd, ps, seid]
        n1 = GRID.add_op2_data(datai)
        #print n1

        msg = n1.write_card(size=8)
        #print(msg)
        msg = n1.write_card(size=16)
        #print(msg)
        msg = n1.write_card(size=16, is_double=True)
        #print(msg)
        if 0:
            msg = n1.write_card(size=8)
            #print('%r' % msg)
            # small field
            self.assertEqual(msg, 'GRID           1       2      0.      0.      0.                        \n')
            msg = n1.write_card(size=16)

            # large field
            card = ('GRID*                  1               2             .-0             .-0\n'
                    '*                    .-0                                                \n')
            print('%r' % msg)
            ref = 'ERROR\n'
            if card != msg:
                scard = card.split('\n')
                smsg = msg.split('\n')
                i = 0
                print(scard)
                print(smsg)
                for sc, sm in zip(scard, smsg):
                    if sc != sm:
                        ref += 'i=%s\ncard=%r\nmsg =%r\n' % (i, sc, sm)
                    i += 1
            print(ref)
            self.assertEqual(msg, card), ref
Esempio n. 9
0
    def test_grid_02(self):
        nid = 1
        cp = 2
        cd = 0
        ps = '1'
        seid = 4
        datai = ['GRID', nid, cp, 0., 0., 0., cd, ps, seid]
        card = BDFCard(datai)
        n1 = GRID.add_card(card)

        x = 0.1
        y = 0.2
        z = 0.3
        self.assertEqual(n1.get_field(3), 0., msg='%s' % n1.get_field(3))
        self.assertEqual(n1.get_field(4), 0., msg='%s' % n1.get_field(4))
        self.assertEqual(n1.get_field(5), 0., msg='%s' % n1.get_field(5))

        self.assertEqual(n1.get_field(6), cd, msg='%s' % n1.get_field(6))
        self.assertEqual(n1.get_field(7), ps, msg='%s' % n1.get_field(7))
        self.assertEqual(n1.get_field(8), seid, msg='%s' % n1.get_field(8))
        n1.update_field(3, x)
        n1.update_field(4, y)
        n1.update_field(5, z)
        #print('ps = %r' % n1.ps)
        self.assertEqual(n1.xyz[0], x)
        self.assertEqual(n1.xyz[1], y)
        self.assertEqual(n1.xyz[2], z)
        self.assertEqual(n1.ps, ps)
        self.assertEqual(n1.cd, cd)
        self.assertEqual(n1.seid, seid)

        self.assertEqual(n1.get_field(3), x, msg='%s' % n1.get_field(3))
        self.assertEqual(n1.get_field(4), y, msg='%s' % n1.get_field(4))
        self.assertEqual(n1.get_field(5), z, msg='%s' % n1.get_field(5))

        self.assertEqual(n1.get_field(6), cd, msg='%s' % n1.get_field(6))
        self.assertEqual(n1.get_field(7), ps, msg='%s' % n1.get_field(7))
        self.assertEqual(n1.get_field(8), seid, msg='%s' % n1.get_field(8))
Esempio n. 10
0
    def test_grid_02(self):
        nid = 1
        cp = 2
        cd = 0
        ps = '1'
        seid = 4
        datai = ['GRID', nid, cp, 0., 0., 0., cd, ps, seid]
        card = BDFCard(datai)
        n1 = GRID.add_card(card)

        x = 0.1
        y = 0.2
        z = 0.3
        self.assertEqual(n1.get_field(3), 0., msg='%s' % n1.get_field(3))
        self.assertEqual(n1.get_field(4), 0., msg='%s' % n1.get_field(4))
        self.assertEqual(n1.get_field(5), 0., msg='%s' % n1.get_field(5))

        self.assertEqual(n1.get_field(6), cd, msg='%s' % n1.get_field(6))
        self.assertEqual(n1.get_field(7), ps, msg='%s' % n1.get_field(7))
        self.assertEqual(n1.get_field(8), seid, msg='%s' % n1.get_field(8))
        n1.update_field(3, x)
        n1.update_field(4, y)
        n1.update_field(5, z)
        #print('ps = %r' % n1.ps)
        self.assertEqual(n1.xyz[0], x)
        self.assertEqual(n1.xyz[1], y)
        self.assertEqual(n1.xyz[2], z)
        self.assertEqual(n1.ps, ps)
        self.assertEqual(n1.cd, cd)
        self.assertEqual(n1.seid, seid)

        self.assertEqual(n1.get_field(3), x, msg='%s' % n1.get_field(3))
        self.assertEqual(n1.get_field(4), y, msg='%s' % n1.get_field(4))
        self.assertEqual(n1.get_field(5), z, msg='%s' % n1.get_field(5))

        self.assertEqual(n1.get_field(6), cd, msg='%s' % n1.get_field(6))
        self.assertEqual(n1.get_field(7), ps, msg='%s' % n1.get_field(7))
        self.assertEqual(n1.get_field(8), seid, msg='%s' % n1.get_field(8))
Esempio n. 11
0
    def test_time_type_check(self):
        """this tests what the best way to do type checking is"""
        g = GRID(4)
        s = SPOINT(4)
        import time
        import six

        t0 = time.time()
        for i in six.moves.range(5000000):
            if g.type == 'GRID':
                pass
            if s.type == 'GRID':
                pass
        dt1 = time.time() - t0

        t1 = time.time()
        for i in six.moves.range(5000000):
            if isinstance(g, GRID):
                pass
            if isinstance(s, GRID):
                pass
        dt2 = time.time() - t1
        print('dt1=%.4f dt2=%.4f' % (dt1, dt2))
        assert dt2 > dt1, 'flip the way you do type checking'
Esempio n. 12
0
    def test_grid_01(self):
        nid = 1
        cp = 2
        cd = 0
        ps = ""
        seid = 0
        datai = [nid, cp, 0.0, 0.0, 0.0, cd, ps, seid]
        n1 = GRID(data=datai)
        # print n1

        msg = n1.write_card(size=8)
        # print(msg)
        msg = n1.write_card(size=16)
        # print(msg)
        msg = n1.write_card(size=16, is_double=True)
        # print(msg)
        if 0:
            msg = n1.write_card(size=8)
            # print('%r' % msg)
            # small field
            self.assertEqual(msg, "GRID           1       2      0.      0.      0.                        \n")
            msg = n1.write_card(size=16)

            # large field
            card = (
                "GRID*                  1               2             .-0             .-0\n"
                "*                    .-0                                                \n"
            )
            print("%r" % msg)
            ref = "ERROR\n"
            if card != msg:
                scard = card.split("\n")
                smsg = msg.split("\n")
                i = 0
                print(scard)
                print(smsg)
                for sc, sm in zip(scard, smsg):
                    if sc != sm:
                        ref += "i=%s\ncard=%r\nmsg =%r\n" % (i, sc, sm)
                    i += 1
            print(ref)
            self.assertEqual(msg, card), ref
Esempio n. 13
0
    def get_mass(self, nid1, nid2, xyz1, xyz2, eid, pid, mid, A, J, c, nsm, E,
                 G, nu, rho, L):
        """tests a CROD and a CONROD"""
        model = BDF(debug=False)
        lines = [
            'conrod,%i, %i, %i, %i, %f, %f, %f, %f' %
            (eid, nid1, nid2, mid, A, J, c, nsm)
        ]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        conrod = CONROD.add_card(cardi)
        model._add_element_object(conrod)
        card = model.elements[eid]
        node_ids = card.node_ids
        assert node_ids == [nid1, nid2], node_ids  # probably wrong

        lines = ['crod,%i, %i, %i, %i' % (eid + 1, pid, nid1, nid2)]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        crod = CROD.add_card(cardi)
        model._add_element_object(crod)
        card = model.elements[eid + 1]
        node_ids = card.node_ids
        assert node_ids == [nid1, nid2], node_ids  # probably wrong

        lines = ['ctube,%i, %i, %i, %i' % (eid + 2, pid + 1, nid1, nid2)]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        ctube = CTUBE.add_card(cardi)
        model._add_element_object(ctube)
        card = model.elements[eid + 2]
        node_ids = card.node_ids
        assert node_ids == [nid1, nid2], node_ids  # probably wrong

        lines = ['prod,%i, %i, %f, %f, %f, %f' % (pid, mid, A, J, c, nsm)]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        prod = PROD.add_card(cardi)
        model._add_property_object(prod)

        #self.pid = integer(card, 1, 'pid')
        #self.mid = integer(card, 2, 'mid')
        #self.OD1 = double(card, 3, 'OD1')
        #self.t = double_or_blank(card, 4, 't', self.OD1 / 2.)
        #self.nsm = double_or_blank(card, 5, 'nsm', 0.0)
        #self.OD2 = double_or_blank(card, 6, 'OD2', self.OD1)
        OD1 = sqrt(4 * A / pi)
        t = 0.
        OD2 = OD1
        lines = [
            'ptube,%i, %i, %f, %f, %f, %f' % (pid + 1, mid, OD1, t, nsm, OD2)
        ]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        ptube = PTUBE.add_card(cardi)
        model._add_property_object(ptube)

        lines = ['mat1,%i, %.2e, %.2e, %f, %f' % (mid, E, G, nu, rho)]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        card = MAT1.add_card(cardi)
        model._add_structural_material_object(card)

        lines = [
            'grid,%i, %i, %f, %f, %f' % (nid1, 0, xyz1[0], xyz1[1], xyz1[2])
        ]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        card = GRID.add_card(cardi)
        model._add_node_object(card)

        lines = [
            'grid,%i, %i, %f, %f, %f' % (nid2, 0, xyz2[0], xyz2[1], xyz2[2])
        ]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        card = GRID.add_card(cardi)
        model._add_node_object(card)

        model.cross_reference()
        mass = L * (rho * A + nsm)

        # conrod
        self.assertEqual(conrod.eid, eid)
        self.assertEqual(conrod.Pid(), -10)
        self.assertEqual(conrod.Mid(), mid)
        self.assertEqual(conrod.Length(), L)
        self.assertEqual(conrod.Nsm(), nsm)
        self.assertEqual(conrod.Mass(), mass)
        self.assertEqual(conrod.E(), E)
        self.assertEqual(conrod.G(), G)
        self.assertEqual(conrod.Area(), A)
        self.assertEqual(conrod.J(), J)
        self.assertEqual(conrod.C(), c)
        self.assertEqual(conrod.Rho(), rho)

        # crod
        self.assertEqual(crod.eid, eid + 1)
        self.assertEqual(crod.Pid(), pid)
        self.assertEqual(crod.Mid(), mid)
        self.assertEqual(crod.Length(), L)
        self.assertEqual(crod.Nsm(), nsm)
        self.assertEqual(crod.Mass(), mass)
        self.assertEqual(crod.E(), E)
        self.assertEqual(crod.G(), G)
        self.assertEqual(crod.Area(), A)
        self.assertEqual(crod.J(), J)
        self.assertEqual(crod.C(), c)
        self.assertEqual(crod.Rho(), rho)
        #self.assertEqual(crod.Nu(), nu)

        # prod
        self.assertEqual(prod.Pid(), pid)
        self.assertEqual(prod.Mid(), mid)
        self.assertEqual(prod.Nsm(), nsm)
        self.assertEqual(prod.E(), E)
        self.assertEqual(prod.G(), G)
        self.assertEqual(prod.Area(), A)
        self.assertEqual(prod.J(), J)
        self.assertEqual(prod.C(), c)
        self.assertEqual(prod.Rho(), rho)

        # ctube
        self.assertEqual(ctube.eid, eid + 2)
        self.assertEqual(ctube.Pid(), pid + 1)
        self.assertEqual(ctube.Mid(), mid)
        self.assertEqual(ctube.Length(), L)
        self.assertEqual(ctube.Nsm(), nsm)
        self.assertAlmostEqual(ctube.Mass(), mass, 5)
        self.assertEqual(ctube.E(), E)
        self.assertEqual(ctube.G(), G)
        self.assertAlmostEqual(ctube.Area(), A, 5)
        ctube.J()
        self.assertEqual(ctube.Rho(), rho)

        # ptube
        self.assertEqual(ptube.Pid(), pid + 1)
        self.assertEqual(ptube.Mid(), mid)
        self.assertEqual(ptube.Nsm(), nsm)
        self.assertEqual(ptube.E(), E)
        self.assertEqual(ptube.G(), G)
        self.assertAlmostEqual(ptube.Area(), A, 5)
        ptube.J()
        self.assertEqual(ptube.Rho(), rho)
Esempio n. 14
0
    def test_spline2(self):
        """checks the SPLINE2 card"""
        #| SPLINE2 | EID  | CAERO |  ID1  |  ID2  | SETG | DZ | DTOR | CID |
        #|         | DTHX | DTHY  | None  | USAGE |      |    |      |     |
        #+---------+------+-------+-------+-------+------+----+------+-----+
        #| SPLINE2 |   5  |   8   |  12   | 24    | 60   | 0. | 1.0  |  3  |
        #|         |  1.  |       |       |       |      |    |      |     |

        cid = 3
        origin = [0., 0., 0.]
        xaxis = [1., 0., 0.]
        xyplane = [0., 1., 0.]
        coord = CORD2R.add_axes(cid, rid=0, origin=origin,
                                xaxis=xaxis, yaxis=None, zaxis=None,
                                xyplane=xyplane, yzplane=None, xzplane=None,
                                comment='comment')
        eid = 8
        pid = 10
        cp = 0
        nsb = 4
        nint = 2
        lsb = None
        lint = None
        p1 = [0., 0., 0.]
        x12 = 42.
        igid = None
        caero2 = CAERO2(eid, pid, igid, p1, x12,
                        cp=cp, nsb=nsb, nint=nint, lsb=lsb, lint=lint,
                        comment='this is a caero')
        #caero = CAERO2(eid, pid, cp, nsb, nint, lsb, lint, igid, p1, x12)

        sid = 60
        ids = [7, 13]
        set_obj = SET1(sid, ids, is_skin=False, comment='set card')
        grid7 = GRID(nid=7, cp=0, xyz=[7., 0., 0.], cd=0, ps='', seid=0, comment='')
        grid13 = GRID(nid=13, cp=0, xyz=[13., 0., 0.], cd=0, ps='', seid=0, comment='')

        model = BDF(log=None)
        model._add_coord_object(coord)
        model._add_caero_object(caero2)
        model._add_set_object(set_obj)
        model._add_node_object(grid7)
        model._add_node_object(grid13)

        eid = 5
        caero = 8
        id1 = 12
        id2 = 24
        setg = 60
        dz = 0.
        dtor = 1.0
        cid = 3
        dthx = 1.
        dthy = None
        usage = None
        card = ['SPLINE2', eid, caero, id1, id2, setg, dz, dtor, cid,
                dthx, dthy, None, usage]

        bdf_card = BDFCard(card, has_none=True)
        spline_a = SPLINE2.add_card(bdf_card, comment='spline2_a')
        spline_a.write_card()

        spline_b = SPLINE2(eid, caero, id1, id2, setg, dz, dtor, cid, dthx,
                           dthy, usage, comment='spline2_b')
        spline_b.validate()
        spline_b.write_card()
        spline_b.cross_reference(model)
        spline_b.write_card()
Esempio n. 15
0
    def get_mass(self, nid1, nid2, xyz1, xyz2, eid, pid, mid, A, J, c, nsm, E, G, nu, rho, L):
        """tests a CROD and a CONROD"""
        model = BDF(debug=False)
        lines = ['conrod,%i, %i, %i, %i, %f, %f, %f, %f' % (eid, nid1, nid2, mid, A, J, c, nsm)]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        conrod = CONROD.add_card(cardi)
        model._add_element_object(conrod)
        card = model.elements[eid]
        node_ids = card.node_ids
        assert node_ids == [nid1, nid2], node_ids # probably wrong

        lines = ['crod,%i, %i, %i, %i' % (eid+1, pid, nid1, nid2)]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        crod = CROD.add_card(cardi)
        model._add_element_object(crod)
        card = model.elements[eid+1]
        node_ids = card.node_ids
        assert node_ids == [nid1, nid2], node_ids # probably wrong

        lines = ['ctube,%i, %i, %i, %i' % (eid+2, pid+1, nid1, nid2)]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        ctube = CTUBE.add_card(cardi)
        model._add_element_object(ctube)
        card = model.elements[eid+2]
        node_ids = card.node_ids
        assert node_ids == [nid1, nid2], node_ids # probably wrong

        lines = ['prod,%i, %i, %f, %f, %f, %f' % (pid, mid, A, J, c, nsm)]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        prod = PROD.add_card(cardi)
        model._add_property_object(prod)

        #self.pid = integer(card, 1, 'pid')
        #self.mid = integer(card, 2, 'mid')
        #self.OD1 = double(card, 3, 'OD1')
        #self.t = double_or_blank(card, 4, 't', self.OD1 / 2.)
        #self.nsm = double_or_blank(card, 5, 'nsm', 0.0)
        #self.OD2 = double_or_blank(card, 6, 'OD2', self.OD1)
        OD1 = sqrt(4*A/pi)
        t = 0.
        OD2 = OD1
        lines = ['ptube,%i, %i, %f, %f, %f, %f' % (pid+1, mid, OD1, t, nsm, OD2)]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        ptube = PTUBE.add_card(cardi)
        model._add_property_object(ptube)

        lines = ['mat1,%i, %.2e, %.2e, %f, %f' % (mid, E, G, nu, rho)]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        card = MAT1.add_card(cardi)
        model._add_structural_material_object(card)

        lines = ['grid,%i, %i, %f, %f, %f' % (nid1, 0, xyz1[0], xyz1[1], xyz1[2])]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        card = GRID.add_card(cardi)
        model._add_node_object(card)

        lines = ['grid,%i, %i, %f, %f, %f' % (nid2, 0, xyz2[0], xyz2[1], xyz2[2])]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        card = GRID.add_card(cardi)
        model._add_node_object(card)

        model.cross_reference()
        mass = L * (rho * A + nsm)

        # conrod
        self.assertEqual(conrod.eid, eid)
        self.assertEqual(conrod.Pid(), None)
        self.assertEqual(conrod.Mid(), mid)
        self.assertEqual(conrod.Length(), L)
        self.assertEqual(conrod.Nsm(), nsm)
        self.assertEqual(conrod.Mass(), mass)
        self.assertEqual(conrod.E(), E)
        self.assertEqual(conrod.G(), G)
        self.assertEqual(conrod.Area(), A)
        self.assertEqual(conrod.J(), J)
        self.assertEqual(conrod.C(), c)
        self.assertEqual(conrod.Rho(), rho)

        # crod
        self.assertEqual(crod.eid, eid+1)
        self.assertEqual(crod.Pid(), pid)
        self.assertEqual(crod.Mid(), mid)
        self.assertEqual(crod.Length(), L)
        self.assertEqual(crod.Nsm(), nsm)
        self.assertEqual(crod.Mass(), mass)
        self.assertEqual(crod.E(), E)
        self.assertEqual(crod.G(), G)
        self.assertEqual(crod.Area(), A)
        self.assertEqual(crod.J(), J)
        self.assertEqual(crod.C(), c)
        self.assertEqual(crod.Rho(), rho)
        #self.assertEqual(crod.Nu(), nu)

        # prod
        self.assertEqual(prod.Pid(), pid)
        self.assertEqual(prod.Mid(), mid)
        self.assertEqual(prod.Nsm(), nsm)
        self.assertEqual(prod.E(), E)
        self.assertEqual(prod.G(), G)
        self.assertEqual(prod.Area(), A)
        self.assertEqual(prod.J(), J)
        self.assertEqual(prod.C(), c)
        self.assertEqual(prod.Rho(), rho)

        # ctube
        self.assertEqual(ctube.eid, eid+2)
        self.assertEqual(ctube.Pid(), pid+1)
        self.assertEqual(ctube.Mid(), mid)
        self.assertEqual(ctube.Length(), L)
        self.assertEqual(ctube.Nsm(), nsm)
        self.assertAlmostEqual(ctube.Mass(), mass, 5)
        self.assertEqual(ctube.E(), E)
        self.assertEqual(ctube.G(), G)
        self.assertAlmostEqual(ctube.Area(), A, 5)
        ctube.J()
        self.assertEqual(ctube.Rho(), rho)

        # ptube
        self.assertEqual(ptube.Pid(), pid+1)
        self.assertEqual(ptube.Mid(), mid)
        self.assertEqual(ptube.Nsm(), nsm)
        self.assertEqual(ptube.E(), E)
        self.assertEqual(ptube.G(), G)
        self.assertAlmostEqual(ptube.Area(), A, 5)
        ptube.J()
        self.assertEqual(ptube.Rho(), rho)
Esempio n. 16
0
    def test_pbarl_1(self):
        """tests the PBARL"""
        model = BDF(log=None, debug=False)
        pid = 4
        mid = 40
        group = 'group'
        Type = 'bad_type'
        dim = 42
        nsm = 0.5
        pbarl = PBARL(pid,
                      mid,
                      Type,
                      dim,
                      group=group,
                      nsm=nsm,
                      comment='comment')
        with self.assertRaises(ValueError):  # Type
            pbarl.validate()

        pbarl.Type = 'TUBE'
        with self.assertRaises(TypeError):  # dim
            pbarl.validate()

        pbarl.dim = [20.]
        with self.assertRaises(RuntimeError):
            pbarl.validate()

        pbarl.dim = [2., 1.]
        #with self.assertRaises(ValueError):
        #pbarl.validate()
        #pbarl.group = 'MSCBMLO'

        pbarl.validate()
        str(pbarl)
        pbarl.write_card(size=8, is_double=False)
        pbarl.write_card(size=16, is_double=False)
        pbarl.write_card(size=16, is_double=True)
        model.properties[pid] = pbarl

        nid1 = 52
        xyz1 = [0., 0., 0.]
        model.nodes[nid1] = GRID(nid1, cp=0, xyz=xyz1)

        nid2 = 53
        xyz2 = [1., 0., 0.]
        model.nodes[nid2] = GRID(nid2, cp=0, xyz=xyz2)

        E = 30.0e7
        G = None
        nu = 0.3
        mat = MAT1(mid, E, G, nu, rho=1.0)
        model.materials[mid] = mat

        eid = 42
        x = None
        g0 = None
        cbar = CBAR(eid,
                    pid, [nid1, nid2],
                    x,
                    g0,
                    offt='GGG',
                    pa=0,
                    pb=0,
                    wa=None,
                    wb=None,
                    comment='')
        cbar.validate()
        model.elements[eid] = cbar
        pbarl._verify(xref=False)

        model.validate()
        model.cross_reference()
        pbarl._verify(xref=True)
        assert allclose(cbar.Mass(), 9.9247779608), cbar.Mass()

        mat.rho = 0.
        assert allclose(cbar.Mass(), 0.5), cbar.Mass()
Esempio n. 17
0
    def test_grid_02(self):
        nid = 1
        cp = 2
        cd = 0
        ps = "1"
        seid = 4
        datai = ["GRID", nid, cp, 0.0, 0.0, 0.0, cd, ps, seid]
        card = BDFCard(datai)
        n1 = GRID(card=card)

        x = 0.1
        y = 0.2
        z = 0.3
        self.assertEqual(n1.get_field(3), 0.0, msg="%s" % n1.get_field(3))
        self.assertEqual(n1.get_field(4), 0.0, msg="%s" % n1.get_field(4))
        self.assertEqual(n1.get_field(5), 0.0, msg="%s" % n1.get_field(5))

        self.assertEqual(n1.get_field(6), cd, msg="%s" % n1.get_field(6))
        self.assertEqual(n1.get_field(7), ps, msg="%s" % n1.get_field(7))
        self.assertEqual(n1.get_field(8), seid, msg="%s" % n1.get_field(8))
        n1.update_field(3, x)
        n1.update_field(4, y)
        n1.update_field(5, z)
        print("ps = %r" % n1.ps)
        self.assertEqual(n1.xyz[0], x)
        self.assertEqual(n1.xyz[1], y)
        self.assertEqual(n1.xyz[2], z)
        self.assertEqual(n1.ps, ps)
        self.assertEqual(n1.cd, cd)
        self.assertEqual(n1.seid, seid)

        self.assertEqual(n1.get_field(3), x, msg="%s" % n1.get_field(3))
        self.assertEqual(n1.get_field(4), y, msg="%s" % n1.get_field(4))
        self.assertEqual(n1.get_field(5), z, msg="%s" % n1.get_field(5))

        self.assertEqual(n1.get_field(6), cd, msg="%s" % n1.get_field(6))
        self.assertEqual(n1.get_field(7), ps, msg="%s" % n1.get_field(7))
        self.assertEqual(n1.get_field(8), seid, msg="%s" % n1.get_field(8))
Esempio n. 18
0
    def test_loads_sum_radial_01(self):
        model = BDF(debug=False)
        model.nodes[1] = GRID(1,
                              cp=1,
                              xyz=[0., 0., 0.],
                              cd=0,
                              ps='',
                              seid=0,
                              comment='')
        cid = 1
        origin = [0., 0., 0.]
        zaxis = [0., 0., 1.]
        xaxis = [1., 0., 0.]
        model.add_cord2c(cid,
                         rid=0,
                         origin=origin,
                         zaxis=zaxis,
                         xzplane=xaxis,
                         comment='')

        sid = 1
        node = 1
        cid = 1
        mag = 1.1
        xyz = [1., 0., 0.]
        unused_radial_force = model.add_force(sid,
                                              node,
                                              mag,
                                              xyz,
                                              cid=cid,
                                              comment='')

        sid = 2
        xyz = [1., 90., 0.]
        mag = 2.2
        unused_theta_force = model.add_force(sid,
                                             node,
                                             mag,
                                             xyz,
                                             cid=cid,
                                             comment='')
        model.cross_reference()

        p0 = 1
        eids = None
        nids = None

        loadcase_id = 1
        F1, M1 = sum_forces_moments(model,
                                    p0,
                                    loadcase_id,
                                    include_grav=False,
                                    xyz_cid0=None)
        F2, M2 = sum_forces_moments_elements(model,
                                             p0,
                                             loadcase_id,
                                             eids,
                                             nids,
                                             include_grav=False,
                                             xyz_cid0=None)
        assert np.allclose(F1, F2), 'F1=%s F2=%s' % (F1, F2)
        assert np.allclose(M1, M2), 'M1=%s M2=%s' % (M1, M2)

        F1_expected = np.array([1.1, 0., 0.])
        M1_expected = np.array([0., 0., 0.])
        self.assertTrue(
            allclose(F1_expected, F1), 'loadcase_id=%s F_expected=%s F1=%s' %
            (loadcase_id, F1_expected, F1))
        self.assertTrue(
            allclose(M1_expected, M1), 'loadcase_id=%s M_expected=%s M1=%s' %
            (loadcase_id, M1_expected, M1))

        loadcase_id = 2
        F1, M1 = sum_forces_moments(model,
                                    p0,
                                    loadcase_id,
                                    include_grav=False,
                                    xyz_cid0=None)
        F2, M2 = sum_forces_moments_elements(model,
                                             p0,
                                             loadcase_id,
                                             eids,
                                             nids,
                                             include_grav=False,
                                             xyz_cid0=None)
        assert np.allclose(F1, F2), 'F1=%s F2=%s' % (F1, F2)
        assert np.allclose(M1, M2), 'M1=%s M2=%s' % (M1, M2)
        F2_expected = np.array([0., 2.2, 0.])
        M2_expected = np.array([0., 0., 0.])
        self.assertTrue(
            allclose(F2_expected, F1), 'loadcase_id=%s F_expected=%s F1=%s' %
            (loadcase_id, F2_expected, F1))
        self.assertTrue(
            allclose(M2_expected, M1), 'loadcase_id=%s M_expected=%s M1=%s' %
            (loadcase_id, M2_expected, M1))
Esempio n. 19
0
def read_delaunay(points, tri, silent=True):
    """Read a Delaunay mesh

    Creates a mesh with the proper references for the ES-PIM using data from
    :class:`scipy.spatial.Delaunay`.


    Parameters
    ----------
    points : (N, ndim) array-like
        Cloud of N points with ndim coordinates (usually 2D or 3D), also passed
        as input to the Delaunay algorithm

    tri : :class:`scipy.spatial.qhull.Delaunay` object
        A triangular mesh generated by the Delaunay class


    Returns
    -------
    mesh : :class:`BDF`
        A pyNastran's :class:`BDF` object with the proper edge references used
        in the ES-PIM

    """
    msg('Reading Delaunay ouptut...', silent=silent)
    mesh = BDF()
    nodes = []
    nid = 0
    for pt in points:
        if len(pt) == 2:
            pt = np.array([pt[0], pt[1], 0.])
        nid += 1
        node = GRID(nid, cp=0, cd=0, xyz=pt)
        node.trias = set()
        node.edges = set()
        node.index = set()
        node.prop = None
        nodes.append(node)
        mesh.nodes[nid] = node
    eid = 0
    trias = []
    for i1, i2, i3 in tri.simplices:
        n1 = nodes[i1]
        n2 = nodes[i2]
        n3 = nodes[i3]
        eid += 1
        tria = CTRIA3(eid, 0, (n1.nid, n2.nid, n3.nid))
        tria.nodes = [n1, n2, n3]
        tria.nodes_ref = tria.nodes
        tria._node_ids(nodes=tria.nodes_ref)
        tria.edges = []
        tria.prop = None
        trias.append(tria)
        mesh.elements[eid] = tria
    edges = {}
    edges_ids = defaultdict(list)
    for tria in trias:
        for edge_id in tria.get_edge_ids():
            edges_ids[edge_id].append(tria)
    for (n1, n2), e_trias in edges_ids.items():
        edge = Edge(mesh.nodes[n1], mesh.nodes[n2])
        edge.trias = e_trias
        edges[(n1, n2)] = edge
        mesh.nodes[n1].edges.add(edge)
        mesh.nodes[n2].edges.add(edge)
    for edge in edges.values():
        for tria in edge.trias:
            tria.edges.append(edge)
    for tria in trias:
        for nid in tria.node_ids:
            mesh.nodes[nid].trias.add(tria.eid)
    mesh.edges = edges
    msg('finished!', silent=silent)
    return mesh