Example #1
0
    def add_card(self, card_lines, card_name, comment='', is_list=True):
        card_name = card_name.upper()
        self._increase_card_count(card_name)
        if card_name in ['DEQATN']:
            card_obj = card_lines
            card = card_lines
        else:
            if is_list:
                fields = card_lines
            else:
                fields = to_fields(card_lines, card_name)

            # apply OPENMDAO syntax
            if self._is_dynamic_syntax:
                fields = [self._parse_dynamic_syntax(field) if '%' in
                          field[0:1] else field for field in fields]

                card = wipe_empty_fields([interpret_value(field, fields)
                                          if field is not None
                                          else None for field in fields])
            else:  # leave everything as strings
                card = wipe_empty_fields(fields)
            card_obj = BDFCard(card)

        if card_name == 'HYPER':
            hyper = HYPER(card_obj, comment)
            self.hyper[hyper.pid] = hyper
            return
        elif card_name == 'FLOW':
            flow = FLOW(card_obj, comment)
            self.flow[flow.flow_id] = flow
            return
        BDF.add_card(self, card, card_name, comment=comment, is_list=True)
Example #2
0
    def test_grid_01(self):
        nid = 1
        cp = 2
        cd = 0
        ps = ''
        seid = 0
        card_count = {'GRID': 1,}

        model = BDF(debug=False)
        model.allocate(card_count)
        data1 = BDFCard(['GRID', nid, cp, 0., 0., 0., cd, ps, seid])

        nodes = model.grid
        nodes.add(data1)

        #print(n1)
        f = StringIO()
        nodes.write_card(f, size=8, write_header=False)
        nodes.write_card(f, size=16, write_header=False)
        nodes.write_card(f, size=16, is_double=True, write_header=False)

        # small field
        f = StringIO()
        nodes.write_card(f, size=8, write_header=False)
        msg = f.getvalue()
        card = 'GRID           1       2      0.      0.      0.\n'
        self.assertCardEqual(msg, card)

        # large field
        f = StringIO()
        nodes.write_card(f, size=16, write_header=False)
        card = ('GRID*                  1               2              0.              0.\n'
                '*                     0.\n')
        msg = f.getvalue()
        self.assertCardEqual(msg, card)
Example #3
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
Example #4
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, :, :]
Example #5
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()
Example #6
0
    def test_grid_01(self):
        nid = 1
        cp = 2
        cd = 0
        ps = ''
        seid = 0
        card_count = {'GRID': 1,}

        model = BDF()
        model.allocate(card_count)
        data1 = BDFCard(['GRID', nid, cp, 0., 0., 0., cd, ps, seid])

        nodes = model.grid
        nodes.add(data1)

        #print n1
        f = StringIO()
        nodes.write_bdf(f, size=8, write_header=False)
        nodes.write_bdf(f, size=16, write_header=False)
        nodes.write_bdf(f, size=16, is_double=True, write_header=False)

        # small field
        f = StringIO()
        nodes.write_bdf(f, size=8, write_header=False)
        msg = f.getvalue()
        card = 'GRID           1       2      0.      0.      0.\n'
        self.assertCardEqual(msg, card)

        # large field
        f = StringIO()
        nodes.write_bdf(f, size=16, write_header=False)
        card = ('GRID*                  1               2              0.              0.\n'
                '*                     0.\n')
        msg = f.getvalue()
        self.assertCardEqual(msg, card)
Example #7
0
    def test_cord1c_01(self):
        lines = ['cord1c,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 = {
            'CORD1C': 1,
            'GRID': 3,
        }

        model = BDF(debug=False)
        model.allocate(card_count)
        model.add_card(lines, 'CORD1C', is_list=False)
        for grid in grids:
            model.add_card(grid, grid[0], is_list=True)
        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)
Example #8
0
    def test_combo_1(self):
        model = BDF(debug=False, log=None)
        bdfname = os.path.join(testpath, 'test_mass.dat')
        model.read_bdf(bdfname, include_dir=None, xref=True)

        # these are valid
        eids, mass = model.elements.get_mass_by_element_id([8, 9])
        print('massA = %s' % mass)
        eids, mass = model.elements.get_mass_by_element_id(range(1, 10))
        print('massB = %s' % mass)

        # no analysis - out of range
        elements = model.elements[[100000, 100001]]
        eids, mass = model.elements.get_mass_by_element_id(range(100000, 100005))
        print('elementsC = %s' % eids)
        print('massC = %s' % mass)

        eids, mass = model.elements.get_mass_by_element_id(range(-10, -5))
        print('elementsD = %s' % eids)
        print('massD = %s' % mass)

        print('-------------------------')
        eids, mass = model.elements.get_mass_by_element_id(range(-3, 20))
        print('massE = %s' % mass)
        print('eidsE = %s' % eids)
        print('\neid   mass')
        print('----------')
        for eidi, massi in zip(eids, mass):
            print('%-5s %-5s' % (eidi, massi))
Example #9
0
    def getNodes(self, grids, grids_expected, coords):
        model = BDF(debug=False)

        card_count = {
            'GRID' : len(grids),
            'CORD2R' : len(coords),
        }
        model.allocate(card_count)
        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')
            #coordObj = model.Coord(cid)

        model.cross_reference()

        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
Example #10
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)
Example #11
0
def run_fem2(bdf_model, out_model, xref, punch, sum_load, size, is_double, reject, debug=False, log=None):
    """
    Reads/writes the BDF to verify nothing has been lost

    Parameters
    ----------
    bdf_model : str
        the filename to run
    xref : bool
       xrefs
    punch : bool
       punches
    """
    assert os.path.exists(bdf_model), bdf_model
    assert os.path.exists(out_model), out_model
    fem2 = BDF(debug=debug, log=log)
    fem2.log.info("starting fem2")
    sys.stdout.flush()
    try:
        fem2.read_bdf(out_model, xref=xref, punch=punch)
    except:
        print("failed reading %r" % out_model)
        raise

    # fem2.sumForces()
    # fem2.sumMoments()
    out_model2 = bdf_model + "_out2"
    fem2.write_bdf(out_model2, interspersed=True)
    # fem2.writeAsCTRIA3(out_model_2)
    os.remove(out_model2)
    return fem2
Example #12
0
    def getNodes(self, grids, grids_expected, coords, debug=False):
        model = BDF(debug=False)

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

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

        model.cross_reference()

        for (i, grid) in enumerate(grids_expected):
            (nid, cid, x, y, z) = grid
            nodes = model.grid
            pos = nodes.get_positions([nid])
            n = array([x, y, z])
            msg = 'i=%s expected=%s actual=%s\n' % (i, n, pos)
            print(msg)
            assert allclose(n, pos), msg
Example #13
0
    def test_cord1_01(self):
        model = BDF(debug=False)
        card_count = {
            'CCORD1R' : 1,
            'GRID' : 3,
        }
        model.allocate(card_count)
        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.assertEquals(c1.G1(), 1)
        self.assertEquals(c1.G2(), 2)
        self.assertEquals(c1.G3(), 3)

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

        self.assertEquals(c1.NodeIDs(), [1, 2, 3])
Example #14
0
    def test_cord1c_01(self):
        lines = ['cord1c,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 = {
            'CORD1C' : 1,
            'GRID' : 3,
        }

        model = BDF(debug=False)
        model.allocate(card_count)
        model.add_card(lines, 'CORD1C', is_list=False)
        for grid in grids:
            model.add_card(grid, grid[0], is_list=True)
        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)
Example #15
0
    def test_cord2_rcs_03(self):
        """
        all points are located at <30,40,50>
        """
        model = BDF(debug=False)
        #card_count = {
        #'GRID' : 3,
        #'CORD2R' : 1,
        #'CORD2C' : 1,
        #'CORD2S' : 2,
        #}

        card_lines = [
            [
                'CORD2S*                2               0              0.              0.',
                '*                     0.              0.              0.              1.*       ',
                '*                     1.              0.              1.',
            ],
            [
                #'$ Femap with NX Nastran Coordinate System 30 : rectangular in spherical',
                'CORD2R*               30               2             14.             30.',
                '*                    70.    13.431863852   32.1458443949   75.2107442927*       ',
                '*          14.4583462334   33.4569982885   68.2297989286',
            ],
            [
                #'$ Femap with NX Nastran Coordinate System 31 : cylindrical in spherical',
                'CORD2C*               31               2              3.             42.',
                '*                  -173.   2.86526881213   45.5425615252   159.180363517*       ',
                '*          3.65222385965   29.2536614627  -178.631312271',
            ],
            [
                #'$ Femap with NX Nastran Coordinate System 32 : spherical in spherical',
                'CORD2S*               32               2             22.             14.',
                '*                    85.   22.1243073983   11.9537753718   77.9978191005*       ',
                '*          21.0997242967   13.1806120497   88.4824763008',
            ],
            [
                'GRID*                 30              30   40.7437952957  -23.6254877994',
                '*           -33.09784854               0',
            ],
            [
                'GRID*                 31              31   62.9378078196   15.9774797923',
                '*          31.0484428362               0',
            ],
            [
                'GRID*                 32              32   53.8270847449   95.8215692632',
                '*          159.097767463               0',
            ],
        ]
        cards, card_count = model.add_cards_lines(card_lines)
        model.allocate(card_count, cards)
        model.build()

        for nid in model.nodes:
            a = array([30., 40., 50.])
            b = model.Node(nid).get_position()
            self.assertTrue(
                allclose(array([30., 40., 50.]),
                         model.Node(nid).get_position()), str(a - b))
Example #16
0
    def test_cpenta_01(self):
        model = BDF()
        lines = ['CPENTA,85,22,201,202,203,205,206,207']
        card = model.process_card(lines)
        card = BDFCard(card)

        size = 8
        f = StringIO()
        penta = CPENTA6(model)
        penta.allocate(1)
        penta.add(card)
        penta.write_bdf(f, size)
        #card.rawFields()
        print(f.getvalue())
Example #17
0
    def test_ctetra_01(self):
        model = BDF()
        lines = ['CTETRA,85,22,201,202,203,205']
        card = model.process_card(lines)
        card = BDFCard(card)

        size = 8
        f = StringIO()
        hexa = CTETRA4(model)
        hexa.allocate(1)
        hexa.add(card)
        hexa.write_bdf(f, size)
        #card.rawFields()
        print(f.getvalue())
Example #18
0
    def test_cpenta_01(self):
        model = BDF()
        lines = ['CPENTA,85,22,201,202,203,205,206,207']
        card = model.process_card(lines)
        card = BDFCard(card)

        size = 8
        f = StringIO()
        penta = CPENTA6(model)
        penta.allocate(1)
        penta.add(card)
        penta.write_bdf(f, size)
        #card.rawFields()
        print(f.getvalue())
Example #19
0
def run_bdf(folder, bdf_filename, debug=False, xref=True, check=True, punch=False,
            cid=None, meshForm='combined', isFolder=False, print_stats=False,
            sum_load=False, size=8, precision='single',
            reject=False, dynamic_vars=None):
    if dynamic_vars is None:
        dynamic_vars = {}
    bdfModel = str(bdf_filename)
    print("bdfModel = %r" % bdfModel)
    if isFolder:
        bdfModel = os.path.join(test_path, folder, bdf_filename)

    assert os.path.exists(bdfModel), '%r doesnt exist' % bdfModel

    print("before read bdf, Memory usage: %s (Mb) " % memory_usage_psutil())
    #print('before read bdf, Memory usage: %s (kb)' % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
    fem1 = BDF(debug=debug, log=None)
    if dynamic_vars:
        fem1.set_dynamic_syntax(dynamic_vars)

    fem1.log.info('starting fem1')
    sys.stdout.flush()
    fem2 = None
    diffCards = []
    try:
        outModel = run_fem1(fem1, bdfModel, meshForm, xref, punch, sum_load, size, precision, cid)
        fem2 = run_fem2(bdfModel, outModel, xref, punch, sum_load, size, precision, reject, debug=debug, log=None)
        diffCards = compare(fem1, fem2, xref=xref, check=check, print_stats=print_stats)

    except KeyboardInterrupt:
        sys.exit('KeyboardInterrupt...sys.exit()')
    #except IOError:
        #pass
    #except AttributeError:  # only temporarily uncomment this when running lots of tests
        #pass
    #except SyntaxError:  # only temporarily uncomment this when running lots of tests
        #pass
    #except AssertionError:  # only temporarily uncomment this when running lots of tests
        #pass
    except SystemExit:
        sys.exit('sys.exit...')
    except:
        #exc_type, exc_value, exc_traceback = sys.exc_info()
        #print "\n"
        traceback.print_exc(file=sys.stdout)
        #print msg
        print("-" * 80)
        raise

    print("-" * 80)
    return (fem1, fem2, diffCards)
Example #20
0
    def test_ctetra_01(self):
        model = BDF()
        lines = ['CTETRA,85,22,201,202,203,205']
        card = model.process_card(lines)
        card = BDFCard(card)

        size = 8
        f = StringIO()
        hexa = CTETRA4(model)
        hexa.allocate(1)
        hexa.add(card)
        hexa.write_bdf(f, size)
        #card.rawFields()
        print(f.getvalue())
Example #21
0
    def test_chexa_01(self):
        model = BDF()
        lines = ['CHEXA,85,22,201,202,203,205,206,207,+PN2', '+PN2,209,210']
        card = model.process_card(lines)
        card = BDFCard(card)

        size = 8
        f = StringIO()
        hexa = CHEXA8(model)
        hexa.allocate(1)
        hexa.add(card)
        hexa.write_bdf(f, size)
        #card.rawFields()
        print(f.getvalue())
Example #22
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)
        model.coords.add_cord2c(card)

        lines = [
            'CORD2R         4       3     10.      0.      5.     10.     90.      5.',
            '             10.      0.      6.'
        ]
        card = model.process_card(lines)
        card = BDFCard(card)
        model.coords.add_cord2r(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))
Example #23
0
    def test_cord2_rcs_01(self):
        """
        all points are located at <30,40,50>
        """
        model = BDF(debug=False)
        card_count = {
            'GRID': 3,
            'CORD2R': 1,
            'CORD2C': 1,
            'CORD2S': 1,
        }
        cards = []
        card_lines = [
            [
                #'$ Femap with NX Nastran Coordinate System 10 : rectangular defined in a rectangular',
                'CORD2R*               10               0             10.              5.',
                '*                     3.   10.3420201433   4.53015368961   3.81379768136*       ',
                '*          10.7198463104   5.68767171433   3.09449287122',
            ],
            [
                #'$ Femap with NX Nastran Coordinate System 11 : cylindrical defined in rectangular',
                'CORD2C*               11               0              7.              3.',
                '*                     9.   7.64278760969   2.73799736977   9.71984631039*       ',
                '*          7.75440650673   3.37968226211   8.46454486422',
            ],
            [
                #'$ Femap with NX Nastran Coordinate System 12 : spherical defined in rectangular',
                'CORD2S*               12               0             12.              8.',
                '*                     5.   12.6427876097   7.86697777844   5.75440650673*       ',
                '*          12.6634139482   8.58906867688   4.53861076379',
            ],
            [
                'GRID*                 10              10   42.9066011565   34.2422137135',
                '*          28.6442730262               0',
            ],
            [
                'GRID*                 11              11   48.8014631871   78.8394787869',
                '*          34.6037164304               0',
            ],
            [
                'GRID*                 12              12   58.0775343829   44.7276544324',
                '*          75.7955331161               0',
            ],
        ]
        cards, card_count = model.add_cards_lines(card_lines)
        model.allocate(card_count, cards)
        model.build()

        for nid in model.nodes:
            a = array([30., 40., 50.])
            b = model.Node(nid).get_position()
            self.assertTrue(
                allclose(array([30., 40., 50.]),
                         model.Node(nid).get_position()), str(a - b))
Example #24
0
    def test_cpenta_02(self):
        model = BDF()
        lines = ['CPENTA,85,22,201,202,203,205,206,207,+PN2',
                 '+PN2,209,210,217,  ,  ,  ,213,214,218']
        card = model.process_card(lines)
        card = BDFCard(card)

        size = 8
        f = StringIO()
        penta = CPENTA15(model)
        penta.allocate(1)
        penta.add(card)
        penta.write_card(f, size)
        #card.rawFields()
        print(f.getvalue())
Example #25
0
    def test_bad_01(self):
        model = BDF(debug=False, log=None)
        bdfname = os.path.join(testpath, 'test_mass.dat')
        model.read_bdf(bdfname, xref=True)

        # this passes silently
        print(model.elements[['cat']])

        # this does not
        with self.assertRaises(TypeError):
            print(model.elements[None])

        #print('elements = %r' % model.elements['cat'])
        with self.assertRaises(KeyError):
            model.elements['cat']
Example #26
0
    def test_chexa_02(self):
        model = BDF()
        lines = ['CHEXA,85,22,201,202,203,205,206,207,+PN2',
                 '+PN2,209,210,217,  ,  ,  ,213,214,218']
        card = model.process_card(lines)
        card = BDFCard(card)

        size = 8
        f = StringIO()
        hexa = CHEXA20(model)
        hexa.allocate(1)
        hexa.add(card)
        hexa.write_bdf(f, size)
        #card.rawFields()
        print(f.getvalue())
Example #27
0
    def test_crod_01(self):
        model = BDF(debug=debug)
        model.allocate({"CROD": 1})

        lines = ["CROD          10     100      10       2"]
        model.add_card(lines, "CROD", is_list=False)

        size = 8
        f = StringIO()
        # card = CROD(card)
        card = model.crod.slice_by_element_id([10])
        card.write_card(f, size)
        # card.rawFields()
        self.assertEquals(card.get_element_id_by_element_index(), 10)
        self.assertEquals(card.get_property_id_by_element_index(), 100)
Example #28
0
    def test_bad_01(self):
        model = BDF(debug=False, log=None)
        bdfname = os.path.join(testpath, 'test_mass.dat')
        model.read_bdf(bdfname, include_dir=None, xref=True)

        # this passes silently
        print(model.elements[['cat']])

        # this does not
        with self.assertRaises(TypeError):
            print(model.elements[None])

        #print(model.get_elements('cat'))
        with self.assertRaises(KeyError):
            model.get_elements('cat')
Example #29
0
    def test_grid_04(self):
        model = BDF()
        nid = 1
        cp = 2
        cd = 0
        ps = ''
        seid = 0
        card_count = {'GRID': 2,}

        model = BDF()
        model.allocate(card_count)

        nodes = model.grid
        data1 = BDFCard(['GRID', nid, cp, 0., 0., 0., cd, ps, seid])
        data2 = BDFCard(['GRID', nid+1, cp, 0., 0., 0., cd, ps, seid])
        data3 = BDFCard(['GRID', nid+2, cp, 0., 0., 0., cd, ps, seid])
        data4 = BDFCard(['GRID', nid+3, cp, 0., 0., 0., cd, ps, seid])
        nodes.add(data1)
        nodes.add(data2)
        nodes.resize(4, refcheck=False)
        #print('nodes.node_id = %s' % nodes.node_id)
        nodes.add(data3)
        self.assertEqual(len(nodes.node_id), 4)
        self.assertEqual(nodes.n, 4)
        self.assertEqual(nodes.i, 3)
        nodes.shrink(refcheck=False)
        #print('nodes.node_id = %s' % nodes.node_id)
        self.assertEqual(len(nodes.node_id), 3)
        self.assertEqual(nodes.n, 3)
        self.assertEqual(nodes.i, 3)

        nodes.resize(4, refcheck=False)
        nodes.add(data4)
        self.assertEqual(len(nodes.node_id), 4)
        self.assertEqual(nodes.n, 4)
        self.assertEqual(nodes.i, 4)

        f = StringIO()
        nodes.write_bdf(f, size=8, write_header=False)
        #print(f.getvalue())

        nodes.resize(2, refcheck=False)
        self.assertEqual(len(nodes.node_id), 2)
        self.assertEqual(nodes.n, 2)
        self.assertEqual(nodes.i, 2)

        f = StringIO()
        nodes.write_bdf(f, size=8, write_header=False)
Example #30
0
    def test_mass_solid_1(self):  # passes
        model = BDF(debug=False, log=None)
        bdfname = os.path.join(testpath, 'test_mass.dat')
        model.read_bdf(bdfname, xref=True)

        # hexa - psolid - nsm = 0
        #print(model.elements[7:8])
        #print(model.elements[[7,8]])
        model.elements[7:9]
        model.elements[7:9:2]
        model.elements[1:100]
        #hexa = model.get_elements(7)
        #hexa = model.get_elements(7)
        #print(hexa)
        hexa = model.elements[7]
        print('hexa =', hexa)
        mass = 0.2
        volume = 2.  # l * w * h = 1 * 1 * 2
        rho = 0.1
        E = 1.0
        G = 2.0
        nu = 3.0
        centroid = array([0.5, 0.5, 1.0])
        self.verify_psolid_element(hexa, mass, volume, centroid, rho, E, G, nu)

        # tetra - psolid
        tetra = model.elements[8]
        mass = 1 / 30.
        volume = 1 / 3.  # 1/3 * b * h = 1/3 * 0.5 * 2.0
        rho = 0.1
        E = 1.0
        G = 2.0
        nu = 3.0
        centroid = array([0.5, 0.25, 0.5])
        self.verify_psolid_element(tetra, mass, volume, centroid, rho, E, G,
                                   nu)

        # penta - psolid
        penta = model.elements[9]
        mass = 0.1
        volume = 1.0  # b * h = 0.5 * 2
        rho = 0.1
        E = 1.0
        G = 2.0
        nu = 3.0
        centroid = array([2 / 3., 1 / 3., 1.])
        self.verify_psolid_element(penta, mass, volume, centroid, rho, E, G,
                                   nu)
Example #31
0
    def test_ctetra_02(self):
        model = BDF(debug=False)
        lines = [
            'CTETRA,85,22,201,202,203,205,206,207,+PN2', '+PN2,209,210,217'
        ]
        card = model.process_card(lines)
        card = BDFCard(card)

        size = 8
        f = StringIO()
        hexa = CTETRA10(model)
        hexa.allocate(1)
        hexa.add(card)
        hexa.write_card(f, size)
        #card.rawFields()
        print(f.getvalue())
Example #32
0
 def _write_common(self, size, card_writer):
     msg = ''
     for fid, flow in sorted(iteritems(self.flow)):
         msg += str(flow)
     for fid, subsonic in sorted(iteritems(self.subsonic)):
         msg += str(subsonic)
     msg += BDF._write_common(self, size, card_writer)
     return msg
Example #33
0
 def test_cord1r_02(self):
     model = BDF(debug=False)
     card_count = {
         'CORD1R' : 1,
         'GRID' : 3,
     }
     #model.allocate(card_count)
     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\n', is_list=True)
     model.build()
     c1 = model.coords.slice_by_coord_id(1)
Example #34
0
 def _write_common(self, size, card_writer):
     msg = ''
     for fid,flow in sorted(iteritems(self.flow)):
         msg += str(flow)
     for fid,subsonic in sorted(iteritems(self.subsonic)):
         msg += str(subsonic)
     msg += BDF._write_common(self, size, card_writer)
     return msg
Example #35
0
 def _write_common(self, size, card_writer):
     msg = ''
     for fid,flow in sorted(iteritems(self.flow)):
         msg += str(flow)
     for fid,hyper in sorted(iteritems(self.hyper)):
         msg += str(hyper)
     msg += BDF._write_common(self, size, card_writer)
     return msg
Example #36
0
    def test_cpenta_02(self):
        model = BDF(debug=False)
        lines = [
            'CPENTA,85,22,201,202,203,205,206,207,+PN2',
            '+PN2,209,210,217,  ,  ,  ,213,214,218'
        ]
        card = model.process_card(lines)
        card = BDFCard(card)

        size = 8
        f = StringIO()
        penta = CPENTA15(model)
        penta.allocate(1)
        penta.add(card)
        penta.write_card(f, size)
        #card.rawFields()
        print(f.getvalue())
Example #37
0
    def test_mass_solid_1(self):  # passes
        model = BDF(debug=False, log=None)
        bdfname = os.path.join(testpath, 'test_mass.dat')
        model.read_bdf(bdfname, xref=True)

        # hexa - psolid - nsm = 0
        #print(model.elements[7:8])
        #print(model.elements[[7,8]])
        model.elements[7:9]
        model.elements[7:9:2]
        model.elements[1:100]
        #hexa = model.get_elements(7)
        #hexa = model.get_elements(7)
        #print(hexa)
        hexa = model.elements[7]
        print('hexa =', hexa)
        mass = 0.2
        volume = 2. # l * w * h = 1 * 1 * 2
        rho = 0.1
        E = 1.0
        G = 2.0
        nu = 3.0
        centroid = array([0.5, 0.5, 1.0])
        self.verify_psolid_element(hexa, mass, volume, centroid, rho, E, G, nu)

        # tetra - psolid
        tetra = model.elements[8]
        mass = 1/30.
        volume = 1/3. # 1/3 * b * h = 1/3 * 0.5 * 2.0
        rho = 0.1
        E = 1.0
        G = 2.0
        nu = 3.0
        centroid = array([0.5, 0.25, 0.5])
        self.verify_psolid_element(tetra, mass, volume, centroid, rho, E, G, nu)

        # penta - psolid
        penta = model.elements[9]
        mass = 0.1
        volume = 1.0 # b * h = 0.5 * 2
        rho = 0.1
        E = 1.0
        G = 2.0
        nu = 3.0
        centroid = array([2/3., 1/3., 1.])
        self.verify_psolid_element(penta, mass, volume, centroid, rho, E, G, nu)
Example #38
0
 def _write_common(self, size, card_writer):
     msg = ''
     for fid, flow in sorted(iteritems(self.flow)):
         msg += str(flow)
     for fid, hyper in sorted(iteritems(self.hyper)):
         msg += str(hyper)
     msg += BDF._write_common(self, size, card_writer)
     return msg
Example #39
0
    def test_solid_02(self):
        mid = 2
        pid = 4
        rho = 0.1
        cards = [
            #$ Solid Nodes
            ['GRID', 11, 0, 0., 0., 0., 0],
            ['GRID', 12, 0, 1., 0., 0., 0],
            ['GRID', 13, 0, 1., 1., 0., 0],
            ['GRID', 14, 0, 0., 1., 0., 0],

            ['GRID', 15, 0, 0., 0., 2., 0],
            ['GRID', 16, 0, 1., 0., 2., 0],
            ['GRID', 17, 0, 1., 1., 2., 0],
            ['GRID', 18, 0, 0., 1., 2., 0],

            # Solids
            ['CHEXA', 7, pid, 11, 12, 13, 14, 15, 16,  17, 18],
            ['CTETRA', 8, pid, 11, 12, 13, 15],

            # Solid Nodes
            ['GRID', 21, 0, 0., 0., 0.,  0,],
            ['GRID', 22, 0, 1., 0., 0.,  0,],
            ['GRID', 23, 0, 1., 1., 0.,  0,],
            ['GRID', 24, 0, 0., 0., 2.,  0,],
            ['GRID', 25, 0, 1., 0., 2.,  0,],
            ['GRID', 26, 0, 1., 1., 2.,  0,],
            ['CPENTA', 9, pid, 21, 22, 23, 24, 25, 26],

            # hyperelastic
            ['PLSOLID', pid, mid, 'GRID'],
            ['MATHP', mid, None, None, None, rho],
        ]
        card_count = {
            'GRID' : 14,
            'CTETRA4': 1,
            'CPENTA6': 1,
            'CHEXA8' : 1,
            'PLSOLID': 1,
            'MATHP': 1,
        }
        model = BDF(debug=True)
        model.allocate(card_count)
        for fields in cards:
            model.add_card(fields, fields[0], is_list=True)
        model.cross_reference()

        # CTETRA
        eid = 8
        nsm = 0.
        V = 1. / 3.
        self.check_solid(model, eid, 'CTETRA4', pid, 'PLSOLID', mid, 'MATHP', nsm, rho, V)

        eid = 9
        V = 1.0
        self.check_solid(model, eid, 'CPENTA6', pid, 'PLSOLID', mid, 'MATHP', nsm, rho, V)

        eid = 7
        V = 2.0
        self.check_solid(model, eid, 'CHEXA8', pid, 'PLSOLID', mid, 'MATHP', nsm, rho, V)
Example #40
0
    def test_solid_03(self):
        """checks linear static solid material"""
        mid = 2
        pid = 4
        rho = 0.1
        tableID = 42
        cards = [
            #$ Solid Nodes
            ['GRID', 11, 0, 0., 0., 0., 0],
            ['GRID', 12, 0, 1., 0., 0., 0],
            ['GRID', 13, 0, 1., 1., 0., 0],
            ['GRID', 14, 0, 0., 1., 0., 0],

            ['GRID', 15, 0, 0., 0., 2., 0],
            ['GRID', 16, 0, 1., 0., 2., 0],
            ['GRID', 17, 0, 1., 1., 2., 0],
            ['GRID', 18, 0, 0., 1., 2., 0],

            # Solids
            ['CHEXA',  7, pid, 11, 12, 13, 14, 15, 16,  17, 18],
            ['CTETRA', 8, pid, 11, 12, 13, 15],

            # Solid Nodes
            ['GRID',  21, 0, 0., 0., 0.,  0,],
            ['GRID',  22, 0, 1., 0., 0.,  0,],
            ['GRID',  23, 0, 1., 1., 0.,  0,],
            ['GRID',  24, 0, 0., 0., 2.,  0,],
            ['GRID',  25, 0, 1., 0., 2.,  0,],
            ['GRID',  26, 0, 1., 1., 2.,  0,],
            ['CPENTA', 9, pid, 21, 22, 23, 24, 25, 26],

            # static
            ['PSOLID', pid, mid, 0],
            ['MAT1', mid, 1.0, 2.0, 3.0, rho],
            ['MATS1', mid, tableID, 'PLASTIC', 0.0, 1, 1, 100000., ],
            #['TABLEST'],
            ['TABLES1', tableID, 1, None, None, None, None, None, None,
            1.0, 10.0, 2.0, 10.0, 'ENDT'],
        ]
        card_count = {
            'GRID' : 14,
            'CPENTA6': 1,
            'CTETRA4': 1,
            'PSOLID': 1,
            'CHEXA8' : 1,
            'MAT1': 1,
            'MATS1': 1,
            'TABLES1': 1,
        }
        model = BDF(debug=False)
        model.allocate(card_count)
        for fields in cards:
            model.add_card(fields, fields[0], is_list=True)
        model.cross_reference()

        mat = model.materials[mid]
        print('----MAT----', type(mat))
        print(mat)
        print('E = %s' % mat.get_E_by_material_index())
        print('E = %s' % mat.get_E_by_material_id())
Example #41
0
    def test_conrod_01(self):
        model = BDF(debug=debug)
        model.allocate({"CONROD": 1})
        eid = 10
        nid1 = 2
        nid2 = 3
        mid = 5
        A = 27.0
        lines = ["conrod,%i, %i, %i, %i, %f" % (eid, nid1, nid2, mid, A)]
        model.add_card(lines, "CONROD", is_list=False)

        size = 8
        card = model.conrod.slice_by_element_id([eid])
        f = StringIO()
        card.write_card(f, size)
        # card.rawFields()
        self.assertEquals(card.get_element_id_by_element_index(), eid)
        self.assertEquals(card.get_material_id_by_element_index(), mid)
Example #42
0
 def test_cord2_rcs_02(self):
     """
     all points are located at <30,40,50>
     """
     model = BDF(debug=False)
     cards = [
         [
             'CORD2C*                1               0              0.              0.',
             '*                     0.              0.              0.              1.*       ',
             '*                     1.              0.              1.',
         ],
         [  #'$ Femap with NX Nastran Coordinate System 20 : rectangular defined in cylindrical',
             'CORD2R*               20               1              7.             20.',
             '*                    -6.   7.07106781187   28.1301023542             -6.*       ',
             '*          7.70710678119             20.  -5.29289321881',
         ],
         [  #'$ Femap with NX Nastran Coordinate System 21 : cylindrical defined in cylindrical',
             'CORD2C*               21               1             15.            -30.',
             '*                    12.   14.6565766735  -30.3177805524   12.9355733712*       ',
             '*          14.6234241583  -26.4257323272   11.9304419665',
         ],
         [  #'$ Femap with NX Nastran Coordinate System 22 : spherical defined in cylindrical',
             'CORD2S*               22               1              5.            -75.',
             '*                    20.   5.66032384035  -82.9319986389   19.8502545865*       ',
             '*          4.88876051026  -73.8006653677   19.0116094889',
         ],
         [
             'GRID*                 20              20   64.2559135157  -14.9400459772',
             '*          27.3271005317               0',
         ],
         [
             'GRID*                 21              21   52.8328862418  -28.8729017195',
             '*           34.615939507               0',
         ],
         [
             'GRID*                 22              22   61.1042111232   158.773483595',
             '*           -167.4951724               0',
         ],
     ]
     for lines in cards:
         card = model.process_card(lines)
         model.add_card(card, card[0])
     model.cross_reference()
     for nid in model.nodes:
         a = array([30., 40., 50.])
         b = model.Node(nid).Position()
         self.assertTrue(
             allclose(array([30., 40., 50.]),
                      model.Node(nid).Position()), str(a - b))
Example #43
0
    def test_grid_02(self):
        model = BDF()
        nid = 1
        cp = 2
        cd = 0
        ps = ''
        seid = 0
        card_count = {'GRID': 2,}

        model = BDF()
        model.allocate(card_count)

        nodes = model.grid
        data1 = BDFCard(['GRID', nid, cp, 0., 0., 0., cd, ps, seid])
        data2 = BDFCard(['GRID', nid+1, cp, 0., 0., 0., cd, ps, seid])
        nodes.add(data1)
        nodes.add(data2)
        f = StringIO()
        nodes.write_bdf(f, size=8, write_header=False)
Example #44
0
 def test_grid_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', 4, 0, 1., 2., 3.],
     ]
     card_count = {
         'GRID': 3,
     }
     model.allocate(card_count)
     for card in cards:
         model.add_card(card, card[0], comment='comment', is_list=True)
     #+------+-----+----+----+----+----+----+----+------+
     #|   0  |  1  | 2  | 3  | 4  | 5  |  6 | 7  |  8   |
     #+======+=====+====+====+====+====+====+====+======+
     #| GRID | NID | CP | X1 | X2 | X3 | CD | PS | SEID |
     #+------+-----+----+----+----+----+----+----+------+
     node = model.Node(4)
    def test_cord2_rcs_03(self):
        """
        all points are located at <30,40,50>
        """
        model = BDF(debug=False)
        card_count = {
            'GRID' : 3,
            'CORD2R' : 1,
            'CORD2C' : 1,
            'CORD2S' : 2,
        }
        model.allocate(card_count)

        cards = [
            [
                'CORD2S*                2               0              0.              0.',
                '*                     0.              0.              0.              1.*       ',
                '*                     1.              0.              1.',],
            [
                #'$ Femap with NX Nastran Coordinate System 30 : rectangular in spherical',
                'CORD2R*               30               2             14.             30.',
                '*                    70.    13.431863852   32.1458443949   75.2107442927*       ',
                '*          14.4583462334   33.4569982885   68.2297989286',],
            [
                #'$ Femap with NX Nastran Coordinate System 31 : cylindrical in spherical',
                'CORD2C*               31               2              3.             42.',
                '*                  -173.   2.86526881213   45.5425615252   159.180363517*       ',
                '*          3.65222385965   29.2536614627  -178.631312271',],
            [
                #'$ Femap with NX Nastran Coordinate System 32 : spherical in spherical',
                'CORD2S*               32               2             22.             14.',
                '*                    85.   22.1243073983   11.9537753718   77.9978191005*       ',
                '*          21.0997242967   13.1806120497   88.4824763008',],
            [
                'GRID*                 30              30   40.7437952957  -23.6254877994',
                '*           -33.09784854               0',],
            [
                'GRID*                 31              31   62.9378078196   15.9774797923',
                '*          31.0484428362               0',],
            [
                'GRID*                 32              32   53.8270847449   95.8215692632',
                '*          159.097767463               0',],
        ]
        for lines in cards:
            card = model.process_card(lines)
            model.add_card(card, card[0])
        model.build()
        for nid in model.nodes:
            a = array([30., 40., 50.])
            b = model.Node(nid).get_position()
            self.assertTrue(allclose(array([30., 40., 50.]), model.Node(nid).get_position()), str(a - b))
Example #46
0
def run_fem2(bdf_model, out_model, xref, punch,
             sum_load, size, precision,
             reject, debug=False, log=None):
    assert os.path.exists(bdf_model), bdf_model
    assert os.path.exists(out_model), out_model
    fem2 = BDF(debug=debug, log=log)
    fem2.log.info('starting fem2')
    sys.stdout.flush()
    try:
        fem2.read_bdf(out_model, xref=xref, punch=punch)
    except:
        print("failed reading %r" % out_model)
        raise

    #fem2.sumForces()
    #fem2.sumMoments()
    out_model2 = bdf_model + '_out2'
    fem2.write_bdf(out_model2, interspersed=True)
    #fem2.writeAsCTRIA3(out_model_2)
    os.remove(out_model2)
    return fem2
Example #47
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
Example #48
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, :, :]
Example #49
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)
Example #50
0
def run_fem2(bdf_model,
             out_model,
             xref,
             punch,
             sum_load,
             size,
             precision,
             reject,
             debug=False,
             log=None):
    assert os.path.exists(bdf_model), bdf_model
    assert os.path.exists(out_model), out_model
    fem2 = BDF(debug=debug, log=log)
    fem2.log.info('starting fem2')
    sys.stdout.flush()
    try:
        fem2.read_bdf(out_model, xref=xref, punch=punch)
    except:
        print("failed reading %r" % out_model)
        raise

    #fem2.sumForces()
    #fem2.sumMoments()
    out_model2 = bdf_model + '_out2'
    fem2.write_bdf(out_model2, interspersed=True)
    #fem2.writeAsCTRIA3(out_model_2)
    os.remove(out_model2)
    return fem2
Example #51
0
    def test_grid_03(self):
        model = BDF()
        nid = 1
        cp = 2
        cd = 0
        ps = ''
        seid = 0
        card_count = {
            'GRID': 2,
        }

        model = BDF()
        model.allocate(card_count)

        nodes = model.grid
        data1 = BDFCard(['GRID', nid, cp, 0., 0., 0., cd, ps, seid])
        data2 = BDFCard(['GRID', nid + 1, cp, 0., 0., 0., cd, ps, seid])
        data3 = BDFCard(['GRID', nid + 2, cp, 0., 0., 0., cd, ps, seid])
        nodes.add(data1)
        nodes.add(data2)
        nodes.resize(3, refcheck=False)
        #print('nodes.node_id = %s' % nodes.node_id)
        nodes.add(data3)
        f = StringIO()
        nodes.write_bdf(f, size=8, write_header=False)
Example #52
0
    def test_grid_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', 4, 0, 1., 2., 3.],
        ]
        for card in cards:
            model.add_card(card, card[0], comment='comment', is_list=True)

        #+------+-----+----+----+----+----+----+----+------+
        #|   0  |  1  | 2  | 3  | 4  | 5  |  6 | 7  |  8   |
        #+======+=====+====+====+====+====+====+====+======+
        #| GRID | NID | CP | X1 | X2 | X3 | CD | PS | SEID |
        #+------+-----+----+----+----+----+----+----+------+
        node = model.Node(4)
        self.assertEqual(node.get_field(1), 4)
        self.assertEqual(node.get_field(2), 0)
        self.assertEqual(node.get_field(3), 1.)
        self.assertEqual(node.get_field(4), 2.)
        self.assertEqual(node.get_field(5), 3.)

        node.update_field(1, 5)
        node.update_field(2, 6)
        node.update_field(3, 7.)
        node.update_field(4, 8.)
        node.update_field(5, 9.)
        with self.assertRaises(KeyError):
            node.update_field(9, 'dummy')

        self.assertEqual(node.get_field(1), 5)
        self.assertEqual(node.get_field(2), 6)
        self.assertEqual(node.get_field(3), 7.)
        self.assertEqual(node.get_field(4), 8.)
        self.assertEqual(node.get_field(5), 9.)
        with self.assertRaises(KeyError):
            node.get_field(9)
Example #53
0
    def add_card(self, card_lines, card_name, comment='', is_list=True):
        card_name = card_name.upper()
        self._increase_card_count(card_name)
        if card_name in ['DEQATN']:
            card_obj = card_lines
            card = card_lines
        else:
            if is_list:
                fields = card_lines
            else:
                fields = to_fields(card_lines, card_name)

            # apply OPENMDAO syntax
            if self._is_dynamic_syntax:
                fields = [
                    self._parse_dynamic_syntax(field)
                    if '%' in field[0:1] else field for field in fields
                ]

                card = wipe_empty_fields([
                    interpret_value(field, fields)
                    if field is not None else None for field in fields
                ])
            else:  # leave everything as strings
                card = wipe_empty_fields(fields)
            card_obj = BDFCard(card)

        if card_name == 'HYPER':
            hyper = HYPER(card_obj, comment)
            self.hyper[hyper.pid] = hyper
            return
        elif card_name == 'FLOW':
            flow = FLOW(card_obj, comment)
            self.flow[flow.flow_id] = flow
            return
        BDF.add_card(self, card, card_name, comment=comment, is_list=True)
Example #54
0
 def test_grid_01(self):
     model = BDF(debug=False)
     card_lines = [
         #['CORD1R', 1, 1, 2, 3],  # fails on self.k
         ['GRID', 1, 0, 0., 0., 0.],
         ['GRID', 2, 0, 1., 0., 0.],
         ['GRID', 4, 0, 1., 2., 3.],
     ]
     #card_count = {
     #'GRID': 3,
     #}
     cards, card_count = model.add_cards_lines(card_lines)
     model.allocate(card_count, cards)
     for card in cards:
         model.add_card(card, card[0], comment='comment', is_list=True)
     model.build()
     #+------+-----+----+----+----+----+----+----+------+
     #|   0  |  1  | 2  | 3  | 4  | 5  |  6 | 7  |  8   |
     #+======+=====+====+====+====+====+====+====+======+
     #| GRID | NID | CP | X1 | X2 | X3 | CD | PS | SEID |
     #+------+-----+----+----+----+----+----+----+------+
     node = model.grid.slice_by_node_id(4)
Example #55
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))
Example #56
0
    def test_grid_04(self):
        model = BDF()
        nid = 1
        cp = 2
        cd = 0
        ps = ''
        seid = 0
        card_count = {
            'GRID': 2,
        }

        model = BDF()
        model.allocate(card_count)

        nodes = model.grid
        data1 = BDFCard(['GRID', nid, cp, 0., 0., 0., cd, ps, seid])
        data2 = BDFCard(['GRID', nid + 1, cp, 0., 0., 0., cd, ps, seid])
        data3 = BDFCard(['GRID', nid + 2, cp, 0., 0., 0., cd, ps, seid])
        data4 = BDFCard(['GRID', nid + 3, cp, 0., 0., 0., cd, ps, seid])
        nodes.add(data1)
        nodes.add(data2)
        nodes.resize(4, refcheck=False)
        #print('nodes.node_id = %s' % nodes.node_id)
        nodes.add(data3)
        self.assertEqual(len(nodes.node_id), 4)
        self.assertEqual(nodes.n, 4)
        self.assertEqual(nodes.i, 3)
        nodes.shrink(refcheck=False)
        #print('nodes.node_id = %s' % nodes.node_id)
        self.assertEqual(len(nodes.node_id), 3)
        self.assertEqual(nodes.n, 3)
        self.assertEqual(nodes.i, 3)

        nodes.resize(4, refcheck=False)
        nodes.add(data4)
        self.assertEqual(len(nodes.node_id), 4)
        self.assertEqual(nodes.n, 4)
        self.assertEqual(nodes.i, 4)

        f = StringIO()
        nodes.write_bdf(f, size=8, write_header=False)
        #print(f.getvalue())

        nodes.resize(2, refcheck=False)
        self.assertEqual(len(nodes.node_id), 2)
        self.assertEqual(nodes.n, 2)
        self.assertEqual(nodes.i, 2)

        f = StringIO()
        nodes.write_bdf(f, size=8, write_header=False)