Skip to content

Commit de872bb

Browse files
committed
Merge branch 'fix-unit-conv-bug' into dev
2 parents e69d478 + 81c7ceb commit de872bb

3 files changed

Lines changed: 63 additions & 13 deletions

File tree

epanet-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)

epanet-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 *);

epanet-src/project.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ int openproject(Project *pr, const char *inpFile, const char *rptFile,
9797
pr->Openflag = TRUE;
9898
}
9999
errmsg(pr, errcode);
100+
101+
// Fix curve types
102+
assigncurvetypes(&pr->network);
103+
100104
return errcode;
101105
}
102106

@@ -1101,6 +1105,58 @@ int findcurve(Network *network, const char *id)
11011105
return 0;
11021106
}
11031107

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

0 commit comments

Comments
 (0)