Example #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)]),
                       float_fmt='%-10g'), r)
        self.assertEqual(
            list_print(matrix([(1, 2, 3), (4, 5, 6), (7, 8, 9)]),
                       float_fmt='%-10g'), r)
        self.assertEqual(
            list_print(array([(1.0, 2, 3.), (4., 5., 6), (7.0, 8, 9)]),
                       float_fmt='%-10g'), r)
        self.assertEqual(
            list_print(matrix([(1, 2, 3.0), (4, 5.0, 6), (7., 8, 9.0)]),
                       float_fmt='%-10g'), 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)]),
                       float_fmt='%-10g'), r)
        self.assertEqual(
            list_print(matrix([(1.1, 2.234, 3.00001),
                               (4.001, 5.0000005, 6.2)]),
                       float_fmt='%-10g'), r)

        self.assertEqual(list_print(['a', None, 11, '']), '[a, None, 11, ]')
        self.assertEqual(list_print(('a', None, 11, '')), '[a, None, 11, ]')
Example #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)
Example #3
0
    def __init__(self, xy, nrepeated, is_data=False):
        """
        Parameters
        ----------
        xy : List[float/str]
            the X/Y data with an ENDT appended
        nrepeated : int
            ???
        is_data : bool
            did this come from the OP2/BDF (True -> OP2)
        """
        self.table = []
        xy = self._cleanup_xy(xy, is_data)

        nxy = len(xy)

        if not is_data:
            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)
Example #4
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)
Example #5
0
    def test_list_print(self):
        #self.b = B(7)
        """tests the list_print method, which is a nice way to write a 2d array"""
        self.assertEqual(list_print(None), 'None')
        #self.assertRaises(TypeError, lambda: list_print(None))

        for ai, bi in [([], '[]'), (np.array([]), '[]'), (tuple(), '[]')]:
            self.assertEqual(list_print(ai), bi)
        expected_array_str = (
            '[[1         ,2         ,3         ],\n'
            ' [4         ,5         ,6         ],\n'
            ' [7         ,8         ,9         ]]'
        )
        self.assertEqual(
            list_print(np.array([(1, 2, 3), (4, 5, 6), (7, 8, 9)]), float_fmt='%-10g'),
            expected_array_str)
        self.assertEqual(
            list_print(np.array([(1., 2, 3.), (4., 5., 6), (7., 8, 9)]), float_fmt='%-10g'),
            expected_array_str)

        expected_array_str = (
            '[[1.1       ,2.234     ,3.00001   ],\n'
            ' [4.001     ,5         ,6.2       ]]'
        )
        self.assertEqual(
            list_print(np.array([(1.1, 2.234, 3.00001), (4.001, 5.0000005, 6.2)]), float_fmt='%-10g'),
            expected_array_str)

        self.assertEqual(list_print(['a', None, 11, '']), '[a, None, 11, ]')
        self.assertEqual(list_print(('a', None, 11, '')), '[a, None, 11, ]')
Example #6
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)]), float_fmt='%-10g'), r)
        self.assertEqual(list_print(matrix([(1,2,3),(4,5,6),(7,8,9)]), float_fmt='%-10g'), r)
        self.assertEqual(list_print(array([(1.0,2,3.),(4.,5.,6),(7.0,8,9)]), float_fmt='%-10g'), r)
        self.assertEqual(list_print(matrix([(1,2,3.0),(4,5.0,6),(7.,8,9.0)]), float_fmt='%-10g'), 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)]), float_fmt='%-10g'), r)
        self.assertEqual(list_print(matrix([(1.1,2.234,3.00001),(4.001,5.0000005,6.2)]), float_fmt='%-10g'), r)

        self.assertEqual(list_print(['a',None,11,'']), '[a, None, 11, ]')
        self.assertEqual(list_print(('a',None,11,'')), '[a, None, 11, ]')
Example #7
0
    def test_list_print(self):
        # self.b = B(7)
        """tests the list_print method, which is a nice way to write a 2d matrix"""
        self.assertEqual(list_print(None), "None")
        # self.assertRaises(TypeError, lambda: list_print(None))

        for ai, bi in [([], "[]"), (np.array([]), "[]"), (tuple(), "[]"), (np.matrix([]), "[[]]")]:
            self.assertEqual(list_print(ai), bi)
        r = (
            "[[1         ,2         ,3         ],\n"
            " [4         ,5         ,6         ],\n"
            " [7         ,8         ,9         ]]"
        )
        self.assertEqual(list_print(np.array([(1, 2, 3), (4, 5, 6), (7, 8, 9)]), float_fmt="%-10g"), r)
        self.assertEqual(list_print(np.matrix([(1, 2, 3), (4, 5, 6), (7, 8, 9)]), float_fmt="%-10g"), r)
        self.assertEqual(list_print(np.array([(1.0, 2, 3.0), (4.0, 5.0, 6), (7.0, 8, 9)]), float_fmt="%-10g"), r)
        self.assertEqual(list_print(np.matrix([(1, 2, 3.0), (4, 5.0, 6), (7.0, 8, 9.0)]), float_fmt="%-10g"), r)

        r = "[[1.1       ,2.234     ,3.00001   ],\n [4.001     ,5         ,6.2       ]]"
        self.assertEqual(list_print(np.array([(1.1, 2.234, 3.00001), (4.001, 5.0000005, 6.2)]), float_fmt="%-10g"), r)
        self.assertEqual(list_print(np.matrix([(1.1, 2.234, 3.00001), (4.001, 5.0000005, 6.2)]), float_fmt="%-10g"), r)

        self.assertEqual(list_print(["a", None, 11, ""]), "[a, None, 11, ]")
        self.assertEqual(list_print(("a", None, 11, "")), "[a, None, 11, ]")
Example #8
0
    def get_stiffness_matrix(self, i, model, positions, index0s, knorm=1.0):
        #print("----------------")
        pid = self.property_id[i]
        assert isinstance(pid, int), pid
        A = self.get_area_by_element_id(pid)
        E = self.get_E_by_element_id(pid)
        G = self.get_G_by_element_id(pid)
        J = self.get_J_by_element_id(pid)
        #print('A=%s E=%s G=%s J=%s' % (A, E, G, J))

        #========================
        #(n1, n2) = self.node_ids()
        n1 = self.node_ids[i, 0]
        n2 = self.node_ids[i, 1]

        i1 = index0s[n1]
        i2 = index0s[n2]

        #print("n0", n0)
        #print("n1", n1)
        n1 = positions[n1]
        n2 = positions[n2]
        #p1 = model.Node(n1).xyz

        v1 = n1 - n2
        L = norm(v1)
        if L == 0.0:
            msg = 'invalid CROD length=0.0\n%s' % (self.__repr__())
            raise ZeroDivisionError(msg)
        #========================
        #print("A=%g E=%g G=%g J=%g L=%g" % (A, E, G, J, L))
        k_axial = A * E / L
        k_torsion = G * J / L
        #k_axial = 1.0
        #k_torsion = 2.0

        k = array([[1., -1.], [-1., 1.]])  # 1D rod

        Lambda = _Lambda(v1, debug=True)
        K = dot(dot(transpose(Lambda), k), Lambda)
        Ki, Kj = K.shape

        # for testing
        #K = ones((Ki, Ki), 'float64')

        K2 = zeros((Ki * 2, Kj * 2), 'float64')
        if k_axial == 0.0 and k_torsion == 0.0:
            dofs = []
            n_ijv = []
            K2 = []
        elif k_torsion == 0.0:  # axial; 2D or 3D
            K2 = K * k_axial
            dofs = array([
                i1,
                i1 + 1,
                i1 + 2,
                i2,
                i2 + 1,
                i2 + 2,
            ], 'int32')
            n_ijv = [
                # axial
                (n1, 1),
                (n1, 2),
                (n1, 3),
                (n2, 1),
                (n2, 2),
                (n2, 3),
            ]
        elif k_axial == 0.0:  # torsion; assume 3D
            K2 = K * k_torsion
            dofs = array([
                i1 + 3,
                i1 + 4,
                i1 + 5,
                i2 + 3,
                i2 + 4,
                i2 + 5,
            ], 'int32')
            n_ijv = [
                # torsion
                (n1, 4),
                (n1, 5),
                (n2, 6),
                (n2, 4),
                (n2, 5),
                (n1, 6),
            ]

        else:  # axial + torsion; assume 3D
            # u1fx, u1fy, u1fz, u2fx, u2fy, u2fz
            K2[:Ki, :Ki] = K * k_axial

            # u1mx, u1my, u1mz, u2mx, u2my, u2mz
            K2[Ki:, Ki:] = K * k_torsion

            dofs = array([
                i1,
                i1 + 1,
                i1 + 2,
                i2,
                i2 + 1,
                i2 + 2,
                i1 + 3,
                i1 + 4,
                i1 + 5,
                i2 + 3,
                i2 + 4,
                i2 + 5,
            ], 'int32')
            n_ijv = [
                # axial
                (n1, 1),
                (n1, 2),
                (n1, 3),
                (n2, 1),
                (n2, 2),
                (n2, 3),

                # torsion
                (n1, 4),
                (n1, 5),
                (n1, 6),
                (n2, 4),
                (n2, 5),
                (n2, 6),
            ]

        #Fg = dot(dot(transpose(Lambda), grav), Lambda)
        #print("K=\n", K / knorm)
        #print("K2=\n", K2 / knorm)

        #========================

        #print(K / knorm)
        #print("K[%s] = \n%s\n" % (self.eid, list_print(K/knorm)))

        self.model.log.info('dofs = %s' % dofs)
        self.model.log.info('K =\n%s' % list_print(K / knorm))

        return (K2, dofs, n_ijv)
Example #9
0
    def get_stiffness_matrix(self, i, model, positions, index0s, knorm=1.0):
        # print("----------------")
        pid = self.property_id[i]
        assert isinstance(pid, int), pid
        element_id = self.element_id[i]
        i = self.get_element_index_by_element_id(element_id)
        A = self.get_area_by_element_index(i)
        G = self.model.prod.get_G_by_property_id(pid)
        E = self.model.prod.get_E_by_property_id(pid)
        J = self.model.prod.get_J_by_property_id(pid)
        # A = self.get_area_by_element_id(pid)
        # E = self.get_E_by_element_id(pid)
        # G = self.get_G_by_element_id(pid)
        # J = self.get_J_by_element_id(pid)
        # print('A=%s E=%s G=%s J=%s' % (A, E, G, J))

        # ========================
        # (n1, n2) = self.node_ids()
        i = np.asarray(i)
        nids = self.node_ids[i, :]
        n1, n2 = nids.squeeze()

        i1 = index0s[n1]
        i2 = index0s[n2]

        xyz1 = positions[n1]
        xyz2 = positions[n2]
        # p1 = model.Node(n1).xyz

        dxyz12 = xyz1 - xyz2
        L = norm(dxyz12)
        if L == 0.0:
            msg = "invalid CROD length=0.0\n%s" % (self.__repr__())
            raise ZeroDivisionError(msg)
        # ========================
        # print("A=%g E=%g G=%g J=%g L=%g" % (A, E, G, J, L))
        k_axial = A * E / L
        k_torsion = G * J / L
        # k_axial = 1.0
        # k_torsion = 2.0

        k = array([[1.0, -1.0], [-1.0, 1.0]])  # 1D rod

        Lambda = _Lambda(dxyz12, debug=False)
        K = dot(dot(transpose(Lambda), k), Lambda)
        Ki, Kj = K.shape

        K2 = zeros((Ki * 2, Kj * 2), "float64")
        if k_axial == 0.0 and k_torsion == 0.0:
            dofs = []
            n_ijv = []
            K2 = []
        elif k_torsion == 0.0:  # axial; 2D or 3D
            K2 = K * k_axial
            dofs = array([i1, i1 + 1, i1 + 2, i2, i2 + 1, i2 + 2], "int32")
            n_ijv = [
                # axial
                (n1, 1),
                (n1, 2),
                (n1, 3),
                (n2, 1),
                (n2, 2),
                (n2, 3),
            ]
        elif k_axial == 0.0:  # torsion; assume 3D
            K2 = K * k_torsion
            dofs = array([i1 + 3, i1 + 4, i1 + 5, i2 + 3, i2 + 4, i2 + 5], "int32")
            n_ijv = [
                # torsion
                (n1, 4),
                (n1, 5),
                (n1, 6),
                (n2, 4),
                (n2, 5),
                (n2, 6),
            ]

        else:  # axial + torsion; assume 3D
            # u1fx, u1fy, u1fz, u2fx, u2fy, u2fz
            K2[:Ki, :Ki] = K * k_axial

            # u1mx, u1my, u1mz, u2mx, u2my, u2mz
            K2[Ki:, Ki:] = K * k_torsion

            dofs = array(
                [i1, i1 + 1, i1 + 2, i2, i2 + 1, i2 + 2, i1 + 3, i1 + 4, i1 + 5, i2 + 3, i2 + 4, i2 + 5], "int32"
            )
            n_ijv = [
                # axial
                (n1, 1),
                (n1, 2),
                (n1, 3),
                (n2, 1),
                (n2, 2),
                (n2, 3),
                # torsion
                (n1, 4),
                (n1, 5),
                (n1, 6),
                (n2, 4),
                (n2, 5),
                (n2, 6),
            ]

        # Fg = dot(dot(transpose(Lambda), grav), Lambda)
        # print("K=\n", K / knorm)
        # print("K2=\n", K2 / knorm)

        # ========================

        # print(K / knorm)
        # print("K[%s] = \n%s\n" % (self.eid, list_print(K/knorm)))

        self.model.log.info("dofs = %s" % dofs)
        self.model.log.info("K =\n%s" % list_print(K / knorm))

        return (K2, dofs, n_ijv)
Example #10
0
    def get_stiffness_matrix(self, i, model, positions, index0s, knorm=1.0):  # CROD/CONROD
        """gets the stiffness matrix for CQUAD4/PSHELL"""
        area = self.get_area_by_element_index(i)
        #print('self.thickness =', self.thickness)
        #print('self.i =', i)

        n1, n2, n3, n4 = self.node_ids[i, :]
        pid = self.property_id[i]
        prop = self.model.properties_shell.get_property_by_property_id(pid)
        #prop.get_
        #print(prop)

        # TODO: nodal thickness not supported
        #thickness = self.thickness.flatten()[i]

        thickness = prop.thickness#.flatten()[i]
        #print('thickness =', thickness)

        mid1 = prop.material_id[0]
        mat = self.model.materials.get_shell_material(mid1)
        assert prop.material_id2[0] == -1, prop.material_id2
        assert prop.material_id3[0] == -1, prop.material_id3
        assert prop.material_id4[0] == -1, prop.material_id4
        #print(mat)
        E = mat.E[0]
        nu = mat.nu[0]
        #print('area=%s thickness=%s E=%e nu=%s' % (area, thickness, E, nu))
        #sdd
        i1 = index0s[n1]
        i2 = index0s[n2]
        i3 = index0s[n3]
        i4 = index0s[n4]

        xyz1 = positions[n1]
        xyz2 = positions[n2]
        xyz3 = positions[n3]
        xyz4 = positions[n4]
        xy = np.vstack([
            xyz1,
            xyz2,
            xyz3,
            xyz4,
        ])[:, :2]

        #print(xy)

        centroid = (xyz1 + xyz2 + xyz3 + xyz4) / 4.

        #normal = self.Normal()
        is_theta = self.is_theta[i]
        if is_theta:
            theta = self.theta[i]

            if theta != 0.0:
                self.model.log.debug(self.model.coords)
                mcid_ref = self.model.coords.get_coord_index_by_coord_id(0)
                #print('mcid_ref\n', mcid_ref)
                #assert self.theta == 0.0, self.theta
                raise NotImplementedError('theta=%r' % theta)
        else:
            mcid = self.mcid[i]
            #print(mcid)
            #print(self.model.coords)
            mcid_ref = self.model.coords.get_coord_index_by_coord_id(mcid)
            i = mcid_ref.i
            jmat = np.cross(normal, i) # k x i
            jmat /= np.linalg.norm(jmat)
            imat = np.cross(jmat, normal)
            T = np.vstack([imat, jmat, normal])
            self.model.log.debug(T)
        if 0:
            xyz = np.vstack([
                xyz1,
                xyz2,
                xyz3,
                xyz4,
            ]).dot(T)

        dofs = array([
            i1, i1+1,
            i2, i2+1,
            i3, i3+1,
            i4, i4+1,
        ], 'int32')

        n_ijv = [
            # axial
            (n1, 1), (n1, 2),
            (n2, 1), (n2, 2),
            (n3, 1), (n3, 2),
            (n4, 1), (n4, 2),
        ]

        #n1 = 0.25 * (1 - u) * (1 - v)
        #n2 = 0.25 * (1 + u) * (1 - v)
        #n3 = 0.25 * (1 + u) * (1 + v)
        #n4 = 0.25 * (1 - u) * (1 + v)
        #wti = -0.57735
        #wtj = -0.57735

        is_heat_transfer = False
        if is_heat_transfer:
            u = wti
            v = wtj
            Ji = array([
                [v - 1.0, -v + 1.0, v + 1.0, -v - 1.0],
                [u - 1.0, -u - 1.0, u + 1.0, -u + 1.0],
            ]) / 4.
            J = Ji.dot(xy)
            Jinv = np.linalg.inv(J)
            detJ = np.linalg.det(J)
            darea = detJ
            #print('Ji*4 =\n', Ji*4.)
            #print('J =\n', J)
            #print('Jinv =\n', Jinv)

            #B2 = array([
                #[-1.0 - wti, 1.0 - wti, 1.0 - wti, -1.0 + wti],
                #[-1.0 - wtj, -1.0 + wtj, 1.0 - wtj, 1.0 + wtj],
            #])
            #print('B2 =\n', B2)
            #B = B2.dot(xy)
            B = Jinv.dot(Ji)
            #print('B =\n', B)
            k = 1. * darea
            #print('dA =', darea)

            K = k * B.T.dot(B)
            #print('K =\n', K)
        else:
            K = np.zeros((8, 8), dtype='float64')
            #u = wti
            #v = wtj
            wts = [-0.57735, 0.57735]
            for u in wts:
                for v in wts:
                    Ji = array([
                        [v - 1.0, -v + 1.0, v + 1.0, -v - 1.0],
                        [u - 1.0, -u - 1.0, u + 1.0, -u + 1.0],
                    ]) / 4.
                    J = Ji.dot(xy)
                    Jinv = np.linalg.inv(J)
                    det_j = np.linalg.det(J)
                    darea = det_j


                    B1 = Jinv.dot(Ji)
                    #print('B1 =\n', B1)
                    N1x, N2x, N3x, N4x = B1[0, :]
                    N1y, N2y, N3y, N4y = B1[1, :]
                    #print('Nix =', B1[0, :])


                    #N1x, N2x, N3x, N4x = v - 1.0, -v + 1.0, v + 1.0, -v - 1.0
                    #N1y, N2y, N3y, N4y = u - 1.0, -u - 1.0, u + 1.0, -u + 1.0
                    B = array([
                        [N1x, 0., N2x, 0., N3x, 0., N4x, 0.],
                        [0., N1y, 0., N2y, 0., N3y, 0., N4y],
                        [N1y, N1x, N2y, N2x, N3y, N3x, N4y, N4x]
                    ])
                    #print('B =\n', B)

                    #E = 1.0
                    #nu = 0.25
                    denom = 1 - nu**2
                    #C = E/(1 - (poisson^2))*[1 poisson 0; poisson 1 0;0 0 ((1-poisson)/2)];
                    C = np.array([
                        [E/denom, nu*E/denom, 0.],
                        [nu*E/denom, E/denom, 0.],
                        [0., 0., E/(2.0*(1.0+nu))],
                    ], dtype='float64')
                    #print('C =\n', C)
                    #print('thickness =', thickness)
                    Ki = np.dot(B.T, C.dot(B)) * (thickness * darea)
                    #print('Ki(%s,%s) =%s\n' % (u, v, Ki))
                    #print('Ki(%s,%s) =\n%s\n' % (u, v, list_print(Ki, '%.4e')))
                    K += Ki

        #K *= (thickness * darea)

        knorm = 1.0
        self.model.log.info("K_norm / %s = \n" % knorm + list_print(K / knorm, float_fmt='%-4.4f'))
        return(K, dofs, n_ijv)
Example #11
0
    def get_stiffness_matrix(self,
                             i,
                             model,
                             positions,
                             index0s,
                             knorm=1.0):  # CROD/CONROD
        """gets the stiffness matrix for CQUAD4/PSHELL"""
        area = self.get_area_by_element_index(i)
        #print('self.thickness =', self.thickness)
        #print('self.i =', i)

        n1, n2, n3, n4 = self.node_ids[i, :]
        pid = self.property_id[i]
        prop = self.model.properties_shell.get_property_by_property_id(pid)
        #prop.get_
        #print(prop)

        # TODO: nodal thickness not supported
        #thickness = self.thickness.flatten()[i]

        thickness = prop.thickness  #.flatten()[i]
        #print('thickness =', thickness)

        mid1 = prop.material_id[0]
        mat = self.model.materials.get_shell_material(mid1)
        assert prop.material_id2[0] == -1, prop.material_id2
        assert prop.material_id3[0] == -1, prop.material_id3
        assert prop.material_id4[0] == -1, prop.material_id4
        #print(mat)
        E = mat.E[0]
        nu = mat.nu[0]
        #print('area=%s thickness=%s E=%e nu=%s' % (area, thickness, E, nu))
        #sdd
        i1 = index0s[n1]
        i2 = index0s[n2]
        i3 = index0s[n3]
        i4 = index0s[n4]

        xyz1 = positions[n1]
        xyz2 = positions[n2]
        xyz3 = positions[n3]
        xyz4 = positions[n4]
        xy = np.vstack([
            xyz1,
            xyz2,
            xyz3,
            xyz4,
        ])[:, :2]

        #print(xy)

        centroid = (xyz1 + xyz2 + xyz3 + xyz4) / 4.

        #normal = self.Normal()
        is_theta = self.is_theta[i]
        if is_theta:
            theta = self.theta[i]

            if theta != 0.0:
                self.model.log.debug(self.model.coords)
                mcid_ref = self.model.coords.get_coord_index_by_coord_id(0)
                #print('mcid_ref\n', mcid_ref)
                #assert self.theta == 0.0, self.theta
                raise NotImplementedError('theta=%r' % theta)
        else:
            mcid = self.mcid[i]
            #print(mcid)
            #print(self.model.coords)
            mcid_ref = self.model.coords.get_coord_index_by_coord_id(mcid)
            i = mcid_ref.i
            jmat = np.cross(normal, i)  # k x i
            jmat /= np.linalg.norm(jmat)
            imat = np.cross(jmat, normal)
            T = np.vstack([imat, jmat, normal])
            self.model.log.debug(T)
        if 0:
            xyz = np.vstack([
                xyz1,
                xyz2,
                xyz3,
                xyz4,
            ]).dot(T)

        dofs = array([
            i1,
            i1 + 1,
            i2,
            i2 + 1,
            i3,
            i3 + 1,
            i4,
            i4 + 1,
        ], 'int32')

        n_ijv = [
            # axial
            (n1, 1),
            (n1, 2),
            (n2, 1),
            (n2, 2),
            (n3, 1),
            (n3, 2),
            (n4, 1),
            (n4, 2),
        ]

        #n1 = 0.25 * (1 - u) * (1 - v)
        #n2 = 0.25 * (1 + u) * (1 - v)
        #n3 = 0.25 * (1 + u) * (1 + v)
        #n4 = 0.25 * (1 - u) * (1 + v)
        #wti = -0.57735
        #wtj = -0.57735

        is_heat_transfer = False
        if is_heat_transfer:
            u = wti
            v = wtj
            Ji = array([
                [v - 1.0, -v + 1.0, v + 1.0, -v - 1.0],
                [u - 1.0, -u - 1.0, u + 1.0, -u + 1.0],
            ]) / 4.
            J = Ji.dot(xy)
            Jinv = np.linalg.inv(J)
            detJ = np.linalg.det(J)
            darea = detJ
            #print('Ji*4 =\n', Ji*4.)
            #print('J =\n', J)
            #print('Jinv =\n', Jinv)

            #B2 = array([
            #[-1.0 - wti, 1.0 - wti, 1.0 - wti, -1.0 + wti],
            #[-1.0 - wtj, -1.0 + wtj, 1.0 - wtj, 1.0 + wtj],
            #])
            #print('B2 =\n', B2)
            #B = B2.dot(xy)
            B = Jinv.dot(Ji)
            #print('B =\n', B)
            k = 1. * darea
            #print('dA =', darea)

            K = k * B.T.dot(B)
            #print('K =\n', K)
        else:
            K = np.zeros((8, 8), dtype='float64')
            #u = wti
            #v = wtj
            wts = [-0.57735, 0.57735]
            for u in wts:
                for v in wts:
                    Ji = array([
                        [v - 1.0, -v + 1.0, v + 1.0, -v - 1.0],
                        [u - 1.0, -u - 1.0, u + 1.0, -u + 1.0],
                    ]) / 4.
                    J = Ji.dot(xy)
                    Jinv = np.linalg.inv(J)
                    det_j = np.linalg.det(J)
                    darea = det_j

                    B1 = Jinv.dot(Ji)
                    #print('B1 =\n', B1)
                    N1x, N2x, N3x, N4x = B1[0, :]
                    N1y, N2y, N3y, N4y = B1[1, :]
                    #print('Nix =', B1[0, :])

                    #N1x, N2x, N3x, N4x = v - 1.0, -v + 1.0, v + 1.0, -v - 1.0
                    #N1y, N2y, N3y, N4y = u - 1.0, -u - 1.0, u + 1.0, -u + 1.0
                    B = array([[N1x, 0., N2x, 0., N3x, 0., N4x, 0.],
                               [0., N1y, 0., N2y, 0., N3y, 0., N4y],
                               [N1y, N1x, N2y, N2x, N3y, N3x, N4y, N4x]])
                    #print('B =\n', B)

                    #E = 1.0
                    #nu = 0.25
                    denom = 1 - nu**2
                    #C = E/(1 - (poisson^2))*[1 poisson 0; poisson 1 0;0 0 ((1-poisson)/2)];
                    C = np.array([
                        [E / denom, nu * E / denom, 0.],
                        [nu * E / denom, E / denom, 0.],
                        [0., 0., E / (2.0 * (1.0 + nu))],
                    ],
                                 dtype='float64')
                    #print('C =\n', C)
                    #print('thickness =', thickness)
                    Ki = (B.T @ C @ B) * (thickness * darea)
                    #print('Ki(%s,%s) =%s\n' % (u, v, Ki))
                    #print('Ki(%s,%s) =\n%s\n' % (u, v, list_print(Ki, '%.4e')))
                    K += Ki

        #K *= (thickness * darea)

        knorm = 1.0
        self.model.log.info("K_norm / %s = \n" % knorm +
                            list_print(K / knorm, float_fmt='%-4.4f'))
        return (K, dofs, n_ijv)
Example #12
0
    def Stiffness(self, model, node_ids, index0s, fnorm=1.0):  # CROD/CONROD
        #print("----------------")
        A = self.Area()
        E = self.E()
        G = self.G()
        J = self.J()

        #========================
        #(n1, n2) = self.nodeIDs()
        n0, n1 = self.nodeIDs()

        i0, i1 = index0s
        node0 = self.nodes[0]
        node1 = self.nodes[1]

        p0 = model.Node(n0).xyz
        p1 = model.Node(n1).xyz
        L = norm(p0 - p1)
        if L == 0.0:
            msg = 'invalid CROD length=0.0\n%s' % (self.__repr__())
            raise ZeroDivisionError(msg)
        #========================
        print("A=%g E=%g G=%g J=%g L=%g" % (A, E, G, J, L))
        k_axial = A * E / L
        k_torsion = G * J / L
        #k_axial = 1.0
        #k_torsion = 2.0

        k = matrix([[1., -1.], [-1., 1.]])  # 1D rod

        Lambda = self.Lambda(model)
        K = dot(dot(transpose(Lambda), k), Lambda)
        Ki, Kj = K.shape

        # for testing
        #K = ones((Ki, Ki), 'float64')

        K2 = zeros((Ki * 2, Kj * 2), 'float64')
        if k_axial == 0.0 and k_torsion == 0.0:
            dofs = []
            nIJV = []
            K2 = []
        elif k_torsion == 0.0:  # axial; 2D or 3D
            K2 = K * k_axial
            dofs = array([
                i0,
                i0 + 1,
                i0 + 2,
                i1,
                i1 + 1,
                i1 + 2,
            ], 'int32')
            nIJV = [
                # axial
                (n0, 1),
                (n0, 2),
                (n0, 3),
                (n1, 1),
                (n1, 2),
                (n1, 3),
            ]
        elif k_axial == 0.0:  # torsion; assume 3D
            K2 = K * k_torsion
            dofs = array([
                i0 + 3,
                i0 + 4,
                i0 + 5,
                i1 + 3,
                i1 + 4,
                i1 + 5,
            ], 'int32')
            nIJV = [
                # torsion
                (n0, 4),
                (n0, 5),
                (n0, 6),
                (n1, 4),
                (n1, 5),
                (n1, 6),
            ]

        else:  # axial + torsion; assume 3D
            # u1fx, u1fy, u1fz, u2fx, u2fy, u2fz
            K2[:Ki, :Ki] = K * k_axial

            # u1mx, u1my, u1mz, u2mx, u2my, u2mz
            K2[Ki:, Ki:] = K * k_torsion

            dofs = array([
                i0,
                i0 + 1,
                i0 + 2,
                i1,
                i1 + 1,
                i1 + 2,
                i0 + 3,
                i0 + 4,
                i0 + 5,
                i1 + 3,
                i1 + 4,
                i1 + 5,
            ], 'int32')
            nIJV = [
                # axial
                (n0, 1),
                (n0, 2),
                (n0, 3),
                (n1, 1),
                (n1, 2),
                (n1, 3),

                # torsion
                (n0, 4),
                (n0, 5),
                (n0, 6),
                (n1, 4),
                (n1, 5),
                (n1, 6),
            ]

        #Fg = dot(dot(transpose(Lambda), grav), Lambda)
        #print("K=\n", K / fnorm)
        #print("K2=\n", K2 / fnorm)

        #========================

        #print(K / fnorm)
        #print("K[%s] = \n%s\n" % (self.eid, list_print(K/fnorm)))

        print('dofs =', dofs)
        print('K =\n', list_print(K / fnorm))

        return (K2, dofs, nIJV)
Example #13
0
    def get_stiffness_matrix(self, i, model, positions, index0s, knorm=1.0):
        #print("----------------")
        pid = self.property_id[i]
        assert isinstance(pid, int), pid
        A = self.get_area_by_element_id(pid)
        E = self.get_E_by_element_id(pid)
        G = self.get_G_by_element_id(pid)
        J = self.get_J_by_element_id(pid)
        #print('A=%s E=%s G=%s J=%s' % (A, E, G, J))

        #========================
        #(n1, n2) = self.node_ids()
        n1 = self.node_ids[i, 0]
        n2 = self.node_ids[i, 1]

        i1 = index0s[n1]
        i2 = index0s[n2]

        #print("n0", n0)
        #print("n1", n1)
        n1 = positions[n1]
        n2 = positions[n2]
        #p1 = model.Node(n1).xyz

        v1 = n1 - n2
        L = norm(v1)
        if L == 0.0:
            msg = 'invalid CROD length=0.0\n%s' % (self.__repr__())
            raise ZeroDivisionError(msg)
        #========================
        #print("A=%g E=%g G=%g J=%g L=%g" % (A, E, G, J, L))
        k_axial = A * E / L
        k_torsion = G * J / L
        #k_axial = 1.0
        #k_torsion = 2.0

        k = array([[1., -1.],
                   [-1., 1.]])  # 1D rod

        Lambda = _Lambda(v1, debug=True)
        K = dot(dot(transpose(Lambda), k), Lambda)
        Ki, Kj = K.shape

        # for testing
        #K = ones((Ki, Ki), 'float64')

        K2 = zeros((Ki*2, Kj*2), 'float64')
        if k_axial == 0.0 and k_torsion == 0.0:
            dofs = []
            nIJV = []
            K2 = []
        elif k_torsion == 0.0: # axial; 2D or 3D
            K2 = K * k_axial
            dofs = array([
                i1, i1+1, i1+2,
                i2, i2+1, i2+2,
            ], 'int32')
            nIJV = [
                # axial
                (n1, 1), (n1, 2), (n1, 3),
                (n2, 1), (n2, 2), (n2, 3),
            ]
        elif k_axial == 0.0: # torsion; assume 3D
            K2 = K * k_torsion
            dofs = array([
                i1+3, i1+4, i1+5,
                i2+3, i2+4, i2+5,
            ], 'int32')
            nIJV = [
                # torsion
                (n1, 4), (n1, 5), (n2, 6),
                (n2, 4), (n2, 5), (n1, 6),
            ]

        else:  # axial + torsion; assume 3D
            # u1fx, u1fy, u1fz, u2fx, u2fy, u2fz
            K2[:Ki, :Ki] = K * k_axial

            # u1mx, u1my, u1mz, u2mx, u2my, u2mz
            K2[Ki:, Ki:] = K * k_torsion

            dofs = array([
                i1, i1+1, i1+2,
                i2, i2+1, i2+2,

                i1+3, i1+4, i1+5,
                i2+3, i2+4, i2+5,
            ], 'int32')
            nIJV = [
                # axial
                (n1, 1), (n1, 2), (n1, 3),
                (n2, 1), (n2, 2), (n2, 3),

                # torsion
                (n1, 4), (n1, 5), (n1, 6),
                (n2, 4), (n2, 5), (n2, 6),
            ]

        #Fg = dot(dot(transpose(Lambda), grav), Lambda)
        #print("K=\n", K / knorm)
        #print("K2=\n", K2 / knorm)

        #========================

        #print(K / knorm)
        #print("K[%s] = \n%s\n" % (self.eid, list_print(K/knorm)))

        self.model.log.info('dofs = %s' % dofs)
        self.model.log.info('K =\n%s' % list_print(K / knorm))

        return(K2, dofs, nIJV)
Example #14
0
    def transformToGlobal(self, p, 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}]_{1\times 3}[\beta_{ij}]_{3\times 3} + [p_{origin}]

        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 in the local frame.  Type=1x3 NUMPY.NDARRAY
        :param debug:   developer debug (default=False)
        :returns p2:  the point in the global frame.  Type=1x3 NUMPY.NDARRAY
        :returns beta:  the rotation matrix.  Type=6x6 NUMPY.NDARRAY

        .. 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)

        if self.cid == 0:
            return p, array([[1., 0., 0.],
                             [0., 1., 0.],
                             [0., 0., 1.]], dtype='float64')
        if not self.isResolved:
            self.rid.setup()

        # the ijk axes arent resolved as R-theta-z, only points
        p2 = self.coordToXYZ(p)

        if self.i is None:
            raise RuntimeError("Local unit vectors haven't been set.\nType=%r cid=%s rid=%s" % (self.type, self.cid, self.rid))
        # Bij = Bip*j
        #i = self.i
        #j = self.j
        #k = self.k
        #gx = array([1., 0., 0.], dtype='float64')
        #gy = array([0., 1., 0.], dtype='float64')
        #gz = array([0., 0., 1.], dtype='float64')

        #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)]], dtype='float64')
        matrix = vstack([self.i, self.j, self.k])

        # rotate point p2 from the local frame to the global frame
        # shift point p by origin is in global coordinates
        #p3 = p2[0]*self.i + p2[1]*self.j + p2[2]*self.k + self.origin
        p3 = dot(p2, matrix) + self.origin

        if debug:
            print("Cp = ", self.Cid())
            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" % (list_print(p3)))

        return (p3, matrix)
Example #15
0
    def transformToGlobal(self, p, 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}]_{1\times 3}[\beta_{ij}]_{3\times 3} + [p_{origin}]

        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 in the local frame.  Type=1x3 NUMPY.NDARRAY
        :param debug:   developer debug (default=False)
        :returns p2:  the point in the global frame.  Type=1x3 NUMPY.NDARRAY
        :returns beta:  the rotation matrix.  Type=6x6 NUMPY.NDARRAY

        .. 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)

        if self.cid == 0:
            return p, array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]],
                            dtype='float64')
        if not self.isResolved:
            self.rid.setup()

        # the ijk axes arent resolved as R-theta-z, only points
        p2 = self.coordToXYZ(p)

        if self.i is None:
            raise RuntimeError(
                "Local unit vectors haven't been set.\nType=%r cid=%s rid=%s" %
                (self.type, self.cid, self.rid))
        # Bij = Bip*j
        #i = self.i
        #j = self.j
        #k = self.k
        #gx = array([1., 0., 0.], dtype='float64')
        #gy = array([0., 1., 0.], dtype='float64')
        #gz = array([0., 0., 1.], dtype='float64')

        #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)]], dtype='float64')
        matrix = vstack([self.i, self.j, self.k])

        # rotate point p2 from the local frame to the global frame
        # shift point p by origin is in global coordinates
        #p3 = p2[0]*self.i + p2[1]*self.j + p2[2]*self.k + self.origin
        p3 = dot(p2, matrix) + self.origin

        if debug:
            print("Cp = ", self.Cid())
            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" % (list_print(p3)))

        return (p3, matrix)
Example #16
0
    def get_stiffness_matrix(self, i, model, positions, index0s, knorm=1.0):
        #print("----------------")
        pid = self.property_id[i]
        assert isinstance(pid, int), pid
        element_id = self.element_id[i]
        i = self.get_element_index_by_element_id(element_id)
        A = self.get_area_by_element_index(i)
        G = self.model.prod.get_G_by_property_id(pid)
        E = self.model.prod.get_E_by_property_id(pid)
        J = self.model.prod.get_J_by_property_id(pid)
        #A = self.get_area_by_element_id(pid)
        #E = self.get_E_by_element_id(pid)
        #G = self.get_G_by_element_id(pid)
        #J = self.get_J_by_element_id(pid)
        #print('A=%s E=%s G=%s J=%s' % (A, E, G, J))

        #========================
        #(n1, n2) = self.node_ids()
        i = np.asarray(i)
        nids = self.node_ids[i, :]
        n1, n2 = nids.squeeze()

        i1 = index0s[n1]
        i2 = index0s[n2]

        xyz1 = positions[n1]
        xyz2 = positions[n2]
        #p1 = model.Node(n1).xyz

        dxyz12 = xyz1 - xyz2
        L = norm(dxyz12)
        if L == 0.0:
            msg = 'invalid CROD length=0.0\n%s' % (self.__repr__())
            raise ZeroDivisionError(msg)
        #========================
        #print("A=%g E=%g G=%g J=%g L=%g" % (A, E, G, J, L))
        k_axial = A * E / L
        k_torsion = G * J / L
        #k_axial = 1.0
        #k_torsion = 2.0

        k = array([[1., -1.], [-1., 1.]])  # 1D rod

        Lambda = _Lambda(dxyz12, debug=False)
        K = (Lambda.T @ k) @ Lambda
        Ki, Kj = K.shape

        K2 = zeros((Ki * 2, Kj * 2), 'float64')
        if k_axial == 0.0 and k_torsion == 0.0:
            dofs = []
            n_ijv = []
            K2 = []
        elif k_torsion == 0.0:  # axial; 2D or 3D
            K2 = K * k_axial
            dofs = array([
                i1,
                i1 + 1,
                i1 + 2,
                i2,
                i2 + 1,
                i2 + 2,
            ], 'int32')
            n_ijv = [
                # axial
                (n1, 1),
                (n1, 2),
                (n1, 3),
                (n2, 1),
                (n2, 2),
                (n2, 3),
            ]
        elif k_axial == 0.0:  # torsion; assume 3D
            K2 = K * k_torsion
            dofs = array([
                i1 + 3,
                i1 + 4,
                i1 + 5,
                i2 + 3,
                i2 + 4,
                i2 + 5,
            ], 'int32')
            n_ijv = [
                # torsion
                (n1, 4),
                (n1, 5),
                (n1, 6),
                (n2, 4),
                (n2, 5),
                (n2, 6),
            ]

        else:  # axial + torsion; assume 3D
            # u1fx, u1fy, u1fz, u2fx, u2fy, u2fz
            K2[:Ki, :Ki] = K * k_axial

            # u1mx, u1my, u1mz, u2mx, u2my, u2mz
            K2[Ki:, Ki:] = K * k_torsion

            dofs = array([
                i1,
                i1 + 1,
                i1 + 2,
                i2,
                i2 + 1,
                i2 + 2,
                i1 + 3,
                i1 + 4,
                i1 + 5,
                i2 + 3,
                i2 + 4,
                i2 + 5,
            ], 'int32')
            n_ijv = [
                # axial
                (n1, 1),
                (n1, 2),
                (n1, 3),
                (n2, 1),
                (n2, 2),
                (n2, 3),

                # torsion
                (n1, 4),
                (n1, 5),
                (n1, 6),
                (n2, 4),
                (n2, 5),
                (n2, 6),
            ]

        #Fg = Lambda.T @ grav @ Lambda
        #print("K=\n", K / knorm)
        #print("K2=\n", K2 / knorm)

        #========================

        #print(K / knorm)
        #print("K[%s] = \n%s\n" % (self.eid, list_print(K/knorm)))

        self.model.log.info('dofs = %s' % dofs)
        self.model.log.info('K =\n%s' % list_print(K / knorm))

        return (K2, dofs, n_ijv)
Example #17
0
    def Stiffness(self, model, node_ids, index0s, fnorm=1.0):  # CROD/CONROD
        #print("----------------")
        A = self.Area()
        E = self.E()
        G = self.G()
        J = self.J()

        #========================
        #(n1, n2) = self.nodeIDs()
        n0, n1 = self.nodeIDs()

        i0, i1 = index0s
        node0 = self.nodes[0]
        node1 = self.nodes[1]

        p0 = model.Node(n0).xyz
        p1 = model.Node(n1).xyz
        L = norm(p0 - p1)
        if L == 0.0:
            msg = 'invalid CROD length=0.0\n%s' % (self.__repr__())
            raise ZeroDivisionError(msg)
        #========================
        print("A=%g E=%g G=%g J=%g L=%g" % (A, E, G, J, L))
        k_axial = A * E / L
        k_torsion = G * J / L
        #k_axial = 1.0
        #k_torsion = 2.0

        k = matrix([[1., -1.], [-1., 1.]])  # 1D rod

        Lambda = self.Lambda(model)
        K = dot(dot(transpose(Lambda), k), Lambda)
        Ki, Kj = K.shape

        # for testing
        #K = ones((Ki, Ki), 'float64')

        K2 = zeros((Ki*2, Kj*2), 'float64')
        if k_axial == 0.0 and k_torsion == 0.0:
            dofs = []
            nIJV = []
            K2 = []
        elif k_torsion == 0.0: # axial; 2D or 3D
            K2 = K * k_axial
            dofs = array([
                i0, i0+1, i0+2,
                i1, i1+1, i1+2,
            ], 'int32')
            nIJV = [
                # axial
                (n0, 1), (n0, 2), (n0, 3),
                (n1, 1), (n1, 2), (n1, 3),
            ]
        elif k_axial == 0.0: # torsion; assume 3D
            K2 = K * k_torsion
            dofs = array([
                i0+3, i0+4, i0+5,
                i1+3, i1+4, i1+5,
            ], 'int32')
            nIJV = [
                # torsion
                (n0, 4), (n0, 5), (n0, 6),
                (n1, 4), (n1, 5), (n1, 6),
            ]

        else:  # axial + torsion; assume 3D
            # u1fx, u1fy, u1fz, u2fx, u2fy, u2fz
            K2[:Ki, :Ki] = K * k_axial

            # u1mx, u1my, u1mz, u2mx, u2my, u2mz
            K2[Ki:, Ki:] = K * k_torsion

            dofs = array([
                i0, i0+1, i0+2,
                i1, i1+1, i1+2,

                i0+3, i0+4, i0+5,
                i1+3, i1+4, i1+5,
            ], 'int32')
            nIJV = [
                # axial
                (n0, 1), (n0, 2), (n0, 3),
                (n1, 1), (n1, 2), (n1, 3),

                # torsion
                (n0, 4), (n0, 5), (n0, 6),
                (n1, 4), (n1, 5), (n1, 6),
            ]

        #Fg = dot(dot(transpose(Lambda), grav), Lambda)
        #print("K=\n", K / fnorm)
        #print("K2=\n", K2 / fnorm)

        #========================

        #print(K / fnorm)
        #print("K[%s] = \n%s\n" % (self.eid, list_print(K/fnorm)))

        print('dofs =', dofs)
        print('K =\n', list_print(K / fnorm))

        return(K2, dofs, nIJV)