-
Notifications
You must be signed in to change notification settings - Fork 1
/
four_reservoirs.py
75 lines (63 loc) · 2.22 KB
/
four_reservoirs.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
from hydraulics.pipe_network import PNetwork
from hydraulics.edges import Pipe, EndNode
from hydraulics.nodes import ConnectionNode
from hydraulics.solvers import UserSolver
elevations = [100, 85, 65, 65, 70, 70]
names = [0, 1, 2, 3, 4, 5]
network = PNetwork()
# SET NODES
# END NODES
for cont in range(4):
cur_node = EndNode()
cur_node.set_elevation(elevations[cont], 'm')
cur_node.name = names[cont]
network.add_node(cur_node)
node_count = len(elevations)
end_count = 4
for node_index in range(end_count, node_count):
cur_node = ConnectionNode()
cur_node.set_pressure(0, 'psi')
cur_node.set_elevation(elevations[node_index], 'm')
cur_node.name = names[node_index]
network.add_node(cur_node)
# SET PIPES
lengths = [1000, 1200, 900, 500, 600]
inner_diameters = [10.02, 7.981, 7.981, 6.065, 6.065]
pipe_count = len(lengths)
for pipe_index in range(pipe_count):
cur_pipe = Pipe()
cur_pipe.set_length(lengths[pipe_index], 'm')
cur_pipe.set_inner_diam(inner_diameters[pipe_index], 'in')
cur_pipe.set_c_coefficient(100)
cur_pipe.name = pipe_index
network.add_edge(cur_pipe)
# SET CONNECTIVITY
network.connect_node_downstream_edge(4, 2)
network.connect_node_upstream_edge(4, 1)
network.connect_node_upstream_edge(4, 0)
network.connect_node_downstream_edge(0, 0)
network.connect_node_downstream_edge(1, 1)
network.connect_node_upstream_edge(5, 2)
network.connect_node_downstream_edge(5, 3)
network.connect_node_downstream_edge(5, 4)
network.connect_node_upstream_edge(2, 3)
network.connect_node_upstream_edge(3, 4)
# OUTPUT FLOW AT NODE 4
# network.get_nodes()[4].set_output_flow(200, 'gpm')
user_solver = UserSolver(network)
user_solver.solve_system()
# FLOW CHECK
for cont in range(pipe_count):
cur_pipe = network.get_edges()[cont]
print "p%s) flow %.4f gpm" % (cur_pipe.name, cur_pipe.calculate_gpm_flow())
# PRESSURE CHECK
test_press = [0, 0, 0, 0, 30.016, 7.383]
print
for node in network.get_nodes():
in_gpm = 0
for edge in node.get_input_pipes():
in_gpm += edge.get_vol_flow('gpm')
for edge in node.get_output_pipes():
in_gpm -= edge.get_vol_flow('gpm')
pressure = node.get_pressure('psi')
print "n%s)P= %6.3f psi, Q= %9.3f" % (node.name, pressure, in_gpm)