In [1]:
#Packages are defined here.
%config InlineBackend.figure_format='retina'
import numpy as np
import matplotlib.pyplot as plt
from IPython import display
from subprocess import Popen

Parameters

  • $n_x=512$, $n_y=128$
  • $ppc=400$
  • $n_t=8192$
  • $d_x=0.5$, $d_y=0.5$
  • $d_t=0.1$
  • $n_{CL}=10$ (sub-cycle time steps)
  • $\beta_e=0.02$
  • $\beta_i=10^{-4}$
  • $\theta_{B}=0^\circ$
In [24]:
nx=512
ny=128
dx=0.5
dy=0.1
dt=0.1
Lx=nx*dx  
Ly=ny*dy  

Snapshots

In [27]:
%%time
it=200
f1 =open('data/ex%05d.d' %(it),'r')
f2 =open('data/ey%05d.d' %(it),'r')
f3 =open('data/ez%05d.d' %(it),'r')
f4 =open('data/bx%05d.d' %(it),'r')
f5 =open('data/by%05d.d' %(it),'r')
f6 =open('data/bz%05d.d' %(it),'r')
f7 =open('data/rho%05d.d' %(it),'r')
f8 =open('data/jix%05d.d' %(it),'r')
f9 =open('data/jiy%05d.d' %(it),'r')
f10=open('data/jiz%05d.d' %(it),'r')

ex =np.fromfile(f1, dtype='float64',sep=" ").reshape(-1,nx)
ey =np.fromfile(f2, dtype='float64',sep=" ").reshape(-1,nx)
ez =np.fromfile(f3, dtype='float64',sep=" ").reshape(-1,nx)
bx =np.fromfile(f4, dtype='float64',sep=" ").reshape(-1,nx)
by =np.fromfile(f5, dtype='float64',sep=" ").reshape(-1,nx)
bz =np.fromfile(f6, dtype='float64',sep=" ").reshape(-1,nx)
rho=np.fromfile(f7, dtype='float64',sep=" ").reshape(-1,nx)
jix=np.fromfile(f8, dtype='float64',sep=" ").reshape(-1,nx)
jiy=np.fromfile(f9, dtype='float64',sep=" ").reshape(-1,nx)
jiz=np.fromfile(f10,dtype='float64',sep=" ").reshape(-1,nx)

display.clear_output(True)
plt.figure(figsize=(20,12))
plt.subplots_adjust(wspace=0.2, hspace=0.2)

plt.subplot(3,4,1) ;plt.imshow(ex,aspect='auto',origin='lower',cmap='jet');plt.colorbar();plt.title(r'$E_x$');    plt.tick_params(labelbottom='off',labelleft='off')
plt.subplot(3,4,2) ;plt.imshow(ey,aspect='auto',origin='lower',cmap='jet');plt.colorbar();plt.title(r'$E_y$');    plt.tick_params(labelbottom='off',labelleft='off')
plt.subplot(3,4,3) ;plt.imshow(ez,aspect='auto',origin='lower',cmap='jet');plt.colorbar();plt.title(r'$E_z$');    plt.tick_params(labelbottom='off',labelleft='off')
plt.subplot(3,4,5) ;plt.imshow(bx,aspect='auto',origin='lower',cmap='jet');plt.colorbar();plt.title(r'$B_x$');    plt.tick_params(labelbottom='off',labelleft='off')
plt.subplot(3,4,6) ;plt.imshow(by,aspect='auto',origin='lower',cmap='jet');plt.colorbar();plt.title(r'$B_y$');    plt.tick_params(labelbottom='off',labelleft='off')
plt.subplot(3,4,7) ;plt.imshow(bz,aspect='auto',origin='lower',cmap='jet');plt.colorbar();plt.title(r'$B_z$');    plt.tick_params(labelbottom='off',labelleft='off')
plt.subplot(3,4,9) ;plt.imshow(jix,aspect='auto',origin='lower',cmap='jet');plt.colorbar();plt.title(r'$J_{ix}$');    plt.tick_params(labelbottom='off',labelleft='off')
plt.subplot(3,4,10) ;plt.imshow(jiy,aspect='auto',origin='lower',cmap='jet');plt.colorbar();plt.title(r'$J_{iy}$');    plt.tick_params(labelbottom='off',labelleft='off')
plt.subplot(3,4,11) ;plt.imshow(jiz,aspect='auto',origin='lower',cmap='jet');plt.colorbar();plt.title(r'$J_{iz}$');    plt.tick_params(labelbottom='off',labelleft='off')
plt.subplot(3,4,12);plt.imshow(rho,aspect='auto',origin='lower',cmap='jet');plt.colorbar();plt.title(r'$\rho_i$');    plt.tick_params(labelbottom='off',labelleft='off')

plt.suptitle('it=%06d' %(it*dt))    
plt.show()
CPU times: user 7.08 s, sys: 24 ms, total: 7.1 s
Wall time: 7.11 s

Animation

In [3]:
!mkdir figures #if you have the directory, comment out this line.
In [10]:
%%bash
echo -e " 
import numpy as np
import matplotlib.pyplot as plt
nx=512
for it in range(1,400):
    f =open('data/rho%05d.d'   %(it),'r')
    #f3 =open('data/by%05d.d'   %(it),'rb')
    
    rho  =np.fromfile(f, dtype='float64',sep=' ').reshape(-1,nx)
    #by  =np.fromfile(f3, dtype='float64').reshape(-1,nx)
    
    fig=plt.figure(figsize=(16,4))
    #fig.suptitle(r"$t\omega_{pe}=%.2f$" %(it*dt), fontsize=16)
    plt.imshow(rho,aspect='auto',origin='lower',cmap='Blues');
    #plt.colorbar(shrink=0.15)#;plt.title(r'$B$')
    #plt.imshow(np.sqrt(by**2+bx**2),aspect='auto',origin='lower',cmap='bwr');plt.colorbar()#;plt.title(r'$B$')

    plt.savefig('figures/rho%03d.png' %(it), bbox_inches='tight',dpi=160)
    plt.close()
" > animation.py
In [11]:
proc = Popen(["python", "animation.py"], shell=False)
In [28]:
!convert -delay 10 -loop 0 figures/rho*.png hybrid2d_rho.gif