Skip to content

Commit a948eec

Browse files
committed
Add dedicated function assigncurvetypes and call it in openproject and EN_setflowunits
1 parent b2f8265 commit a948eec

File tree

3 files changed

+59
-45
lines changed

3 files changed

+59
-45
lines changed

epanet-src/epanet.c

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

@@ -1477,6 +1477,9 @@ int DLLEXPORT EN_setflowunits(EN_Project p, int units)
14771477

14781478
if (!p->Openflag) return 102;
14791479

1480+
// Make sure all curve types are correctly set
1481+
assigncurvetypes(net);
1482+
14801483
// Determine unit system based on flow units
14811484
qfactor = Ucf[FLOW];
14821485
vfactor = Ucf[VOLUME];

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: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -99,49 +99,7 @@ int openproject(Project *pr, const char *inpFile, const char *rptFile,
9999
errmsg(pr, errcode);
100100

101101
// Fix curve types
102-
Network *net = &pr->network;
103-
104-
// Pump curves
105-
for (int i = 1; i <= net->Npumps; i++)
106-
{
107-
Spump *pump = &net->Pump[i];
108-
109-
int j;
110-
if ((j = pump->Hcurve) > 0) {
111-
net->Curve[j].Type = PUMP_CURVE;
112-
}
113-
if ((j = pump->Ecurve) > 0) {
114-
net->Curve[j].Type = EFFIC_CURVE;
115-
}
116-
}
117-
118-
// Tank volume curves
119-
for (int i=1; i <= net->Ntanks; i++) {
120-
Stank* tank = &net->Tank[i];
121-
122-
int j;
123-
if ((j = tank->Vcurve) > 0) {
124-
net->Curve[j].Type = VOLUME_CURVE;
125-
}
126-
}
127-
128-
// Valve curves
129-
for (int i=1; i <= net->Nvalves; i++) {
130-
Svalve* valve = &net->Valve[i];
131-
Slink* link = &net->Link[valve->Link];
132-
133-
int j;
134-
if (link->Type == PCV) {
135-
if((j = valve->Curve) > 0) {
136-
net->Curve[j].Type = VALVE_CURVE;
137-
}
138-
}
139-
else if (link->Type == GPV){
140-
if((j = valve->Curve) > 0) {
141-
net->Curve[j].Type = HLOSS_CURVE;
142-
}
143-
}
144-
}
102+
assigncurvetypes(&pr->network);
145103

146104
return errcode;
147105
}
@@ -1147,6 +1105,58 @@ int findcurve(Network *network, const char *id)
11471105
return 0;
11481106
}
11491107

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+
11501160
void adjustpattern(int *pat, int index)
11511161
/*----------------------------------------------------------------
11521162
** Local function that modifies a reference to a deleted time pattern

0 commit comments

Comments
 (0)