forked from WaterFutures/EPANET-PLUS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_epyt.py
More file actions
119 lines (84 loc) · 4.01 KB
/
Copy pathtest_epyt.py
File metadata and controls
119 lines (84 loc) · 4.01 KB
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
"""
This module tests the toolkit functions implemented in the clas EPyT.
"""
import os
import numpy as np
from epanet_plus import EPyT, EpanetConstants
def test_topology():
def __test_code(epanet_api: EPyT):
assert len(epanet_api.get_all_nodes_id()) > 0
assert len(epanet_api.get_all_links_id()) > 0
assert len(epanet_api.get_all_nodes_idx()) > 0
assert len(epanet_api.get_all_links_idx()) > 0
epanet_api.get_all_junctions_id()
epanet_api.get_all_junctions_idx()
assert len(epanet_api.get_all_pipes_id()) > 0
assert len(epanet_api.get_all_pipes_idx()) > 0
assert len(epanet_api.get_all_tanks_id()) > 0
assert len(epanet_api.get_all_tanks_idx()) > 0
epanet_api.get_all_reservoirs_id()
epanet_api.get_all_reservoirs_idx()
epanet_api.get_all_pumps_id()
epanet_api.get_all_pumps_idx()
with EPyT(os.path.join("tests", "net2-cl2.inp")) as epanet_api:
__test_code(epanet_api)
with EPyT(os.path.join("tests", "net2-cl2.inp"), use_project=True) as epanet_api:
__test_code(epanet_api)
def test_parameters():
def __test_code(epanet_api: EPyT):
assert epanet_api.get_simulation_duration() > 0
assert epanet_api.get_hydraulic_time_step() > 0
assert epanet_api.get_reporting_start_time() >= 0
assert epanet_api.get_reporting_time_step() > 0
assert epanet_api.get_quality_time_step() > 0
with EPyT(os.path.join("tests", "net2-cl2.inp")) as epanet_api:
__test_code(epanet_api)
with EPyT(os.path.join("tests", "net2-cl2.inp"), use_project=True) as epanet_api:
__test_code(epanet_api)
def test_hyd_simulation():
def __test_code(epanet_api: EPyT):
epanet_api.openH()
epanet_api.initH(EpanetConstants.EN_NOSAVE)
tstep = 1
while tstep > 0:
epanet_api.runH()
assert len(epanet_api.getnodevalues(EpanetConstants.EN_PRESSURE)) > 0
assert len(epanet_api.getlinkvalues(EpanetConstants.EN_FLOW)) > 0
tstep = epanet_api.nextH()
epanet_api.closeH()
with EPyT(os.path.join("tests", "net2-cl2.inp")) as epanet_api:
__test_code(epanet_api)
with EPyT(os.path.join("tests", "net2-cl2.inp"), use_project=True) as epanet_api:
__test_code(epanet_api)
def test_quality_simulation():
def __test_code(epanet_api: EPyT):
epanet_api.openH()
epanet_api.initH(EpanetConstants.EN_NOSAVE)
epanet_api.openQ()
epanet_api.initQ(EpanetConstants.EN_NOSAVE)
tstep = 1
while tstep > 0:
epanet_api.runH()
epanet_api.runQ()
assert len(epanet_api.getnodevalues(EpanetConstants.EN_PRESSURE)) > 0
assert len(epanet_api.getlinkvalues(EpanetConstants.EN_FLOW)) > 0
assert len(epanet_api.getnodevalues(EpanetConstants.EN_QUALITY)) > 0
assert len(epanet_api.getlinkvalues(EpanetConstants.EN_QUALITY)) > 0
assert np.all(epanet_api.getnodevalues_numpy(EpanetConstants.EN_QUALITY) == np.array(epanet_api.getnodevalues(EpanetConstants.EN_QUALITY))) == True
assert np.all(epanet_api.getlinkvalues_numpy(EpanetConstants.EN_QUALITY) == np.array(epanet_api.getlinkvalues(EpanetConstants.EN_QUALITY))) == True
tstep = epanet_api.nextH()
epanet_api.nextQ()
epanet_api.closeQ()
epanet_api.closeH()
with EPyT(os.path.join("tests", "net2-cl2.inp")) as epanet_api:
__test_code(epanet_api)
with EPyT(os.path.join("tests", "net2-cl2.inp"), use_project=True) as epanet_api:
__test_code(epanet_api)
def test_msx():
with EPyT(os.path.join("tests", "net2-cl2.inp"), use_project=False) as epanet_api:
epanet_api.load_msx_file(os.path.join("tests", "net2-cl2.msx"))
assert epanet_api.get_msx_time_step() > 0
epanet_api.set_msx_time_step(150)
assert epanet_api.get_msx_time_step() == 150
epanet_api.get_all_msx_species_id()
epanet_api.get_all_msx_species_info()