Skip to content

Commit b5a7b64

Browse files
authored
Merge pull request #62 from ichrys03/epanet2.3-undercover
Epanet2.3 new updates
2 parents 05495d4 + 3031160 commit b5a7b64

16 files changed

+2838
-245
lines changed

README.md

Lines changed: 720 additions & 133 deletions
Large diffs are not rendered by default.

epyt/epanet.py

Lines changed: 1597 additions & 87 deletions
Large diffs are not rendered by default.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from epyt import epanet
2+
3+
# Model + time settings
4+
5+
d = epanet('ky10.inp')
6+
TIME_H = 24 * 3600 # 24 hours
7+
HYD_STEP = 15 * 60 # 15 min
8+
PAT_STEP = 15 * 60
9+
RPT_STEP = 15 * 60
10+
11+
LINK_LEAK_AREA = 3e-7
12+
EMITTER_COEFF = 0.002
13+
14+
d.setTimeSimulationDuration(TIME_H)
15+
d.setTimeHydraulicStep(HYD_STEP)
16+
d.setTimePatternStep(PAT_STEP)
17+
d.setTimeReportingStep(RPT_STEP)
18+
19+
linkID = d.getLinkNameID(10)
20+
pipe_ix = d.getLinkIndex(linkID)
21+
22+
nodeID = d.getNodeNameID(10)
23+
junc_ix = d.getNodeIndex(nodeID)
24+
25+
# Apply leakage settings
26+
27+
d.setLinkLeakArea(pipe_ix, LINK_LEAK_AREA)
28+
d.setLinkExpansionProperties(pipe_ix, 0.5) # example elasticity coefficient
29+
30+
d.setNodeEmitterCoeff(junc_ix, EMITTER_COEFF)
31+
32+
p_unit = d.getOptionsPressureUnits()
33+
q_unit = d.getFlowUnits()
34+
35+
print(f"[Units] Flow={q_unit} | Pressure={p_unit} ")
36+
print(f"[Params] LinkLeakArea={LINK_LEAK_AREA:g} m^2 | EmitterCoeff={EMITTER_COEFF:g}")
37+
38+
# Run hydraulics
39+
40+
d.openHydraulicAnalysis()
41+
d.initializeHydraulicAnalysis()
42+
43+
t = 0.0
44+
while True:
45+
d.runHydraulicAnalysis()
46+
47+
# Leakages
48+
leak_pipe = d.getLinkLeakageRate(pipe_ix)
49+
leak_node = d.getNodeLeakageFlow(junc_ix)
50+
emitter = d.getNodeEmitterFlow(junc_ix)
51+
52+
# Demand
53+
dem_req = d.getConsumerDemandRequested(junc_ix)
54+
dem_del = d.getConsumerDemandDelivered(junc_ix)
55+
56+
# Optional diagnostics
57+
Pj = d.getNodePressure(junc_ix)
58+
59+
total_out = max(dem_del + leak_pipe + leak_node + emitter, 1e-12)
60+
leak_share = 100.0 * (leak_pipe + leak_node + emitter) / total_out
61+
62+
print(
63+
f"t={t:5.0f}s | P={Pj:7.3f} {p_unit:>3} | "
64+
f"PipeLeak={leak_pipe:9.4f} | NodeLeak={leak_node:9.4f} | Emitter={emitter:8.4f} | "
65+
f"DemReq={dem_req:8.3f} | DemDel={dem_del:8.3f} | LeakShare={leak_share:5.1f}%"
66+
)
67+
68+
dt = d.nextHydraulicAnalysisStep()
69+
if dt <= 0:
70+
break
71+
t += dt
72+
73+
d.closeHydraulicAnalysis()
74+
d.unload()
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
from epyt import epanet
2+
3+
# inpfile = "Richmond_standard.inp"
4+
5+
# #Warning that a link is missing and the network is not fully connected
6+
# inpfile = "BrokenNetwork.inp"
7+
# d = epanet(inpfile)
8+
# d.unload()
9+
10+
inpfile = "Net1.inp"
11+
d = epanet(inpfile)
12+
13+
# d.getNodeNameID('dakjsdfhjksdfhsd')
14+
# setcurvetype functions
15+
d.setCurveTypePump(1)
16+
d.printv(d.getCurveType(1))
17+
d.setCurveTypeVolume(1)
18+
d.printv(d.getCurveType())
19+
d.setCurveTypeGeneral(1)
20+
d.printv(d.getCurveType())
21+
d.setCurveTypeHeadloss(1)
22+
d.printv(d.getCurveType())
23+
d.setCurveTypeEfficiency(1)
24+
d.printv(d.getCurveType())
25+
d.setCurveTypeValveCurve(1)
26+
d.printv(d.getCurveType())
27+
28+
# Setvertex
29+
linkID = '10'
30+
x = [22, 24, 28]
31+
y = [30, 68, 69]
32+
d.setLinkVertices(linkID, x, y)
33+
x = d.getLinkVertices()
34+
d.setVertex(1, 1, 1, 1)
35+
d.printv(d.getLinkVertices())
36+
37+
# set and get linkvalvecurvegpv
38+
linkid = d.getLinkPipeNameID(1)
39+
condition = 1
40+
index = d.setLinkTypeValveGPV(linkid, condition)
41+
d.setLinkValveCurveGPV(index, 1)
42+
d.printv(d.getLinkValveCurveGPV())
43+
44+
# set and get linkvalvecurvepcv
45+
linkid = d.getLinkPipeNameID(1)
46+
condition = 1
47+
index = d.setLinkTypeValvePCV(linkid, condition)
48+
d.setLinkValveCurvePCV(index, 1)
49+
d.printv(d.getLinkValveCurvePCV(index))
50+
51+
# setTimeClockStartTime & getTimeClockStartTime
52+
d.printv(d.getTimeClockStartTime())
53+
d.setTimeClockStartTime(3600)
54+
d.printv(d.getTimeClockStartTime())
55+
56+
# getOptionsDemandPattern())
57+
d.printv(d.getOptionsDemandPattern())
58+
d.setOptionsDemandPattern(0)
59+
d.printv(d.getOptionsDemandPattern())
60+
61+
# getLinkType / d.setLinkTypeValvePCV / d.addLinkValvePCV
62+
d.getLinkType(1) # Retrieves the type of the 1st link
63+
linkid = d.getLinkPipeNameID(1) # Retrieves the ID of the 1t pipe
64+
index = d.setLinkTypeValvePCV(linkid) # Changes the 1st pipe to valve PCV given it's ID
65+
print(d.getLinkType(index))
66+
67+
# addLinkValvePCV
68+
# d.plot()
69+
valveID = 'newValvePCV'
70+
fromNode = '10'
71+
toNode = '21'
72+
valveIndex = d.addLinkValvePCV(valveID, fromNode, toNode)
73+
# d.plot()
74+
75+
# getset OptionsEmiterBackFlow
76+
d.printv(d.getOptionsEmitterBackFlow())
77+
d.setOptionsEmitterBackFlowDisallowed()
78+
d.printv(d.getOptionsEmitterBackFlow())
79+
d.setOptionsEmitterBackFlowAllowed()
80+
d.printv(d.getOptionsEmitterBackFlow())
81+
82+
# getNodeInControl & getLinkInControl
83+
d.printv(d.getLinkInControl())
84+
d.printv(d.getLinkInControl(10))
85+
d.printv(d.getNodeInControl())
86+
d.printv(d.getNodeInControl(11))
87+
88+
# setLinkFlowUnitsCMS
89+
d.setFlowUnitsCMS() # kpa and meters
90+
d.printv(d.getFlowUnits())
91+
92+
# example with change from kpa to psi without changing metric first
93+
d.setOptionsPressureUnitsPSI()
94+
d.printv(d.getOptionsPressureUnits())
95+
96+
# how to do it right
97+
d.setFlowUnitsIMGD()
98+
d.setOptionsPressureUnitsPSI()
99+
d.printv(d.getOptionsPressureUnits())
100+
101+
# example with change from psi to KPA without changing the metric
102+
d.setOptionsPressureUnitsKPA()
103+
d.printv(d.getOptionsPressureUnits())
104+
105+
# reseting
106+
d.setFlowUnitsGPM()
107+
d.setOptionsPressureUnitsPSI()
108+
109+
# setNodeEmitterCoeff
110+
d.setNodeEmitterCoeff([2, 3], [0.5, 0.6])
111+
d.printv(d.getNodeEmitterCoeff())
112+
113+
# getset Optionsstatusreport
114+
d.setOptionsStatusReportNo()
115+
d.printv(d.getOptionsStatusReport())
116+
d.setOptionsStatusReportNormal()
117+
d.printv(d.getOptionsStatusReport())
118+
d.setOptionsStatusReportFull()
119+
d.printv(d.getOptionsStatusReport())
120+
121+
# Leakage section
122+
d.solveCompleteHydraulics()
123+
124+
d.setLinkLeakArea(2, 10.5)
125+
d.printv(d.getLinkLeakArea())
126+
127+
d.setLinkExpansionProperties(5, 2)
128+
d.printv(d.getLinkExpansionProperties())
129+
130+
d.printv(d.getLinkLeakageRate())
131+
132+
d.printv(d.getConsumerDemandRequested(5))
133+
134+
d.printv(d.getConsumerDemandDelivered(5))
135+
136+
d.printv(d.getNodeEmitterFlow())
137+
138+
d.unload()
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from epyt import epanet
2+
import time
3+
4+
"""
5+
Performance Example Summary:
6+
7+
Objective:
8+
9+
To compare the execution speed of two functions, getLinkFlows vs. getLinkValues.
10+
11+
Criteria:
12+
13+
The main criterion for comparison was speed.
14+
Both functions were tested under the same simulation conditions.
15+
16+
Test Setup:
17+
18+
The simulation was designed to extract link flow values:
19+
getLinkFlows: Extracts flows for all links - 1.
20+
getLinkValues: Extracts the flow values for all links.
21+
22+
Results:
23+
24+
getLinkFlows: Extracted fewer values (flows set to -1).
25+
getLinkValues: Extracted all actual flow values for each link,
26+
processing more data than getLinkFlows.
27+
Despite extracting more data, getLinkValues performed faster than getLinkFlows.
28+
29+
Conclusion:
30+
31+
The function getLinkValues was more efficient in terms of speed,
32+
even though it processed and returned more values compared to getLinkFlows.
33+
"""
34+
35+
36+
37+
inp= "Net1.inp"
38+
d = epanet(inp)
39+
40+
d.setTimeSimulationDuration(1000*3600*24)
41+
start_time = time.time()
42+
d.openHydraulicAnalysis()
43+
d.initializeHydraulicAnalysis()
44+
numbers = [i for i in range(1, 13)]
45+
tstep = 1
46+
T_H, Ft, Fb = [], [], []
47+
while tstep > 0:
48+
t = d.runHydraulicAnalysis()
49+
#flow test
50+
Fb.append(d.getLinkFlows(numbers))
51+
T_H.append(t)
52+
tstep = d.nextHydraulicAnalysisStep()
53+
54+
d.closeHydraulicAnalysis()
55+
print(Fb)
56+
end_time = time.time()
57+
timeforold = end_time - start_time
58+
print(f"Time taken by old function: {timeforold} seconds")
59+
d.unload()
60+
61+
d = epanet(inp)
62+
start_time = time.time()
63+
64+
d.openHydraulicAnalysis()
65+
d.initializeHydraulicAnalysis()
66+
67+
tstep = 1
68+
T_H, Ft, Fb = [], [], []
69+
while tstep > 0:
70+
t = d.runHydraulicAnalysis()
71+
#flow test
72+
Ft.append(d.getLinkValues(d.ToolkitConstants.EN_FLOW))
73+
T_H.append(t)
74+
tstep = d.nextHydraulicAnalysisStep()
75+
76+
d.closeHydraulicAnalysis()
77+
print(Ft)
78+
end_time = time.time()
79+
timefornew = end_time - start_time
80+
print(f"Time taken by newfunction: {timefornew} seconds")
81+
print(f"The new function is faster by {timeforold-timefornew} seconds")

epyt/libraries/glnx/libepanet2.so

40.1 KB
Binary file not shown.
119 KB
Binary file not shown.
404 KB
Binary file not shown.

epyt/libraries/win/2.2/epanet2.dll

341 KB
Binary file not shown.

epyt/libraries/win/2.2/epanet2.exe

11.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)