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,368 @@
1
+ /*******************************************************************************
2
+ ** MODULE: MSXCOMPILER.C
3
+ ** PROJECT: EPANET-MSX
4
+ ** DESCRIPTION: compiles chemistry functions to a dynamic library file.
5
+ ** COPYRIGHT: Copyright (C) 2006 Feng Shang, Lewis Rossman, and James Uber.
6
+ ** All Rights Reserved. See license information in LICENSE.TXT.
7
+ ** AUTHORS: L. Rossman, US EPA - NRMRL
8
+ ** VERSION: 2.0.00
9
+ ** LAST UPDATE: 04/14/2021
10
+ *******************************************************************************/
11
+
12
+ #include <stdlib.h>
13
+ #include <stdio.h>
14
+ #include <string.h>
15
+
16
+ #include "msxtypes.h"
17
+ #include "msxutils.h"
18
+ #include "msxfuncs.h"
19
+
20
+ // --- define WINDOWS
21
+
22
+ #undef WINDOWS
23
+ #ifdef _WIN32
24
+ #define WINDOWS
25
+ #endif
26
+ #ifdef __WIN32__
27
+ #define WINDOWS
28
+ #endif
29
+ #ifdef WIN32
30
+ #define WINDOWS
31
+ #endif
32
+
33
+ // Local variables
34
+ //-----------------
35
+ char *Fname; // Prefix used for all file names
36
+ char TempName[L_tmpnam];
37
+ char srcFile[MAXFNAME]; // Name of source code file
38
+ char objFile[MAXFNAME]; // Name of object file
39
+ char libFile[MAXFNAME]; // Name of library file
40
+ int Compiled; // Flag for compilation step
41
+
42
+ // External variables
43
+ //--------------------
44
+ extern MSXproject MSX; // MSX project data
45
+
46
+ // Imported functions
47
+ //--------------------
48
+ char * MSXchem_getVariableStr(int i, char *s);
49
+ //void MSXrpt_writeLine(char *line);
50
+
51
+ // Exported functions
52
+ //--------------------
53
+ int MSXcompiler_open(void);
54
+ void MSXcompiler_close(void);
55
+
56
+ // Local functions
57
+ //-----------------
58
+ static void writeSrcFile(FILE* f);
59
+
60
+ //=============================================================================
61
+
62
+ int MSXcompiler_open()
63
+ /*
64
+ ** Purpose:
65
+ ** compiles MSX chemistry functions into a dynamic link library
66
+ ** and loads the functions into the running application
67
+ **
68
+ ** Input:
69
+ ** none
70
+ **
71
+ ** Returns:
72
+ ** an error code (0 if no error).
73
+ */
74
+ {
75
+ char cmd[256];
76
+ char arch[100];
77
+ FILE* f;
78
+ int err;
79
+
80
+ // --- initialize
81
+
82
+ Fname = NULL;
83
+ Compiled = FALSE;
84
+
85
+ // --- get the name of a temporary file with directory path stripped from it
86
+ // and replace any '.' characters in it (for the Borland compiler to work)
87
+
88
+ Fname = MSXutils_getTempName(TempName) ;
89
+
90
+ // --- assign names to source code and compiled files
91
+
92
+ strcpy(srcFile, Fname);
93
+ strcat(srcFile, ".c");
94
+ strcpy(objFile, Fname);
95
+ strcat(objFile, ".o");
96
+ #ifdef WINDOWS
97
+ strcpy(libFile, Fname);
98
+ strcat(libFile, ".dll");
99
+ #else
100
+ strcpy(libFile, "lib");
101
+ strcat(libFile, Fname);
102
+ strcat(libFile, ".so");
103
+ #endif
104
+
105
+ // --- write the chemistry functions to the source code file
106
+
107
+ f = fopen(srcFile, "wt");
108
+ if ( f == NULL ) return ERR_COMPILE_FAILED;
109
+ writeSrcFile(f);
110
+ fclose(f);
111
+
112
+ // --- compile the source code file to a dynamic link library file
113
+
114
+ #ifdef WINDOWS
115
+ #ifdef _WIN64
116
+ strcpy(arch, "x64");
117
+ #else
118
+ strcpy(arch, "x86");
119
+ #endif
120
+ if ( MSX.Compiler == VC )
121
+ {
122
+ sprintf(cmd, "runvc.bat %s %s", srcFile, arch);
123
+ err = MSXfuncs_run(cmd);
124
+ }
125
+
126
+ else if ( MSX.Compiler == GC )
127
+ {
128
+ sprintf(cmd, "gcc -c -O3 %s", srcFile);
129
+ err = MSXfuncs_run(cmd);
130
+ sprintf(cmd, "gcc -lm -shared -o %s %s", libFile, objFile);
131
+ err = MSXfuncs_run(cmd);
132
+ }
133
+ else return ERR_COMPILE_FAILED;
134
+ #else
135
+ if ( MSX.Compiler == GC )
136
+ {
137
+ sprintf(cmd, "gcc -c -fPIC -O3 %s", srcFile);
138
+ err = system(cmd);
139
+ sprintf(cmd, "gcc -lm -shared -o %s %s", libFile, objFile);
140
+ err = system(cmd);
141
+ }
142
+ else return ERR_COMPILE_FAILED;
143
+ #endif
144
+ Compiled = (err == 0); // ttaxon - 9/7/10
145
+
146
+ // --- load the compiled chemistry functions from the library file
147
+
148
+ if(Compiled)
149
+ {
150
+ err = MSXfuncs_load(libFile);
151
+ if ( err == 1 ) return ERR_COMPILE_FAILED;
152
+ if ( err == 2 ) return ERR_COMPILED_LOAD;
153
+ }
154
+ else
155
+ {
156
+ MSXcompiler_close();
157
+ return ERR_COMPILE_FAILED;
158
+ }
159
+ return 0;
160
+ }
161
+
162
+ //=============================================================================
163
+
164
+ void MSXcompiler_close()
165
+ /*
166
+ ** Purpose:
167
+ ** frees resources used to load chemistry functions from the shared
168
+ ** library and deletes all files used to compile and link the library.
169
+ **
170
+ ** Input:
171
+ ** none
172
+ **
173
+ ** Returns:
174
+ ** none.
175
+ */
176
+ {
177
+ char cmd[256];
178
+ if ( Compiled ) MSXfuncs_free();
179
+ if ( Fname )
180
+ {
181
+ #ifdef WINDOWS
182
+ // --- delete all files created from compilation
183
+ // (VC++ creates more than just an obj and dll file)
184
+ sprintf(cmd, "cmd /c del %s.*", Fname);
185
+ MSXfuncs_run(cmd);
186
+ #else
187
+ remove(TempName);
188
+ remove(srcFile);
189
+ remove(objFile);
190
+ remove(libFile);
191
+ #endif
192
+ }
193
+ }
194
+ //=============================================================================
195
+
196
+ void writeSrcFile(FILE* f)
197
+ /*
198
+ ** Purpose:
199
+ ** writes C statements to the chemistry function source code file
200
+ **
201
+ ** Input:
202
+ ** f = pointer to the source code file
203
+ **
204
+ ** Returns:
205
+ ** none.
206
+ **
207
+ ** Note: this function uses mathexpr_getStr() from mathexpr.c to
208
+ ** reconstruct math expressions that were previously parsed
209
+ ** into a stack of atomic terms by mathexpr_create(). The
210
+ ** mathexpr_getStr function calls MSXchem_getVariableStr (in
211
+ ** msxchem.c) to return a symbol for a particular variable that
212
+ ** is used in the reconstucted expression in place of the
213
+ ** variable's original name. For example, if NH3 were the name
214
+ ** of the 2nd chemical species, then in the source code written
215
+ ** here it would be denoted as c[2]; the third hydraulic variable,
216
+ ** Velocity, would appear as h[3]. Similar notation is used for
217
+ ** constants (k[]) and parameters (p[]).
218
+ */
219
+ {
220
+ int i;
221
+ char e[1024];
222
+ char headers[] =
223
+
224
+ " /* Machine Generated EPANET-MSX File - Do Not Edit */ \n\n"
225
+ " #include <math.h> \n"
226
+ " \n"
227
+ " #undef WINDOWS \n"
228
+ " #ifdef _WIN32 \n"
229
+ " #define WINDOWS \n"
230
+ " #endif \n"
231
+ " #ifdef __WIN32__ \n"
232
+ " #define WINDOWS \n"
233
+ " #endif \n"
234
+ " #ifdef WIN32 \n"
235
+ " #define WINDOWS \n"
236
+ " #endif \n"
237
+ " \n"
238
+ " #ifdef WINDOWS \n"
239
+ " #define DLLEXPORT __declspec(dllexport) \n"
240
+ " #else \n"
241
+ " #define DLLEXPORT \n"
242
+ " #endif \n"
243
+ " \n"
244
+ " void DLLEXPORT MSXgetPipeRates(double *, double *, double *, double *, double *); \n"
245
+ " void DLLEXPORT MSXgetTankRates(double *, double *, double *, double *, double *); \n"
246
+ " void DLLEXPORT MSXgetPipeEquil(double *, double *, double *, double *, double *); \n"
247
+ " void DLLEXPORT MSXgetTankEquil(double *, double *, double *, double *, double *); \n"
248
+ " void DLLEXPORT MSXgetPipeFormulas(double *, double *, double *, double *); \n"
249
+ " void DLLEXPORT MSXgetTankFormulas(double *, double *, double *, double *); \n"
250
+ " double term(int, double *, double *, double *, double *); \n";
251
+
252
+ char mathFuncs[] =
253
+
254
+ " double coth(double); \n"
255
+ " double cot(double); \n"
256
+ " double acot(double); \n"
257
+ " double step(double); \n"
258
+ " double sgn(double); \n"
259
+ " \n"
260
+ " double coth(double x) { \n"
261
+ " return (exp(x) + exp(-x)) / (exp(x) - exp(-x)); } \n"
262
+ " double cot(double x) { \n"
263
+ " return 1.0 / tan(x); } \n"
264
+ " double acot(double x) { \n"
265
+ " return 1.57079632679489661923 - atan(x); } \n"
266
+ " double step(double x) { \n"
267
+ " if (x <= 0.0) return 0.0; \n"
268
+ " return 1.0; } \n"
269
+ " double sgn(double x) { \n"
270
+ " if (x < 0.0) return -1.0; \n"
271
+ " if (x > 0.0) return 1.0; \n"
272
+ " return 0.0; } \n";
273
+
274
+
275
+ // --- write headers & non-intrinsic math functions to file
276
+
277
+ fprintf(f, "%s", headers);
278
+ fprintf(f, "%s", mathFuncs);
279
+
280
+ // --- write term functions
281
+
282
+ fprintf(f,
283
+ "\n double term(int i, double c[], double k[], double p[], double h[])\n { \n");
284
+ if ( MSX.Nobjects[TERM] > 0 )
285
+ {
286
+ fprintf(f, " switch(i) { \n");
287
+ for (i=1; i<=MSX.Nobjects[TERM]; i++)
288
+ {
289
+ fprintf(f, " case %d: return %s; \n",
290
+ i, mathexpr_getStr(MSX.Term[i].expr, e, MSXchem_getVariableStr));
291
+ }
292
+ fprintf(f, " } \n");
293
+ }
294
+ fprintf(f, " return 0.0; \n }\n");
295
+
296
+ // --- write pipe rate functions
297
+
298
+ fprintf(f,
299
+ "\n void DLLEXPORT MSXgetPipeRates(double c[], double k[], double p[], double h[], double f[])\n { \n");
300
+ for (i=1; i<=MSX.Nobjects[SPECIES]; i++)
301
+ {
302
+ if ( MSX.Species[i].pipeExprType == RATE )
303
+ fprintf(f, " f[%d] = %s; \n", i, mathexpr_getStr(MSX.Species[i].pipeExpr, e,
304
+ MSXchem_getVariableStr));
305
+ }
306
+ fprintf(f, " }\n");
307
+
308
+ // --- write tank rate functions
309
+
310
+ fprintf(f,
311
+ "\n void DLLEXPORT MSXgetTankRates(double c[], double k[], double p[], double h[], double f[])\n { \n");
312
+ for (i=1; i<=MSX.Nobjects[SPECIES]; i++)
313
+ {
314
+ if ( MSX.Species[i].tankExprType == RATE )
315
+ fprintf(f, " f[%d] = %s; \n", i, mathexpr_getStr(MSX.Species[i].tankExpr, e,
316
+ MSXchem_getVariableStr));
317
+ }
318
+ fprintf(f, " }\n");
319
+
320
+ // --- write pipe equilibrium functions
321
+
322
+ fprintf(f,
323
+ "\n void DLLEXPORT MSXgetPipeEquil(double c[], double k[], double p[], double h[], double f[])\n { \n");
324
+ for (i=1; i<=MSX.Nobjects[SPECIES]; i++)
325
+ {
326
+ if ( MSX.Species[i].pipeExprType == EQUIL )
327
+ fprintf(f, " f[%d] = %s; \n", i, mathexpr_getStr(MSX.Species[i].pipeExpr, e,
328
+ MSXchem_getVariableStr));
329
+ }
330
+ fprintf(f, " }\n");
331
+
332
+ // --- write tank equilibrium functions
333
+
334
+ fprintf(f,
335
+ "\n void DLLEXPORT MSXgetTankEquil(double c[], double k[], double p[], double h[], double f[])\n { \n");
336
+ for (i=1; i<=MSX.Nobjects[SPECIES]; i++)
337
+ {
338
+ if ( MSX.Species[i].tankExprType == EQUIL )
339
+ fprintf(f, " f[%d] = %s; \n", i, mathexpr_getStr(MSX.Species[i].tankExpr, e,
340
+ MSXchem_getVariableStr));
341
+ }
342
+ fprintf(f, " }\n");
343
+
344
+ // --- write pipe formula functions
345
+
346
+ fprintf(f,
347
+ "\n void DLLEXPORT MSXgetPipeFormulas(double c[], double k[], double p[], double h[])\n { \n");
348
+ for (i=1; i<=MSX.Nobjects[SPECIES]; i++)
349
+ {
350
+ if ( MSX.Species[i].pipeExprType == FORMULA )
351
+ fprintf(f, " c[%d] = %s; \n", i, mathexpr_getStr(MSX.Species[i].pipeExpr, e,
352
+ MSXchem_getVariableStr));
353
+ }
354
+ fprintf(f, " }\n");
355
+
356
+ // --- write tank formula functions
357
+
358
+ fprintf(f,
359
+ "\n void DLLEXPORT MSXgetTankFormulas(double c[], double k[], double p[], double h[])\n { \n");
360
+ for (i=1; i<=MSX.Nobjects[SPECIES]; i++)
361
+ {
362
+ if ( MSX.Species[i].tankExprType == FORMULA )
363
+ fprintf(f, " c[%d] = %s; \n", i, mathexpr_getStr(MSX.Species[i].tankExpr, e,
364
+ MSXchem_getVariableStr));
365
+ }
366
+ fprintf(f, " }\n");
367
+ fprintf(f, "\n");
368
+ }
@@ -0,0 +1,42 @@
1
+ /************************************************************************
2
+ ** MODULE: MSXDICT.H
3
+ ** PROJECT: EPANET-MSX
4
+ ** DESCRIPTION: Dictionary of key words 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: 09/29/08
11
+ ***********************************************************************/
12
+
13
+ #ifndef MSXDICT_H
14
+ #define MSXDICT_H
15
+
16
+
17
+ // NOTE: the entries in MsxsectWords must match the entries in the enumeration
18
+ // variable SectionType defined in msxtypes.h.
19
+ static char *MsxSectWords[] = {"[TITLE", "[SPECIE", "[COEFF", "[TERM",
20
+ "[PIPE", "[TANK", "[SOURCE", "[QUALITY",
21
+ "[PARAM", "[PATTERN", "[OPTION",
22
+ "[REPORT", "[DIFFU", NULL};
23
+ static char *ReportWords[] = {"NODE", "LINK", "SPECIE", "FILE", "PAGESIZE", NULL};
24
+ static char *OptionTypeWords[] = {"AREA_UNITS", "RATE_UNITS", "SOLVER", "COUPLING",
25
+ "TIMESTEP", "RTOL", "ATOL", "COMPILER", "SEGMENTS","PECLET",NULL};
26
+ static char *CompilerWords[] = {"NONE", "VC", "GC", NULL};
27
+ static char *SourceTypeWords[] = {"CONC", "MASS", "SETPOINT", "FLOW", NULL};
28
+ static char *MixingTypeWords[] = {"MIXED", "2COMP", "FIFO", "LIFO", NULL};
29
+ static char *MassUnitsWords[] = {"MG", "UG", "MOLE", "MMOL", NULL};
30
+ static char *AreaUnitsWords[] = {"FT2", "M2", "CM2", NULL};
31
+ static char *TimeUnitsWords[] = {"SEC", "MIN", "HR", "DAY", NULL};
32
+ static char *SolverTypeWords[] = {"EUL", "RK5", "ROS2", NULL};
33
+ static char *CouplingWords[] = {"NONE", "FULL", NULL};
34
+ static char *ExprTypeWords[] = {"", "RATE", "FORMULA", "EQUIL", NULL};
35
+ static char *HydVarWords[] = {"", "D", "Q", "U", "Re",
36
+ "Us", "Ff", "Av", "Kc", "Len", NULL}; /*Len added Feng Shang 01/27/2023*/
37
+ static char YES[] = "YES";
38
+ static char NO[] = "NO";
39
+ static char ALL[] = "ALL";
40
+ static char NONE[] = "NONE";
41
+
42
+ #endif