Skip to content

Commit 444725f

Browse files
committed
Merge branch 'dev'
2 parents 9b90723 + 473b87d commit 444725f

File tree

6 files changed

+69
-121
lines changed

6 files changed

+69
-121
lines changed

ReleaseNotes2_3.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,5 @@ This document describes the changes and updates that have been made in version 2
148148
#### 2.3.4:
149149
- Fixes errors converting the units of the Leak Area and Leak Area Expansion parameters used in the FAVAD pipe leakage model.
150150
- To avoid reporting that full tanks are overflowing when they see negligible net inflows or outflows, those flows are now ignored when updating the tank's volume and head.
151+
#### 2.3.5:
152+
- Makes `EN_setflowunits` change flow units for all assigned data curves but no longer changes pressure units when the unit system changes since v2.3 supports mixed-unit conventions (e.g., using LPS for flow and PSI for pressure).

src/epanet.c

Lines changed: 5 additions & 12 deletions
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: 01/28/2026
10+
Last Updated: 02/17/2026
1111
******************************************************************************
1212
*/
1313

@@ -1470,7 +1470,7 @@ int DLLEXPORT EN_setflowunits(EN_Project p, int units)
14701470
{
14711471
Network *net = &p->network;
14721472

1473-
int i, j, oldUnitFlag;
1473+
int i, j;
14741474
double qfactor, vfactor, hfactor, efactor, pfactor, dfactor, xfactor, yfactor;
14751475
double dcf, pcf, hcf, qcf;
14761476
double *Ucf = p->Ucf;
@@ -1485,7 +1485,6 @@ int DLLEXPORT EN_setflowunits(EN_Project p, int units)
14851485
pfactor = Ucf[PRESSURE];
14861486
dfactor = Ucf[DEMAND];
14871487

1488-
oldUnitFlag = p->parser.Unitsflag;
14891488
p->parser.Flowflag = units;
14901489
switch (units)
14911490
{
@@ -1501,23 +1500,17 @@ int DLLEXPORT EN_setflowunits(EN_Project p, int units)
15011500
p->parser.Unitsflag = US;
15021501
break;
15031502
}
1504-
1505-
// Revise pressure units depending on flow units
1506-
if (oldUnitFlag != p->parser.Unitsflag)
1507-
{
1508-
if (p->parser.Unitsflag == US) p->parser.Pressflag = PSI;
1509-
else p->parser.Pressflag = METERS;
1510-
}
15111503
initunits(p);
15121504

1513-
// Update pressure units in rules
1505+
// Update units in rules
15141506
dcf = Ucf[DEMAND] / dfactor;
15151507
pcf = Ucf[PRESSURE] / pfactor;
15161508
hcf = Ucf[HEAD] / hfactor;
15171509
qcf = Ucf[FLOW] / qfactor;
15181510
updateruleunits(p, dcf, pcf, hcf, qcf);
15191511

1520-
//update curves
1512+
//update curves after making sure that all curve types are correctly set
1513+
assigncurvetypes(net);
15211514
for (i = 1; i <= net->Ncurves; i++)
15221515
{
15231516
switch (net->Curve[i].Type)

src/funcs.h

Lines changed: 2 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: 04/23/2025
10+
Last Updated: 02/17/2025
1111
******************************************************************************
1212
*/
1313
#ifndef FUNCS_H
@@ -40,6 +40,7 @@ int findvalve(Network *, int);
4040
int findpump(Network *, int);
4141
int findpattern(Network *, const char *);
4242
int findcurve(Network *, const char *);
43+
void assigncurvetypes(Network *network);
4344

4445
Pdemand finddemand(Pdemand, int);
4546
int adddemand(Snode *, double, int, const char *);

src/project.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ int openproject(Project *pr, const char *inpFile, const char *rptFile,
9797
pr->Openflag = TRUE;
9898
}
9999
errmsg(pr, errcode);
100+
100101
return errcode;
101102
}
102103

@@ -1101,6 +1102,58 @@ int findcurve(Network *network, const char *id)
11011102
return 0;
11021103
}
11031104

1105+
void assigncurvetypes(Network *network)
1106+
/*----------------------------------------------------------------
1107+
** Input: none
1108+
** Output: none
1109+
** Returns: none
1110+
** Purpose: assign correct curve type to all curves
1111+
**----------------------------------------------------------------
1112+
*/
1113+
{
1114+
// Pump curves
1115+
for (int i = 1; i <= network->Npumps; i++)
1116+
{
1117+
Spump *pump = &network->Pump[i];
1118+
1119+
int j;
1120+
if ((j = pump->Hcurve) > 0) {
1121+
network->Curve[j].Type = PUMP_CURVE;
1122+
}
1123+
if ((j = pump->Ecurve) > 0) {
1124+
network->Curve[j].Type = EFFIC_CURVE;
1125+
}
1126+
}
1127+
1128+
// Tank volume curves
1129+
for (int i=1; i <= network->Ntanks; i++) {
1130+
Stank* tank = &network->Tank[i];
1131+
1132+
int j;
1133+
if ((j = tank->Vcurve) > 0) {
1134+
network->Curve[j].Type = VOLUME_CURVE;
1135+
}
1136+
}
1137+
1138+
// Valve curves
1139+
for (int i=1; i <= network->Nvalves; i++) {
1140+
Svalve* valve = &network->Valve[i];
1141+
Slink* link = &network->Link[valve->Link];
1142+
1143+
int j;
1144+
if (link->Type == PCV) {
1145+
if((j = valve->Curve) > 0) {
1146+
network->Curve[j].Type = VALVE_CURVE;
1147+
}
1148+
}
1149+
else if (link->Type == GPV){
1150+
if((j = valve->Curve) > 0) {
1151+
network->Curve[j].Type = HLOSS_CURVE;
1152+
}
1153+
}
1154+
}
1155+
}
1156+
11041157
void adjustpattern(int *pat, int index)
11051158
/*----------------------------------------------------------------
11061159
** Local function that modifies a reference to a deleted time pattern

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

tests/test_units.cpp

Lines changed: 6 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ BOOST_FIXTURE_TEST_CASE(test_pda_unit_change, FixtureOpenClose)
131131

132132
error = EN_setflowunits(ph, EN_LPS);
133133
BOOST_REQUIRE(error == 0);
134+
error = EN_setoption(ph, EN_PRESS_UNITS, EN_METERS);
135+
BOOST_REQUIRE(error == 0);
134136

135137
error = EN_getdemandmodel(ph, &type, &pmin, &preq, &pexp);
136138
BOOST_REQUIRE(error == 0);
@@ -180,6 +182,8 @@ BOOST_FIXTURE_TEST_CASE(test_rule_unit_change, FixtureOpenClose)
180182
// Change flow units to lps and pressure to meters
181183
error = EN_setflowunits(ph, EN_LPS);
182184
BOOST_REQUIRE(error == 0);
185+
error = EN_setoption(ph, EN_PRESS_UNITS, EN_METERS);
186+
BOOST_REQUIRE(error == 0);
183187

184188
error = EN_getoption(ph, EN_PRESS_UNITS, &units);
185189
BOOST_REQUIRE(error == 0);
@@ -312,10 +316,10 @@ BOOST_FIXTURE_TEST_CASE(test_decoupled_pressure_units, FixtureInitClose)
312316
error = EN_setflowunits(ph, EN_LPS);
313317
BOOST_REQUIRE(error == 0);
314318

315-
// Pressure units should change to metric default of meters
319+
// Pressure units should not change
316320
error = EN_getoption(ph, EN_PRESS_UNITS, &units);
317321
BOOST_REQUIRE(error == 0);
318-
BOOST_CHECK(units == EN_METERS);
322+
BOOST_CHECK(units == EN_KPA);
319323

320324
// Test 5: With SI flow units, set pressure to PSI (should now work)
321325
error = EN_setoption(ph, EN_PRESS_UNITS, EN_PSI);
@@ -351,110 +355,5 @@ BOOST_FIXTURE_TEST_CASE(test_decoupled_pressure_units, FixtureInitClose)
351355
BOOST_REQUIRE(error == 0);
352356
}
353357

354-
BOOST_FIXTURE_TEST_CASE(test_automatic_pressure_unit_switching, FixtureInitClose)
355-
{
356-
int index;
357-
double pressure_units;
358-
359-
// Create basic network
360-
error = EN_addnode(ph, "R1", EN_RESERVOIR, &index);
361-
BOOST_REQUIRE(error == 0);
362-
error = EN_setnodevalue(ph, index, EN_ELEVATION, 100);
363-
BOOST_REQUIRE(error == 0);
364-
error = EN_addnode(ph, "J1", EN_JUNCTION, &index);
365-
BOOST_REQUIRE(error == 0);
366-
error = EN_addlink(ph, "P1", EN_PIPE, "R1", "J1", &index);
367-
BOOST_REQUIRE(error == 0);
368-
369-
// Test 1: Start with US flow units (CFS) - should have PSI pressure units
370-
error = EN_setflowunits(ph, EN_CFS);
371-
BOOST_REQUIRE(error == 0);
372-
error = EN_getoption(ph, EN_PRESS_UNITS, &pressure_units);
373-
BOOST_REQUIRE(error == 0);
374-
BOOST_CHECK(pressure_units == EN_PSI);
375-
376-
// Test 2: Change from US flow units (CFS) to metric flow units (LPS)
377-
// Pressure units should automatically change from PSI to METERS
378-
error = EN_setflowunits(ph, EN_LPS);
379-
BOOST_REQUIRE(error == 0);
380-
error = EN_getoption(ph, EN_PRESS_UNITS, &pressure_units);
381-
BOOST_REQUIRE(error == 0);
382-
BOOST_CHECK(pressure_units == EN_METERS);
383-
384-
// Test 3: Change from metric flow units (LPS) back to US flow units (GPM)
385-
// Pressure units should automatically change from METERS to PSI
386-
error = EN_setflowunits(ph, EN_GPM);
387-
BOOST_REQUIRE(error == 0);
388-
error = EN_getoption(ph, EN_PRESS_UNITS, &pressure_units);
389-
BOOST_REQUIRE(error == 0);
390-
BOOST_CHECK(pressure_units == EN_PSI);
391-
392-
// Test 4: Change from US flow units (GPM) to another metric flow unit (MLD)
393-
// Pressure units should automatically change from PSI to METERS
394-
error = EN_setflowunits(ph, EN_MLD);
395-
BOOST_REQUIRE(error == 0);
396-
error = EN_getoption(ph, EN_PRESS_UNITS, &pressure_units);
397-
BOOST_REQUIRE(error == 0);
398-
BOOST_CHECK(pressure_units == EN_METERS);
399-
400-
// Test 5: Manually set pressure units to kPa while using metric flow units
401-
error = EN_setoption(ph, EN_PRESS_UNITS, EN_KPA);
402-
BOOST_REQUIRE(error == 0);
403-
error = EN_getoption(ph, EN_PRESS_UNITS, &pressure_units);
404-
BOOST_REQUIRE(error == 0);
405-
BOOST_CHECK(pressure_units == EN_KPA);
406-
407-
// Test 6: Change from metric flow units (MLD) to US flow units (MGD)
408-
// Pressure units should automatically change from kPa to PSI
409-
error = EN_setflowunits(ph, EN_MGD);
410-
BOOST_REQUIRE(error == 0);
411-
error = EN_getoption(ph, EN_PRESS_UNITS, &pressure_units);
412-
BOOST_REQUIRE(error == 0);
413-
BOOST_CHECK(pressure_units == EN_PSI);
414-
415-
// Test 7: Change from US flow units (MGD) to metric flow units (CMH)
416-
// Pressure units should automatically change from PSI to METERS
417-
error = EN_setflowunits(ph, EN_CMH);
418-
BOOST_REQUIRE(error == 0);
419-
error = EN_getoption(ph, EN_PRESS_UNITS, &pressure_units);
420-
BOOST_REQUIRE(error == 0);
421-
BOOST_CHECK(pressure_units == EN_METERS);
422-
423-
// Test 8: Set pressure to kPa again with metric flow units
424-
error = EN_setoption(ph, EN_PRESS_UNITS, EN_KPA);
425-
BOOST_REQUIRE(error == 0);
426-
427-
// Test 9: Change between metric flow units (CMH to CMD)
428-
// Pressure units should remain kPa (not changed to METERS since not switching from PSI)
429-
error = EN_setflowunits(ph, EN_CMD);
430-
BOOST_REQUIRE(error == 0);
431-
error = EN_getoption(ph, EN_PRESS_UNITS, &pressure_units);
432-
BOOST_REQUIRE(error == 0);
433-
BOOST_CHECK(pressure_units == EN_KPA);
434-
435-
// Test 10: Change from metric flow units (CMD) to US flow units (AFD)
436-
// Pressure units should automatically change from kPa to PSI
437-
error = EN_setflowunits(ph, EN_AFD);
438-
BOOST_REQUIRE(error == 0);
439-
error = EN_getoption(ph, EN_PRESS_UNITS, &pressure_units);
440-
BOOST_REQUIRE(error == 0);
441-
BOOST_CHECK(pressure_units == EN_PSI);
442-
443-
// Test 11: Change between US flow units (AFD to IMGD)
444-
// Pressure units should remain PSI
445-
error = EN_setflowunits(ph, EN_IMGD);
446-
BOOST_REQUIRE(error == 0);
447-
error = EN_getoption(ph, EN_PRESS_UNITS, &pressure_units);
448-
BOOST_REQUIRE(error == 0);
449-
BOOST_CHECK(pressure_units == EN_PSI);
450-
451-
// Test 12: Final test - metric flow units (CMS) should change PSI to METERS
452-
error = EN_setflowunits(ph, EN_CMS);
453-
BOOST_REQUIRE(error == 0);
454-
error = EN_getoption(ph, EN_PRESS_UNITS, &pressure_units);
455-
BOOST_REQUIRE(error == 0);
456-
BOOST_CHECK(pressure_units == EN_METERS);
457-
}
458-
459358

460359
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)