U
    @f7                     @   s  d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZ 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mZmZmZmZmZ d dl m!Z! edZ"e"# \Z$Z%Z&e"' \Z(Z)Z*e Z+e	d\Z,Z-Z.Z/dd Z0dd Z1e"2de/e"j&Z3de(d  e) e* Z4ee4Z5e)d e$ de( e%  de) e* e&  Z6ee6Z7dd Z8dd Z9dd Z:dd Z;dd  Z<d!d" Z=d#d$ Z>d%S )&    )
Derivative)Vector)
CoordSys3D)simplify)symbols)S)cossin)Dot)curl
divergencegradientGradient
DivergenceCross)Del)is_conservativeis_solenoidalscalar_potentialdirectional_derivative	laplacianscalar_potential_difference)raisesCza b c qc                  C   sL
  t tjA tjkstt tjA  tj  kr:ttjks@n tt tjt tjA ksZtt tA  tjksptt jdtd  t	 ddtjkstt dtd  t	 t dtd  t	 A kstt
t t tt	 t  } t | A  t
 t t
t  t t
t tt  t	  t
 t tt  t    kr:t| ks@n tt | A t | ksXtt dt
d  t	 tdtjtdtj
d  tj tj tdtj
 tdtj tj	  tdtj tdtj
d  tj
 tj  kstt jdt
d  t	 dddt
 t   kr,tdt
d  t	 ks2n tt tj@ tj  krXttjks^n tt tj@  tjksxtt tjt tj@ kstt t@  tjkstt t
d t @  dt
   krtt
d t ksn tt j| ddt
t tt  tt
    kr$t| ks*n tt | @ t | ksBtt jdt
t t  tt	 t  dddt
t td   dt
td  t   dt
d t t   kstt
t tt	  tt  } t | @ ttj
tj
ttjtj ttjtj kstt j| ddd  kr t| ks&n tt | @ t | ks>ttt | @  dksXtt jdddtj  krtdksn tt dt dkstt tj tjkstt t
ttj
tj
tj ttj
tjtj	  ttj
tjtj  kstt t
 t  kr&tt
ks,n tt t
t t ttj
tj tj tj
tj ttj
tj tj tjtj	  ttj
tj tj tjtj  kstt jt
t t ddtt t tt
 t	  t
t t    krtt
t t ksn tt t
t t t t
t t ks&tt dt
d   dt
 t ksLtt ttt t
  t tt t
d  t ttt t
 t	  ksttjt @ ttjksttjt @ t tjkst| t @ tj tjkst| t @ tj tjksttt @ t
 dks&tt	t @ t dks@ttt @ t dksZttt @ t
t t  tt kst| t @ t
 t
kst| t @ t
t t  dt
 t t kst| t @ t
t t tj
tj tj kst| t @ t
t t  t
t t kst| t @ |  | ks8ttt @ |  tksRtt	t @ |  t	kslttt @ |  tkst| t @ tj tjksttt
t t tjksttt
d tdksttt
d td  td  dtd  td  dt
d  td   dt
d  td   k	s8ttd	d
dddgd}tdddddgd}t|j|j |j d|j t|j|jd t|j   k	stt|j|j |j d|j k	sttt
t t tt	 t  tjk	sttt
td  t tt	 t  dt
 t t dt
 t t	  dt
 t t  k
sHtd S )N   Tdoitr            A	sphericalrthetaphiZtransformationvariable_namesBcylindricalz)delopr   zeroAssertionErrorr   r   Zcrossiyjxr*   kr   r   r   Zeror   dotr   r   ar	   r   r   r   r#   r$   r%   )vr!   r(    r7   K/tmp/pip-unpacked-wheel-6uje5nh9/sympy/vector/tests/test_field_functions.pytest_del_operator   s    $.
>
&(
,,>,$:
,*
"
(&,
&.,*:
D&(.r9   c                  C   s   dt  t t } t t tt  tt   }t d t dt  td t t  }dt t t t t  }t| | dd}| t| |t|    }t|t|kst	t||@  }|t|A A |t|A A  |t@ | |t@ |  }t|t|kst	t| | @  }| t|@  |t| @   }t|t|ks>t	t||A @  }|t|A @ |t|A @   }t|t|kst	t| | A  }t| |A | t|A    }t|t|kst	t||A A  }|t|@  |t|@   |t@ | |t@ |  }t|t|kst	dS )z
    Tests the six product rules defined with respect to the Del
    operator

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Del

    r   r   Tr   N)
r1   r/   r*   r.   r0   r2   r+   r   r   r-   )fgur6   lhsrhsr7   r7   r8   test_product_rulesv   s<    $



r?   Pr   r       c                   C   s  t tjdkstt tdks"tt dt dt  dt  dksFtt tt t t	t t  t	t t  dksvtt t	t dkstt t
dkstt tdkstt dt	 t t t dt	d  t t  dkstt ttj tj	t  dkstd S )NTr   r    r   F)r   r   r,   r-   r.   r0   r2   r/   r*   r1   
grad_field
curl_fieldr@   r7   r7   r7   r8   test_conservative   s    $&*rD   c                   C   s  t tjdkstt tdks"tt dt dt  dt  dksFtt tt t t	t t  t	t t  dksvtt tt dkstt t
dkstt tdkstt dt d t dkstt ttt ttt  tttj  dkstt ttj tj	t  dkstd S )NTr   r    r   F)r   r   r,   r-   r.   r0   r2   r/   r*   r1   rB   rC   r   qr	   r@   r7   r7   r7   r8   test_solenoidal   s    $&2rG   c                  C   s~  t tjtj tj dtj dtj  tj tjtj dtj tj  dtj tj  ks^tt dtjd  tj dtj dtj  tj dtjd  dtj tj  kstt dtjd  tj dtj t	j
ksttdddd	d
gdddgd} |  \}}}|  \}}}t |d | |d| | ks6tt d|d  | d| d|  | d|d  d| |  ksztd S )Nr    r   rA   r      Dr"   r#   r$   r%   e_re_thetae_phi)r'   Zvector_names)r   r   r1   r/   r*   r.   r0   r2   r-   r   r3   r   base_scalarsbase_vectors)rI   r#   r$   r%   rJ   rK   rL   r7   r7   r8   test_directional_derivative   s    ^R*$rO   c                   C   s  t tjtdkstt tttks&tt tttks8tt t	tt
ksJtt tt
 t tt
 t  tt t	  ttt t
 kstt tttkstt t
tj tjt	  ttt
 tt tt
 tt  kstt t
tj tjt	  ttjtj
 kstttdd  d S )Nr   c                   S   s   t tt tS )N)r   r1   r0   r   r7   r7   r7   r8   <lambda>       z'test_scalar_potential.<locals>.<lambda>)r   r   r,   r   r-   r.   r1   r0   r/   r2   r*   rB   scalar_fieldr@   r   rF   r	   r   
ValueErrorr7   r7   r7   r8   test_scalar_potential   s    :>*rT   c                  C   s  t jddt dt  dt  } t jddt dt  dt  }t jd	tt tt  tt  }t	jd
t	jt	j t	jt	j  t	jt	j  }t
tjt | |dkstt
tt t j|tkstt
tt t j|tkstt
tt | |dkstt
tt t tt t  tt t  t | |tt t d ks6tdt	j t	jtt t	jtt   t	jtt t	jtt  d  }t
tt	t	j| | kstd S )NZP1r   r   r    ZP2r   rA      ZRPZPPr   i  )r   originZ
locate_newr.   r0   r2   r1   r/   r*   r@   r   r   r3   r-   rR   rB   r	   rF   r   r   )Zpoint1Zpoint2ZgenericpointCZgenericpointPZpotential_diff_Pr7   r7   r8    test_scalar_potential_difference   sB    """.


 
$
rW   c                  C   s  t dddddgd} t ddddd	gd}td
| j d| j  d
| j d| j | j  ks^ttd
| j | j d| j  d
| j | j d| j | j  d
t| j | j	  ksttd| j d| j  d| j  t
jkstt| j| j | j | j| j | j | j| j  | jt| j | j	  ks0tt| j| j | j| j  | j| j	  t| j| j t| j| j | j  t| j| jd   d
 dt| j| j   ksttd
| j | j | j | j| j  | j| j | j | j	  t| j| j t| j| j | j  t| j| jd   d| j  | jt| j  ksHttt
jdks\ttd| j d| j  d| j	  dkstt| j| j | j| j  | j| j	  t| j| j t| j| j  | j | j | j | j  | j| j | j	  kstt| j| j | j| j	  t| j| j t| j| j  | j | j | j | j  d| j	  kshttd|j d|j  d|j  t
jkstt|j|j |j |j|j |j |j|j  |j|j |j	  ksttd
|j d
|j ks ttd|j d|j |j ks$ttd|j d|j	 ksBtt|j|j |j|j  |j|j	  d
d|j  ks~tt|j|j |j|j	  dkstt|j|j |j|j	  d|j	 ksttd
|j d|j |j  d|j	  t
jkstd S )Nr!   r"   r#   r$   r%   r&   r(   r)   r*   r    r   r   r   r   	   )r   r   r#   r$   r.   r0   r-   r%   r	   r2   r   r,   r   r   r   r*   )r!   r(   r7   r7   r8   .test_differential_operators_curvilinear_system   s6    6V,P&P
<R
,&J
f.L$<&,rY   c                  C   s  t d} t d}t d}t| j|j |j| j | j|j  ksDttdtt | j |j | j| jtt|j    | jd|j tt  | j | j|j tt | j  d| j tt | j |j  kstt| j|j t	| j|j ksttt| j|j t	t| j|j ks&ttdtt | j |j | j
 | j |j|j
  t| j| j |j
  d| j | j
 |j tt |j
t| j| j   | j d| j | j
 |j tt |j
t| j| j   | j  d| j | j |j tt | j  d| j | j | j
 tt |j  |j
|j  |jt| j| j  |j  ksZtt| j| j | j| j  | j
| j  |j|j  |j|j  |j
|j  |j|j  |j|j  |j
|j  tdksttd| j | j | j
 |j|j |j
  d| j | j
 | j  d| j
 |jt|j|j  ks>ttdtt | j |j |j |j d| j |j tt t|j|j d| j |j tt  d|j |j tt t|j| j  kstt| j|j |j t| j| j | j|j  | j|j |j tt| j| j | j|j  |j|j tt| j| j | j|j | j  | j|j tt| j| j | j|j |j  | j|j tt| j| j | j|j |j  kstt| j|j |j | j| j |j|j   d| j |j |j | jd |j t| j|j  | jd |j t| j|j  |jd |j t|j| j  | j|jd  t|j|j  kstd S )	Nr5   bcr    rX   rU   r   r   )r   r   r1   r/   r.   r0   r-   r   rF   r   r*   r	   r2   r   r   r
   r   r   )r5   rZ   r[   r7   r7   r8   test_mixed_coordinates  sb    ,4T$.H88""

~@
&b
..,,,
,r\   N)?Zsympy.core.functionr   Zsympy.vector.vectorr   Zsympy.vector.coordsysrectr   Zsympy.simplifyr   Zsympy.core.symbolr   Z
sympy.corer   Z(sympy.functions.elementary.trigonometricr   r	   r
   Zsympy.vector.operatorsr   r   r   r   r   r   Zsympy.vector.deloperatorr   Zsympy.vector.functionsr   r   r   r   r   r   Zsympy.testing.pytestr   r   rN   r.   r0   r2   rM   r1   r/   r*   r+   r5   rZ   r[   rF   r9   r?   Zorient_new_axisr@   rR   rB   Zvector_fieldrC   rD   rG   rO   rT   rW   rY   r\   r7   r7   r7   r8   <module>   s<     _3(!