Merge pull request #873 from OpenWaterAnalytics/Fix_Set_InitSetting

Fix set EN_INITSETTING and EN_INITSTATUS
This commit is contained in:
Lew Rossman
2025-07-28 13:37:41 -04:00
committed by GitHub
5 changed files with 20 additions and 18 deletions

View File

@@ -4177,6 +4177,10 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
{ {
Link[index].Kc = value; Link[index].Kc = value;
Link[index].InitSetting = value; Link[index].InitSetting = value;
if (Link[index].Type > PUMP && Link[index].Type != GPV)
{
Link[index].InitStatus = ACTIVE;
}
} }
else else
{ {
@@ -4338,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]); if (p->hydraul.Formflag == DW) Link[index].Kc /= (1000.0 * Ucf[ELEV]);
// Update minor loss factor & pipe flow resistance // Update minor loss factor & pipe flow resistance
Link[index].Km = 0.02517 * mloss / SQR(Link[index].Diam) / SQR(Link[index].Diam); if (p->hydraul.OpenHflag)
resistcoeff(p, index); {
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; return 0;
} }

View File

@@ -41,6 +41,7 @@ void tanklevels(Project *, long);
void resetpumpflow(Project *, int); void resetpumpflow(Project *, int);
void getallpumpsenergy(Project *); void getallpumpsenergy(Project *);
int openhyd(Project *pr) int openhyd(Project *pr)
/* /*
*-------------------------------------------------------------- *--------------------------------------------------------------
@@ -126,18 +127,9 @@ void inithyd(Project *pr, int initflag)
// Initialize status and setting // Initialize status and setting
hyd->LinkStatus[i] = link->InitStatus; hyd->LinkStatus[i] = link->InitStatus;
hyd->LinkSetting[i] = link->InitSetting; hyd->LinkSetting[i] = link->InitSetting;
if (link->Type > PUMP && link->Type != GPV && link->InitStatus != ACTIVE)
// Setting of non-ACTIVE FCV, PRV, PSV valves is "MISSING"
switch (link->Type)
{ {
case FCV: hyd->LinkSetting[i] = MISSING;
case PRV:
case PSV:
if (link->InitStatus != ACTIVE)
{
link->Kc = MISSING;
hyd->LinkSetting[i] = MISSING;
}
} }
// Compute flow resistance // Compute flow resistance
@@ -146,7 +138,7 @@ void inithyd(Project *pr, int initflag)
// Start active control valves in ACTIVE position // Start active control valves in ACTIVE position
if ( if (
(link->Type == PRV || link->Type == PSV (link->Type == PRV || link->Type == PSV
|| link->Type == FCV) && (link->Kc != MISSING) || link->Type == FCV) && (hyd->LinkSetting[i] != MISSING)
) hyd->LinkStatus[i] = ACTIVE; ) hyd->LinkStatus[i] = ACTIVE;
// Initialize flows if necessary // Initialize flows if necessary
@@ -475,7 +467,7 @@ void setlinksetting(Project *pr, int index, double value, StatusType *s,
else else
{ {
if (*k == MISSING && *s <= CLOSED) *s = OPEN; 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; *k = value;
} }
} }

View File

@@ -191,6 +191,7 @@ void writelogo(Project *pr)
int version; int version;
int major; int major;
int minor; int minor;
int patch;
char s[80]; char s[80];
time_t timer; // time_t structure & functions time() & time_t timer; // time_t structure & functions time() &
// ctime() are defined in time.h // ctime() are defined in time.h
@@ -198,6 +199,7 @@ void writelogo(Project *pr)
version = CODEVERSION; version = CODEVERSION;
major = version / 10000; major = version / 10000;
minor = (version % 10000) / 100; minor = (version % 10000) / 100;
patch = version % 100;
time(&timer); time(&timer);
strcpy(rpt->DateStamp, ctime(&timer)); strcpy(rpt->DateStamp, ctime(&timer));
@@ -209,7 +211,7 @@ void writelogo(Project *pr)
writeline(pr, LOGO2); writeline(pr, LOGO2);
writeline(pr, LOGO3); writeline(pr, LOGO3);
writeline(pr, LOGO4); writeline(pr, LOGO4);
sprintf(s, LOGO5, major, minor); sprintf(s, LOGO5, major, minor, patch);
writeline(pr, s); writeline(pr, s);
writeline(pr, LOGO6); writeline(pr, LOGO6);
writeline(pr, ""); writeline(pr, "");

View File

@@ -359,7 +359,7 @@
#define LOGO4 \ #define LOGO4 \
"* Analysis for Pipe Networks *" "* Analysis for Pipe Networks *"
#define LOGO5 \ #define LOGO5 \
"* Version %d.%d *" "* Version %d.%d.%02d *"
#define LOGO6 \ #define LOGO6 \
"******************************************************************" "******************************************************************"
#define FMT02 "\n o Retrieving network data" #define FMT02 "\n o Retrieving network data"

View File

@@ -31,7 +31,7 @@ typedef int INT4;
Various constants Various constants
---------------------------------------------- ----------------------------------------------
*/ */
#define CODEVERSION 20300 #define CODEVERSION 20301
#define MAGICNUMBER 516114521 #define MAGICNUMBER 516114521
#define ENGINE_VERSION 201 // Used for binary hydraulics file #define ENGINE_VERSION 201 // Used for binary hydraulics file
#define EOFMARK 0x1A // Use 0x04 for UNIX systems #define EOFMARK 0x1A // Use 0x04 for UNIX systems