-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoordinates.py
79 lines (53 loc) · 985 Bytes
/
coordinates.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
69
70
71
72
73
74
75
76
77
78
79
"""
Holds all the computation relevant to coordinate systems.
"""
from constants import unit_roll
"""
U is x dimension velocity, with the i component
V is y dimension velocity, with the j component
arrays are [y, x]
[j, i]
h = half
m = minus one
p = plus one
Coordinates:
Pij Uij Pijp
Vij Vijp
Pipj Uipj Pipjp
grid is:
i h ip
j P U P
h V V
jp P U P
"""
def ipj(q):
"""
i+1,j
"""
return unit_roll(q, -1, 1)
def imj(q):
return unit_roll(q, 1, 1)
def ijp(q):
return unit_roll(q, -1, 0)
def ijm(q):
return unit_roll(q, 1, 0)
def imjp(q):
return imj(ijp(q))
def iph(q):
return (q + ipj(q)) / 2
def imh(q):
return (q + imj(q)) / 2
def jph(q):
return (q + ijp(q)) / 2
def jmh(q):
return (q + ijm(q)) / 2
def gradi(q_i, dx):
"""
Gradient at h of q_i
"""
return (ipj(q_i) - q_i) / dx
def gradj(q_j, dy):
"""
Gradient at h of q_i
"""
return (ijp(q_j) - q_j) / dy