This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geometry.py
223 lines (177 loc) · 6.74 KB
/
geometry.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import matplotlib.pyplot as plt
from sympy import Point, Polygon, Line, Ray
from sympy.geometry import intersection
from sympy.geometry.entity import GeometrySet
from operator import itemgetter
from numpy import meshgrid
import math
import numpy
g= 9.81
coordinates = (
(0, 0),
(0,-10),
(60, -10),
(60, 0),
)
def angle(p1, p2):
k = (p2[1] - p1[1]) / Point(p1).distance(Point(p2))
x2 = p2[0]
x1 = p1[0]
if k >= 0:
if x2 >= x1: # First Quadrant
return (2.0 * math.pi - math.asin(k))
else: # Second Quadrant
return (math.pi + math.asin(k))
else:
if x2 >= x1: # Fourth Quadrant
return math.asin(-k)
else: # Third Quadrant
return (math.pi - math.asin(-k))
class ChannelSection:
"""A cross section taken normal to the direction of flow"""
def __init__(self, coordinates):
self.abscissas = []
self.ordinates = []
for i in range(len(coordinates)):
self.abscissas.append(coordinates[i][0])
self.ordinates.append(coordinates[i][1])
self.abscissas.append(coordinates[0][0])
self.ordinates.append(coordinates[0][1])
def lowest(self):
return sorted(coordinates, key=itemgetter(1))[0]
def plot_geometry(self):
plt.plot(self.abscissas, self.ordinates)
plt.title('Channel Section', fontsize=14, color='black')
plt.show()
class FlowArea(ChannelSection):
"""
Cross-section in which there is flow, has a height y(depth), Flow(QQ)
"""
def __init__(self, ChannelSection, depth, QQ):
self.ChannelSection = ChannelSection
self.depth = depth
self.QQ = QQ
def flow_area_polygon(self):
point_on_surface_above_lowest_depth = Point(self.ChannelSection.lowest()[0], self.ChannelSection.lowest()[1]+self.depth)
line = Line(point_on_surface_above_lowest_depth, Point(100, self.ChannelSection.lowest()[1]+self.depth))
i1, i2 = intersection(line, Polygon(*coordinates))
i1 = (i1[0], i1[1])
i2 = (i2[0], i2[1])
flow_coordinates = []
for p in coordinates:
if p[1] < self.ChannelSection.lowest()[1]+self.depth:
flow_coordinates.append(p)
if i1 not in flow_coordinates:
flow_coordinates.append(i1)
if i2 not in flow_coordinates:
flow_coordinates.append(i2)
def centroid(*points):
x_coords = [p[0] for p in points]
y_coords = [p[1] for p in points]
_len = len(points)
centroid_x = sum(x_coords) / _len
centroid_y = sum(y_coords) / _len
return [centroid_x, centroid_y]
return sorted(flow_coordinates, key = lambda point: -angle(point, centroid(*flow_coordinates)))
def free_surface_length(self):
"""
B
:return:
"""
point_on_surface_above_lowest_depth = Point(self.ChannelSection.lowest()[0], self.ChannelSection.lowest()[1]+self.depth)
line = Line(point_on_surface_above_lowest_depth, Point(0.5464321348512123132, self.ChannelSection.lowest()[1]+self.depth))
i1, i2 = intersection(line, Polygon(*coordinates))
return i1.distance(i2)
def wetted_perimeter(self):
"""
P
:return:
"""
flow_coordinates = []
for p in coordinates:
if p[1] > self.ChannelSection.lowest()[1] + self.depth:
pass
else:
flow_coordinates.append(p)
perimeter = 0
surface_points = []
surface_points = list( map(Point, flow_coordinates))
for i in range(0,len(surface_points)-1):
perimeter += surface_points[i].distance(surface_points[i+1])
return perimeter
def hydraulic_radius(self):
return self.area()/self.wetted_perimeter()
def hydraulic_depth(self):
return self.area()/self.free_surface_length()
def get_centroid(self):
points = self.flow_area_polygon()
return Polygon(*points).centroid
def area(self):
points = self.flow_area_polygon()
return Polygon(*points).area
def plot_geometry(self):
self.abscissas = []
self.ordinates = []
points = self.flow_area_polygon()
for i in range(len(points)):
self.abscissas.append(points[i][0])
self.ordinates.append(points[i][1])
self.abscissas.append(points[0][0])
self.ordinates.append(points[0][1])
plt.plot(self.abscissas, self.ordinates)
plt.title('Channel Section with flow depth', fontsize=14, color='black')
plt.show()
def specific_force(self):
"""
momentum function or specific force,
Q 2
Fs = -------- + z A
gA
:return: Fs
"""
specific_force = self.QQ*self.QQ/(g* self.area()) + (self.get_centroid()[1]-self.lowest()[1])*self.area()
return specific_force
def velocity(self):
return self.QQ / self.area()
def froude_number(self):
return self.velocity()/math.sqrt(g*self.depth)
def energy(self):
return self.depth + self.velocity()*self.velocity()/(2*g)
def hydraulic_jump_y2(self):
"""
Conservation of momentum flux
:return:
"""
y21= self.depth +(-1 + math.sqrt(1+ 8*self.froude_number()))/2
y22= self.depth +(-1 - math.sqrt(1+ 8*self.froude_number()))/2 # Negative answers do not yield meaningful physical solutions
return y21
def discharge_per_unit_length(self):
return self.QQ/self.free_surface_length()
def specific_energy_plot(self):
e = numpy.linspace(0,20.0, 100)
delta = 0.125
xrange = numpy.arange(0.0, 20.0, delta)
yrange = numpy.arange(0.0, 20.0, delta)
X, Y = meshgrid(xrange, yrange)
F = (X - Y)*Y*Y
G = (self.discharge_per_unit_length()*self.discharge_per_unit_length())/(2*g)
plt.plot(e, e, 'b--')
plt.contour(X, Y, (F - G), [0])
plt.title('Specific Energy E[m]', fontsize=14, color='black')
plt.xlabel('Specific Energy', fontsize=14, color='black')
plt.ylabel('Flow depth, y[m]', fontsize=14, color='black')
plt.show()
A = ChannelSection(coordinates)
A.plot_geometry()
Af = FlowArea(A, 5.55, 2500)
Af.plot_geometry()
print("Centroid :", Af.get_centroid())
print("Specific Force :", Af.specific_force())
print("velocity : ", Af.velocity())
print("Top Width: ", Af.free_surface_length())
print("Hydraulic Radius : ", Af.hydraulic_radius())
print("Hydraulic Depth : ", Af.hydraulic_depth())
print("Hydraulic Jump y2 : ", Af.hydraulic_jump_y2())
print("Area cross-section flow:", round(Af.area(), 2))
print("Froud number :", Af.froude_number())
Af.specific_energy_plot()