Ejemplo n.º 1
0
def main():
    fp = Points()
    nodes = fp.read_points()
    nnodes = nodes.shape[0]

    fe = Faces()
    quads = fe.read_faces()
    quads += 1

    f = open('points_faces.bdf', 'wb')
    f.write('CEND\n')
    f.write('BEGIN BULK\n')

    for inode, node in enumerate(nodes):
        card = ['GRID', inode + 1, None] + list(node)
        f.write(print_card_8(card))

    ielement = 1
    pid = 1
    for quad in quads:
        card = ['CQUAD4', ielement, pid] + list(quad)
        f.write(print_card_8(card))
        ielement += 1
    f.write('PSHELL, 1, 1, 0.1\n')
    f.write('MAT1, 1, 1.0,,0.3\n')
    f.write('ENDDATA\n')
    f.close()
Ejemplo n.º 2
0
def main():
    fp = Points()
    nodes = fp.read_points()
    nnodes = nodes.shape[0]

    fe = Faces()
    quads = fe.read_faces()
    quads += 1

    f = open('points_faces.bdf', 'wb')
    f.write('CEND\n')
    f.write('BEGIN BULK\n')

    for inode, node in enumerate(nodes):
        card = ['GRID', inode + 1, None] + list(node)
        f.write(print_card_8(card))

    ielement = 1
    pid = 1
    for quad in quads:
        card = ['CQUAD4', ielement, pid] + list(quad)
        f.write(print_card_8(card))
        ielement += 1
    f.write('PSHELL, 1, 1, 0.1\n')
    f.write('MAT1, 1, 1.0,,0.3\n')
    f.write('ENDDATA\n')
    f.close()
Ejemplo n.º 3
0
def main():
    foam_points = Points()
    nodes = foam_points.read_points()
    unused_nnodes = nodes.shape[0]

    foam_faces = Faces()
    quads = foam_faces.read_faces()
    quads += 1

    with open('points_faces.bdf', 'wb') as bdf_file:
        bdf_file.write('CEND\n')
        bdf_file.write('BEGIN BULK\n')

        for inode, node in enumerate(nodes):
            card = ['GRID', inode + 1, None] + list(node)
            bdf_file.write(print_card_8(card))

        ielement = 1
        pid = 1
        for quad in quads:
            card = ['CQUAD4', ielement, pid] + list(quad)
            bdf_file.write(print_card_8(card))
            ielement += 1
        bdf_file.write('PSHELL, 1, 1, 0.1\n')
        bdf_file.write('MAT1, 1, 1.0,,0.3\n')
        bdf_file.write('ENDDATA\n')
Ejemplo n.º 4
0
def vrml_to_nastran(vrml_filename: str,
                    nastran_filename: str,
                    debug=False,
                    log=None):
    """
    Converts a vrml file into a Nastran BDF.  Doesn't consider:
     - non-faceted geometry (only quads/tris, no spheres)
     - transforms

    """
    from pyNastran.bdf.field_writer import print_card_8, print_card_16

    nodes, quads, tris = read_vrml(vrml_filename, debug=debug, log=log)

    cp = 0
    mid = 1
    thickness = 0.1
    pid = 1
    E = 3.0e7
    G = None
    nu = 0.3

    ntris = len(tris)
    nquads = len(quads)
    with open(nastran_filename, 'w') as bdf_file:
        bdf_file.write('$ pyNastran: punch=True\n')
        card = ['PSHELL', pid, mid, thickness]
        bdf_file.write(print_card_8(card))

        card = ['MAT1', mid, E, G, nu]
        bdf_file.write(print_card_8(card))

        for i, xyz in enumerate(nodes):
            card = [
                'GRID',
                i + 1,
                cp,
            ] + xyz.tolist()
            bdf_file.write(print_card_16(card))

        if ntris:
            for ie, n123 in enumerate(tris + 1):
                card = [
                    'CTRIA3',
                    ie + 1,
                    pid,
                ] + n123.tolist()
                bdf_file.write(print_card_8(card))
        if nquads:
            for ie, n1234 in enumerate(quads + 1):
                card = [
                    'CQUAD4',
                    ntris + ie + 1,
                    pid,
                ] + n1234.tolist()
                bdf_file.write(print_card_8(card))
Ejemplo n.º 5
0
def write_buckling_bdfs(model, op2_filename, xyz_cid0, patches, patch_edges_array,
                        subcase_id=1, mode='displacement', workpath='results'):
    """
    Creates a series of buckling BDFs from a static analysis

    Parameters
    ----------
    model : BDF()
        the BDF object
    op2_filename : str
        the name of the OP2 to analyze
    xyz_cid0 : (nnodes, 3) ndarray
        the nodes in the global CID=0 frame
    patches : ???
        ???
    patch_edges_array : (n, 2) int ndarray
        all the edges on the geometry as (n1, n2) integer pairs
        where n1 < n2
    subcase_id : int; default=1
        the subcase to analyze
    mode : str; default='displacement'
        'displacement' : map displacements from the OP2 to the new BDFs
        'load' : map the grid point forces from the OP2 to the new BDFs
    workpath : str; default='results'
        the location of where the output files should be placed
    """
    # TODO: Create 'BDF' of deflected shape that doesn't include the wing up bend from the CAERO1
    #       boxes.  This will allow you to visually see where the wing undulates relative to the
    #       center plane of the wing
    assert mode in ['load', 'displacement'], 'mode=%r' % mode

    subcase = model.subcases[subcase_id]

    case_control_lines, bulk_data_cards, spc_id, mpc_id, load_id = create_buckling_header(subcase)

    out_model = OP2()
    print('**** workpath', workpath)
    out_model.read_op2(op2_filename)
    if mode == 'displacement':
        #print('out_model.displacements =', out_model.displacements)
        displacements = out_model.displacements[subcase_id]
        node_ids_full_model = displacements.node_gridtype[:, 0]
        ## TODO: check for cd != 0
    elif mode == 'load':
        nodal_forces = out_model.grid_point_forces[subcase_id]
    else:
        raise RuntimeError(mode)

    edge_nids = np.unique(patch_edges_array.ravel())
    #free_nodes = setdiff1d(node_ids_full_model, edge_nids) # A-B

    # TODO: support excluded pids
    excluded_pids = []

    patch_dir = os.path.join(workpath, 'patches')
    edge_dir = os.path.join(workpath, 'edges')
    if not os.path.exists(patch_dir):
        os.makedirs(patch_dir)
    if not os.path.exists(edge_dir):
        os.makedirs(edge_dir)
    for ipatch, patch_eids in enumerate(patches):
        patch_eids_array = np.array(patch_eids, dtype='int32')

        patch_filename = os.path.join(patch_dir, 'patch_%i.bdf' % ipatch)
        edge_filename = os.path.join(edge_dir, 'edge_%i.csv' % ipatch)
        patch_file = open(patch_filename, 'w')
        edge_file = open(edge_filename, 'w')

        patch_file.write('SOL 105\n')
        patch_file.write('CEND\n')
        patch_file.write(''.join(case_control_lines))
        patch_file.write('BEGIN BULK\n')
        for card in bulk_data_cards:
            patch_file.write(print_card_8(card))

        # get list of all nodes on patch_eids_array; write elements
        all_nids_on_patch = []
        pids_on_patch = set([])
        for eid in patch_eids_array:
            elem = model.elements[eid]
            node_ids = elem.node_ids

            all_nids_on_patch.append(node_ids)
            patch_file.write(str(elem))
            pids_on_patch.add(elem.Pid())

        # TODO: assumes a patch has only one property region
        pid = elem.Pid()

        if pid in excluded_pids:
            print('pid=%s is excluded; patch_filename=%s' % patch_filename)
            patch_file.close()
            edge_file.close()
            os.remove(patch_filename)
            os.remove(edge_filename)
            continue

        all_nids_on_patch = np.unique(np.hstack(all_nids_on_patch))

        nnodes = len(all_nids_on_patch)

        # get nodal cd; write nodes
        if mode == 'load':
            cd = np.zeros(nnodes, dtype='int32')
            for i, nid in enumerate(all_nids_on_patch):
                node = model.nodes[nid]
                cdi = node.Cd()
                patch_file.write(str(node))
                cd[i] = cdi
        elif mode == 'displacement':
            for i, nid in enumerate(all_nids_on_patch):
                node = model.nodes[nid]
                patch_file.write(str(node))
        else:
            raise NotImplementedError(mode)

        # model._write_common(patch_file, size=8, is_double=False)
        size = 8
        is_double = False
        model._write_coords(patch_file, size, is_double)
        model._write_materials(patch_file, size, is_double)

        for pid in pids_on_patch:
            prop = model.properties[pid]
            patch_file.write(prop.write_card(size=size, is_double=is_double))
            #model._write_properties(patch_file, size, is_double)

        # msg = ['                                          G R I D   P O I N T   F O R C E   B A L A N C E\n',
            # '  POINT-ID    ELEMENT-ID    SOURCE         T1             T2             T3             R1             R2             R3\n', ]
            #'0     13683          3736    TRIAX6         4.996584E+00   0.0            1.203093E+02   0.0            0.0            0.0'
            #'      13683          3737    TRIAX6        -4.996584E+00   0.0           -1.203093E+02   0.0            0.0            0.0'
            #'      13683                  *TOTALS*       6.366463E-12   0.0           -1.364242E-12   0.0            0.0            0.0'
        zero = ' '
        if 0:
            msg = []
            self = nodal_forces
            for ekey, force in sorted(iteritems(self.force_moment)):
                for iload, forcei in enumerate(force):
                    (f1, f2, f3, m1, m2, m3) = forcei
                    elem_name = self.elemName[ekey][iload]
                    eid = self.eids[ekey][iload]
                    # vals = [f1, f2, f3, m1, m2, m3]
                    # vals2 = write_floats_13e(vals)
                    # [f1, f2, f3, m1, m2, m3] = vals2
                    if eid == 0:
                        eid = ''
                    msg.append('%s  %8s    %10s    %-8s      %-13s  %-13s  %-13s  %-13s  %-13s  %s\n' % (
                        zero, ekey, eid, elem_name, f1, f2, f3, m1, m2, m3))
                    zero = ' '
                zero = '0'

        if mode == 'displacement':
            # the displacement are in the Cd coordinate frame
            # because we're just carrying along the GRID cards
            # we shouldn't need to do anything
            patch_edge_nids = []
            for edge in patch_edges_array:
                n1, n2 = edge
                if n1 in all_nids_on_patch and n2 in all_nids_on_patch:
                    patch_edge_nids.append(edge)
            patch_edge_nids = np.unique(np.vstack(patch_edge_nids))
            #print('patch_edge_nids = %s' % patch_edge_nids)
            #print('node_ids_full_model = %s' % node_ids_full_model)
            idisp_full_model = np.searchsorted(node_ids_full_model, patch_edge_nids)
            nids2 = node_ids_full_model[idisp_full_model]

            #print('idisp_full_model = %s' % idisp_full_model)
            #print('nids2 = %s' % nids2)
            #print('delta = %s' % (node_ids_full_model[idisp_full_model] - patch_edge_nids))


            # make sure we're in Cd == 0
            disp = displacements.data[0, idisp_full_model, :]
            #disp = displacements.data[:, 3]

            ipack = 0
            spc_pack = []
            #$SPCD         100   20028       1.0009906   20028       24.3233-4
            #$SPCD         100   20028       3.3169889   20028       41.6345-4
            #$SPCD         100   20028       5.0004592   20028       6-2.092-3
            #FORCE,1,20036,0,0.000001,1.0,1.0,1.0
            #SPC1,100,123456,20028


            n1 = patch_edge_nids[0]
            n2 = patch_edge_nids[1]

            spc1 = ['SPC1', spc_id, 123] + list(patch_edge_nids)
            #patch_file.write('SPC1,%i,123456,%i\n' % (spc_id, n1))
            patch_file.write(print_card_8(spc1))

            # dummy load
            # TODO: figure out free node
            #edge_nids = unique(patch_edges_array.ravel())
            #free_nodes = setdiff1d(node_ids_full_model, edge_nids) # A-B
            #free_nodes_on_patch = setdiff1d(free_nodes, all_nids_on_patch) # A-B
            #free_nodes_on_patch = in1d(free_nodes, all_nids_on_patch) # A and B

            free_nodes_on_patch = np.setdiff1d(all_nids_on_patch, edge_nids)
            #print('free_nodes_on_patch =', free_nodes_on_patch)
            if len(free_nodes_on_patch) == 0:
                print('couldnt find free node for patch_filename=%s' % patch_filename)
                patch_file.close()
                edge_file.close()
                #os.remove(patch_filename)
                #os.remove(edge_filename)
                continue
            free_node = free_nodes_on_patch[0]
            if free_node not in all_nids_on_patch:
                msg = 'free_node=%s is not patch_filename=in %s' % (free_node, patch_filename)
                raise RuntimeError(msg)
            patch_file.write('FORCE,%i,%i,0,0.000001,1.0,1.0,1.0\n' % (load_id, free_node))

            for i, nid in enumerate(patch_edge_nids):
                #if i == 0:
                    #continue
                xyz = xyz_cid0[nid]
                edge_file.write('%f, %f, %f\n' % (xyz[0], xyz[1], xyz[2]))
                assert nids2[i] == nid, 'nid=%s nid2=%s' % (nid, node_ids_full_model[i])
                for j in range(3):
                #for j in range(6):
                    dispi = disp[i, j]
                    if np.abs(dispi) > 0.0:
                        # SPCD, sid, g1, c1, d1
                        #patch_file.write(print_card_8(['SPCD', spc_id, nid, j + 1, dispi]))
                        if ipack == 0:
                            # SPCDs are loads, not SPCs.  Don't change this!!!
                            spc_pack = ['SPCD', load_id, nid, j + 1, dispi]
                            ipack += 1
                        else:
                            # ipack = 1
                            spc_pack += [nid, j + 1, dispi]
                            patch_file.write(print_card_8(spc_pack))
                            ipack = 0
                            spc_pack = []
            if len(spc_pack):
                patch_file.write(print_card_8(spc_pack))

        elif mode == 'load':
            # TODO: does this work for vectorized classes?
            for node_id, cdi in zip(all_nids_on_patch[1:], cd[1:]):
                force = nodal_forces.force_moment[node_id]
                force_moment_sum = np.zeros(6, dtype='float32')
                for iload, forcei in enumerate(force):
                    eid = nodal_forces.eids[node_id][iload]
                    element_name = nodal_forces.elemName[node_id][iload]
                    if eid not in patch_eids_array: # neighboring element
                        force_moment_sum += force[iload]
                    elif eid == 0 and element_name != '*TOTALS*':
                        print(element_name)
                        force_moment_sum += force[iload]

                abs_force_moment_sum = np.abs(force_moment_sum)
                forcei = abs_force_moment_sum[:3]
                momenti = abs_force_moment_sum[3:]
                if forcei.sum() > 0.0:
                    card = ['FORCE', load_id, node_id, cdi, 1.0, ] + list(forcei)
                    patch_file.write(print_card_8(card))
                if momenti.sum() > 0.0:
                    card = ['MOMENT', load_id, node_id, cdi, 1.0, ] + list(momenti)
                    patch_file.write(print_card_8(card))
        else:
            raise RuntimeError(mode)
        patch_file.write('ENDDATA\n')
        patch_file.close()
        edge_file.close()
    return