epanet-plus 0.0.1__cp311-cp311-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.
- docs/conf.py +67 -0
- epanet-msx-src/dispersion.h +27 -0
- epanet-msx-src/hash.c +107 -0
- epanet-msx-src/hash.h +28 -0
- epanet-msx-src/include/epanetmsx.h +104 -0
- epanet-msx-src/include/epanetmsx_export.h +42 -0
- epanet-msx-src/mathexpr.c +937 -0
- epanet-msx-src/mathexpr.h +39 -0
- epanet-msx-src/mempool.c +204 -0
- epanet-msx-src/mempool.h +24 -0
- epanet-msx-src/msxchem.c +1285 -0
- epanet-msx-src/msxcompiler.c +368 -0
- epanet-msx-src/msxdict.h +42 -0
- epanet-msx-src/msxdispersion.c +586 -0
- epanet-msx-src/msxerr.c +116 -0
- epanet-msx-src/msxfile.c +260 -0
- epanet-msx-src/msxfuncs.c +175 -0
- epanet-msx-src/msxfuncs.h +35 -0
- epanet-msx-src/msxinp.c +1504 -0
- epanet-msx-src/msxout.c +398 -0
- epanet-msx-src/msxproj.c +791 -0
- epanet-msx-src/msxqual.c +2011 -0
- epanet-msx-src/msxrpt.c +400 -0
- epanet-msx-src/msxtank.c +422 -0
- epanet-msx-src/msxtoolkit.c +1164 -0
- epanet-msx-src/msxtypes.h +551 -0
- epanet-msx-src/msxutils.c +524 -0
- epanet-msx-src/msxutils.h +56 -0
- epanet-msx-src/newton.c +158 -0
- epanet-msx-src/newton.h +34 -0
- epanet-msx-src/rk5.c +287 -0
- epanet-msx-src/rk5.h +39 -0
- epanet-msx-src/ros2.c +293 -0
- epanet-msx-src/ros2.h +35 -0
- epanet-msx-src/smatrix.c +816 -0
- epanet-msx-src/smatrix.h +29 -0
- epanet-src/AUTHORS +60 -0
- epanet-src/LICENSE +21 -0
- epanet-src/enumstxt.h +151 -0
- epanet-src/epanet.c +5937 -0
- epanet-src/epanet2.c +961 -0
- epanet-src/epanet2.def +131 -0
- epanet-src/errors.dat +79 -0
- epanet-src/flowbalance.c +186 -0
- epanet-src/funcs.h +219 -0
- epanet-src/genmmd.c +1000 -0
- epanet-src/hash.c +177 -0
- epanet-src/hash.h +28 -0
- epanet-src/hydcoeffs.c +1303 -0
- epanet-src/hydraul.c +1164 -0
- epanet-src/hydsolver.c +781 -0
- epanet-src/hydstatus.c +442 -0
- epanet-src/include/epanet2.h +466 -0
- epanet-src/include/epanet2_2.h +1962 -0
- epanet-src/include/epanet2_enums.h +518 -0
- epanet-src/inpfile.c +884 -0
- epanet-src/input1.c +672 -0
- epanet-src/input2.c +970 -0
- epanet-src/input3.c +2265 -0
- epanet-src/leakage.c +527 -0
- epanet-src/mempool.c +146 -0
- epanet-src/mempool.h +24 -0
- epanet-src/output.c +853 -0
- epanet-src/project.c +1691 -0
- epanet-src/quality.c +695 -0
- epanet-src/qualreact.c +800 -0
- epanet-src/qualroute.c +696 -0
- epanet-src/report.c +1559 -0
- epanet-src/rules.c +1500 -0
- epanet-src/smatrix.c +871 -0
- epanet-src/text.h +508 -0
- epanet-src/types.h +928 -0
- epanet-src/util/cstr_helper.c +59 -0
- epanet-src/util/cstr_helper.h +38 -0
- epanet-src/util/errormanager.c +92 -0
- epanet-src/util/errormanager.h +39 -0
- epanet-src/util/filemanager.c +212 -0
- epanet-src/util/filemanager.h +81 -0
- epanet-src/validate.c +408 -0
- epanet.cpython-311-x86_64-linux-musl.so +0 -0
- epanet_plus/VERSION +1 -0
- epanet_plus/__init__.py +8 -0
- epanet_plus/epanet_plus.c +118 -0
- epanet_plus/epanet_toolkit.py +2730 -0
- epanet_plus/epanet_wrapper.py +2414 -0
- epanet_plus/include/epanet_plus.h +9 -0
- epanet_plus-0.0.1.dist-info/METADATA +152 -0
- epanet_plus-0.0.1.dist-info/RECORD +105 -0
- epanet_plus-0.0.1.dist-info/WHEEL +5 -0
- epanet_plus-0.0.1.dist-info/licenses/LICENSE +21 -0
- epanet_plus-0.0.1.dist-info/top_level.txt +11 -0
- examples/basic_usage.py +35 -0
- python-extension/ext.c +344 -0
- python-extension/pyepanet.c +2133 -0
- python-extension/pyepanet.h +143 -0
- python-extension/pyepanet2.c +1823 -0
- python-extension/pyepanet2.h +141 -0
- python-extension/pyepanet_plus.c +37 -0
- python-extension/pyepanet_plus.h +4 -0
- python-extension/pyepanetmsx.c +388 -0
- python-extension/pyepanetmsx.h +35 -0
- tests/test_epanet.py +16 -0
- tests/test_epanetmsx.py +36 -0
- tests/test_epyt.py +114 -0
- tests/test_load_inp_from_buffer.py +18 -0
epanet-msx-src/ros2.c
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/*******************************************************************************
|
|
2
|
+
** MODULE: ROS2.C
|
|
3
|
+
** PROJECT: EPANET-MSX
|
|
4
|
+
** DESCRIPTION: a second order Rosenbrock 2(1) method for solving stiff sets of
|
|
5
|
+
** ordinary differential equations.
|
|
6
|
+
** AUTHOR: L. Rossman, US EPA - NRMRL
|
|
7
|
+
** VERSION: 2.0.00
|
|
8
|
+
** LAST UPDATE: 04/14/2021
|
|
9
|
+
**
|
|
10
|
+
** This code is based on material presented in:
|
|
11
|
+
** Verwer, J.G., Spee, E.J., Blom, J.G. and Hundsdorfer, W.H.,
|
|
12
|
+
** "A second order Rosenbrock method applied to photochemical dispersion
|
|
13
|
+
** problems", SIAM J. Sci. Comput., 20:1456-1480, July 1999.
|
|
14
|
+
*******************************************************************************/
|
|
15
|
+
|
|
16
|
+
#include <stdlib.h>
|
|
17
|
+
#include <math.h>
|
|
18
|
+
#include "msxutils.h"
|
|
19
|
+
#include "ros2.h"
|
|
20
|
+
|
|
21
|
+
#define fmin(x,y) (((x)<=(y)) ? (x) : (y)) /* minimum of x and y */
|
|
22
|
+
#define fmax(x,y) (((x)>=(y)) ? (x) : (y)) /* maximum of x and y */
|
|
23
|
+
|
|
24
|
+
// Local variables
|
|
25
|
+
//-----------------
|
|
26
|
+
MSXRosenbrock MSXRosenbrockSolver;
|
|
27
|
+
|
|
28
|
+
#pragma omp threadprivate(MSXRosenbrockSolver)
|
|
29
|
+
|
|
30
|
+
//=============================================================================
|
|
31
|
+
|
|
32
|
+
int ros2_open(int n, int adjust)
|
|
33
|
+
/*
|
|
34
|
+
** Purpose:
|
|
35
|
+
** Opens the ROS2 integrator.
|
|
36
|
+
**
|
|
37
|
+
** Input:
|
|
38
|
+
** n = number of equations to be solved
|
|
39
|
+
** adjust = 1 if step size adjustment used, 0 if not
|
|
40
|
+
**
|
|
41
|
+
** Returns:
|
|
42
|
+
** 1 if successful, 0 if not.
|
|
43
|
+
*/
|
|
44
|
+
{
|
|
45
|
+
int errorcode = 1;
|
|
46
|
+
int n1 = n + 1;
|
|
47
|
+
|
|
48
|
+
#pragma omp parallel
|
|
49
|
+
{
|
|
50
|
+
MSXRosenbrockSolver.Nmax = n;
|
|
51
|
+
MSXRosenbrockSolver.Adjust = adjust;
|
|
52
|
+
MSXRosenbrockSolver.K1 = NULL;
|
|
53
|
+
MSXRosenbrockSolver.K2 = NULL;
|
|
54
|
+
MSXRosenbrockSolver.Jindx = NULL;
|
|
55
|
+
MSXRosenbrockSolver.Ynew = NULL;
|
|
56
|
+
MSXRosenbrockSolver.A = NULL;
|
|
57
|
+
MSXRosenbrockSolver.K1 = (double*)calloc(n1, sizeof(double));
|
|
58
|
+
MSXRosenbrockSolver.K2 = (double*)calloc(n1, sizeof(double));
|
|
59
|
+
MSXRosenbrockSolver.Jindx = (int*)calloc(n1, sizeof(int));
|
|
60
|
+
MSXRosenbrockSolver.Ynew = (double*)calloc(n1, sizeof(double));
|
|
61
|
+
MSXRosenbrockSolver.A = createMatrix(n1, n1);
|
|
62
|
+
#pragma omp critical
|
|
63
|
+
{
|
|
64
|
+
if (!MSXRosenbrockSolver.Jindx || !MSXRosenbrockSolver.Ynew ||
|
|
65
|
+
!MSXRosenbrockSolver.K1 || !MSXRosenbrockSolver.K2) errorcode = 0;
|
|
66
|
+
if (!MSXRosenbrockSolver.A) errorcode = 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return errorcode;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//=============================================================================
|
|
74
|
+
|
|
75
|
+
void ros2_close()
|
|
76
|
+
/*
|
|
77
|
+
** Purpose:
|
|
78
|
+
** closes the ROS2 integrator.
|
|
79
|
+
**
|
|
80
|
+
** Input:
|
|
81
|
+
** none.
|
|
82
|
+
*/
|
|
83
|
+
{
|
|
84
|
+
|
|
85
|
+
#pragma omp parallel
|
|
86
|
+
{
|
|
87
|
+
|
|
88
|
+
if (MSXRosenbrockSolver.Jindx) { free(MSXRosenbrockSolver.Jindx); MSXRosenbrockSolver.Jindx = NULL; }
|
|
89
|
+
if (MSXRosenbrockSolver.Ynew) { free(MSXRosenbrockSolver.Ynew); MSXRosenbrockSolver.Ynew = NULL; }
|
|
90
|
+
if (MSXRosenbrockSolver.K1) { free(MSXRosenbrockSolver.K1); MSXRosenbrockSolver.K1 = NULL; }
|
|
91
|
+
if (MSXRosenbrockSolver.K2) { free(MSXRosenbrockSolver.K2); MSXRosenbrockSolver.K2 = NULL; }
|
|
92
|
+
freeMatrix(MSXRosenbrockSolver.A);
|
|
93
|
+
MSXRosenbrockSolver.A = NULL;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//=============================================================================
|
|
99
|
+
|
|
100
|
+
int ros2_integrate(double y[], int n, double t, double tnext,
|
|
101
|
+
double* htry, double atol[], double rtol[],
|
|
102
|
+
void (*func)(double, double*, int, double*))
|
|
103
|
+
/*
|
|
104
|
+
** Purpose:
|
|
105
|
+
** integrates a system of ODEs over a specified time interval.
|
|
106
|
+
**
|
|
107
|
+
** Input:
|
|
108
|
+
** y[1..n] = vector of dependent variable values at the start
|
|
109
|
+
** of the integration interval
|
|
110
|
+
** n = number of dependent variables
|
|
111
|
+
** t = time value at the start of the interval
|
|
112
|
+
** tnext = time value at the end of the interval
|
|
113
|
+
** htry = initial step size to be taken
|
|
114
|
+
** atol[1..n] = vector of absolute tolerances on the variables y
|
|
115
|
+
** rtol[1..n] = vector of relative tolerances on the variables y
|
|
116
|
+
** func = name of the function that computes dy/dt for each y
|
|
117
|
+
**
|
|
118
|
+
** Output:
|
|
119
|
+
** htry = size of the last full time step taken.
|
|
120
|
+
**
|
|
121
|
+
** Returns:
|
|
122
|
+
** the number of times that func() was called, -1 if
|
|
123
|
+
** the Jacobian is singular, or -2 if the step size
|
|
124
|
+
** shrinks to 0.
|
|
125
|
+
**
|
|
126
|
+
** Notes:
|
|
127
|
+
** 1. The arguments to the function func() are:
|
|
128
|
+
** t = current time
|
|
129
|
+
** y[1..n] = vector of dependent variable values
|
|
130
|
+
** n = number of dependent variables
|
|
131
|
+
** dfdy[1..n] = vector of derivative values computed.
|
|
132
|
+
**
|
|
133
|
+
** 2. The arrays used in this function are 1-based, so
|
|
134
|
+
** they must have been sized to n+1 when first created.
|
|
135
|
+
*/
|
|
136
|
+
{
|
|
137
|
+
double UROUND = 2.3e-16;
|
|
138
|
+
double g, ghinv, ghinv1, dghinv, ytol;
|
|
139
|
+
double h, hold, hmin, hmax, tplus;
|
|
140
|
+
double ej, err, factor, facmax;
|
|
141
|
+
int nfcn, njac, naccept, nreject, j;
|
|
142
|
+
int isReject;
|
|
143
|
+
int adjust = MSXRosenbrockSolver.Adjust;
|
|
144
|
+
|
|
145
|
+
// --- Initialize counters, etc.
|
|
146
|
+
|
|
147
|
+
g = 1.0 + 1.0 / sqrt(2.0);
|
|
148
|
+
ghinv1 = 0.0;
|
|
149
|
+
tplus = t;
|
|
150
|
+
isReject = 0;
|
|
151
|
+
naccept = 0;
|
|
152
|
+
nreject = 0;
|
|
153
|
+
nfcn = 0;
|
|
154
|
+
njac = 0;
|
|
155
|
+
|
|
156
|
+
// --- Initial step size
|
|
157
|
+
|
|
158
|
+
hmax = tnext - t;
|
|
159
|
+
hmin = 1.e-8;
|
|
160
|
+
h = *htry;
|
|
161
|
+
if ( h == 0.0 )
|
|
162
|
+
{
|
|
163
|
+
func(t, y, n, MSXRosenbrockSolver.K1);
|
|
164
|
+
nfcn += 1;
|
|
165
|
+
adjust = 1;
|
|
166
|
+
h = tnext - t;
|
|
167
|
+
for (j=1; j<=n; j++)
|
|
168
|
+
{
|
|
169
|
+
ytol = atol[j] + rtol[j]*fabs(y[j]);
|
|
170
|
+
if (MSXRosenbrockSolver.K1[j] != 0.0) h = fmin(h, (ytol/fabs(MSXRosenbrockSolver.K1[j])));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
h = fmax(hmin, h);
|
|
174
|
+
h = fmin(hmax, h);
|
|
175
|
+
|
|
176
|
+
// --- Start the time loop
|
|
177
|
+
|
|
178
|
+
while ( t < tnext )
|
|
179
|
+
{
|
|
180
|
+
// --- check for zero step size
|
|
181
|
+
|
|
182
|
+
if (0.10*fabs(h) <= fabs(t)*UROUND) return -2;
|
|
183
|
+
|
|
184
|
+
// --- adjust step size if interval exceeded
|
|
185
|
+
|
|
186
|
+
tplus = t + h;
|
|
187
|
+
if ( tplus > tnext )
|
|
188
|
+
{
|
|
189
|
+
h = tnext - t;
|
|
190
|
+
tplus = tnext;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// --- Re-compute the Jacobian if step size accepted
|
|
194
|
+
|
|
195
|
+
if ( isReject == 0 )
|
|
196
|
+
{
|
|
197
|
+
jacobian(y, n, MSXRosenbrockSolver.K1, MSXRosenbrockSolver.K2, MSXRosenbrockSolver.A, func);
|
|
198
|
+
njac++;
|
|
199
|
+
nfcn += 2*n;
|
|
200
|
+
ghinv1 = 0.0;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// --- Update the Jacobian to reflect new step size
|
|
204
|
+
|
|
205
|
+
ghinv = -1.0 / (g*h);
|
|
206
|
+
dghinv = ghinv - ghinv1;
|
|
207
|
+
for (j=1; j<=n; j++)
|
|
208
|
+
{
|
|
209
|
+
MSXRosenbrockSolver.A[j][j] += dghinv;
|
|
210
|
+
}
|
|
211
|
+
ghinv1 = ghinv;
|
|
212
|
+
if ( !factorize(MSXRosenbrockSolver.A, n, MSXRosenbrockSolver.K1, MSXRosenbrockSolver.Jindx) ) return -1;
|
|
213
|
+
|
|
214
|
+
// --- Stage 1 solution
|
|
215
|
+
|
|
216
|
+
func(t, y, n, MSXRosenbrockSolver.K1);
|
|
217
|
+
nfcn += 1;
|
|
218
|
+
for (j=1; j<=n; j++) MSXRosenbrockSolver.K1[j] *= ghinv;
|
|
219
|
+
solve(MSXRosenbrockSolver.A, n, MSXRosenbrockSolver.Jindx, MSXRosenbrockSolver.K1);
|
|
220
|
+
|
|
221
|
+
// --- Stage 2 solution
|
|
222
|
+
|
|
223
|
+
for (j=1; j<=n; j++)
|
|
224
|
+
{
|
|
225
|
+
MSXRosenbrockSolver.Ynew[j] = y[j] + h* MSXRosenbrockSolver.K1[j];
|
|
226
|
+
}
|
|
227
|
+
func(t, MSXRosenbrockSolver.Ynew, n, MSXRosenbrockSolver.K2);
|
|
228
|
+
nfcn += 1;
|
|
229
|
+
for (j=1; j<=n; j++)
|
|
230
|
+
{
|
|
231
|
+
MSXRosenbrockSolver.K2[j] = (MSXRosenbrockSolver.K2[j] - 2.0* MSXRosenbrockSolver.K1[j])*ghinv;
|
|
232
|
+
}
|
|
233
|
+
solve(MSXRosenbrockSolver.A, n, MSXRosenbrockSolver.Jindx, MSXRosenbrockSolver.K2);
|
|
234
|
+
|
|
235
|
+
// --- Overall solution
|
|
236
|
+
|
|
237
|
+
for (j=1; j<=n; j++)
|
|
238
|
+
{
|
|
239
|
+
MSXRosenbrockSolver.Ynew[j] = y[j] + 1.5*h* MSXRosenbrockSolver.K1[j] + 0.5*h* MSXRosenbrockSolver.K2[j];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// --- Error estimation
|
|
243
|
+
|
|
244
|
+
hold = h;
|
|
245
|
+
err = 0.0;
|
|
246
|
+
if ( adjust )
|
|
247
|
+
{
|
|
248
|
+
for (j=1; j<=n; j++)
|
|
249
|
+
{
|
|
250
|
+
ytol = atol[j] + rtol[j]*fabs(MSXRosenbrockSolver.Ynew[j]);
|
|
251
|
+
ej = fabs(MSXRosenbrockSolver.Ynew[j] - y[j] - h* MSXRosenbrockSolver.K1[j])/ytol;
|
|
252
|
+
err = err + ej*ej;
|
|
253
|
+
}
|
|
254
|
+
err = sqrt(err/n);
|
|
255
|
+
err = fmax(UROUND, err);
|
|
256
|
+
|
|
257
|
+
// --- Choose the step size
|
|
258
|
+
|
|
259
|
+
factor = 0.9 / sqrt(err);
|
|
260
|
+
if (isReject) facmax = 1.0;
|
|
261
|
+
else facmax = 10.0;
|
|
262
|
+
factor = fmin(factor, facmax);
|
|
263
|
+
factor = fmax(factor, 1.0e-1);
|
|
264
|
+
h = factor*h;
|
|
265
|
+
h = fmin(hmax, h);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// --- Reject/accept the step
|
|
269
|
+
|
|
270
|
+
if ( err > 1.0 )
|
|
271
|
+
{
|
|
272
|
+
isReject = 1;
|
|
273
|
+
nreject++;
|
|
274
|
+
h = 0.5*h;
|
|
275
|
+
}
|
|
276
|
+
else
|
|
277
|
+
{
|
|
278
|
+
isReject = 0;
|
|
279
|
+
for (j=1; j<=n; j++)
|
|
280
|
+
{
|
|
281
|
+
y[j] = MSXRosenbrockSolver.Ynew[j];
|
|
282
|
+
if ( y[j] <= UROUND ) y[j] = 0.0;
|
|
283
|
+
}
|
|
284
|
+
if ( adjust ) *htry = h;
|
|
285
|
+
t = tplus;
|
|
286
|
+
naccept++;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// --- End of the time loop
|
|
290
|
+
|
|
291
|
+
}
|
|
292
|
+
return nfcn;
|
|
293
|
+
}
|
epanet-msx-src/ros2.h
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/************************************************************************
|
|
2
|
+
** MODULE: ROS2.H
|
|
3
|
+
** PROJECT: EPANET-MSX
|
|
4
|
+
** DESCRIPTION: Header file for the stiff ODE solver ROS2.C.
|
|
5
|
+
** AUTHOR: L. Rossman, US EPA - NRMRL
|
|
6
|
+
** VERSION: 2.0.00
|
|
7
|
+
** LAST UPDATE: 04/14/2021
|
|
8
|
+
***********************************************************************/
|
|
9
|
+
|
|
10
|
+
#ifndef ROS2_H
|
|
11
|
+
#define ROS2_H
|
|
12
|
+
|
|
13
|
+
typedef struct {
|
|
14
|
+
|
|
15
|
+
double** A; // Jacobian matrix
|
|
16
|
+
double* K1; // Intermediate solutions
|
|
17
|
+
double* K2;
|
|
18
|
+
double* Ynew; // Updated function values
|
|
19
|
+
int* Jindx; // Jacobian column indexes
|
|
20
|
+
int Nmax; // Max. number of equations
|
|
21
|
+
int Adjust; // use adjustable step size
|
|
22
|
+
}MSXRosenbrock;
|
|
23
|
+
|
|
24
|
+
// Opens the ODE solver system
|
|
25
|
+
int ros2_open(int n, int adjust);
|
|
26
|
+
|
|
27
|
+
// Closes the ODE solver system
|
|
28
|
+
void ros2_close(void);
|
|
29
|
+
|
|
30
|
+
// Applies the solver to integrate a specific system of ODEs
|
|
31
|
+
int ros2_integrate(double y[], int n, double t, double tnext,
|
|
32
|
+
double* htry, double atol[], double rtol[],
|
|
33
|
+
void (*func)(double, double*, int, double*));
|
|
34
|
+
|
|
35
|
+
#endif
|