\begin{align} \frac{{d{{\mathbf{x}}_i}}}{{dt}} &= {{\mathbf{v}}_i} \hfill \\ \frac{{d{{\mathbf{v}}_i}}}{{dt}} &= \frac{{{q_i}}}{{{m_i}}}\left( {{\mathbf{E}} + {{\mathbf{v}}_i} \times {\mathbf{B}}} \right) \hfill \\ \frac{{\partial {\mathbf{B}}}}{{\partial t}} &= - c\nabla \times {\mathbf{E}} \hfill \\ \nabla \times {\mathbf{B}} &= \frac{{4\pi }}{c}{\mathbf{J}} = \frac{{4\pi }}{c}{q_i}{n_i}\left( {{{\mathbf{V}}_i} - {{\mathbf{V}}_e}} \right) \hfill \\ e{n_e} &= {q_i}{n_i} \hfill \\ {n_e}{m_e}\frac{{d{{\mathbf{V}}_e}}}{{dt}} &= 0 = - \frac{{{{\mathbf{V}}_i} \times {\mathbf{B}}}}{c} - \frac{{\nabla {P_e}}}{{{q_i}{n_i}}} - \frac{{{\mathbf{B}} \times \left( {\nabla \times {\mathbf{B}}} \right)}}{{4\pi {q_i}{n_i}}} \hfill \\ \end{align}
We solve those equations with CAM_CL method [Matthews1994JCP].
In this simulation, $v_A$ (Alfv\'en speed) is the unit of speed, $c/\omega_{pi}=v_A/\Omega_{ci}$ (ion inertial length) is the unit of length, $\Omega_{ci}^{-1}$ (cyclotron time) is the unit of time.
%%bash
cat input.f90
%config InlineBackend.figure_format = 'retina'
from numba import jit,f8,u8
import numpy as np
import math as mt
import matplotlib.pyplot as plt
import math as mt
from scipy.fftpack import fft, ifft,fft2,ifft2,fftshift,ifftshift
import time
from IPython import display
plt.rcParams['font.size'] = 14
plt.rcParams['axes.linewidth'] = 1.5
nx=512
nt=1024
isav=8
dx=0.5
dt=0.025*isav
lx=dx*nx
lt=dt*nt
f1 =open('data/exhst.d' ,'r')
f2 =open('data/eyhst.d' ,'r')
f3 =open('data/ezhst.d' ,'r')
f4 =open('data/bxhst.d' ,'r')
f5 =open('data/byhst.d' ,'r')
f6 =open('data/bzhst.d' ,'r')
f7 =open('data/nihst.d' ,'r')
f8 =open('data/vixhst.d' ,'r')
f9 =open('data/viyhst.d' ,'r')
f10=open('data/vizhst.d' ,'r')
exhst =np.fromfile(f1, dtype='float64',sep=" ").reshape(-1,nx)
eyhst =np.fromfile(f2, dtype='float64',sep=" ").reshape(-1,nx)
ezhst =np.fromfile(f3, dtype='float64',sep=" ").reshape(-1,nx)
bxhst =np.fromfile(f4, dtype='float64',sep=" ").reshape(-1,nx)
byhst =np.fromfile(f5, dtype='float64',sep=" ").reshape(-1,nx)
bzhst =np.fromfile(f6, dtype='float64',sep=" ").reshape(-1,nx)
nihst =np.fromfile(f7, dtype='float64',sep=" ").reshape(-1,nx)
vixhst=np.fromfile(f8, dtype='float64',sep=" ").reshape(-1,nx)
viyhst=np.fromfile(f9, dtype='float64',sep=" ").reshape(-1,nx)
vizhst=np.fromfile(f10,dtype='float64',sep=" ").reshape(-1,nx)
plt.figure(figsize=(12,12))
plt.subplot(221);plt.imshow(nihst,origin='lower',cmap='jet',aspect='auto',extent=(0,nx*dx,0,nt*dt))
plt.title(r'$\rho_i$');plt.xlabel(r'$x/(c/\omega_{pi})$');plt.ylabel(r'$t\Omega_{ci}$')
plt.subplot(222);plt.imshow(vixhst,origin='lower',cmap='jet',aspect='auto',extent=(0,nx*dx,0,nt*dt))
plt.title(r'$V_i$');plt.xlabel(r'$x/(c/\omega_{pi})$');plt.ylabel(r'$t\Omega_{ci}$');#plt.colorbar()
plt.subplot(223);plt.imshow(exhst,origin='lower',cmap='bwr',aspect='auto',extent=(0,nx*dx,0,nt*dt))
plt.title(r'$E_x$');plt.xlabel(r'$x/(c/\omega_{pi})$');plt.ylabel(r'$t\Omega_{ci}$')
plt.subplot(224);plt.imshow(byhst,origin='lower',cmap='bwr',aspect='auto',extent=(0,nx*dx,0,nt*dt))
plt.title(r'$B_z$');plt.xlabel(r'$x/(c/\omega_{pi})$');plt.ylabel(r'$t\Omega_{ci}$')
plt.show()
tt=dt*np.arange(nt)
bhst=np.sqrt(byhst**2+bzhst**2)
plt.plot(tt,np.mean(exhst**2,axis=1),label=(r'$E_x^2$'))
plt.plot(tt,np.mean(eyhst**2,axis=1),label=(r'$E_y^2$'))
plt.plot(tt,np.mean(ezhst**2,axis=1),label=(r'$E_z^2$'))
plt.plot(tt,np.mean(byhst**2,axis=1),label=(r'$B_y^2$'))
plt.plot(tt,np.mean(bzhst**2,axis=1),label=(r'$B_z^2$'))
plt.legend()
plt.xlabel(r'$t\Omega_{ci}$');plt.ylabel(r'$|B|$');
plt.yscale('log')
plt.show()
%%time
plt.figure(figsize=(12,8))
fftbz=fftshift(fft2(bzhst[:,:]))
bzpls=np.zeros((nt,nx), dtype=np.complex)
bzmin=np.zeros((nt,nx), dtype=np.complex)
plt.subplot(131)
plt.imshow(bzhst,aspect='auto',origin='lower',extent=[0,lx,0,lt],clim=(-2,2),cmap='bwr')
plt.colorbar()
plt.title(r'$B_z^{raw}$')
plt.xlabel(r'$x/(c/\omega_{e})$')
plt.ylabel(r'$t\Omega_{ci}$')
plt.subplot(132)
bzpls[0:nt//2,nx//2:nx]=fftbz[0:nt//2,nx//2:nx]
bzpls[nt//2:nt,0:nx//2]=fftbz[nt//2:nt,0:nx//2]
bzpls=ifft2(ifftshift(bzpls))
plt.imshow(np.real(bzpls),aspect='auto',origin='lower',extent=[0,lx,0,lt],clim=(-1.5,1.5),cmap='bwr')
plt.colorbar()
plt.title(r'$B_z^+$')
plt.subplot(133)
bzmin[0:nt//2,0:nx//2] =fftbz[0:nt//2,0:nx//2]
bzmin[nt//2:nt,nx//2:nx]=fftbz[nt//2:nt,nx//2:nx]
bzmin=ifft2(ifftshift(bzmin))
plt.imshow(np.real(bzmin),aspect='auto',origin='lower',extent=[0,lx,0,lt],clim=(-1,1),cmap='bwr')
plt.colorbar()
plt.title(r'$B_z^-$')
plt.show()