U
    ZÊ¹j¯(  ã                   @   sj   d dl mZ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 d dlmZ dgZG dd„ de
ƒZdS )	é    )ÚBodyÚ
LagrangianÚKanesMethodÚLagrangesMethodÚ	RigidBodyÚParticle)ÚBodyBase)Ú_Methods)ÚMatrix)Úsympy_deprecation_warningÚJointsMethodc                   @   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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efd$d%„Zd)d'd(„Zd&S )*r   aè
  Method for formulating the equations of motion using a set of interconnected bodies with joints.

    .. deprecated:: 1.13
        The JointsMethod class is deprecated. Its functionality has been
        replaced by the new :class:`~.System` class.

    Parameters
    ==========

    newtonion : Body or ReferenceFrame
        The newtonion(inertial) frame.
    *joints : Joint
        The joints in the system

    Attributes
    ==========

    q, u : iterable
        Iterable of the generalized coordinates and speeds
    bodies : iterable
        Iterable of Body objects in the system.
    loads : iterable
        Iterable of (Point, vector) or (ReferenceFrame, vector) tuples
        describing the forces on the system.
    mass_matrix : Matrix, shape(n, n)
        The system's mass matrix
    forcing : Matrix, shape(n, 1)
        The system's forcing vector
    mass_matrix_full : Matrix, shape(2*n, 2*n)
        The "mass matrix" for the u's and q's
    forcing_full : Matrix, shape(2*n, 1)
        The "forcing vector" for the u's and q's
    method : KanesMethod or Lagrange's method
        Method's object.
    kdes : iterable
        Iterable of kde in they system.

    Examples
    ========

    As Body and JointsMethod have been deprecated, the following examples are
    for illustrative purposes only. The functionality of Body is fully captured
    by :class:`~.RigidBody` and :class:`~.Particle` and the functionality of
    JointsMethod is fully captured by :class:`~.System`. To ignore the
    deprecation warning we can use the ignore_warnings context manager.

    >>> from sympy.utilities.exceptions import ignore_warnings

    This is a simple example for a one degree of freedom translational
    spring-mass-damper.

    >>> from sympy import symbols
    >>> from sympy.physics.mechanics import Body, JointsMethod, PrismaticJoint
    >>> from sympy.physics.vector import dynamicsymbols
    >>> c, k = symbols('c k')
    >>> x, v = dynamicsymbols('x v')
    >>> with ignore_warnings(DeprecationWarning):
    ...     wall = Body('W')
    ...     body = Body('B')
    >>> J = PrismaticJoint('J', wall, body, coordinates=x, speeds=v)
    >>> wall.apply_force(c*v*wall.x, reaction_body=body)
    >>> wall.apply_force(k*x*wall.x, reaction_body=body)
    >>> with ignore_warnings(DeprecationWarning):
    ...     method = JointsMethod(wall, J)
    >>> method.form_eoms()
    Matrix([[-B_mass*Derivative(v(t), t) - c*v(t) - k*x(t)]])
    >>> M = method.mass_matrix_full
    >>> F = method.forcing_full
    >>> rhs = M.LUsolve(F)
    >>> rhs
    Matrix([
    [                     v(t)],
    [(-c*v(t) - k*x(t))/B_mass]])

    Notes
    =====

    ``JointsMethod`` currently only works with systems that do not have any
    configuration or motion constraints.

    c                 G   sj   t dddd� t|tƒr"|j| _n|| _|| _|  ¡ | _|  ¡ | _|  	¡ | _
|  ¡ | _|  ¡ | _d | _d S )Nzˆ
            The JointsMethod class is deprecated.
            Its functionality has been replaced by the new System class.
            z1.13z!deprecated-mechanics-jointsmethod)Zdeprecated_since_versionZactive_deprecations_target)r   Ú
isinstancer   ÚframeÚ_jointsÚ_generate_bodylistÚ_bodiesÚ_generate_loadlistÚ_loadsÚ_generate_qÚ_qÚ_generate_uÚ_uÚ_generate_kdesÚ_kdesÚ_method)ÚselfZ	newtonionZjoints© r   úc/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/physics/mechanics/jointsmethod.pyÚ__init__^   s    ú






zJointsMethod.__init__c                 C   s   | j S )zList of bodies in they system.)r   ©r   r   r   r   Úbodiesu   s    zJointsMethod.bodiesc                 C   s   | j S )zList of loads on the system.)r   r   r   r   r   Úloadsz   s    zJointsMethod.loadsc                 C   s   | j S ©z$List of the generalized coordinates.)r   r   r   r   r   Úq   s    zJointsMethod.qc                 C   s   | j S )zList of the generalized speeds.)r   r   r   r   r   Úu„   s    zJointsMethod.uc                 C   s   | j S r"   )r   r   r   r   r   Úkdes‰   s    zJointsMethod.kdesc                 C   s   | j jS )z)The "forcing vector" for the u's and q's.)ÚmethodÚforcing_fullr   r   r   r   r'   Ž   s    zJointsMethod.forcing_fullc                 C   s   | j jS )z&The "mass matrix" for the u's and q's.)r&   Úmass_matrix_fullr   r   r   r   r(   “   s    zJointsMethod.mass_matrix_fullc                 C   s   | j jS )zThe system's mass matrix.)r&   Úmass_matrixr   r   r   r   r)   ˜   s    zJointsMethod.mass_matrixc                 C   s   | j jS )zThe system's forcing vector.)r&   Úforcingr   r   r   r   r*   �   s    zJointsMethod.forcingc                 C   s   | j S )z3Object of method used to form equations of systems.)r   r   r   r   r   r&   ¢   s    zJointsMethod.methodc                 C   s@   g }| j D ]0}|j|kr$| |j¡ |j|kr
| |j¡ q
|S ©N)r   ÚchildÚappendÚparent)r   r    Újointr   r   r   r   §   s    


zJointsMethod._generate_bodylistc                 C   s*   g }| j D ]}t|tƒr
| |j¡ q
|S r+   )r    r   r   Úextendr!   )r   Ú	load_listÚbodyr   r   r   r   °   s
    

zJointsMethod._generate_loadlistc                 C   s>   g }| j D ]*}|jD ]}||kr(tdƒ‚| |¡ qq
t|ƒS )Nz'Coordinates of joints should be unique.)r   ZcoordinatesÚ
ValueErrorr-   r
   )r   Úq_indr/   Z
coordinater   r   r   r   ·   s    

zJointsMethod._generate_qc                 C   s>   g }| j D ]*}|jD ]}||kr(tdƒ‚| |¡ qq
t|ƒS )Nz"Speeds of joints should be unique.)r   Zspeedsr3   r-   r
   )r   Úu_indr/   Úspeedr   r   r   r   À   s    

zJointsMethod._generate_uc                 C   s*   t ddg ƒj}| jD ]}| |j¡}q|S )Né   r   )r
   ÚTr   Zcol_joinr%   )r   Zkd_indr/   r   r   r   r   É   s    
zJointsMethod._generate_kdesc                 C   sˆ   g }| j D ]x}t|tƒs$| |¡ q
|jr^t|j|j|j|j	|j
|jfƒ}|j|_| |¡ q
t|j|j|j	ƒ}|j|_| |¡ q
|S r+   )r    r   r   r-   Zis_rigidbodyr   ÚnameZ
masscenterr   ZmassZcentral_inertiaZpotential_energyr   )r   Úbodylistr2   ÚrbÚpartr   r   r   Ú_convert_bodiesÏ   s    



ÿzJointsMethod._convert_bodiesc                 C   sj   |   ¡ }t|tƒr<t| jf|žŽ }||| j| j|| jƒ| _n || j| j| j| j	| j|d�| _| j
 ¡ }|S )aŠ  Method to form system's equation of motions.

        Parameters
        ==========

        method : Class
            Class name of method.

        Returns
        ========

        Matrix
            Vector of equations of motions.

        Examples
        ========

        As Body and JointsMethod have been deprecated, the following examples
        are for illustrative purposes only. The functionality of Body is fully
        captured by :class:`~.RigidBody` and :class:`~.Particle` and the
        functionality of JointsMethod is fully captured by :class:`~.System`. To
        ignore the deprecation warning we can use the ignore_warnings context
        manager.

        >>> from sympy.utilities.exceptions import ignore_warnings

        This is a simple example for a one degree of freedom translational
        spring-mass-damper.

        >>> from sympy import S, symbols
        >>> from sympy.physics.mechanics import LagrangesMethod, dynamicsymbols, Body
        >>> from sympy.physics.mechanics import PrismaticJoint, JointsMethod
        >>> q = dynamicsymbols('q')
        >>> qd = dynamicsymbols('q', 1)
        >>> m, k, b = symbols('m k b')
        >>> with ignore_warnings(DeprecationWarning):
        ...     wall = Body('W')
        ...     part = Body('P', mass=m)
        >>> part.potential_energy = k * q**2 / S(2)
        >>> J = PrismaticJoint('J', wall, part, coordinates=q, speeds=qd)
        >>> wall.apply_force(b * qd * wall.x, reaction_body=part)
        >>> with ignore_warnings(DeprecationWarning):
        ...     method = JointsMethod(wall, J)
        >>> method.form_eoms(LagrangesMethod)
        Matrix([[b*Derivative(q(t), t) + k*q(t) + m*Derivative(q(t), (t, 2))]])

        We can also solve for the states using the 'rhs' method.

        >>> method.rhs()
        Matrix([
        [                Derivative(q(t), t)],
        [(-b*Derivative(q(t), t) - k*q(t))/m]])

        )r4   r5   Zkd_eqsZ	forcelistr    )r=   Ú
issubclassr   r   r   r#   r!   r   r$   r%   r&   Z
_form_eoms)r   r&   r:   ÚLZsolnr   r   r   Ú	form_eomsá   s    8
 ÿ
zJointsMethod.form_eomsNc                 C   s   | j j|d�S )az  Returns equations that can be solved numerically.

        Parameters
        ==========

        inv_method : str
            The specific sympy inverse matrix calculation method to use. For a
            list of valid methods, see
            :meth:`~sympy.matrices.matrixbase.MatrixBase.inv`

        Returns
        ========

        Matrix
            Numerically solvable equations.

        See Also
        ========

        sympy.physics.mechanics.kane.KanesMethod.rhs:
            KanesMethod's rhs function.
        sympy.physics.mechanics.lagrange.LagrangesMethod.rhs:
            LagrangesMethod's rhs function.

        )Ú
inv_method)r&   Úrhs)r   rA   r   r   r   rB   #  s    zJointsMethod.rhs)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr    r!   r#   r$   r%   r'   r(   r)   r*   r&   r   r   r   r   r   r=   r   r@   rB   r   r   r   r   r      s<   R









			BN)Zsympy.physics.mechanicsr   r   r   r   r   r   Z!sympy.physics.mechanics.body_baser   Zsympy.physics.mechanics.methodr	   Zsympyr
   Zsympy.utilities.exceptionsr   Ú__all__r   r   r   r   r   Ú<module>   s    