<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This module contains the different elements used and all its methods.
"""
import numpy as np
from .utils import Local_Csys_two_points

class Beam(object):
    """Beam object, joining two nodes. Parent class for the 2D and 3D implementation."""

    def __init__(self, node1, node2, number):
        """TODO: to be defined1.

        :node1: first node
        :node2: second node
        :number: number of the line

        """
        self._beam_section = None
        # TODO: accept tuples with coordinates also
        self._node1 = node1
        self._node2 = node2
        self._nodes = [self._node1, self._node2]
        # TODO: check that the number is not in use
        self.number = number
        #
        node1.append_beam(self, 1)
        node2.append_beam(self, 2)
        # Calculate the length of the element
        self._length = np.linalg.norm(node2-node1)
        # Local coordinate system
        self._localCSys = Local_Csys_two_points(point1=node1, point2=node2, type='cartesian')
        # Section
        self._beam_section = None
        # Directive cosines
        delta = node2 - node1
        cx = delta[0] / self._length
        cy = delta[1] / self._length
        cz = delta[2] / self._length

        # Transformation matrix
        self.transformation_matrix = self._localCSys.calc_transformation_matrix(self._length, cx, cy, cz)

        self._Ke = None

    def assign_section(self, beam_section):
        """Assign a beam section instance to the beam

        :beam_section: a BeamSection instance
        :returns: self

        """
        self._beam_section = beam_section

        return self

    def __str__(self):
        """
        Returns the printable string for this object
        """
        return 'Beam {number}: (N{n1}, N{n2})'.format(number=self.number,
                n1=self._node1.number, n2=self._node2.number)

    def __repr__(self):
        """
        Returns the printable string for this object
        """
        return 'Beam {number}'.format(number=self.number)

class Beam2D(Beam):
    """Beam object, joining two nodes"""

    def __init__(self, node1, node2, number):
        """TODO: to be defined1.

        :node1: first node
        :node2: second node
        :number: number of the line

        """
        Beam.__init__(self, node1, node2, number)
        # Number of nodes of the element
        self._n_nodes = 2
        # Number of DOF per node
        self._dof_per_node = 3
        # displacement/rotation of each degree of freedom, for each node
        # - Node 1
        self.dof1 = 0. # trans x
        self.dof2 = 0. # trans y
        self.dof3 = 0. # rot z

        # Node 2
        self.dof4 = 0. # trans x
        self.dof5 = 0. # trans y
        self.dof6 = 0. # rot z

        # Release rotation on the ends of the beam
        self.release_node_1 = False # first node
        self.release_node_2 = False # second node

        self._Ke = None

    def assembleK(self, second_order=False):
        """This function assembles the stiffness matrix for one individual element. Optionally
        it can take the shear effect into account (second order effect).

        :element: segment instance
        :seecond_order: boolean
        :returns: local stiffness matrix

        """
        # Modulus of elasticity
        E = self._beam_section._material._data[0]
        # Area of the section
        EA = self._beam_section._area * E
        # Inertias
        EI = self._beam_section._Iz * E
        # Length of the element
        L = self._length
        # TODO: Take account of the second order effects
        if second_order:
            G = self._material.G
            Ksy = 12.*E*Iz / (G*Asy*L*L)
            Ksz = 12.*E*Iy / (G*Asz*L*L)
        else:
            Ksy = 0.0
            Ksz = 0.0

        # Initialize stiffness matrix
        k = np.zeros((6,6))

        k[0,0] = k[3,3] = EA / L
        k[1,1] = k[4,4] = 12. * EI / L**3
        k[2,2] = k[5,5] = 4. * EI / L
        k[2,1] = k[1,2] = 6 * EI / L**2
        k[3,0] = k[0,3] = - EA / L
        k[4,1] = k[1,4] = -12. * EI / L**3
        k[4,2] = k[2,4] = -6. * EI / L**2
        k[5,1] = k[1,5] = 6. * EI / L**2
        k[5,2] = k[2,5] = 2. * EI / L
        k[5,4] = k[4,5] = -6. * EI / L**2

        # transform to global coordinates
        #T = element.transformation_matrix

        #Ke = np.dot(T.T, np.dot(k,T))<commit_msg>Speed improvement: L*L*L is faster than L^3<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This module contains the different elements used and all its methods.
"""
import numpy as np
from .utils import Local_Csys_two_points

class Beam(object):
    """Beam object, joining two nodes. Parent class for the 2D and 3D implementation."""

    def __init__(self, node1, node2, number):
        """TODO: to be defined1.

        :node1: first node
        :node2: second node
        :number: number of the line

        """
        self._beam_section = None
        # TODO: accept tuples with coordinates also
        self._node1 = node1
        self._node2 = node2
        self._nodes = [self._node1, self._node2]
        # TODO: check that the number is not in use
        self.number = number
        #
        node1.append_beam(self, 1)
        node2.append_beam(self, 2)
        # Calculate the length of the element
        self._length = np.linalg.norm(node2-node1)
        # Local coordinate system
        self._localCSys = Local_Csys_two_points(point1=node1, point2=node2, type='cartesian')
        # Section
        self._beam_section = None
        # Directive cosines
        delta = node2 - node1
        cx = delta[0] / self._length
        cy = delta[1] / self._length
        cz = delta[2] / self._length

        # Transformation matrix
        self.transformation_matrix = self._localCSys.calc_transformation_matrix(self._length, cx, cy, cz)

        self._Ke = None

    def assign_section(self, beam_section):
        """Assign a beam section instance to the beam

        :beam_section: a BeamSection instance
        :returns: self

        """
        self._beam_section = beam_section

        return self

    def __str__(self):
        """
        Returns the printable string for this object
        """
        return 'Beam {number}: (N{n1}, N{n2})'.format(number=self.number,
                n1=self._node1.number, n2=self._node2.number)

    def __repr__(self):
        """
        Returns the printable string for this object
        """
        return 'Beam {number}'.format(number=self.number)

class Beam2D(Beam):
    """Beam object, joining two nodes"""

    def __init__(self, node1, node2, number):
        """TODO: to be defined1.

        :node1: first node
        :node2: second node
        :number: number of the line

        """
        Beam.__init__(self, node1, node2, number)
        # Number of nodes of the element
        self._n_nodes = 2
        # Number of DOF per node
        self._dof_per_node = 3
        # displacement/rotation of each degree of freedom, for each node
        # - Node 1
        self.dof1 = 0. # trans x
        self.dof2 = 0. # trans y
        self.dof3 = 0. # rot z

        # Node 2
        self.dof4 = 0. # trans x
        self.dof5 = 0. # trans y
        self.dof6 = 0. # rot z

        # Release rotation on the ends of the beam
        self.release_node_1 = False # first node
        self.release_node_2 = False # second node

        self._Ke = None

    def assembleK(self, second_order=False):
        """This function assembles the stiffness matrix for one individual element. Optionally
        it can take the shear effect into account (second order effect).

        :element: segment instance
        :second_order: boolean
        :returns: local stiffness matrix

        """
        # Modulus of elasticity
        E = self._beam_section._material._data[0]
        # Area of the section
        EA = self._beam_section._area * E
        # Inertias
        EI = self._beam_section._Iz * E
        # Length of the element
        L = self._length
        # TODO: Take account of the second order effects
        if second_order:
            G = self._material.G
            Ksy = 12.*E*Iz / (G*Asy*L*L)
            Ksz = 12.*E*Iy / (G*Asz*L*L)
        else:
            Ksy = 0.0
            Ksz = 0.0

        # Initialize stiffness matrix
        k = np.zeros((6,6))

        k[0,0] = k[3,3] = EA / L
        k[1,1] = k[4,4] = 12. * EI / (L*L*L)
        k[2,2] = k[5,5] = 4. * EI / L
        k[2,1] = k[1,2] = 6 * EI / L**2
        k[3,0] = k[0,3] = - EA / L
        k[4,1] = k[1,4] = -12. * EI / (L*L*L)
        k[4,2] = k[2,4] = -6. * EI / L**2
        k[5,1] = k[1,5] = 6. * EI / L**2
        k[5,2] = k[2,5] = 2. * EI / L
        k[5,4] = k[4,5] = -6. * EI / L**2

        # transform to global coordinates
        #T = element.transformation_matrix

        #Ke = np.dot(T.T, np.dot(k,T))
{'fraction_non_alphanumeric': 0.1133043381286941, 'fraction_numerical': 0.02843760455001673, 'mean_word_length': 1.8334913112164297, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1022037', 'n_tokens_mistral': 3025, 'n_tokens_neox': 2874, 'n_words': 845}