U
    ZÊ¹j:'  ã                   @   sÔ   d Z dgZddlmZ ddlmZ ddlmZmZ ddl	m
Z
mZmZ ddlmZ ddlmZmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZmZmZ ddlmZmZm Z  e !ee  ¡Z"G dd„ deƒZ#dS )zb
This module has all the classes and functions related to waves in optics.

**Contains**

* TWave
ÚTWaveé    )ÚBasic)ÚExpr)Ú
DerivativeÚFunction)ÚNumberÚpiÚI)ÚS)ÚSymbolÚsymbols)Ú_sympifyÚsympify)Úexp)Úsqrt)Úatan2ÚcosÚsin)Úspeed_of_lightÚmeterÚsecondc                   @   sø   e Zd ZdZdejdedƒf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eZdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ ZdS )0r   a4  
    This is a simple transverse sine wave travelling in a one-dimensional space.
    Basic properties are required at the time of creation of the object,
    but they can be changed later with respective methods provided.

    Explanation
    ===========

    It is represented as :math:`A \times cos(k*x - \omega \times t + \phi )`,
    where :math:`A` is the amplitude, :math:`\omega` is the angular frequency,
    :math:`k` is the wavenumber (spatial frequency), :math:`x` is a spatial variable
    to represent the position on the dimension on which the wave propagates,
    and :math:`\phi` is the phase angle of the wave.


    Arguments
    =========

    amplitude : Sympifyable
        Amplitude of the wave.
    frequency : Sympifyable
        Frequency of the wave.
    phase : Sympifyable
        Phase angle of the wave.
    time_period : Sympifyable
        Time period of the wave.
    n : Sympifyable
        Refractive index of the medium.

    Raises
    =======

    ValueError : When neither frequency nor time period is provided
        or they are not consistent.
    TypeError : When anything other than TWave objects is added.


    Examples
    ========

    >>> from sympy import symbols
    >>> from sympy.physics.optics import TWave
    >>> A1, phi1, A2, phi2, f = symbols('A1, phi1, A2, phi2, f')
    >>> w1 = TWave(A1, f, phi1)
    >>> w2 = TWave(A2, f, phi2)
    >>> w3 = w1 + w2  # Superposition of two waves
    >>> w3
    TWave(sqrt(A1**2 + 2*A1*A2*cos(phi1 - phi2) + A2**2), f,
        atan2(A1*sin(phi1) + A2*sin(phi2), A1*cos(phi1) + A2*cos(phi2)), 1/f, n)
    >>> w3.amplitude
    sqrt(A1**2 + 2*A1*A2*cos(phi1 - phi2) + A2**2)
    >>> w3.phase
    atan2(A1*sin(phi1) + A2*sin(phi2), A1*cos(phi1) + A2*cos(phi2))
    >>> w3.speed
    299792458*meter/(second*n)
    >>> w3.angular_velocity
    2*pi*f

    NÚnc           	      C   s²   |d k	rt |ƒ}tj| }|d k	rRt |ƒ}tj| }|d k	rR|tj| krRtdƒ‚|d krj|d krjtdƒ‚|d krv|}|d kr‚|}t |ƒ}t |ƒ}t|ƒ}t | |||||¡}|S )Nz/frequency and time_period should be consistent.z*Either frequency or time period is needed.)r   r
   ZOneÚ
ValueErrorr   r   Ú__new__)	ÚclsÚ	amplitudeÚ	frequencyÚphaseÚtime_periodr   Z
_frequencyZ_time_periodÚobj© r    úY/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/physics/optics/waves.pyr   Y   s(    

zTWave.__new__c                 C   s
   | j d S )a!  
        Returns the amplitude of the wave.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.amplitude
        A
        r   ©Úargs©Úselfr    r    r!   r   v   s    zTWave.amplitudec                 C   s
   | j d S )a?  
        Returns the frequency of the wave,
        in cycles per second.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.frequency
        f
        é   r"   r$   r    r    r!   r   ‡   s    zTWave.frequencyc                 C   s
   | j d S )a5  
        Returns the phase angle of the wave,
        in radians.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.phase
        phi
        é   r"   r$   r    r    r!   r   ™   s    zTWave.phasec                 C   s
   | j d S )aI  
        Returns the temporal period of the wave,
        in seconds per cycle.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.time_period
        1/f
        é   r"   r$   r    r    r!   r   «   s    zTWave.time_periodc                 C   s
   | j d S )z<
        Returns the refractive index of the medium
        é   r"   r$   r    r    r!   r   ½   s    zTWave.nc                 C   s   t | j| j  S )aš  
        Returns the wavelength (spatial period) of the wave,
        in meters per cycle.
        It depends on the medium of the wave.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.wavelength
        299792458*meter/(second*f*n)
        )Úcr   r   r$   r    r    r!   Ú
wavelengthÄ   s    zTWave.wavelengthc                 C   s   | j | j S )a�  
        Returns the propagation speed of the wave,
        in meters per second.
        It is dependent on the propagation medium.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.speed
        299792458*meter/(second*n)
        )r+   r   r$   r    r    r!   ÚspeedØ   s    zTWave.speedc                 C   s   dt  | j S )aS  
        Returns the angular velocity of the wave,
        in radians per second.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.angular_velocity
        2*pi*f
        r'   )r   r   r$   r    r    r!   Úangular_velocityë   s    zTWave.angular_velocityc                 C   s   dt  | j S )a_  
        Returns the wavenumber of the wave,
        in radians per meter.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.wavenumber
        pi*second*f*n/(149896229*meter)
        r'   )r   r+   r$   r    r    r!   Ú
wavenumberý   s    zTWave.wavenumberc                 C   s    ddl m} t| ƒj|| jƒ S )z!String representation of a TWave.r   )Ússtr)Zsympy.printingr/   ÚtypeÚ__name__r#   )r%   r/   r    r    r!   Ú__str__  s    zTWave.__str__c              	   C   sÂ   t |tƒr¬| j|jkr¢| j|jkr¢tt| jd |jd  d| j |j t| j|j ƒ  ƒ| jt| jt	| jƒ |jt	|jƒ  | jt| jƒ |jt|jƒ  ƒƒS t
dƒ‚ntt|ƒjd ƒ‚dS )z�
        Addition of two waves will result in their superposition.
        The type of interference will depend on their phase angles.
        r'   zJInterference of waves with different frequencies has not been implemented.z# and TWave objects cannot be added.N)Ú
isinstancer   r   r+   r   r   r   r   r   r   ÚNotImplementedErrorÚ	TypeErrorr0   r1   ©r%   Úotherr    r    r!   Ú__add__  s,    
ÿÿ
ÿÿÿÿþü

zTWave.__add__c                 C   sF   t |ƒ}t|tƒr0t| j| f| jdd… žŽ S tt|ƒjd ƒ‚dS )zT
        Multiplying a wave by a scalar rescales the amplitude of the wave.
        r&   Nz( and TWave objects cannot be multiplied.)	r   r3   r   r   r   r#   r5   r0   r1   r6   r    r    r!   Ú__mul__,  s    
zTWave.__mul__c                 C   s   |   d| ¡S ©Néÿÿÿÿ©r8   r6   r    r    r!   Ú__sub__6  s    zTWave.__sub__c                 C   s
   |   d¡S r:   ©r9   r$   r    r    r!   Ú__neg__9  s    zTWave.__neg__c                 C   s
   |   |¡S ©Nr<   r6   r    r    r!   Ú__radd__<  s    zTWave.__radd__c                 C   s
   |   |¡S r@   r>   r6   r    r    r!   Ú__rmul__?  s    zTWave.__rmul__c                 C   s   |    |¡S r@   )rA   r6   r    r    r!   Ú__rsub__B  s    zTWave.__rsub__c                 O   s8   | j t| jtdƒ | jtdƒ  | j td  dd� S )NÚxÚtr'   F)Úevaluate)r   r   r.   r   r-   r   r   ©r%   r#   Úkwargsr    r    r!   Ú_eval_rewrite_as_sinE  s    ÿÿÿÿzTWave._eval_rewrite_as_sinc                 O   s,   | j t| jtdƒ | jtdƒ  | j ƒ S ©NrD   rE   )r   r   r.   r   r-   r   rG   r    r    r!   Ú_eval_rewrite_as_cosI  s
    ÿÿzTWave._eval_rewrite_as_cosc                 O   sD   t dƒ\}}}}tdƒ}t|||ƒ|dƒ|| t|||ƒ|dƒ  S )Nzmu, epsilon, x, tÚEr'   )r   r   r   )r%   r#   rH   ÚmuÚepsilonrD   rE   rL   r    r    r!   Ú_eval_rewrite_as_pdeM  s    zTWave._eval_rewrite_as_pdec                 O   s0   | j tt| jtdƒ | jtdƒ  | j  ƒ S rJ   )r   r   r	   r.   r   r-   r   rG   r    r    r!   Ú_eval_rewrite_as_expR  s
    ÿÿzTWave._eval_rewrite_as_exp)r1   Ú
__module__Ú__qualname__Ú__doc__r
   ZZeror   r   Úpropertyr   r   r   r   r   r+   r,   r-   r.   r2   Ú__repr__r8   r9   r=   r?   rA   rB   rC   rI   rK   rO   rP   r    r    r    r!   r      sJ   ?ú










N)$rS   Ú__all__Zsympy.core.basicr   Zsympy.core.exprr   Zsympy.core.functionr   r   Zsympy.core.numbersr   r   r	   Zsympy.core.singletonr
   Zsympy.core.symbolr   r   Zsympy.core.sympifyr   r   Z&sympy.functions.elementary.exponentialr   Z(sympy.functions.elementary.miscellaneousr   Z(sympy.functions.elementary.trigonometricr   r   r   Zsympy.physics.unitsr   r   r   Z
convert_tor*   r   r    r    r    r!   Ú<module>   s   