forked from JanisErdmanis/PythonPhysics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
9.5.py
53 lines (39 loc) · 798 Bytes
/
9.5.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 19 22:01:36 2013
@author: akels
"""
from __future__ import division, print_function
from pylab import *
h = 2e-6
L = 1
v = 100
d = 0.1
C = 1
sigma = 0.3
N = 500 # grid spacings
a = L/N
def phi0(x):
return C * x*(L-x)/L**2*exp(- (x-d)**2/2/sigma**2)
fi = zeros(N+1,float)
x = linspace(0,L,N+1)
phi = phi0(x)
#t = 0
#t_end = 50e-3/100
def iterate(fi,phi,dt=50e-3):
iterations = int(dt/h)
for i in range(iterations):
fi[1:N] += h*phi[1:N]
phi[1:N] += h*v**2/a**2*(fi[2:N+1] + fi[0:N-1] - 2*fi[1:N])
#t +=h
return fi,phi
#fi,phi = iterate(fi,phi,iterations = int(50e-3/h))
#plot(fi)
#show()
from visual import curve,rate
c = curve()
c.set_x(x - L/2)
while True:
rate(30)
c.set_y(fi*2e3)
fi,phi = iterate(fi,phi,dt = 50e-3/100)