epanet-plus 0.2.1__cp311-cp311-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. docs/conf.py +67 -0
  2. epanet-msx-src/dispersion.h +27 -0
  3. epanet-msx-src/hash.c +107 -0
  4. epanet-msx-src/hash.h +28 -0
  5. epanet-msx-src/include/epanetmsx.h +104 -0
  6. epanet-msx-src/include/epanetmsx_export.h +42 -0
  7. epanet-msx-src/mathexpr.c +937 -0
  8. epanet-msx-src/mathexpr.h +39 -0
  9. epanet-msx-src/mempool.c +204 -0
  10. epanet-msx-src/mempool.h +24 -0
  11. epanet-msx-src/msxchem.c +1285 -0
  12. epanet-msx-src/msxcompiler.c +368 -0
  13. epanet-msx-src/msxdict.h +42 -0
  14. epanet-msx-src/msxdispersion.c +586 -0
  15. epanet-msx-src/msxerr.c +116 -0
  16. epanet-msx-src/msxfile.c +260 -0
  17. epanet-msx-src/msxfuncs.c +175 -0
  18. epanet-msx-src/msxfuncs.h +35 -0
  19. epanet-msx-src/msxinp.c +1504 -0
  20. epanet-msx-src/msxout.c +398 -0
  21. epanet-msx-src/msxproj.c +791 -0
  22. epanet-msx-src/msxqual.c +2011 -0
  23. epanet-msx-src/msxrpt.c +400 -0
  24. epanet-msx-src/msxtank.c +422 -0
  25. epanet-msx-src/msxtoolkit.c +1164 -0
  26. epanet-msx-src/msxtypes.h +551 -0
  27. epanet-msx-src/msxutils.c +524 -0
  28. epanet-msx-src/msxutils.h +56 -0
  29. epanet-msx-src/newton.c +158 -0
  30. epanet-msx-src/newton.h +34 -0
  31. epanet-msx-src/rk5.c +287 -0
  32. epanet-msx-src/rk5.h +39 -0
  33. epanet-msx-src/ros2.c +293 -0
  34. epanet-msx-src/ros2.h +35 -0
  35. epanet-msx-src/smatrix.c +816 -0
  36. epanet-msx-src/smatrix.h +29 -0
  37. epanet-src/AUTHORS +60 -0
  38. epanet-src/LICENSE +21 -0
  39. epanet-src/enumstxt.h +151 -0
  40. epanet-src/epanet.c +5937 -0
  41. epanet-src/epanet2.c +961 -0
  42. epanet-src/epanet2.def +131 -0
  43. epanet-src/errors.dat +79 -0
  44. epanet-src/flowbalance.c +186 -0
  45. epanet-src/funcs.h +219 -0
  46. epanet-src/genmmd.c +1000 -0
  47. epanet-src/hash.c +177 -0
  48. epanet-src/hash.h +28 -0
  49. epanet-src/hydcoeffs.c +1303 -0
  50. epanet-src/hydraul.c +1164 -0
  51. epanet-src/hydsolver.c +781 -0
  52. epanet-src/hydstatus.c +442 -0
  53. epanet-src/include/epanet2.h +466 -0
  54. epanet-src/include/epanet2_2.h +1962 -0
  55. epanet-src/include/epanet2_enums.h +518 -0
  56. epanet-src/inpfile.c +884 -0
  57. epanet-src/input1.c +672 -0
  58. epanet-src/input2.c +970 -0
  59. epanet-src/input3.c +2265 -0
  60. epanet-src/leakage.c +527 -0
  61. epanet-src/mempool.c +146 -0
  62. epanet-src/mempool.h +24 -0
  63. epanet-src/output.c +853 -0
  64. epanet-src/project.c +1691 -0
  65. epanet-src/quality.c +695 -0
  66. epanet-src/qualreact.c +800 -0
  67. epanet-src/qualroute.c +696 -0
  68. epanet-src/report.c +1559 -0
  69. epanet-src/rules.c +1500 -0
  70. epanet-src/smatrix.c +871 -0
  71. epanet-src/text.h +508 -0
  72. epanet-src/types.h +928 -0
  73. epanet-src/util/cstr_helper.c +59 -0
  74. epanet-src/util/cstr_helper.h +38 -0
  75. epanet-src/util/errormanager.c +92 -0
  76. epanet-src/util/errormanager.h +39 -0
  77. epanet-src/util/filemanager.c +212 -0
  78. epanet-src/util/filemanager.h +81 -0
  79. epanet-src/validate.c +408 -0
  80. epanet.cpython-311-darwin.so +0 -0
  81. epanet_plus/VERSION +1 -0
  82. epanet_plus/__init__.py +8 -0
  83. epanet_plus/epanet_plus.c +118 -0
  84. epanet_plus/epanet_toolkit.py +2833 -0
  85. epanet_plus/epanet_wrapper.py +2434 -0
  86. epanet_plus/include/epanet_plus.h +9 -0
  87. epanet_plus-0.2.1.dist-info/METADATA +157 -0
  88. epanet_plus-0.2.1.dist-info/RECORD +106 -0
  89. epanet_plus-0.2.1.dist-info/WHEEL +6 -0
  90. epanet_plus-0.2.1.dist-info/licenses/LICENSE +21 -0
  91. epanet_plus-0.2.1.dist-info/top_level.txt +11 -0
  92. examples/basic_usage.py +35 -0
  93. examples/epanet_msx.py +35 -0
  94. python-extension/ext.c +344 -0
  95. python-extension/pyepanet.c +2771 -0
  96. python-extension/pyepanet.h +144 -0
  97. python-extension/pyepanet2.c +2453 -0
  98. python-extension/pyepanet2.h +142 -0
  99. python-extension/pyepanet_plus.c +43 -0
  100. python-extension/pyepanet_plus.h +4 -0
  101. python-extension/pyepanetmsx.c +524 -0
  102. python-extension/pyepanetmsx.h +35 -0
  103. tests/test_epanet.py +18 -0
  104. tests/test_epanetmsx.py +38 -0
  105. tests/test_epyt.py +115 -0
  106. tests/test_load_inp_from_buffer.py +59 -0
@@ -0,0 +1,35 @@
1
+ #include <Python.h>
2
+
3
+
4
+ PyObject* method_MSXENopen(PyObject* self, PyObject* args);
5
+ PyObject* method_MSXopen(PyObject* self, PyObject* args);
6
+ PyObject* method_MSXsolveH(PyObject* self, PyObject* Py_UNUSED(args));
7
+ PyObject* method_MSXusehydfile(PyObject* self, PyObject* args);
8
+ PyObject* method_MSXsolveQ(PyObject* self, PyObject* Py_UNUSED(args));
9
+ PyObject* method_MSXinit(PyObject* self, PyObject* args);
10
+ PyObject* method_MSXstep(PyObject* self, PyObject* args);
11
+ PyObject* method_MSXsaveoutfile(PyObject* self, PyObject* args);
12
+ PyObject* method_MSXsavemsxfile(PyObject* self, PyObject* args);
13
+ PyObject* method_MSXreport(PyObject* self, PyObject* Py_UNUSED(args));
14
+ PyObject* method_MSXclose(PyObject* self, PyObject* Py_UNUSED(args));
15
+ PyObject* method_MSXENclose(PyObject* self, PyObject* Py_UNUSED(args));
16
+ PyObject* method_MSXgetindex(PyObject* self, PyObject* args);
17
+ PyObject* method_MSXgetIDlen(PyObject* self, PyObject* args);
18
+ PyObject* method_MSXgetID(PyObject* self, PyObject* args);
19
+ PyObject* method_MSXgetcount(PyObject* self, PyObject* args);
20
+ PyObject* method_MSXgetspecies(PyObject* self, PyObject* args);
21
+ PyObject* method_MSXgetconstant(PyObject* self, PyObject* args);
22
+ PyObject* method_MSXgetparameter(PyObject* self, PyObject* args);
23
+ PyObject* method_MSXgetsource(PyObject* self, PyObject* args);
24
+ PyObject* method_MSXgetpatternlen(PyObject* self, PyObject* args);
25
+ PyObject* method_MSXgetpatternvalue(PyObject* self, PyObject* args);
26
+ PyObject* method_MSXgetinitqual(PyObject* self, PyObject* args);
27
+ PyObject* method_MSXgetqual(PyObject* self, PyObject* args);
28
+ PyObject* method_MSXgeterror(PyObject* self, PyObject* args);
29
+ PyObject* method_MSXsetconstant(PyObject* self, PyObject* args);
30
+ PyObject* method_MSXsetparameter(PyObject* self, PyObject* args);
31
+ PyObject* method_MSXsetinitqual(PyObject* self, PyObject* args);
32
+ PyObject* method_MSXsetsource(PyObject* self, PyObject* args);
33
+ PyObject* method_MSXsetpatternvalue(PyObject* self, PyObject* args);
34
+ PyObject* method_MSXsetpattern(PyObject* self, PyObject* args);
35
+ PyObject* method_MSXaddpattern(PyObject* self, PyObject* args);
tests/test_epanet.py ADDED
@@ -0,0 +1,18 @@
1
+ """
2
+ This module tests the EPANET functions.
3
+ """
4
+ import os
5
+ from epanet_plus import EpanetAPI, EpanetConstants
6
+
7
+
8
+ def test():
9
+ epanet_api = EpanetAPI()
10
+ epanet_api.open(os.path.join("tests", "net2-cl2.inp"),
11
+ os.path.join("tests", "net2-cl2.rpt"), "")
12
+
13
+ assert epanet_api.gettitle() is not None
14
+ assert epanet_api.getcount(EpanetConstants.EN_NODECOUNT) > 0
15
+ assert epanet_api.getcount(EpanetConstants.EN_LINKCOUNT) > 0
16
+ assert epanet_api.getcount(EpanetConstants.EN_TANKCOUNT) > 0
17
+
18
+ epanet_api.close()
@@ -0,0 +1,38 @@
1
+ """
2
+ This module tests EPANET-MSX functions.
3
+ """
4
+ import os
5
+ from epanet_plus import EPyT, EpanetAPI, EpanetConstants
6
+
7
+
8
+ def test_msx_basic():
9
+ epanet_api = EpanetAPI()
10
+ epanet_api.MSXENopen(os.path.join("tests", "net2-cl2.inp"),
11
+ os.path.join("tests", "net2-cl2.rpt"), "")
12
+ epanet_api.MSXopen(os.path.join("tests", "net2-cl2.msx"))
13
+
14
+ epanet_api.gettitle()
15
+ epanet_api.MSXgetspecies(1)
16
+ epanet_api.MSXgetID(3, 1)
17
+
18
+ epanet_api.MSXclose()
19
+ epanet_api.MSXENclose()
20
+
21
+
22
+ def test_simulation():
23
+ with EPyT(os.path.join("tests", "net2-cl2.inp"), use_project=False) as epanet_api:
24
+ epanet_api.load_msx_file(os.path.join("tests", "net2-cl2.msx"))
25
+
26
+ epanet_api.MSXsolveH()
27
+
28
+ epanet_api.MSXinit(0)
29
+ while True:
30
+ _, tleft = epanet_api.MSXstep()
31
+
32
+ for idx in epanet_api.get_all_nodes_idx():
33
+ assert epanet_api.MSXgetqual(EpanetConstants.MSX_NODE, idx, 1) >= 0
34
+ for idx in epanet_api.get_all_pipes_idx():
35
+ assert epanet_api.MSXgetqual(EpanetConstants.MSX_LINK, idx, 1) >= 0
36
+
37
+ if tleft == 0:
38
+ break
tests/test_epyt.py ADDED
@@ -0,0 +1,115 @@
1
+ """
2
+ This module tests the toolkit functions implemented in the clas EPyT.
3
+ """
4
+ import os
5
+ from epanet_plus import EPyT, EpanetConstants
6
+
7
+
8
+ def test_topology():
9
+ def __test_code(epanet_api: EPyT):
10
+ assert len(epanet_api.get_all_nodes_id()) > 0
11
+ assert len(epanet_api.get_all_links_id()) > 0
12
+
13
+ assert len(epanet_api.get_all_nodes_idx()) > 0
14
+ assert len(epanet_api.get_all_links_idx()) > 0
15
+
16
+ epanet_api.get_all_junctions_id()
17
+ epanet_api.get_all_junctions_idx()
18
+
19
+ assert len(epanet_api.get_all_pipes_id()) > 0
20
+ assert len(epanet_api.get_all_pipes_idx()) > 0
21
+
22
+ assert len(epanet_api.get_all_tanks_id()) > 0
23
+ assert len(epanet_api.get_all_tanks_idx()) > 0
24
+
25
+ epanet_api.get_all_reservoirs_id()
26
+ epanet_api.get_all_reservoirs_idx()
27
+ epanet_api.get_all_pumps_id()
28
+ epanet_api.get_all_pumps_idx()
29
+
30
+ with EPyT(os.path.join("tests", "net2-cl2.inp")) as epanet_api:
31
+ __test_code(epanet_api)
32
+
33
+ with EPyT(os.path.join("tests", "net2-cl2.inp"), use_project=True) as epanet_api:
34
+ __test_code(epanet_api)
35
+
36
+
37
+ def test_parameters():
38
+ def __test_code(epanet_api: EPyT):
39
+ assert epanet_api.get_simulation_duration() > 0
40
+ assert epanet_api.get_hydraulic_time_step() > 0
41
+ assert epanet_api.get_reporting_start_time() >= 0
42
+ assert epanet_api.get_reporting_time_step() > 0
43
+ assert epanet_api.get_quality_time_step() > 0
44
+
45
+ with EPyT(os.path.join("tests", "net2-cl2.inp")) as epanet_api:
46
+ __test_code(epanet_api)
47
+
48
+ with EPyT(os.path.join("tests", "net2-cl2.inp"), use_project=True) as epanet_api:
49
+ __test_code(epanet_api)
50
+
51
+
52
+ def test_hyd_simulation():
53
+ def __test_code(epanet_api: EPyT):
54
+ epanet_api.openH()
55
+ epanet_api.initH(EpanetConstants.EN_NOSAVE)
56
+
57
+ tstep = 1
58
+ while tstep > 0:
59
+ epanet_api.runH()
60
+
61
+ assert len(epanet_api.getnodevalues(EpanetConstants.EN_PRESSURE)) > 0
62
+ assert len(epanet_api.getlinkvalues(EpanetConstants.EN_FLOW)) > 0
63
+
64
+ tstep = epanet_api.nextH()
65
+
66
+ epanet_api.closeH()
67
+
68
+ with EPyT(os.path.join("tests", "net2-cl2.inp")) as epanet_api:
69
+ __test_code(epanet_api)
70
+
71
+ with EPyT(os.path.join("tests", "net2-cl2.inp"), use_project=True) as epanet_api:
72
+ __test_code(epanet_api)
73
+
74
+
75
+ def test_quality_simulation():
76
+ def __test_code(epanet_api: EPyT):
77
+ epanet_api.openH()
78
+ epanet_api.initH(EpanetConstants.EN_NOSAVE)
79
+
80
+ epanet_api.openQ()
81
+ epanet_api.initQ(EpanetConstants.EN_NOSAVE)
82
+
83
+ tstep = 1
84
+ while tstep > 0:
85
+ epanet_api.runH()
86
+ epanet_api.runQ()
87
+
88
+ assert len(epanet_api.getnodevalues(EpanetConstants.EN_PRESSURE)) > 0
89
+ assert len(epanet_api.getlinkvalues(EpanetConstants.EN_FLOW)) > 0
90
+ assert len(epanet_api.getnodevalues(EpanetConstants.EN_QUALITY)) > 0
91
+ assert len(epanet_api.getlinkvalues(EpanetConstants.EN_QUALITY)) > 0
92
+
93
+ tstep = epanet_api.nextH()
94
+ epanet_api.nextQ()
95
+
96
+ epanet_api.closeQ()
97
+ epanet_api.closeH()
98
+
99
+ with EPyT(os.path.join("tests", "net2-cl2.inp")) as epanet_api:
100
+ __test_code(epanet_api)
101
+
102
+ with EPyT(os.path.join("tests", "net2-cl2.inp"), use_project=True) as epanet_api:
103
+ __test_code(epanet_api)
104
+
105
+
106
+ def test_msx():
107
+ with EPyT(os.path.join("tests", "net2-cl2.inp"), use_project=False) as epanet_api:
108
+ epanet_api.load_msx_file(os.path.join("tests", "net2-cl2.msx"))
109
+
110
+ assert epanet_api.get_msx_time_step() > 0
111
+ epanet_api.set_msx_time_step(150)
112
+ assert epanet_api.get_msx_time_step() == 150
113
+
114
+ epanet_api.get_all_msx_species_id()
115
+ epanet_api.get_all_msx_species_info()
@@ -0,0 +1,59 @@
1
+ """
2
+ This module tests the EPANET-PLUS function for loading an .inp file from a buffer.
3
+ """
4
+ import os
5
+ import tempfile
6
+ import epanet
7
+ from epanet_plus import EpanetConstants, EPyT
8
+
9
+
10
+ def test_load_from_buffer():
11
+ inp_buffer = ""
12
+ with open(os.path.join("tests", "net2-cl2.inp"), "rt") as f_in:
13
+ inp_buffer = "".join(f_in.readlines())
14
+
15
+ assert epanet.ENopenfrombuffer(inp_buffer, os.path.join("tests", "net2-cl2.inp"),
16
+ os.path.join("tests", "net2-cl2.rpt"), "") == (0,)
17
+
18
+ assert epanet.ENgettitle() == (0, "EPANET Example Network 2", "", "")
19
+ assert epanet.ENgetcount(EpanetConstants.EN_NODECOUNT)[1] > 0
20
+
21
+ epanet.ENclose()
22
+
23
+
24
+ def test_epyt_load_from_buffer():
25
+ def __test_code(epanet_api: EPyT):
26
+ epanet_api.openH()
27
+ epanet_api.initH(EpanetConstants.EN_NOSAVE)
28
+
29
+ epanet_api.openQ()
30
+ epanet_api.initQ(EpanetConstants.EN_NOSAVE)
31
+
32
+ tstep = 1
33
+ while tstep > 0:
34
+ epanet_api.runH()
35
+ epanet_api.runQ()
36
+
37
+ assert len(epanet_api.getnodevalues(EpanetConstants.EN_PRESSURE)) > 0
38
+ assert len(epanet_api.getlinkvalues(EpanetConstants.EN_FLOW)) > 0
39
+ assert len(epanet_api.getnodevalues(EpanetConstants.EN_QUALITY)) > 0
40
+ assert len(epanet_api.getlinkvalues(EpanetConstants.EN_QUALITY)) > 0
41
+
42
+ tstep = epanet_api.nextH()
43
+ epanet_api.nextQ()
44
+
45
+ epanet_api.closeQ()
46
+ epanet_api.closeH()
47
+
48
+ # Load .inp file into buffer
49
+ inp_buffer = ""
50
+ with open(os.path.join("tests", "net2-cl2.inp"), "rt") as f_in:
51
+ inp_buffer = "".join(f_in.readlines())
52
+
53
+ # Load .inp buffer into EPANET via EPyT
54
+ with EPyT(os.path.join(tempfile.gettempdir(), "net2-cl2.inp"), inp_buffer=inp_buffer) as epanet_api:
55
+ __test_code(epanet_api)
56
+
57
+ with EPyT(os.path.join(tempfile.gettempdir(), "net2-cl2.inp"), use_project=True,
58
+ inp_buffer=inp_buffer) as epanet_api:
59
+ __test_code(epanet_api)