-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathadvection.py
68 lines (52 loc) · 1.6 KB
/
advection.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import taichi as ti
from differentiation import diff_x, diff_y, fdiff_x, fdiff_y, sample
@ti.func
def advect(vc, phi, i, j, dx):
"""Central Differencing"""
return vc[i, j].x * diff_x(phi, i, j, dx) + vc[i, j].y * diff_y(phi, i, j, dx)
@ti.func
def advect_upwind(vc, phi, i, j, dx):
"""Upwind differencing
http://www.slis.tsukuba.ac.jp/~fujisawa.makoto.fu/cgi-bin/wiki/index.php?%B0%DC%CE%AE%CB%A1#tac8e468
"""
k = i if vc[i, j].x < 0.0 else i - 1
a = vc[i, j].x * fdiff_x(phi, k, j, dx)
k = j if vc[i, j].y < 0.0 else j - 1
b = vc[i, j].y * fdiff_y(phi, i, k, dx)
return a + b
@ti.func
def advect_kk_scheme(vc, phi, i, j, dx):
"""Kawamura-Kuwabara Scheme
http://www.slis.tsukuba.ac.jp/~fujisawa.makoto.fu/cgi-bin/wiki/index.php?%B0%DC%CE%AE%CB%A1#y2dbc484
"""
coef = [-2, 10, -9, 2, -1]
v = ti.Vector([0.0, 0.0, 0.0, 0.0, 0.0])
if vc[i, j].x < 0:
v = ti.Vector(coef)
else:
v = -ti.Vector(coef[::-1])
mx = ti.Matrix.cols(
[
sample(phi, i + 2, j),
sample(phi, i + 1, j),
sample(phi, i, j),
sample(phi, i - 1, j),
sample(phi, i - 2, j),
]
)
a = mx @ v / (6 * dx)
if vc[i, j].y < 0:
v = ti.Vector(coef)
else:
v = -ti.Vector(coef[::-1])
my = ti.Matrix.cols(
[
sample(phi, i, j + 2),
sample(phi, i, j + 1),
sample(phi, i, j),
sample(phi, i, j - 1),
sample(phi, i, j - 2),
]
)
b = my @ v / (6 * dx)
return vc[i, j].x * a + vc[i, j].y * b