Ejemplo n.º 1
0
    def write_card(self, size=8, is_double=False):
        msg = '\n$' + '-' * 80
        msg += '\n$ %s Matrix %s\n' % ('DMI', self.name)
        list_fields = ['DMI', self.name, 0, self.form, self.tin,
                       self.tout, None, self.nRows, self.nCols]
        if size == 8:
            msg += print_card_8(list_fields)
        #elif is_double:
            #msg += print_card_double(list_fields)
        else:
            msg += print_card_16(list_fields)
        #msg += self.print_card(list_fields,size=16,isD=False)

        if self.is_complex():
            for (gci, gcj, reali, imagi) in zip(self.GCi, self.GCj, self.Real, self.Complex):
                list_fields = ['DMI', self.name, gcj, gci, reali, imagi]
                if size == 8:
                    msg += print_card_8(list_fields)
                elif is_double:
                    msg += print_card_double(list_fields)
                else:
                    msg += print_card_16(list_fields)
        else:
            for (gci, gcj, reali) in zip(self.GCi, self.GCj, self.Real):
                list_fields = ['DMI', self.name, gcj, gci, reali]
                if size == 8:
                    msg += print_card_8(list_fields)
                elif is_double:
                    msg += print_card_double(list_fields)
                else:
                    msg += print_card_16(list_fields)
        return msg
Ejemplo n.º 2
0
    def write_card(self, size=8, is_double=False):
        """
        .. todo:: support double precision
        """
        msg = '\n$' + '-' * 80
        msg += '\n$ %s Matrix %s\n' % (self.type, self.name)
        list_fields = [self.type, self.name, 0, self.ifo, self.tin,
                       self.tout, self.polar, None, self.ncols]
        if size == 8:
            msg += print_card_8(list_fields)
        else:
            msg += print_card_16(list_fields)

        if self.is_complex():
            if self.is_polar():
                for (GCi, GCj, reali, complexi) in zip(self.GCi, self.GCj, self.Real, self.Complex):
                    magi = sqrt(reali**2 + complexi**2)
                    if reali == 0.0:
                        phasei = 0.0
                    else:
                        phasei = degrees(atan2(complexi, reali))
                    list_fields = [self.type, self.name, GCj[0], GCj[1],
                                   None, GCi[0], GCi[1], magi, phasei]
                    if size == 8:
                        msg += print_card_8(list_fields)
                    elif is_double:
                        msg += print_card_double(list_fields)
                    else:
                        msg += print_card_16(list_fields)
            else:
                for (GCi, GCj, reali, complexi) in zip(self.GCi, self.GCj, self.Real, self.Complex):
                    list_fields = [self.type, self.name, GCj[0], GCj[1],
                                   None, GCi[0], GCi[1], reali, complexi]
                    if size == 8:
                        msg += print_card_8(list_fields)
                    elif is_double:
                        msg += print_card_double(list_fields)
                    else:
                        msg += print_card_16(list_fields)
        else:
            for (GCi, GCj, reali) in zip(self.GCi, self.GCj, self.Real):
                list_fields = [self.type, self.name, GCj[0], GCj[1],
                               None, GCi[0], GCi[1], reali, None]
                if size == 8:
                    msg += print_card_8(list_fields)
                elif is_double:
                    msg += print_card_double(list_fields)
                else:
                    msg += print_card_16(list_fields)
        return msg
Ejemplo n.º 3
0
def cogsg_bc_to_nastran(cogsg_filename, bc_filename, nastran_filename,
                        include_shells=True, include_solids=False):
    """
    converts a *.cogsg and a *.bc file to a *.bdf file
    """
    model = Usm3d(log=None, debug=None)
    nodes, tets = model.read_cogsg(cogsg_filename, stop_after_header=False)
    assert tets.min() == 0, tets.min()

    if not include_shells or include_solids:
        msg = 'include_shells=%r include_solids=%r; one/both must be True' % (
            include_shells, include_solids)
        raise RuntimeError(msg)

    bcs = [0]
    if include_shells:
        header, tris, bcs = model.read_bc(bc_filename)

    with open(nastran_filename, 'w') as bdf_file:
        bdf_file.write('$ pyNastran : punch=True\n')

        if include_solids:
            for nid, (x, y, z) in zip(count(), nodes):
                bdf_file.write(print_card_16(['GRID', nid + 1, '', x, y, z]))
        else:
            nids = np.unique(tris.ravel())
            for nid in nids:
                x, y, z = nodes[nid, :]
                bdf_file.write(print_card_16(['GRID', nid + 1, '', x, y, z]))

        if include_shells:
            for itri, tri, bc in zip(count(), tris + 1, bcs):
                bdf_file.write(
                    print_card_8(['CTRIA3', itri + 1, bc] + list(tri))
                )

            mid = 1
            for bc in np.unique(bcs):
                bdf_file.write(print_card_8(['PSHELL', bc, mid, 0.1]))
            bdf_file.write(print_card_8(['MAT1', mid, 3.0e7, None, 0.3]))

        if include_solids:
            pid = max(bcs) + 1
            mid = 2
            for itet, tet in zip(count(), tets + 1):
                print_card_8(['CTETRA', itet + 1, pid] + list(tet))
            bdf_file.write(print_card_8(['PSOLID', pid, mid]))
            bdf_file.write(print_card_8(['MAT1', mid, 3.0e7, None, 0.3]))
Ejemplo n.º 4
0
    def write_card(self, f, size=8, property_id=None):
        #print('PBARL.n = %s' % self.n)
        if self.n:
            if property_id is None:
                i = arange(self.n)
            else:
                i = searchsorted(self.property_id, property_id)
            #print('i = %s' % i)
            #cid = [cid if cid != 0 else '' for cid in self.coord_id]

            #group = set_blank_if_default(self.group, 'MSCBMLO')
            #list_fields = ['PBARL', self.pid, self.Mid(), group, self.Type, None,
                           #None, None, None] + self.dim + [self.nsm]

            #self.model.log.debug('*pbarl write pids=%s' % self.property_id)
            for (j, pid, mid, group, Type, nsm) in zip(count(), self.property_id[i], self.material_id[i],
                                                       self.group[i], self.Type[i], self.nsm[i]):
                dim = self.dim[j]
                sgroup = set_blank_if_default(group, 'MSCBMLO')

                list_fields = ['PBARL', pid, mid, group, Type, None,
                               None, None, None] + dim + [nsm]
                if size == 8:
                    f.write(print_card_8(list_fields))
                else:
                    f.write(print_card_16(list_fields))
Ejemplo n.º 5
0
def print_card(fields, size=8, is_double=False):
    """
    Prints a card in 8-character of 16-character Nastran format.

    Parameters
    ----------
    fields : List[int/float/str/None]
        all the fields in the BDF card (no trailing Nones)
    size : int; default=8
        the size of the field (8/16)
    is_double : bool; default=False
        is the card double precision?
        Double precision applies to specific cards and turns
        1.234E+5 into 1.234D+5.  Applies to GRID, CORDx only?

    Returns
    -------
    card : str
        string representation of the card

    .. note:: be careful of using is_double on cards that aren't
              GRID or CORDx
    """
    if size == 8:
        return print_card_8(fields)
    elif is_double:
        return print_card_double(fields)
    return print_card_16(fields)
Ejemplo n.º 6
0
 def write_card(self, size=8, is_double=False):
     card = wipe_empty_fields(self.repr_fields())
     if size == 8 or len(card) == 8: # to last node
         msg = self.comment + print_card_8(card)
     else:
         msg = self.comment + print_card_16(card)
     return msg
Ejemplo n.º 7
0
 def write_card(self, size=8, is_double=False):
     card = self.raw_fields()
     if size == 8:
         return self.comment + print_card_8(card)
     if is_double:
         return self.comment + print_card_double(card)
     return self.comment + print_card_16(card)
Ejemplo n.º 8
0
 def write_card(self, bdf_file, size=8):
     card = ['SPCADD', self.spc_id] + self.spc_ids
     #print("card = ", card)
     if size == 8:
         bdf_file.write(print_card_8(card))
     else:
         bdf_file.write(print_card_16(card))
Ejemplo n.º 9
0
 def write_card(self, bdf_file, size=8):
     card = ['NLPCI', self.nlpci_id, self.Type, self.minalr,
             self.maxalr, self.scale, None, self.desiter, self.mxinc]
     if size == 8:
         bdf_file.write(print_card_8(card))
     else:
         bdf_file.write(print_card_16(card))
Ejemplo n.º 10
0
 def write_card(self, f, size=8, is_double=False):
     if self.n:
         card = ['GRDSET', None, self.cp, None, None, None, self.cd, self.seid]
         if size == 8:
             f.write(print_card_8(card))
         else:
             f.write(print_card_16(card))
Ejemplo n.º 11
0
    def write_card(self, f, size=8, is_double=True, element_id=None):
        assert size in [8, 16], size
        assert is_double in [True, False], is_double
        if self.n:
            if element_id is None:
                i = arange(self.n)
            else:
                #assert len(unique(element_id))==len(element_id), unique(element_id)
                i = searchsorted(self.element_id, element_id)

            Cid = [cid if cid != 0 else '' for cid in self.coord_id[i]]
            Nspan = [nspan if nspan != 0 else '' for nspan in self.nspan[i]]
            Nchord = [nchord if nchord != 0 else '' for nchord in self.nchord[i]]

            Igid = self.igid[i]
            Lspan = [lspan if lspan != 0. else '' for lspan in self.lspan[i]]
            Lchord = [lchord if lchord != 0. else '' for lchord in self.lchord[i]]

            for (eid, pid, cid, nspan, nchord, lspan, lchord, igid,
                 p1, x12, p4, x43) in zip(self.element_id[i], self.property_id[i],
                 Cid, Nspan, Nchord, Lspan, Lchord, Igid,
                 self.p1[i, :], self.x12[i], self.p4[i, :], self.x43[i]):
                card = ['CAERO1', eid, pid, cid, nspan, nchord, lspan, lchord, igid,
                        p1[0], p1[1], p1[2], x12,
                        p4[0], p4[1], p4[2], x43,]
                if size == 8:
                    f.write(print_card_8(card))
                else:
                    f.write(print_card_16(card))
Ejemplo n.º 12
0
 def write_card(self, f, size=8):
     for comp, nodes in iteritems(self.components):
         card = ['SPC1', self.constraint_id, comp] + list(nodes)
         if size == 8:
             f.write(print_card_8(card))
         else:
             f.write(print_card_16(card))
Ejemplo n.º 13
0
    def write_card(self, f, size=8, element_ids=None):
        if self.n:
            if element_ids is None:
                i = arange(self.n)
            else:
                i = searchsorted(self.element_id, self.element_id)

            for (eid, pid, n, is_g0, g0, x, offt, pin, wa, wb) in zip(
                self.element_id[i], self.property_id[i], self.node_ids[i],
                self.is_g0[i], self.g0[i], self.x[i],
                self.offt[i],
                self.pin_flags[i], self.wa[i], self.wb[i]):

                pa = set_blank_if_default(pin[0], 0)
                pb = set_blank_if_default(pin[1], 0)

                w1a = set_blank_if_default(wa[0], 0.0)
                w2a = set_blank_if_default(wa[1], 0.0)
                w3a = set_blank_if_default(wa[2], 0.0)
                w1b = set_blank_if_default(wb[0], 0.0)
                w2b = set_blank_if_default(wb[1], 0.0)
                w3b = set_blank_if_default(wb[2], 0.0)
                x1 = g0 if is_g0 else x[0]
                x2 = 0 if is_g0 else x[1]
                x3 = 0 if is_g0 else x[2]

                offt = set_string8_blank_if_default(offt, 'GGG')
                card = ['CBAR', eid, pid, n[0], n[1], x1, x2, x3, offt,
                        pa, pb, w1a, w2a, w3a, w1b, w2b, w3b]
                if size == 8:
                    f.write(print_card_8(card))
                else:
                    f.write(print_card_16(card))
Ejemplo n.º 14
0
 def write_card(self, f, size=8):
     card = ['SPCADD', self.spc_id] + self.spc_ids
     #print "card = ", card
     if size == 8:
         f.write(print_card_8(card))
     else:
         f.write(print_card_16(card))
Ejemplo n.º 15
0
def cart3d_to_nastran_filename(cart3d_filename, bdf_filename, log=None, debug=False):
    """
    Converts a Cart3D file to Nastran format.

    Parameters
    ----------
    cart3d_filename : str
        path to the input Cart3D file
    bdf_filename : str
        path to the output BDF file
    log : log / None
        log : a logger object
        None : a log will be defined
    debug : bool
        True/False (used if log is not defined)
    """
    cart3d = Cart3D(log=log, debug=debug)
    cart3d.read_cart3d(cart3d_filename)
    nodes = cart3d.nodes
    elements = cart3d.elements
    regions = cart3d.regions

    #bdf = BDF()
    #bdf.nodes = cart3d.nodes
    #bdf.elements = cart3d.elements
    #bdf.write_bdf(bdf_filename)
    #return
    f = open(bdf_filename, 'wb')
    f.write('CEND\n')
    f.write('BEGIN BULK\n')
    f.write('$Nodes\n')

    i = 0
    nid = 1
    cid = 0
    for node in nodes:
        card = print_card_16(['GRID', nid, cid] + list(node))
        f.write(card)
        nid += 1

    eid = 1
    f.write('$Elements\n')
    for (n1, n2, n3), pid in zip(elements, regions):
        card = print_card_8(['CTRIA3', eid, pid, n1, n2, n3])
        f.write(card)
        eid += 1

    t = 0.1
    E = 1e7
    nu = 0.3
    f.write('$Properties\n')
    for pid in unique(regions):
        mid = pid
        card = print_card_8(['PSHELL', pid, mid, t])
        f.write(card)
        card = print_card_8(['MAT1', mid, E, None, nu])
        f.write(card)
    f.write('ENDDATA\n')
    f.close()
Ejemplo n.º 16
0
    def write_card_by_index(self, bdf_file, size=8, is_double=False, i=None):
        for (lid, nid, cid, mag, xyz) in zip(self.load_id, self.node_id, self.coord_id, self.mag, self.xyz):

            card = ["FORCE2", lid, nid, cid, mag, xyz[0], xyz[1], xyz[2]]
            if size == 8:
                bdf_file.write(print_card_8(card))
            else:
                bdf_file.write(print_card_16(card))
Ejemplo n.º 17
0
 def write_card(self, f, size=8, is_double=False):
     #.. todo:: collapse the IDs
     if self.n:
         card = ['EPOINT'] + list(self.epoint)
         if size == 8:
             f.write(print_card_8(card))
         else:
             f.write(print_card_16(card))
Ejemplo n.º 18
0
 def write_card_by_index(self, bdf_file, size=8, is_double=False, i=None):
     if self.n:
         for (pid, k, ge, s) in zip(self.property_id[i], self.K[i], self.ge[i], self.s[i]):
             card = ['PELAS', pid, k, ge, s]
             if size == 8:
                 bdf_file.write(print_card_8(card))
             else:
                 bdf_file.write(print_card_16(card))
Ejemplo n.º 19
0
 def write_card(self, bdf_file, size=8):
     if self.n:
         for (nid, constraint, enforced) in zip(self.node_id, self.components, self.enforced_motion):
             fields = ['SPCD', self.constraint_id, nid, constraint, enforced]
             if size == 8:
                 bdf_file.write(print_card_8(fields))
             else:
                 bdf_file.write(print_card_16(fields))
Ejemplo n.º 20
0
 def write_card(self, bdf_file, size=8, is_double=False):
     # .. todo:: collapse the IDs
     if self.n:
         card = ["EPOINT"] + list(self.epoint)
         if size == 8:
             bdf_file.write(print_card_8(card))
         else:
             bdf_file.write(print_card_16(card))
Ejemplo n.º 21
0
 def write_card(self, f, size=8):
     if self.n:
         #n = 0
         for lid, t in zip(self.load_id, self.temperature_default):
             card = ['TEMPD', lid, t]
             if size == 8:
                 f.write(print_card_8(card))
             else:
                 f.write(print_card_16(card))
Ejemplo n.º 22
0
 def write_card(self, size=8, is_double=False):
     card = wipe_empty_fields(self.repr_fields())
     if size == 8 or len(card) == 8: # to last node
         msg = self.comment + print_card_8(card)
     else:
         msg = self.comment + print_card_16(card)
     #msg2 = self.write_card(size)
     #assert msg == msg2, '\n%s---\n%s\n%r\n%r' % (msg, msg2, msg, msg2)
     return msg
Ejemplo n.º 23
0
 def write_card(self, f, size=8, is_double=False):
     if self.n:
         f.write('$POINTAX\n')
         for (nid, rid, phi) in zip(self.point_id, self.ring_id, self.phi):
             card = ['POINTAX', rid, phi]
             if size == 8:
                 f.write(print_card_8(card))
             else:
                 f.write(print_card_16(card))
Ejemplo n.º 24
0
    def write_card_by_index(self, bdf_file, size=8, is_double=False, i=None):
        for (lid, cid, scale, N, mb) in zip(
             self.load_id[i], self.coord_id[i], self.scale[i], self.N[i, :], self.mb[i]):

            card = ['GRAV', lid, cid, scale, N[0], N[1], N[2], mb]
            if size == 8:
                bdf_file.write(print_card_8(card))
            else:
                bdf_file.write(print_card_16(card))
Ejemplo n.º 25
0
def stl_to_nastran_filename(stl_filename, bdf_filename,
                            nnodes_offset=0, nelements_offset=0,
                            pid=100, mid=200,
                            size=8, is_double=False,
                            log=None):
    model = STLReader(log=log)
    model.read_stl(stl_filename)

    nid = nnodes_offset + 1
    cid = None
    load_id = 10

    nodal_normals = model.get_normals_at_nodes(model.elements)

    bdf = open(bdf_filename, 'wb')
    bdf.write('CEND\n')
    #bdf.write('LOAD = %s\n' % load_id)
    bdf.write('BEGIN BULK\n')
    nid2 = 1
    magnitude = 100.

    if size == 8:
        print_card = print_card_8
    elif size == 16:
        if is_double:
            print_card = print_card_16
        else:
            print_card = print_card_double

    for x, y, z in model.nodes:
        card = ['GRID', nid, cid, x, y, z]
        bdf.write(print_card_16(card))

        #nx, ny, nz = nodal_normals[nid2 - 1]
        #card = ['FORCE', load_id, nid, cid, magnitude, nx, ny, nz]
        #bdf.write(print_card_8(card))
        nid += 1
        nid2 += 1

    eid = nelements_offset + 1
    for (n1, n2, n3) in (model.elements + (nnodes_offset + 1)):
        card = ['CTRIA3', eid, pid, n1, n2, n3]
        bdf.write(print_card_8(card))
        eid += 1

    t = 0.1
    card = ['PSHELL', pid, mid, t]
    bdf.write(print_card_8(card))

    E = 1e7
    G = None
    nu = 0.3
    card = ['MAT1', mid, E, G, nu]
    bdf.write(print_card_8(card))

    bdf.write('ENDDATA\n')
    bdf.close()
Ejemplo n.º 26
0
    def write_card_by_index(self, bdf_file, size=8, is_double=False, i=None):
        for (lid, nid, cid, mag, n1234) in zip(
             self.load_id, self.node_id, self.mag, self.grids):

            card = ['MOMENT2', lid, nid, cid, mag] + list(n1234)
            if size == 8:
                bdf_file.write(print_card_8(card))
            else:
                bdf_file.write(print_card_16(card))
Ejemplo n.º 27
0
 def write_card(self, f, size=8):
     if self.n:
         for dof, node_ids in sorted(iteritems(self.components)):
             card = ['SPC', self.constraint_id]
             for node_id in node_ids:
                 card += [node_id, dof, 0.0]
             if size == 8:
                 f.write(print_card_8(card))
             else:
                 f.write(print_card_16(card))
Ejemplo n.º 28
0
 def write_card(self, bdf_file, size=8, is_double=False, load_id=None):
     if self.n:
         i = self.get_index(load_ids)
         for (lid, eid, p, n, theta) in zip(self.load_id[i],
                 self.element_id[i], self.p[i], self.node_ids[i], self.theta[i]):
             card = ['PLOADX1', lid, eid, p[0], p[1], n[0], n[1], theta]
             if size == 8:
                 bdf_file.write(print_card_8(card))
             else:
                 bdf_file.write(print_card_16(card))
Ejemplo n.º 29
0
 def write_card(self, size=8, is_double=False):
     msg = self.comment
     node_ids = self.node_ids
     if size == 8:
         for nid, comp, delay in zip(node_ids, self.components, self.phase_leads):
             msg += print_card_8(['DPHASE', self.sid, nid, comp, delay])
     else:
         for nid, comp, delay in zip(node_ids, self.components, self.phase_leads):
             msg += print_card_16(['DPHASE', self.sid, nid, comp, delay])
     return msg
Ejemplo n.º 30
0
    def write_card(self, f, size=8, lids=None):
        if self.n:
            for (lid, nid, cid, mag, xyz) in zip(
                 self.load_id, self.node_id, self.coord_id, self.mag, self.xyz):

                card = ['MOMENT', lid, nid, cid, mag, xyz[0], xyz[1], xyz[2]]
                if size == 8:
                    f.write(print_card_8(card))
                else:
                    f.write(print_card_16(card))
Ejemplo n.º 31
0
def cart3d_to_nastran_filename(cart3d_filename,
                               bdf_filename,
                               log=None,
                               debug=False):
    """
    Converts a Cart3D file to Nastran format.

    Parameters
    ----------
    cart3d_filename : str
        path to the input Cart3D file
    bdf_filename : str
        path to the output BDF file
    log : log / None
        log : a logger object
        None : a log will be defined
    debug : bool
        True/False (used if log is not defined)

    Examples
    --------
    >>> cart3d_filename = 'threePlugs.tri'
    >>> bdf_filename = 'threePlugs.bdf'
    >>> cart3d_to_nastran_filename(cart3d_filename, bdf_filename)
    """
    if isinstance(cart3d_filename, Cart3D):
        cart3d = cart3d_filename
    else:
        cart3d = read_cart3d(cart3d_filename,
                             log=log,
                             debug=debug,
                             result_names=None)

    nodes = cart3d.nodes
    elements = cart3d.elements + 1
    regions = cart3d.regions

    if regions.min() == 0:
        # bit of a hack to take an invalid cart3d model and make it
        # work in Nastran, which requires property_ids > 0
        regions += 1

    #bdf = BDF()
    #bdf.nodes = cart3d.nodes
    #bdf.elements = cart3d.elements
    #bdf.write_bdf(bdf_filename)
    #return
    with open(bdf_filename, 'w') as bdf_file:
        bdf_file.write('CEND\n')
        bdf_file.write('BEGIN BULK\n')
        bdf_file.write('$Nodes\n')

        i = 0
        nid = 1
        cid = 0
        for node in nodes:
            card = print_card_16(['GRID', nid, cid] + list(node))
            bdf_file.write(card)
            nid += 1

        eid = 1
        bdf_file.write('$Elements\n')
        assert 0 not in elements
        for (n1, n2, n3), pid in zip(elements, regions):
            card = print_card_8(['CTRIA3', eid, pid, n1, n2, n3])
            bdf_file.write(card)
            eid += 1

        t = 0.1
        E = 1e7
        nu = 0.3
        bdf_file.write('$Properties\n')
        for pid in unique(regions):
            mid = pid
            card = print_card_8(['PSHELL', pid, mid, t])
            bdf_file.write(card)
            card = print_card_8(['MAT1', mid, E, None, nu])
            bdf_file.write(card)
        bdf_file.write('ENDDATA\n')
Ejemplo n.º 32
0
 def write_card(self, bdf_file, size=8):
     card = ['MPCADD', self.constraint_id] + self.mpc_ids
     if size == 8:
         bdf_file.write(print_card_8(card))
     else:
         bdf_file.write(print_card_16(card))
Ejemplo n.º 33
0
    def project(self, bdf_filename, x0, growth_rate=1.3, nlayers=10):
        x = zeros(nlayers, dtype='float64')
        for i in range(nlayers):
            x[i] = x0 * growth_rate ** i

        #print(self.nodes.shape)
        #print(self.elements.shape)

        nnodes = self.nodes.shape[0]
        nelements = self.elements.shape[0]

        nnodes2 = nnodes * (nlayers + 1)
        npents = nelements * nlayers

        cnormals = self.get_normals(self.nodes, self.elements)
        nnormals = self.get_normals_at_nodes(self.nodes, self.elements, cnormals)

        nodes = zeros((nnodes2, 3), dtype='float64')
        pents = zeros((npents, 6), dtype='int32')
        ih1 = 0

        in1 = 0
        in2 = nnodes
        nodes[in1:in2, :] = self.nodes
        in1 += nnodes
        in2 += nnodes

        ih1 = 0
        ih2 = nelements
        print('x = %s' % x)
        for i in range(nlayers):
            nodes_old = self.nodes
            dx = nnormals * x[i]
            nodes_new = self.nodes + dx
            dn0 = nnodes * i
            dn1 = nnodes * (i + 1)
            elements_old = self.elements + nnodes * i
            elements_new = self.elements + nnodes * (i + 1)

            pents[ih1:ih2, 0:3] = deepcopy(elements_old)
            pents[ih1:ih2, 3:6] = deepcopy(elements_new)
            nodes[in1:in2, :] = deepcopy(nodes_new)

            in1 += nnodes
            in2 += nnodes
            ih1 += nelements
            ih2 += nelements

        with open(bdf_filename, 'wb') as f:
            f.write('CEND\n')
            f.write('BEGIN BULK\n')

            pents += 1
            cid = None
            for nid, grid in enumerate(nodes):
                if nid % 5000 == 0:
                    print('writing nid=%s' % (nid + 1))

                card = ['GRID', nid + 1, cid, ] + list(grid)
                f.write(print_card_16(card))

            pid = 0
            mid = 1
            for eid, penta in enumerate(pents):
                if (eid + 1) % nelements == 1:
                    pid += 1
                    card = ['PSOLID', pid, mid]
                    f.write(print_card_8(card))
                    print('bumping pid -> %s' % pid)
                if eid % 5000 == 0:
                    print('writing eid=%s' % (eid + 1))
                card = ['CPENTA', eid + 1, pid, ] + list(penta)
                f.write(print_card_8(card))

            card = ['MAT1', mid, 1.0e7, None, 0.3]
            f.write(print_card_8(card))
            f.write('ENDDATA\n')
Ejemplo n.º 34
0
 def write_card(self, size: int = 8, is_double: bool = False) -> str:
     # double precision?
     card = self.repr_fields()
     if size == 8:
         return self.comment + print_card_8(card)
     return self.comment + print_card_16(card)
Ejemplo n.º 35
0
 def write_card(self, size: int = 8, is_double: bool = False) -> str:
     card = self.repr_fields()
     if size == 8:
         return self.comment + print_card_8(
             card)  # having trouble with double precision...
     return self.comment + print_card_16(card)
Ejemplo n.º 36
0
def stl_to_nastran(stl_filename,
                   bdf_filename,
                   nnodes_offset=0,
                   nelements_offset=0,
                   pid=100,
                   mid=200,
                   size=8,
                   is_double=False,
                   log=None):
    if isinstance(stl_filename, string_types):
        model = STL(log=log)
        model.read_stl(stl_filename)
    elif isinstance(stl_filename, STL):
        model = stl_filename
    else:
        raise TypeError('stl_filename must be a string or STL; type=%s' %
                        type(stl_filename))

    nid = nnodes_offset + 1
    cid = None
    load_id = 10

    nodal_normals = model.get_normals_at_nodes(model.elements)

    if size == 8:
        print_card = print_card_8
    elif size == 16:
        if is_double:
            print_card = print_card_16
        else:
            print_card = print_card_double
    else:
        raise RuntimeError('size=%r' % size)

    with open(bdf_filename, 'w') as bdf:
        bdf.write('CEND\n')
        #bdf.write('LOAD = %s\n' % load_id)
        bdf.write('BEGIN BULK\n')
        nid2 = 1
        magnitude = 100.

        for x, y, z in model.nodes:
            card = ['GRID', nid, cid, x, y, z]
            bdf.write(print_card_16(card))

            #nx, ny, nz = nodal_normals[nid2 - 1]
            #card = ['FORCE', load_id, nid, cid, magnitude, nx, ny, nz]
            #bdf.write(print_card_8(card))
            nid += 1
            nid2 += 1

        eid = nelements_offset + 1
        for (n1, n2, n3) in (model.elements + (nnodes_offset + 1)):
            card = ['CTRIA3', eid, pid, n1, n2, n3]
            bdf.write(print_card_8(card))
            eid += 1

        t = 0.1
        card = ['PSHELL', pid, mid, t]
        bdf.write(print_card_8(card))

        E = 1e7
        G = None
        nu = 0.3
        card = ['MAT1', mid, E, G, nu]
        bdf.write(print_card_8(card))
        bdf.write('ENDDATA\n')
    return bdf
Ejemplo n.º 37
0
 def write_card_16(self, is_double=False):
     # type: (bool) -> str
     card = self.repr_fields()
     return self.comment + print_card_16(card)
Ejemplo n.º 38
0
    def test_card_double(self):
        fields = ['GRID', 1, None, 120.322, -4.82872, 1.13362]
        card_expected = (
            'GRID*                  1                1.2032200000D+02-4.828720000D+00\n'
            '*       1.1336200000D+00\n')
        card1 = print_card(fields, size=16, is_double=True)
        card2 = print_card_double(fields)
        self.assertEqual(card1, card_expected)
        self.assertEqual(card2, card_expected)

        #card = print_card_double(['CHEXA', 1, 2, 2, 3, 4, 1, 8, 5,
        #6, 7])
        #card_expected = ''
        #card_expected += 'CHEXA*                 1               2               2               3\n'
        #card_expected +='*                      4               1               8               5\n'
        #card_expected +='*                      6               7\n'
        #card_expected += '*       1.1336200000D+00\n'

        #card = print_card_double(['CTETRA',6437,1,14533,5598,1577,9976,42364,5599,42365,42363,30022,12904])
        #card_expected = ''

        #card_expected += 'CTETRA*             6437               1           14533            5598\n'
        #card_expected += '*                   1577            9976           42364            5599\n'
        #card_expected += '*                  42365           42363           30022           12904\n'
        #card_expected += '*       \n'

        #card_expected +='CTETRA*  6437            1               14533           5598\n'
        #card_expected +='*        1577            9976            42364           5599\n'
        #card_expected +='*        42365           42363           30022           12904\n'
        #card_expected +='*       \n'
        #self.assertEqual(card, card_expected)

        #=============================
        #           mid   E1      E2      nu12 G12      G1z      G2z      rho
        fields = [
            'MAT8',
            6,
            1.7e+7,
            1.7e+7,
            .98,
            340000.,
            180000.,
            180000.,
            0.0001712,
            # a1    a2    tref
            None,
            71.33
        ]
        card_expected = (
            'MAT8           6   1.7+7   1.7+7     .98 340000. 180000. 180000..0001712\n'
            '                   71.33\n')
        card1 = print_card_8(fields)
        card2 = print_card(fields)
        self.assertEqual(card1, card_expected)
        self.assertEqual(card2, card_expected)

        fields = [
            'MAT8',
            6,
            1.7e+7,
            1.7e+7,
            .98,
            340000.,
            180000.,
            180000.,
            0.0001712,
            # a1    a2    tref
            None,
            71.33
        ]
        card1 = print_card_16(fields)
        card2 = print_card(fields, size=16)

        card_expected = (
            'MAT8*                  6       17000000.       17000000.             .98\n'
            '*                340000.         180000.         180000.        .0001712\n'
            '*                                  71.33\n'
            '*\n')
        # bad
        self.assertEqual(card1, card_expected)
        self.assertEqual(card2, card_expected)
Ejemplo n.º 39
0
 def write_card_16(self, is_double=False):
     card = self.raw_fields()
     return self.comment + print_card_16(card)
Ejemplo n.º 40
0
 def write_card_16(self, is_double: bool = False) -> str:
     card = self.repr_fields()
     return self.comment + print_card_16(card)
Ejemplo n.º 41
0
def _write_skin_solid_faces(model,
                            skin_filename,
                            face_map,
                            nids_to_write,
                            eids_to_write,
                            mids_to_write,
                            eid_set,
                            eid_shell,
                            pid_shell,
                            mid_shell,
                            write_solids=False,
                            write_shells=True,
                            size=8,
                            is_double=False,
                            encoding=None):
    """
    helper method for ``write_skin_solid_faces``

    Parameters
    ----------
    model : BDF()
        the BDF object
    skin_filename : str
        the file to write
    face_map : dict[sorted_face] : face
        sorted_face : List[int, int, int] / List[int, int, int, int]
        face : List[int, int, int] / List[int, int, int, int]
    nids_to_write : List[int, int, ...]
        list of node ids to write
    eids_to_write : List[int, int, ...]
        list of element ids to write
    mids_to_write : List[int, int, ...]
        list of material ids to write
    eid_set : dict[face] : eids
        ???
    eid_shell : int
        the next id to use for the shell id
    pid_shell : int
        the next id to use for the shell property
    mid_shell : int
        the next id to use for the shell material
    write_solids : bool; default=False
        write solid elements that have skinned faces
    write_shells : bool; default=True
        write shell elements
    size : int; default=8
        the field width
    is_double : bool; default=False
        double precision flag
    encoding : str; default=None -> system default
        the string encoding

    """
    encoding = model.get_encoding(encoding)
    if PY2:
        wb = 'wb'
    else:
        wb = 'w'
    with open(skin_filename, wb, encoding=encoding) as bdf_file:
        bdf_file.write('$ pyNastran: punch=True\n')
        for nid in sorted(nids_to_write):
            if nid is None:
                continue
            node = model.nodes[nid]
            bdf_file.write(node.write_card(size=size, is_double=is_double))

        for cid, coord in model.coords.items():
            if cid == 0:
                continue
            bdf_file.write(coord.write_card(size=size, is_double=is_double))

        if write_solids:
            for eid in sorted(eids_to_write):
                elem = model.elements[eid]
                bdf_file.write(elem.write_card(size=size))
            for pid, prop in model.properties.items():
                bdf_file.write(prop.write_card(size=size, is_double=is_double))
            for mid in sorted(mids_to_write):
                material = model.materials[mid]
                bdf_file.write(
                    material.write_card(size=size, is_double=is_double))
            del eid, pid, mid

        if write_shells:
            mids_to_write.sort()
            for imid, mid in enumerate(mids_to_write):
                card = ['PSHELL', pid_shell + imid, mid_shell + imid, 0.1]
                try:
                    msg = print_card_8(card)
                except RuntimeError:
                    msg = print_card_16(card)
                bdf_file.write(msg)

                card = ['MAT1', mid_shell + imid, 3.e7, None, 0.3]
                #bdf_file.write(model.materials[mid].comment)
                try:
                    msg = print_card_8(card)
                except RuntimeError:
                    msg = print_card_16(card)
                bdf_file.write(msg)

            for face, eids in eid_set.items():
                face_raw = face_map[face]
                nface = len(face)
                #print("eids =", eids)
                #assert len(eids) == 1, eids
                #for eid in sorted(eids):
                #elem = model.elements[eid]
                #print(elem)
                #break

                #elem = next(itervalues(model.elements)) # old
                assert len(eids) == 1, eids
                elem = model.elements[eids[0]]
                #pid = next(model.properties.keys())
                pid = elem.Pid()
                prop = model.properties[pid]
                if prop.type in ['PSOLID']:  # 'PSHELL',
                    mid = prop.Mid()
                #elif prop.type in ['PCOMP', 'PCOMPG']:
                #mid = prop.mids[0]
                else:
                    raise NotImplementedError(prop)

                #print('mids_to_write = %s' % mids_to_write)
                #print('mids = ', model.materials.keys())
                imid = mids_to_write.index(mid)

                if nface == 3:
                    card = ['CTRIA3', eid_shell, pid_shell + imid
                            ] + list(face_raw)
                elif nface == 4:
                    card = ['CQUAD4', eid_shell, pid_shell + imid
                            ] + list(face_raw)
                elif nface == 4:
                    card = ['CQUAD4', eid_shell, pid_shell + imid
                            ] + list(face_raw)
                elif nface == 6:
                    card = ['CTRIA6', eid_shell, pid_shell + imid
                            ] + list(face_raw)
                elif nface == 8:
                    card = ['CQUAD8', eid_shell, pid_shell + imid
                            ] + list(face_raw)
                else:
                    raise NotImplementedError('face=%s len(face)=%s' %
                                              (face, nface))
                try:
                    msg = print_card_8(card)
                except RuntimeError:
                    msg = print_card_16(card)
                bdf_file.write(msg)
                eid_shell += 1

                #elem = model.elements[eid]
                #bdf_file.write(elem.write_card(size=size))
            #for pid, prop in model.properties.items():
            #bdf_file.write(prop.write_card(size=size, is_double=is_double))
        bdf_file.write('ENDDATA\n')
Ejemplo n.º 42
0
 def write_card(self, bdf_file, size=8):
     card = self._repr_fields()
     if size == 8:
         bdf_file.write(print_card_8(card))
     else:
         bdf_file.write(print_card_16(card))
Ejemplo n.º 43
0
 def write_card(self, size=8, is_double=False):
     card = self.repr_fields()
     if size == 8:
         return self.comment + print_card_8(card)
     return self.comment + print_card_16(card)