-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexercise6.py
More file actions
31 lines (24 loc) · 955 Bytes
/
exercise6.py
File metadata and controls
31 lines (24 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
def eta_epsilon(r, epsilon):
return np.exp(-r**2 / (4 * epsilon**2)) / np.sqrt(4 * np.pi * epsilon**2)
def pse_diffusion_1d(D, epsilon, u, x, verlet, N, V):
du = np.zeros_like(u)
for p in range(N):
for q in verlet[p]:
du[p] += (u[q] - u[p])*eta_epsilon(x[q] - x[p], epsilon)*V[q]
return V*D/epsilon**2*du
def pse_diffusion_2d(D, epsilon, u, positions, verlet, N, V):
du = np.zeros_like(u)
for p in range(N):
for q in verlet[p]:
r = np.linalg.norm(positions[q] - positions[p])
du[p] += (u[q] - u[p])*eta_epsilon(r, epsilon)*V[q]
return V*D/epsilon**2*du
def periodic_boundaries(u):
n = int(np.sqrt(len(u)))
u_reshaped = u.reshape((n, n))
u_reshaped[:, 0] = u_reshaped[:, -2]
u_reshaped[:, -1] = u_reshaped[:, 1]
u_reshaped[0, :] = u_reshaped[-2, :]
u_reshaped[-1, :] = u_reshaped[1, :]
return u_reshaped.flatten()