Exemplo n.º 1
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 = model.process_card(grid)
        model.add_card(card, card[0])

        card = model.process_card(coord)
        model.add_card(card, card[0])
        model.cross_reference()
        coord = model.Coord(7)
        #print(coord.origin)
        #print(coord.i, coord.j, coord.k)

        g = model.Node(20143)
        #print(g.Position(debug=False))
        xyz = g.Position()

        # 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.Coord(7)
        coord.T()
        self.assertTrue(array_equal(coord.T(), coord.beta_n(2)))
Exemplo n.º 2
0
    def test_cord2_bad_01(self):
        model = BDF(debug=False)
        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 cards:
            cid = card[1]
            if cid in [1, 2]:
                with self.assertRaises(RuntimeError):
                    model.add_card(card, card[0], is_list=True)
            else:
                model.add_card(card, card[0], is_list=True)

        # this runs because it's got rid=0
        cord4 = model.Coord(4)
        cord4.transformToGlobal([0., 0., 0.])

        # this doesn't run because rid != 0
        cord5 = model.Coord(5)
        with self.assertRaises(RuntimeError):
            cord5.transformToGlobal([0., 0., 0.])
        model.cross_reference()
Exemplo n.º 3
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 = model._process_card(grid)
        model.add_card(card, card[0])

        card = model._process_card(coord)
        model.add_card(card, card[0])
        model.cross_reference()
        coord = model.Coord(7)
        #print(coord.origin)
        #print(coord.i, coord.j, coord.k)

        node = model.Node(20143)
        xyzp1 = Position(node.xyz, node.cp, model)
        xyzp2 = Position(node.xyz, node.cp_ref, model)
        xyz = node.get_position()
        assert np.array_equal(xyz, xyzp1)
        assert np.array_equal(xyz, xyzp2)

        xyz_same = PositionWRT([1., 2., 3.], 100, 100, model)
        assert np.array_equal(xyz_same, [1., 2., 3.])

        xyz_wrt_p1 = PositionWRT(node.xyz, node.cp, 0, model)
        xyz_wrt_p2 = PositionWRT(node.xyz, node.cp_ref, 0, model)
        xyz_wrt = node.get_position_wrt(model, 0)
        assert np.array_equal(xyz, xyz_wrt_p1)
        assert np.array_equal(xyz, xyz_wrt_p2)
        assert np.array_equal(xyz, xyz_wrt)

        # 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.Coord(7)
        coord.beta_n(1)
        coord.beta_n(2)
        coord.beta_n(3)
        coord.beta_n(6)
        with self.assertRaises(AttributeError):
            self.assertTrue(array_equal(coord.T(), coord.beta_n(2)))
        #with self.assertRaises(NotImplementedError):
            #self.assertTrue(array_equal(coord.T(), coord.beta_n(2)))

        model2 = BDF(debug=False)
        cid = 7
        origin = [1.135, .089237, -.0676]
        zaxis = [.135, .089237, -.0676]
        xzplane = [1.135, .089237, .9324]
        coord2 = model2.add_cord2r(cid, origin, zaxis, xzplane, rid=0, comment='cord2r')
        coord2.comment = ''
        assert coord == coord2, 'coord:\n%r\ncoord2:\n%r' % (str(coord), str(coord2))
Exemplo n.º 4
0
    def test_cord2c_01(self):
        lines = [
            'CORD2C*                3               0              0.              0.',
            '*                     0.              0.              0.              1.*',
            '*                     1.              0.              1.'
        ]
        model = BDF(debug=False)
        card = model.process_card(lines)
        card = BDFCard(card)
        card = CORD2C(card)
        model.add_coord(card)

        lines = [
            'CORD2R         4       3     10.      0.      5.     10.     90.      5.',
            '             10.      0.      6.'
        ]
        card = model.process_card(lines)
        card = BDFCard(card)
        card = CORD2R(card)
        model.add_coord(card)
        model.cross_reference()

        cord2r = model.Coord(3)
        self.assertEquals(cord2r.Cid(), 3)
        self.assertEquals(cord2r.Rid(), 0)

        cord2r = model.Coord(4)
        self.assertEquals(cord2r.Cid(), 4)
        self.assertEquals(cord2r.Rid(), 3)

        self.assertTrue(allclose(cord2r.i, array([0., 0., 1.])))
        delta = cord2r.j - array([1., 1., 0.]) / 2**0.5
        self.assertTrue(allclose(cord2r.j, array([1., 1., 0.]) / 2**0.5), str(delta))
        delta = cord2r.k - array([-1., 1., 0.]) / 2**0.5
        self.assertTrue(allclose(cord2r.k, array([-1., 1., 0.]) / 2**0.5), str(delta))
Exemplo n.º 5
0
    def getNodes(self, grids, grids_expected, coords, debug=False):
        model = BDF(debug=False)

        for (nid, grid) in enumerate(grids):
            (cid, x, y, z) = grid
            model.add_card(['GRID', nid + 1, cid, x, y, z], 'GRID')
            gridObj = model.Node(nid + 1)
            if debug:
                print(gridObj)

        for (cid, coord) in enumerate(coords):
            #print coord
            (rid, x, y, z) = coord
            model.add_card(['CORD2R', cid + 1, rid] + x + y + z, 'CORD2R')
            coordObj = model.Coord(cid + 1)
            if debug:
                print(coordObj)

        model.cross_reference()

        for (i, grid) in enumerate(grids_expected):
            (cid, x, y, z) = grid
            node = model.Node(i + 1)
            pos = node.Position()
            n = array([x, y, z])

            msg = 'expected=%s actual=%s\n' % (n, pos)
            msg += 'n=%s grid=\n%s' % (i + 1, node)
            coord = node.cp
            msg += 'n=%s coord=\n%s' % (node.nid, coord)
            while coord.rid:
                msg += 'n=%s rcoord=\n%s' % (node.nid, coord.rid)
                coord = coord.rid
            assert allclose(n, pos), msg
Exemplo n.º 6
0
    def _get_nodes(self, grids, grids_expected, coords):
        model = BDF(debug=False)

        for grid in grids:
            (nid, cid, x, y, z) = grid
            model.add_card(['GRID', nid, cid, x, y, z], 'GRID')

        for coord in coords:
            (cid, rid, x, y, z) = coord
            model.add_card(['CORD2R', cid, rid] + x + y + z, 'CORD2R')
            coord_obj = model.Coord(cid)

        model.cross_reference()
        for i, grid in enumerate(grids_expected):
            nid, cid, x, y, z = grid
            node = model.Node(nid)
            pos = node.get_position()
            n = array([x, y, z])

            msg = 'i=%s expected=%s actual=%s\n' % (i, n, pos)
            msg += 'n=%s grid=\n%s' % (nid, node)
            coord = node.cp
            msg += 'n=%s coord=\n%s' % (node.nid, coord)
            while coord.rid:
                msg += 'n=%s rcoord=\n%s' % (node.nid, coord.rid)
                coord = coord.rid
            assert allclose(n, pos), msg
Exemplo n.º 7
0
def _coord(model: BDF, cid: int) -> Coord:
    """helper method"""
    if isinstance(cid, integer_types):
        cp_ref = model.Coord(cid)
    else:
        cp_ref = cid
    return cp_ref
Exemplo n.º 8
0
    def test_cord2r_1(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 = model.process_card(grid)
        model.add_card(card, card[0])

        card = model.process_card(coord)
        model.add_card(card, card[0])
        model.cross_reference()

        g = model.Node(20143)
        #print(g.Position(debug=False))

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

        msg = 'diff=%s' % diff
        assert allclose(diff, 0.), msg
        coord = model.Coord(7)
        coord.T()
        self.assertTrue(array_equal(coord.T(), coord.beta_n(2)))
Exemplo n.º 9
0
 def cross_reference(self, model: BDF) -> None:
     msg = f', which is required by BCONP line_id={self.contact_id}'
     #self.nodes_ref = model.Nodes(self.nodes, msg=msg)
     self.cid_ref = model.Coord(self.cid, msg=msg)
     if self.friction_id is not None:
         self.friction_id_ref = model.bfric[self.friction_id]
     self.slave_ref = model.blseg[self.slave]
     self.master_ref = model.blseg[self.master]
Exemplo n.º 10
0
    def cross_reference(self, model: BDF) -> None:
        """
        Cross links the card so referenced cards can be extracted directly

        Parameters
        ----------
        model : BDF()
            the BDF object
        """
        msg = ', which is required by CBUSH eid=%s' % self.eid
        self.nodes_ref = model.EmptyNodes(self.node_ids, msg=msg)
        self.pid_ref = model.Property(self.pid, msg=msg)
        if self.g0 is not None:
            self.g0_ref = model.Node(self.g0, msg=msg)
        if self.cid is not None:
            self.cid_ref = model.Coord(self.cid, msg=msg)
        if self.ocid is not None and self.ocid != -1:
            self.ocid_ref = model.Coord(self.ocid, msg=msg)
Exemplo n.º 11
0
    def cross_reference(self, model: BDF) -> None:
        """
        Cross refernece aerodynamic coordinate system.

        Parameters
        ----------
        model : BDF
            The BDF object.

        """
        msg = ', which is required by AERO'
        self.acsid_ref = model.Coord(self.acsid, msg=msg)
Exemplo n.º 12
0
def _asymmetrically_mirror_coords(model: BDF,
                                  mirror_model: BDF,
                                  cids_nominal_set: Set[int],
                                  cid_offset: int,
                                  plane: str = 'xz') -> None:
    """we'll leave i the same, flip j, and invert k"""
    # doesn't handle CORD1x

    coord_map = {
        'CORD1R': CORD1R,
        'CORD1C': CORD1C,
        'CORD1S': CORD1S,
        'CORD2R': CORD2R,
        'CORD2C': CORD2C,
        'CORD2S': CORD2S,
    }
    cids = list(cids_nominal_set)
    cids.sort()
    model.log.debug('asymmetrically mirroring coordinate systems')
    for cid in cids:

        coord = model.Coord(cid)
        if cid == 0:
            continue
        cid_new = cid + cid_offset
        model.log.debug(f'  cid={cid} -> {cid_new}')

        if coord.type in {'CORD2R', 'CORD2C', 'CORD2S'}:
            i, j, unused_k = coord.beta().copy()
            origin = coord.origin.copy()
            if plane == 'xz':
                origin[1] *= -1
                j[1] *= -1
            elif plane == 'xy':
                origin[2] *= -1
                j[2] *= -1
            else:
                model.log.warning(f'skipping coord_id={coord.cid}')
                return
            #k = np.cross(i, j)
            coord_obj = coord_map[coord.type]  # CORD2R/C/S
            coord_new = coord_obj.add_ijk(cid_new,
                                          origin=origin,
                                          i=i,
                                          j=j,
                                          k=None,
                                          rid=0,
                                          comment='')
        else:
            model.log.warning(f'skipping coord_id={coord.cid}')
            continue
        mirror_model.coords[cid_new] = coord_new
    return
Exemplo n.º 13
0
    def cross_reference(self, model: BDF) -> None:
        """
        Cross links the card so referenced cards can be extracted directly

        Parameters
        ----------
        model : BDF()
            the BDF object

        """
        msg = ', which is required by GMLOAD sid=%s' % self.sid
        self.cid_ref = model.Coord(self.Cid(), msg=msg)
Exemplo n.º 14
0
    def cross_reference(self, model: BDF) -> None:
        """
        Cross links the card so referenced cards can be extracted directly

        Parameters
        ----------
        model : BDF()
            the BDF object

        """
        msg = ', which is required by PFAST pid=%s' % self.pid
        if self.mcid != -1:
            self.mcid_ref = model.Coord(self.Mcid(), msg)
Exemplo n.º 15
0
    def test_cord2c_01(self):
        """simple CORD2R/CORD2C input/output test"""
        lines = [
            'CORD2C*                3               0              0.              0.',
            '*                     0.              0.              0.              1.*',
            '*                     1.              0.              1.'
        ]
        model = BDF(debug=False)
        card = model.process_card(lines)
        cardi = BDFCard(card)
        cord2c = CORD2C.add_card(cardi)
        model._add_coord_object(cord2c)

        lines = [
            'CORD2R         4       3     10.      0.      5.     10.     90.      5.',
            '             10.      0.      6.'
        ]
        card = model.process_card(lines)
        cardi = BDFCard(card)
        cord2r = CORD2R.add_card(cardi)
        model._add_coord_object(cord2r)
        model.cross_reference()

        cord2r_b = model.Coord(3)
        self.assertEqual(cord2r_b.Cid(), 3)
        self.assertEqual(cord2r_b.Rid(), 0)

        cord2r_c = model.Coord(4)
        self.assertEqual(cord2r_c.Cid(), 4)
        self.assertEqual(cord2r_c.Rid(), 3)

        self.assertTrue(allclose(cord2r_c.i, array([0., 0., 1.])))
        delta = cord2r_c.j - array([1., 1., 0.]) / 2**0.5
        self.assertTrue(allclose(cord2r_c.j,
                                 array([1., 1., 0.]) / 2**0.5), str(delta))
        delta = cord2r_c.k - array([-1., 1., 0.]) / 2**0.5
        self.assertTrue(allclose(cord2r_c.k,
                                 array([-1., 1., 0.]) / 2**0.5), str(delta))
Exemplo n.º 16
0
    def cross_reference(self, model: BDF) -> None:
        """
        Cross links the card so referenced cards can be extracted directly

        Parameters
        ----------
        model : BDF()
            the BDF object
        """
        msg = ', which is required by CBUSH2D eid=%s' % self.eid
        self.ga_ref = model.Node(self.ga, msg=msg)
        self.gb_ref = model.Node(self.gb, msg=msg)
        self.pid_ref = model.Property(self.pid)
        if self.cid is not None:
            self.cid_ref = model.Coord(self.cid, msg=msg)
Exemplo n.º 17
0
    def cross_reference(self, model: BDF) -> None:
        """
        Cross links the card so referenced cards can be extracted directly

        Parameters
        ----------
        model : BDF()
            the BDF object

        """
        msg = ', which is required by CONM2 eid=%s' % self.eid
        self.nid_ref = model.Node(self.nid, msg=msg)

        cid = self.Cid()
        if cid != -1:
            self.cid_ref = model.Coord(cid, msg=msg)
Exemplo n.º 18
0
    def cross_reference(self, model: BDF) -> None:
        """
        Cross links the card so referenced cards can be extracted directly

        Parameters
        ----------
        model : BDF()
            the BDF object

        """
        msg = ', which is required by CGAP eid=%s' % self.eid
        self.ga_ref = model.Node(self.ga, msg=msg)
        self.gb_ref = model.Node(self.gb, msg=msg)
        if self.g0:
            self.g0_ref = model.Node(self.g0, msg=msg)
            self.x = self.g0_ref.get_position()
        self.pid_ref = model.Property(self.pid, msg=msg)
        if self.cid:
            self.cid_ref = model.Coord(self.cid, msg=msg)
Exemplo n.º 19
0
    def test_cord1_01(self):
        model = BDF(debug=False)
        cards = [
            ['CORD1R', 1, 1, 2, 3],  # fails on self.k
            ['GRID', 1, 0, 0., 0., 0.],
            ['GRID', 2, 0, 1., 0., 0.],
            ['GRID', 3, 0, 1., 1., 0.],
        ]
        for card in cards:
            model.add_card(card, card[0], comment='comment', is_list=True)
        c1 = model.Coord(1)
        self.assertEqual(c1.G1(), 1)
        self.assertEqual(c1.G2(), 2)
        self.assertEqual(c1.G3(), 3)

        model.cross_reference()
        self.assertEqual(c1.G1(), 1)
        self.assertEqual(c1.G2(), 2)
        self.assertEqual(c1.G3(), 3)

        self.assertEqual(c1.node_ids, [1, 2, 3])
grid = vtk.vtkUnstructuredGrid()
Color = vtk.vtkFloatArray()
CntCONM2 = 0
for (eid, element) in model.elements.iteritems():
    CntCONM2 = CntCONM2 + 1

Scale = vtk.vtkFloatArray()

nidMap = {}
EidMap = {}

i = 0
for (nid, node) in model.nodes.iteritems():
    #node = model.Node(1)
    cp = node.Cp()
    coord = model.Coord(cp)
    pos = coord.transformToGlobal(node.xyz)
    Coord = []
    gpos = pos[0]
    x = float(gpos[0])
    y = float(gpos[1])
    z = float(gpos[2])
    Coord.append(x)
    Coord.append(y)
    Coord.append(z)
    test = points.InsertNextPoint(*Coord)
    Color.InsertTuple1(test, 0)
    nidMap[nid] = i
    i = i + 1
grid.SetPoints(points)