epanet-plus 0.0.1__cp313-cp313-musllinux_1_2_x86_64.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.

Potentially problematic release.


This version of epanet-plus might be problematic. Click here for more details.

Files changed (105) 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-313-x86_64-linux-musl.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 +2730 -0
  85. epanet_plus/epanet_wrapper.py +2414 -0
  86. epanet_plus/include/epanet_plus.h +9 -0
  87. epanet_plus-0.0.1.dist-info/METADATA +152 -0
  88. epanet_plus-0.0.1.dist-info/RECORD +105 -0
  89. epanet_plus-0.0.1.dist-info/WHEEL +5 -0
  90. epanet_plus-0.0.1.dist-info/licenses/LICENSE +21 -0
  91. epanet_plus-0.0.1.dist-info/top_level.txt +11 -0
  92. examples/basic_usage.py +35 -0
  93. python-extension/ext.c +344 -0
  94. python-extension/pyepanet.c +2133 -0
  95. python-extension/pyepanet.h +143 -0
  96. python-extension/pyepanet2.c +1823 -0
  97. python-extension/pyepanet2.h +141 -0
  98. python-extension/pyepanet_plus.c +37 -0
  99. python-extension/pyepanet_plus.h +4 -0
  100. python-extension/pyepanetmsx.c +388 -0
  101. python-extension/pyepanetmsx.h +35 -0
  102. tests/test_epanet.py +16 -0
  103. tests/test_epanetmsx.py +36 -0
  104. tests/test_epyt.py +114 -0
  105. tests/test_load_inp_from_buffer.py +18 -0
@@ -0,0 +1,398 @@
1
+ /******************************************************************************
2
+ ** MODULE: MSXOUT.C
3
+ ** PROJECT: EPANET-MSX
4
+ ** DESCRIPTION: I/O routines for the binary output file used by the
5
+ ** EPANET Multi-Species Extension toolkit.
6
+ ** AUTHORS: see AUTHORS
7
+ ** Copyright: see AUTHORS
8
+ ** License: see LICENSE
9
+ ** VERSION: 2.0.00
10
+ ** LAST UPDATE: 08/30/2022
11
+ ******************************************************************************/
12
+
13
+ #include <stdio.h>
14
+ #include <string.h>
15
+ #include <math.h>
16
+ #include <stdlib.h>
17
+
18
+ #include "msxtypes.h"
19
+
20
+ // External variables
21
+ //--------------------
22
+ extern MSXproject MSX; // MSX project data
23
+
24
+ // Local variables
25
+ //-----------------
26
+ static long ResultsOffset; // Offset byte where results begin
27
+ static long NodeBytesPerPeriod; // Bytes per time period used by all nodes
28
+ static long LinkBytesPerPeriod; // Bytes per time period used by all links
29
+
30
+ // Imported functions
31
+ //--------------------
32
+ double MSXqual_getNodeQual(int j, int m);
33
+ double MSXqual_getLinkQual(int k, int m);
34
+
35
+ // Exported functions
36
+ //--------------------
37
+ int MSXout_open(void);
38
+ int MSXout_saveInitialResults(void);
39
+ int MSXout_saveResults(void);
40
+ int MSXout_saveFinalResults(void);
41
+ float MSXout_getNodeQual(int k, int j, int m);
42
+ float MSXout_getLinkQual(int k, int j, int m);
43
+
44
+ // Local functions
45
+ //-----------------
46
+ static int saveStatResults(void);
47
+ static void getStatResults(int objType, int m, double* stats1,
48
+ double* stats2, REAL4* x);
49
+
50
+
51
+ //=============================================================================
52
+
53
+ int MSXout_open()
54
+ /*
55
+ ** Purpose:
56
+ ** opens an MSX binary output file.
57
+ **
58
+ ** Input:
59
+ ** none.
60
+ **
61
+ ** Returns:
62
+ ** an error code (or 0 if no error).
63
+ */
64
+ {
65
+ // --- close output file if already opened
66
+
67
+ if (MSX.OutFile.file != NULL) fclose(MSX.OutFile.file);
68
+
69
+ // --- try to open the file
70
+
71
+ if ( (MSX.OutFile.file = fopen(MSX.OutFile.name, "w+b")) == NULL)
72
+ {
73
+ return ERR_OPEN_OUT_FILE;
74
+ }
75
+
76
+ // --- open a scratch output file for statistics
77
+
78
+ if ( MSX.Statflag == SERIES ) MSX.TmpOutFile.file = MSX.OutFile.file;
79
+ else if ( (MSX.TmpOutFile.file = fopen(MSX.TmpOutFile.name, "w+b")) == NULL)
80
+ {
81
+ return ERR_OPEN_OUT_FILE;
82
+ }
83
+
84
+ // --- write initial results to file
85
+
86
+ MSX.Nperiods = 0;
87
+ MSXout_saveInitialResults();
88
+ return 0;
89
+ }
90
+
91
+ //=============================================================================
92
+
93
+ int MSXout_saveInitialResults()
94
+ /*
95
+ ** Purpose:
96
+ ** saves general information to beginning of MSX binary output file.
97
+ **
98
+ ** Input:
99
+ ** none.
100
+ **
101
+ ** Returns:
102
+ ** an error code (or 0 if no error).
103
+ */
104
+ {
105
+ int m;
106
+ INT4 n;
107
+ INT4 magic = MAGICNUMBER;
108
+ INT4 version = VERSION;
109
+ FILE* f = MSX.OutFile.file;
110
+
111
+ rewind(f);
112
+ fwrite(&magic, sizeof(INT4), 1, f); //Magic number
113
+ fwrite(&version, sizeof(INT4), 1, f); //Version number
114
+ n = (INT4)MSX.Nobjects[NODE];
115
+ fwrite(&n, sizeof(INT4), 1, f); //Number of nodes
116
+ n = (INT4)MSX.Nobjects[LINK];
117
+ fwrite(&n, sizeof(INT4), 1, f); //Number of links
118
+ n = (INT4)MSX.Nobjects[SPECIES];
119
+ fwrite(&n, sizeof(INT4), 1, f); //Number of species
120
+ n = (INT4)MSX.Rstep;
121
+ fwrite(&n, sizeof(INT4), 1, f); //Reporting step size
122
+ for (m=1; m<=MSX.Nobjects[SPECIES]; m++)
123
+ {
124
+ n = (INT4)strlen(MSX.Species[m].id);
125
+ fwrite(&n, sizeof(INT4), 1, f); //Length of species ID
126
+ fwrite(MSX.Species[m].id, sizeof(char), n, f); //Species ID string
127
+ fwrite(&MSX.Species[m].units, sizeof(char), MAXUNITS, f); //Species mass units
128
+ }
129
+ ResultsOffset = ftell(f);
130
+ NodeBytesPerPeriod = MSX.Nobjects[NODE]*MSX.Nobjects[SPECIES]*sizeof(REAL4);
131
+ LinkBytesPerPeriod = MSX.Nobjects[LINK]*MSX.Nobjects[SPECIES]*sizeof(REAL4);
132
+ return 0;
133
+ }
134
+
135
+
136
+ //=============================================================================
137
+
138
+ int MSXout_saveResults()
139
+ /*
140
+ ** Purpose:
141
+ ** saves computed species concentrations for each node and link at the
142
+ ** current time period to the temporary MSX binary output file (which
143
+ ** will be the same as the permanent MSX binary file if time series
144
+ ** values were specified as the reported statistic, which is the
145
+ ** default case).
146
+ **
147
+ ** Input:
148
+ ** none.
149
+ **
150
+ ** Returns:
151
+ ** an error code (or 0 if no error).
152
+ */
153
+ {
154
+ int m, j;
155
+ REAL4 x;
156
+ for (m=1; m<=MSX.Nobjects[SPECIES]; m++)
157
+ {
158
+ for (j=1; j<=MSX.Nobjects[NODE]; j++)
159
+ {
160
+ x = (REAL4)MSXqual_getNodeQual(j, m);
161
+ fwrite(&x, sizeof(REAL4), 1, MSX.TmpOutFile.file);
162
+ }
163
+ }
164
+ for (m=1; m<=MSX.Nobjects[SPECIES]; m++)
165
+ {
166
+ for (j=1; j<=MSX.Nobjects[LINK]; j++)
167
+ {
168
+ x = (REAL4)MSXqual_getLinkQual(j, m);
169
+ fwrite(&x, sizeof(REAL4), 1, MSX.TmpOutFile.file);
170
+ }
171
+ }
172
+ return 0;
173
+ }
174
+
175
+ //=============================================================================
176
+
177
+ int MSXout_saveFinalResults()
178
+ /*
179
+ ** Purpose:
180
+ ** saves any statistical results plus the following information to the end
181
+ ** of the MSX binary output file:
182
+ ** - byte offset into file where WQ results for each time period begins,
183
+ ** - total number of time periods written to the file,
184
+ ** - any error code generated by the analysis (0 if there were no errors),
185
+ ** - the Magic Number to indicate that the file is complete.
186
+ **
187
+ ** Input:
188
+ ** none.
189
+ **
190
+ ** Returns:
191
+ ** an error code (or 0 if no error).
192
+ */
193
+ {
194
+ INT4 n;
195
+ INT4 magic = MAGICNUMBER;
196
+ int err = 0;
197
+
198
+ // --- save statistical results to the file
199
+
200
+ if ( MSX.Statflag != SERIES ) err = saveStatResults();
201
+ if ( err > 0 ) return err;
202
+
203
+ // --- write closing records to the file
204
+
205
+ n = (INT4)ResultsOffset;
206
+ fwrite(&n, sizeof(INT4), 1, MSX.OutFile.file);
207
+ n = (INT4)MSX.Nperiods;
208
+ fwrite(&n, sizeof(INT4), 1, MSX.OutFile.file);
209
+ n = (INT4)MSX.ErrCode;
210
+ fwrite(&n, sizeof(INT4), 1, MSX.OutFile.file);
211
+ fwrite(&magic, sizeof(INT4), 1, MSX.OutFile.file);
212
+ return 0;
213
+ }
214
+
215
+ //=============================================================================
216
+
217
+ float MSXout_getNodeQual(int k, int j, int m)
218
+ /*
219
+ ** Purpose:
220
+ ** retrieves a result for a specific node from the MSX binary output file.
221
+ **
222
+ ** Input:
223
+ ** k = time period index
224
+ ** j = node index
225
+ ** m = species index.
226
+ **
227
+ ** Returns:
228
+ ** the requested species concentration.
229
+ */
230
+ {
231
+ REAL4 c;
232
+ long bp = ResultsOffset + k * (NodeBytesPerPeriod + LinkBytesPerPeriod);
233
+ bp += ((m-1)*MSX.Nobjects[NODE] + (j-1)) * sizeof(REAL4);
234
+ fseek(MSX.OutFile.file, bp, SEEK_SET);
235
+ fread(&c, sizeof(REAL4), 1, MSX.OutFile.file);
236
+ return (float)c;
237
+ }
238
+
239
+ //=============================================================================
240
+
241
+ float MSXout_getLinkQual(int k, int j, int m)
242
+ /*
243
+ ** Purpose:
244
+ ** retrieves a result for a specific link from the MSX binary output file.
245
+ **
246
+ ** Input:
247
+ ** k = time period index
248
+ ** j = link index
249
+ ** m = species index.
250
+ **
251
+ ** Returns:
252
+ ** the requested species concentration.
253
+ */
254
+ {
255
+ REAL4 c;
256
+ long bp = ResultsOffset + ((k+1)*NodeBytesPerPeriod) + (k*LinkBytesPerPeriod);
257
+ bp += ((m-1)*MSX.Nobjects[LINK] + (j-1)) * sizeof(REAL4);
258
+ fseek(MSX.OutFile.file, bp, SEEK_SET);
259
+ fread(&c, sizeof(REAL4), 1, MSX.OutFile.file);
260
+ return (float)c;
261
+ }
262
+
263
+ //=============================================================================
264
+
265
+ int saveStatResults()
266
+ /*
267
+ ** Purpose:
268
+ ** saves time statistic results (average, min., max., or range) for each
269
+ ** node and link to the permanent binary output file.
270
+ **
271
+ ** Input:
272
+ ** none.
273
+ **
274
+ ** Returns:
275
+ ** an error code (or 0 if no error).
276
+ */
277
+ {
278
+ int m, err = 0;
279
+ REAL4* x = NULL;
280
+ double* stats1 = NULL;
281
+ double* stats2 = NULL;
282
+
283
+ // --- create arrays used to store statistics results
284
+
285
+ if ( MSX.Nperiods <= 0 ) return err;
286
+ m = MAX(MSX.Nobjects[NODE], MSX.Nobjects[LINK]);
287
+ x = (REAL4 *) calloc(m+1, sizeof(REAL4));
288
+ stats1 = (double *) calloc(m+1, sizeof(double));
289
+ stats2 = (double *) calloc(m+1, sizeof(double));
290
+
291
+ // --- get desired statistic for each node & link and save to binary file
292
+
293
+ if ( x && stats1 && stats2 )
294
+ {
295
+ for (m = 1; m <= MSX.Nobjects[SPECIES]; m++ )
296
+ {
297
+ getStatResults(NODE, m, stats1, stats2, x);
298
+ fwrite(x+1, sizeof(REAL4), MSX.Nobjects[NODE], MSX.OutFile.file);
299
+ }
300
+ for (m = 1; m <= MSX.Nobjects[SPECIES]; m++)
301
+ {
302
+ getStatResults(LINK, m, stats1, stats2, x);
303
+ fwrite(x+1, sizeof(REAL4), MSX.Nobjects[LINK], MSX.OutFile.file);
304
+ }
305
+ MSX.Nperiods = 1;
306
+ }
307
+ else err = ERR_MEMORY;
308
+
309
+ // --- free allocated arrays
310
+
311
+ FREE(x);
312
+ FREE(stats1);
313
+ FREE(stats2);
314
+ return err;
315
+ }
316
+
317
+ //=============================================================================
318
+
319
+ void getStatResults(int objType, int m, double * stats1, double * stats2,
320
+ REAL4 * x)
321
+ /*
322
+ ** Purpose:
323
+ ** reads all results for a given type of object from the temporary
324
+ ** binary output file and computes the required statistic (average,
325
+ ** min., max., or range) for each object.
326
+ **
327
+ ** Input:
328
+ ** objType = type of object (nodes or links)
329
+ ** m = species index
330
+ ** stats1, stats2 = work arrays used to hold intermediate values
331
+ ** x = array used to store results read from file.
332
+ **
333
+ ** Output:
334
+ ** x = array that contains computed statistic for each object.
335
+ */
336
+ {
337
+ int j, k;
338
+ int n = MSX.Nobjects[objType];
339
+ long bp;
340
+
341
+ // --- initialize work arrays
342
+
343
+ for (j = 1; j <= n; j++)
344
+ {
345
+ stats1[j] = 0.0;
346
+ stats2[j] = 0.0;
347
+ }
348
+
349
+ // --- for all time periods
350
+
351
+ for (k = 0; k < MSX.Nperiods; k++)
352
+ {
353
+
354
+ // --- position file at start of time period
355
+
356
+ bp = k*(NodeBytesPerPeriod + LinkBytesPerPeriod);
357
+ if ( objType == NODE )
358
+ {
359
+ bp += (m-1) * MSX.Nobjects[NODE] * sizeof(REAL4);
360
+ }
361
+ if ( objType == LINK)
362
+ {
363
+ bp += NodeBytesPerPeriod +
364
+ (m-1) * MSX.Nobjects[LINK] * sizeof(REAL4);
365
+ }
366
+ fseek(MSX.TmpOutFile.file, bp, SEEK_SET);
367
+
368
+ // --- read concentrations and update stats for all objects
369
+
370
+ fread(x+1, sizeof(REAL4), n, MSX.TmpOutFile.file);
371
+ if ( MSX.Statflag == AVGERAGE )
372
+ {
373
+ for (j = 1; j <= n; j++) stats1[j] += x[j];
374
+ }
375
+ else for (j = 1; j <= n; j++)
376
+ {
377
+ stats1[j] = MIN(stats1[j], x[j]);
378
+ stats2[j] = MAX(stats2[j], x[j]);
379
+ }
380
+ }
381
+
382
+ // --- place final stat value for each object in x
383
+
384
+ if ( MSX.Statflag == AVGERAGE )
385
+ {
386
+ for ( j = 1; j <= n; j++) stats1[j] /= (double)MSX.Nperiods;
387
+ }
388
+ if ( MSX.Statflag == RANGE )
389
+ {
390
+ for ( j = 1; j <= n; j++)
391
+ stats1[j] = fabs(stats2[j] - stats1[j]);
392
+ }
393
+ if ( MSX.Statflag == MAXIMUM)
394
+ {
395
+ for ( j = 1; j <= MSX.Nobjects[NODE]; j++) stats1[j] = stats2[j];
396
+ }
397
+ for (j = 1; j <= n; j++) x[j] = (REAL4)stats1[j];
398
+ }