Ejemplo n.º 1
0
    def _get_nodes(self, grids, grids_expected, coords):
        model = BDF(debug=False)

        card_count = {
            'GRID': len(grids),
            'CORD2R': len(coords),
        }
        cards = {'GRID': [], 'CORD2R': []}
        for grid in grids:
            nid, cid, x, y, z = grid
            card = ['GRID', nid, cid, x, y, z]
            cards['GRID'].append(('', card))

        for coord in coords:
            cid, rid, x, y, z = coord
            card = ['CORD2R', cid, rid] + x + y + z
            cards['CORD2R'].append(('', card))
            #coordObj = model.coords.slice_by_coord_id(cid)
        model.add_cards(cards, card_count)
        model.build()

        for (i, grid) in enumerate(grids_expected):
            nid, cid, x, y, z = grid
            nodes = model.grid
            pos = nodes.get_position_by_node_id([nid])[0]
            n = array([x, y, z])
            msg = 'i=%s expected=%s actual=%s\n' % (i, n, pos)
            #print(msg)
            assert allclose(n, pos), msg
Ejemplo n.º 2
0
    def test_cord2r_02(self):
        grid = ['GRID       20143       7 -9.31-4  .11841 .028296']
        coord = [
            'CORD2R         7           1.135 .089237  -.0676    .135 .089237  -.0676',
            '           1.135 .089237   .9324'
        ]

        model = BDF(debug=False)
        card_count = {
            'GRID': 1,
            'CORD2R': 1,
        }
        cards = {
            'CORD2R': [('', coord)],
            'GRID': [('', grid)],
        }
        model.add_cards(cards, card_count)
        model.build()

        g = model.grid.slice_by_node_id(20143)
        #xyz = g.get_position()
        xyz = model.coords.get_global_position_by_node_id(20143, g.cp[0])[0]

        # by running it through Patran...
        #GRID     20143          1.1067  .207647 -.068531
        expected = array([1.106704, .207647, -0.068531])
        diff = xyz - expected

        msg = '\nexpected=%s \nactual  =%s \ndiff    =%s' % (expected, xyz,
                                                             diff)
        assert allclose(diff, 0.), msg
        coord = model.coords.slice_by_coord_id(7)
        T = coord.T[0, :, :]
Ejemplo n.º 3
0
    def test_cord1s_01(self):
        cord1s = ['cord1s,2, 1,4,3']
        grids = [
            ['GRID', 4, 0, 0.0, 0., 0.],
            ['GRID', 3, 0, 0.0, 0., 1.],
            ['GRID', 1, 0, 0.0, 1., 0.],
        ]
        card_count = {
            'CORD1S': 1,
            'GRID': 3,
        }
        model = BDF(debug=False)
        cards = {
            'GRID': [
                ('', grids[0]),
                ('', grids[1]),
                ('', grids[2]),
            ],
            'CORD1S': [('', cord1s)]
        }
        model.add_cards(cards, card_count)
        model.build()

        size = 8
        bdf_file = StringIO()
        card = model.coords.slice_by_coord_id(2)
        self.assertEquals(card.get_cid_by_coord_id(), 2)
        self.assertEquals(card.get_rid_by_coord_id(), 0)
        card.write_card(bdf_file, size=8, is_double=False)
Ejemplo n.º 4
0
    def test_cord2c_01(self):
        lines_a = [
            'CORD2C*                3               0              0.              0.',
            '*                     0.              0.              0.              1.*',
            '*                     1.              0.              1.'
        ]
        lines_b = [
            'CORD2R         4       3     10.      0.      5.     10.     90.      5.',
            '             10.      0.      6.'
        ]
        card_count = {
            'CORD2C': 1,
            'CORD2R': 1,
        }

        model = BDF(debug=False)
        cards = {
            'CORD2C': ['', lines_a],
            'CORD2R': ['', lines_b],
        }
        model.add_cards(cards, card_count)
        #model.allocate(cards, card_count)
        card = model.add_card(lines_a, 'CORD2C', is_list=False)
        card = model.add_card(lines_b, 'CORD2R', is_list=False)
        model.build()

        cord2r = model.coords.slice_by_coord_id(3)
        #print(type(cord2r))
        self.assertEquals(cord2r.get_cid_by_coord_id(), 3)
        self.assertEquals(cord2r.get_rid_by_coord_id(), 0)

        cord2r = model.coords.slice_by_coord_id(4)
        #print(type(cord2r))
        self.assertEquals(cord2r.get_cid_by_coord_id(), 4)
        self.assertEquals(cord2r.get_rid_by_coord_id(), 3)

        i = model.coords.get_coord_index_by_coord_id(4)
        T = model.coords.T[i, :, :].reshape(3, 3)
        Ti = T[0, :]
        Tj = T[1, :]
        Tk = T[2, :]
        msg = 'i=%s expected=(0., 0., 1.)' % Ti
        self.assertTrue(allclose(Ti, array([0., 0., 1.])), msg)
        delta = Tj - array([1., 1., 0.]) / 2**0.5
        self.assertTrue(allclose(Tj, array([1., 1., 0.]) / 2**0.5), str(delta))
        delta = Tk - array([-1., 1., 0.]) / 2**0.5
        self.assertTrue(allclose(Tk,
                                 array([-1., 1., 0.]) / 2**0.5), str(delta))
Ejemplo n.º 5
0
    def test_cord2r_bad_01(self):
        model = BDF(debug=True)

        card_count = {
            'GRID': 4,
            'CORD2R': 3,
        }
        cards = {'GRID': [], 'CORD2R': []}
        grids = [
            ['GRID', 1, 0],
            ['GRID', 20, 0],
            ['GRID', 30, 0],
            ['GRID', 11, 5],
        ]
        for grid in grids:
            cards['GRID'].append(('', grid))

        coord_cards = [
            ['CORD2R', 1, 0, 0., 0., 0., 0., 0., 0., 0., 0.,
             0.],  # fails on self.k
            ['CORD2R', 2, 0, 0., 0., 0., 1., 0., 0., 0., 0.,
             0.],  # fails on normalize self.j
            ['CORD2R', 3, 0, 0., 0., 0., 1., 0., 0., 1., 1., 0.],  # passes
            ['CORD2R', 4, 0, 0., 1., 0., 1., 0., 0., 1., 1., 0.],  # passes
            ['CORD2R', 5, 4, 0., 1., 0., 1., 0., 0., 1., 1., 0.],  # passes
        ]
        for card in coord_cards:
            card_name = card[0]
            cid = card[1]
            if cid in [1, 2]:
                with self.assertRaises(RuntimeError):
                    cards[card_name].append(('', card))
            else:
                cards[card_name].append(('', card))
        model.add_cards(cards, card_count)
        model.build()

        # this runs because it's got rid=0
        coords = model.coords  #.slice_by_coord_id(4)
        coords.transform_node_id_to_global_xyz(30)  # nid
        coords.transform_node_id_to_global_xyz([30, 1, 11])  # [nid, nid, nid]
        coords.transform_node_id_to_local_by_coord_id([30, 1, 11],
                                                      4)  # [nid, ...], cp_goal
        coords.transform_node_id_to_local_by_coord_id([30, 1, 11],
                                                      0)  # [nid, ...], cp_goal

        xyz = [0., 0., 0.]
        coords.transform_xyz_to_global_by_coord_id(xyz, 4)  # [xyz], cp_initial
        xyz = [
            [0., 0., 0.],
            [1., 1., 1.],
        ]
        coords.transform_xyz_to_global_by_coord_id(xyz, 4)  # [xyz], cp_initial

        # global from global
        coords.transform_xyz_to_global_by_coord_id(xyz, 0)  # [xyz], cp_initial

        # this doesn't run because rid != 0
        with self.assertRaises(RuntimeError):
            # cp=0 doesn't exist
            coords.transform_xyz_to_global_by_coord_id(xyz, 2)