From ebafb87e6aee0a36101e2574fcb88331154980ef Mon Sep 17 00:00:00 2001 From: Lew Rossman Date: Fri, 25 Jul 2025 11:02:40 -0400 Subject: [PATCH] Fix link InitSetting/InitStatus properties --- src/epanet.c | 11 +++++++---- src/hydraul.c | 18 +++++------------- src/report.c | 5 ++++- src/text.h | 2 +- src/types.h | 2 +- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index 720e442..b2fa631 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -4177,8 +4177,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu { Link[index].Kc = value; Link[index].InitSetting = value; - valveType = Link[index].Type; - if (valveType > PUMP && valveType != GPV) + if (Link[index].Type > PUMP && Link[index].Type != GPV) { Link[index].InitStatus = ACTIVE; } @@ -4343,8 +4342,12 @@ int DLLEXPORT EN_setpipedata(EN_Project p, int index, double length, if (p->hydraul.Formflag == DW) Link[index].Kc /= (1000.0 * Ucf[ELEV]); // Update minor loss factor & pipe flow resistance - Link[index].Km = 0.02517 * mloss / SQR(Link[index].Diam) / SQR(Link[index].Diam); - resistcoeff(p, index); + if (p->hydraul.OpenHflag) + { + Link[index].Km = 0.02517 * mloss / SQR(Link[index].Diam) / SQR(Link[index].Diam); + resistcoeff(p, index); + } + else Link[index].InitSetting = Link[index].Kc; return 0; } diff --git a/src/hydraul.c b/src/hydraul.c index 903e7b9..5f3b1f2 100755 --- a/src/hydraul.c +++ b/src/hydraul.c @@ -41,6 +41,7 @@ void tanklevels(Project *, long); void resetpumpflow(Project *, int); void getallpumpsenergy(Project *); + int openhyd(Project *pr) /* *-------------------------------------------------------------- @@ -126,18 +127,9 @@ void inithyd(Project *pr, int initflag) // Initialize status and setting hyd->LinkStatus[i] = link->InitStatus; hyd->LinkSetting[i] = link->InitSetting; - - // Setting of non-ACTIVE FCV, PRV, PSV valves is "MISSING" - switch (link->Type) + if (link->Type > PUMP && link->Type != GPV && link->InitStatus != ACTIVE) { - case FCV: - case PRV: - case PSV: - if (link->InitStatus != ACTIVE) - { - link->Kc = MISSING; - hyd->LinkSetting[i] = MISSING; - } + hyd->LinkSetting[i] = MISSING; } // Compute flow resistance @@ -146,7 +138,7 @@ void inithyd(Project *pr, int initflag) // Start active control valves in ACTIVE position if ( (link->Type == PRV || link->Type == PSV - || link->Type == FCV) && (link->Kc != MISSING) + || link->Type == FCV) && (hyd->LinkSetting[i] != MISSING) ) hyd->LinkStatus[i] = ACTIVE; // Initialize flows if necessary @@ -475,7 +467,7 @@ void setlinksetting(Project *pr, int index, double value, StatusType *s, else { if (*k == MISSING && *s <= CLOSED) *s = OPEN; - if (t == PCV) link->R = pcvlosscoeff(pr, index, link->Kc); + if (t == PCV) link->R = pcvlosscoeff(pr, index, value); *k = value; } } diff --git a/src/report.c b/src/report.c index 6ce3fe8..4f6b188 100644 --- a/src/report.c +++ b/src/report.c @@ -191,6 +191,7 @@ void writelogo(Project *pr) int version; int major; int minor; + int patch; char s[80]; time_t timer; // time_t structure & functions time() & // ctime() are defined in time.h @@ -198,6 +199,8 @@ void writelogo(Project *pr) version = CODEVERSION; major = version / 10000; minor = (version % 10000) / 100; + patch = version % 100; + //patch = version - (10000 * major) - (100 * minor); time(&timer); strcpy(rpt->DateStamp, ctime(&timer)); @@ -209,7 +212,7 @@ void writelogo(Project *pr) writeline(pr, LOGO2); writeline(pr, LOGO3); writeline(pr, LOGO4); - sprintf(s, LOGO5, major, minor); + sprintf(s, LOGO5, major, minor, patch); writeline(pr, s); writeline(pr, LOGO6); writeline(pr, ""); diff --git a/src/text.h b/src/text.h index 895680d..1525f4c 100755 --- a/src/text.h +++ b/src/text.h @@ -359,7 +359,7 @@ #define LOGO4 \ "* Analysis for Pipe Networks *" #define LOGO5 \ -"* Version %d.%d *" +"* Version %d.%d.%02d *" #define LOGO6 \ "******************************************************************" #define FMT02 "\n o Retrieving network data" diff --git a/src/types.h b/src/types.h index 36ad59e..aaa8f88 100755 --- a/src/types.h +++ b/src/types.h @@ -31,7 +31,7 @@ typedef int INT4; Various constants ---------------------------------------------- */ -#define CODEVERSION 20300 +#define CODEVERSION 20301 #define MAGICNUMBER 516114521 #define ENGINE_VERSION 201 // Used for binary hydraulics file #define EOFMARK 0x1A // Use 0x04 for UNIX systems