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

@@ -5,7 +5,7 @@ Attribute VB_Name = "Module1"
'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT
'(EPANET2.DLL)
'Last updated on 02/14/2025
'Last updated on 04/23/2025
' These are codes used by the DLL functions
Public Const EN_ELEVATION = 0 ' Node parameters
@@ -71,6 +71,7 @@ Public Const EN_PCV_CURVE = 25
Public Const EN_LEAK_AREA = 26
Public Const EN_LEAK_EXPAN = 27
Public Const EN_LINK_LEAKAGE = 28
Public Const EN_VALVE_TYPE = 29
Public Const EN_DURATION = 0 ' Time parameters
Public Const EN_HYDSTEP = 1

View File

@@ -3,7 +3,7 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
//epanet2.cs[By Oscar Vegas]
//Last updated on 02/14/2025
//Last updated on 04/23/2025
//Declarations of functions in the EPANET PROGRAMMERs TOOLKIT
//(EPANET2.DLL) for use with C#
@@ -84,6 +84,7 @@ namespace EpanetCSharpLibrary
public const int EN_LEAK_AREA = 26;
public const int EN_LEAK_EXPAN = 27;
public const int EN_LINK_LEAKAGE = 28;
public const int EN_VALVE_TYPE = 29;
public const int EN_DURATION = 0; //Time parameters
public const int EN_HYDSTEP = 1;

View File

@@ -3,7 +3,7 @@ unit epanet2;
{ Declarations of imported procedures from the EPANET PROGRAMMERs TOOLKIT }
{ (EPANET2.DLL) }
{Last updated on 02/14/2025}
{Last updated on 04/23/2025}
interface
@@ -79,6 +79,7 @@ const
EN_LEAK_AREA = 26;
EN_LEAK_EXPAN = 27;
EN_LINK_LEAKAGE = 28;
EN_VALVE_TYPE = 29;
EN_DURATION = 0; { Time parameters }
EN_HYDSTEP = 1;

View File

@@ -4,7 +4,7 @@
'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT
'(EPANET2.DLL) for use with VB.Net.
'Last updated on 02/14/2025
'Last updated on 04/23/2025
Imports System.Runtime.InteropServices
Imports System.Text
@@ -75,6 +75,7 @@ Public Const EN_PCV_CURVE = 25
Public Const EN_LEAK_AREA = 26
Public Const EN_LEAK_EXPAN = 27
Public Const EN_LINK_LEAKAGE = 28
Public Const EN_VALVE_TYPE = 29
Public Const EN_DURATION = 0 ' Time parameters
Public Const EN_HYDSTEP = 1

View File

@@ -9,7 +9,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 03/22/2025
Last Updated: 04/23/2025
******************************************************************************
*/
@@ -103,7 +103,8 @@ typedef enum {
EN_PCV_CURVE = 25, //!< PCV loss coeff. curve index
EN_LEAK_AREA = 26, //!< Pipe leak area (sq mm per 100 length units)
EN_LEAK_EXPAN = 27, //!< Leak expansion rate (sq mm per unit of pressure head)
EN_LINK_LEAKAGE = 28 //!< Current leakage rate (read only)
EN_LINK_LEAKAGE = 28, //!< Current leakage rate (read only)
EN_VALVE_TYPE = 29 //!< Type of valve (see @ref EN_LinkType)
} EN_LinkProperty;
/// Time parameters

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