-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen_flow.py
254 lines (210 loc) · 7.67 KB
/
open_flow.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# Imports
from sympy import Symbol, nsolve, sqrt, acos, sin, lambdify, re, solve
import numpy as np
from matplotlib import pyplot as plt
import sys
# Variables definition
'''
https://www.eng.auburn.edu/~xzf0001/Handbook/Channels.html
'n': "Manning's Coef.",
'So': 'Channel Slope [m/m]',
'Q': 'Flow Rate [m3/s]',
'y': 'Depth [m]',
'b': 'Bottom Width [m]',
'z': 'Side Slope',
'D': 'Diameter [m]',
'a': 'Area [m2]',
'rh': 'Hydraulic Radius',
'dh': 'Hydraulic Depth',
'tw': 'Top Width [m]',
'p': 'Wetted Perimeter [m]',
'f': 'Froude Number',
'v': 'Velocity [m/s]',
'flow_status': 'Flow Status',
'zc': 'Section Factor',
'yc': 'WIP',
'''
# Constants
G = 9.81 #acceleration due gravity
# Classes
class Channel:
def __init__(self, n, So, Q):
self.n = n
self.So = So
self.Q = Q
self.y = None
self.a = None
self.p = None
self.rh = None
self.tw = None
self.dh = None
self.zc = None
self.v = None
self.f = None
self.flow_status = None
self.yn = Symbol('yn')
self.ac = None
self.rc = None
self.pc = None
self.twc = None
self.yc = None
self.Sc = None
def calc_properties(self):
if self.Q is not None and type(self.y) is not Symbol:
self.v = self.Q / self.a
self.f = self.v / sqrt(G * self.dh)
self.rc = self.ac / self.pc if (self.ac and self.pc) != None else None
froude_value = float(str(self.f))
if froude_value > 1.0:
self.flow_status = 'Supercritical'
elif froude_value == 1.0:
self.flow_status = 'Critical'
else:
self.flow_status = 'Subcritical'
else:
pass
def calc_flow(self):
#Manning
self.calc_properties()
self.Q = (self.a * self.rh**(2/3) * self.So**0.5) / self.n
self.calc_properties()
return self.Q
def calc_yn(self):
if(type(self.y) is Symbol):
try:
self.calc_properties()
sol = (self.a * self.rh**(2/3) * self.So**0.5) / self.n
self.y = re(nsolve(sol - self.Q, self.y, 1))
self.calc_properties()
except ValueError:
return 'Incorrect value selected'
return self.y
def get_parameters(self):
return self.__dict__
def get_energy(self):
y = np.arange(0.1,4, 0.01)
# Crear una función evaluable a partir de la expresión self.ac
specific_energy = lambdify(self.yn, self.yn + (self.Q**2 / (2 * G * self.ac**2)))
# Evaluar la función en los puntos de y
E_values = specific_energy(y)
plt.title("Specific energy diagram")
plt.xlabel("Energy")
plt.ylabel("Depth")
plt.plot(E_values, y)
plt.show()
def get_critical_parameters(self):
froude_critical = (self.Q**2 * self.twc) - (self.ac**3 * G)
x0 = 1 if (hasattr(self, 'D') and self.D > 1.1) else 0.4
try:
self.yn = re(nsolve(froude_critical, self.yn, x0))
except:
self.yn = solve(froude_critical, self.yn)[0]
self.yc = self.yn
self.calc_properties()
self.Sc = ((self.Q**2 * self.n**2) / (self.ac**2 * self.rc**(4/3)))
class RectangularChannel(Channel):
def __init__(self, n, So, b, Q = None, y = Symbol('y')):
super().__init__(n, So, Q)
self.channel_type = 'Rectangular'
self.b = b
self.y = y if y != None else Symbol('y')
if(type(self.y) is Symbol):
self.calc_yn()
if(self.Q is None):
self.calc_flow()
self.get_critical_parameters()
def calc_properties(self):
self.a = self.b * self.y
self.p = self.b + (self.y * 2)
self.rh = self.a / self.p
self.tw = self.b
self.twc = self.b
self.dh = self.y
self.zc = self.b * (self.y**1.5)
self.ac = self.b * self.yn
self.pc = self.b + (self.yn * 2)
super().calc_properties()
class TrapezoidalChannel(Channel):
def __init__(self, n, So, z, b, Q = None, y = Symbol('y')):
super().__init__(n, So, Q)
self.channel_type = 'Trapezoidal'
self.b = b
self.z = z
self.y = y if y != None else Symbol('y')
if(type(self.y) is Symbol):
self.calc_yn()
if(self.Q is None):
self.calc_flow()
self.get_critical_parameters()
def calc_properties(self):
self.a = (self.b + (self.y*self.z)) * self.y
self.p = self.b + (2 * self.y * (1 + self.z**2)**(1/2))
self.rh = self.a / self.p
self.tw = self.b + (2 * self.y * self.z)
self.dh = ((self.b + (self.z * self.y))* self.y) / (self.b + (2 * self.z * self.y))
self.zc = ((self.b + (self.z * self.y))* self.y)**1.5 / (self.b + (2 * self.y * self.b))**0.5
self.ac = (self.b + (self.yn*self.z)) * self.yn
self.twc = self.b + (2 * self.yn * self.z)
self.pc = self.b + (2 * self.yn * (1 + self.z**2)**(1/2))
super().calc_properties()
# channel = TrapezoidalChannel(b=2, n=0.013, So=0.0075, Q = 3.5, z=1.5)
# channel.get_energy()
# print(channel.get_critical_parameters())
class TriangularChannel(Channel):
def __init__(self, n, So, z, Q = None, y = Symbol('y')):
super().__init__(n, So, Q)
self.channel_type = 'Triangular'
self.z = z
self.y = y if y != None else Symbol('y')
if(type(self.y) is Symbol):
self.calc_yn()
if(self.Q is None):
self.calc_flow()
self.get_critical_parameters()
def calc_properties(self):
self.a = self.z * self.y**2
self.an = self.z * self.yn**2
self.p = (self.y * 2) * (1 + self.z**2)**0.5
self.rh = self.a / self.p
self.tw = 2 * self.z * self.y
self.dh = 0.5 * self.y
self.ac = self.z * self.yn**2
self.twc = 2 * self.z * self.yn
self.pc = (self.yn * 2) * (1 + self.z**2)**0.5
self.zc = ((2**0.5)/2) * self.z * self.y**2.5
super().calc_properties()
def caudal_manning(self):
self.calc_properties()
self.Q = (self.a * self.rh**(2/3) * self.So**0.5) / self.n
self.calc_properties()
class CircularChannel(Channel):
def __init__(self, n, So, D, Q = None, y = Symbol('y')):
super().__init__(n, So, Q)
self.channel_type = 'Circular'
self.D = D
self.y = y if y != None else Symbol('y')
if(type(self.y) is Symbol):
self.calc_yn()
if(self.Q is None):
self.calc_flow()
self.get_critical_parameters()
def calc_properties(self):
self.theta_n = acos((1 - ( 2 * (self.yn / self.D)))) * 2
self.theta = (acos((1 - ( 2 * (self.y / self.D)))) * 2).evalf()
self.a = (((self.theta - sin(self.theta)) * self.D**2) / 8)
self.ac = ((self.theta_n - sin(self.theta_n)) * self.D**2) / 8
self.a = ((self.theta - sin(self.theta)) * self.D**2) / 8
self.p = ( self.D * self.theta) / 2
self.rh = self.a / self.p
self.tw = sin(self.theta / 2) * self.D
self.twc = sin(self.theta_n / 2) * self.D
self.pc = ( self.D * self.theta_n) / 2
self.dh = self.a / self.tw
self.zc = self.D * (self.y**1.5)
super().calc_properties()
def __str__(self):
return f"\nChannel: {self.channel_type}\nDimensions: \n\tDiameter: {self.D}\n{super().__str__()}"
def caudal_manning(self):
self.calc_properties()
self.Q = (self.a * self.rh**(2/3) * self.So**0.5) / self.n
self.calc_properties()