Esempio n. 1
0
    def test_simple_logger_log_func(self):
        def log_func(typ, filename, n, msg):
            print('typ=%r filename=%r n=%r msg=%r' % (typ, filename, n, msg))
            assert typ == 'INFO', '%r' % msg
            assert msg == 'info_log_func', '%r' % msg

        log = SimpleLogger(level='info', log_func=log_func)
        log.info('info_log_func')
Esempio n. 2
0
    def test_aelist_1(self):
        """checks the AELIST card"""
        log = SimpleLogger(level='warning')
        model = BDF(log=log)
        data = ['AELIST', 75, 1001, 'THRU', 1075, 1101, 'THRU', 1109, 1201, 1202]
        model.add_card(data, data[0], comment_bad, is_list=True)
        elements = list(range(1001, 1076)) + list(range(1101, 1110)) + [1201, 1202]
        aelist = AELIST(74, elements)
        aelist.validate()
        aelist.write_card()
        aelist75 = model.aelists[75]
        #print(aelist.elements)
        #print(elements)
        self.assertTrue(elements == aelist75.elements)

        elements = list(range(1001, 1076)) + list(range(1101, 1110)) + [1108, 1202]
        data = ['AELIST', 76, 1001, 'THRU', 1075, 1101, 'THRU', 1109, 1108, 1202]
        model.add_card(data, data[0], comment_bad, is_list=True)
        aelist76 = model.aelists[76]
        #print(aelist76 .elements)
        #print(elements)
        self.assertFalse(elements == aelist76.elements)

        elements = list(set(elements))
        elements.sort()
        self.assertTrue(elements == aelist76.elements)

        elements = [1000, 1000, 1000, 2000, 1000, 2000]
        aelist = AELIST(75, elements)
        aelist.clean_ids()
        str(aelist.write_card())
Esempio n. 3
0
    def test_renumber_01(self):
        """renumber a bdf"""
        log = SimpleLogger(level='warning')
        bdf_filename = os.path.abspath(
            os.path.join(pkg_path, '..', 'models', 'bwb', 'BWB_saero.bdf'))
        bdf_filename_out1 = os.path.abspath(
            os.path.join(pkg_path, '..', 'models', 'bwb', 'BWB_saero1.out'))
        bdf_filename_out2 = os.path.abspath(
            os.path.join(pkg_path, '..', 'models', 'bwb', 'BWB_saero2.out'))
        bdf_filename_out3 = os.path.abspath(
            os.path.join(pkg_path, '..', 'models', 'bwb', 'BWB_saero3.out'))
        model = bdf_renumber(bdf_filename, bdf_filename_out1, size=8,
                             is_double=False, starting_id_dict=None,
                             round_ids=False, cards_to_skip=None)

        model = read_bdf(bdf_filename, log=log)
        bdf_renumber(model, bdf_filename_out2, size=16, is_double=False,
                     starting_id_dict={
                         'eid' : 1000, 'pid':2000, 'mid':3000,
                         'spc_id' : 4000,},
                     round_ids=False, cards_to_skip=None)
        bdf_renumber(bdf_filename, bdf_filename_out3, size=8,
                     is_double=False, starting_id_dict=None,
                     round_ids=True, cards_to_skip=None)
        read_bdf(bdf_filename_out1, log=log)
        read_bdf(bdf_filename_out2, log=log)
        read_bdf(bdf_filename_out3, log=log)
Esempio n. 4
0
 def test_mirror2(self):
     """mirrors the BDF (we care about the aero cards)"""
     log = SimpleLogger(level='warning')
     bdf_filename = os.path.join(MODEL_PATH, 'bwb', 'bwb_saero.bdf')
     model = bdf_mirror(bdf_filename, plane='xz', log=log)[0]
     model.uncross_reference()
     model.cross_reference()
     make_symmetric_model(model, plane='xz', zero_tol=1e-12)
Esempio n. 5
0
    def test_export_mcids(self):
        """creates material coordinate systems"""
        log = SimpleLogger(level='error')
        bdf_filename = os.path.join(MODEL_PATH, 'bwb', 'bwb_saero.bdf')
        csv_filename = os.path.join(MODEL_PATH, 'bwb', 'mcids.csv')
        export_mcids(bdf_filename,
                     csv_filename,
                     export_xaxis=True,
                     export_yaxis=True,
                     iply=9,
                     log=log,
                     debug=False)

        model = read_bdf(bdf_filename, xref=False, debug=False)
        model.safe_cross_reference()

        eids = [1204, 1211]
        export_mcids(model,
                     csv_filename=None,
                     eids=eids,
                     export_xaxis=True,
                     export_yaxis=True,
                     iply=9,
                     log=log,
                     debug=False)
        export_mcids(model,
                     csv_filename=None,
                     eids=eids,
                     export_xaxis=True,
                     export_yaxis=False,
                     iply=9,
                     log=log,
                     debug=False)
        export_mcids(model,
                     csv_filename=None,
                     eids=eids,
                     export_xaxis=False,
                     export_yaxis=True,
                     iply=9,
                     log=log,
                     debug=False)
        with self.assertRaises(AssertionError):
            export_mcids(model,
                         csv_filename=None,
                         eids=eids,
                         export_xaxis=False,
                         export_yaxis=False,
                         iply=9)

        with self.assertRaises(RuntimeError):
            export_mcids(model,
                         csv_filename,
                         eids=eids,
                         export_xaxis=True,
                         export_yaxis=True,
                         iply=10)
Esempio n. 6
0
 def test_renumber_02(self):
     bdf_filename = os.path.join(MODEL_PATH, 'iSat', 'ISat_Dploy_Sm.dat')
     bdf_filename_renumber = os.path.join(MODEL_PATH, 'iSat',
                                          'ISat_Dploy_Sm_renumber.dat')
     bdf_filename_check = os.path.join(MODEL_PATH, 'iSat',
                                       'ISat_Dploy_Sm_check.dat')
     log = SimpleLogger('error')
     check_renumber(bdf_filename,
                    bdf_filename_renumber,
                    bdf_filename_check,
                    log=log)
Esempio n. 7
0
 def test_cquad4_1(self):
     """runs a 1 element CQUAD4 problem"""
     fargs = {
         '--k': 1.0,
         '--f': 1.0,
         '--m': 1.0,
         '--debug': False,
         'BDFNAME': os.path.join(test_path, 'cquad4.bdf'),
         'BDFBASE': 'cquad4',
     }
     log = SimpleLogger('warning', encoding='utf8')
     solver = Solver(fargs, log=log)
     solver.run_solver()
Esempio n. 8
0
def _cut_shell_model_quads():
    """helper method"""
    log = SimpleLogger(level='error')
    pid = 10
    mid1 = 100
    model = BDF(log=log)

    # intersects (min)
    model.add_grid(1, [0., 0., 0.])
    model.add_grid(2, [1., 0., 0.])
    model.add_grid(3, [1., 1., 0.])
    model.add_grid(4, [0., 1., 0.])
    model.add_cquad4(1, pid, [1, 2, 3, 4])

    # intersects (max)
    model.add_grid(5, [0., 0., 1.])
    model.add_grid(6, [1., 0., 1.])
    model.add_grid(7, [1., 1., 1.])
    model.add_grid(8, [0., 1., 1.])
    model.add_cquad4(2, pid, [5, 6, 7, 8])

    # intersects (mid)
    model.add_grid(9, [0., 0., 0.5])
    model.add_grid(10, [1., 0., 0.5])
    model.add_grid(11, [1., 1., 0.5])
    model.add_grid(12, [0., 1., 0.5])
    model.add_cquad4(3, pid, [9, 10, 11, 12])

    # doesn't intersect
    model.add_grid(13, [10., 0., 0.])
    model.add_grid(14, [11., 0., 0.])
    model.add_grid(15, [11., 1., 0.])
    model.add_grid(16, [10., 1., 0.])
    model.add_cquad4(4, pid, [13, 14, 15, 16])

    model.add_pshell(pid, mid1=mid1, t=2.)

    E = 1.0
    G = None
    nu = 0.3
    model.add_mat1(mid1, E, G, nu, rho=1.0)
    model.validate()

    model.cross_reference()

    #xyz_points = [
    #[0.4, 0.6, 0.], [-1., -1, 0.],]

    #tol = 2.
    nodal_result = np.linspace(0., 1., num=16)
    return model, nodal_result
Esempio n. 9
0
    def test_caero3_1(self):
        """checks the CAERO3/PAERO3"""
        eid = 100
        pid = 200
        cp = 4
        list_w = 5
        list_c1 = 6
        list_c2 = 7
        p1 = [0., 0., 0.]
        x12 = 10.
        p4 = [5., 10., 0.]
        x43 = 3.

        nbox = 10
        ncontrol_surfaces = 0
        x = None
        y = None

        log = SimpleLogger(level='warning')
        model = BDF(log=log)
        coord = CORD2R.add_card(BDFCard(['CORD2R', cp, 0,
                                         0., 0., 0.,
                                         0., 0., 1.,
                                         1., 0., 0.]))
        coord = CORD2R(cp, rid=0, origin=None, zaxis=None, xzplane=None,
                       comment='')
        coord.validate()
        model.coords[cp] = coord

        paero = PAERO3(pid, nbox, ncontrol_surfaces, x, y)
        model.paeros[pid] = paero

        card = ['CAERO3', 2000, 20001, 0, 22, 33, None, None, None,
                1.0, 0.0, 0., 100., 17., 130., 0., 100.]
        bdf_card = BDFCard(card, has_none=True)
        caero3a = CAERO3.add_card(bdf_card, comment='msg')
        caero3a.validate()
        caero3a.write_card()
        caero3a.raw_fields()

        caero3b = CAERO3(eid, pid, cp, list_w, list_c1, list_c2, p1, x12, p4,
                         x43, comment='caero3')
        model.caeros[pid] = caero3b

        caero3b.write_card()
        caero3b.cross_reference(model)
        caero3b.write_card()
        caero3a.raw_fields()
        caero3b.uncross_reference()
        caero3b.write_card()
        caero3a.raw_fields()
Esempio n. 10
0
    def test_pierce_model(self):
        """tests pierce_shell_model"""
        log = SimpleLogger(level='error')
        pid = 10
        mid1 = 100
        model = BDF(log=log)

        # intersects (min)
        model.add_grid(1, [0., 0., 0.])
        model.add_grid(2, [1., 0., 0.])
        model.add_grid(3, [1., 1., 0.])
        model.add_grid(4, [0., 1., 0.])
        model.add_cquad4(1, pid, [1, 2, 3, 4])

        # intersects (max)
        model.add_grid(5, [0., 0., 1.])
        model.add_grid(6, [1., 0., 1.])
        model.add_grid(7, [1., 1., 1.])
        model.add_grid(8, [0., 1., 1.])
        model.add_cquad4(2, pid, [5, 6, 7, 8])

        # intersects (mid)
        model.add_grid(9, [0., 0., 0.5])
        model.add_grid(10, [1., 0., 0.5])
        model.add_grid(11, [1., 1., 0.5])
        model.add_grid(12, [0., 1., 0.5])
        model.add_cquad4(3, pid, [9, 10, 11, 12])

        # doesn't intersect
        model.add_grid(13, [10., 0., 0.])
        model.add_grid(14, [11., 0., 0.])
        model.add_grid(15, [11., 1., 0.])
        model.add_grid(16, [10., 1., 0.])
        model.add_cquad4(4, pid, [13, 14, 15, 16])

        model.add_pshell(pid, mid1=mid1, t=2.)

        E = 1.0
        G = None
        nu = 0.3
        model.add_mat1(mid1, E, G, nu, rho=1.0)
        model.validate()

        model.cross_reference()

        xyz_points = [
            [0.4, 0.6, 0.],
            [-1., -1, 0.],
        ]
        pierce_shell_model(model, xyz_points)
Esempio n. 11
0
    def test_diverg(self):
        """checks the DIVERG card"""
        log = SimpleLogger(level='warning')
        model = BDF(log=log)

        sid = 100
        nroots = 21
        machs = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]
        x0 = 3.
        V = 42.
        diverg = DIVERG(sid, nroots, machs, comment='divergence')
        diverg.validate()
        diverg.write_card()

        diverg = model.add_card(['DIVERG', sid, nroots] + machs, 'DIVERG', comment='divergence')
Esempio n. 12
0
    def test_merge_01(self):
        """merges multiple bdfs into a single deck"""
        log = SimpleLogger(level='error')
        bdf_filename1 = os.path.join(MODEL_PATH, 'bwb', 'bwb_saero.bdf')
        bdf_filename2 = os.path.join(MODEL_PATH, 'sol_101_elements',
                                     'static_solid_shell_bar.bdf')
        bdf_filename3 = os.path.join(MODEL_PATH, 'solid_bending',
                                     'solid_bending.bdf')
        bdf_filename4 = os.path.join(MODEL_PATH, 'iSat', 'ISat_Dploy_Sm.dat')
        bdf_filename_out1 = os.path.join(MODEL_PATH, 'bwb',
                                         'BWBsaero_staticbar_8.out')
        bdf_filename_out2 = os.path.join(MODEL_PATH, 'bwb',
                                         'BWBsaero_static_bar_16.out')
        bdf_filename_out3 = os.path.join(MODEL_PATH, 'bwb',
                                         'BWBsaero_staticbar_isat.out')

        bdf_filenames1 = [bdf_filename1, bdf_filename2]
        bdf_filenames2 = [
            bdf_filename1, bdf_filename2, bdf_filename3, bdf_filename4
        ]
        bdf_merge(bdf_filenames1,
                  bdf_filename_out=bdf_filename_out1,
                  renumber=True,
                  encoding=None,
                  size=8,
                  is_double=False,
                  cards_to_skip=None,
                  log=log)
        bdf_merge(bdf_filenames1,
                  bdf_filename_out=bdf_filename_out2,
                  renumber=False,
                  encoding=None,
                  size=16,
                  is_double=False,
                  cards_to_skip=None,
                  log=log)

        bdf_merge(bdf_filenames2,
                  bdf_filename_out=bdf_filename_out3,
                  renumber=False,
                  encoding=None,
                  size=16,
                  is_double=False,
                  cards_to_skip=None,
                  log=log)
        read_bdf(bdf_filename_out1, log=log)
        read_bdf(bdf_filename_out2, log=log)
        read_bdf(bdf_filename_out3, log=log)
Esempio n. 13
0
    def test_aefact_1(self):
        """checks the AEFACT card"""
        data = ['AEFACT', 97, .3, 0.7, 1.0]
        log = SimpleLogger(level='warning')
        model = BDF(log=log)
        model.add_card(data, data[0], comment_bad, is_list=True)

        data = ['AEFACT', 97, .3, 0.7, 1.0]
        model.add_card(data, data[0], comment_bad, is_list=True)

        data = ['AEFACT', '98', '.3', '0.7', '1.0']
        model.add_card(data, data[0], comment_good, is_list=True)

        msg = '$this is a bad comment\nAEFACT        97      .3      .7      1.\n'
        aefact97 = model.aefacts[97]
        aefact98 = model.aefacts[98]
        self.assertTrue(all(aefact97.Di == [.3, .7, 1.0]))
        self.assertTrue(all(aefact98.Di == [.3, .7, 1.0]))

        out = aefact97.write_card(8, None)
        self.assertEqual(msg, out)

        msg = '$this is a good comment\nAEFACT        98      .3      .7      1.\n'
        out = aefact98.write_card(8, None)
        self.assertEqual(msg, out)

        #data = ['AEFACT', 99, .3, 0.7, 1.0, None, 'cat']
        #with self.assertRaises(SyntaxError):
            #model.add_card(data, data[0], comment_good, is_list=True)

        #data = ['AEFACT', 100, .3, 0.7, 1.0, 'cat']
        #with self.assertRaises(SyntaxError):
            #model.add_card(data, data[0], comment_good, is_list=True)

        #data = ['AEFACT', 101, .3, 0.7, 1.0, 2]
        #with self.assertRaises(SyntaxError):
            #model.add_card(data, data[0], comment_good, is_list=True)

        Di = [1., 2., 3.]
        aefact = AEFACT(200, Di, comment='')
        aefact.validate()
        aefact.write_card()
Esempio n. 14
0
    def test_eq1(self):
        """
        Collapse nodes 2 and 3; consider 1-3
        """
        log = SimpleLogger(level='error')
        msg = ('CEND\n'
               'BEGIN BULK\n'
               'GRID,1,,0.,0.,0.\n'
               'GRID,2,,0.,0.,0.5\n'
               'GRID,3,,0.,0.,0.51\n'
               'GRID,10,,0.,0.,1.\n'
               'GRID,11,,0.,0.,1.\n'
               'CTRIA3,1,1,1,2,11\n'
               'CTRIA3,3,1,2,3,11\n'
               'CTRIA3,4,1,1,2,10\n'
               'PSHELL,1,1,0.1\n'
               'MAT1,1,3.0,, 0.3\n'
               'ENDDATA')
        bdf_filename = 'nonunique.bdf'
        bdf_filename_out = 'unique.bdf'

        with open(bdf_filename, 'w') as bdf_file:
            bdf_file.write(msg)

        tol = 0.2
        bdf_equivalence_nodes(bdf_filename,
                              bdf_filename_out,
                              tol,
                              renumber_nodes=False,
                              neq_max=4,
                              xref=True,
                              node_set=None,
                              crash_on_collapse=False,
                              log=log,
                              debug=False)

        # model = BDF(debug=False)
        # model.read_bdf(bdf_filename_out)
        # assert len(model.nodes) == 3, len(model.nodes)

        os.remove(bdf_filename)
        os.remove(bdf_filename_out)
Esempio n. 15
0
    def test_aelink_1(self):
        log = SimpleLogger(level='warning')
        model = BDF(log=log)
        id = 10
        label = 'CS'
        independent_labels = ['A', 'B', 'C']
        Cis = [1.0, 2.0]
        aelink = AELINK(id, label, independent_labels, Cis, comment='')
        with self.assertRaises(RuntimeError):
            aelink.validate()
        str(aelink)
        aelink.write_card()

        card = ['AELINK', id, label, independent_labels[0], Cis[0],
                independent_labels[1], Cis[1], independent_labels[2]]
        with self.assertRaises(AssertionError):
            model.add_card(card, 'AELINK')

        card = ['AELINK', id, label, independent_labels[0], Cis[0],
                independent_labels[1], Cis[1]]
        model.add_card(card, 'AELINK', comment='cat')
Esempio n. 16
0
    def test_trim(self):
        """checks the TRIM card"""
        log = SimpleLogger(level='warning')
        model = BDF(log=log)

        sid = 100
        mach = 0.75
        q = 100.
        labels = ['ALPHA', 'ALPHA']
        uxs = [10., 20.]
        trim = TRIM(sid, mach, q, labels, uxs)
        with self.assertRaises(RuntimeError):
            trim.validate()

        labels = ['ALPHA']
        uxs = [10., 20.]
        trim = TRIM(sid, mach, q, labels, uxs)
        with self.assertRaises(RuntimeError):
            trim.validate()

        labels = ['ALPHA', 'BETA']
        uxs = [10., 20.]
        trim = TRIM(sid, mach, q, labels, uxs)
        trim.validate()
        trim.write_card()

        labels = ['ALPHA']
        uxs = [10.]
        trim = TRIM(sid, mach, q, labels, uxs, aeqr=3.0, comment='')
        trim.validate()
        trim.write_card()

        labels = ['ALPHA', 'BETA']
        uxs = [10., 20.]
        trim = TRIM(sid, mach, q, labels, uxs, aeqr=3.0, comment='')
        trim.validate()
        trim.write_card()

        model.add_card(['TRIM', sid, mach, q, labels[0], uxs[0]], 'TRIM', comment='$ trim')
Esempio n. 17
0
    def test_renumber_05(self):
        """renumbers a deck in a couple ways"""
        log = SimpleLogger(level='error')
        bdf_filename = os.path.join(MODEL_PATH, 'bwb', 'bwb_saero.bdf')
        bdf_filename_out1 = os.path.join(MODEL_PATH, 'bwb', 'bwb_saero1.out')
        bdf_filename_out2 = os.path.join(MODEL_PATH, 'bwb', 'bwb_saero2.out')
        bdf_filename_out3 = os.path.join(MODEL_PATH, 'bwb', 'bwb_saero3.out')
        model = bdf_renumber(bdf_filename,
                             bdf_filename_out1,
                             size=8,
                             is_double=False,
                             starting_id_dict=None,
                             round_ids=False,
                             cards_to_skip=None,
                             debug=False)

        model = read_bdf(bdf_filename, log=log)
        bdf_renumber(model,
                     bdf_filename_out2,
                     size=16,
                     is_double=False,
                     starting_id_dict={
                         'eid': 1000,
                         'pid': 2000,
                         'mid': 3000,
                         'spc_id': 4000,
                     },
                     round_ids=False,
                     cards_to_skip=None)
        bdf_renumber(bdf_filename,
                     bdf_filename_out3,
                     size=8,
                     is_double=False,
                     starting_id_dict=None,
                     round_ids=True,
                     cards_to_skip=None)
        read_bdf(bdf_filename_out1, log=log)
        read_bdf(bdf_filename_out2, log=log)
        read_bdf(bdf_filename_out3, log=log)
Esempio n. 18
0
 def test_fix_bad_quads(self):
     """split high interior angle quads"""
     msg = [
         'SOL 101',
         'CEND',
         'BEGIN BULK',
         'GRID,1,,0.,0.,0.',
         'GRID,2,,1.,0.,0.',
         'GRID,3,,1.,1.,0.',
         'GRID,4,,0.,1.,0.',
         'GRID,5,,1.,1.,0.00001',
         'GRID,6,,0.,0.,0.00001',
         'CQUAD4,1, 2, 1,2,3,4',
         'CQUAD4,2, 2, 1,2,3,5',
         'CQUAD4,3, 2, 1,6,3,5',
     ]
     log = SimpleLogger(level='error')
     bdf_filename = 'fix_bad_quads.bdf'
     with open(bdf_filename, 'w') as bdf_file:
         bdf_file.write('\n'.join(msg))
     model = read_bdf(bdf_filename, log=log, xref=False, debug=False)
     model.cross_reference(xref=True, xref_elements=False,
                           xref_nodes_with_elements=False,
                           xref_properties=False,
                           xref_masses=False,
                           xref_materials=False,
                           xref_loads=False,
                           xref_constraints=False,
                           xref_aero=False,
                           xref_sets=False,
                           xref_optimization=False)
     convert_bad_quads_to_tris(model, min_edge_length=0.01)
     #for eid, elem in sorted(model.elements.items()):
         #print(elem)
     assert model.card_count['CQUAD4'] == 2, model.card_count
     assert model.card_count['CTRIA3'] == 1, model.card_count
     os.remove(bdf_filename)
Esempio n. 19
0
    def test_msgmesh_1(self):
        """tests CGEN"""
        log = SimpleLogger(level='warning')
        model = BDF(log=log, debug=False)
        model.add_grid(1, [0., 0., 0.])
        model.add_grid(2, [1., 0., 0.])
        model.add_grid(3, [1., 1., 0.])
        model.add_grid(4, [0., 1., 0.])
        #feedge = model.add_feedge()

        Type = 10
        field_eid = 'cat'
        pid = 20
        field_id = 30
        th_geom_opt = 301.
        eidl = 40
        eidh = 50
        cgen = model.add_cgen(Type, field_eid, pid, field_id, th_geom_opt,
                              eidl, eidh)
        cgen.raw_fields()

        #----------------------------------------
        bdf_filename = StringIO()
        bdf_filename2 = StringIO()
        bdf_filename3 = StringIO()
        bdf_filename4 = StringIO()

        model.validate()
        model._verify_bdf(xref=False)
        model.write_bdf(bdf_filename,
                        encoding=None,
                        size=8,
                        is_double=False,
                        interspersed=False,
                        enddata=None,
                        close=False)

        model.cross_reference()
        model.pop_xref_errors()

        model._verify_bdf(xref=True)
        model.write_bdf(bdf_filename2,
                        encoding=None,
                        size=16,
                        is_double=False,
                        interspersed=False,
                        enddata=None,
                        close=False)
        model.write_bdf(bdf_filename3,
                        encoding=None,
                        size=16,
                        is_double=True,
                        interspersed=False,
                        enddata=None,
                        close=False)
        ##model.cross_reference()

        ##print(bdf_filename.getvalue())

        #bdf_filename2.seek(0)
        #model2 = read_bdf(bdf_filename2, xref=False)
        #print('---------------')
        #model2.safe_cross_reference()
        save_load_deck(model, run_convert=False)
    def test_op2_solid_shell_bar_01_gpforce_radial(self):
        warning_log = SimpleLogger(level='warning')
        debug_log = SimpleLogger(level='debug')
        folder = os.path.join(model_path, 'sol_101_elements')
        op2_filename = os.path.join(folder,
                                    'static_solid_shell_bar_radial.op2')
        op2_1 = read_op2_geom(op2_filename, xref=False, log=warning_log)
        op2_1.log = debug_log

        print("disp_orig =\n", op2_1.displacements[1].data[0, :2, :])
        #print("spc_orig =\n", op2_1.spc_forces[1].data[0, -3:, :])
        #print("gpf_orig =\n", op2_1.grid_point_forces[1].data[0, :2, :])

        op2_1.cross_reference(xref_elements=False,
                              xref_nodes_with_elements=False,
                              xref_properties=False,
                              xref_masses=False,
                              xref_materials=False,
                              xref_loads=False,
                              xref_constraints=False,
                              xref_aero=False,
                              xref_sets=False,
                              xref_optimization=False)
        xyz_cid0 = op2_1.get_xyz_in_coord(cid=0)

        nid_cd = np.array([[nid, node.Cd()]
                           for nid, node in sorted(iteritems(op2_1.nodes))])
        #-------------------------------------------------
        #coords = op2_1.coords
        #used_cds = np.unique(nid_cd[:, 1])
        #for cd in used_cds:
        #coord = op2_1.coords[cd]
        #print(coord)
        #print('origin = %s' % coord.origin)
        #print('beta =\n%s' % coord.beta())
        #print('-----------------------------')

        #disp = op2_1.displacements[1]
        #for line in list(disp.data[0, :, :3]):
        #print('%10.4e %10.4e %10.4e' % tuple(line))

        nids_all, nids_transform_1, icd_transform_1 = op2_1.get_displacement_index(
        )
        op2_1.transform_displacements_to_global(icd_transform_1,
                                                op2_1.coords,
                                                xyz_cid0=xyz_cid0)
        op2_1.transform_gpforce_to_global(nids_all,
                                          nids_transform_1,
                                          icd_transform_1,
                                          op2_1.coords,
                                          xyz_cid0=xyz_cid0)
        #print('stuff...')
        #disp = op2_1.displacements[1]
        #for line in list(disp.data[0, :, :3]):
        #print('%10.4e %10.4e %10.4e' % tuple(line))
        #print(disp.data[0, :, :3])

        print("disp_new =\n", op2_1.displacements[1].data[0, :2, :])
        #print("spc_new =\n", op2_1.spc_forces[1].data[0, -3:, :])
        #print("gpf_new =\n", op2_1.grid_point_forces[1].data[0, :2, :])

        #-----------------------------------------------------------------------
        op2_filename2 = os.path.join(folder, 'static_solid_shell_bar.op2')
        op2_2 = read_op2_geom(op2_filename2, debug=False)
        nids_all, nids_transform_2, icd_transform_2 = op2_2.get_displacement_index(
        )
        op2_2.transform_displacements_to_global(icd_transform_2, op2_2.coords)
        op2_2.transform_gpforce_to_global(nids_all, nids_transform_2,
                                          icd_transform_2, op2_2.coords)

        print("disp_goal =\n", op2_2.displacements[1].data[0, :2, :])
        #print("spc_goal =\n", op2_2.spc_forces[1].data[0, -3:, :])
        #print("gpf_goal =\n", op2_2.grid_point_forces[1].data[0, :2, :])

        return
        msg = 'displacements baseline=\n%s\ndisplacements xyz=\n%s' % (
            op2_1.displacements[1].data[0, :, :],
            op2_2.displacements[1].data[0, :, :])
        #print(msg)
        assert op2_1.displacements[1].assert_equal(op2_2.displacements[1])

        msg = 'grid_point_forces baseline=\n%s\ngrid_point_forces xyz=\n%s' % (
            op2_1.grid_point_forces[1].data[0, :, :],
            op2_2.grid_point_forces[1].data[0, :, :])
        #print(msg)

        assert op2_1.spc_forces[1].assert_equal(op2_2.spc_forces[1],
                                                atol=4.4341e-04), msg
        assert op2_1.mpc_forces[1].assert_equal(op2_2.mpc_forces[1]), msg
        assert op2_1.load_vectors[1].assert_equal(op2_2.load_vectors[1]), msg
        assert op2_1.grid_point_forces[1].assert_equal(
            op2_2.grid_point_forces[1], atol=0.000123), msg
        #-----------------------------------------------------------------------
        gpforce = op2_1.grid_point_forces[1]
        data = _get_gpforce_data()
        for i, datai in enumerate(data):
            eids, nids, cid, summation_point, total_force_local_expected, total_moment_local_expected = datai
            coord_out = op2_1.coords[cid]
            op2_1.log.debug('*' * 30 + 'Next Test #%s' % i + '*' * 30)
            out = gpforce.extract_interface_loads(nids,
                                                  eids,
                                                  coord_out,
                                                  op2_1.coords,
                                                  nid_cd,
                                                  icd_transform_1,
                                                  xyz_cid0,
                                                  summation_point,
                                                  itime=0,
                                                  debug=False,
                                                  logger=op2_1.log)
            total_force_global, total_moment_global, total_force_local, total_moment_local = out

            op2_1.log.debug('***********')
            op2_1.log.debug(
                'force = %s; %s' %
                (total_force_global, np.linalg.norm(total_force_global)))
            op2_1.log.debug(
                'moment = %s; %s' %
                (total_moment_global, np.linalg.norm(total_moment_global)))

            case = 'eids=%s nids=%s cid=%s summation_point=%s' % (
                eids, nids, cid, summation_point)
            msg = '%s\ntotal_force_local_expected=%s total_force_local=%s delta=%s' % (
                case, total_force_local_expected, total_force_local,
                np.abs(total_force_local_expected - total_force_local))
            self.assertTrue(
                np.allclose(total_force_local_expected,
                            total_force_local,
                            atol=0.2), msg)

            msg = '%s\ntotal_moment_local_expected=%s total_moment_local=%s delta=%s' % (
                case, total_moment_local_expected, total_moment_local,
                np.abs(total_moment_local_expected - total_moment_local))
            self.assertTrue(
                np.allclose(total_moment_local_expected,
                            total_moment_local,
                            atol=0.005), msg)
Esempio n. 21
0
    def test_quad_quality_02(self):
        r"""
        Identify bad quads

        EID = 101 (skew)
        y
        ^         4
        |       /  \
        |     /       \
        |   /               \
        | /                      \
        /                             \
        1------------------------------5-> x
          \                     /
             \          /
                  3

        EID = 102 (aspect ratio)
        y
        ^         8--------------------------6
        |       /                           /
        |     /                            /
        |   /                             /
        | /                              /
        /                               /
        1------------------------------5-> x

        EID = 103 (taper ratio)
        y
        ^         8--------------7
        |       /                 \
        |     /                    \
        |   /                       \
        | /                          \
        /                             \
        1------------------------------5-> x

        """
        msg = (
            'CEND\n'
            'BEGIN BULK\n'
            'GRID,1,,0.,   0.,0.\n'
            #'GRID,2,,1.,   0.,0.\n'
            'GRID,3,,2.,  -1.,0.\n'
            'GRID,4,,2.,   1.,0.\n'

            # shift x by 200
            'GRID,5,,200., 0.,0.\n'

            # shifted by 30 to match dx of GRID 8
            #raised up to match 7,8 height
            'GRID,6,,245., 100.,0.\n'

            # raised up to prevent large thetas
            # brought in to cause a taper
            'GRID,7,,55.,  100.,0.\n'
            'GRID,8,,45.,  100.,0.\n'

            #'CQUAD4,100,1, 1,2,3,4\n'
            'CQUAD4,101,1, 1,3,5,4\n'
            'CQUAD4,102,1, 1,5,6,8\n'
            'CQUAD4,103,1, 1,5,7,8\n'
            'PSHELL,1,1,0.1\n'
            'MAT1,1,3.0,, 0.3\n'
            'ENDDATA'
        )
        log = SimpleLogger(level='error')
        bdf_filename = 'cquad4.bdf'
        with open(bdf_filename, 'w') as bdf_file:
            bdf_file.write(msg)

        model = read_bdf(bdf_filename, log=log, xref=True)
        xyz_cid0 = model.get_xyz_in_coord(cid=0, fdtype='float32')
        nid_map = {}
        for i, nid in enumerate(sorted(model.nodes.keys())):
            nid_map[nid] = i


        max_skew_active = 70.
        max_aspect_ratio_active = 50.
        max_taper_ratio_active = 2.5

        min_theta = 0.1
        max_theta = 1000.
        max_skew = 1000.
        max_aspect_ratio = 1000.
        max_taper_ratio = 1000.

        #log = SimpleLogger(level='debug')
        #model.log = log

        # max skew
        eids_to_delete = get_bad_shells(
            model, xyz_cid0, nid_map,
            min_theta=min_theta,
            max_theta=max_theta,
            max_skew=max_skew_active,
            max_aspect_ratio=max_aspect_ratio,
            max_taper_ratio=max_taper_ratio)
        assert eids_to_delete == [101], eids_to_delete

        # aspect ratio
        eids_to_delete = get_bad_shells(
            model, xyz_cid0, nid_map,
            min_theta=min_theta,
            max_theta=max_theta,
            max_skew=max_skew,
            max_aspect_ratio=max_aspect_ratio_active,
            max_taper_ratio=max_taper_ratio,
        )
        assert eids_to_delete == [101], eids_to_delete

        # taper ratio
        eids_to_delete = get_bad_shells(
            model, xyz_cid0, nid_map,
            min_theta=min_theta,
            max_theta=max_theta,
            max_skew=max_skew,
            max_aspect_ratio=max_aspect_ratio,
            max_taper_ratio=max_taper_ratio_active,
        )
        assert eids_to_delete == [103], eids_to_delete
        os.remove(bdf_filename)
Esempio n. 22
0
    def test_quad_180_01(self):
        r"""
        Identify a 180+ degree quad

        EID = 100 (max_theta > 180)
        y
        ^         4
        |       / |
        |     /   |
        |   /     |
        | /       |
        /         |
        1------2  |----> x
                \ |
                 \|
                  3


        """
        msg = (
            'CEND\n'
            'BEGIN BULK\n'
            'GRID,1,,0.,   0.,0.\n'
            'GRID,2,,1.,   0.,0.\n'
            'GRID,3,,2.,  -1.,0.\n'
            'GRID,4,,2.,   1.,0.\n'
            'CQUAD4,100,1, 1,2,3,4\n'
            'PSHELL,1,1,0.1\n'
            'MAT1,1,3.0,, 0.3\n'
            'ENDDATA'
        )
        log = SimpleLogger(level='error')
        bdf_filename = 'cquad4.bdf'
        with open(bdf_filename, 'w') as bdf_file:
            bdf_file.write(msg)

        model = read_bdf(bdf_filename, log=log, xref=True)
        xyz_cid0 = model.get_xyz_in_coord(cid=0, fdtype='float32')
        nid_map = {}
        for i, nid in enumerate(sorted(model.nodes.keys())):
            nid_map[nid] = i


        max_theta_active = 180.

        min_theta = 0.1
        max_skew = 1000.
        max_aspect_ratio = 1000.
        max_taper_ratio = 1000.

        # max theta
        eids_to_delete = get_bad_shells(
            model, xyz_cid0, nid_map,
            min_theta=min_theta,
            max_theta=max_theta_active,
            max_skew=max_skew,
            max_aspect_ratio=max_aspect_ratio,
            max_taper_ratio=max_taper_ratio)
        assert eids_to_delete == [100], eids_to_delete

        delete_bad_shells(
            model,
            min_theta=min_theta,
            max_theta=max_theta_active,
            max_skew=max_skew,
            max_aspect_ratio=max_aspect_ratio,
            max_taper_ratio=max_taper_ratio)

        assert len(model.elements) == 0, model.elements
        os.remove(bdf_filename)
Esempio n. 23
0
    def test_tri_quality_01(self):
        r"""
        Identify a 180+ degree quad

        EID = 100 (perfect)
        y
        ^     3
        |    / \
        |   /   \
        |  /     \
        | /       \
        |/         \
        1-----------2----> x

        EID = 101 (???)
        y
        ^     6
        |    /   \
        |   /       \
        |  /           \
        | /               \
        |/                   \
        4----------------------5----> x

        """
        msg = (
            'CEND\n'
            'BEGIN BULK\n'
            'GRID,1,,0.,   0.,0.\n'
            'GRID,2,,1.,   0.,0.\n'
            'GRID,3,,0.5,  1.,0.\n'
            'CTRIA3,100,1, 1,2,3\n'

            'GRID,4,,  0.,   0.,5.\n'
            'GRID,5,,300.,  0.,5.\n'
            'GRID,6,, 0.5,  1.,5.\n'
            'CTRIA3,101,1, 4,5,6\n'

            'PSHELL,1,1,0.1\n'
            'MAT1,1,3.0,, 0.3\n'
            'ENDDATA'
        )
        log = SimpleLogger(level='error')
        bdf_filename = 'cquad4.bdf'
        with open(bdf_filename, 'w') as bdf_file:
            bdf_file.write(msg)

        model = read_bdf(bdf_filename, log=log, xref=True)
        xyz_cid0 = model.get_xyz_in_coord(cid=0, fdtype='float32')
        nid_map = {}
        for i, nid in enumerate(sorted(model.nodes.keys())):
            nid_map[nid] = i


        max_skew_active = 70.
        max_theta_active = 115.
        max_aspect_ratio_active = 15.

        min_theta = 0.1
        max_theta = 1000.
        max_skew = 1000.
        max_aspect_ratio = 1000.

        # max theta
        eids_to_delete = get_bad_shells(
            model, xyz_cid0, nid_map,
            min_theta=min_theta,
            max_theta=max_theta_active,
            max_skew=max_skew,
            max_aspect_ratio=max_aspect_ratio,
        )
        assert eids_to_delete == [101], eids_to_delete

        # max skew
        eids_to_delete = get_bad_shells(
            model, xyz_cid0, nid_map,
            min_theta=min_theta,
            max_theta=max_theta,
            max_skew=max_skew_active,
            max_aspect_ratio=max_aspect_ratio,
        )
        assert eids_to_delete == [101], eids_to_delete

        # aspect ratio
        eids_to_delete = get_bad_shells(
            model, xyz_cid0, nid_map,
            min_theta=min_theta,
            max_theta=max_theta,
            max_skew=max_skew,
            max_aspect_ratio=max_aspect_ratio_active,
        )
        assert eids_to_delete == [101], eids_to_delete

        delete_bad_shells(
            model,
            min_theta=min_theta,
            max_theta=max_theta_active,
            max_skew=max_skew,
            max_aspect_ratio=max_aspect_ratio,
        )
        assert eids_to_delete == [101], eids_to_delete
Esempio n. 24
0
    def test_flutter(self):
        """checks the FLUTTER/FLFACT cards"""
        log = SimpleLogger(level='warning')
        model = BDF(log=log)
        sid = 75
        method = 'PKNL'
        idensity = 76
        imach = 77
        ivelocity = 78

        # density, mach, velocity
        flutter1 = FLUTTER(sid, method, idensity, imach, ivelocity)
        flutter2 = FLUTTER.add_card(BDFCard(['FLUTTER', sid, method, idensity, imach,
                                             ivelocity]), comment='flutter card')
        assert flutter2.headers == ['density', 'mach', 'velocity'], flutter2.headers

        flutter1.validate()
        flutter1.write_card()
        flutter2.validate()
        flutter2.write_card()
        model.flutters[75] = flutter1

        densities = np.linspace(0., 1.)
        density = FLFACT(idensity, densities)
        model.flfacts[idensity] = density

        machs = np.linspace(0.7, 0.8)
        mach = FLFACT(imach, machs)
        mach = FLFACT.add_card(BDFCard(['FLFACT', imach] + list(machs)), comment='flfact card')
        mach.write_card(size=16)
        model.flfacts[imach] = mach

        velocities = np.linspace(3., 4.)
        velocity = FLFACT(ivelocity, velocities)
        velocity.validate()
        velocity.write_card()
        assert velocity.min() == 3., velocities
        assert velocity.max() == 4., velocities
        model.flfacts[ivelocity] = velocity

        ikfreq = 79
        kfreqs = np.linspace(0.1, 0.2)
        card = ['FLFACT', ikfreq] + list(kfreqs)
        model.add_card(card, card[0])
        kfreq = model.FLFACT(ikfreq)
        kfreq.validate()
        kfreq.write_card()
        assert kfreq.min() == 0.1, kfreqs
        assert kfreq.max() == 0.2, kfreqs
        model.flfacts[ikfreq] = kfreq

        ikfreq2 = 80
        card = ['FLFACT', ikfreq2, 10., 'THRU', 20., 11]
        model.add_card(card, card[0])
        kfreq = model.FLFACT(ikfreq2)
        kfreq.validate()
        kfreq.write_card()
        assert kfreq.min() == 10., 'min=%s; card=%s factors=%s' % (kfreq.min(), card, kfreq.factors)
        assert kfreq.max() == 20., 'max=%s; card=%s factors=%s' % (kfreq.max(), card, kfreq.factors)
        model.flfacts[ikfreq] = kfreq

        ikfreq3 = 81
        factors = [10., 'THRU', 20., 10]
        kfreq = FLFACT(ikfreq3, factors)
        kfreq.validate()
        kfreq.write_card()
        assert kfreq.min() == 10., 'min=%s; factors=%s' % (kfreq.min(), factors)
        assert kfreq.max() == 20., 'max=%s; factors=%s' % (kfreq.max(), factors)
        model.flfacts[ikfreq] = kfreq

        # density, mach, rfreq
        card = ['FLUTTER', 85, 'KE', idensity, imach, ikfreq]
        model.add_card(card, card[0])
        model.cross_reference()
        flutter = model.Flutter(85)
        assert flutter.headers == ['density', 'mach', 'reduced_frequency'], flutter.headers
        flutter.write_card()
Esempio n. 25
0
    def test_nsm_cquad4(self):
        eid_quad = 1
        eid_tri = 2
        eid_conrod = 3
        eid_crod = 4
        eid_pbeaml = 5
        eid_pbarl = 6
        pid_pbeaml = 40
        pid_pshell = 10
        pid_pbeaml = 21
        pid_pbarl = 31
        pid_prod = 41
        mid = 100
        E = 3.0e7
        G = None
        nu = 0.3
        nids = [1, 2, 3, 4]
        model = BDF(debug=False)
        model.add_grid(1, [0., 0., 0.])
        model.add_grid(2, [1., 0., 0.])
        model.add_grid(3, [1., 1., 0.])
        model.add_grid(4, [0., 1., 0.])
        model.add_cquad4(eid_quad, pid_pshell, nids) # area=1.0
        model.add_ctria3(eid_tri, pid_pshell, nids[:-1]) # area=0.5
        model.add_conrod(eid_conrod, mid, [1, 2], A=1.0, j=0.0, c=0.0, nsm=0.0, comment='')

        x = [0., 0., 1.]
        g0 = None
        model.add_cbar(eid_pbarl, pid_pbarl, [1, 2], x, g0, offt='GGG', pa=0, pb=0,
                       wa=None, wb=None, comment='')
        model.add_cbeam(eid_pbeaml, pid_pbeaml, nids, x, g0, offt='GGG', bit=None,
                        pa=0, pb=0, wa=None, wb=None, sa=0, sb=0, comment='')
        model.add_crod(eid_crod, pid_prod, [1, 2])
        model.add_prod(pid_prod, mid, A=0.1)
        model.add_pshell(pid_pshell, mid1=mid, t=0.1) #, nsm=None)

        bar_type = 'BAR'
        dims = [1., 2.]
        xxb = [0.]
        model.add_pbarl(pid_pbarl, mid, bar_type, dims, group='MSCBML0', nsm=0., comment='')

        beam_type = 'BAR'
        dims = [[1., 2.]]
        nsm = [0.0]
        model.add_pbeaml(pid_pbeaml, mid, beam_type, xxb, dims, so=None, nsm=nsm,
                         group='MSCBML0', comment='')
        model.add_mat1(mid, E, G, nu, rho=0.0)

        # TODO: these are correct barring incorrect formulas
        model.add_nsm1(1000, 'PSHELL', 1.0, pid_pshell, comment='nsm1') # correct; 1.5
        model.add_nsm1(1001, 'ELEMENT', 1.0, eid_quad) # correct; 1.0
        model.add_nsm1(1002, 'ELEMENT', 1.0, [eid_quad, eid_tri]) # correct; 1.5
        model.add_nsm1(1003, 'ELEMENT', 1.0, [eid_pbeaml]) # correct; 1.0
        model.add_nsm1(1004, 'ELEMENT', 1.0, eid_pbarl) # correct; 1.0
        model.add_nsm1(1005, 'ELEMENT', 1.0, 'ALL') # crash according to QRG b/c mixed type; 2.5
        model.add_nsm1(1006, 'PSHELL', 1.0, 'ALL') # correct; 1.5
        model.add_nsm1(1007, 'PSHELL', 1.0, [10, 'THRU', 12]) # correct; 1.5
        model.add_nsm1(1008, 'PSHELL', 1.0, [10, 'THRU', 12, 'BY', 2]) # correct; 1.5
        model.add_nsm1(1009, 'PBARL', 1.0, pid_pbarl) # correct; 1.0
        model.add_nsm1(1010, 'PBEAML', 1.0, pid_pbeaml) # correct; 1.0
        model.add_nsm1(1011, 'PROD', 1.0, pid_prod) # correct; 1.0
        model.add_nsm1(1012, 'CONROD', 1.0, eid_conrod) # correct; 1.0

        #model.add_nsml1(sid, nsm_type, value, ids)
        model.add_nsml1(2000, 'PSHELL', 1.0, pid_pshell, comment='nsml1') # correct; 1.0
        model.add_nsml1(2001, 'ELEMENT', 1.0, eid_quad) # correct; 1.0
        model.add_nsml1(2002, 'ELEMENT', 1.0, [eid_quad, eid_tri]) # correct; 1.0
        model.add_nsml1(2003, 'ELEMENT', 1.0, [eid_pbeaml]) # correct; 1.0
        model.add_nsml1(2004, 'ELEMENT', 1.0, eid_pbarl) # correct; 1.0
        model.add_nsml1(2005, 'ELEMENT', 1.0, 'ALL') # crash according to QRG b/c mixed type; 1.0
        model.add_nsml1(2006, 'PSHELL', 1.0, 'ALL') # correct; 1.0
        model.add_nsml1(2007, 'PSHELL', 1.0, [10, 'THRU', 12]) # correct; 1.0
        model.add_nsml1(2008, 'PSHELL', 1.0, [10, 'THRU', 12, 'BY', 2]) # correct; 1.0
        model.add_nsml1(2009, 'PBARL', 1.0, pid_pbarl) # correct; 1.0
        model.add_nsml1(2010, 'PBEAML', 1.0, pid_pbeaml) # correct; 1.0
        model.add_nsml1(2011, 'PROD', 1.0, pid_prod) # correct; 1.0
        model.add_nsml1(2012, 'CONROD', 1.0, eid_conrod) # correct; 1.0

        #model.add_nsml1(2011, 'PSHELL', 1.0, ['1240', 'THRU', '1250', None, None, # correct; 0.0
        #'2567', 'THRU', '2575',
        #'35689', 'THRU', '35700', None, None,
        #'76', 'THRU', '85',])
        #print(model.nsms[2011])

        model.add_nsm(3000, 'PSHELL', pid_pshell, 1.0, comment='nsm') # correct; 1.5
        model.add_nsm(3001, 'ELEMENT', eid_quad, 1.0) # correct; 1.0
        model.add_nsm(3003, 'ELEMENT', [eid_pbeaml], 1.0) # correct; 1.0
        model.add_nsm(3004, 'ELEMENT', eid_pbarl, 1.0) # correct; 1.0
        model.add_nsm(3009, 'PBARL', pid_pbarl, 1.0) # correct; 1.0
        model.add_nsm(3010, 'PBEAML', pid_pbeaml, 1.0) # correct; 1.0
        model.add_nsm(3011, 'PROD', pid_prod, 1.0) # correct; 1.0
        model.add_nsm(3012, 'CONROD', eid_conrod, 1.0) # correct; 1.0

        model.add_nsml(4000, 'PSHELL', pid_pshell, 1.0, comment='nsml') # correct; 1.0
        model.add_nsml(4001, 'ELEMENT', eid_quad, 1.0) # correct; 1.0
        model.add_nsml(4003, 'ELEMENT', [eid_pbeaml], 1.0) # correct; 1.0
        model.add_nsml(4004, 'ELEMENT', eid_pbarl, 1.0) # correct; 1.0
        model.add_nsml(4009, 'PBARL', pid_pbarl, 1.0) # correct; 1.0
        model.add_nsml(4010, 'PBEAML', pid_pbeaml, 1.0) # correct; 1.0
        model.add_nsml(4011, 'PROD', pid_prod, 1.0) # correct; 1.0
        model.add_nsml(4012, 'CONROD', eid_conrod, 1.0) # correct; 1.0

        model.pop_parse_errors()
        model.cross_reference()
        model.pop_xref_errors()

        expected_dict = {
            # NSM1
            1000 : 1.5,
            1001 : 1.0,
            1002 : 1.5,
            1003 : 1.0,
            1004 : 1.0,
            1005 : -1.0,  # crash
            1006 : 1.5,
            1007 : 1.5,
            1008 : 1.5,
            1009 : 1.0,
            1010 : 1.0,
            1011 : 1.0,
            1012 : 1.0,

            #model.add_nsml1(sid, nsm_type, value, ids)
            # NSML1
            2000 : 1.0,
            2001 : 1.0,
            2002 : 1.0,
            2003 : 1.0,
            2004 : 1.0,
            2005 : -1.0, # crash
            2006 : 1.0,
            2007 : 1.0,
            2008 : 1.0,
            2009 : 1.0,
            2010 : 1.0,
            2011 : 1.0,
            2012 : 1.0,

            # NSM
            3000 : 1.5,
            3001 : 1.0,
            3003 : 1.0,
            3004 : 1.0,
            3009 : 1.0,
            3010 : 1.0,
            3011 : 1.0,
            3012 : 1.0,

            # NSM1
            4000 : 1.0,
            4001 : 1.0,
            4003 : 1.0,
            4004 : 1.0,
            4009 : 1.0,
            4010 : 1.0,
            4011 : 1.0,
            4012 : 1.0,
        }
        for nsm_id in sorted(model.nsms):
            mass1_expected = expected_dict[nsm_id]
            if mass1_expected == -1.0:
                with self.assertRaises(RuntimeError):
                    mass1, unused_cg, unused_I = mass_properties_nsm(model, nsm_id=nsm_id, debug=False)
            else:
                mass1, unused_cg, unused_I = mass_properties_nsm(model, nsm_id=nsm_id, debug=False)
                if mass1 != mass1_expected:
                    unused_mass2 = mass_properties_nsm(model, nsm_id=nsm_id, debug=True)[0]
                    raise RuntimeError('nsm_id=%s mass != %s; mass1=%s' % (nsm_id, mass1_expected, mass1))
            #print('mass[%s] = %s' % (nsm_id, mass))
            #print('----------------------------------------------')

        model2 = save_load_deck(model)
        model2.reset_rslot_map()
        #print(model2._type_to_slot_map)
        model2.elements = {}

        type_to_id_map = {}
        for card_type, ids in model2._type_to_id_map.items():
            if card_type in ['CQUAD4', 'CTRIA3', 'CBEAM', 'CONROD', 'CBAR', 'CROD']:
                pass
            elif card_type in ['NSM', 'NSM1', 'NSML', 'NSML1', 'MAT1',
                               'PBARL', 'PBEAM', 'PSHELL', 'PCOMP', 'PROD', 'PBEAML', 'GRID']:
                type_to_id_map[card_type] = ids
            else:
                raise NotImplementedError(str((card_type, ids)))
        model2._type_to_id_map = type_to_id_map

        model2.log = SimpleLogger(level='error')

        # don't crash on the null case
        for nsm_id in sorted(model2.nsms):
            mass, unused_cg, unused_I = mass_properties_nsm(model2, nsm_id=nsm_id, debug=False)
            self.assertEqual(mass, 0.0)
Esempio n. 26
0
    def test_thermal_1(self):
        """tests various thermal cards"""
        log = SimpleLogger(level='warning')
        model = BDF(log=log, debug=False)
        model.sol = 101
        lines = [
            'SUBCASE 1',
            '  DISP(PLOT) = ALL',
            '  ANALYSIS = HEAT',
            'BEGIN BULK',
        ]
        model.case_control_deck = CaseControlDeck(lines, log=None)

        model.add_grid(11, [0., 0., 0.])
        model.add_grid(12, [1., 0., 0.])
        model.add_grid(13, [1., 1., 0.])
        model.add_grid(14, [0., 1., 0.])
        model.add_grid(15, [0., 2., 0.])

        eid = 1
        pid = 1
        mid = 1
        nodes = [11, 12, 13, 14]
        model.add_cquad4(eid,
                         pid,
                         nodes,
                         theta_mcid=0.0,
                         zoffset=0.,
                         tflag=0,
                         T1=1.0,
                         T2=1.0,
                         T3=1.0,
                         T4=1.0,
                         comment='')
        model.add_pshell(pid, mid1=1, t=0.1)

        eid = 10
        nids = [11, 12, 13, 15]
        pid = 2
        model.add_ctetra(eid, pid, nids)
        model.add_psolid(pid, mid)

        E = 3.0e7
        G = None
        nu = 0.3
        model.add_mat1(mid, E, G, nu)

        eid = 2
        Type = 'AREA3'
        chbdyg = CHBDYG(eid,
                        Type,
                        nodes,
                        iview_front=0,
                        ivew_back=0,
                        rad_mid_front=0,
                        rad_mid_back=0,
                        comment='chbdyg')
        with self.assertRaises(ValueError):
            chbdyg.validate()

        Type = 'AREA4'
        chbdyg = model.add_chbdyg(eid,
                                  Type,
                                  nodes,
                                  iview_front=0,
                                  ivew_back=0,
                                  rad_mid_front=0,
                                  rad_mid_back=0,
                                  comment='chbdyg')
        chbdyg.raw_fields()

        eid = 3
        eid2 = 4
        side = 1
        chbdye = model.add_chbdye(eid,
                                  eid2,
                                  side,
                                  iview_front=0,
                                  ivew_back=0,
                                  rad_mid_front=0,
                                  rad_mid_back=0,
                                  comment='chbdye')
        chbdye.raw_fields()

        eid = 4
        g1 = 11
        g2 = 12
        pid = 10
        chbdyp = model.add_chbdyp(eid,
                                  pid,
                                  Type,
                                  g1,
                                  g2,
                                  g0=0,
                                  gmid=None,
                                  ce=0,
                                  iview_front=0,
                                  ivew_back=0,
                                  rad_mid_front=0,
                                  rad_mid_back=0,
                                  e1=None,
                                  e2=None,
                                  e3=None,
                                  comment='chbdyp')
        chbdyp.raw_fields()

        phbdy = model.add_phbdy(pid,
                                af=None,
                                d1=None,
                                d2=None,
                                comment='phbdy')
        phbdy.raw_fields()

        #---------------------------
        ta = 2
        ta1 = 2
        pconid = 11
        conv = model.add_conv(eid,
                              pconid,
                              ta,
                              film_node=0,
                              cntrlnd=0,
                              comment='conv')
        conv.raw_fields()
        pconv = model.add_pconv(pconid,
                                mid,
                                form=0,
                                expf=0.0,
                                ftype=0,
                                tid=None,
                                chlen=None,
                                gidin=None,
                                ce=0,
                                e1=None,
                                e2=None,
                                e3=None,
                                comment='pconv')
        pconv.raw_fields()

        pconid = 12
        convm = model.add_convm(eid,
                                pconid,
                                ta1,
                                film_node=0,
                                cntmdot=0,
                                ta2=None,
                                mdot=1.0,
                                comment='convm')
        convm.raw_fields()
        coef = 0.023
        pconvm = model.add_pconvm(pconid,
                                  mid,
                                  coef,
                                  form=0,
                                  flag=0,
                                  expr=0.0,
                                  exppi=0.0,
                                  exppo=0.0,
                                  comment='pconvm')
        pconvm.raw_fields()

        radmid = 42
        absorb = 0.2
        emissivity = 0.8
        radm = model.add_radm(radmid, absorb, emissivity, comment='radm')
        radm.raw_fields()

        famb = 100.
        nodamb = 33
        eids = [1]
        cntrlnd = 1000
        radbc = model.add_radbc(nodamb, famb, cntrlnd, eids, comment='radbc')
        radbc.raw_fields()

        sid = 43
        qvol = 17.
        control_point = 1001
        elements = [1, 2]
        qvol = model.add_qvol(sid,
                              qvol,
                              control_point,
                              elements,
                              comment='qvol')
        qvol.raw_fields()

        q0 = 18.
        t_source = 19.
        eids = [2]
        qvect = model.add_qvect(sid,
                                q0,
                                eids,
                                t_source,
                                ce=0,
                                vector_tableds=None,
                                control_id=0,
                                comment='qvect')
        qvect.raw_fields()

        q0 = 15.8
        flag = 'POINT'
        grids = [-1]
        qhbdy = model.add_qhbdy(sid, flag, q0, grids, af=None, comment='qhbdy')
        qhbdy.raw_fields()

        qflux = 20.
        eids = [1]
        qbdy1 = model.add_qbdy1(sid, qflux, eids, comment='qbdy1')
        qbdy1.raw_fields()

        eid = 1
        qfluxs = 12.
        qbdy2 = model.add_qbdy2(sid, eid, qfluxs, comment='qbdhy2')
        qbdy2.raw_fields()

        q0 = 14.
        cntrlnd = 57
        eids = [1, 2]
        qbdy3 = model.add_qbdy3(sid, q0, cntrlnd, eids, comment='qbdy3')
        qbdy3.raw_fields()

        temperature = 13.3
        model.add_tempd(sid, temperature, comment='tempd')

        temperatures = {
            15: 37.,
            16: 38.,
        }
        model.add_temp(sid, temperatures)
        #-------------------------
        bdf_filename = StringIO()
        bdf_filename2 = StringIO()
        bdf_filename3 = StringIO()
        bdf_filename4 = StringIO()

        model.validate()
        model._verify_bdf(xref=False)
        model.write_bdf(bdf_filename,
                        encoding=None,
                        size=8,
                        is_double=False,
                        interspersed=False,
                        enddata=None,
                        close=False)

        model.cross_reference()
        model.pop_xref_errors()

        model._verify_bdf(xref=True)
        model.write_bdf(bdf_filename2,
                        encoding=None,
                        size=16,
                        is_double=False,
                        interspersed=False,
                        enddata=None,
                        close=False)
        model.write_bdf(bdf_filename3,
                        encoding=None,
                        size=16,
                        is_double=True,
                        interspersed=False,
                        enddata=None,
                        close=False)
        write_bdf_symmetric(model,
                            bdf_filename4,
                            encoding=None,
                            size=8,
                            is_double=False,
                            enddata=None,
                            close=False,
                            plane='xz')
        #model.cross_reference()

        #print(bdf_filename.getvalue())

        bdf_filename2.seek(0)
        model2 = read_bdf(bdf_filename2, xref=False, log=log, debug=False)
        model2.safe_cross_reference()
        save_load_deck(model, punch=False, run_convert=False)
Esempio n. 27
0
"""tests the pyNastran solver"""
from __future__ import print_function, unicode_literals
import os
import unittest

import pyNastran
from pyNastran.utils.log import SimpleLogger
from pyNastran.bdf.dev_vectorized.solver.solver import Solver

pkg_path = pyNastran.__path__[0]
test_path = os.path.join(pkg_path, 'bdf', 'dev_vectorized', 'solver', 'test')
log = SimpleLogger('warning', encoding='utf8')


class TestSolver(unittest.TestCase):
    """tests the pyNastran solver"""
    def test_celas1(self):
        """runs a 1 element CELAS1 problem"""
        fargs = {
            '--k': 1.0,
            '--f': 1.0,
            '--m': 1.0,
            '--debug': False,
            'BDFNAME': os.path.join(test_path, 'celas1.bdf'),
            'BDFBASE': 'celas1',
        }
        solver = Solver(fargs, log=log)
        solver.run_solver()

    def test_celas2(self):
        """runs a 1 element CELAS2 problem"""
Esempio n. 28
0
from pyNastran.bdf.bdf import BDF, read_bdf, CaseControlDeck, PARAM
from pyNastran.bdf.mesh_utils.convert import convert, get_scale_factors
from pyNastran.utils.log import SimpleLogger

pkg_path = pyNastran.__path__[0]

np.set_printoptions(edgeitems=3,
                    infstr='inf',
                    linewidth=75,
                    nanstr='nan',
                    precision=3,
                    suppress=True,
                    threshold=1000,
                    formatter=None)

log = SimpleLogger(level='error')


class TestConvert(unittest.TestCase):
    """various BDF conversion tests"""
    def test_convert_bar(self):
        """converts a bar model"""
        model_path = os.path.join(pkg_path, '..', 'models', 'beam_modes')
        bdf_filename = os.path.join(model_path, 'beam_modes.dat')
        bdf_filename_out = os.path.join(model_path, 'beam_modes_temp.bdf')
        bdf_filename_out2 = os.path.join(model_path,
                                         'beam_modes_converted.bdf')
        model = read_bdf(bdf_filename, log=log, validate=False)
        #card_lines = ['EIGRL', 42, None, None, 20]
        #model.add_card(card_lines, 'EIGRL')
        #model.case_control_deck = CaseControlDeck(lines)
Esempio n. 29
0
 def test_simple_logger(self):
     log = SimpleLogger(level='critical')
     log.info('info')
     log.warning('warning')
     log.error('error')
     log.debug('debug')
     log.exception('exception')
     out = log.critical('critical')
     assert out is None
Esempio n. 30
0
    def test_aesurf_1(self):
        """checks the AESURF/AELIST cards"""
        aesid = 10
        label = 'FLAP'
        cid1 = 0
        aelist_id1 = 10
        cid2 = None
        alid2 = None
        aesurf1 = AESURF(aesid, label, cid1, aelist_id1, cid2, alid2,
                         #eff, ldw,
                         #crefc, crefs, pllim, pulim,
                         #hmllim, hmulim, tqllim, tqulim,
                         comment='aesurf comment')
        aesurf2 = AESURF.add_card(BDFCard(
            [
                'AESURF', aesid, label, cid1, aelist_id1, cid2, alid2,
                #eff, ldw,
                #crefc, crefs, pllim, pulim,
                #hmllim, hmulim, tqllim, tqulim,
            ]), comment='aesurf comment')
        #assert aesurf1 == aesurf2

        cid2 = 1
        coord = CORD2R(cid2, rid=0, origin=[0., 0., 0.],
                       zaxis=[1., 0., 0.], xzplane=[0., 1., 1.], comment='')

        aelist_id1 = 10
        aelist_id2 = 20
        aesurf2 = AESURF.add_card(BDFCard(
            [
                'AESURF', aesid, label, cid1, aelist_id1, cid2, aelist_id2,
                #eff, ldw,
                #crefc, crefs, pllim, pulim,
                #hmllim, hmulim, tqllim, tqulim,
            ]), comment='aesurf comment')

        aesurf1.validate()
        aesurf2.validate()
        log = SimpleLogger(level='warning')

        model = BDF()
        model._add_coord_object(coord)
        model._add_aesurf_object(aesurf1)

        elements = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
        aelist = AELIST(aelist_id1, elements)
        model._add_aelist_object(aelist)

        elements = [11, 22, 33, 44, 55, 66, 77, 88, 99]
        aelist = AELIST(aelist_id2, elements)
        model._add_aelist_object(aelist)

        aesurf1.cross_reference(model)
        aesurf1.write_card()
        aesurf1.raw_fields()
        aesurf1.uncross_reference()
        aesurf1.write_card()
        aesurf1.cross_reference(model)
        aesurf1.raw_fields()

        aesurf2.cross_reference(model)
        aesurf2.write_card()
        aesurf2.raw_fields()
        aesurf2.uncross_reference()
        aesurf2.write_card()
        aesurf2.cross_reference(model)
        aesurf2.raw_fields()