-
Notifications
You must be signed in to change notification settings - Fork 1
/
reservoir_and_nozzle.py
86 lines (72 loc) · 2.76 KB
/
reservoir_and_nozzle.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
from hydraulics.pipe_network import PNetwork
from hydraulics.edges import Pipe, Nozzle
from hydraulics.nodes import ConnectionNode, EndNode
from hydraulics.solvers import UserSolver
network = PNetwork()
# SET NODES
system_nodes = ['e', 'e', 'c', 'c', 'c', 'e', 'e', 'e', 'c']
elevations = [30, 35, 25, 0, 0, 0, 0, 0, 0]
for index in range(len(system_nodes)):
if system_nodes[index] == 'e':
cur_node = EndNode()
if system_nodes[index] == 'c':
cur_node = ConnectionNode()
cur_node.set_pressure(0, 'psi')
cur_node.set_elevation(elevations[index], 'm')
cur_node.name = index
network.add_node(cur_node)
# SET EDGES
# SET PIPES
lengths = [100, 150, 20, 2, 2]
inner_diameters = [1.939, 1.939, 1.939, .957, .957]
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)
network.add_edge(cur_pipe)
network.set_pipe_name(pipe_index, pipe_index)
# cur_pipe.name = pipe_index
# SET NOZZLES
for index in range(5, 8):
cur_pipe = Nozzle()
cur_pipe.set_factor(2, 'gpm/psi^0.5')
cur_pipe.name = index
network.add_edge(cur_pipe)
# for element in problem.get_edges():
# print '%s is %s' % (element.name, type(element))
# SET CONNECTIVITY
network.connect_node_downstream_edge(0, 0)
network.connect_node_downstream_edge(1, 1)
network.connect_node_downstream_edge(2, 2)
network.connect_node_upstream_edge(2, 0)
network.connect_node_upstream_edge(2, 1)
network.connect_node_downstream_edge(3, 5)
network.connect_node_downstream_edge(3, 3)
network.connect_node_upstream_edge(3, 2)
network.connect_node_downstream_edge(4, 4)
network.connect_node_downstream_edge(4, 6)
network.connect_node_upstream_edge(4, 3)
network.connect_node_upstream_edge(5, 5)
network.connect_node_upstream_edge(6, 6)
network.connect_node_upstream_edge(7, 7)
network.connect_node_downstream_edge(8, 7)
network.connect_node_upstream_edge(8, 4)
# for index in range(8):
# cur_pipe = problem.get_edges()[index]
# message = 'complete' if cur_pipe.is_complete() else 'not complete'
# print "Pipe #%s is %s" % (cur_pipe.name, message)
reservoir_solve = UserSolver(network)
reservoir_solve.solve_system()
for edge in network.get_edges():
print "%s) flow: %8.4f" % (edge.name, edge.calculate_gpm_flow())
for node in network.get_nodes():
if isinstance(node, ConnectionNode):
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_energy('psi')
print "%s)Press: %7.4f psi, flow: %6.3f" % (node.name, pressure, in_gpm)