-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpflow.py
185 lines (148 loc) · 4.64 KB
/
pflow.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
"""
Module:
Function definitions for various potential flows
"""
import numpy as np
def source(xs, ys, Sstr, X, Y):
"""
Returns the velocity and stream function field generated by the source(s)
Parameters
----------
xs: Numpy column vector
x-coordinates of the sources
ys: Numpy column vector
y-coordinates of the sources
Sstr: Numpy column vector
strengths of the sources
X, Y: 2D np arrays
grid generated by np.meshgrid( )
Returns
-------
u: 2D Numpy array of floats
x-component of the velocity field
v: 2D Numpy array of floats
y-component of the velocity field
psi: 2D np array of floats
stream function field
"""
# initialize u, v and psi
u = np.zeros(np.shape(X))
v = np.zeros(np.shape(X))
psi = np.zeros(np.shape(X))
for i in range(0, np.shape(xs)[0]):
# radial distance and angle from source
r = np.sqrt( (X - xs[i])**2 + (Y - ys[i])**2)
theta = np.arctan2(Y - ys[i], X - xs[i])
# velocity field
u = u + 0.5 * Sstr[i] / (np.pi * r) * np.cos(theta)
v = v + 0.5 * Sstr[i] / (np.pi * r) * np.sin(theta)
# stream function
psi = psi + 0.5 * Sstr[i] / np.pi * np.arctan2((Y - ys[i]), (X - xs[i]))
return u, v, psi
def vortex(xv, yv, Vstr, X, Y):
"""
Returns the velocity and stream function field generated by the source
Parameters
----------
xv: 1D Numpy Array
x-coordinates of the vortices
yv: 1D Numpy array
y-coordinate of the vortices
Vstr: float
strength of the vortices
X, Y: 2D np arrays
grid generated by np.meshgrid( )
Returns
-------
u: 2D Numpy array of floats
x-component of the velocity field
v: 2D Numpy array of floats
y-component of the velocity field
psi: 2D Numpy array of floats
stream function field
"""
# initialize u, v and psi
u = np.zeros(np.shape(X))
v = np.zeros(np.shape(X))
psi = np.zeros(np.shape(X))
for i in range(0, np.shape(xv)[0]):
# radial distance and angle of grid points from vortex
r = np.sqrt((X - xv[i])**2 + (Y - yv[i])**2)
theta = np.arctan2(Y - yv[i], X - xv[i])
V = - Vstr[i] / (2 * np.pi * r) # vortex velocity
# velocity field
u = u + V * np.cos(theta + np.pi / 2)
v = v + V * np.sin(theta + np.pi / 2)
# stream function
psi = psi + 0.5 * Vstr[i] / np.pi * np.log(r)
return u, v, psi
def doublet(xd, yd, Dstr, X, Y):
"""
Returns velocity field and stream function generated by doublets
Parameters
----------
X, Y: 2D Numpy array
grid generated by numpy.meshgrid()
xd, yd: 1D Numpy array of floats
positions of doublets
Dstr: 1D Numpy array of floats
strengths of doublets
Returns
-------
u, v: 2D Numpy array
velocity field
psi: 2D Numpy array
stream function
"""
# initialize u, v and psi
u = np.zeros(np.shape(X))
v = np.zeros(np.shape(X))
psi = np.zeros(np.shape(X))
for i in range(0, np.shape(xd)[0]):
# velocity field
u = u - 0.5 * Dstr[i] / np.pi * ((X - xd[i])**2 - (Y - yd[i])**2) / ((X - xd[i])**2 + (Y - yd[i])**2)**2
v = v - 0.5 * Dstr[i] / np.pi * 2 * (X - xd[i]) * (Y-yd[i]) / ((X-xd[i])**2 + (Y-yd[i])**2)**2
# stream function
psi = psi - 0.5 * Dstr[i] / np.pi * (Y - yd[i]) / ((X-xd[i])**2 + (Y-yd[i])**2)
return u, v, psi
def freestream(U, aoa, X, Y):
"""
Returns uniform flow velocity field and stream function
Parameters
----------
U: float
uniform flow velocity
aoa: float
angle of attack
X, Y: 2D Numpy array
grid points
Returns
-------
u, v: 2D Numpy arrays
x and y direction velocity fields
psi: 2D Numpy array of floats
stream function field
"""
# velocity field
u = U * np.cos(aoa) * np.ones(np.shape(X))
v = U * np.sin(aoa) * np.ones(np.shape(X))
# stream function
psi = U * Y
return u, v, psi
def cp_get(u, v, U):
"""
Returns coefficient of pressure given velocity field
Parameters
----------
u, v: 2D Numpy array
velocity field x and y components
U: float
free stream velocity
Returns
-------
cp: 2D Numpy array
pressure co-efficient field
"""
V = np.sqrt(u**2 + v**2)
cp = np.ones(np.shape(V)) - (V/U)**2
return cp