-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwntr_WSN.py
51 lines (44 loc) · 1.74 KB
/
wntr_WSN.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
import wntr
import pandas as pd
import matplotlib.pyplot as plt
import networkx as nx
data_file = 'Walkerton_v1.inp' # water supply network .inp file
def get_data_file() -> str:
"""
Returns value of var data_file (str)
Purpose is to get the value to another .py file
"""
return data_file
def get_sim_results() -> wntr.sim.results.SimulationResults:
"""
Runs and returns a hydraulic simulation WNTR object (NO LEAKS)
Returns: Simulation results (wntr.sim.results.SimulationResults)
"""
print("Running the simulation (wntr_WSN.py - get_sim_results())")
wn = wntr.network.WaterNetworkModel(data_file)
sim = wntr.sim.WNTRSimulator(wn)
return sim.run_sim()
def get_sim_results_LEAK(node: str, area: float, start_time: int, end_time: int) -> wntr.sim.results.SimulationResults:
"""
Runs and returns a hydraulic simulation WNTR object (WITH A LEAK)
Arguments: node - node which will have the leak (str)
area - area of the leak in (float, meters squared)
start_time - when the leak starts (int, hours)
end_time - when the leak ends (int, hours)
Returns: Simulation results (wntr.sim.results.SimulationResults)
"""
wn_leaks = wntr.network.WaterNetworkModel(data_file)
leak_node = wn_leaks.get_node(node)
leak_node.add_leak(wn_leaks, area=area, start_time=start_time*3600, end_time=end_time*3600)
sim_leaks = wntr.sim.WNTRSimulator(wn_leaks)
return sim_leaks.run_sim()
if __name__ == '__main__':
inp_file = 'Walkerton_v1.inp'
wn = wntr.network.WaterNetworkModel(data_file)
#sim = wntr.sim.WNTRSimulator(wn)
#results = sim.run_sim()
#length = wn.query_link_attribute('length')
#G = wn.get_graph(wn, link_weight=length)
#nx.draw(G)
res = get_sim_results_LEAK('J63', 0.001, 3, 5)
print(res.node['pressure'])