epyt-flow 0.14.1__py3-none-any.whl → 0.14.2__py3-none-any.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 (55) hide show
  1. epyt_flow/EPANET/EPANET/SRC_engines/AUTHORS +8 -40
  2. epyt_flow/EPANET/EPANET/SRC_engines/LICENSE +3 -3
  3. epyt_flow/EPANET/EPANET/SRC_engines/Readme_SRC_Engines.txt +18 -0
  4. epyt_flow/EPANET/EPANET/SRC_engines/enumstxt.h +7 -24
  5. epyt_flow/EPANET/EPANET/SRC_engines/epanet.c +374 -726
  6. epyt_flow/EPANET/EPANET/SRC_engines/epanet2.c +32 -128
  7. epyt_flow/EPANET/EPANET/SRC_engines/epanet2.def +131 -0
  8. epyt_flow/EPANET/EPANET/SRC_engines/errors.dat +1 -7
  9. epyt_flow/EPANET/EPANET/SRC_engines/funcs.h +14 -40
  10. epyt_flow/EPANET/EPANET/SRC_engines/hash.c +177 -177
  11. epyt_flow/EPANET/EPANET/SRC_engines/hash.h +28 -28
  12. epyt_flow/EPANET/EPANET/SRC_engines/hydcoeffs.c +40 -192
  13. epyt_flow/EPANET/EPANET/SRC_engines/hydraul.c +46 -101
  14. epyt_flow/EPANET/EPANET/SRC_engines/hydsolver.c +24 -85
  15. epyt_flow/EPANET/EPANET/SRC_engines/hydstatus.c +63 -29
  16. epyt_flow/EPANET/EPANET/SRC_engines/include/epanet2.h +37 -70
  17. epyt_flow/EPANET/EPANET/SRC_engines/include/epanet2_2.h +234 -408
  18. epyt_flow/EPANET/EPANET/SRC_engines/include/epanet2_enums.h +37 -87
  19. epyt_flow/EPANET/EPANET/SRC_engines/inpfile.c +79 -153
  20. epyt_flow/EPANET/EPANET/SRC_engines/input1.c +94 -59
  21. epyt_flow/EPANET/EPANET/SRC_engines/input2.c +202 -73
  22. epyt_flow/EPANET/EPANET/SRC_engines/input3.c +351 -446
  23. epyt_flow/EPANET/EPANET/SRC_engines/main.c +93 -0
  24. epyt_flow/EPANET/EPANET/SRC_engines/mempool.c +4 -8
  25. epyt_flow/EPANET/EPANET/SRC_engines/mempool.h +23 -23
  26. epyt_flow/EPANET/EPANET/SRC_engines/output.c +4 -5
  27. epyt_flow/EPANET/EPANET/SRC_engines/project.c +75 -407
  28. epyt_flow/EPANET/EPANET/SRC_engines/quality.c +2 -12
  29. epyt_flow/EPANET/EPANET/SRC_engines/qualreact.c +13 -70
  30. epyt_flow/EPANET/EPANET/SRC_engines/qualroute.c +5 -7
  31. epyt_flow/EPANET/EPANET/SRC_engines/report.c +20 -88
  32. epyt_flow/EPANET/EPANET/SRC_engines/rules.c +6 -144
  33. epyt_flow/EPANET/EPANET/SRC_engines/smatrix.c +19 -19
  34. epyt_flow/EPANET/EPANET/SRC_engines/text.h +5 -16
  35. epyt_flow/EPANET/EPANET/SRC_engines/types.h +19 -73
  36. epyt_flow/EPANET/compile_linux.sh +1 -1
  37. epyt_flow/EPANET/compile_macos.sh +1 -1
  38. epyt_flow/VERSION +1 -1
  39. epyt_flow/simulation/scada/scada_data.py +1 -1
  40. epyt_flow/utils.py +66 -0
  41. epyt_flow/visualization/visualization_utils.py +4 -2
  42. {epyt_flow-0.14.1.dist-info → epyt_flow-0.14.2.dist-info}/METADATA +1 -1
  43. {epyt_flow-0.14.1.dist-info → epyt_flow-0.14.2.dist-info}/RECORD +46 -52
  44. epyt_flow/EPANET/EPANET/SRC_engines/flowbalance.c +0 -186
  45. epyt_flow/EPANET/EPANET/SRC_engines/leakage.c +0 -527
  46. epyt_flow/EPANET/EPANET/SRC_engines/util/cstr_helper.c +0 -59
  47. epyt_flow/EPANET/EPANET/SRC_engines/util/cstr_helper.h +0 -38
  48. epyt_flow/EPANET/EPANET/SRC_engines/util/errormanager.c +0 -92
  49. epyt_flow/EPANET/EPANET/SRC_engines/util/errormanager.h +0 -39
  50. epyt_flow/EPANET/EPANET/SRC_engines/util/filemanager.c +0 -212
  51. epyt_flow/EPANET/EPANET/SRC_engines/util/filemanager.h +0 -81
  52. epyt_flow/EPANET/EPANET/SRC_engines/validate.c +0 -408
  53. {epyt_flow-0.14.1.dist-info → epyt_flow-0.14.2.dist-info}/WHEEL +0 -0
  54. {epyt_flow-0.14.1.dist-info → epyt_flow-0.14.2.dist-info}/licenses/LICENSE +0 -0
  55. {epyt_flow-0.14.1.dist-info → epyt_flow-0.14.2.dist-info}/top_level.txt +0 -0
@@ -1,527 +0,0 @@
1
- /*
2
- ******************************************************************************
3
- Project: OWA EPANET
4
- Version: 2.3
5
- Module: leakage.c
6
- Description: models additional nodal demands due to pipe leaks.
7
- Authors: see AUTHORS
8
- Copyright: see AUTHORS
9
- License: see LICENSE
10
- Last Updated: 06/14/2024
11
- ******************************************************************************
12
- */
13
- /*
14
- This module uses the FAVAD (Fixed and Variable Discharge) equation to model
15
- leaky pipes:
16
-
17
- Q = Co * L * (Ao + m * H) * sqrt(H)
18
-
19
- where Q = pipe leak flow rate, Co = an orifice coefficient (= 0.6*sqrt(2g)),
20
- L = pipe length, Ao = initial area of leak per unit of pipe length,
21
- m = change in leak area per unit of pressure head, and H = pressure head.
22
-
23
- The inverted form of this equation is used to model the leakage demand from
24
- a pipe's end node using a pair of equivalent emitters as follows:
25
-
26
- H = Cfa * Qfa^2
27
- H = Cva * Qva^(2/3)
28
-
29
- where Qfa = fixed area node leakage rate, Qva = variable area node leakage rate,
30
- Cfa = 1 / SUM(Co*(L/2)*Ao)^2, Cva = 1 / SUM(Co*(L/2)*m)^2/3, and
31
- SUM(x) is the summation of x over all pipes connected to the node.
32
-
33
- In implementing this model, the pipe property "LeakArea" represents Ao in
34
- sq. mm per 100 units of pipe length and "LeakExpan" represents m in sq. mm
35
- per unit of pressure head.
36
-
37
- */
38
- #include <stdlib.h>
39
- #include <math.h>
40
-
41
- #include "types.h"
42
- #include "funcs.h"
43
-
44
- // Exported functions (declared in funcs.h)
45
- //int openleakage(Project *);
46
- //void closeleakage(Project *);
47
- //double findlinkleakage(Project *, int);
48
- //void leakagecoeffs(Project *);
49
- //double leakageflowchange(Project *, int);
50
- //int leakagehasconverged(Project *);
51
-
52
- // Local functions
53
- static int check_for_leakage(Project *pr);
54
- static int create_leakage_objects(Project *pr);
55
- static void convert_pipe_to_node_leakage(Project *pr);
56
- static void init_node_leakage(Project *pr);
57
- static int leakage_headloss(Project* pr, int i, double *hfa,
58
- double *gfa, double *hva, double *gva);
59
- static void eval_leak_headloss(double q, double c,
60
- double n, double *hloss, double *hgrad);
61
- static void add_lower_barrier(double q, double *hloss, double *hgrad);
62
-
63
-
64
- int openleakage(Project *pr)
65
- /*-------------------------------------------------------------
66
- ** Input: none
67
- ** Output: returns an error code
68
- ** Purpose: opens the pipe leakage modeling system
69
- **-------------------------------------------------------------
70
- */
71
- {
72
- Hydraul *hyd = &pr->hydraul;
73
-
74
- int err;
75
-
76
- // Check if project includes leakage
77
- closeleakage(pr);
78
- hyd->HasLeakage = check_for_leakage(pr);
79
- if (!hyd->HasLeakage) return 0;
80
-
81
- // Allocate memory for leakage data objects
82
- err = create_leakage_objects(pr);
83
- if (err > 0) return err;
84
-
85
- // Convert pipe leakage coeffs. to node coeffs.
86
- convert_pipe_to_node_leakage(pr);
87
- init_node_leakage(pr);
88
- return 0;
89
- }
90
-
91
-
92
- int check_for_leakage(Project *pr)
93
- /*-------------------------------------------------------------
94
- ** Input: none
95
- ** Output: returns TRUE if any pipes can leak, FALSE otherwise
96
- ** Purpose: checks if any pipes can leak.
97
- **-------------------------------------------------------------
98
- */
99
- {
100
- Network *net = &pr->network;
101
- int i;
102
- Slink *link;
103
-
104
- for (i = 1; i <= net->Nlinks; i++)
105
- {
106
- // Only pipes have leakage
107
- link = &net->Link[i];
108
- if (link->Type > PIPE) continue;
109
- if (link->LeakArea > 0.0 || link->LeakExpan > 0.0) return TRUE;
110
- }
111
- return FALSE;
112
- }
113
-
114
-
115
- int create_leakage_objects(Project *pr)
116
- /*-------------------------------------------------------------
117
- ** Input: none
118
- ** Output: returns an error code
119
- ** Purpose: allocates an array of node leakage objects.
120
- **-------------------------------------------------------------
121
- */
122
- {
123
- Network *net = &pr->network;
124
- Hydraul *hyd = &pr->hydraul;
125
- int i;
126
-
127
- hyd->Leakage = (Sleakage *)calloc(net->Njuncs + 1, sizeof(Sleakage));
128
- if (hyd->Leakage == NULL) return 101;
129
- for (i = 1; i <= net->Njuncs; i++)
130
- {
131
- hyd->Leakage[i].cfa = 0.0;
132
- hyd->Leakage[i].cva = 0.0;
133
- hyd->Leakage[i].qfa = 0.0;
134
- hyd->Leakage[i].qva = 0.0;
135
- }
136
- return 0;
137
- }
138
-
139
- void convert_pipe_to_node_leakage(Project *pr)
140
- /*-------------------------------------------------------------
141
- ** Input: none
142
- ** Output: none
143
- ** Purpose: converts pipe leakage parameters into node leakage
144
- ** coefficients.
145
- **-------------------------------------------------------------
146
- */
147
- {
148
- Network *net = &pr->network;
149
- Hydraul *hyd = &pr->hydraul;
150
-
151
- int i;
152
- double c_area, c_expan, c_orif, len;
153
- Slink *link;
154
- Snode *node1;
155
- Snode *node2;
156
-
157
- // Orifice coeff. with conversion from sq. mm to sq. m
158
- c_orif = 4.8149866 * 1.e-6;
159
-
160
- // Examine each link
161
- for (i = 1; i <= net->Nlinks; i++)
162
- {
163
- // Only pipes have leakage
164
- link = &net->Link[i];
165
- if (link->Type > PIPE) continue;
166
-
167
- // Ignore leakage in a pipe connecting two tanks or
168
- // reservoirs (since those nodes don't have demands)
169
- node1 = &net->Node[link->N1];
170
- node2 = &net->Node[link->N2];
171
- if (node1->Type != JUNCTION && node2->Type != JUNCTION) continue;
172
-
173
- // Get pipe's fixed and variable area leak coeffs.
174
- if (link->LeakArea == 0.0 && link->LeakExpan == 0.0) continue;
175
- c_area = c_orif * link->LeakArea / SQR(MperFT);
176
- c_expan = c_orif * link->LeakExpan;
177
-
178
- // Adjust for number of 100-ft pipe sections
179
- len = link->Len * pr->Ucf[LENGTH] / 100.;
180
- if (node1->Type == JUNCTION && node2->Type == JUNCTION)
181
- {
182
- len *= 0.5;
183
- }
184
- c_area *= len;
185
- c_expan *= len;
186
-
187
- // Add these coeffs. to pipe's end nodes
188
- if (node1->Type == JUNCTION)
189
- {
190
- hyd->Leakage[link->N1].cfa += c_area;
191
- hyd->Leakage[link->N1].cva += c_expan;
192
- }
193
- if (node2->Type == JUNCTION)
194
- {
195
- hyd->Leakage[link->N2].cfa += c_area;
196
- hyd->Leakage[link->N2].cva += c_expan;
197
- }
198
- }
199
- }
200
-
201
- void init_node_leakage(Project *pr)
202
- /*-------------------------------------------------------------
203
- ** Input: none
204
- ** Output: none
205
- ** Purpose: initializes node leakage coeffs. and flows.
206
- **-------------------------------------------------------------
207
- */
208
- {
209
- Network *net = &pr->network;
210
- Hydraul *hyd = &pr->hydraul;
211
-
212
- int i;
213
- double c_area, c_expan;
214
-
215
- for (i = 1; i <= net->Njuncs; i++)
216
- {
217
- // Coeff. for fixed area leakage
218
- c_area = hyd->Leakage[i].cfa;
219
- if (c_area > 0.0)
220
- hyd->Leakage[i].cfa = 1.0 / (c_area * c_area);
221
- else
222
- hyd->Leakage[i].cfa = 0.0;
223
-
224
- // Coeff. for variable area leakage
225
- c_expan = hyd->Leakage[i].cva;
226
- if (c_expan > 0.0)
227
- hyd->Leakage[i].cva = 1.0 / pow(c_expan, 2./3.);
228
- else
229
- hyd->Leakage[i].cva = 0.0;
230
-
231
- // Initialize leakage flow to a non-zero value (as required by
232
- // the hydraulic solver)
233
- if (hyd->Leakage[i].cfa > 0.0)
234
- hyd->Leakage[i].qfa = 0.001;
235
- if (hyd->Leakage[i].cva > 0.0)
236
- hyd->Leakage[i].qva = 0.001;
237
- }
238
- }
239
-
240
- void closeleakage(Project *pr)
241
- /*-------------------------------------------------------------
242
- ** Input: none
243
- ** Output: none
244
- ** Purpose: frees memory for nodal leakage objects.
245
- **-------------------------------------------------------------
246
- */
247
- {
248
- Hydraul *hyd = &pr->hydraul;
249
- if (hyd->Leakage) free(hyd->Leakage);
250
- hyd->Leakage = NULL;
251
- hyd->HasLeakage = FALSE;
252
- }
253
-
254
- double findlinkleakage(Project *pr, int i)
255
- /*-------------------------------------------------------------
256
- ** Input: i = link index
257
- ** Output: returns link leakage flow (cfs)
258
- ** Purpose: computes leakage flow from link i at current
259
- ** hydraulic solution.
260
- **-------------------------------------------------------------
261
- */
262
- {
263
- Network *net = &pr->network;
264
- Hydraul *hyd = &pr->hydraul;
265
- Smatrix *sm = &hyd->smatrix;
266
- Slink *link = &net->Link[i];
267
-
268
- int n1, n2;
269
- double h1, h2, hsqrt, a, m, c, len, q1, q2;
270
-
271
- // Only pipes can leak
272
- link = &net->Link[i];
273
- if (link->Type > PIPE) return 0.0;
274
-
275
- // No leakage if area & expansion are 0
276
- if (link->LeakArea == 0.0 && link->LeakExpan == 0.0) return 0.0;
277
-
278
- // No leakage if link's end nodes are both fixed grade
279
- n1 = link->N1;
280
- n2 = link->N2;
281
- if (n1 > net->Njuncs && n2 > net->Njuncs) return 0.0;
282
-
283
- // Pressure head of end nodes
284
- h1 = hyd->NodeHead[n1] - net->Node[n1].El;
285
- h1 = MAX(h1, 0.0);
286
- h2 = hyd->NodeHead[n2] - net->Node[n2].El;
287
- h2 = MAX(h2, 0.0);
288
-
289
- // Pipe leak parameters converted to feet
290
- a = link->LeakArea / SQR(MperFT);
291
- m = link->LeakExpan;
292
- len = link->Len * pr->Ucf[LENGTH] / 100.; // # 100 ft pipe lengths
293
- c = 4.8149866 * len / 2.0 * 1.e-6;
294
-
295
- // Leakage from 1st half of pipe connected to node n1
296
- q1 = 0.0;
297
- if (n1 <= net->Njuncs)
298
- {
299
- hsqrt = sqrt(h1);
300
- q1 = c * (a + m * h1) * hsqrt;
301
- }
302
-
303
- // Leakage from 2nd half of pipe connected to node n2
304
- q2 = 0.0;
305
- if (n2 <= net->Njuncs)
306
- {
307
- hsqrt = sqrt(h2);
308
- q2 = c * (a + m * h2) * hsqrt;
309
- }
310
-
311
- // Adjust leakage flows to account for one node being fixed grade
312
- if (n2 > net->Njuncs) q1 *= 2.0;
313
- if (n1 > net->Njuncs) q2 *= 2.0;
314
- return q1 + q2;
315
- }
316
-
317
- void leakagecoeffs(Project *pr)
318
- /*
319
- **--------------------------------------------------------------
320
- ** Input: none
321
- ** Output: none
322
- ** Purpose: computes coeffs. of the linearized hydraulic eqns.
323
- ** contributed by node leakages.
324
- **--------------------------------------------------------------
325
- */
326
- {
327
- Network *net = &pr->network;
328
- Hydraul *hyd = &pr->hydraul;
329
- Smatrix *sm = &hyd->smatrix;
330
-
331
- int i, row;
332
- double hfa, // head loss producing current fixed area leakage
333
- gfa, // gradient of fixed area head loss
334
- hva, // head loss producing current variable area leakage
335
- gva; // gradient of variable area head loss
336
-
337
- Snode* node;
338
-
339
- for (i = 1; i <= net->Njuncs; i++)
340
- {
341
- // Skip junctions that don't leak
342
- node = &net->Node[i];
343
- if (!leakage_headloss(pr, i, &hfa, &gfa, &hva, &gva)) continue;
344
-
345
- // Addition to matrix diagonal & r.h.s
346
- row = sm->Row[i];
347
- if (gfa > 0.0)
348
- {
349
- sm->Aii[row] += 1.0 / gfa;
350
- sm->F[row] += (hfa + node->El) / gfa;
351
- }
352
- if (gva > 0.0)
353
- {
354
- sm->Aii[row] += 1.0 / gva;
355
- sm->F[row] += (hva + node->El) / gva;
356
- }
357
-
358
- // Update node's flow excess (inflow - outflow)
359
- hyd->Xflow[i] -= (hyd->Leakage[i].qfa + hyd->Leakage[i].qva);
360
- }
361
- }
362
-
363
- double leakageflowchange(Project *pr, int i)
364
- /*
365
- **--------------------------------------------------------------
366
- ** Input: i = node index
367
- ** Output: returns change in leakage flow rate
368
- ** Purpose: finds new leakage flow rate at a node after new
369
- ** heads are computed by the hydraulic solver.
370
- **--------------------------------------------------------------
371
- */
372
- {
373
- Network *net = &pr->network;
374
- Hydraul *hyd = &pr->hydraul;
375
-
376
- double hfa, gfa, hva, gva; // same as defined in leakage_solvercoeffs()
377
- double h, dqfa, dqva; // pressure head, change in leakage flows
378
-
379
- // Find the head loss and gradient of the inverted leakage
380
- // equation for both fixed and variable area leakage at the
381
- // current leakage flow rates
382
- if (!leakage_headloss(pr, i, &hfa, &gfa, &hva, &gva)) return 0.0;
383
-
384
- // Pressure head using latest head solution
385
- h = hyd->NodeHead[i] - net->Node[i].El;
386
-
387
- // GGA flow update formula for fixed area leakage
388
- dqfa = 0.0;
389
- if (gfa > 0.0)
390
- {
391
- dqfa = (hfa - h) / gfa * hyd->RelaxFactor;
392
- hyd->Leakage[i].qfa -= dqfa;
393
- }
394
-
395
- // GGA flow update formula for variable area leakage
396
- dqva = 0.0;
397
- if (gva > 0.0)
398
- {
399
- dqva = (hva - h) / gva * hyd->RelaxFactor;
400
- hyd->Leakage[i].qva -= dqva;
401
- }
402
-
403
- // New leakage flow at the node
404
- hyd->LeakageFlow[i] = hyd->Leakage[i].qfa + hyd->Leakage[i].qva;
405
- return dqfa + dqva;
406
- }
407
-
408
- int leakagehasconverged(Project *pr)
409
- /*
410
- **--------------------------------------------------------------
411
- ** Input: none
412
- ** Output: returns TRUE if leakage calculations converged,
413
- ** FALSE if not
414
- ** Purpose: checks if leakage calculations have converged.
415
- **--------------------------------------------------------------
416
- */
417
- {
418
- Network *net = &pr->network;
419
- Hydraul *hyd = &pr->hydraul;
420
-
421
- int i;
422
- double h, qref, qtest;
423
- const double QTOL = 0.0001; // 0.0001 cfs ~= 0.005 gpm ~= 0.2 lpm)
424
-
425
- for (i = 1; i <= net->Njuncs; i++)
426
- {
427
- // Skip junctions that don't leak
428
- if (hyd->Leakage[i].cfa == 0 && hyd->Leakage[i].cva == 0) continue;
429
-
430
- // Evaluate node's pressure head
431
- h = hyd->NodeHead[i] - net->Node[i].El;
432
-
433
- // Directly compute a reference leakage at this pressure head
434
- qref = 0.0;
435
- // Contribution from pipes with fixed area leaks
436
- if (hyd->Leakage[i].cfa > 0.0)
437
- qref = sqrt(h / hyd->Leakage[i].cfa);
438
- // Contribution from pipes with variable area leaks
439
- if (hyd->Leakage[i].cva > 0.0)
440
- qref += pow((h / hyd->Leakage[i].cva), 1.5);
441
-
442
- // Compare reference leakage to solution leakage
443
- qtest = hyd->Leakage[i].qfa + hyd->Leakage[i].qva;
444
- if (fabs(qref - qtest) > QTOL) return FALSE;
445
- }
446
- return TRUE;
447
- }
448
-
449
- int leakage_headloss(Project* pr, int i, double *hfa, double *gfa,
450
- double *hva, double *gva)
451
- /*
452
- **--------------------------------------------------------------
453
- ** Input: i = node index
454
- ** Output: hfa = fixed area leak head loss (ft)
455
- ** gfa = gradient of fixed area head loss (ft/cfs)
456
- ** hva = variable area leak head loss (ft)
457
- ** gva = gradient of variable area head loss (ft/cfs)
458
- ** returns TRUE if node has leakage, FALSE otherwise
459
- ** Purpose: finds head loss and its gradient for a node's
460
- ** leakage as a function of leakage flow.
461
- **--------------------------------------------------------------
462
- */
463
- {
464
- Hydraul *hyd = &pr->hydraul;
465
-
466
- if (hyd->Leakage[i].cfa == 0.0 && hyd->Leakage[i].cva == 0.0) return FALSE;
467
- if (hyd->Leakage[i].cfa == 0.0)
468
- {
469
- *hfa = 0.0;
470
- *gfa = 0.0;
471
- }
472
- else
473
- eval_leak_headloss(hyd->Leakage[i].qfa, hyd->Leakage[i].cfa,
474
- 0.5, hfa, gfa);
475
- if (hyd->Leakage[i].cva == 0.0)
476
- {
477
- *hva = 0.0;
478
- *gva = 0.0;
479
- }
480
- else
481
- eval_leak_headloss(hyd->Leakage[i].qva, hyd->Leakage[i].cva,
482
- 1.5, hva, gva);
483
- return TRUE;
484
- }
485
-
486
- void eval_leak_headloss(double q, double c, double n,
487
- double *hloss, double *hgrad)
488
- /*
489
- **--------------------------------------------------------------
490
- ** Input: q = leakage flow rate (cfs)
491
- ** c = leakage head loss coefficient
492
- ** n = leakage head loss exponent
493
- ** Output: hloss = leakage head loss (ft)
494
- ** hgrad = gradient of leakage head loss (ft/cfs)
495
- ** Purpose: evaluates inverted form of leakage equation to
496
- ** compute head loss and its gradient as a function
497
- ** flow.
498
- **
499
- ** Note: Inverted leakage equation is:
500
- ** hloss = c * q ^ (1/n)
501
- **--------------------------------------------------------------
502
- */
503
- {
504
- n = 1.0 / n;
505
- *hgrad = n * c * pow(fabs(q), n - 1.0);
506
- *hloss = (*hgrad) * q / n;
507
-
508
- // Prevent leakage from going negative
509
- add_lower_barrier(q, hloss, hgrad);
510
- }
511
-
512
- void add_lower_barrier(double q, double* hloss, double* hgrad)
513
- /*
514
- **--------------------------------------------------------------------
515
- ** Input: q = current flow rate
516
- ** Output: hloss = head loss value
517
- ** hgrad = head loss gradient value
518
- ** Purpose: adds a head loss barrier to prevent flow from falling
519
- ** below 0.
520
- **--------------------------------------------------------------------
521
- */
522
- {
523
- double a = 1.e9 * q;
524
- double b = sqrt(a*a + 1.e-6);
525
- *hloss += (a - b) / 2.;
526
- *hgrad += (1.e9 / 2.) * ( 1.0 - a / b);
527
- }
@@ -1,59 +0,0 @@
1
- /*
2
- ******************************************************************************
3
- Project: OWA EPANET
4
- Version: 2.3
5
- Module: util/cstr_helper.c
6
- Description: Provides C string helper functions
7
- Authors: see AUTHORS
8
- Copyright: see AUTHORS
9
- License: see LICENSE
10
- Last Updated: 04/02/2019
11
- ******************************************************************************
12
- */
13
-
14
- #include <stdlib.h>
15
- #include <string.h>
16
-
17
- #include "cstr_helper.h"
18
-
19
-
20
- int cstr_duplicate(char **dest, const char *source)
21
- // Duplicates source string
22
- {
23
- size_t size = 1 + strlen(source);
24
- *dest = (char *) calloc(size, sizeof(char));
25
-
26
- if (*dest == NULL)
27
- return -1;
28
- else {
29
- #ifdef _MSC_VER
30
- strncpy_s(*dest, size, source, size);
31
- #else
32
- strncpy(*dest, source, size);
33
- #endif
34
- }
35
- return 0;
36
- }
37
-
38
-
39
- bool cstr_isvalid(const char *element_id)
40
- // Determines if invalid characters are present in an element id string
41
- {
42
- const char *invalid_chars = " \";";
43
-
44
- // if invalid char is present a pointer to it is returned else NULL
45
- if (strpbrk(element_id, invalid_chars))
46
- return false;
47
- else
48
- return true;
49
- }
50
-
51
-
52
- bool cstr_isnullterm(const char *source)
53
- // Determines if the string passed is null terminated or not
54
- {
55
- if (strchr(source, '\0'))
56
- return true;
57
- else
58
- return false;
59
- }
@@ -1,38 +0,0 @@
1
- /*
2
- ******************************************************************************
3
- Project: OWA EPANET
4
- Version: 2.3
5
- Module: util/cstr_helper.h
6
- Description: Provides C string helper functions
7
- Authors: see AUTHORS
8
- Copyright: see AUTHORS
9
- License: see LICENSE
10
- Last Updated: 04/02/2019
11
- ******************************************************************************
12
- */
13
-
14
- #ifndef CSTR_HELPER_H_
15
- #define CSTR_HELPER_H_
16
-
17
-
18
- #include <stdbool.h>
19
-
20
-
21
- #if defined(__cplusplus)
22
- extern "C" {
23
- #endif
24
-
25
-
26
- int cstr_duplicate(char **dest, const char *source);
27
-
28
- bool cstr_isvalid(const char *element_id);
29
-
30
- bool cstr_isnullterm(const char *source);
31
-
32
-
33
- #if defined(__cplusplus)
34
- }
35
- #endif
36
-
37
-
38
- #endif /* CSTR_HELPER_H_ */
@@ -1,92 +0,0 @@
1
- /*
2
- ******************************************************************************
3
- Project: OWA EPANET
4
- Version: 2.3
5
- Module: util/errormanager.c
6
- Description: Provides a simple interface for managing errors
7
- Authors: see AUTHORS
8
- Copyright: see AUTHORS
9
- License: see LICENSE
10
- Last Updated: 08/02/2023
11
- ******************************************************************************
12
- */
13
-
14
- //#ifdef _WIN32
15
- //#define _CRTDBG_MAP_ALLOC
16
- //#include <stdlib.h>
17
- //#include <crtdbg.h>
18
- //#else
19
- #include <stdlib.h>
20
- //#endif
21
- #include <string.h>
22
-
23
- #include "errormanager.h"
24
-
25
-
26
- typedef struct error_s {
27
- int error_status;
28
- void (*p_msg_lookup)(int, char*, int);
29
- } error_handle_t;
30
-
31
-
32
- error_handle_t *create_error_manager(void (*p_error_message)(int, char*, int))
33
- //
34
- // Purpose: Constructs a new error handle.
35
- //
36
- {
37
- error_handle_t *error_handle;
38
- error_handle = (error_handle_t*)calloc(1, sizeof(error_handle_t));
39
- if (error_handle == NULL) return NULL;
40
-
41
- error_handle->p_msg_lookup = p_error_message;
42
-
43
- return error_handle;
44
- }
45
-
46
- void delete_error_manager(error_handle_t *error_handle)
47
- //
48
- // Purpose: Destroys the error handle.
49
- //
50
- {
51
- free(error_handle);
52
- }
53
-
54
- int set_error(error_handle_t *error_handle, int error_code)
55
- //
56
- // Purpose: Sets an error code in the handle.
57
- //
58
- {
59
- // If the error code is 0 no action is taken and 0 is returned.
60
- // This is a feature not a bug.
61
- if (error_code)
62
- error_handle->error_status = error_code;
63
-
64
- return error_code;
65
- }
66
-
67
- int check_error(error_handle_t *error_handle, char **error_message)
68
- //
69
- // Purpose: Returns the error message or NULL.
70
- //
71
- // Note: Caller must free memory allocated by check_error
72
- //
73
- { int error_code = error_handle->error_status;
74
- char *temp = NULL;
75
-
76
- if (error_code != 0) {
77
- temp = (char*) calloc(ERR_MAXMSG + 1, sizeof(char));
78
-
79
- if (temp)
80
- error_handle->p_msg_lookup(error_code, temp, ERR_MAXMSG);
81
- }
82
- *error_message = temp;
83
- return error_code;
84
- }
85
-
86
- void clear_error(error_handle_t *error_handle)
87
- //
88
- // Purpose: Clears the error from the handle.
89
- //
90
- {
91
- error_handle->error_status = 0;
92
- }