Ejemplo n.º 1
0
    def test_list_print(self):
        self.assertEqual(list_print(None), 'None')
        #self.assertRaises(TypeError, lambda: list_print(None))

        for a, b in [([], '[]'), (array([]), '[]'), (tuple(), '[]'),
                     (matrix([]), '[[]]')]:
            self.assertEqual(list_print(a), b)
        r = ('[[1         ,2         ,3         ],\n [4         ,5         ,6'
             '         ],\n [7         ,8         ,9         ]]')
        self.assertEqual(list_print(array([(1, 2, 3), (4, 5, 6), (7, 8, 9)])),
                         r)
        self.assertEqual(list_print(matrix([(1, 2, 3), (4, 5, 6), (7, 8, 9)])),
                         r)
        self.assertEqual(
            list_print(array([(1.0, 2, 3.), (4., 5., 6), (7.0, 8, 9)])), r)
        self.assertEqual(
            list_print(matrix([(1, 2, 3.0), (4, 5.0, 6), (7., 8, 9.0)])), r)

        r = "[[1.1       ,2.234     ,3.00001   ],\n [4.001     ,5         ,6.2       ]]"
        self.assertEqual(
            list_print(array([(1.1, 2.234, 3.00001),
                              (4.001, 5.0000005, 6.2)])), r)
        self.assertEqual(
            list_print(matrix([(1.1, 2.234, 3.00001),
                               (4.001, 5.0000005, 6.2)])), r)

        self.assertEqual(list_print(['a', None, 11, '']), '[a, None, 11, ]')
        self.assertEqual(list_print(('a', None, 11, '')), '[a, None, 11, ]')
Ejemplo n.º 2
0
    def __init__(self, xy, nrepeated, isData=False):
        """
        :param self: the Table Object
        :param xy:   the X/Y data with an ENDT appended
        :param nrepeated: ???
        :param isData:     did this come from the OP2/BDF (True -> OP2)
        """
        self.table = []
        xy = self._cleanup_xy(xy, isData)

        nxy = len(xy)

        if not isData:
            if nxy % nrepeated != 0:
                self._crash_fields(xy, nrepeated, nxy)
            if nxy % nrepeated != 0:
                msg = 'invalid table length nrepeat=%s xy=%s' % (
                    nrepeated, list_print(xy))
                raise RuntimeError(msg)

        i = 0
        while i < nxy:
            pack = []
            for j in range(nrepeated):
                pack.append(xy[i + j])
            i += nrepeated
            self.table.append(pack)
Ejemplo n.º 3
0
    def __init__(self, xy, nrepeated, isData=False):
        """
        :param self: the Table Object
        :param xy:   the X/Y data with an ENDT appended
        :param nrepeated: ???
        :param isData:     did this come from the OP2/BDF (True -> OP2)
        """
        self.table = []
        xy = self._cleanup_xy(xy, isData)

        nxy = len(xy)

        if not isData:
            if nxy % nrepeated != 0:
                self._crash_fields(xy, nrepeated, nxy)
            if nxy % nrepeated != 0:
                msg = 'invalid table length nrepeat=%s xy=%s' % (
                    nrepeated, list_print(xy))
                raise RuntimeError(msg)

        i = 0
        while i < nxy:
            pack = []
            for j in range(nrepeated):
                pack.append(xy[i + j])
            i += nrepeated
            self.table.append(pack)
Ejemplo n.º 4
0
def buildGlobalStiffness(model):
    nodeIDs = model.nodeIDs()
    nDOFperNode = 2

    Dofs = {}
    nDOF = 0
    for nodeID in nodeIDs:
        Dofs[nodeID] = [nDOF, nDOF + 1, nDOF + 2]
        nDOF += 3

    nElements = model.nElements()
    Kg = matrix(zeros((nDOF, nDOF), 'd'))  # K_global

    for id, element in sorted(model.elements.iteritems()):
        #nodes = element.nodes
        print element
        Ke = element.Stiffness(model)
        #print "K_element[%s] = \n%s\n" %(id,Ke)

        nodes = element.nodeIDs()
        print "nodes = ", nodes

        dofs = []
        for i, iNode in enumerate(nodes):
            dofs += Dofs[iNode]
        print "allDOFs = ", dofs

        # put in global stiffness matrix
        for j, dof in enumerate(dofs):
            print "nid=%s dofs=%s" % (iNode, dof)
            for k, dof2 in enumerate(dofs):
                print "Kg[%s][%s] = Ke[%s][%s] = %s" % (dof, dof2, j, k, Ke[j,
                                                                            k])
                #print "Kg[%s][%s] = Ke[%s][%s] = %s" %(dof2,dof, k,j,Ke[k,j])
                #print "Kg[%s][%s] = Ke[%s][%s] = %s" %(dof2,dof2,k,k,Ke[k,k])
                #print "Kg[%s][%s] = Ke[%s][%s] = %s" %(dof, dof, j,j,Ke[j,j])
                Kg[dof, dof2] += Ke[j, k]
                #Kg[dof2,dof ] += Ke[k,j]
                #Kg[dof2,dof2] += Ke[k,k]
                #Kg[dof ,dof ] += Ke[j,j]

        print "K_global =\n", list_print(Kg)
    print "K_global =\n", list_print(Kg)
    #print "K_global = \n",Kg
    return Kg, Dofs
Ejemplo n.º 5
0
 def get_data_code(self):
     msg = []
     for name in self.data_code['dataNames']:
         try:
             if hasattr(self, name + 's'):
                 vals = getattr(self, name + 's')
                 name = name + 's'
             else:
                 vals = getattr(self, name)
             msg.append('  %s = %s\n' % (name, list_print(vals)))
         except AttributeError:  # weird case...
             pass
     return msg
Ejemplo n.º 6
0
 def get_data_code(self):
     msg = []
     for name in self.data_code['dataNames']:
         try:
             if hasattr(self, name + 's'):
                 vals = getattr(self, name + 's')
                 name = name + 's'
             else:
                 vals = getattr(self, name)
             msg.append('  %s = %s\n' % (name, list_print(vals)))
         except AttributeError:  # weird case...
             pass
     return msg
Ejemplo n.º 7
0
def applyBoundaryConditions(model, Kg):
    nids = []
    allNodes = []
    for (eid, element) in model.elements.iteritems():
        nodes = element.nodeIDs()
        allNodes += nodes
        for nid in nodes:
            node = model.Node(nid)
            BCs = str(node.ps)
            if '1' in BCs:
                Kg = setRow(Kg, nid - 1, 0.)
                Kg = setCol(Kg, nid - 1, 0.)
            else:
                nids.append(nid - 1)

    notNids = [nid - 1 for nid in allNodes if nid not in nids]
    #print "notNids =\n",notNids
    print "nids = ", nids
    print "Kg2 =\n", list_print(Kg)
    Kr = reduce_matrix(Kg, nids)
    #Kr = reduce_matrix(Kg,notNids)
    print "Kreduced =\n", list_print(Kr)
    return Kr
Ejemplo n.º 8
0
    def transformToGlobal(self, p, resolveAltCoord=True, debug=False):
        r"""
        Transforms a point from the local coordinate system to the reference
        coordinate frames "global" coordinate system.

        .. math::
            [p_{global}]_{1\times 3} =
            [p_{local} -p_{origin}]_{1\times 3}[\beta_{ij}]_{3\times 3}

        where :math:`[\beta]_{ij}` is the transformation matrix

        .. math::
          [\beta]_{ij} = \left[
          \begin{array}{ccc}
              g_x \cdot i  &  g_x \cdot j  &  g_x \cdot k    \\
              g_y \cdot i  &  g_y \cdot j  &  g_y \cdot k    \\
              g_z \cdot i  &  g_z \cdot j  &  g_z \cdot k
          \end{array} \right]
        

        * :math:`g` is the global directional vector (e.g. :math:`g_x = [1,0,0]`)
        * :math:`ijk` is the math:`i^{th}` direction in the local coordinate system

        :param self:            the coordinate system object
        :param p:               the point to be transformed.  Type=NUMPY.NDARRAY
        :param resolveAltCoord: should the CD field be resolved (default=True)
        :param debug:           developer debug (default=False)

        .. warning:: make sure you cross-reference before calling this
        .. warning:: you probably shouldnt call this, call the Node methods
                     Position and PositionWRT
        """
        if debug:
            print("p = %s" % p)
            print("p-e1 = %s" % (p - self.e1))

        if not self.isResolved:
            self.resolveCid()
        if self.cid == 0:
            return p, array([[1., 0., 0.],
                             [0., 1., 0.],
                             [0., 0., 1.]])

        # the ijk axes arent resolved as R-theta-z, only points
        if resolveAltCoord:
            #print("p* = %s" % p)
            p = self.coordToXYZ(p)
        #p2 = p-self.eo

        # Bij = Bip*j
        i = self.i
        j = self.j
        k = self.k
        if isinstance(self.rid, int):  # rid=0
            gx = array([1., 0., 0.])
            gy = array([0., 1., 0.])
            gz = array([0., 0., 1.])
        else:
            gx = self.rid.i
            gy = self.rid.j
            gz = self.rid.k

        matrix = array([[dot(gx, i), dot(gy, i), dot(gz, i)],
                        [dot(gx, j), dot(gy, j), dot(gz, j)],
                        [dot(gx, k), dot(gy, k), dot(gz, k)]])
        p2 = dot(p - self.e1, matrix)
        p3 = p2 + self.e1

        if debug:
            print("Cp = ", self.Cid())
            print("gx = %s" % (gx))
            print("gy = %s" % (gy))
            print("gz = %s" % (gz))
            print("p = %s" % (list_print(p)))
            print("matrix = \n", matrix)
            print("e1 = %s" % (list_print(self.e1)))
            print("p2 = %s" % (list_print(p2)))
            print('------------------------')
            print("p3 = %s\n" % (list_print(p3)))

        if isinstance(self.rid, int):
            return (p3, matrix)
        else:
            #: .. todo:: do i need to multiply rid.transform(p3)[1]*matrix
            return (self.rid.transformToGlobal(p3)[0], matrix)