Example #1
0
 def test_deqatn_1b(self):
     model = BDF(debug=None)
     #model.cards_to_read.add('DEQATN')
     model.test_deqatn = True
     card = ["DEQATN", 1000, "MAXDIFF(t1,t2)=abs(t2-t1)/t1"]
     with self.assertRaises(ValueError):
         model.add_card(card, "DEQATN", is_list=False)
    def test_enddata_1(self):
        """
        There is an ENDDATA is in the baseline BDF, so None -> ENDDATA
        """
        model = BDF(debug=False)
        full_path = os.path.join(test_path, 'include_dir')
        model2 = BDF(debug=False)

        bdf_filename = 'test_include.bdf'
        if not os.path.exists(bdf_filename):
            bdf_filename = os.path.join(test_path, bdf_filename)
        model2.read_bdf(bdf_filename, xref=True, punch=False)
        for out_filename, is_enddata, write_flag in [
            ('enddata1.bdf', True, None),
            ('enddata2.bdf', True, True),
            ('enddata3.bdf', False, False)]:
            out_filename = os.path.join(test_path, out_filename)
            model2.write_bdf(out_filename=out_filename+'.out', interspersed=True, size=8,
                             is_double=False, enddata=write_flag)

            with codec_open(out_filename + '.out', 'r') as f:
                data = f.read()

            if is_enddata:
                self.assertTrue('ENDDATA' in data)
            else:
                self.assertFalse('ENDDATA' in data)
            os.remove(out_filename + '.out')
    def test_include_04(self):
        #if PY2:
            #wb = 'wb'
        #else:
            #wb = 'w'

        with codec_open('include4.bdf', 'w') as f:
            f.write('$ pyNastran: punch=True\n')
            f.write('$ pyNastran: dumplines=True\n')
            f.write("INCLUDE 'include4b.inc'\n\n")

        with codec_open('include4b.inc', 'w') as f:
            f.write('$ GRID comment\n')
            f.write('GRID,2,,2.0\n')

        model = BDF(log=log, debug=False)
        model.read_bdf('include4.bdf')
        model.write_bdf('include4.out.bdf')

        os.remove('include4.out.bdf')
        os.remove('include4b.inc')
        #os.remove('include4.inc')
        # os.remove('c.bdf')
        # os.remove('executive_control.inc')
        # os.remove('case_control.inc')

        self.assertEqual(len(model.nodes), 1)
        self.assertEqual(model.nnodes, 1, 'nnodes=%s' % model.nnodes)
    def test_op2_bcell_01(self):
        folder = os.path.abspath(os.path.join(test_path, '..', 'models'))
        bdf_filename = os.path.join(folder, 'other', 'bcell9p0.bdf')
        op2_filename = os.path.join(folder, 'other', 'bcell9p0.op2')
        make_geom = False
        write_bdf = False
        write_f06 = True
        debug = False
        op2file = os.path.join(folder, op2_filename)
        bdf = BDF(debug=False)
        bdf.read_bdf(bdf_filename, xref=False)

        debug = False
        debug_file = 'debug.out'
        op2 = OP2(debug=debug, debug_file=debug_file)
        op2.read_op2(op2_filename)
        assert os.path.exists(debug_file), os.listdir('.')

        self._verify_ids(bdf, op2, isubcase=1)

        msg = ''
        for isubcase, keys in sorted(iteritems(op2.subcase_key)):
            if len(keys) != 1:
                msg += 'isubcase=%s keys=%s len(keys) != 1\n' % (isubcase, keys)
                if len(keys) == 0:
                    continue
            if isubcase != keys[0]:
                msg += 'isubcase=%s != key0=%s keys=%s\n' % (isubcase, keys[0], keys)
        if msg:
            assert msg == '', msg
        op2.write_f06('junk.f06')
        os.remove('junk.f06')
 def test_disable_cards(self):
     bdf_filename = os.path.join(root_path, '..', 'models',
         'solid_bending', 'solid_bending.bdf')
     model = BDF(debug=False)
     model.disable_cards(['CTETRA'])
     model.read_bdf(bdf_filename)
     assert len(model.elements) == 0, len(model.elements)
    def test_enddata_2(self):
        """
        There is no ENDDATA is in the baseline BDF, so None -> no ENDDATA
        """
        model = BDF(debug=False)
        full_path = os.path.join(test_path, 'include_dir')
        model2 = BDF(debug=False)
        bdf_name = os.path.join(test_path, 'test_mass.dat')
        model2.read_bdf(bdf_name, xref=True, punch=False)
        for out_filename, is_enddata, write_flag in [
            ('test_mass1.dat', False, None),
            ('test_mass2.dat', True, True),
            ('test_mass3.dat', False, False)]:
            model2.write_bdf(out_filename=out_filename, interspersed=True, size=8,
                             is_double=False, enddata=write_flag)

            with codec_open(out_filename, 'r') as f:
                data = f.read()

            msg = 'outfilename=%r expected=%r write_flag=%s card_count=%r' % (out_filename, is_enddata, write_flag, model2.card_count.keys())
            if is_enddata:
                self.assertTrue('ENDDATA' in data, msg)
            else:
                self.assertFalse('ENDDATA' in data, msg)
            os.remove(out_filename)
    def test_include_end_02(self):
        with codec_open('a.bdf', 'w') as f:
            f.write('CEND\n')
            f.write('BEGIN BULK\n')
            f.write('GRID,1,,1.0\n')
            f.write("INCLUDE 'b.bdf'\n\n")
            f.write('GRID,4,,4.0\n')

        with codec_open('b.bdf', 'w') as f:
            f.write('GRID,2,,2.0\n')
            f.write("INCLUDE 'c.bdf'\n\n")
            f.write('GRID,5,,5.0\n')

        with codec_open('c.bdf', 'w') as f:
            f.write('GRID,3,,3.0\n\n')

        model = BDF(log=log, debug=False)
        model.read_bdf('a.bdf')
        model.write_bdf('a.out.bdf')

        os.remove('a.bdf')
        os.remove('b.bdf')
        os.remove('c.bdf')
        os.remove('a.out.bdf')
        self.assertEqual(len(model.nodes), 5)
        self.assertEqual(model.nnodes, 5, 'nnodes=%s' % model.nnodes)
    def test_dmig_5(self):
        model = BDF(debug=False)
        bdf_name = os.path.join(test_path, 'dmig.bdf')
        model.read_bdf(bdf_name, xref=False, punch=True)
        out = model.dmigs['POLE'].get_matrix(is_sparse=False)

        POLE_actual, rows_reversed, cols_reversed = out
        #print "---POLE_actual---\n", POLE_actual
        mag_expected = array([
            [1.0, 4.0, 5.0],
            [0.0, 2.0, 6.0],
            [0.0, 0.0, 3.0],
        ])

        a_matrix = model.dmigs['POLE']
        assert len(a_matrix.GCi) == 6, 'len(GCi)=%s GCi=%s matrix=\n%s' % (len(a_matrix.GCi), a_matrix.GCi, a_matrix)
        assert len(a_matrix.GCj) == 6, 'len(GCj)=%s GCj=%s matrix=\n%s' % (len(a_matrix.GCj), a_matrix.GCj, a_matrix)

        A_expected = mag_expected * cos(radians(45))
        B_expected = mag_expected * sin(radians(45))
        POLE_expected = A_expected + B_expected * 1j

        msg = '\n%s_actual\n%s\n\n----' % ('POLE', POLE_actual)
        msg += '\n%s_expected\n%s\n----' % ('POLE', POLE_expected)
        msg += '\n%s_delta\n%s\n----' % ('POLE', POLE_actual-POLE_expected)
        self.assertTrue(array_equal(POLE_expected, POLE_actual), msg)
    def test_dmig_4(self):
        model = BDF(debug=False)
        bdf_name = os.path.join(test_path, 'dmig.bdf')
        model.read_bdf(bdf_name, xref=False, punch=True)

        out = model.dmigs['IMAGS'].get_matrix(is_sparse=False)
        IMAGS_actual, rows_reversed, cols_reversed = out
        #print "---IMAGS_actual---\n", IMAGS_actual
        IMAGS_expected_real = [
            [1.0, 0.5, 0.25],
            [0.5, 2.0, 0.75],
            [0.25, 0.75, 3.0],
        ]
        IMAGS_expected_imag = [
            [1.1, 0.51, 0.251],
            [0.51, 2.1, 0.751],
            [0.251, 0.751, 3.1],
        ]
        a_matrix = model.dmigs['IMAGS']
        assert len(a_matrix.GCi) == 6, 'len(GCi)=%s GCi=%s matrix=\n%s' % (len(a_matrix.GCi), a_matrix.GCi, a_matrix)
        assert len(a_matrix.GCj) == 6, 'len(GCj)=%s GCj=%s matrix=\n%s' % (len(a_matrix.GCj), a_matrix.GCj, a_matrix)

        IMAGS_expected = array(IMAGS_expected_real) + array(IMAGS_expected_imag)*1j
        msg = '\n%s_actual\n%s\n\n----' % ('IMAGS', IMAGS_actual)
        msg += '\n%s_expected\n%s\n----' % ('IMAGS', IMAGS_expected)
        msg += '\n%s_delta\n%s\n----' % ('IMAGS', IMAGS_actual-IMAGS_expected)
        self.assertTrue(array_equal(IMAGS_expected, IMAGS_actual), msg)
def get_eigs(debug=False):
    patch_files = glob.glob('patch_*.bdf')
    patch_numbers = []
    evals = []
    for patch_filename in patch_files:
        patch_number = patch_filename.split('_')[1].split('.')[0]
        patch_numbers.append(int(patch_number))
        model = BDF(debug=debug)
        model.read_bdf(patch_filename)
        #eids = model.elements.keys()
        op2_filename = ''.join([patch_filename[:-4], '.op2'])
        eigenvalues = np.array(get_eigenvalues(op2_filename, debug=debug))
        i = np.where(eigenvalues > 0.0)
        min_eigenvalue = eigenvalues[i].min()
        evals.append(min_eigenvalue)
        print('Patch:%s  Min eigenvalue:%s' % (patch_number, min_eigenvalue))

    fig = plt.figure(figsize=(12, 9))
    plt.plot(patch_numbers, evals, label='Eigenvalues')
    plt.xticks(fontsize=12, y=-0.01)
    plt.yticks(fontsize=12, x=-0.01)
    plt.title('', fontsize=16, y=1.02)
    plt.xlabel('Patch Number', fontsize=12, y=-0.01)
    plt.ylabel('Minimum Eigenvalue', fontsize=12, x=-0.01)
    # plt.legend()
    plt.show()
    plt.close()
Example #11
0
    def __init__(self, make_geom=True,
                 debug=False, log=None, debug_file=None):
        """
        Initializes the OP2 object

        :param make_geom: reads the BDF tables (default=False)
        :param debug: enables the debug log and sets the debug in the logger (default=False)
        :param log: a logging object to write debug messages to
         (.. seealso:: import logging)
        :param debug_file: sets the filename that will be written to (default=None -> no debug)
        """
        assert make_geom == True, make_geom

        BDF.__init__(self, debug=debug, log=log)
        GEOM1.__init__(self)
        GEOM2.__init__(self)
        GEOM3.__init__(self)
        GEOM4.__init__(self)

        EPT.__init__(self)
        MPT.__init__(self)
        DIT.__init__(self)
        DYNAMICS.__init__(self)

        OP2.__init__(self, debug, log=log, debug_file=debug_file)
        self.make_geom = make_geom
Example #12
0
    def test_include_end(self):
        with codec_open('a.bdf', 'w') as bdf_file:
            bdf_file.write('CEND\n')
            bdf_file.write('BEGIN BULK\n')
            bdf_file.write('GRID,1,,1.0\n')
            bdf_file.write("INCLUDE 'b.bdf'\n\n")

        with codec_open('b.bdf', 'w') as bdf_file:
            bdf_file.write('GRID,2,,2.0\n')
            bdf_file.write("INCLUDE 'c.bdf'\n\n")

        with codec_open('c.bdf', 'w') as bdf_file:
            bdf_file.write('GRID,3,,3.0\n\n')
            bdf_file.write("ENDDATA\n")

        model = BDF(log=log, debug=False)
        model.read_bdf('a.bdf')
        model.write_bdf('a.out.bdf')

        os.remove('a.bdf')
        os.remove('b.bdf')
        os.remove('c.bdf')
        os.remove('a.out.bdf')
        self.assertEqual(len(model.nodes), 3)
        self.assertEqual(model.nnodes, 3, 'nnodes=%s' % model.nnodes)
Example #13
0
    def test_include_05(self):
        with codec_open('include5.bdf', 'w') as bdf_file:
            bdf_file.write('$ pyNastran: punch=True\n')
            bdf_file.write('$ pyNastran: dumplines=True\n')
            bdf_file.write("INCLUDE 'include5b.inc'\n\n")

        with codec_open('include5b.inc', 'w') as bdf_file:
            bdf_file.write('ECHOON\n')
            bdf_file.write('$ GRID comment\n')
            bdf_file.write('GRID,2,,2.0\n')
            bdf_file.write('ECHOOFF\n')
            bdf_file.write('GRID,3,,3.0\n')
            bdf_file.write('grid,4,,4.0\n')
            bdf_file.write('grid ,5,,5.0\n')

        model = BDF(log=log, debug=False)
        model.read_bdf('include5.bdf')
        assert model.echo is False, model.echo
        #model.write_bdf('include5.out.bdf')

        # os.remove('c.bdf')
        # os.remove('executive_control.inc')
        # os.remove('case_control.inc')

        self.assertEqual(len(model.nodes), 4)
        self.assertEqual(model.nnodes, 4, 'nnodes=%s' % model.nnodes)

        model2 = read_bdf(bdf_filename='include5.bdf', xref=True, punch=False,
                          log=log, encoding=None)
        self.assertEqual(len(model2.nodes), 4)
        self.assertEqual(model2.nnodes, 4, 'nnodes=%s' % model.nnodes)
        os.remove('include5.bdf')
        #os.remove('include5.out.bdf')
        os.remove('include5b.inc')
Example #14
0
def run_map_deflections(nodeList, bdf_filename, out_filename, cart3d, cart3d2, log=None):
    fbase, ext = os.path.splitext(out_filename)
    if ext == '.op2':
        deflections = read_op2(out_filename)
    elif ext == '.f06':
        deflections = read_f06(out_filename)
    else:
        raise NotImplementedError('out_filename = %r' % out_filename)

    mesh = BDF(debug=True, log=log)
    mesh.read_bdf(bdf_filename, include_dir=None, xref=True, punch=False)

    nodeList = remove_duplicate_nodes(nodeList, mesh)
    C = getCmatrix(nodeList, mesh)
    wS = get_WS(nodeList, deflections)
    del deflections

    aPoints = read_cart3d_points(cart3d)
    wA = get_WA(nodeList, C, wS, mesh, aPoints)
    del C
    #del wS
    del mesh

    write_new_cart3d_mesh(cart3d, cart3d2, wA)
    return (wA,wS)
Example #15
0
 def test_pbeam_11(self):
     model = BDF()
     lines = [
         #'PBEAM         1       1    1.e8    1.e8    1.e8              10.      1.',
         #'             NO      1.    3.e5    3.e8    3.e8              10.      1.',
         'PBEAM          1       1    1.+8    1.+8    1.+8             10.      1.',
         '              NO      1. 300000.    3.+8    3.+8             10.      1.',
     ]
     model.add_card(lines, 'PBEAM', is_list=False)
     lines_expected = [
         'PBEAM          1       1    1.+8    1.+8    1.+8             10.      1.',
         '+',
         '              NO      1. 300000.    3.+8    3.+8             10.      1.',
     ]
     prop = model.properties[1]
     #print(prop.raw_fields())
     lines_actual = prop.write_card().split('\n')
     msgA = ''
     for line_expected, line_actual in zip(lines_expected, lines_actual):
         #assert line_expected == line_actual, line_actual
         actual = str(line_actual)
         expected = str(line_expected)
         msg = msgA + '\nactual   = %r\n' % actual
         msg += 'expected = %r' % expected
         self.assertEqual(actual, expected, msg)
    def test_mpc_03(self):
        model = BDF(debug=False)

        card = [
            'MPC            1    1002       4      1.    1000       4-.129394',
            '                    1000       5-7.152-3    1000       6-.013655',
            '                    1004       2   123.3',]
        msg8 = (
            'MPC            1    1002       4      1.    1000       4-.129394\n'
            '                    1000       5-7.152-3    1000       6-.013655\n'
            '                    1004       2   123.3\n')
        msg16 = (
            'MPC*                   1            1002               4              1.\n'
            '*                   1000               4        -.129394\n'
            '*                                   1000               5        -.007152\n'
            '*                   1000               6        -.013655\n'
            '*                                   1004               2           123.3\n'
            '*\n')


        card = model.add_card(card, 'MPC', is_list=False)
        assert card is not None
        mpc = MPC.add_card(card)
        msg_8_actual = mpc.write_card(size=8)
        msg_16_actual = mpc.write_card(size=16)
        msg_16_double_actual = mpc.write_card(size=16, is_double=True)
        self.check_card(msg8, msg_8_actual)
        self.check_card(msg16, msg_16_actual)
Example #17
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 #18
0
def get_free_edges(bdf_filename, eids=None, maps=None):
    """
    assumes no solids/bars

    Parameters
    ----------
    bdf_filename : str, BDF()
       a BDF object or filename
    maps : List[...] (default=None -> calculate)
       the output from _get_maps(eids, map_names=None,
                              consider_0d=False, consider_0d_rigid=False,
                              consider_1d=False, consider_2d=True, consider_3d=False)

    Returns
    -------
    free_edges : List[(int nid1, int nid2), ...]
       the free edges
    """
    if isinstance(bdf_filename, string_types):
        model = BDF(debug=False)
        model.read_bdf(bdf_filename)
    else:
        model = bdf_filename

    free_edges = []
    if maps is None:
        maps = model._get_maps(eids, map_names=None,
                               consider_0d=False, consider_0d_rigid=False,
                               consider_1d=False, consider_2d=True, consider_3d=False)
    edge_to_eid_map = maps[0]
    for edge, eids in iteritems(edge_to_eid_map):
        if len(eids) == 2:
            continue
        free_edges.append(edge)
    return free_edges
Example #19
0
    def test_include_05(self):
        #if PY2:
            #wb = 'wb'
        #else:
            #wb = 'w'

        with codec_open('include5.bdf', 'w') as f:
            f.write('$ pyNastran: punch=True\n')
            f.write('$ pyNastran: dumplines=True\n')
            f.write("INCLUDE 'include5b.inc'\n\n")

        with codec_open('include5b.inc', 'w') as f:
            f.write('ECHOON\n')
            f.write('$ GRID comment\n')
            f.write('GRID,2,,2.0\n')
            f.write('ECHOOFF\n')
            f.write('GRID,3,,3.0\n')
            f.write('grid,4,,4.0\n')
            f.write('grid ,5,,5.0\n')

        model = BDF(log=log, debug=False)
        model.read_bdf('include5.bdf')
        assert model.echo == False, model.echo
        #model.write_bdf('include4.out.bdf')

        os.remove('include5.bdf')
        #os.remove('include5.out.bdf')
        os.remove('include5b.inc')
        # os.remove('c.bdf')
        # os.remove('executive_control.inc')
        # os.remove('case_control.inc')

        self.assertEqual(len(model.nodes), 4)
        self.assertEqual(model.nnodes, 4, 'nnodes=%s' % model.nnodes)
Example #20
0
def process_nastran(bdf_filename, fmt2, fname2, data=None, debug=True):
    """
    Converts Nastran to STL/Cart3d/Tecplot
    """
    assert fmt2 in ['stl', 'cart3d', 'tecplot', 'ugrid', 'nastran'], 'format2=%s' % fmt2
    xref = True
    if fmt2 == 'ugrid':
        xref = False
    model = BDF(debug=debug)
    model.read_bdf(bdf_filename, xref=xref)

    if data['--scale'] != 1.0:
        scale = data['--scale']
        data['--scale'] = 1.0
        for nid, node in iteritems(model.nodes):
            xyz = node.get_position()
            node.xyz *= scale
            node.cp = 0
            del node.cp_ref

    if fmt2 == 'stl':
        nastran_to_stl(model, fname2, is_binary=data['--binary'])
    elif fmt2 == 'cart3d':
        cart3d = nastran_to_cart3d(model)
        cart3d.write_cart3d(fname2)
    elif fmt2 == 'tecplot':
        tecplot = nastran_to_tecplot(model)
        tecplot_filename = fname2
        tecplot.write_tecplot(tecplot_filename, adjust_nids=False)
    elif fmt2 == 'ugrid':
        ugrid = nastran_to_ugrid(model, fname2)
    elif fmt2 == 'nastran':
        model.write_bdf(fname2, size=16)
    else:
        raise NotImplementedError(fmt2)
Example #21
0
    def __init__(self, make_geom=True,
                 debug=False, log=None, debug_file=None, mode='msc'):
        """
        Initializes the OP2 object

        Parameters
        ----------
        make_geom : bool; default=False
            reads the BDF tables
        debug : bool; default=False
            enables the debug log and sets the debug in the logger
        log: log()
            a logging object to write debug messages to
            (.. seealso:: import logging)
        debug_file : default=None -> no debug
            sets the filename that will be written to
        mode : str; default='msc'
            {msc, nx}
        """
        # make_geom=False, debug=True, log=None, debug_file=None

        BDF.__init__(self, debug=debug, log=log)
        GEOM1.__init__(self)
        GEOM2.__init__(self)
        GEOM3.__init__(self)
        GEOM4.__init__(self)

        EPT.__init__(self)
        MPT.__init__(self)
        DIT.__init__(self)
        DYNAMICS.__init__(self)

        OP2.__init__(self, debug, log=log, debug_file=debug_file, mode=mode)
        self.make_geom = True
Example #22
0
    def test_include_end(self):
        if PY2:
            wb = 'wb'
        else:
            wb = 'w'
        f = open('a.bdf', wb)
        f.write('CEND\n')
        f.write('BEGIN BULK\n')
        f.write('GRID,1,,1.0\n')
        f.write("INCLUDE 'b.bdf'\n\n")

        f = open('b.bdf', wb)
        f.write('GRID,2,,2.0\n')
        f.write("INCLUDE 'c.bdf'\n\n")

        f = open('c.bdf', wb)
        f.write('GRID,3,,3.0\n\n')
        f.write("ENDDATA\n")
        f.close()

        model = BDF(log=log, debug=False)
        model.read_bdf('a.bdf')
        model.write_bdf('a.out.bdf')

        os.remove('a.bdf')
        os.remove('b.bdf')
        os.remove('c.bdf')
        os.remove('a.out.bdf')
        self.assertEqual(len(model.nodes), 3)
        self.assertEqual(model.nnodes, 3, 'nnodes=%s' % model.nnodes)
Example #23
0
def example4():
    """
    Example 4: Get Element ID & Type - Level 2
    """
    # Print the Element ID and its type(e.g. CQUAD4, CTRIA3, etc.) to a file

    # note this skips rigidElements

    # this example will demonstate:
    #  - accessing element type information

    # our model
    import pyNastran
    pkg_path = pyNastran.__path__[0]
    test_path = os.path.join(pkg_path, '..', 'models', 'solid_bending')
    bdf_filename = os.path.join(test_path, 'solid_bending.bdf')

    # instantiate the model
    from pyNastran.bdf.bdf import BDF
    model = BDF()
    model.read_bdf(bdf_filename, xref=True)
    f = open('junk.out', 'w')

    ####
    ####Method 1 - using objects
    ####---------------------------------
    ####
    for eid,element in sorted(model.elements.items()):
        msg = 'eid=%s type=%s\n' %(eid, element.type)
    f.write(msg)
Example #24
0
 def test_solid_03(self):
     """checks linear static solid material"""
     mid = 2
     pid = 4
     rho = 0.1
     cards = [
         # $ Solid Nodes
         ["GRID", 11, 0, 0.0, 0.0, 0.0, 0],
         ["GRID", 12, 0, 1.0, 0.0, 0.0, 0],
         ["GRID", 13, 0, 1.0, 1.0, 0.0, 0],
         ["GRID", 14, 0, 0.0, 1.0, 0.0, 0],
         ["GRID", 15, 0, 0.0, 0.0, 2.0, 0],
         ["GRID", 16, 0, 1.0, 0.0, 2.0, 0],
         ["GRID", 17, 0, 1.0, 1.0, 2.0, 0],
         ["GRID", 18, 0, 0.0, 1.0, 2.0, 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, 0.0, 0],
         ["GRID", 22, 0, 1.0, 0.0, 0.0, 0],
         ["GRID", 23, 0, 1.0, 1.0, 0.0, 0],
         ["GRID", 24, 0, 0.0, 0.0, 2.0, 0],
         ["GRID", 25, 0, 1.0, 0.0, 2.0, 0],
         ["GRID", 26, 0, 1.0, 1.0, 2.0, 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, None, "PLASTIC", 0.0, 1, 1, 100000.0],
     ]
     model = BDF(debug=False)
     for fields in cards:
         model.add_card(fields, fields[0], is_list=True)
     model.cross_reference()
Example #25
0
    def test_pbeam_03(self):
        bdf = BDF(debug=False)
        lines = [
            'PBEAM,39,6,2.9,3.5,5.97',
            '     ,  , ,2.0,-4.0',
            '     ,YES,1.0,5.3,56.2,78.6',
            '     ,   ,   ,2.5,-5.0',
            '     ,   ,   ,1.1,    ,2.1,,0.21',
            '     ,   ,   ,   ,    ,0.5,,0.0',
        ]

        card = bdf.process_card(lines)
        cardi = BDFCard(card)
        card2 = PBEAM.add_card(cardi)
        fields = card2.raw_fields()

        lines_expected = [
            'PBEAM         39       6     2.9     3.5    5.97      0.      0.      0.',
            '              0.      0.      2.     -4.      0.      0.      0.      0.',
            '             YES      1.     5.3    56.2    78.6      0.      0.      0.',
            '              0.      0.     2.5     -5.      0.      0.      0.      0.',
            '              1.      1.     1.1      0.     2.1     2.1     .21     .21',
            '              0.      0.      0.      0.      .5      .5      0.      0.',
        ]
        self._compare(fields, lines_expected)
Example #26
0
    def run(self, bdfName):
        model = BDF()
        model.cardsToRead = get_cards()
        model.readBDF(bdfName)
        cc = model.caseControlDeck
        #print cc.subcases
        analysisCases = []
        for (isub, subcase) in sorted(cc.subcases.iteritems()):
            if subcase.hasParameter('LOAD'):
                analysisCases.append(subcase)

        #print analysisCases
        for case in analysisCases:
            print(case)
            (value, options) = case.get_parameter('STRESS')
            print("STRESS value   = %s" % (value))
            print("STRESS options = %s" % (options))

            if case.hasParameter('TEMPERATURE(INITIAL)'):
                (value, options) = case.get_parameter('TEMPERATURE(INITIAL)')
                print('value   = %s' % (value))
                print('options = %s' % (options))
                raise NotImplementedError('TEMPERATURE(INITIAL) not supported')
                #integrate(B.T*E*alpha*dt*Ads)
            #sys.exit('starting case')
            self.runCase(model, case)
 def test_strain(self):
     for folder, prefix, subcase in CASES:
         bdf = BDF(debug=False)
         op2 = OP2(debug=False)
         basepath = os.path.join(pkg_path, 'op2', 'test', folder)
         bdf.read_bdf(os.path.join(basepath, prefix + '.bdf'))
         op2.read_op2(os.path.join(basepath, prefix + '.op2'))
         op2_new = data_in_material_coord(bdf, op2)
         for vecname in strain_vectors:
             vector = getattr(op2_new, vecname).get(subcase)
             if vector is None:
                 continue
             name = os.path.join(basepath, '{0}_subcase_{1:02d}.txt'.format(vecname, subcase))
             if not os.path.isfile(name):
                 raise AssertionError('Not found reference result {0}'.format(name))
             ref_result = np.loadtxt(name)
             data = vector.data
             eids = get_eids_from_op2_vector(vector)
             check = eids != 0
             if 'cquad8' in vecname:
                 assert np.allclose(data[:, check][:, 0::10, :], ref_result[0::10], rtol=RTOL, atol=ATOL)
                 assert np.allclose(data[:, check][:, 1::10, :], ref_result[1::10], rtol=RTOL, atol=ATOL)
             else:
                 assert np.allclose(data[:, check], ref_result, rtol=RTOL, atol=ATOL)
         print('OK')
Example #28
0
def example5():
    """
    Example 5: Get Elements by Node ID - Level 2
    """

    # this example will demonstate:
    #  - getting the list of elements that share a certain node

    # our model
    import pyNastran
    pkg_path = pyNastran.__path__[0]
    test_path = os.path.join(pkg_path, '..', 'models', 'solid_bending')
    bdf_filename = os.path.join(test_path, 'solid_bending.bdf')

    # instantiate the model
    from pyNastran.bdf.bdf import BDF
    model = BDF()
    model.read_bdf(bdf_filename, xref=True)
    f = open('junk.out', 'w')

    # given a Node, get the Elements Attached to that Node
    # assume node 55
    # doesnt support 0d/1d elements yet
    nid_to_eids_map = model.get_node_id_to_element_ids_map()
    eids = nid_to_eids_map[55]

    # convert to elements instead of element IDs
    elements = []
    for eid in eids:
        elements.append(model.Element(eid))

    print("eids = %s" % eids)
    print("elements =\n %s" % elements)
Example #29
0
    def test_cpenta_01(self):
        """tests a cpenta15"""
        lines = [
            'CPENTA,85,22,201,202,203,205,206,207,+PN2',
            '+PN2,209,210,217,  ,  ,  ,213,214,',
            ',218'
        ]
        bdf = BDF(debug=False)
        card = bdf.process_card(lines)
        card = BDFCard(card)

        solid = CPENTA15.add_card(card, comment='cpenta15')
        solid.write_card(size=8, is_double=False)
        solid.write_card(size=16, is_double=False)
        solid.raw_fields()

        node_ids = solid.node_ids
        assert node_ids == [201, 202, 203, 205, 206, 207,
                            209, 210, 217, None, None, None, 213, 214, 218], node_ids
        nids = [201, 202, 203, 205, 206, 207,
                209, 210, 217, None, None, None, 213, 214, 218]
        CPENTA.add_card(card, comment='spike')
        eid = 85
        pid = 22
        bdf.add_cpenta(eid, pid, nids, comment='spike')
Example #30
0
    def test_encoding_write(self):
        from pyNastran.bdf.bdf import BDF

        mesh = BDF()
        mesh.add_card(['GRID', 100000, 0, 43.91715, -29., .8712984], 'GRID')
        mesh.write_bdf('out.bdf')
        lines_expected = [
            '$pyNastran: version=msc',
            '$pyNastran: punch=False',
            '$pyNastran: encoding=ascii',
            '$NODES',
            'GRID      100000        43.91715    -29..8712984',
        ]
        bdf_filename = 'out.bdf'
        with codec_open(bdf_filename, 'r', encoding='ascii') as f:
            lines = f.readlines()
            i = 0
            for line, line_expected in zip(lines, lines_expected):
                line = line.rstrip()
                line_expected = line_expected.rstrip()
                msg = 'The lines are not the same...i=%s\n' % i
                msg += 'line     = %r\n' % line
                msg += 'expected = %r\n' % line_expected
                msg += '-------------\n--Actual--\n%s' % ''.join(lines)
                msg += '-------------\n--Expected--\n%s' % ''.join(lines_expected)
                self.assertEqual(line, line_expected, msg)
                i += 1
Example #31
0
    def test_cord2_rcs_01(self):
        """
        all points are located at <30,40,50>
        """
        model = BDF(debug=False)
        cards = [
            [
                #'$ 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',],
            [
                #'$ 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',],
            [
                #'$ 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',],
        ]
        for lines in cards:
            card = model._process_card(lines)
            model.add_card(card, card[0])

        unused_xyz_cid0b = model.get_xyz_in_coord_no_xref(cid=0, fdtype='float64')
        unused_xyz_cid0c = model.get_xyz_in_coord_no_xref(cid=12, fdtype='float64')
        model.cross_reference()

        xyz_cid0_actual = array([
            [30., 40., 50.],
            [30., 40., 50.],
            [30., 40., 50.],
        ], dtype='float64')
        for nid in model.nodes:
            node = model.Node(nid)
            a = array([30., 40., 50.])
            b = node.get_position()
            self.assertTrue(allclose(array([30., 40., 50.]),
                                     node.get_position()), str(a - b))

        xyz_cid0 = model.get_xyz_in_coord(cid=0, fdtype='float64')
        array_equal(xyz_cid0_actual, xyz_cid0)

        unused_icd_transform, icp_transform, xyz_cp, nid_cp_cd = model.get_displacement_index_xyz_cp_cd()
        xyz_cid0_xform = model.transform_xyzcp_to_xyz_cid(
            xyz_cp, nid_cp_cd[:, 0], icp_transform, cid=0)
        array_equal(xyz_cid0_actual, xyz_cid0_xform)
        assert array_equal(nid_cp_cd[:, 0], array([10, 11, 12]))

        unused_xyz_cid_10 = model.transform_xyzcp_to_xyz_cid(
            xyz_cp, nid_cp_cd[:, 0], icp_transform, cid=10)
        unused_xyz_cid_11 = model.transform_xyzcp_to_xyz_cid(
            xyz_cp, nid_cp_cd[:, 0], icp_transform, cid=11)
        unused_xyz_cid_12 = model.transform_xyzcp_to_xyz_cid(
            xyz_cp, nid_cp_cd[:, 0], icp_transform, cid=12)
Example #32
0
    def test_create_coord_line(self):
        """tests creating a series of coordinate systems down an axis"""
        model = BDF(debug=False)
        model.add_grid(1, [0., 0., 0.])
        model.add_grid(2, [0., 100., 0.])
        eid = 10
        mid = 11
        nids = [1, 2]
        model.add_conrod(eid, mid, nids, A=1.0, j=0.0, c=0.0, nsm=0.0,
                         comment='')
        E = 3.0e7
        G = None
        nu = 0.3
        model.add_mat1(mid, E, G, nu, rho=0.0, a=0.0, tref=0.0, ge=0.0,
                       St=0.0, Sc=0.0, Ss=0.0, mcsid=0,
                       comment='')
        model.cross_reference()


        cid = 0
        unused_icd_transform, icp_transform, xyz_cp, nid_cp_cd = model.get_displacement_index_xyz_cp_cd(
            fdtype='float64', idtype='int32', sort_ids=True)
        nids = nid_cp_cd[:, 0]
        #unused_xyz_cid0 = model.transform_xyzcp_to_xyz_cid(
            #xyz_cp, nids, icp_transform,
            #cid=cid, in_place=False, atol=1e-6)


        npoints = 50
        percents = np.linspace(0., 1., num=npoints, endpoint=True)
        p1 = np.array([50., -100, 0.])
        p2 = np.array([50., 100, 0.])

        cids = create_coords_along_line(model, p1, p2, percents, cid=0, axis=cid)
        cid_to_inids = get_nodes_along_axis_in_coords(
            model, nids, xyz_cp, icp_transform,
            cids)
        make_monpnt1s_from_cids(model, nids, cids, cid_to_inids)
Example #33
0
    def test_add_coord_cards(self):
        """tests the ``add_card`` method"""
        model = BDF(debug=False)
        fields = ['CORD1R',
                  10, 1, 2, 3,
                  11, 7, 8, 9]
        model.add_card(fields, 'CORD1R')

        fields = ['CORD1R',
                  12, 1, 2, 3,
                  13, 7, 8, 9]
        model.add_card(fields, 'CORD1S')

        fields = ['CORD1R',
                  14, 1, 2, 3,
                  15, 7, 8, 9]
        model.add_card(fields, 'CORD1C')
        model.pop_parse_errors()
        #print(model.coords)
        model.pop_xref_errors()
        self.assertEqual(len(model.coords), 7)
Example #34
0
    def test_cord2r_02(self):
        grid = ['GRID       20143       7 -9.31-4  .11841 .028296']
        coord = [
            'CORD2R         7           1.135 .089237  -.0676    .135 .089237  -.0676',
            '           1.135 .089237   .9324'
        ]

        model = BDF(debug=False)
        card = model._process_card(grid)
        model.add_card(card, card[0])

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

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

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

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

        msg = '\nexpected=%s \nactual  =%s \ndiff    =%s' % (expected, xyz, diff)
        assert allclose(diff, 0.), msg
        coord = model.Coord(7)
        coord.beta_n(1)
        coord.beta_n(2)
        coord.beta_n(3)
        coord.beta_n(6)
        with self.assertRaises(AttributeError):
            self.assertTrue(array_equal(coord.T(), coord.beta_n(2)))
        #with self.assertRaises(NotImplementedError):
            #self.assertTrue(array_equal(coord.T(), coord.beta_n(2)))

        model2 = BDF(debug=False)
        cid = 7
        origin = [1.135, .089237, -.0676]
        zaxis = [.135, .089237, -.0676]
        xzplane = [1.135, .089237, .9324]
        coord2 = model2.add_cord2r(cid, origin, zaxis, xzplane, rid=0, comment='cord2r')
        coord2.comment = ''
        assert coord == coord2, 'coord:\n%r\ncoord2:\n%r' % (str(coord), str(coord2))
Example #35
0
    def test_cord1s_01(self):
        lines = ['cord1s,2,1,4,3']
        model = BDF(debug=False)
        card = model._process_card(lines)
        cardi = BDFCard(card)

        size = 8
        card = CORD1S.add_card(cardi)
        self.assertEqual(card.Cid(), 2)
        self.assertEqual(card.Rid(), 0)
        card.write_card(size, 'dummy')
        card.raw_fields()

        model = BDF(debug=False)
        model.set_error_storage(nparse_errors=0, stop_on_parsing_error=True,
                                nxref_errors=0, stop_on_xref_error=True)

        cid = 2
        grid1, grid2, grid3 = 1, 4, 3
        coord = model.add_cord1s(cid, grid1, grid2, grid3, comment='cord1c')
        coord.comment = ''
        assert coord == card, 'card:\n%r\ncoord:\n%r' % (str(coord), str(card))

        make_tri(model)
        coord.cross_reference(model)
        unused_cord2s = coord.to_cord2x(model, rid=0)

        model.pop_parse_errors()
        model.coords[cid] = coord
        save_load_deck(model, run_renumber=False)
Example #36
0
    def test_cord2_rcs_03(self):
        """
        all points are located at <30,40,50>
        """
        model = BDF(debug=False)
        cards = [
            [
                'CORD2S*                2               0              0.              0.',
                '*                     0.              0.              0.              1.*       ',
                '*                     1.              0.              1.',],
            [
                #'$ Coordinate System 30 : rectangular in spherical',
                'CORD2R*               30               2             14.             30.',
                '*                    70.    13.431863852   32.1458443949   75.2107442927*       ',
                '*          14.4583462334   33.4569982885   68.2297989286',],
            [
                #'$ Coordinate System 31 : cylindrical in spherical',
                'CORD2C*               31               2              3.             42.',
                '*                  -173.   2.86526881213   45.5425615252   159.180363517*       ',
                '*          3.65222385965   29.2536614627  -178.631312271',],
            [
                #'$ 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])
        unused_xyz_cid0b = model.get_xyz_in_coord_no_xref(cid=0, fdtype='float64')
        unused_xyz_cid0c = model.get_xyz_in_coord_no_xref(cid=32, fdtype='float64')
        bdf_file = StringIO()
        model.write_bdf(bdf_file, close=False)
        bdf_file.seek(0)

        #-------------------------------------------------
        model.cross_reference()

        model2 = BDFv(debug=False)
        model2.read_bdf(bdf_file, punch=True, xref=False, save_file_structure=False)
        bdf_file.seek(0)
        #-------------------------------------------------

        xyz_cid0_actual = array([
            [30., 40., 50.],
            [30., 40., 50.],
            [30., 40., 50.],
        ], dtype='float64')
        for nid in model.nodes:
            node = model.Node(nid)
            a = array([30., 40., 50.])
            b = node.get_position()
            self.assertTrue(allclose(array([30., 40., 50.]),
                                     node.get_position()), str(a - b))
        xyz_cid0 = model.get_xyz_in_coord(cid=0, fdtype='float64')
        assert np.allclose(xyz_cid0_actual, xyz_cid0), '%s' % (xyz_cid0_actual - xyz_cid0)

        out = model.get_displacement_index_xyz_cp_cd()
        unused_icd_transform, icp_transform, xyz_cp, nid_cp_cd = out
        nids = nid_cp_cd[:, 0]
        xyz_cid0_xform = model.transform_xyzcp_to_xyz_cid(
            xyz_cp, nids, icp_transform, cid=0)
        array_equal(xyz_cid0_actual, xyz_cid0_xform)
        assert array_equal(nids, array([30, 31, 32]))
        model2.nodes.nids = nid_cp_cd[:, 0]


        for cid in [30, 31, 32]:
            unused_xyz_cid_a = model.transform_xyzcp_to_xyz_cid(
                xyz_cp, nids, icp_transform, cid=cid)
            unused_xyz_cid_b = model2.transform_xyzcp_to_xyz_cid(
                xyz_cp, nids, icp_transform, cid=cid, atol=None)
            #assert np.allclose(xyz_cid_a, xyz_cid_b), '%s' % np.isclose(xyz_cid_a, xyz_cid_b)

            #print(xyz_cid_a)
            #print(xyz_cid_b)
            #print(xyz_cid_a - xyz_cid_b)
            #print('-------------')
            #assert array_equal(xyz_cid_a, xyz_cid_b), 'error=%s'  % (
                #xyz_cid_a - xyz_cid_b)

        #---------------------------------------------
        xyz_cid0 = model.transform_xyzcp_to_xyz_cid(
            xyz_cp, nids, icp_transform,
            cid=0, atol=None)
        array_equal(xyz_cid0_actual, xyz_cid0)

        model.write_bdf(bdf_file, close=False)

        model3 = BDF(debug=False)
        origin = [14., 30., 70.]
        zaxis = [13.431863852, 32.1458443949, 75.2107442927]
        xzplane = [14.4583462334, 33.4569982885, 68.2297989286]
        cord2r = model3.add_cord2r(30, origin, zaxis, xzplane, rid=2, comment='')

        origin = [3., 42., -173.]
        zaxis = [2.86526881213, 45.5425615252, 159.180363517]
        xzplane = [3.65222385965, 29.2536614627, -178.631312271]
        cord2c = model3.add_cord2c(31, origin, zaxis, xzplane, rid=2, comment='')

        origin = [22., 14., 85.]
        zaxis = [22.1243073983, 11.9537753718, 77.9978191005]
        xzplane = [21.0997242967, 13.1806120497, 88.4824763008]
        cord2s = model3.add_cord2s(32, origin, zaxis, xzplane, rid=2, comment='')

        assert cord2r == model.coords[cord2r.cid], 'cord2r:\n%r\ncord2r[cid]:\n%r' % (str(cord2r), str(model.coords[cord2r.cid]))
        assert cord2c == model.coords[cord2c.cid], 'cord2c:\n%r\ncord2c[cid]:\n%r' % (str(cord2c), str(model.coords[cord2c.cid]))
        assert cord2s == model.coords[cord2s.cid], 'cord2s:\n%r\ncord2s[cid]:\n%r' % (str(cord2s), str(model.coords[cord2s.cid]))
Example #37
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.',],
            [
                #'$ Coordinate System 20 : rectangular defined in cylindrical',
                'CORD2R*               20               1              7.             20.',
                '*                    -6.   7.07106781187   28.1301023542             -6.*       ',
                '*          7.70710678119             20.  -5.29289321881',],
            [
                #'$ 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',],
            [
                #'$ 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])
        unused_xyz_cid0b = model.get_xyz_in_coord_no_xref(cid=0, fdtype='float64')
        unused_xyz_cid0c = model.get_xyz_in_coord_no_xref(cid=22, fdtype='float64')
        model.cross_reference()

        xyz_cid0_actual = array([
            [30., 40., 50.],
            [30., 40., 50.],
            [30., 40., 50.],
        ], dtype='float64')
        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))
        xyz_cid0 = model.get_xyz_in_coord(cid=0, fdtype='float64')
        array_equal(xyz_cid0_actual, xyz_cid0)

        unused_icd_transform, icp_transform, xyz_cp, nid_cp_cd = model.get_displacement_index_xyz_cp_cd()
        xyz_cid0_xform = model.transform_xyzcp_to_xyz_cid(
            xyz_cp, nid_cp_cd[:, 0], icp_transform, cid=0)
        array_equal(xyz_cid0_actual, xyz_cid0_xform)
        assert array_equal(nid_cp_cd[:, 0], array([20, 21, 22]))

        unused_xyz_cid_20 = model.transform_xyzcp_to_xyz_cid(
            xyz_cp, nid_cp_cd[:, 0], icp_transform, cid=20)
        unused_xyz_cid_21 = model.transform_xyzcp_to_xyz_cid(
            xyz_cp, nid_cp_cd[:, 0], icp_transform, cid=21)
        unused_xyz_cid_22 = model.transform_xyzcp_to_xyz_cid(
            xyz_cp, nid_cp_cd[:, 0], icp_transform, cid=22)
Example #38
0
    def test_doptprm(self):
        """tests a doptprm"""
        #DOPTPRM    CONV1  .00001  DELOBJ .000001  DESMAX     100      P1       1
        #              P2      13
        model = BDF(debug=False)

        params = {
            'CONV1': 0.0001,
            'DELOBJ': 0.000001,
            'DESMAX': 100,
            'P1': 1,
            'P2': 13,
        }
        doptprm = model.add_doptprm(params, comment='doptprm')
        model.validate()
        model._verify_bdf(xref=False)
        model.cross_reference()
        model._verify_bdf(xref=True)

        doptprm.comment = ''
        doptprm.raw_fields()
        doptprm.write_card(size=8)
        doptprm.write_card(size=16)
        doptprm.write_card(size=16, is_double=True)
        save_load_deck(model)
Example #39
0
    def test_dvmrel1(self):
        """tests a DVMREL1"""
        model = BDF(debug=False)
        oid = 10
        mid1 = 4
        mp_min = 1e6
        mp_max = 1e7
        dvids = 11
        coeffs = 1.0
        dvmrel1_1 = model.add_dvmrel1(oid,
                                      'MAT1',
                                      mid1,
                                      'E',
                                      dvids,
                                      coeffs,
                                      mp_min=mp_min,
                                      mp_max=mp_max,
                                      c0=0.,
                                      validate=True,
                                      comment='dmvrel')

        oid = 11
        mid8 = 8
        dvmrel1_8 = model.add_dvmrel1(oid,
                                      'MAT8',
                                      mid8,
                                      'NU12',
                                      dvids,
                                      coeffs,
                                      mp_min=0.25,
                                      mp_max=0.3,
                                      c0=0.,
                                      validate=True,
                                      comment='dmvrel')
        oid = 12
        mid10 = 10
        dvmrel1_10 = model.add_dvmrel1(oid,
                                       'MAT10',
                                       mid10,
                                       'RHO',
                                       dvids,
                                       coeffs,
                                       mp_min=0.1,
                                       mp_max=0.2,
                                       c0=0.,
                                       validate=True,
                                       comment='dmvrel')

        oid = 21
        deqation = 42
        mp_name = 'E'
        mat_type = 'MAT1'
        labels = []
        dvmrel2_1 = model.add_dvmrel2(oid,
                                      mat_type,
                                      mid1,
                                      mp_name,
                                      deqation,
                                      dvids,
                                      labels,
                                      mp_min=None,
                                      mp_max=1e20,
                                      validate=True,
                                      comment='dvmrel')
        E = 30.e7
        G = None
        nu = 0.3
        #nids = [1, 2, 3]
        model.add_mat1(mid1, E, G, nu, rho=0.1, comment='mat1')

        e11 = 3e7
        e22 = 0.2 * e11
        nu12 = 0.3
        mat8 = model.add_mat8(mid8, e11, e22, nu12, comment='mat8')
        #bulk = c ** 2. * rho
        bulk = None
        rho = 0.1
        c = 4000.
        mat10 = model.add_mat10(mid10, bulk, rho, c, ge=0.0, comment='mat10')

        equation_id = 42
        eqs = ['fstress(x) = x + 10.']
        model.add_deqatn(equation_id, eqs, comment='deqatn')

        dvmrel1_1.raw_fields()
        dvmrel1_1.write_card(size=8)
        dvmrel1_1.write_card(size=16)

        dvmrel1_8.raw_fields()
        dvmrel1_8.write_card(size=8)
        dvmrel1_8.write_card(size=16)

        dvmrel1_10.raw_fields()
        dvmrel1_10.write_card(size=8)
        dvmrel1_10.write_card(size=16)

        dvmrel2_1.raw_fields()
        dvmrel2_1.write_card(size=8)
        dvmrel2_1.write_card(size=16)

        mat8.raw_fields()
        mat8.write_card(size=8)
        mat8.write_card(size=16)

        mat10.raw_fields()
        mat10.write_card(size=8)
        mat10.write_card(size=16)

        model.validate()
        model.cross_reference()

        dvmrel1_1.raw_fields()
        dvmrel1_8.raw_fields()
        dvmrel1_10.raw_fields()
        dvmrel2_1.raw_fields()
        mat8.raw_fields()
        mat10.raw_fields()
        save_load_deck(model)
Example #40
0
    def test_cord2c_01(self):
        """simple CORD2R/CORD2C input/output test"""
        lines = [
            'CORD2C*                3               0              0.              0.',
            '*                     0.              0.              0.              1.*',
            '*                     1.              0.              1.'
        ]
        model = BDF(debug=False)
        card = model._process_card(lines)
        cardi = BDFCard(card)
        cord2c = CORD2C.add_card(cardi)
        model._add_coord_object(cord2c)

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

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

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

        self.assertTrue(allclose(cord2r_c.i, array([0., 0., 1.])))
        delta = cord2r_c.j - array([1., 1., 0.]) / 2**0.5
        self.assertTrue(allclose(cord2r_c.j, array([1., 1., 0.]) / 2**0.5), str(delta))
        delta = cord2r_c.k - array([-1., 1., 0.]) / 2**0.5
        self.assertTrue(allclose(cord2r_c.k, array([-1., 1., 0.]) / 2**0.5), str(delta))
Example #41
0
def main():
    model = BDF(debug=False)
    model.read_bdf('plate.bdf')
    #model.write_bdf('plate2.bdf')

    max_deflection_error = 0.01
    nids = [
        19,
        20,
        21,
        22,
        23,
        24,
    ]
    nids = model.nodes.keys()
    nids.sort()

    def centroid_at_7(element):
        centroidi = element.Centroid()
        if centroidi[1] == 7.0:  # update if the element centroid > 6
            #print(centroidi)
            return True  # upper group
        return False  # lower group

    func = centroid_at_7
    #nnodes = len(model.nodes)

    #if 0:
    #split_model(model, nids, func)
    #model.write_bdf('plate_split.bdf')

    #model2 = BDF(debug=False)
    #model2.read_bdf('plate_split.bdf')
    #assert nnodes + 12 == len(model2.nodes), 'nnodes+12=%s nnodes2=%s' % (nnodes + 12, len(model2.nodes))
    ##assert nnodes + 6 == len(model2.nodes), 'nnodes+6=%s nnodes2=%s' % (nnodes + 6, len(model2.nodes))

    group1_nodes = set([])
    group2_nodes = set([])
    for eid, element in iteritems(model.elements):
        nids = element.node_ids
        if func(element):
            for nid in nids:
                group1_nodes.add(nid)
        else:
            for nid in nids:
                group2_nodes.add(nid)

    group1_nodes = list(group1_nodes)
    group2_nodes = list(group2_nodes)
    surface1 = {
        'group1_nodes': group1_nodes,
        'group2_nodes': group2_nodes,
        'dof': 1,  # dof in contact (1, 2, 3, 4, 5, 6) - nodes in group1/2
        'stiffness': 1.e8,  # stiffness of contact interface
        'cid': 0,  # coordinate system defining contact direction
        'glue': False,  #
        'initial_gap': 0.0,
        'max_deflection_error': max_deflection_error,
    }
    contact_surfaces = [surface1, surface1]
    main_bdf_filename = 'plate_split.bdf'
    main_op2_filename = 'plate_split.op2'
    main_op2_filename = 'plate.op2'

    run(contact_surfaces, main_bdf_filename, main_op2_filename)
Example #42
0
    def test_dvcrel1(self):
        """tests a DVCREL1, DVCREL2, DVGRID"""
        model = BDF(debug=False)
        oid = 10
        conm2_eid = 100
        cp_min = 0.01
        cp_max = 1.
        desvar_id = 11
        desvar_ids = 11
        coeffs = 1.0
        dvcrel1 = model.add_dvcrel1(oid,
                                    'CONM2',
                                    conm2_eid,
                                    'X2',
                                    desvar_ids,
                                    coeffs,
                                    cp_min,
                                    cp_max,
                                    c0=0.,
                                    validate=True,
                                    comment='dvcrel')

        label = 'X2_MASS'
        xinit = 0.1
        xlb = 0.01
        xub = 1.0
        desvar = model.add_desvar(desvar_id,
                                  label,
                                  xinit,
                                  xlb,
                                  xub,
                                  comment='desvar')

        mass = 1.
        nid1 = 100
        nid2 = 101
        conm2 = model.add_conm2(conm2_eid,
                                nid1,
                                mass,
                                cid=0,
                                X=None,
                                I=None,
                                comment='conm2')
        model.add_grid(100, xyz=[1., 2., 3.])
        model.add_grid(101, xyz=[2., 2., 4.])

        eid = 101
        pid = 102
        x = [1., 0., 0.]
        g0 = None
        cbar = model.add_cbar(eid,
                              pid, [nid1, nid2],
                              x,
                              g0,
                              offt='GGG',
                              pa=0,
                              pb=0,
                              wa=None,
                              wb=None,
                              comment='cbar')

        oid = 11
        equation_id = 100
        dvcrel2 = model.add_dvcrel2(oid,
                                    'CBAR',
                                    eid,
                                    'X3',
                                    equation_id,
                                    desvar_ids,
                                    labels=None,
                                    cp_min=2.,
                                    cp_max=4.,
                                    validate=True,
                                    comment='dvcrel2')

        mid = 1000
        dim = [1., 2., 0.1, 0.2]
        model.add_pbarl(pid,
                        mid,
                        'T',
                        dim,
                        group='MSCBMLO',
                        nsm=0.1,
                        comment='pbarl')
        E = 30.e7
        G = None
        nu = 0.3
        model.add_mat1(mid, E, G, nu, rho=0.1, comment='mat1')

        eqs = ['fx2(x) = x + 10.']
        deqatn = model.add_deqatn(equation_id, eqs, comment='deqatn')

        nid = 100
        dvid = 10000
        dxyz = [1., 2., 3.]
        dvgrid1 = model.add_dvgrid(dvid,
                                   nid,
                                   dxyz,
                                   cid=0,
                                   coeff=1.0,
                                   comment='dvgrid')

        nid = 101
        dvid = 10001
        dxyz = np.array([1., 2., 3.])
        dvgrid2 = model.add_dvgrid(dvid,
                                   nid,
                                   dxyz,
                                   cid=0,
                                   coeff=1.0,
                                   comment='dvgrid')

        model.pop_parse_errors()

        dvcrel1.raw_fields()
        dvcrel1.write_card(size=16)
        dvcrel2.raw_fields()
        dvcrel2.write_card(size=16)
        dvgrid1.raw_fields()
        dvgrid1.write_card(size=16)

        dvcrel1.comment = ''
        dvcrel2.comment = ''
        desvar.comment = ''
        dvgrid1.comment = ''
        dvcrel1_msg = dvcrel1.write_card(size=8)
        dvcrel2_msg = dvcrel2.write_card(size=8)
        desvar_msg = desvar.write_card(size=8)
        dvgrid_msg = dvgrid1.write_card(size=8)

        model.validate()
        model.cross_reference()
        model.pop_xref_errors()

        dvcrel1.raw_fields()
        dvcrel1.write_card(size=16)
        dvcrel1.write_card(size=8)

        dvcrel2.raw_fields()
        dvcrel2.write_card(size=16)
        dvcrel2.write_card(size=8)

        dvgrid1.raw_fields()
        dvgrid1.write_card(size=16)
        dvgrid1.write_card(size=8)

        deqatn.write_card()
        assert cbar.Mass() > 0, cbar.Mass()
        model.uncross_reference()

        #-------------------------------------------
        dvcrel1_lines = dvcrel1_msg.split('\n')
        dvcrel2_lines = dvcrel2_msg.split('\n')
        desvar_lines = desvar_msg.split('\n')
        dvgrid_lines = dvgrid_msg.split('\n')
        model2 = BDF(debug=True)

        model2.add_card(dvcrel1_lines, 'DVCREL1', is_list=False)
        model2.add_card(dvcrel2_lines, 'DVCREL2', is_list=False)
        model2.add_card(desvar_lines, 'DESVAR', is_list=False)
        model2.add_card(dvgrid_lines, 'DVGRID', is_list=False)
Example #43
0
def main():
    from pyNastran.bdf.bdf import BDF
    model = BDF()

    pid = 1
    model.add_pshell(pid,
                     mid1=1,
                     t=0.1,
                     mid2=None,
                     twelveIt3=1.0,
                     mid3=None,
                     tst=0.833333,
                     nsm=0.0,
                     z1=None,
                     z2=None,
                     mid4=None,
                     comment='')

    pid = 2
    mids = [1, 2]
    thicknesses = [0.1, 0.2]
    thetas = None
    model.add_pcomp(pid,
                    mids,
                    thicknesses,
                    thetas=thetas,
                    souts=None,
                    nsm=0.,
                    sb=0.,
                    ft=None,
                    tref=0.,
                    ge=0.,
                    lam=None,
                    z0=None,
                    comment='')

    pid = 3
    mids = [1, 2]
    thicknesses = [0.1, 0.2]
    thetas = None
    model.add_pcomp(pid,
                    mids,
                    thicknesses,
                    thetas=thetas,
                    souts=None,
                    nsm=0.,
                    sb=0.,
                    ft=None,
                    tref=0.,
                    ge=0.,
                    lam='SYM',
                    z0=0.,
                    comment='')

    pid = 5
    mid = 1
    Type = 'BOX'
    dim = [2., 1., 0.2, 0.1]
    model.add_pbarl(pid, mid, Type, dim)
    model.validate()

    pid = 6
    mid = 1
    Type = 'BAR'
    dim = [2., 1.]
    model.add_pbarl(pid, mid, Type, dim)
    model.validate()

    import sys
    from qtpy.QtWidgets import QApplication
    app = QApplication(sys.argv)
    window = PropertyPlotter(model, parent=None)

    # Enter the main loop
    app.exec_()
Example #44
0
    def test_dvprel1(self):
        """tests a DESVAR, DVPREL1, DVPREL2, DRESP1, DRESP2, DRESP3, DCONSTR, DSCREEN, DCONADD"""
        model = BDF(debug=False)
        dvprel1_id = 10
        desvar_id = 12
        desvar_ids = 12
        Type = 'PSHELL'
        pid = 20
        eid = 25
        mid = 30
        pname_fid = 'T'

        coeffs = 1.
        E = 30.e7
        G = None
        nu = 0.3
        nids = [1, 2, 3]

        label = 'T_SHELL'
        xinit = 0.1
        xlb = 0.01
        xub = 2.0

        model.add_grid(1, xyz=[0., 0., 0.])
        model.add_grid(2, xyz=[1., 0., 0.])
        model.add_grid(3, xyz=[1., 1., 0.])
        model.add_ctria3(eid, pid, nids, comment='ctria3')
        model.add_pshell(pid, mid1=30, t=0.1, comment='pshell')
        model.add_mat1(mid, E, G, nu, rho=0.1, comment='mat1')
        desvar = model.add_desvar(desvar_id,
                                  label,
                                  xinit,
                                  xlb,
                                  xub,
                                  comment='desvar')
        dvprel1 = model.add_dvprel1(dvprel1_id,
                                    Type,
                                    pid,
                                    pname_fid,
                                    desvar_ids,
                                    coeffs,
                                    p_min=None,
                                    p_max=1e20,
                                    c0=0.0,
                                    validate=True,
                                    comment='dvprel')

        dvprel2_id = dvprel1_id + 1
        deqation = 100
        dvids = desvar_id
        labels = None
        dvprel2 = model.add_dvprel2(dvprel2_id,
                                    Type,
                                    pid,
                                    pname_fid,
                                    deqation,
                                    dvids,
                                    labels,
                                    p_min=None,
                                    p_max=1e20,
                                    validate=True,
                                    comment='')
        equation_id = 100
        eqs = ['fstress(x) = x + 10.']
        model.add_deqatn(equation_id, eqs, comment='deqatn')
        #print(deqatn.object_attributes())
        #print(deqatn.func_str)
        #print(deqatn)

        dresp1_id = 42
        label = 'STRESS1'
        response_type = 'STRESS'
        property_type = 'PSHELL'
        region = None
        atta = 9
        attb = None
        atti = pid
        dresp1 = model.add_dresp1(dresp1_id,
                                  label,
                                  response_type,
                                  property_type,
                                  region,
                                  atta,
                                  attb,
                                  atti,
                                  validate=True,
                                  comment='dresp1')
        dconstr = model.add_dconstr(dresp1_id,
                                    dresp1_id,
                                    lid=-1.e20,
                                    uid=1.e20,
                                    lowfq=0.,
                                    highfq=1.e20,
                                    comment='dconstr')

        params = {
            (0, 'DRESP1'): [42],
            (1, 'DESVAR'): [12],
            (3, 'DNODE'): [[100, 101], [1, 2]],
        }
        dresp2_id = 43
        dequation = equation_id
        label = 'dresp2'
        region = None
        dresp2 = model.add_dresp2(dresp2_id,
                                  label,
                                  dequation,
                                  region,
                                  params,
                                  method='MIN',
                                  c1=100.,
                                  c2=0.005,
                                  c3=None,
                                  comment='dresp2')

        dresp3_id = 44
        label = 'dresp3'
        group = 'cat'
        Type = 'dog'
        region = None
        params = {
            (0, 'DRESP1'): [42],
            (1, 'DESVAR'): [12],
            (2, 'DRESP2'): [dresp2_id],
            (2, 'DVPREL1'): [dvprel1_id],
            (3, 'DVPREL2'): [dvprel2_id],
            (3, 'DNODE'): [[100, 101], [1, 2]],
        }
        dresp3 = model.add_dresp3(dresp3_id,
                                  label,
                                  group,
                                  Type,
                                  region,
                                  params,
                                  comment='dresp3')
        dresp3.raw_fields()

        oid = 1001
        dconstr = model.add_dconstr(oid,
                                    dresp1_id,
                                    lid=-1.e20,
                                    uid=1.e20,
                                    lowfq=0.,
                                    highfq=1.e20,
                                    comment='dconstr1')
        oid = 1002
        dconstr = model.add_dconstr(oid,
                                    dresp2_id,
                                    lid=-1.e20,
                                    uid=1.e20,
                                    lowfq=0.,
                                    highfq=1.e20)
        oid = 1003
        dconstr = model.add_dconstr(oid,
                                    dresp3_id,
                                    lid=-1.e20,
                                    uid=1.e20,
                                    lowfq=0.,
                                    highfq=1.e20)

        oid = 45
        dconstrs = [1001, 1002, 1003]
        dconadd = model.add_dconadd(oid, dconstrs, comment='dconadd')

        dscreen = model.add_dscreen('dunno', comment='dscreen')

        #print(dresp3)
        grid = model.add_grid(100)
        model.add_grid(101)
        model.pop_parse_errors()

        desvar.write_card(size=8)
        desvar.write_card(size=16)
        dvprel1.write_card(size=8)
        dvprel1.write_card(size=16)
        dconstr.write_card(size=8)
        dconstr.write_card(size=16)
        dresp1.write_card(size=8)
        dresp1.write_card(size=16)
        dresp1.write_card(size=16, is_double=True)
        dresp2.write_card(size=8)
        dresp2.write_card(size=16)
        dresp2.write_card(size=16, is_double=True)
        dresp3.write_card(size=8)
        dresp3.write_card(size=16)
        dresp3.write_card(size=16, is_double=True)
        dvprel2.write_card(size=8)
        dvprel2.write_card(size=16)
        dvprel2.write_card(size=16, is_double=True)
        dconadd.write_card(size=8)
        dconadd.write_card(size=16)
        dconadd.write_card(size=16, is_double=True)
        dscreen.write_card(size=8)
        dscreen.write_card(size=16)
        dscreen.write_card(size=16, is_double=True)

        model.validate()
        model._verify_bdf(xref=False)
        model.cross_reference()
        model.pop_xref_errors()

        desvar.write_card(size=8)
        desvar.write_card(size=16)
        desvar.raw_fields()
        dvprel1.write_card(size=8)
        dvprel1.write_card(size=16)
        dvprel1.raw_fields()
        dconstr.write_card(size=8)
        dconstr.write_card(size=16)
        dconstr.raw_fields()
        dresp1.write_card(size=8)
        dresp1.write_card(size=16)
        dresp1.raw_fields()
        dresp2.write_card(size=8)
        dresp2.write_card(size=16)
        dresp2.write_card(size=16, is_double=True)
        dresp3.write_card(size=8)
        dresp3.write_card(size=16)
        dresp3.write_card(size=16, is_double=True)
        dvprel2.write_card(size=8)
        dvprel2.write_card(size=16)
        dvprel2.write_card(size=16, is_double=True)
        dconadd.write_card(size=8)
        dconadd.write_card(size=16)
        dconadd.write_card(size=16, is_double=True)

        grid.nid = 200
        assert '200' in str(dresp3), dresp3

        save_load_deck(model)
Example #45
0
    def test_pbar_2(self):
        """tests the PBAR BDF add"""
        pid = 1
        mid = 2
        A = None
        I1 = I2 = None
        J = None
        nsm = None
        c1 = c2 = d1 = d2 = e1 = e2 = f1 = f2 = None
        k1 = k2 = None
        i12 = 3.
        fields = [
            'PBAR', pid, mid, A, I1, I2, J, nsm, None, c1, c2, d1, d2, e1, e2,
            f1, f2, k1, k2, i12
        ]
        card = print_card_8(fields)
        lines = card.split('\n')
        model = BDF(debug=False)
        card = model.process_card(lines)
        cardi = BDFCard(card)

        pbar = PBAR.add_card(cardi)
        self.assertEqual(pbar.pid, 1)
        self.assertEqual(pbar.mid, 2)
        self.assertEqual(pbar.A, 0.0)
        self.assertEqual(pbar.i1, 0.0)
        self.assertEqual(pbar.i2, 0.0)
        self.assertEqual(pbar.j, 0.0)
        self.assertEqual(pbar.nsm, 0.0)
        self.assertEqual(pbar.i12, 3.0)
        self.assertEqual(pbar.c1, 0.0)
        self.assertEqual(pbar.c2, 0.0)
        self.assertEqual(pbar.d1, 0.0)
        self.assertEqual(pbar.d2, 0.0)
        self.assertEqual(pbar.e1, 0.0)
        self.assertEqual(pbar.e2, 0.0)
        self.assertEqual(pbar.k1, None)
        self.assertEqual(pbar.k2, None)

        #--------------------------------------------------------
        A = 6.
        I1 = 5.
        I2 = 4.
        J = 3.
        nsm = 2.
        c1 = c2 = d1 = d2 = e1 = e2 = f1 = f2 = None
        k1 = k2 = 1e2
        i12 = 0.
        fields = [
            'PBAR', pid, mid, A, I1, I2, J, nsm, None, c1, c2, d1, d2, e1, e2,
            f1, f2, k1, k2, i12
        ]
        card = print_card_8(fields)
        lines = card.split('\n')
        model = BDF(debug=False)
        card = model.process_card(lines)

        cardi = BDFCard(card)
        pbar = PBAR.add_card(cardi)

        self.assertEqual(pbar.pid, 1)
        self.assertEqual(pbar.mid, 2)
        self.assertEqual(pbar.A, 6.0)
        self.assertEqual(pbar.i1, 5.0)
        self.assertEqual(pbar.i2, 4.0)
        self.assertEqual(pbar.j, 3.0)
        self.assertEqual(pbar.nsm, 2.0)
        self.assertEqual(pbar.i12, 0.0)
        self.assertEqual(pbar.c1, 0.0)
        self.assertEqual(pbar.c2, 0.0)
        self.assertEqual(pbar.d1, 0.0)
        self.assertEqual(pbar.d2, 0.0)
        self.assertEqual(pbar.e1, 0.0)
        self.assertEqual(pbar.e2, 0.0)
        self.assertEqual(pbar.k1, 1e2)
        self.assertEqual(pbar.k2, 1e2)
Example #46
0
def setup_contact(main_bdf, contact_bdf, contact_surfaces):
    main_bdf2 = 'main2.bdf'

    model_main = BDF()
    model_main.read_bdf(main_bdf)

    # ------------------------------------------------------------------------
    # update the case control deck

    cc = model_main.case_control_deck
    subcase_ids = cc.get_subcase_list()
    subcase_ids.pop(0)
    subcase0_id = subcase_ids[0]

    cc.add_parameter_to_local_subcase(subcase0_id, 'FORCE(SORT1, REAL) = ALL')
    print(cc)

    model_main.write_bdf('junk.bdf')
    #sys.exit()

    # ------------------------------------------------------------------------
    # update the main bdf with the INCLUDE fiel

    contact_include = write_include(contact_bdf)
    model_main.rejects.append([contact_include])
    # ------------------------------------------------------------------------

    eid_start = get_max_eid(model_main) + 1  # elements + 1 -> starting ID
    eid = eid_start

    # ------------------------------------------------------------------------
    # apply springs based on distance

    with open(contact_bdf, 'w') as f:
        eid_groups = []
        nodes_groups = []
        neids = []
        i = 0
        for contact_surface in contact_surfaces:
            nids_group1 = contact_surface['group1_nodes']
            nids_group2 = contact_surface['group2_nodes']
            stiffness = contact_surface['stiffness']
            dof = contact_surface['dof']
            cid = contact_surface['cid']

            print("nids_group1 = %s" % nids_group1)
            #model_left = BDF(debug=False)
            #model_left.read_bdf(left_bdf)

            #model_right = BDF(debug=False)
            #model_right.read_bdf(right_bdf)

            # change nodes from cid=0 to cid=N
            nodes_left = update_nodes_cid(model_main, nids_group1, cid)
            nodes_right = update_nodes_cid(model_main, nids_group2, cid)

            # find 5 closest nodes; TODO: update this...
            spring_sets = {
                # left  # right
                1: [2, 4, 5],
                2: [10, 3],
            }

            c1 = c2 = dof
            neids_start = eid
            #i = 0
            if i > 0:
                f.write(
                    '$-------------------------------------------------------\n'
                )
            f.write('$ contact set %i\n' % i)
            for g1, spring_nodes in sorted(iteritems(spring_sets)):
                f.write('$ g1=%i, dof=%i\n' % (g1, dof))
                for g2 in spring_nodes:
                    celas = ['CELAS2', eid, stiffness, g1, c1, g2, c2]
                    f.write(print_card(celas))
                    eid += 1
                #i += 1
            neid = eid - neids_start

            eid_group = (neids_start, neid)
            eid_groups.append(eid_group)
            nodes_group = (nodes_left, nodes_right)
            nodes_groups.append(nodes_group)
            neids.append(neid)
            i += 1
    f.close()

    # ------------------------------------------------------------------------
    # we put this at the bottom b/c we need to update the node coordinate systems
    model_main.write_bdf(main_bdf2)
    del model_main

    # ------------------------------------------------------------------------
    # set the initial stiffnesses
    stiffnesses = zeros(sum(neids), 'float64')
    errors = ones(sum(neids), 'float64')
    ieid = 0
    for neid, contact_surface in zip(neids, contact_surfaces):
        nids_group1 = contact_surface['group1_nodes']
        #nids_group2 = contact_surface['group2_nodes']
        stiffness = contact_surface['stiffness']
        #dof = contact_surface['dof']
        #cid = contact_surface['cid']

        #(nids_group1, nids_group2, dof, stiffness, cid, glue, initial_gap, max_deflection_error) =
        #'group1_nodes' : group1_nodes,
        #'group2_nodes' : group2_nodes,
        #'dof'          : 1,     # dof in contact (1, 2, 3, 4, 5, 6) - nodes in group1/2
        #'K'            : 1.e8,  # stiffness of contact interface
        #'cid'          : 1,     # direction of contact
        #'glue'         : False, #
        #'initial_gap'  : 0.0,
        #'max_deflection_error' : max_deflection_error,
        #left_bdf, right_bdf, dof, stiffness, cid, glue, initial_gap = contact_surface
        stiffnesses[ieid:ieid + neid] = stiffness
        ieid += neid
    return eid_groups, nodes_groups, stiffnesses, errors
Example #47
0
    def test_pbarl_1(self):
        """tests the PBARL"""
        model = BDF(log=None, debug=False)
        pid = 4
        mid = 40
        group = 'group'
        Type = 'bad_type'
        dim = 42
        nsm = 0.5
        pbarl = PBARL(pid,
                      mid,
                      Type,
                      dim,
                      group=group,
                      nsm=nsm,
                      comment='comment')
        with self.assertRaises(ValueError):  # Type
            pbarl.validate()

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

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

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

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

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

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

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

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

        with self.assertRaises(AttributeError):
            pbarl._verify()

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

        mat.rho = 0.
        assert allclose(cbar.Mass(), 0.5), cbar.Mass()
Example #48
0
    def test_pconeax(self):
        """PCONEAX"""
        model = BDF(debug=False)
        model.add_grid(1)
        pid = 100
        mid1 = 1000
        nsm = 0.0
        z1 = 0.
        z2 = 0.
        pconeax = model.add_pconeax(pid,
                                    mid1,
                                    t1=None,
                                    mid2=0,
                                    i=None,
                                    mid3=None,
                                    t2=None,
                                    nsm=nsm,
                                    z1=z1,
                                    z2=z2,
                                    phi=None,
                                    comment='pconeax')
        model.add_mat1(mid=mid1, E=3.0e7, G=None, nu=0.3)

        eid = 10
        rings = [2, 3]
        cconeax = model.add_cconeax(eid, pid, rings, comment='ccone')

        sid = 42
        ring = 6
        phi = 37.
        temperature = 420.
        tempax = model.add_tempax(sid,
                                  ring,
                                  phi,
                                  temperature,
                                  comment='tempax')

        R = 1.2
        z = 3.2
        ringax = model.add_ringax(ring, R, z, ps=None, comment='ringax')

        nid = 7
        pointax = model.add_pointax(nid, ring, phi, comment='pointax')

        nharmonics = 12
        axic = model.add_axic(nharmonics, comment='axic')
        ringax.raw_fields()
        pointax.raw_fields()
        cconeax.raw_fields()
        pconeax.raw_fields()
        axic.raw_fields()
        save_load_deck(model)
Example #49
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)
Example #50
0
    def test_bar_mass_1(self):
        """tests CBAR/PBAR mass"""
        model = BDF(debug=False)
        #model.case_control_deck = CaseControlDeck(case_control_lines)
        spc = ['SPC1', 123456, 123456, 1]
        grid1 = ['GRID', 1, None, 0., 0., 0.]
        grid2 = ['GRID', 2, None, 1., 0., 0.]
        grid3 = ['GRID', 3, None, 1., 0., 0.]
        force = ['FORCE', 100, 1, 0, 2., 3., 4.]
        cbar = [
            'CAR',
            10,
            11,
            1,
            2,
            0.,
            1.,
            0.,
            None,
        ]
        k1 = k2 = None
        area = 2.0
        rho = 3.
        nu = 0.3
        i1 = 2.1
        i2 = 1.2
        i12 = 0.1
        j = None
        nsm = 0.1
        pbar = [
            'PBAR', 11, 12, area, i1, i2, j, nsm, None, None, None, None, None,
            None, None, None, k1, k2, i12
        ]

        mat1 = ['MAT1', 12, 3.0e7, None, nu, rho]
        model.add_card(grid1, 'GRID')
        model.add_card(grid2, 'GRID')
        model.add_card(cbar, 'CBAR')
        model.add_card(pbar, 'PBAR')
        model.add_card(mat1, 'MAT1')
        model.add_card(spc, 'SPC1')
        model.add_card(force, 'FORCE')
        model.validate()
        model.cross_reference()

        mass, cg, I = model.mass_properties(element_ids=None,
                                            mass_ids=None,
                                            reference_point=None,
                                            sym_axis=None,
                                            num_cpus=1,
                                            scale=None)
        #print('cg* =', cg)
        L = 1.0
        mass_per_length = area * rho + nsm
        mass = L * mass_per_length

        #xcg = (0.0 * mass_a + 1.0 * mass_b) / (mass_a + mass_b)
        #print(mass_a, mass_b, xcg, mass_a + mass_b)
        #print('mass =', mass)
        #cbar = CBEAM()
        cbar = model.elements[10]
        pbar = model.properties[11]
        assert pbar.Nu() == nu, 'pbar.Nu()=%s nu=%s' % (pbar.Nu(), nu)
        assert pbar.Rho() == rho, 'pbar.Rho()=%s rho=%s' % (pbar.Rho(), rho)
        assert allclose(cbar.Length(), 1.0), cbar.Length()
        #assert allclose(cbar.Mass(), 10.25), cbar.Mass()
        #assert allclose(cbar.MassPerLength(), 10.25), cbar.MassPerLength()
        #assert allclose(mass, 10.25), mass

        case_control_lines = ('SOL 101\n'
                              'CEND\n'
                              'SUBCASE 1\n'
                              '    STRESS(PLOT,SORT1,REAL) = ALL\n'
                              '    SPC = 123456\n'
                              '    LOAD = 100\n'
                              'BEGIN BULK\n'
                              'PARAM,GRDPNT,0\n'
                              'PARAM,POST,-1\n'
                              'PARAM   POSTEXT YES\n')
        with open('cbar.bdf', 'w') as bdf_file:
            bdf_file.write(case_control_lines)
            model.write_bdf(bdf_file, enddata=True)
        model2 = BDF(debug=False)
        model2.read_bdf('cbar.bdf')

        model2._verify_bdf(xref=True)
        if not os.path.exists('cbar.op2') and 0:
            os.system('nastran scr=yes bat=no old=no cbar.bdf')
        os.remove('cbar.bdf')

        if 0:
            from pyNastran.op2.op2 import OP2
            op2 = OP2()
            op2.read_op2('cbar.op2')
            #os.remove('cbar.op2')
            gpw = op2.grid_point_weight
            op2_mass = gpw.mass.max()
            assert allclose(op2_mass,
                            mass), 'op2_mass=%s mass=%s' % (op2_mass, mass)
            #print('op2_mass=%s mass=%s' % (op2_mass, mass))
            op2_cg = gpw.cg

            cg = array([0.5, 0., 0.], dtype='float32')
Example #51
0
    def test_shells_add(self):
        """
        tests differential mass and material coordinate systems
        on CQUAD4/CTRIA3 elements
        """
        pid = 10
        mid1 = 100
        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(10, pid, [1, 2, 3, 4])
        model.add_ctria3(11, pid, [1, 2, 3])

        mids = [100, 100, 100]
        thicknesses = [0.1, 0.1, 0.1]
        model.add_pcomp(pid,
                        mids,
                        thicknesses,
                        thetas=[0., 45., 90.],
                        souts=None,
                        nsm=0.,
                        sb=0.,
                        ft=None,
                        tref=0.,
                        ge=0.,
                        lam=None,
                        z0=None,
                        comment='')

        pid = 11
        model.add_ctria3(
            12,
            pid,
            [1, 2, 3],
            theta_mcid=45.,
            zoffset=0.,
            tflag=0,
            T1=0.1,
            T2=0.1,
            T3=0.1,  # absolute - mass=0.1*0.5=0.05
            comment='')
        model.add_ctria3(
            13,
            pid,
            [1, 2, 3],
            theta_mcid=1,
            zoffset=0.,
            tflag=0,
            T1=0.1,
            T2=0.1,
            T3=0.1,  # absolute
            comment='')

        model.add_cquad4(
            14,
            pid,
            [1, 2, 3, 4],
            theta_mcid=45.,
            zoffset=0.,
            tflag=0,
            T1=0.1,
            T2=0.1,
            T3=0.1,
            T4=0.1,  # absolute
            comment='')
        model.add_cquad4(
            15,
            pid,
            [1, 2, 3, 4],
            theta_mcid=1,
            zoffset=0.,
            tflag=1,
            T1=0.1,
            T2=0.1,
            T3=0.1,
            T4=0.1,  # relative
            comment='')

        origin = [0., 0., 0.]
        zaxis = [0., 0., 1.]
        xzplane = [1., 0., 0.]
        model.add_cord2r(1, origin, zaxis, xzplane, rid=0)
        model.add_pshell(pid, mid1=mid1, t=2.)

        e11 = 1.0
        e22 = 2.0
        nu12 = 0.3
        model.add_mat8(mid1, e11, e22, nu12, rho=1.0)
        model.validate()

        model.cross_reference()
        model.pop_xref_errors()

        mass = model.mass_properties(element_ids=13)[0]
        bdf_file = StringIO()
        model.write_bdf(bdf_file)
        model.uncross_reference()
        model.cross_reference()
        model.pop_xref_errors()

        assert np.allclose(mass, 0.05), mass  # t=0.1; A=0.5; nsm=0.; mass=0.05

        mass = model.mass_properties(element_ids=14)[0]
        bdf_file = StringIO()
        model.write_bdf(bdf_file, close=False)
        bdf_file.seek(0)
        assert np.allclose(mass, 0.1), mass  # t=0.1; A=1.0; nsm=0.; mass=0.1

        csv_filename = 'mcids.csv'
        export_mcids(model,
                     csv_filename=csv_filename,
                     eids=[12, 13],
                     export_xaxis=True,
                     export_yaxis=True,
                     iply=0)
        #with open(csv_filename, 'r') as csv_file:
        #lines = csv_file.readlines()
        #assert len(lines) > 0, 'lines=%s' % lines
        #for line in lines:
        #print(line.rstrip())
        #print('-------------')
        export_mcids(model,
                     csv_filename=csv_filename,
                     eids=[14, 15],
                     export_xaxis=True,
                     export_yaxis=True,
                     iply=0)
        model.uncross_reference()
        model.safe_cross_reference()
        model.uncross_reference()
        os.remove(csv_filename)
        #bdf_file = model.write_bdf(bdf_file)

        model2 = BDF(debug=False)
        model2.read_bdf(bdf_file, punch=True)
    def read_bdf(self,
                 bdf_filename=None,
                 validate=True,
                 xref=True,
                 punch=False,
                 read_includes=True,
                 encoding=None):
        """see ``BDF.read_bdf``"""
        BDF.read_bdf(self,
                     bdf_filename=bdf_filename,
                     validate=validate,
                     xref=False,
                     punch=punch,
                     read_includes=read_includes,
                     encoding=encoding)

        # not done
        etypes = [
            'CELAS1',
            'CELAS2',
            'CELAS3',
            'CELAS4',
            'CDAMP1',
            'CDAMP2',
            'CDAMP3',
            'CDAMP4',
            'CDAMP5',
            'CVISC',
            'CBUSH',
            'CBUSH1D',
            'CBUSH2D',
            'CONROD',
            'CROD',
            'CTUBE',
            'PLOTEL',
            'CBAR',
            'CBEAM',
            'CBEND',
            'CSHEAR',
            'CTRIA3',
            'CQUAD4',
            'CTRIA6',
            'CQUAD8',
            'CTRIAR',
            'CQUADR',
            'CTETRA',
            'CPENTA',
            'CHEXA',
            'CPYRAM',
            'CHBDYG',
            'CHBDYE',
            'CHBDYP',
        ]
        eid0 = 1
        #eid_map = {}
        elements2 = {}
        for etype in etypes:
            if etype in self._type_to_id_map:
                eids = self._type_to_id_map[etype]
                print(etype, eids)
                for eid in eids:
                    #eid_map[eid0] = eid
                    if etype == 'PLOTEL':
                        element = self.plotels[eid]
                    else:
                        element = self.elements[eid]
                    element.eid = eid0
                    print(element)
                    elements2[eid0] = element
                    #self.elements[eid] =
                    eid0 += 1

        failed_types = set()
        for elem in self.elements.values():
            if elem.type not in etypes:
                failed_types.add(elem.type)
        self.elements = elements2
        self.plotels = {}

        if failed_types:
            msg = 'The following types were not converted and may result in a bad deck\n'
            msg += '  %s' % failed_types
            self.log.warning(msg)

        # loads are not currently supported
        self.loads = {}  # type: Dict[int, List[Any]]
        self.load_combinations = {}  # type: Dict[int, List[Any]]
Example #53
0
    def test_split_cbars_by_pin_flag_2(self):
        """real pin flag test"""
        lines = [
            'SOL 101\n',
            'CEND\n',
            'SUBCASE 10\n',
            '    LOAD = 10\n',
            '    SPC = 123456\n',
            '    DISP(PLOT) = ALL\n',
            '    STRESS(PLOT) = ALL\n',
            'BEGIN BULK\n',
            'ENDDATA',
        ]
        model = BDF(debug=False)
        with self.assertRaises(NotImplementedError):
            model.read_bdf(bdf_filename=lines,
                           validate=True,
                           xref=True,
                           punch=False,
                           read_includes=True,
                           encoding=None)

        model.add_grid(1, [0., 0., 0.])
        model.add_grid(2, [1., 0., 0.])
        model.add_grid(3, [2., 0., 0.])
        model.add_grid(4, [3., 0., 0.])

        pid = 1000
        mid = 1000
        Type = 'BAR'
        dim = [1., 2.]
        model.add_pbarl(pid, mid, Type, dim)
        E = 3.0e7
        G = 3.0e6
        nu = None
        model.add_mat1(mid, E, G, nu)

        x = [0., 1., 0.]
        g0 = None
        model.add_cbar(1,
                       pid, [1, 2],
                       x,
                       g0,
                       offt='GGG',
                       pa=0,
                       pb=0,
                       wa=None,
                       wb=None,
                       comment='reaction')
        model.add_cbar(2,
                       pid, [2, 3],
                       x,
                       g0,
                       offt='GGG',
                       pa=0,
                       pb=456,
                       wa=None,
                       wb=None,
                       comment='End B')
        model.add_cbar(3,
                       pid, [3, 4],
                       x,
                       g0,
                       offt='GGG',
                       pa=456,
                       pb=0,
                       wa=None,
                       wb=None,
                       comment='End A')
        sid = 10
        node = 4
        mag = 1.
        xyz = [1., 1., 0.]
        model.add_force(sid, node, mag, xyz)
        model.add_spc1(123456, '123456', 1)
        model.validate()

        bdf_file = StringIO()
        bdf_file.writelines(lines)
        bdf_file.seek(0)
        model.read_bdf(bdf_filename=bdf_file,
                       validate=True,
                       xref=False,
                       punch=False,
                       read_includes=True,
                       encoding=None)
        #model.write_bdf('spike.bdf')

        split_cbars_by_pin_flag(model,
                                pin_flags_filename='pin_flags.csv',
                                bdf_filename_out='pin_flags.bdf',
                                debug=False)
        os.remove('pin_flags.csv')
        os.remove('pin_flags.bdf')
Example #54
0
    def test_mirror(self):
        """tests bdf mirroring"""
        log = SimpleLogger(level='error')
        pid_pshell = 10
        pid_psolid = 11
        mid1 = 100
        model = BDF(log=log)  # (log=log)
        model.add_grid(1, [10., 10., 10.])
        model.add_grid(2, [11., 10., 10.])
        model.add_grid(3, [11., 11., 10.])
        model.add_grid(4, [10., 11., 10.])

        model.add_grid(5, [10., 10., 11.])
        model.add_grid(6, [11., 10., 11.])
        model.add_grid(7, [11., 11., 11.])
        model.add_grid(8, [10., 11., 11.])

        model.add_cquad4(1, pid_pshell, [1, 2, 3, 4])  # mass=1
        model.add_ctria3(2, pid_pshell, [1, 2, 3])  # mass=0.5
        model.add_conrod(3, mid1, [1, 3], A=1.0, j=0.0, c=0.0, nsm=0.0)

        #model.add_ctetra(4, pid_psolid, [1, 2, 3, 5])
        # penta
        # pyram
        #model.add_chexa(7, pid_psolid, [1, 2, 3, 4, 5, 6, 7, 8])

        model.add_pshell(pid_pshell, mid1=mid1, t=1.)
        model.add_psolid(pid_psolid, mid1)
        E = 1.0
        G = None
        nu = 0.3
        model.add_mat1(mid1, E, G, nu, rho=1.0)
        model.validate()
        model.cross_reference()
        mass1, unused_cg1, unused_inertia1 = model.mass_properties()

        # mirror_model=None -> new model
        #
        # just a cord2r
        #   y+ right
        plane = np.array([
            [0., 0., 0.],
            [0., 0., 1.],
            [1., 0., 0.],
        ])
        model, mirror_model, nid_offset, eid_offset = bdf_mirror_plane(
            model,
            plane,
            mirror_model=None,
            log=None,
            debug=True,
            use_nid_offset=False)
        #for nid, node in sorted(mirror_model.nodes.items()):
        #print(nid, node.xyz)

        out_filename = 'sym.bdf'
        write_bdf_symmetric(model,
                            out_filename=out_filename,
                            encoding=None,
                            size=8,
                            is_double=False,
                            enddata=None,
                            close=True,
                            plane='xz')  # +y/-y
        model2 = read_bdf(out_filename, log=log)
        assert len(model2.nodes) == 16, model2.nodes
        mass2, cg2, unused_inertia2 = model2.mass_properties()
        #print('cg1=%s cg2=%s' % (cg1, cg2))
        assert np.allclose(mass1 * 2,
                           mass2), 'mass1=%s mass2=%s' % (mass1, mass2)
        assert np.allclose(
            cg2[1], 0.), 'cg2=%s stats=%s' % (cg2, model2.get_bdf_stats())
        os.remove('sym.bdf')
Example #55
0
    def test_eq3(self):
        """node_set=None"""
        log = SimpleLogger(level='error')
        lines = [
            '$pyNastran: version=msc',
            '$pyNastran: punch=True',
            '$pyNastran: encoding=ascii',
            '$NODES',
            '$ Nodes to merge:',
            '$ 5987 10478',
            '$   GRID        5987           35.46     -6.      0.',
            '$   GRID       10478           35.46     -6.      0.',
            '$ 5971 10479',
            '$   GRID        5971           34.92     -6.      0.',
            '$   GRID       10479           34.92     -6.      0.',
            '$ 6003 10477',
            '$   GRID        6003             36.     -6.      0.',
            '$   GRID       10477             36.     -6.      0.',
            'GRID        5971           34.92     -6.      0.',
            'GRID        5972           34.92-5.73333      0.',
            'GRID        5973           34.92-5.46667      0.',
            'GRID        5987           35.46     -6.      0.',
            'GRID        5988           35.46-5.73333      0.',
            'GRID        5989           35.46-5.46667      0.',
            'GRID        6003             36.     -6.      0.',
            'GRID        6004             36.-5.73333      0.',
            'GRID        6005             36.-5.46667      0.',
            'GRID       10476             36.     -6.    -1.5',
            'GRID       10477             36.     -6.      0.',
            'GRID       10478           35.46     -6.      0.',
            'GRID       10479           34.92     -6.      0.',
            'GRID       10561           34.92     -6.    -.54',
            '$ELEMENTS_WITH_PROPERTIES',
            'PSHELL         1       1      .1',
            'CQUAD4      5471       1    5971    5987    5988    5972',
            'CQUAD4      5472       1    5972    5988    5989    5973',
            'CQUAD4      5486       1    5987    6003    6004    5988',
            'CQUAD4      5487       1    5988    6004    6005    5989',
            'PSHELL        11       1      .1',
            'CTRIA3      9429      11   10561   10476   10478',
            'CTRIA3      9439      11   10478   10479   10561',
            'CTRIA3      9466      11   10476   10477   10478',
            '$MATERIALS',
            'MAT1           1      3.              .3',
        ]
        bdf_filename = 'nonunique2.bdf'
        bdf_filename_out = 'unique2.bdf'

        with open(bdf_filename, 'w') as bdf_file:
            bdf_file.write('\n'.join(lines))

        tol = 0.01
        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) == 11, len(model.nodes)

        os.remove(bdf_filename)
        os.remove(bdf_filename_out)
Example #56
0
    def test_split_line_elements(self):
        """tests split_line_elements"""
        model = BDF(debug=False)
        model.add_grid(1, [0., 0., 0.])
        model.add_grid(2, [1., 0., 0.])

        pid = 1000
        mid = 1000
        Type = 'BAR'
        dim = [1., 2.]
        model.add_pbarl(pid, mid, Type, dim)
        E = 3.0e7
        G = 3.0e6
        nu = None
        model.add_mat1(mid, E, G, nu)

        x = [0., 1., 0.]
        g0 = None
        #model.add_cbar(1, pid, 1, 2, x, g0, offt='GGG', pa=0, pb=0,
        #wa=None, wb=None, comment='reaction')
        #model.add_cbar(2, pid, 2, 3, x, g0, offt='GGG', pa=0, pb=456,
        #wa=None, wb=None, comment='End B')
        #model.add_cbar(3, pid, 3, 4, x, g0, offt='GGG', pa=456, pb=0,
        #wa=None, wb=None, comment='End A')
        #eids = [1, 2, 3]

        nids = [1, 2]
        model.add_cbar(1,
                       pid,
                       nids,
                       x,
                       g0,
                       offt='GGG',
                       pa=456,
                       pb=5,
                       wa=None,
                       wb=None,
                       comment='End A')
        model.add_cbeam(2,
                        2000,
                        nids,
                        x,
                        g0,
                        offt='GGG',
                        bit=None,
                        pa=456,
                        pb=5,
                        wa=None,
                        wb=None,
                        sa=0,
                        sb=0,
                        comment='')
        A = 42.
        model.add_conrod(3, mid, nids, A)
        model.add_prod(4000, mid, A)
        model.add_crod(4, 4000, nids)

        Type = 'ROD'
        xxb = [0.]
        dims = [[1.]]
        model.add_pbeaml(2000, mid, Type, xxb, dims)
        eids = [1, 2, 3, 4]
        split_line_elements(model,
                            eids,
                            neids=10,
                            eid_start=101,
                            nid_start=101)
        bdf_file = StringIO()
        model.write_bdf(bdf_file, close=False)
Example #57
0
    def test_ploadx1(self):
        """tests a PLOADX1"""
        model = BDF(debug=False)
        sid = 10
        eid1 = 11
        pa = 200.
        ga = 1
        gb = 2
        ploadx1 = model.add_ploadx1(sid, eid1, pa, ga, gb, pb=None,
                                    theta=0., comment='ploadx1')
        model.add_grid(1, xyz=[0., 0., 0.])
        model.add_grid(2, xyz=[1., 0., 0.])
        model.add_grid(3, xyz=[1., 1., 0.])

        pid = 20
        nids = [1, 2, 3, None, None, None]
        ctriax = model.add_ctriax(eid1, pid, nids, theta_mcid=0., comment='ctriax')

        mid = 21
        plplane = model.add_plplane(pid, mid, cid=0,
                                    stress_strain_output_location='GRID',
                                    comment='plplane')

        #eid2 = 12
        #model.add_ctriax6(eid2, mid, nids, theta=0., comment='ctriax6')

        #E = 30.e7
        #G = None
        #nu = 0.3
        #mat1 = model.add_mat1(mid, E, G, nu, rho=0.1, comment='mat1')
        #mathe = model.add_mathe(mid, model, bulk, rho, texp, mus, alphas,
                                #betas, mooney, sussbat, comment='mathe')
        mathp = model.add_mathp(mid, comment='mathp')


        ctriax.raw_fields()
        ctriax.write_card(size=8)
        ctriax.write_card(size=16)

        plplane.raw_fields()
        plplane.write_card(size=8)
        plplane.write_card(size=16)

        #mathe.raw_fields()
        #mathe.write_card(size=8)
        #mathe.write_card(size=16)

        mathp.raw_fields()
        mathp.write_card(size=8)
        mathp.write_card(size=16)

        ploadx1.raw_fields()
        ploadx1.write_card(size=8)
        ploadx1.write_card(size=16)
        ploadx1.write_card(size=16, is_double=True)

        model.validate()
        model._verify_bdf(xref=False)
        model.cross_reference()
        model._verify_bdf(xref=True)

        ctriax.write_card(size=8)
        plplane.write_card(size=8)
        #mathe.write_card(size=8)
        mathp.write_card(size=8)
        ploadx1.write_card(size=8)
Example #58
0
    def test_eq4(self):
        r"""
          5
        6 *-------* 40
          | \     |
          |   \   |
          |     \ |
          *-------* 3
          1       20
        """
        log = SimpleLogger(level='error')
        msg = 'CEND\n'
        msg += 'BEGIN BULK\n'
        msg += 'GRID,1, , 0.,   0.,   0.\n'
        msg += 'GRID,20,, 1.,   0.,   0.\n'
        msg += 'GRID,3, , 1.01, 0.,   0.\n'

        msg += 'GRID,41,, 1.,   1.,   0.\n'  # eq
        msg += 'GRID,4,, 1.,   1.,   0.\n'  # eq
        msg += 'GRID,40,, 1.,   1.,   0.\n'  # eq
        msg += 'GRID,4,, 1.,   1.,   0.\n'  # eq

        msg += 'GRID,5, , 0.,   1.,   0.\n'
        msg += 'GRID,6, , 0.,   1.01, 0.\n'
        msg += 'CTRIA3,1, 100,1,20,6\n'
        msg += 'CTRIA3,10,100,3,40,5\n'
        msg += 'PSHELL,100,1000,0.1\n'
        msg += 'MAT1,1000,3.0,, 0.3\n'
        msg += '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
        node_set = [4, 40, 41]
        # Collapse 5/6 and 20/3; Put a 40 and 20 to test non-sequential IDs
        bdf_equivalence_nodes(bdf_filename,
                              bdf_filename_out,
                              tol,
                              renumber_nodes=False,
                              neq_max=4,
                              xref=True,
                              node_set=node_set,
                              crash_on_collapse=False,
                              log=log,
                              debug=False)

        model = BDF(log=log, debug=False)
        model.read_bdf(bdf_filename_out)
        nids = model.nodes.keys()
        assert len(
            model.nodes) == 6, 'nnodes=%s nodes=%s' % (len(model.nodes), nids)
        assert 1 in nids, nids
        assert 20 in nids, nids
        assert 3 in nids, nids
        assert 4 in nids, nids
        assert 5 in nids, nids
        assert 6 in nids, nids
        assert 40 not in nids, nids
        assert 41 not in nids, nids
        #print(nids)
        os.remove(bdf_filename)
        os.remove(bdf_filename_out)
Example #59
0
    def test_pload4_cpenta(self):
        bdf_filename = os.path.join(test_path, '..', 'models', 'pload4', 'cpenta.bdf')
        op2_filename = os.path.join(test_path, '..', 'models', 'pload4', 'cpenta.op2')
        op2 = OP2(debug=False)
        op2.read_op2(op2_filename)

        model_b = BDF(debug=False)
        model_b.read_bdf(bdf_filename)
        # p0 = (model_b.nodes[21].xyz + model_b.nodes[22].xyz + model_b.nodes[23].xyz) / 3.
        p0 = model_b.nodes[21].xyz
        angles = [
            (23, 24), (24, 23),
            (21, 26), (26, 21),
        ]
        nx = [
            (23, 25), (25, 23),
            (22, 26), (26, 22),
        ]

        msg = ''
        for isubcase, subcase in sorted(iteritems(model_b.subcases)):
            if isubcase == 0:
                continue
            #if isubcase != 17:
                #continue
            loadcase_id = subcase.get_parameter('LOAD')[0]
            load = model_b.loads[loadcase_id][0]
            elem = load.eids[0]
            g1 = load.g1.nid
            if load.g34 is None:
                #print(load)
                face, area, centroid, normal = elem.getFaceAreaCentroidNormal(g1)
                assert area == 0.5, area
                if g1 in [21, 22, 23]:
                    assert face == (2, 1, 0), 'g1=%s face=%s' % (g1, face)
                    assert array_equal(centroid, array([2/3., 1/3., 0.])), 'fore g1=%s g34=%s face=%s centroid=%s\n%s' % (g1, g34, face, centroid, msg)
                    assert array_equal(normal, array([0., 0., 1.])), 'fore g1=%s g34=%s face=%s normal=%s\n%s' % (g1, g34, face, normal, msg)
                else:
                    assert face == (3, 4, 5), 'g1=%s face=%s' % (g1, face)
                    assert array_equal(centroid, array([2/3., 1/3., 2.])), 'aft g1=%s g34=%s face=%s centroid=%s\n%s' % (g1, g34, face, centroid, msg)
                    assert array_equal(normal, array([0., 0., -1.])), 'aft g1=%s g34=%s face=%s normal=%s\n%s' % (g1, g34, face, normal, msg)
            else:
                g34 = load.g34.nid
                face, area, centroid, normal = elem.getFaceAreaCentroidNormal(g1, g34)
                if (g1, g34) in angles:
                    self.assertAlmostEqual(area, 2 * 2**0.5, msg='g1=%s g34=%s face=%s area=%s' % (g1, g34, face, area))
                elif (g1, g34) in nx:
                    self.assertEqual(area, 2.0, 'area=%s' % area)
                    msg = '%s%s%s%s\n' % (
                        elem.nodes[face[0]], elem.nodes[face[1]], elem.nodes[face[2]], elem.nodes[face[3]])
                    assert array_equal(centroid, array([1., .5, 1.])), 'Nx g1=%s g34=%s face=%s centroid=%g\n%s' % (g1, g34, face, centroid, msg)
                    assert array_equal(normal, array([-1., 0., 0.])), 'Nx g1=%s g34=%s face=%s normal=%g\n%s' % (g1, g34, face, normal, msg)
                else:
                    msg = '%s%s%s%s\n' % (
                        elem.nodes[face[0]], elem.nodes[face[1]], elem.nodes[face[2]], elem.nodes[face[3]])

                    assert array_equal(centroid, array([0.5, .0, 1.])), 'Ny g1=%s g34=%s face=%s centroid=%s\n%s' % (g1, g34, face, centroid, msg)
                    assert array_equal(normal, array([0., 1., 0.])), 'Ny g1=%s g34=%s face=%s normal=%s\n%s' % (g1, g34, face, normal, msg)
                    self.assertEqual(area, 2.0, 'area=%s' % area)

            f, m = model_b.sum_forces_moments(p0, loadcase_id, include_grav=False)
            eids = None
            nids = None
            f2, m2 = model_b.sum_forces_moments_elements(p0, loadcase_id, eids, nids, include_grav=False)
            assert allclose(f, f2), 'f=%s f2=%s' % (f, f2)
            assert allclose(m, m2), 'm=%s m2=%s' % (m, m2)

            case = op2.spc_forces[isubcase]
            fm = -case.data[0, :3, :].sum(axis=0)
            assert len(fm) == 6, fm
            if not allclose(f[0], fm[0]):
                print('%-2i Fx f=%s fexpected=%s face=%s' % (isubcase, f, fm, face))
            if not allclose(f[1], fm[1]):
                print('%-2i Fy f=%s fexpected=%s face=%s' % (isubcase, f, fm, face))
            if not allclose(f[2], fm[2]):
                print('%-2i Fz f=%s fexpected=%s face=%s' % (isubcase, f, fm, face))
Example #60
0
    def test_eq2(self):
        r"""
          5
        6 *-------* 40
          | \     |
          |   \   |
          |     \ |
          *-------* 3
          1       20
        """
        log = SimpleLogger(level='error')
        msg = ('CEND\n'
               'BEGIN BULK\n'
               'GRID,1, , 0.,   0.,   0.\n'
               'GRID,20,, 1.,   0.,   0.\n'
               'GRID,3, , 1.01, 0.,   0.\n'
               'GRID,40,, 1.,   1.,   0.\n'
               'GRID,5, , 0.,   1.,   0.\n'
               'GRID,6, , 0.,   1.01, 0.\n'
               'CTRIA3,1, 100,1,20,6\n'
               'CTRIA3,10,100,3,40,5\n'
               'PSHELL,100,1000,0.1\n'
               'MAT1,1000,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
        # Collapse 5/6 and 20/3; Put a 40 and 20 to test non-sequential IDs
        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(log=log, debug=False)
        model.read_bdf(bdf_filename_out)

        msg = 'nnodes=%s\n' % len(model.nodes)
        for nid, node in sorted(model.nodes.items()):
            msg += 'nid=%s xyz=%s\n' % (nid, node.xyz)

        assert len(model.nodes) == 4, msg
        #os.remove(bdf_filename)
        os.remove(bdf_filename_out)

        tol = 0.009
        # Don't collapse anything because the tolerance is too small
        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(log=log, debug=False)
        model.read_bdf(bdf_filename_out)
        assert len(model.nodes) == 6, len(model.nodes)
        os.remove(bdf_filename_out)

        tol = 0.2
        node_set = [2, 3]
        # Node 2 is not defined, so crash
        with self.assertRaises(RuntimeError):
            # node 2 is not defined because it should be node 20
            bdf_equivalence_nodes(bdf_filename,
                                  bdf_filename_out,
                                  tol,
                                  renumber_nodes=False,
                                  neq_max=4,
                                  xref=True,
                                  node_set=node_set,
                                  crash_on_collapse=False,
                                  log=log,
                                  debug=False)

        tol = 0.2
        node_list = [20, 3]
        # Only collpase 2 nodes
        bdf_equivalence_nodes(bdf_filename,
                              bdf_filename_out,
                              tol,
                              renumber_nodes=False,
                              neq_max=4,
                              xref=True,
                              node_set=node_list,
                              crash_on_collapse=False,
                              log=log,
                              debug=False)
        model = BDF(log=log, debug=False)
        model.read_bdf(bdf_filename_out)
        assert len(model.nodes) == 5, len(model.nodes)
        os.remove(bdf_filename_out)

        tol = 0.2
        node_set = set([20, 3])
        # Only collpase 2 nodes
        bdf_equivalence_nodes(bdf_filename,
                              bdf_filename_out,
                              tol,
                              renumber_nodes=False,
                              neq_max=4,
                              xref=True,
                              node_set=node_set,
                              crash_on_collapse=False,
                              log=log,
                              debug=False)
        model = BDF(log=log, debug=False)
        model.read_bdf(bdf_filename_out)
        assert len(model.nodes) == 5, len(model.nodes)
        os.remove(bdf_filename_out)

        tol = 0.2
        aset = np.array([20, 3, 4], dtype='int32')
        bset = np.array([20, 3], dtype='int32')

        node_set = np.intersect1d(aset, bset)
        assert len(node_set) > 0, node_set
        # Only collpase 2 nodes
        bdf_equivalence_nodes(bdf_filename,
                              bdf_filename_out,
                              tol,
                              renumber_nodes=False,
                              neq_max=4,
                              xref=True,
                              node_set=node_set,
                              crash_on_collapse=False,
                              debug=False)
        model = BDF(debug=False)
        model.read_bdf(bdf_filename_out)
        assert len(model.nodes) == 5, len(model.nodes)
        os.remove(bdf_filename_out)