o
    oh
U                     @   sn   d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ G dd	 d	Zd
S )zA
This module can be used to solve problems related
to 2D Cables.
    )sympify)Symbol)sincospiatandiff)sqrt)linsolve)Matrixc                   @   s   e Zd ZdZdd Zedd Zedd Zedd	 Zed
d Z	edd Z
edd Zedd Zedd Zdd Zdd Zdd Zdd Zdd Zdd Zd S )!Cablea  
    Cables are structures in engineering that support
    the applied transverse loads through the tensile
    resistance developed in its members.

    Cables are widely used in suspension bridges, tension
    leg offshore platforms, transmission lines, and find
    use in several other engineering applications.

    Examples
    ========
    A cable is supported at (0, 10) and (10, 10). Two point loads
    acting vertically downwards act on the cable, one with magnitude 3 kN
    and acting 2 meters from the left support and 3 meters below it, while
    the other with magnitude 2 kN is 6 meters from the left support and
    6 meters below it.

    >>> from sympy.physics.continuum_mechanics.cable import Cable
    >>> c = Cable(('A', 0, 10), ('B', 10, 10))
    >>> c.apply_load(-1, ('P', 2, 7, 3, 270))
    >>> c.apply_load(-1, ('Q', 6, 4, 2, 270))
    >>> c.loads
    {'distributed': {}, 'point_load': {'P': [3, 270], 'Q': [2, 270]}}
    >>> c.loads_position
    {'P': [2, 7], 'Q': [6, 4]}
    c                 C   s  g | _ g | _i | _g | _i i d| _i | _d| _i | _i | _t	d| _
|d |d kr/td|d |d kr;tdt	|d }t	|d }||g| j|d < t	|d }t	|d }||g| j|d < |d |d k r| j | | j | | j| | j| | j|d  | j|d  n(| j | | j | | j| | j| | j|d  | j|d  | jD ]}d| jtd| d < d| jtd| d	 < qd
S )a  
        Initializes the class.

        Parameters
        ==========

        support_1 and support_2 are tuples of the form
        (label, x, y), where

        label : String or symbol
            The label of the support

        x : Sympifyable
            The x coordinate of the position of the support

        y : Sympifyable
            The y coordinate of the position of the support
        )distributed
point_loadr   z$Supports can not have the same label   z(Supports can not be at the same location   R__x_yN)_left_support_right_support	_supports_support_labels_loads_loads_position_length_reaction_loads_tensionr   _lowest_x_global
ValueErrorappendr   )self	support_1	support_2x1y1x2y2i r(   {/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/physics/continuum_mechanics/cable.py__init__)   sJ   

zCable.__init__c                 C      | j S )zW
        Returns the supports of the cable along with their
        positions.
        )r   r    r(   r(   r)   supportsi      zCable.supportsc                 C   r+   )z;
        Returns the position of the left support.
        )r   r,   r(   r(   r)   left_supportq      zCable.left_supportc                 C   r+   )z<
        Returns the position of the right support.
        )r   r,   r(   r(   r)   right_supportx   r0   zCable.right_supportc                 C   r+   )z_
        Returns the magnitude and direction of the loads
        acting on the cable.
        )r   r,   r(   r(   r)   loads   r.   zCable.loadsc                 C   r+   )zV
        Returns the position of the point loads acting on the
        cable.
        )r   r,   r(   r(   r)   loads_position   r.   zCable.loads_positionc                 C   r+   )z2
        Returns the length of the cable.
        )r   r,   r(   r(   r)   length   r0   zCable.lengthc                 C   r+   )zb
        Returns the reaction forces at the supports, which are
        initialized to 0.
        )r   r,   r(   r(   r)   reaction_loads   r.   zCable.reaction_loadsc                 C   r+   )z^
        Returns the tension developed in the cable due to the loads
        applied.
        )r   r,   r(   r(   r)   tension   r.   zCable.tensionc                 C   s`   d| j  vrtd|| jd ks|| jd k rtd| j d }td}|||| j iS )zf
        Returns the tension at a given value of x developed due to
        distributed load.
        r   z4No distributed load added or solve method not calledr   z1The value of x should be between the two supportsX)r   keysr   r   r   r   subsr   )r    xAr7   r(   r(   r)   
tension_at   s   
zCable.tension_atc                 C   sN   | j d | jd  d | j d | jd  d  d }||k r"td|| _dS )a  
        This method specifies the length of the cable

        Parameters
        ==========

        length : Sympifyable
            The length of the cable

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.cable import Cable
        >>> c = Cable(('A', 0, 10), ('B', 10, 10))
        >>> c.apply_length(20)
        >>> c.length
        20
        r   r   r   g      ?z@length should not be less than the distance between the supportsN)r   r   r   r   )r    r4   distr(   r(   r)   apply_length   s   
zCable.apply_lengthc           
      C   s  || j vr	td| j|}| j|d d  }| j | d }| j | d }t|d }t|d }| jD ]}	|	d t||ksI|	d t||krMtdq5| j | | j	
  | j
  | j
  | j| ||g| j |d < ||k r| j	| | j	| | j| | j| | j|d  n!| j	| | j	| | j| | j| | jd|d  | jD ]}d| jtd| d < d| jtd| d < qd	S )
a^  
        This method changes the mentioned support with a new support.

        Parameters
        ==========
        label: String or symbol
            The label of the support to be changed

        new_support: Tuple of the form (new_label, x, y)
            new_label: String or symbol
                The label of the new support

            x: Sympifyable
                The x-coordinate of the position of the new support.

            y: Sympifyable
                The y-coordinate of the position of the new support.

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.cable import Cable
        >>> c = Cable(('A', 0, 10), ('B', 10, 10))
        >>> c.supports
        {'A': [0, 10], 'B': [10, 10]}
        >>> c.change_support('B', ('C', 5, 6))
        >>> c.supports
        {'A': [0, 10], 'C': [5, 6]}
        z&No support exists with the given labelr   r   r   z>The change in support will throw an existing load out of ranger   r   r   N)r   r   r   indexr   r   maxminpopr   clearr   r   remover   insertr   )
r    labelnew_supportr'   	rem_labelr#   r$   r:   ylr(   r(   r)   change_support   sB   

$



zCable.change_supportc                 C   s  |dkr\t | jd dkrtd|d }|| jd v r tdt|d }t|d }|| jd ks:|| jd k r>td	t|d
 }t|d }||g| jd |< ||g| j|< dS |dkrt | jdkrktd|d }|| jd v rztdt|d }|| jd |< dS td)a  
        This method adds load to the cable.

        Parameters
        ==========

        order : Integer
            The order of the applied load.

                - For point loads, order = -1
                - For distributed load, order = 0

        load : tuple

            * For point loads, load is of the form (label, x, y, magnitude, direction), where:

            label : String or symbol
                The label of the load

            x : Sympifyable
                The x coordinate of the position of the load

            y : Sympifyable
                The y coordinate of the position of the load

            magnitude : Sympifyable
                The magnitude of the load. It must always be positive

            direction : Sympifyable
                The angle, in degrees, that the load vector makes with the horizontal
                in the counter-clockwise direction. It takes the values 0 to 360,
                inclusive.


            * For uniformly distributed load, load is of the form (label, magnitude)

            label : String or symbol
                The label of the load

            magnitude : Sympifyable
                The magnitude of the load. It must always be positive

        Examples
        ========

        For a point load of magnitude 12 units inclined at 30 degrees with the horizontal:

        >>> from sympy.physics.continuum_mechanics.cable import Cable
        >>> c = Cable(('A', 0, 10), ('B', 10, 10))
        >>> c.apply_load(-1, ('Z', 5, 5, 12, 30))
        >>> c.loads
        {'distributed': {}, 'point_load': {'Z': [12, 30]}}
        >>> c.loads_position
        {'Z': [5, 5]}


        For a uniformly distributed load of magnitude 9 units:

        >>> from sympy.physics.continuum_mechanics.cable import Cable
        >>> c = Cable(('A', 0, 10), ('B', 10, 10))
        >>> c.apply_load(0, ('X', 9))
        >>> c.loads
        {'distributed': {'X': 9}, 'point_load': {}}
        r   r   zDistributed load already existsr   zLabel already existsr   r   z2The load should be positioned between the supports      zPoint load(s) already existzOrder should be either -1 or 0N)lenr   r   r   r   r   r   )r    orderloadrF   r:   rI   	magnitude	directionr(   r(   r)   
apply_load  s.   AzCable.apply_loadc                 G   s   |D ]>}t | jdkr#|| jd vrtd| d | jd | q|| jd vr2td| d | jd | | j| qdS )an  
        This methods removes the specified loads.

        Parameters
        ==========
        This input takes multiple label(s) as input
        label(s): String or symbol
            The label(s) of the loads to be removed.

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.cable import Cable
        >>> c = Cable(('A', 0, 10), ('B', 10, 10))
        >>> c.apply_load(-1, ('Z', 5, 5, 12, 30))
        >>> c.loads
        {'distributed': {}, 'point_load': {'Z': [12, 30]}}
        >>> c.remove_loads('Z')
        >>> c.loads
        {'distributed': {}, 'point_load': {}}
        r   r   zError removing load z: no such load existsdisrtibutedr   N)rO   r   r   r   rB   )r    argsr'   r(   r(   r)   remove_loads|  s   zCable.remove_loadsc              	   G   sh	  t | jdkrTt| j dd d}|| jd  |d| jd  | j  d}d}d}d}d| _	t
dt |d D ]L}|dkrp|  j	t| jd | j|| d  d  d | jd | j|| d  d  d  7  _	n;|  j	t| j||d  d  d | j|| d  d  d | j||d  d  d | j|| d  d  d  7  _	|t |d kr|  j	t| jd | j|| d  d  d | jd | j|| d  d  d  7  _	|| jd || d  d tt| jd || d  d  d  t| jd | j|| d  d   7 }|| jd || d  d tt| jd || d  d  d  t| jd | j|| d  d   7 }|| jd || d  d tt| jd || d  d  d  7 }|| jd || d  d tt| jd || d  d  d  7 }t|| d d	 ||d  d  }| j|| d  d }	| j|| d  d }
d}d}|t |d kr| jd }| jd }n| j||d  d  d }| j||d  d  d }t||	 ||
  }| t| jd | j|| d  d  t| t| jd | j|| d  d  t|   }|| j|< || jd || d  d tt| jd || d  d  d  t| jd | j|| d  d   7 }|| jd || d  d tt| jd || d  d  d  t| jd | j|| d  d   7 }q=t|d d d	 |d d  }| j|d d  d }	| j|d d  d }
| jd }| jd }t|	| |
|   }| t| jd | j|d d  d  t| t| jd | j|d d  d  t|   }|| j|< td | }| jd }t| | | jtd
| d < |t| | 7 }t|| | jtd
| d < |t|| 7 }| jd }| | jtd
| d < | | jtd
| d < dS t | jd dkrt |dkritdt|d }t|d }|| _td}td}td}t| jd d | jd d| jd g| jd d | jd d| jd g|d |d|gg}tt||||f}t |dkrtd|d d }|d d }|d d }td}td}||| d  |||   | | }t| jd  }|d }|| jd | d  d| jd |   }| j  t||}|tt| | jd< | jd }| | jd tt||| jd |  | jtd
| d < | | jd tt||| jd |  | jtd
| d < | jd }| | jd tt||| jd |  | jtd
| d < | | jd tt||| jd |  | jtd
| d < dS dS )aU  
        This method solves for the reaction forces at the supports, the tension developed in
        the cable, and updates the length of the cable.

        Parameters
        ==========
        This method requires no input when solving for point loads
        For distributed load, the x and y coordinates of the lowest point of the cable are
        required as

        x: Sympifyable
            The x coordinate of the lowest point

        y: Sympifyable
            The y coordinate of the lowest point

        Examples
        ========
        For point loads,

        >>> from sympy.physics.continuum_mechanics.cable import Cable
        >>> c = Cable(("A", 0, 10), ("B", 10, 10))
        >>> c.apply_load(-1, ('Z', 2, 7.26, 3, 270))
        >>> c.apply_load(-1, ('X', 4, 6, 8, 270))
        >>> c.solve()
        >>> c.tension
        {A_Z: 8.91403453669861, X_B: 19*sqrt(13)/10, Z_X: 4.79150773600774}
        >>> c.reaction_loads
        {R_A_x: -5.25547445255474, R_A_y: 7.2, R_B_x: 5.25547445255474, R_B_y: 3.8}
        >>> c.length
        5.7560958484519 + 2*sqrt(13)

        For distributed load,

        >>> from sympy.physics.continuum_mechanics.cable import Cable
        >>> c=Cable(("A", 0, 40),("B", 100, 20))
        >>> c.apply_load(0, ("X", 850))
        >>> c.solve(58.58, 0)
        >>> c.tension
        {'distributed': 36456.8485*sqrt(0.000543529004799705*(X + 0.00135624381275735)**2 + 1)}
        >>> c.tension_at(0)
        61709.0363315913
        >>> c.reaction_loads
        {R_A_x: 36456.8485, R_A_y: -49788.5866682485, R_B_x: 44389.8401587246, R_B_y: 42866.621696333}
        r   c                 S   s   | d d S )Nr   r   r(   )itemr(   r(   r)   <lambda>  s    zCable.solve.<locals>.<lambda>)keyr   r   r      _r   r   r   r   z%Provide the lowest point of the cableabcz2The lowest point is inconsistent with the supportsr7   YN) rO   r   sorteditemsr   r   rE   r   rC   r   ranger	   r   r   r   r   r   absr   r   r   r   r   r   r   r   listr
   valuesr   r<   r9   )r    rV   sorted_positionmoment_sum_from_left_supportmoment_sum_from_right_supportF_xF_yr'   rF   r&   r%   r$   r#   angle_with_horizontalr6   lowest_xlowest_yr]   r^   r_   Mcoefficient_solutionr;   BCr7   r`   	temp_listapplied_forcehorizontal_force_constanttangent_slope_to_curver(   r(   r)   solve  s   /
XvVhhDD$
^
hj 

^

 
  $(


@@
@DzCable.solveN)__name__
__module____qualname____doc__r*   propertyr-   r/   r1   r2   r3   r4   r5   r6   r<   r>   rK   rT   rW   rw   r(   r(   r(   r)   r      s2    @







Gd&r   N)r{   sympy.core.sympifyr   sympy.core.symbolr   sympyr   r   r   r   r   (sympy.functions.elementary.miscellaneousr	   sympy.solvers.solvesetr
   sympy.matricesr   r   r(   r(   r(   r)   <module>   s    