Skip to content

Commit ba52b59

Browse files
committed
Update EPANET to current dev version
1 parent de872bb commit ba52b59

File tree

8 files changed

+220
-12
lines changed

8 files changed

+220
-12
lines changed

epanet-src/epanet.c

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Authors: see AUTHORS
88
Copyright: see AUTHORS
99
License: see LICENSE
10-
Last Updated: 02/17/2026
10+
Last Updated: 03/19/2026
1111
******************************************************************************
1212
*/
1313

@@ -2758,6 +2758,55 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int property, double valu
27582758
return 0;
27592759
}
27602760

2761+
int DLLEXPORT EN_setnodevalues(EN_Project p, int property, double *values, int *badIndex)
2762+
/*----------------------------------------------------------------
2763+
** Input: property = node property code (see EN_NodeProperty)
2764+
** values = array of node property values
2765+
** Output: badIndex = index of node whose assignment fails (0 if none)
2766+
** Returns: error code
2767+
** Purpose: sets an array of node property values
2768+
**----------------------------------------------------------------
2769+
*/
2770+
{
2771+
int i, j, errcode = 0;
2772+
int n = p->network.Nnodes;
2773+
double *old = NULL;
2774+
2775+
if (badIndex) *badIndex = 0;
2776+
2777+
old = (double *)malloc(n * sizeof(double));
2778+
if (!old) return 101; /* insufficient memory available */
2779+
2780+
for (i = 1; i <= n; i++)
2781+
{
2782+
errcode = EN_getnodevalue(p, i, property, &old[i - 1]);
2783+
if (errcode != 0)
2784+
{
2785+
*badIndex = i;
2786+
j = i - 1; // Need to restore values for nodes 1 to i-1
2787+
}
2788+
else
2789+
{
2790+
errcode = EN_setnodevalue(p, i, property, values[i - 1]);
2791+
if (errcode != 0)
2792+
{
2793+
*badIndex = i;
2794+
j = i; // Need to restore values for nodes 1 to i
2795+
}
2796+
}
2797+
if (errcode != 0)
2798+
{
2799+
for (int k = 1; k <= j; k++)
2800+
{
2801+
EN_setnodevalue(p, k, property, old[k - 1]);
2802+
}
2803+
break;
2804+
}
2805+
}
2806+
free(old);
2807+
return errcode;
2808+
}
2809+
27612810
int DLLEXPORT EN_setjuncdata(EN_Project p, int index, double elev,
27622811
double dmnd, const char *dmndpat)
27632812
/*----------------------------------------------------------------
@@ -4304,6 +4353,55 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
43044353
return 0;
43054354
}
43064355

4356+
int DLLEXPORT EN_setlinkvalues(EN_Project p, int property, double *values, int *badIndex)
4357+
/*----------------------------------------------------------------
4358+
** Input: property = link property code (see EN_LinkProperty)
4359+
** values = array of link property values
4360+
** Output: badIndex = index of link whose assignment fails (0 if none)
4361+
** Returns: error code
4362+
** Purpose: sets property values for all links
4363+
**----------------------------------------------------------------
4364+
*/
4365+
{
4366+
int i, j, errcode = 0;
4367+
int n = p->network.Nlinks;
4368+
double *old = NULL;
4369+
4370+
if (badIndex) *badIndex = 0;
4371+
4372+
old = (double *)malloc(n * sizeof(double));
4373+
if (!old) return 101; /* insufficient memory available */
4374+
4375+
for (i = 1; i <= n; i++)
4376+
{
4377+
errcode = EN_getlinkvalue(p, i, property, &old[i - 1]);
4378+
if (errcode != 0)
4379+
{
4380+
*badIndex = i;
4381+
j = i - 1; // Need to restore values for links 1 to i-1
4382+
}
4383+
else
4384+
{
4385+
errcode = EN_setlinkvalue(p, i, property, values[i - 1]);
4386+
if (errcode != 0)
4387+
{
4388+
*badIndex = i;
4389+
j = i; // Need to restore values for links 1 to i
4390+
}
4391+
}
4392+
if (errcode != 0)
4393+
{
4394+
for (int k = 1; k <= j; k++)
4395+
{
4396+
EN_setlinkvalue(p, k, property, old[k - 1]);
4397+
}
4398+
break;
4399+
}
4400+
}
4401+
free(old);
4402+
return errcode;
4403+
}
4404+
43074405
int DLLEXPORT EN_setpipedata(EN_Project p, int index, double length,
43084406
double diam, double rough, double mloss)
43094407
/*----------------------------------------------------------------

epanet-src/epanet2.c

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Authors: see AUTHORS
88
Copyright: see AUTHORS
99
License: see LICENSE
10-
Last Updated: 02/14/2025
10+
Last Updated: 03/19/2026
1111
******************************************************************************
1212
*/
1313

@@ -383,6 +383,47 @@ int DLLEXPORT ENsetnodevalue(int index, int property, EN_API_FLOAT_TYPE value)
383383
return EN_setnodevalue(_defaultProject, index, property, value);
384384
}
385385

386+
int DLLEXPORT ENsetnodevalues(int property, EN_API_FLOAT_TYPE *values, int *badIndex)
387+
{
388+
int i, j, errcode = 0;
389+
int n = _defaultProject->network.Nnodes;
390+
EN_API_FLOAT_TYPE *old = NULL;
391+
392+
if (badIndex) *badIndex = 0;
393+
394+
old = (EN_API_FLOAT_TYPE *)malloc(n * sizeof(EN_API_FLOAT_TYPE));
395+
if (!old) return 101; /* insufficient memory available */
396+
397+
for (i = 1; i <= n; i++)
398+
{
399+
errcode = ENgetnodevalue(i, property, &old[i - 1]);
400+
if (errcode != 0)
401+
{
402+
*badIndex = i;
403+
j = i - 1; // Need to restore values for nodes 1 to i-1
404+
}
405+
else
406+
{
407+
errcode = ENsetnodevalue(i, property, values[i - 1]);
408+
if (errcode != 0)
409+
{
410+
*badIndex = i;
411+
j = i; // Need to restore values for nodes 1 to i
412+
}
413+
}
414+
if (errcode != 0)
415+
{
416+
for (int k = 1; k <= j; k++)
417+
{
418+
ENsetnodevalue(k, property, old[k - 1]);
419+
}
420+
break;
421+
}
422+
}
423+
free(old);
424+
return errcode;
425+
}
426+
386427
int DLLEXPORT ENsetjuncdata(int index, EN_API_FLOAT_TYPE elev, EN_API_FLOAT_TYPE dmnd,
387428
const char *dmndpat)
388429
{
@@ -565,6 +606,47 @@ int DLLEXPORT ENsetlinkvalue(int index, int property, EN_API_FLOAT_TYPE value)
565606
return EN_setlinkvalue(_defaultProject, index, property, value);
566607
}
567608

609+
int DLLEXPORT ENsetlinkvalues(int property, EN_API_FLOAT_TYPE *values, int *badIndex)
610+
{
611+
int i, j, errcode = 0;
612+
int n = _defaultProject->network.Nlinks;
613+
EN_API_FLOAT_TYPE *old = NULL;
614+
615+
if (badIndex) *badIndex = 0;
616+
617+
old = (EN_API_FLOAT_TYPE *)malloc(n * sizeof(EN_API_FLOAT_TYPE));
618+
if (!old) return 101; /* insufficient memory available */
619+
620+
for (i = 1; i <= n; i++)
621+
{
622+
errcode = ENgetlinkvalue(i, property, &old[i - 1]);
623+
if (errcode != 0)
624+
{
625+
*badIndex = i;
626+
j = i - 1; // Need to restore values for links 1 to i-1
627+
}
628+
else
629+
{
630+
errcode = ENsetlinkvalue(i, property, values[i - 1]);
631+
if (errcode != 0)
632+
{
633+
*badIndex = i;
634+
j = i; // Need to restore values for links 1 to i
635+
}
636+
}
637+
if (errcode != 0)
638+
{
639+
for (int k = 1; k <= j; k++)
640+
{
641+
ENsetlinkvalue(k, property, old[k - 1]);
642+
}
643+
break;
644+
}
645+
}
646+
free(old);
647+
return errcode;
648+
}
649+
568650
int DLLEXPORT ENsetpipedata(int index, EN_API_FLOAT_TYPE length,
569651
EN_API_FLOAT_TYPE diam, EN_API_FLOAT_TYPE rough, EN_API_FLOAT_TYPE mloss)
570652
{

epanet-src/flowbalance.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// Exported functions (declared in funcs.h)
1717
//void startflowbalance(Project *);
1818
//void updateflowbalance(Project *, long);
19-
//void endflowbalance(Project *);
19+
//void endflowbalance(Project *, long);
2020

2121
void startflowbalance(Project *pr)
2222
/*
@@ -143,7 +143,7 @@ void updateflowbalance(Project *pr, long hstep)
143143
hyd->FlowBalance.storageDemand += flowBalance.storageDemand * dt;
144144
}
145145

146-
void endflowbalance(Project *pr)
146+
void endflowbalance(Project *pr, long tFinal)
147147
/*
148148
**-------------------------------------------------------------------
149149
** Input: none
@@ -153,12 +153,11 @@ void endflowbalance(Project *pr)
153153
*/
154154
{
155155
Hydraul *hyd = &pr->hydraul;
156-
Times *time = &pr->times;
157156

158157
double seconds, qin, qout, qstor, r;
159158

160-
if (time->Htime > 0)
161-
seconds = time->Htime;
159+
if (tFinal > 0)
160+
seconds = tFinal;
162161
else
163162
seconds = 1.0;
164163
hyd->FlowBalance.totalInflow /= seconds;

epanet-src/funcs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,6 @@ int leakagehasconverged(Project *);
215215

216216
void startflowbalance(Project *);
217217
void updateflowbalance(Project *, long);
218-
void endflowbalance(Project *);
218+
void endflowbalance(Project *, long);
219219

220220
#endif

epanet-src/hydraul.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ int nexthyd(Project *pr, long *tstep)
243243
Hydraul *hyd = &pr->hydraul;
244244
Times *time = &pr->times;
245245

246+
long tNow = time->Htime;
246247
long hydstep; // Actual time step
247248
int errcode = 0; // Error code
248249

@@ -280,7 +281,7 @@ int nexthyd(Project *pr, long *tstep)
280281
// No more time remains - force completion of analysis
281282
else
282283
{
283-
endflowbalance(pr);
284+
endflowbalance(pr, tNow);
284285
if (pr->report.Statflag) writeflowbalance(pr);
285286
time->Htime++;
286287
if (pr->quality.OpenQflag) time->Qtime++;

epanet-src/include/epanet2.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Authors: see AUTHORS
88
Copyright: see AUTHORS
99
License: see LICENSE
10-
Last Updated: 02/14/2025
10+
Last Updated: 03/05/2026
1111
******************************************************************************
1212
*/
1313

@@ -225,6 +225,8 @@ extern "C" {
225225

226226
int DLLEXPORT ENsetnodevalue(int index, int property, EN_API_FLOAT_TYPE value);
227227

228+
int DLLEXPORT ENsetnodevalues(int property, EN_API_FLOAT_TYPE *values, int *badIndex);
229+
228230
int DLLEXPORT ENsetjuncdata(int index, EN_API_FLOAT_TYPE elev,
229231
EN_API_FLOAT_TYPE dmnd, const char *dmndpat);
230232

@@ -304,6 +306,8 @@ extern "C" {
304306

305307
int DLLEXPORT ENsetlinkvalue(int index, int property, EN_API_FLOAT_TYPE value);
306308

309+
int DLLEXPORT ENsetlinkvalues(int property, EN_API_FLOAT_TYPE *values, int *badIndex);
310+
307311
int DLLEXPORT ENsetpipedata(int index, EN_API_FLOAT_TYPE length,
308312
EN_API_FLOAT_TYPE diam, EN_API_FLOAT_TYPE rough,
309313
EN_API_FLOAT_TYPE mloss);

epanet-src/include/epanet2_2.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Authors: see AUTHORS
1212
Copyright: see AUTHORS
1313
License: see LICENSE
14-
Last Updated: 04/25/2025
14+
Last Updated: 03/05/2026
1515
******************************************************************************
1616
*/
1717

@@ -954,7 +954,19 @@ typedef struct Project *EN_Project;
954954
Values are in units that depend on the units used for flow rate (see @ref Units).
955955
*/
956956
int DLLEXPORT EN_setnodevalue(EN_Project ph, int index, int property, double value);
957+
958+
/**
959+
@brief Sets property values for all nodes.
960+
@param ph an EPANET project handle.
961+
@param property the property to set (see @ref EN_NodeProperty).
962+
@param values an array of property values for all nodes.
963+
@param badIndex returns the index of the node whose assignment fails, or 0 if all succeed.
964+
@return an error code.
957965
966+
Values are in units that depend on the units used for flow rate (see @ref Units).
967+
*/
968+
int DLLEXPORT EN_setnodevalues(EN_Project ph, int property, double *values, int *badIndex);
969+
958970
/**
959971
@brief Sets a group of properties for a junction node.
960972
@param ph an EPANET project handle.
@@ -1324,6 +1336,18 @@ typedef struct Project *EN_Project;
13241336
Values are in units that depend on the units used for flow rate (see @ref Units).
13251337
*/
13261338
int DLLEXPORT EN_setlinkvalue(EN_Project ph, int index, int property, double value);
1339+
1340+
/**
1341+
@brief Sets property values for all links.
1342+
@param ph an EPANET project handle.
1343+
@param property the property to set (see @ref EN_LinkProperty).
1344+
@param values an array of property values for all links.
1345+
@param badIndex returns the index of the link whose assignment fails, or 0 if all succeed.
1346+
@return an error code.
1347+
1348+
Values are in units that depend on the units used for flow rate (see @ref Units).
1349+
*/
1350+
int DLLEXPORT EN_setlinkvalues(EN_Project ph, int property, double *values, int *badIndex);
13271351

13281352
/**
13291353
@brief Sets a group of properties for a pipe link.

epanet-src/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ typedef int INT4;
3131
Various constants
3232
----------------------------------------------
3333
*/
34-
#define CODEVERSION 20304
34+
#define CODEVERSION 20305
3535
#define MAGICNUMBER 516114521
3636
#define ENGINE_VERSION 201 // Used for binary hydraulics file
3737
#define EOFMARK 0x1A // Use 0x04 for UNIX systems

0 commit comments

Comments
 (0)