File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Solve linear advection equation
2
+
3
+ ### Try FTBS
4
+
5
+ from math import *
6
+ import numpy as np
7
+ import pylab
8
+
9
+ # Divide space into equal intervals
10
+ npoints = 40 # no of points
11
+
12
+ points = np .linspace (0 , 1 , npoints )
13
+
14
+ # Divide time into time steps
15
+ ntime = 100 # no of time steps
16
+
17
+ # Wind
18
+ # Courant number
19
+ c = 0.2
20
+ d = 1 - c
21
+
22
+ # Initial conditions (dar reikia paziureti, kaip efektyviau padaryti)
23
+ # Pabandyti ir kitas pradines salygas
24
+ phi_new = []
25
+ for x in points :
26
+ if x <= 0.5 :
27
+ phi_new .append (0.5 * (1 - cos (4 * pi * x )))
28
+ else :
29
+ phi_new .append (0 )
30
+
31
+ phi_new = np .array (phi_new )
32
+ pylab .plot (points , phi_new )
33
+
34
+ for tstep in range (ntime ): # ntime
35
+ #phi_new = np.array(phi_new)
36
+ #pylab.plot(point, phi_new)
37
+ phi_old = phi_new [:]
38
+ phi_new = []
39
+ for j in range (npoints ):
40
+ phi_new .append (d * phi_old [j ] + c * phi_old [j - 1 ])
41
+
42
+ phi_new = np .array (phi_new )
43
+ pylab .plot (points , phi_new )
44
+
45
+ # Jeigu tasku skaicius ir c kitoks, kazkuriuo metu pabaiga pradeda
46
+ # kilti ir tada persinesa visa banga i sona. Kodel ir ar susije su krastais
You can’t perform that action at this time.
0 commit comments