Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
lectures
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Solid state physics
lectures
Commits
d1e86a14
Verified
Commit
d1e86a14
authored
3 years ago
by
Anton Akhmerov
Browse files
Options
Downloads
Patches
Plain Diff
improve and speed up drude animation
parent
fd1ec3cb
No related branches found
Branches containing commit
No related tags found
1 merge request
!108
rework plots
Pipeline
#60424
passed
3 years ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/3_drude_model.md
+26
-39
26 additions, 39 deletions
src/3_drude_model.md
with
26 additions
and
39 deletions
src/3_drude_model.md
+
26
−
39
View file @
d1e86a14
```
python tags=["initialize"]
from matplotlib import pyplot
import matplotlib.animation as animation
from IPython.display import HTML
import numpy as np
from common import draw_classic_axes, configure_plotting
...
...
@@ -61,21 +62,21 @@ Even under these simplistic assumptions, the trajectory of the electrons is hard
Due to the random scattering, each trajectory is different, and this is how several example trajectories look:
```
python
%
matplotlib
inline
import
matplotlib.pyplot
as
plt
import
numpy
as
np
import
matplotlib.animation
as
animation
from
IPython.display
import
HTML
# Use colors from the default color cycle
default_colors
=
pyplot
.
rcParams
[
'
axes.prop_cycle
'
].
by_key
()[
'
color
'
]
blue
,
red
=
default_colors
[
0
],
default_colors
[
3
]
walkers
=
20
# number of particles
tau
=
1
# relaxation time
gamma
=
.
3
# dissipation strength
a
=
1
# acceleration
dt
=
.
1
# infinitesimal
T
=
2
0
# simulation time
T
=
1
0
# simulation time
v
=
np
.
zeros
((
2
,
int
(
T
//
dt
),
walkers
),
dtype
=
float
)
#
# Select random time steps and scattering angles
np
.
random
.
seed
(
1
)
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
rotations
=
np
.
array
(
...
...
@@ -97,47 +98,33 @@ r = np.cumsum(v * dt, axis=1)
scattering_positions
=
np
.
copy
(
r
)
scattering_positions
[:,
~
scattering_events
.
astype
(
bool
)]
=
np
.
nan
fig
=
plt
.
figure
()
scatter_pts
=
scattering_positions
[:,
:
100
]
trace
=
r
[:,
:
100
]
scatter_pts
=
scattering_positions
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
]))]))
r_min
=
np
.
min
(
r
.
reshape
(
2
,
-
1
),
axis
=
1
)
-
1
r_max
=
np
.
max
(
r
.
reshape
(
2
,
-
1
),
axis
=
1
)
+
1
plt
.
axis
([
min
(
nz_scatters
[
0
])
-
1
,
max
(
nz_scatters
[
0
])
+
1
,
min
(
nz_scatters
[
1
])
-
1
,
max
(
nz_scatters
[
1
])
+
1
]
)
fig
=
py
pl
o
t
.
figure
(
figsize
=
(
9
,
6
))
ax
=
fig
.
add_subplot
(
1
,
1
,
1
)
ax
.
axis
(
"
off
"
)
ax
.
set
(
xlim
=
(
r_min
[
0
],
r_max
[
0
]),
ylim
=
(
r_min
[
1
],
r_max
[
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
'
))
trajectories
=
ax
.
plot
([],[],
lw
=
1
,
color
=
blue
,
alpha
=
0.5
)[
0
]
scatterers
=
ax
.
scatter
([],
[],
s
=
20
,
c
=
red
)
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
)
def
frame
(
i
):
concatenated_lines
=
np
.
concatenate
(
(
r
[:,
:
i
],
np
.
nan
*
np
.
ones
((
2
,
1
,
walkers
))),
axis
=
1
).
transpose
(
0
,
2
,
1
).
reshape
(
2
,
-
1
)
trajectories
.
set_data
(
*
concatenated_lines
)
scatterers
.
set_offsets
(
scatter_pts
[:,
:
i
].
reshape
(
2
,
-
1
).
T
)
anim
=
animation
.
FuncAnimation
(
fig
,
animat
e
,
interval
=
100
)
anim
=
animation
.
FuncAnimation
(
fig
,
fram
e
,
interval
=
100
)
def
remove_axes
(
ax
):
ax
.
spines
[
'
bottom
'
].
set_color
(
'
white
'
)
ax
.
spines
[
'
top
'
].
set_color
(
'
white
'
)
ax
.
spines
[
'
right
'
].
set_color
(
'
white
'
)
ax
.
spines
[
'
left
'
].
set_color
(
'
white
'
)
ax
.
tick_params
(
axis
=
'
x
'
,
colors
=
'
white
'
)
ax
.
tick_params
(
axis
=
'
y
'
,
colors
=
'
white
'
)
remove_axes
(
plt
.
gca
());
plt
.
close
();
pyplot
.
close
()
HTML
(
anim
.
to_html5_video
())
```
---
### Equations of motion
Our goal is finding the
*electric current density*
$j$.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment