Add EN_VALVE_TYPE to link getter & setter

This commit is contained in:
Lew Rossman
2025-04-23 12:59:48 -04:00
parent fe77599371
commit e206baaaab
9 changed files with 84 additions and 12 deletions

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 04/19/2025
Last Updated: 04/23/2025
******************************************************************************
*/
@@ -4015,6 +4015,10 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
case EN_LINK_LEAKAGE:
v = findlinkleakage(p, index) * Ucf[FLOW];
break;
case EN_VALVE_TYPE:
if (Link[index].Type > PUMP) v = Link[index].Type;
break;
default:
return 251;
@@ -4060,7 +4064,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
double *Ucf = p->Ucf;
char s;
double r;
int pumpIndex, patIndex, curveIndex;
int pumpIndex, patIndex, curveIndex, valveType;
if (!p->Openflag) return 102;
if (index <= 0 || index > net->Nlinks) return 204;
@@ -4268,6 +4272,14 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
if (value < 0.0) return 211;
Link[index].LeakExpan = value / Ucf[LENGTH];
break;
case EN_VALVE_TYPE:
if (hyd->OpenHflag || qual->OpenQflag) return 262; //Solver is running
if (Link[index].Type <= PUMP) return 264; //Link not a valve
valveType = ROUND(value);
if (valveType < PRV || valveType > PCV) return 213; //Invalid valve type
if (valveType == Link[index].Type) return 0; //No type change
return changevalvetype(p, index, valveType); //See project.c
default:
return 251;

View File

@@ -65,6 +65,7 @@ DAT(260,"attempt to delete node assigned as a Trace Node")
DAT(261,"attempt to delete a node or link contained in a control")
DAT(262,"attempt to modify network structure while solver is active")
DAT(263,"node is not a tank")
DAT(264,"link is not a valve")
// File errors
DAT(301,"identical file names")

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 02/14/2025
Last Updated: 04/23/2025
******************************************************************************
*/
#ifndef FUNCS_H
@@ -29,6 +29,7 @@ int buildadjlists(Network *);
void freeadjlists(Network *);
int incontrols(Project *, int, int);
int changevalvetype(Project *, int, int);
int valvecheck(Project *, int, int, int, int);
int unlinked(Project *);

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 02/19/2025
Last Updated: 04/23/2025
******************************************************************************
*/
@@ -754,7 +754,6 @@ int buildadjlists(Network *net)
return errcode;
}
void freeadjlists(Network *net)
/*
**--------------------------------------------------------------
@@ -841,6 +840,61 @@ int incontrols(Project *pr, int objType, int index)
return 0;
}
int changevalvetype(Project *pr, int index, int type)
/*
**--------------------------------------------------------------
** Input: index = link index
** type = new valve type
** Output: returns an error code
** Purpose: changes a valve's type
**--------------------------------------------------------------
*/
{
Network *net = &pr->network;
Slink *link;
int errcode;
double setting;
// Check that new valve type has legal connections
link = &net->Link[index];
if (link->Type <= PUMP) return 264;
errcode = valvecheck(pr, index, type, link->N1, link->N2);
if (errcode) return errcode;
// Preserve new type's setting in solver units
setting = link->InitSetting;
switch (link->Type)
{
case FCV:
setting *= pr->Ucf[FLOW];
break;
case PRV:
case PSV:
case PBV:
setting *= pr->Ucf[PRESSURE];
break;
}
switch (type)
{
case FCV:
setting /= pr->Ucf[FLOW];
break;
case PRV:
case PSV:
case PBV:
setting /= pr->Ucf[PRESSURE];
break;
}
// If converting to a GPV set its head loss curve to 0 (i.e., none)
if (type == GPV) setting = 0.0;
link->InitSetting = setting;
// Change valve link's type
link->Type = type;
return 0;
}
int valvecheck(Project *pr, int index, int type, int j1, int j2)
/*
**--------------------------------------------------------------
@@ -1365,7 +1419,6 @@ int setcomment(Network *network, int object, int index, const char *newcomment)
}
}
int gettag(Network *network, int object, int index, char *tag)
//----------------------------------------------------------------
// Input: object = a type of network object