예제 #1
0
def assert_fields(card1, card2):
    try:
        fields1 = wipeEmptyFields(card1.reprFields())
        fields2 = wipeEmptyFields(card2.reprFields())
    except:
        print("card1 = \n%s" % (card1))
        print("card2 = \n%s" % (card2))
        raise

    if len(fields1) != len(fields2):
        msg = ('len(fields1)=%s len(fields2)=%s\n%r\n%r\n%s\n%s' %
               (len(fields1), len(fields2), fields1, fields2,
                printCard(fields1), printCard(fields2)))
        raise RuntimeError(msg)

    for (i, field1, field2) in izip(count(), fields1, fields2):
        value1 = print_field(field1)
        value2 = print_field(field2)
        if value1 != value2:
            msg = 'value1 != value2\n'
            msg += ('cardName=%s ID=%s i=%s field1=%r field2=%r value1=%r '
                    'value2=%r\n%r\n%r' %
                    (fields1[0], fields1[1], i, field1, field2, value1, value2,
                     fields1, fields2))
            raise RuntimeError(msg)
예제 #2
0
def assert_fields(card1, card2):
    try:
        fields1 = wipeEmptyFields(card1.reprFields())
        fields2 = wipeEmptyFields(card2.reprFields())
    except:
        print("card1 = \n%s" % (card1))
        print("card2 = \n%s" % (card2))
        raise

    if len(fields1) != len(fields2):
        msg = ('len(fields1)=%s len(fields2)=%s\n%r\n%r\n%s\n%s'
               % (len(fields1), len(fields2), fields1, fields2,
                  printCard(fields1), printCard(fields2)))
        raise RuntimeError(msg)

    for (i, field1, field2) in izip(count(), fields1, fields2):
        value1 = print_field(field1)
        value2 = print_field(field2)
        if value1 != value2:
            msg = 'value1 != value2\n'
            msg += ('cardName=%s ID=%s i=%s field1=%r field2=%r value1=%r '
                    'value2=%r\n%r\n%r' % (fields1[0], fields1[1], i,
                                           field1, field2, value1, value2,
                                           fields1, fields2))
            raise RuntimeError(msg)
예제 #3
0
    def write_rejects(self):
        """
        writes the rejected (processed) cards and the rejected unprocessed
        cardLines
        """
        msg = ""
        if self.reject_cards:
            msg += "$REJECTS\n"
            for reject_card in self.reject_cards:
                try:
                    msg += printCard(reject_card)
                except RuntimeError:
                    for field in reject_card:
                        if field is not None and "=" in field:
                            raise SyntaxError("cannot reject equal signed " "cards\ncard=%s\n" % (reject_card))
                    raise

        if self.rejects:
            msg += "$REJECT_LINES\n"
        for reject_lines in self.rejects:
            if reject_lines[0][0] == " ":
                continue
            else:
                for reject in reject_lines:
                    reject2 = reject.rstrip()
                    if reject2:
                        msg += str(reject2) + "\n"
        return msg
예제 #4
0
    def write_rejects(self):
        """
        writes the rejected (processed) cards and the rejected unprocessed
        cardLines
        """
        msg = ''
        if self.reject_cards:
            msg += '$REJECTS\n'
            for reject_card in self.reject_cards:
                try:
                    msg += printCard(reject_card)
                except RuntimeError:
                    for field in reject_card:
                        if field is not None and '=' in field:
                            raise SyntaxError('cannot reject equal signed '
                                              'cards\ncard=%s\n' %
                                              (reject_card))
                    raise

        if self.rejects:
            msg += '$REJECT_LINES\n'
        for reject_lines in self.rejects:
            if reject_lines[0][0] == ' ':
                continue
            else:
                for reject in reject_lines:
                    reject2 = reject.rstrip()
                    if reject2:
                        msg += str(reject2) + '\n'
        return msg
예제 #5
0
    def exportToNastran(self, fname, points, elements, regions):
        from pyNastran.bdf.fieldWriter import printCard

        f = open(fname, 'wb')
        for nid, grid in enumerate(1, points):
            (x, y, z) = grid
            f.write(printCard(['GRID', nid, '', x, y, z]))
        ###

        e = 1e7
        nu = 0.3
        g = ''
        thickness = 0.25
        setRegions = list(set(regions))
        for pidMid in setRegions:
            f.write(printCard(['MAT1', pidMid, e, g, nu]))
            f.write(printCard(['PSHELL', pidMid, pidMid, thickness]))
        ###

        for eid, (nodes, region) in enumerate(1, izip(elements, regions)):
            (n1, n2, n3) = nodes
            f.write(printCard(['CTRIA3', eid, region, n1, n2, n3]))
        ###
        f.close()
예제 #6
0
    def createPlane(self, width, height, nx, ny, eidStart):
        """
        Creates a quadrilateral plane made of CTRIA3s.  This output
        can be intersected with another geometry.
        @param width width of plane
        @param height height of plane
        @param nx number of elements along the width
        @param ny number of elements along the height
        @param eidStart the starting elementID

        1-----2
        | \ B |
        | A \ |
        4-----3
        """
        assert nx > 0
        assert ny > 0
        dx = width / nx
        dy = height / ny

        nidStart = 200
        n = nidStart
        #x=[]; y=[]
        ij_NMap = {}
        points = {}
        for j in xrange(ny + 1):
            yi = dy * j
            for i in xrange(nx + 1):
                xi = dx * i
                points[n] = array([xi, yi, 0.])
                ij_NMap[(i, j)] = n
                n += 1

        elements = []
        for j in xrange(ny):
            for i in xrange(nx):
                element = [ij_NMap[(i, j)],
                           ij_NMap[(i + 1, j)],
                           ij_NMap[(i + 1, j + 1)], ]
                elements.append(element)
                element = [ij_NMap[(i, j)],
                           ij_NMap[(i + 1, j + 1)],
                           ij_NMap[(i, j + 1)], ]
                elements.append(element)

        #origin = [width/2,height/2,0.]
        origin = [0., 0., -1.]
        zAxis = array([0., 1., 0.])
        xAxis = array([1., 0., 0.])

        f = open('plane.bdf', 'wb')
        #f.write('SOL 101\n')
        #f.write('CEND\n')
        #f.write('BEGIN BULK\n')

        cid = 200
        rid = 0
        coord = ['CORD2R', cid, rid, origin[0], origin[1], origin[2],
                 zAxis[0], zAxis[1], zAxis[2],
                 xAxis[0], xAxis[1], xAxis[2]]
        f.write(printCard(coord))
        for nid, point in sorted(points.iteritems()):
            (x, y, z) = point
            node = ['GRID', nid, cid, x, y, z]
            f.write(printCard(node))

        pid = 123
        mid = pid
        eidStart = 200
        for eid, element in enumerate(elements):
            (n1, n2, n3) = element
            tri = ['CTRIA3', eid + eidStart, pid, n1, n2, n3]
            f.write(printCard(tri))

        shell = ['PSHELL', pid, mid, 1.0]
        f.write(printCard(shell))
        mat = ['MAT1', mid, 1e7, None, 0.3]
        f.write(printCard(mat))
        #f.write('ENDDATA\n')
        f.close()
        return points, elements
예제 #7
0
 def printCard(self, fields, tol=0.):
     """prints a card object"""
     return printCard(fields, tol)
예제 #8
0
    def createPlane(self, width, height, nx, ny, eidStart):
        """
        Creates a quadrilateral plane made of CTRIA3s.  This output
        can be intersected with another geometry.
        @param width width of plane
        @param height height of plane
        @param nx number of elements along the width
        @param ny number of elements along the height
        @param eidStart the starting elementID

        1-----2
        | \ B |
        | A \ |
        4-----3
        """
        assert nx > 0
        assert ny > 0
        dx = width / nx
        dy = height / ny

        nidStart = 200
        n = nidStart
        #x=[]; y=[]
        ij_NMap = {}
        points = {}
        for j in xrange(ny + 1):
            yi = dy * j
            for i in xrange(nx + 1):
                xi = dx * i
                points[n] = array([xi, yi, 0.])
                ij_NMap[(i, j)] = n
                n += 1

        elements = []
        for j in xrange(ny):
            for i in xrange(nx):
                element = [
                    ij_NMap[(i, j)],
                    ij_NMap[(i + 1, j)],
                    ij_NMap[(i + 1, j + 1)],
                ]
                elements.append(element)
                element = [
                    ij_NMap[(i, j)],
                    ij_NMap[(i + 1, j + 1)],
                    ij_NMap[(i, j + 1)],
                ]
                elements.append(element)

        #origin = [width/2,height/2,0.]
        origin = [0., 0., -1.]
        zAxis = array([0., 1., 0.])
        xAxis = array([1., 0., 0.])

        f = open('plane.bdf', 'wb')
        #f.write('SOL 101\n')
        #f.write('CEND\n')
        #f.write('BEGIN BULK\n')

        cid = 200
        rid = 0
        coord = [
            'CORD2R', cid, rid, origin[0], origin[1], origin[2], zAxis[0],
            zAxis[1], zAxis[2], xAxis[0], xAxis[1], xAxis[2]
        ]
        f.write(printCard(coord))
        for nid, point in sorted(points.iteritems()):
            (x, y, z) = point
            node = ['GRID', nid, cid, x, y, z]
            f.write(printCard(node))

        pid = 123
        mid = pid
        eidStart = 200
        for eid, element in enumerate(elements):
            (n1, n2, n3) = element
            tri = ['CTRIA3', eid + eidStart, pid, n1, n2, n3]
            f.write(printCard(tri))

        shell = ['PSHELL', pid, mid, 1.0]
        f.write(printCard(shell))
        mat = ['MAT1', mid, 1e7, None, 0.3]
        f.write(printCard(mat))
        #f.write('ENDDATA\n')
        f.close()
        return points, elements
예제 #9
0
 def printCard(self, fields, tol=0.):
     """prints a card object"""
     return printCard(fields, tol)