Skip to content
Snippets Groups Projects
Commit 2f21fc2a authored by Anton Akhmerov's avatar Anton Akhmerov
Browse files

Merge branch 'animation-drude-model' into 'master'

animate random walkers

See merge request !69
parents 07d00301 f155f774
No related branches found
No related tags found
1 merge request!69animate random walkers
Pipeline #28605 passed
......@@ -26,17 +26,20 @@ Ohm's law states that $V=IR=I\rho\frac{l}{A}$. In this lecture we will investiga
- In-between scattering events electrons respond to the Lorentz force ${\bf F}_{\rm L}=-e\left({\bf E}+{\bf v}\times{\bf B}\right)$.
```python
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
from IPython.display import HTML
walker_number = 20 # number of particles
walkers = 20 # number of particles
tau = 1 # relaxation time
gamma = .3 # dissipation strength
a = 1 # acceleration
dt = .1 # infinitesimal
T = 20 # simulation time
v = np.zeros((2, int(T // dt), walker_number), dtype=float)
v = np.zeros((2, int(T // dt), walkers), dtype=float) #
scattering_events = np.random.binomial(1, dt/tau, size=v.shape[1:])
angles = np.random.uniform(high=2*np.pi, size=scattering_events.shape) * scattering_events
......@@ -59,9 +62,36 @@ r = np.cumsum(v * dt, axis=1)
scattering_positions = np.copy(r)
scattering_positions[:, ~scattering_events.astype(bool)] = np.nan
plt.plot(*r[:, :100], alpha=.5, c='#1f77b4');
plt.scatter(*scattering_positions[:, :100], s=10);
fig = plt.figure()
scatter_pts = scattering_positions[:, :100]
trace = r[:, :100]
nz_scatters = tuple((np.hstack(scatter_pts[0])[~np.isnan(np.hstack(scatter_pts[0]))],
np.hstack(scatter_pts[1])[~np.isnan(np.hstack(scatter_pts[1]))]))
plt.axis([min(nz_scatters[0])-1,
max(nz_scatters[0])+1,
min(nz_scatters[1])-1,
max(nz_scatters[1])+1])
lines = []
scatterers = []
for index in range(walkers):
lobj = plt.plot([],[], lw=1, color='b', alpha=0.5)[0]
lines.append(lobj)
scatterers.append(plt.scatter([], [], s=10, c='r'))
def animate(i):
for lnum, line in enumerate(lines):
line.set_data(trace[0][:i, lnum], trace[1][:i, lnum])
data = np.stack((scatter_pts[0][:i,lnum], scatter_pts[1][:i, lnum])).T
scatterers[lnum].set_offsets(data)
#
anim = animation.FuncAnimation(fig, animate, interval=100)
plt.axis('off');
HTML(anim.to_html5_video())
```
We start by considering only an electric field (_i.e._ ${\bf B}=0$). What velocity do electrons acquire in-between collisions?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment