Added additional network building features (#367)

This commit is contained in:
Lew Rossman
2019-01-02 10:33:58 -05:00
parent 3ce0361c1d
commit 628fffc718
14 changed files with 699 additions and 149 deletions

View File

@@ -5,7 +5,7 @@ Attribute VB_Name = "Module1"
'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT
'(EPANET2.DLL)
'Last updated on 4/3/07
'Last updated on 01/01/2019
' These are codes used by the DLL functions
Public Const EN_ELEVATION = 0 ' Node parameters
@@ -50,15 +50,16 @@ Public Const EN_HEADLOSS = 10
Public Const EN_STATUS = 11
Public Const EN_SETTING = 12
Public Const EN_ENERGY = 13
Public Const EN_LINKQUAL = 14 'ES
Public Const EN_LINKQUAL = 14
Public Const EN_LINKPATTERN = 15
Public Const EN_EFFICIENCY = 16
Public Const EN_HEADCURVE = 17
Public Const EN_EFFICIENCYCURVE = 18
Public Const EN_PRICEPATTERN = 19
Public Const EN_STATE = 20
Public Const EN_CONST_POWER = 21
Public Const EN_SPEED = 22
Public Const EN_PUMP_STATE = 16
Public Const EN_PUMP_EFFIC = 17
Public Const EN_PUMP_POWER = 18
Public Const EN_PUMP_HCURVE = 19
Public Const EN_PUMP_ECURVE = 20
Public Const EN_PUMP_ECOST = 21
Public Const EN_PUMP_EPAT = 22
Public Const EN_DURATION = 0 ' Time parameters
Public Const EN_HYDSTEP = 1
@@ -76,13 +77,13 @@ Public Const EN_QTIME = 12
Public Const EN_HALTFLAG = 13
Public Const EN_NEXTEVENT = 14
Public Const EN_ITERATIONS = 0
Public Const EN_ITERATIONS = 0 ' Run statistics
Public Const EN_RELATIVEERROR = 1
Public Const EN_MAXHEADERROR = 2
Public Const EN_MAXFLOWCHANGE = 3
Public Const EN_MASSBALANCE = 4
Public Const EN_NODECOUNT = 0 'Component counts
Public Const EN_NODECOUNT = 0 ' Component counts
Public Const EN_TANKCOUNT = 1
Public Const EN_LINKCOUNT = 2
Public Const EN_PATCOUNT = 3
@@ -114,7 +115,7 @@ Public Const EN_MASS = 1
Public Const EN_SETPOINT = 2
Public Const EN_FLOWPACED = 3
Public Const EN_HW = 0 ' Head loss formula
Public Const EN_HW = 0 ' Head loss formulas
Public Const EN_DW = 1
Public Const EN_CM = 2
@@ -132,7 +133,7 @@ Public Const EN_CMD = 9
Public Const EN_DDA = 0 ' Demand driven analysis
Public Const EN_PDA = 1 ' Pressure driven analysis
Public Const EN_TRIALS = 0 ' Misc. options
Public Const EN_TRIALS = 0 ' Hydraulic options
Public Const EN_ACCURACY = 1
Public Const EN_TOLERANCE = 2
Public Const EN_EMITEXPON = 3
@@ -141,41 +142,82 @@ Public Const EN_HEADERROR = 5
Public Const EN_FLOWCHANGE = 6
Public Const EN_DEMANDDEFPAT = 7
Public Const EN_HEADLOSSFORM = 8
Public Const EN_GLOBALEFFIC = 9
Public Const EN_GLOBALPRICE = 10
Public Const EN_GLOBALPATTERN = 11
Public Const EN_DEMANDCHARGE = 12
Public Const EN_LOWLEVEL = 0 ' Control types
Public Const EN_LOWLEVEL = 0 ' Control types
Public Const EN_HILEVEL = 1
Public Const EN_TIMER = 2
Public Const EN_TIMEOFDAY = 3
Public Const EN_AVERAGE = 1 'Time statistic types
Public Const EN_AVERAGE = 1 ' Time statistic types
Public Const EN_MINIMUM = 2
Public Const EN_MAXIMUM = 3
Public Const EN_RANGE = 4
Public Const EN_MIX1 = 0 'Tank mixing models
Public Const EN_MIX1 = 0 ' Tank mixing models
Public Const EN_MIX2 = 1
Public Const EN_FIFO = 2
Public Const EN_LIFO = 3
Public Const EN_NOSAVE = 0 ' Save-results-to-file flag
Public Const EN_NOSAVE = 0 ' Save-results-to-file flag
Public Const EN_SAVE = 1
Public Const EN_INITFLOW = 10 ' Re-initialize flow flag
Public Const EN_SAVE_AND_INIT = 11
Public Const EN_INITFLOW = 10 ' Re-initialize flow flag
Public Const EN_CONST_HP = 0 ' Constant horsepower pump curve
Public Const EN_POWER_FUNC = 1 ' Power function pump cuve
Public Const EN_CUSTOM = 2 ' User-defined custom pump curve
Public Const EN_NOCURVE = 3 ' No pump curve
Public Const EN_CONST_HP = 0 ' constant horsepower
Public Const EN_POWER_FUNC = 1 ' power function
Public Const EN_CUSTOM = 2 ' user-defined custom curve
Public Const EN_NOCURVE = 3 ' no curve
Public Const EN_V_CURVE = 0 ' volume curve
Public Const EN_P_CURVE = 1 ' pump curve
Public Const EN_E_CURVE = 2 ' efficiency curve
Public Const EN_H_CURVE = 3 ' head loss curve
Public Const EN_G_CURVE = 4 ' General\default curve
Public Const EN_VOLUME_CURVE = 0 ' Volume curve
Public Const EN_PUMP_CURVE = 1 ' Pump curve
Public Const EN_EFFIC_CURVE = 2 ' Efficiency curve
Public Const EN_HLOSS_CURVE = 3 ' Head loss curve
Public Const EN_GENERIC_CURVE = 4 ' Generic curve
Public Const EN_UNCONDITIONAL = 0 ' Unconditional object deletion
Public Const EN_CONDITIONAL = 1 ' Conditional object deletion
Public Const EN_NO_REPORT = 0 ' No status report
Public Const EN_NORMAL_REPORT = 1 ' Normal status report
Public Const EN_FULL_REPORT = 2 ' Full status report
Public Const EN_R_NODE = 6 ' Rule objects
Public Const EN_R_LINK = 7
Public Const EN_R_SYSTEM = 8
Public Const EN_R_DEMAND = 0 ' Rule variables
Public Const EN_R_HEAD = 1
Public Const EN_R_GRADE = 2
Public Const EN_R_LEVEL = 3
Public Const EN_R_PRESSURE = 4
Public Const EN_R_FLOW = 5
Public Const EN_R_STATUS = 6
Public Const EN_R_SETTING = 7
Public Const EN_R_POWER = 8
Public Const EN_R_TIME = 9
Public Const EN_R_CLOCKTIME = 10
Public Const EN_R_FILLTIME = 11
Public Const EN_R_DRAINTIME = 12
Public Const EN_R_EQ = 0 ' Rule operators
Public Const EN_R_NE = 1
Public Const EN_R_LE = 2
Public Const EN_R_GE = 3
Public Const EN_R_LT = 4
Public Const EN_R_GT = 5
Public Const EN_R_IS = 6
Public Const EN_R_NOT = 7
Public Const EN_R_BELOW = 8
Public Const EN_R_ABOVE = 9
Public Const EN_R_IS_OPEN = 1 ' Rule status types
Public Const EN_R_IS_CLOSED = 2
Public Const EN_R_IS_ACTIVE = 3
'These are the external functions that comprise the DLL
'System Functions
@@ -236,6 +278,8 @@ Public Const EN_CONDITIONAL = 1 ' Conditional object deletion
Declare Function ENgetnodetype Lib "epanet2.dll" (ByVal index As Long, code As Long) As Long
Declare Function ENgetnodevalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, value As Single) As Long
Declare Function ENsetnodevalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, ByVal value As Single) As Long
Declare Function ENsetjuncdata Lib "epanet2.dll" (ByVal index As Long, ByVal elev As Single, ByVal dmnd As Single, ByVal dmndpat As String) As Long
Declare Function ENsettankdata Lib "epanet2.dll" (ByVal index As Long, ByVal elev As Single, ByVal initlvl As Single, ByVal minlvl As Single, ByVal maxlvl As Single, ByVal diam As Single, ByVal minvol As Single, ByVal volcurve As String) As Long
Declare Function ENgetcoord Lib "epanet2.dll" (ByVal index As Long, X As Single, Y As Single) As Long
Declare Function ENsetcoord Lib "epanet2.dll" (ByVal index As Long, ByVal X As Single, ByVal Y As Single) As Long
@@ -262,6 +306,7 @@ Public Const EN_CONDITIONAL = 1 ' Conditional object deletion
Declare Function ENsetlinknodes Lib "epanet2.dll" (ByVal index As Long, ByVal node1 As Long, ByVal node2 As Long) As Long
Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, value As Single) As Long
Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, ByVal value As Single) As Long
Declare Function ENsetpipedata Lib "epanet2.dll" (ByVal index As Long, ByVal length As Single, ByVal diam As Single, ByVal rough As Single, ByVal mloss As Single) As Long
'Pump Functions
Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal pumpIndex As Long, curveIndex As Long) As Long

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 11/29/2018
Last Updated: 12/31/2018
******************************************************************************
*/
@@ -44,12 +44,6 @@
#endif // __cplusplus
#elif defined(CYGWIN)
#define DLLEXPORT __stdcall
#elif defined(__APPLE__)
#ifdef __cplusplus
#define DLLEXPORT
#else
#define DLLEXPORT
#endif
#else
#define DLLEXPORT
#endif
@@ -510,6 +504,34 @@ extern "C" {
*/
int DLLEXPORT ENsetnodevalue(int index, int code, EN_API_FLOAT_TYPE v);
/**
@brief Set a group of properties for a junction node.
@param index The index of a junction node.
@param elev The junction's elevation.
@param dmnd The junction's primary base demand.
@param dmndpat The name of the demand's time pattern ("" for no pattern)
@return Error code.
*/
int DLLEXPORT ENsetjuncdata(int index, EN_API_FLOAT_TYPE elev,
EN_API_FLOAT_TYPE dmnd, char *dmndpat);
/**
@brief Set a group of properties for a tank node.
@param index The index of a tank node.
@param elev The tank's bottom elevation.
@param initlvl The initial water level in the tank.
@param minlvl The minimum water level for the tank.
@param maxlvl The maximum water level for the tank.
@param diam The tank's diameter (0 if volume curve used).
@param minvol The volume of the tank at its minimum water level.
@param volcurve The name of the tank's volume curve ("" for no curve)
@return Error code.
*/
int DLLEXPORT ENsettankdata(int index, EN_API_FLOAT_TYPE elev,
EN_API_FLOAT_TYPE initlvl, EN_API_FLOAT_TYPE minlvl,
EN_API_FLOAT_TYPE maxlvl, EN_API_FLOAT_TYPE diam,
EN_API_FLOAT_TYPE minvol, char *volcurve);
/**
@brief Get coordinates (x,y) for a node.
@param index The index of a node (first node is index 1).
@@ -743,6 +765,20 @@ extern "C" {
*/
int DLLEXPORT ENsetlinkvalue(int index, int code, EN_API_FLOAT_TYPE v);
/**
@brief Set a collection of property values for a pipe link.
@param index The index of a pipe link.
@param length The pipe's length.
@param diam The pipe's diameter.
@param rough The pipe's roughness coefficient.
@param mloss The pipe's minor loss coefficient.
@return Error code.
*/
int DLLEXPORT ENsetpipedata(int index, EN_API_FLOAT_TYPE length,
EN_API_FLOAT_TYPE diam, EN_API_FLOAT_TYPE rough,
EN_API_FLOAT_TYPE mloss);
/********************************************************************
Pump Functions

View File

@@ -4,7 +4,7 @@
'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT
'(EPANET2.DLL) for use with VB.Net.
'Last updated on 7/19/15 - LR
'Last updated on 01/01/2019
Imports System.Runtime.InteropServices
Imports System.Text
@@ -55,15 +55,16 @@ Public Const EN_HEADLOSS = 10
Public Const EN_STATUS = 11
Public Const EN_SETTING = 12
Public Const EN_ENERGY = 13
Public Const EN_LINKQUAL = 14 'ES
Public Const EN_LINKQUAL = 14
Public Const EN_LINKPATTERN = 15
Public Const EN_EFFICIENCY = 16
Public Const EN_HEADCURVE = 17
Public Const EN_EFFICIENCYCURVE = 18
Public Const EN_PRICEPATTERN = 19
Public Const EN_STATE = 20
Public Const EN_CONST_POWER = 21
Public Const EN_SPEED = 22
Public Const EN_PUMP_STATE = 16
Public Const EN_PUMP_EFFIC = 17
Public Const EN_PUMP_POWER = 18
Public Const EN_PUMP_HCURVE = 19
Public Const EN_PUMP_ECURVE = 20
Public Const EN_PUMP_ECOST = 21
Public Const EN_PUMP_EPAT = 22
Public Const EN_DURATION = 0 ' Time parameters
Public Const EN_HYDSTEP = 1
@@ -75,7 +76,7 @@ Public Const EN_REPORTSTART = 6
Public Const EN_RULESTEP = 7
Public Const EN_STATISTIC = 8
Public Const EN_PERIODS = 9
Public Const EN_STARTTIME = 10 'ES
Public Const EN_STARTTIME = 10
Public Const EN_HTIME = 11
Public Const EN_QTIME = 12
Public Const EN_HALTFLAG = 13
@@ -119,7 +120,7 @@ Public Const EN_MASS = 1
Public Const EN_SETPOINT = 2
Public Const EN_FLOWPACED = 3
Public Const EN_HW = 0 ' Head loss formula
Public Const EN_HW = 0 ' Head loss formulas
Public Const EN_DW = 1
Public Const EN_CM = 2
@@ -137,7 +138,7 @@ Public Const EN_CMD = 9
Public Const EN_DDA = 0 ' Demand driven analysis
Public Const EN_PDA = 1 ' Pressure driven analysis
Public Const EN_TRIALS = 0 ' Misc. options
Public Const EN_TRIALS = 0 ' Hydraulic options
Public Const EN_ACCURACY = 1
Public Const EN_TOLERANCE = 2
Public Const EN_EMITEXPON = 3
@@ -146,39 +147,82 @@ Public Const EN_HEADERROR = 5
Public Const EN_FLOWCHANGE = 6
Public Const EN_DEMANDDEFPAT = 7
Public Const EN_HEADLOSSFORM = 8
Public Const EN_GLOBALEFFIC = 9
Public Const EN_GLOBALPRICE = 10
Public Const EN_GLOBALPATTERN = 11
Public Const EN_DEMANDCHARGE = 12
Public Const EN_LOWLEVEL = 0 ' Control types
Public Const EN_LOWLEVEL = 0 ' Control types
Public Const EN_HILEVEL = 1
Public Const EN_TIMER = 2
Public Const EN_TIMEOFDAY = 3
Public Const EN_AVERAGE = 1 'Time statistic types
Public Const EN_AVERAGE = 1 ' Time statistic types
Public Const EN_MINIMUM = 2
Public Const EN_MAXIMUM = 3
Public Const EN_RANGE = 4
Public Const EN_MIX1 = 0 'Tank mixing models
Public Const EN_MIX1 = 0 ' Tank mixing models
Public Const EN_MIX2 = 1
Public Const EN_FIFO = 2
Public Const EN_LIFO = 3
Public Const EN_NOSAVE = 0 ' Save-results-to-file flag
Public Const EN_NOSAVE = 0 ' Save-results-to-file flag
Public Const EN_SAVE = 1
Public Const EN_INITFLOW = 10 ' Re-initialize flow flag
Public Const EN_INITFLOW = 10 ' Re-initialize flow flag
Public Const EN_SAVE_AND_INIT = 11
Public Const EN_CONST_HP = 0 ' constant horsepower
Public Const EN_POWER_FUNC = 1 ' power function
Public Const EN_CUSTOM = 2 ' user-defined custom curve
Public Const EN_CONST_HP = 0 ' Constant horsepower pump curve
Public Const EN_POWER_FUNC = 1 ' Power function pump curve
Public Const EN_CUSTOM = 2 ' User-defined custom pump curve
Public Const EN_NOCURVE = 3 ' No pump curve
Public Const EN_V_CURVE = 0 ' volume curve
Public Const EN_P_CURVE = 1 ' pump curve
Public Const EN_E_CURVE = 2 ' efficiency curve
Public Const EN_H_CURVE = 3 ' head loss curve
Public Const EN_G_CURVE = 4 ' General\default curve
Public Const EN_VOLUME_CURVE = 0 ' Volume curve
Public Const EN_PUMP_CURVE = 1 ' Pump curve
Public Const EN_EFFIC_CURVE = 2 ' Efficiency curve
Public Const EN_HLOSS_CURVE = 3 ' Head loss curve
Public Const EN_GENERIC_CURVE = 4 ' Generic curve
Public Const EN_UNCONDITIONAL = 0 ' Unconditional object deletion
Public Const EN_CONDITIONAL = 1 ' Conditional object deletion
Public Const EN_NO_REPORT = 0 ' No status report
Public Const EN_NORMAL_REPORT = 1 ' Normal status report
Public Const EN_FULL_REPORT = 2 ' Full status report
Public Const EN_R_NODE = 6 ' Rule objects
Public Const EN_R_LINK = 7
Public Const EN_R_SYSTEM = 8
Public Const EN_R_DEMAND = 0 ' Rule variables
Public Const EN_R_HEAD = 1
Public Const EN_R_GRADE = 2
Public Const EN_R_LEVEL = 3
Public Const EN_R_PRESSURE = 4
Public Const EN_R_FLOW = 5
Public Const EN_R_STATUS = 6
Public Const EN_R_SETTING = 7
Public Const EN_R_POWER = 8
Public Const EN_R_TIME = 9
Public Const EN_R_CLOCKTIME = 10
Public Const EN_R_FILLTIME = 11
Public Const EN_R_DRAINTIME = 12
Public Const EN_R_EQ = 0 ' Rule operators
Public Const EN_R_NE = 1
Public Const EN_R_LE = 2
Public Const EN_R_GE = 3
Public Const EN_R_LT = 4
Public Const EN_R_GT = 5
Public Const EN_R_IS = 6
Public Const EN_R_NOT = 7
Public Const EN_R_BELOW = 8
Public Const EN_R_ABOVE = 9
Public Const EN_R_IS_OPEN = 1 ' Rule status types
Public Const EN_R_IS_CLOSED = 2
Public Const EN_R_IS_ACTIVE = 3
'These are the external functions that comprise the DLL
'System Functions
@@ -239,6 +283,8 @@ Public Const EN_CONDITIONAL = 1 ' Conditional object deletion
Declare Function ENgetnodetype Lib "epanet2.dll" (ByVal Index As Int32, ByRef Code As Int32) As Int32
Declare Function ENgetnodevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByRef Value As Single) As Int32
Declare Function ENsetnodevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByVal Value As Single) As Int32
Declare Function ENsetjuncdata Lib "epanet2.dll" (ByVal index As Int32, ByVal elev As Single, ByVal dmnd As Single, ByVal dmndpat As String) As Int32
Declare Function ENsettankdata Lib "epanet2.dll" (ByVal index As Int32, ByVal elev As Single, ByVal initlvl As Single, ByVal minlvl As Single, ByVal maxlvl As Single, ByVal diam As Single, ByVal minvol As Single, ByVal volcurve As String) As Int32
Declare Function ENgetcoord Lib "epanet2.dll" (ByVal Index As Int32, ByRef X As Single, ByRef Y As Single) As Int32
Declare Function ENsetcoord Lib "epanet2.dll" (ByVal Index As Int32, ByVal X As Single, ByVal Y As Single) As Int32
@@ -265,6 +311,7 @@ Public Const EN_CONDITIONAL = 1 ' Conditional object deletion
Declare Function ENsetlinknodes Lib "epanet2.dll" (ByVal index As Int32, ByVal node1 As Int32, ByVal node2 As Int32) As Int32
Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByRef Value As Single) As Int32
Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByVal Value As Single) As Int32
Declare Function ENsetpipedata Lib "epanet2.dll" (ByVal index As Int32, ByVal length As Single, ByVal diam As Single, ByVal rough As Single, ByVal mloss As Single) As Int32
'Pump Functions
Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal Index As Int32, ByVal CurveIndex As int32) As Int32 'ES

View File

@@ -11,7 +11,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 11/29/2018
Last Updated: 12/31/2018
******************************************************************************
*/
@@ -46,22 +46,14 @@
#endif // __cplusplus
#elif defined(CYGWIN)
#define DLLEXPORT __stdcall
#elif defined(__APPLE__)
#ifdef __cplusplus
#define DLLEXPORT
#else
#define DLLEXPORT
#endif
#else
#define DLLEXPORT
#endif
#endif
#endif
#include "epanet2_enums.h"
// --- Declare the EPANET toolkit functions
#if defined(__cplusplus)
extern "C" {
@@ -137,6 +129,12 @@ typedef struct Project *EN_Project;
int DLLEXPORT EN_getnodetype(EN_Project ph, int index, int *code);
int DLLEXPORT EN_getnodevalue(EN_Project ph, int index, int code, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_setnodevalue(EN_Project ph, int index, int code, EN_API_FLOAT_TYPE v);
int DLLEXPORT EN_setjuncdata(EN_Project ph, int index, EN_API_FLOAT_TYPE elev,
EN_API_FLOAT_TYPE dmnd, char *dmndpat);
int DLLEXPORT EN_settankdata(EN_Project ph, int index, EN_API_FLOAT_TYPE elev,
EN_API_FLOAT_TYPE initlvl, EN_API_FLOAT_TYPE minlvl,
EN_API_FLOAT_TYPE maxlvl, EN_API_FLOAT_TYPE diam,
EN_API_FLOAT_TYPE minvol, char *volcurve);
int DLLEXPORT EN_getcoord(EN_Project ph, int index, EN_API_FLOAT_TYPE *x,
EN_API_FLOAT_TYPE *y);
int DLLEXPORT EN_setcoord(EN_Project ph, int index, EN_API_FLOAT_TYPE x,
@@ -173,6 +171,9 @@ typedef struct Project *EN_Project;
int DLLEXPORT EN_getlinkvalue(EN_Project ph, int index, EN_LinkProperty code,
EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_setlinkvalue(EN_Project ph, int index, int code, EN_API_FLOAT_TYPE v);
int DLLEXPORT EN_setpipedata(EN_Project ph, int index, EN_API_FLOAT_TYPE length,
EN_API_FLOAT_TYPE diam, EN_API_FLOAT_TYPE rough, EN_API_FLOAT_TYPE mloss);
int DLLEXPORT EN_getpumptype(EN_Project ph, int linkIndex, int *outType);
int DLLEXPORT EN_getheadcurveindex(EN_Project ph, int pumpIndex, int *curveIndex);

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 11/29/2018
Last Updated: 01/01/2019
******************************************************************************
*/
@@ -69,13 +69,14 @@ typedef enum {
EN_ENERGY = 13, //!> Current pump energy usage
EN_LINKQUAL = 14, //!> Current link quality
EN_LINKPATTERN = 15, //!> Pump speed time pattern
EN_EFFICIENCY = 16, //!> Current pump efficiency
EN_HEADCURVE = 17, //!> Pump head v. flow curve
EN_EFFICIENCYCURVE = 18, //!> Pump efficiency v. flow curve
EN_PRICEPATTERN = 19, //!> Pump energy price time pattern
EN_STATE = 20, //!> Current pump status
EN_CONST_POWER = 21, //!> Horsepower of constant horsepower pump
EN_SPEED = 22 //!> Current pump speed setting
EN_PUMP_STATE = 16, //!> Current pump status
EN_PUMP_EFFIC = 17, //!> Current pump efficiency
EN_PUMP_POWER = 18, //!> Pump constant power rating
EN_PUMP_HCURVE = 19, //!> Pump head v. flow curve
EN_PUMP_ECURVE = 20, //!> Pump efficiency v. flow curve
EN_PUMP_ECOST = 21, //!> Pump average energy price
EN_PUMP_EPAT = 22 //!> Pump energy price time pattern
} EN_LinkProperty;
/// Time parameter codes
@@ -181,17 +182,21 @@ typedef enum {
EN_PDA = 1 //!< Pressure driven analysis
} EN_DemandModel;
/// Simulation Option codes
/// Simulation option codes
typedef enum {
EN_TRIALS = 0, //!> Maximum hydraulic trials allowed
EN_ACCURACY = 1, //!> Hydraulic convergence accuracy
EN_TOLERANCE = 2, //!> Water quality tolerance
EN_EMITEXPON = 3, //!> Exponent for emitter head loss formula
EN_DEMANDMULT = 4, //!> Global demand multiplier
EN_HEADERROR = 5, //!> Maximum allowable head loss error
EN_FLOWCHANGE = 6, //!> Maximum allowable flow change
EN_DEMANDDEFPAT = 7, //!> Default demand time pattern
EN_HEADLOSSFORM = 8 //!> Head loss formula code
EN_TRIALS = 0, //!> Maximum hydraulic trials allowed
EN_ACCURACY = 1, //!> Hydraulic convergence accuracy
EN_TOLERANCE = 2, //!> Water quality tolerance
EN_EMITEXPON = 3, //!> Exponent for emitter head loss formula
EN_DEMANDMULT = 4, //!> Global demand multiplier
EN_HEADERROR = 5, //!> Maximum allowable head loss error
EN_FLOWCHANGE = 6, //!> Maximum allowable flow change
EN_DEFDEMANDPAT = 7, //!> Default demand time pattern
EN_HEADLOSSFORM = 8, //!> Head loss formula code
EN_GLOBALEFFIC = 9, //!> Global pump efficiency
EN_GLOBALPRICE = 10, //!> Global energy price per KWH
EN_GLOBALPATTERN = 11, //!> Global energy price pattern
EN_DEMANDCHARGE = 12 //!> Energy charge per max. KW usage
} EN_Option;
/// Simple control types
@@ -236,19 +241,26 @@ typedef enum {
/// Data curve types
typedef enum {
EN_V_CURVE = 0, //!< Tank volume curve
EN_P_CURVE = 1, //!< Pump characteristic curve
EN_E_CURVE = 2, //!< Pump efficiency curve
EN_H_CURVE = 3, //!< Valve head loss curve
EN_G_CURVE = 4 //!< General\default curve
EN_VOLUME_CURVE = 0, //!< Tank volume curve
EN_PUMP_CURVE = 1, //!< Pump head curve
EN_EFFIC_CURVE = 2, //!< Pump efficiency curve
EN_HLOSS_CURVE = 3, //!< Valve head loss curve
EN_GENERIC_CURVE = 4 //!< Generic curve
} EN_CurveType;
/// Deletion action types
/// Deletion action codes
typedef enum {
EN_UNCONDITIONAL = 0, //!> Delete all controls that contain object
EN_CONDITIONAL = 1 //!> Cancel object deletion if contained in controls
} EN_ActionCodeType;
/// Status report options
typedef enum {
EN_NO_REPORT = 0,
EN_NORMAL_REPORT = 1,
EN_FULL_REPORT = 2
} EN_StatusReport;
/// Rule object codes
typedef enum {
EN_R_NODE = 6,
@@ -294,12 +306,5 @@ typedef enum {
EN_R_IS_ACTIVE = 3
} EN_RuleStatus;
/// Status report types
typedef enum {
EN_NO_REPORT = 0,
EN_NORMAL_REPORT = 1,
EN_FULL_REPORT = 2
} EN_StatusReport;
#endif //EPANET2_ENUMS_H

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 12/15/2018
Last Updated: 01/01/2019
******************************************************************************
*/
@@ -134,7 +134,7 @@ int DLLEXPORT EN_init(EN_Project p, const char *f2, const char *f3,
int errcode = 0;
// Set system flags
p->Openflag = TRUE;
p->Openflag = FALSE;
p->hydraul.OpenHflag = FALSE;
p->quality.OpenQflag = FALSE;
p->outfile.SaveHflag = FALSE;
@@ -143,6 +143,10 @@ int DLLEXPORT EN_init(EN_Project p, const char *f2, const char *f3,
p->report.Messageflag = TRUE;
p->report.Rptflag = 1;
// Check for valid arguments
if (unitsType < 0 || unitsType > CMD) return 251;
if (headLossType < 0 || headLossType > CM) return 251;
// Open files
errcode = openfiles(p, "", f2, f3);
@@ -167,6 +171,7 @@ int DLLEXPORT EN_init(EN_Project p, const char *f2, const char *f3,
// Initialize the default demand pattern
p->parser.MaxPats = 0;
getpatterns(p);
p->Openflag = TRUE;
return errcode;
}
@@ -1032,12 +1037,25 @@ int DLLEXPORT EN_getoption(EN_Project p, EN_Option code,
case EN_FLOWCHANGE:
v = hyd->FlowChangeLimit * Ucf[FLOW];
break;
case EN_DEMANDDEFPAT:
case EN_DEFDEMANDPAT:
v = hyd->DefPat;
break;
case EN_HEADLOSSFORM:
v = hyd->Formflag;
break;
case EN_GLOBALEFFIC:
v = hyd->Epump;
break;
case EN_GLOBALPRICE:
v = hyd->Ecost;
break;
case EN_GLOBALPATTERN:
v = hyd->Epat;
break;
case EN_DEMANDCHARGE:
v = hyd->Dcost;
break;
default:
return 251;
}
@@ -1114,7 +1132,7 @@ int DLLEXPORT EN_setoption(EN_Project p, int code, EN_API_FLOAT_TYPE v)
hyd->FlowChangeLimit = value / Ucf[FLOW];
break;
case EN_DEMANDDEFPAT:
case EN_DEFDEMANDPAT:
//check that the pattern exists or is set to zero to delete the default pattern
if (value < 0 || value > net->Npats) return 205;
tmpPat = hyd->DefPat;
@@ -1145,6 +1163,27 @@ int DLLEXPORT EN_setoption(EN_Project p, int code, EN_API_FLOAT_TYPE v)
hyd->DefPat = (int)value;
break;
case EN_GLOBALEFFIC:
if (value <= 0.0 || value > 100.0) return 213;
hyd->Epump = value;
break;
case EN_GLOBALPRICE:
if (value < 0.0) return 213;
hyd->Ecost = value;
break;
case EN_GLOBALPATTERN:
tmpPat = (int)(value + 0.5);
if (tmpPat < 0 || tmpPat > net->Npats) return 205;
hyd->Epat = tmpPat;
break;
case EN_DEMANDCHARGE:
if (value < 0.0) return 213;
hyd->Dcost = value;
break;
default:
return 251;
}
@@ -1214,16 +1253,16 @@ int DLLEXPORT EN_setflowunits(EN_Project p, int code)
{
switch (net->Curve[i].Type)
{
case V_CURVE:
case VOLUME_CURVE:
xfactor = efactor / Ucf[ELEV];
yfactor = vfactor / Ucf[VOLUME];
break;
case H_CURVE:
case P_CURVE:
case HLOSS_CURVE:
case PUMP_CURVE:
xfactor = qfactor / Ucf[FLOW];
yfactor = hfactor / Ucf[HEAD];
break;
case E_CURVE:
case EFFIC_CURVE:
xfactor = qfactor / Ucf[FLOW];
yfactor = 1;
break;
@@ -2067,6 +2106,7 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int code, EN_API_FLOAT_TY
Snode *Node = net->Node;
Stank *Tank = net->Tank;
Scurve *curve;
const int nNodes = net->Nnodes;
const int nJuncs = net->Njuncs;
@@ -2074,7 +2114,7 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int code, EN_API_FLOAT_TY
double *Ucf = p->Ucf;
int j;
int i, j, n;
Pdemand demand;
Psource source;
double hTmp;
@@ -2179,7 +2219,7 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int code, EN_API_FLOAT_TY
else
{
value = Node[index].El + value / Ucf[ELEV];
if (value > Tank[j].Hmax || value < Tank[j].Hmin) return 209;
if (value > Tank[j].Hmax || value < Tank[j].Hmin) return 225;
Tank[j].H0 = value;
Tank[j].V0 = tankvolume(p, j, Tank[j].H0);
// Resetting Volume in addition to initial volume
@@ -2199,6 +2239,7 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int code, EN_API_FLOAT_TY
Tank[j].Vmin = tankvolume(p, j, Tank[j].Hmin);
Tank[j].V0 = tankvolume(p, j, Tank[j].H0);
Tank[j].Vmax = tankvolume(p, j, Tank[j].Hmax);
Tank[j].Vcurve = 0;
}
break;
@@ -2214,6 +2255,23 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int code, EN_API_FLOAT_TY
}
break;
case EN_VOLCURVE:
if (index < nJuncs) return 0;
i = ROUND(value);
if (i < 0 || i > net->Ncurves) return 205;
curve = &net->Curve[i];
j = index - nJuncs;
if (Tank[j].A == 0.0) return 0;
n = curve->Npts - 1;
if (Tank[j].Vmin * Ucf[VOLUME] < curve->Y[0] ||
Tank[j].Vmax * Ucf[VOLUME] > curve->Y[n]) return 225;
Tank[j].Vcurve = i;
Tank[j].Vmin = tankvolume(p, j, Tank[j].Hmin);
Tank[j].V0 = tankvolume(p, j, Tank[j].H0);
Tank[j].Vmax = tankvolume(p, j, Tank[j].Hmax);
Tank[j].A = (curve->Y[n] - curve->Y[0]) / (curve->X[n] - curve->X[0]);
break;
case EN_MINLEVEL:
if (value < 0.0) return 209;
if (index <= nJuncs) return 0; // not a tank or reservoir
@@ -2226,7 +2284,7 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int code, EN_API_FLOAT_TY
Tank[j].Hmin = hTmp;
Tank[j].Vmin = (Tank[j].Hmin - Node[index].El) * Tank[j].A;
}
else return 209;
else return 225;
break;
case EN_MAXLEVEL:
@@ -2241,7 +2299,7 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int code, EN_API_FLOAT_TY
Tank[j].Hmax = hTmp;
Tank[j].Vmax = tankvolume(p, j, Tank[j].Hmax);
}
else return 209;
else return 225;
break;
case EN_MIXMODEL:
@@ -2280,6 +2338,130 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int code, EN_API_FLOAT_TY
return 0;
}
int DLLEXPORT EN_setjuncdata(EN_Project p, int index, EN_API_FLOAT_TYPE elev,
EN_API_FLOAT_TYPE dmnd, char *patID)
/*----------------------------------------------------------------
** Input: index = junction node index
** elev = junction elevation
** dmnd = junction primary base demand
** patID = name of primary demand time pattern
** Output: none
** Returns: error code
** Purpose: sets several properties for a junction node.
**----------------------------------------------------------------
*/
{
Network *net = &p->network;
int i, patIndex = 0;
Snode *Node = net->Node;
Pdemand demand;
// Check that junction exists
if (!p->Openflag) return 102;
if (index <= 0 || index > net->Njuncs) return 203;
// Check that demand pattern exists
if (strlen(patID) > 0)
{
for (i = 1; i <= net->Npats; i++)
{
if (strcmp(patID, net->Pattern[i].ID) == 0)
{
patIndex = i;
break;
}
}
if (patIndex == 0) return 205;
}
// Assign values to junction's parameters
Node[index].El = elev / p->Ucf[ELEV];
for (demand = Node[index].D; demand != NULL; demand = demand->next)
{
if (demand->next == NULL)
{
demand->Base = dmnd / p->Ucf[FLOW];
demand->Pat = patIndex;
}
}
return 0;
}
int DLLEXPORT EN_settankdata(EN_Project p, int index, EN_API_FLOAT_TYPE elev,
EN_API_FLOAT_TYPE initlvl, EN_API_FLOAT_TYPE minlvl,
EN_API_FLOAT_TYPE maxlvl, EN_API_FLOAT_TYPE diam,
EN_API_FLOAT_TYPE minvol, char *volcurve)
/*----------------------------------------------------------------
** Input: index = tank node index
** elev = tank bottom elevation
** initlvl = initial water depth
** minlvl = minimum water depth
** maxlvl = maximum water depth
** diam = tank diameter
** minvol = tank volume at minimum level
** volCurve = name of curve for volume v. level
** Output: none
** Returns: error code
** Purpose: sets several properties for a tank node.
**----------------------------------------------------------------
*/
{
Network *net = &p->network;
int i, j, n, curveIndex = 0;
double area, elevation = elev;
double *Ucf = p->Ucf;
Snode *Node = net->Node;
Stank *Tank = net->Tank;
Scurve *curve;
// Check that tank exists
if (!p->Openflag) return 102;
if (index <= net->Njuncs || index > net->Nnodes) return 203;
j = index - net->Njuncs;
if (Tank[j].A == 0) return 0; // Tank is a Reservoir
// Check for valid parameter values
if (initlvl < 0.0 || minlvl < 0.0 || maxlvl < 0.0) return 209;
if (minlvl > initlvl || minlvl > maxlvl || initlvl > maxlvl) return 225;
if (diam < 0.0 || minvol < 0.0) return 209;
// volume curve supplied
if (strlen(volcurve) > 0)
{
for (i = 1; i <= net->Ncurves; i++)
{
if (strcmp(volcurve, net->Curve[i].ID) == 0)
{
curveIndex = i;
break;
}
}
if (curveIndex == 0) return 206;
curve = &net->Curve[curveIndex];
n = curve->Npts - 1;
if (minlvl < curve->X[0] || maxlvl > curve->X[n]) return 225;
area = (curve->Y[n] - curve->Y[0]) / (curve->X[n] - curve->X[0]);
}
// Tank diameter supplied
else area = PI * diam * diam / 4.0;
// Assign parameters to tank object
net->Node[Tank[j].Node].El = elevation;
Tank[j].A = area / Ucf[ELEV] / Ucf[ELEV];
Tank[j].H0 = elevation + initlvl / Ucf[ELEV];
Tank[j].Hmin = elevation + minlvl / Ucf[ELEV];
Tank[j].Hmax = elevation + maxlvl / Ucf[ELEV];
Tank[j].Vcurve = curveIndex;
Tank[j].Vmin = tankvolume(p, j, Tank[j].Hmin);
Tank[j].V0 = tankvolume(p, j, Tank[j].H0);
Tank[j].Vmax = tankvolume(p, j, Tank[j].Hmax);
return 0;
}
int DLLEXPORT EN_getcoord(EN_Project p, int index, EN_API_FLOAT_TYPE *x,
EN_API_FLOAT_TYPE *y)
/*----------------------------------------------------------------
@@ -3139,7 +3321,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, EN_LinkProperty code,
else v = 1.0;
break;
case EN_STATE:
case EN_PUMP_STATE:
v = hyd->LinkStatus[index];
if (Link[index].Type == EN_PUMP)
@@ -3156,21 +3338,12 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, EN_LinkProperty code,
}
break;
case EN_CONST_POWER:
case EN_PUMP_POWER:
v = 0;
if (Link[index].Type == EN_PUMP)
{
pmp = findpump(net, index);
if (Pump[pmp].Ptype == CONST_HP) v = Link[index].Km; // Power in HP
}
break;
case EN_SPEED:
v = 0;
if (Link[index].Type == EN_PUMP)
{
pmp = findpump(net, index);
v = Link[index].Kc;
if (Pump[pmp].Ptype == CONST_HP) v = Link[index].Km; // Power in HP or KW
}
break;
@@ -3210,25 +3383,25 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, EN_LinkProperty code,
}
break;
case EN_EFFICIENCY:
case EN_PUMP_EFFIC:
getenergy(p, index, &a, &v);
break;
case EN_PRICEPATTERN:
case EN_PUMP_EPAT:
if (Link[index].Type == EN_PUMP)
{
v = (double)Pump[findpump(&p->network, index)].Epat;
}
break;
case EN_HEADCURVE:
case EN_PUMP_HCURVE:
if (Link[index].Type == EN_PUMP)
{
v = (double)Pump[findpump(&p->network, index)].Hcurve;
}
break;
case EN_EFFICIENCYCURVE:
case EN_PUMP_ECURVE:
if (Link[index].Type == EN_PUMP)
{
v = (double)Pump[findpump(&p->network, index)].Ecurve;
@@ -3262,6 +3435,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int code, EN_API_FLOAT_TY
double *LinkSetting = hyd->LinkSetting;
char s;
double r, value = v;
int pumpIndex, patIndex, curveIndex;
if (!p->Openflag) return 102;
if (index <= 0 || index > net->Nlinks) return 204;
@@ -3379,19 +3553,123 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int code, EN_API_FLOAT_TY
}
break;
case EN_LINKPATTERN:
if (Link[index].Type == EN_PUMP)
{
patIndex = (int) (value + 0.5);
if (patIndex <= 0 || patIndex > net->Npats) return 205;
pumpIndex = findpump(&p->network, index);
net->Pump[pumpIndex].Upat = patIndex;
}
break;
case EN_PUMP_ECOST:
if (Link[index].Type == EN_PUMP)
{
if (value < 0.0) return 211;
pumpIndex = findpump(&p->network, index);
net->Pump[pumpIndex].Ecost = value;
}
break;
case EN_PUMP_EPAT:
if (Link[index].Type == EN_PUMP)
{
patIndex = (int)(value + 0.5);
if (patIndex <= 0 || patIndex > net->Npats) return 205;
pumpIndex = findpump(&p->network, index);
net->Pump[pumpIndex].Epat = patIndex;
}
break;
case EN_PUMP_HCURVE:
if (Link[index].Type == EN_PUMP)
{
return EN_setheadcurveindex(p, index, (int)(value + 0.5));
}
break;
case EN_PUMP_POWER:
if (Link[index].Type == EN_PUMP)
{
if (value <= 0.0) return 211;
pumpIndex = findpump(&p->network, index);
net->Pump[pumpIndex].Ptype = CONST_HP;
net->Pump[pumpIndex].Hcurve = 0;
net->Link[index].Km = v;
updatepumpparams(p, pumpIndex);
net->Pump[pumpIndex].R /= Ucf[POWER];
net->Pump[pumpIndex].Q0 /= Ucf[FLOW];
net->Pump[pumpIndex].Qmax /= Ucf[FLOW];
net->Pump[pumpIndex].Hmax /= Ucf[HEAD];
}
break;
case EN_PUMP_ECURVE:
if (Link[index].Type == EN_PUMP)
{
curveIndex = (int)(v + 0.5);
if (curveIndex <= 0 || curveIndex > net->Ncurves) return 205;
pumpIndex = findpump(&p->network, index);
net->Pump[pumpIndex].Ecurve = curveIndex;
}
break;
default:
return 251;
}
return 0;
}
int DLLEXPORT EN_setpipedata(EN_Project p, int index, EN_API_FLOAT_TYPE length,
EN_API_FLOAT_TYPE diam, EN_API_FLOAT_TYPE rough, EN_API_FLOAT_TYPE mloss)
/*----------------------------------------------------------------
** Input: index = pipe link index
** length = pipe length
** diam = pipe diameter
** rough = pipe roughness coefficient
** mloss = minor loss coefficient
** Output: none
** Returns: error code
** Purpose: sets several properties for a pipe link.
**----------------------------------------------------------------
*/
{
Network *net = &p->network;
Slink *Link = net->Link;
double *Ucf = p->Ucf;
double diameter = diam;
// Check that pipe exists
if (!p->Openflag) return 102;
if (index <= 0 || index > net->Nlinks) return 204;
if (Link[index].Type > EN_PIPE) return 0;
// Check for valid parameters
if (length <= 0.0 || diam <= 0.0 || rough <= 0.0 || mloss < 0.0) return 211;
// Assign parameters to pipe
Link[index].Len = length / Ucf[ELEV];
diameter /= Ucf[DIAM];
Link[index].Diam = diameter;
Link[index].Kc = rough;
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);
return 0;
}
/********************************************************************
Pump Functions
********************************************************************/
int DLLEXPORT EN_getpumptype(EN_Project p, int index, int *type)
int DLLEXPORT EN_getpumptype(EN_Project p, int index, int *type) //2.1
/*----------------------------------------------------------------
** Input: index = index of a pump link
** Output: type = type of pump characteristic curve (see EN_PumpType)
@@ -3414,7 +3692,7 @@ int DLLEXPORT EN_getpumptype(EN_Project p, int index, int *type)
return 0;
}
int DLLEXPORT EN_getheadcurveindex(EN_Project p, int index, int *curveindex)
int DLLEXPORT EN_getheadcurveindex(EN_Project p, int index, int *curveindex) //2.1
/*----------------------------------------------------------------
** Input: index = index of a pump link
** Output: curveindex = index of a pump's characteristic curve
@@ -3480,7 +3758,7 @@ int DLLEXPORT EN_setheadcurveindex(EN_Project p, int index, int curveindex)
pump->Hmax /= Ucf[HEAD];
// Designate the newly assigned curve as being a Pump Curve
p->network.Curve[curveindex].Type = P_CURVE;
p->network.Curve[curveindex].Type = PUMP_CURVE;
return 0;
}
@@ -3729,7 +4007,7 @@ int DLLEXPORT EN_addcurve(EN_Project p, char *id)
curve = &net->Curve[n];
strcpy(curve->ID, id);
curve->Npts = 1;
curve->Type = G_CURVE;
curve->Type = GENERIC_CURVE;
curve->X = (double *)calloc(1, sizeof(double));
curve->Y = (double *)calloc(1, sizeof(double));
if (curve->X == NULL) err = 1;

View File

@@ -288,6 +288,20 @@ int DLLEXPORT ENsetnodevalue(int index, int code, EN_API_FLOAT_TYPE v)
return EN_setnodevalue(_defaultProject, index, code, v);
}
int DLLEXPORT ENsetjuncdata(int index, EN_API_FLOAT_TYPE elev, EN_API_FLOAT_TYPE dmnd,
char *dmndpat)
{
return EN_setjuncdata(_defaultProject, index, elev, dmnd, dmndpat);
}
int DLLEXPORT ENsettankdata(int index, EN_API_FLOAT_TYPE elev, EN_API_FLOAT_TYPE initlvl,
EN_API_FLOAT_TYPE minlvl, EN_API_FLOAT_TYPE maxlvl, EN_API_FLOAT_TYPE diam,
EN_API_FLOAT_TYPE minvol, char *volcurve)
{
return EN_settankdata(_defaultProject, index, elev, initlvl, minlvl, maxlvl,
diam, minvol, volcurve);
}
int DLLEXPORT ENgetcoord(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y)
{
return EN_getcoord(_defaultProject, index, x, y);
@@ -412,6 +426,13 @@ int DLLEXPORT ENsetlinkvalue(int index, int code, EN_API_FLOAT_TYPE v)
return EN_setlinkvalue(_defaultProject, index, code, v);
}
int DLLEXPORT ENsetpipedata(int index, EN_API_FLOAT_TYPE length, EN_API_FLOAT_TYPE diam,
EN_API_FLOAT_TYPE rough, EN_API_FLOAT_TYPE mloss)
{
return EN_setpipedata(_defaultProject, index, length, diam, rough, mloss);
}
/********************************************************************
Pump Functions

View File

@@ -7,7 +7,7 @@ Description: reads and interprets network data from an EPANET input file
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 12/15/2018
Last Updated: 01/01/2019
******************************************************************************
*/
@@ -381,7 +381,7 @@ int updatepumpparams(Project *pr, int pumpindex)
curveindex = pump->Hcurve;
if (curveindex == 0) return 226;
curve = &net->Curve[curveindex];
curve->Type = P_CURVE;
curve->Type = PUMP_CURVE;
npts = curve->Npts;
// Generic power function curve

View File

@@ -7,7 +7,7 @@ Description: parses network data from a line of an EPANET input file
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 12/15/2018
Last Updated: 01/01/2019
******************************************************************************
*/
@@ -205,7 +205,7 @@ int tankdata(Project *pr)
tmplist = getlistitem(parser->Tok[7], parser->Curvelist);
if (tmplist == NULL) return setError(parser, 7, 206);
curve = tmplist->i;
net->Curve[curve].Type = V_CURVE;
net->Curve[curve].Type = VOLUME_CURVE;
}
if (initlevel < 0.0) return setError(parser, 2, 209);
if (minlevel < 0.0) return setError(parser, 3, 209);
@@ -508,7 +508,7 @@ int valvedata(Project *pr)
tmplist = getlistitem(parser->Tok[5], parser->Curvelist);
if (tmplist == NULL) return setError(parser, 5, 206);
setting = tmplist->i;
net->Curve[tmplist->i].Type = H_CURVE;
net->Curve[tmplist->i].Type = HLOSS_CURVE;
status = OPEN;
}
else if (!getfloat(parser->Tok[5], &setting)) return setError(parser, 5, 202);
@@ -1391,7 +1391,7 @@ int energydata(Project *pr)
listitem = getlistitem(parser->Tok[n - 1], parser->Curvelist);
if (listitem == NULL) return setError(parser, n - 1, 206);
Pump[j].Ecurve = listitem->i;
net->Curve[listitem->i].Type = E_CURVE;
net->Curve[listitem->i].Type = EFFIC_CURVE;
}
return 0;
}

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 12/15/2018
Last Updated: 01/01/2019
******************************************************************************
*/
@@ -354,7 +354,7 @@ int allocdata(Project *pr)
for (n = 0; n <= pr->parser.MaxCurves; n++)
{
pr->network.Curve[n].Npts = 0;
pr->network.Curve[n].Type = G_CURVE;
pr->network.Curve[n].Type = GENERIC_CURVE;
pr->network.Curve[n].X = NULL;
pr->network.Curve[n].Y = NULL;
}

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 12/15/2018
Last Updated: 01/01/2019
******************************************************************************
*/
@@ -157,11 +157,11 @@ typedef enum {
} QualType;
typedef enum {
V_CURVE, // volume curve
P_CURVE, // pump curve
E_CURVE, // efficiency curve
H_CURVE, // head loss curve
G_CURVE // general\default curve
VOLUME_CURVE, // volume curve
PUMP_CURVE, // pump curve
EFFIC_CURVE, // efficiency curve
HLOSS_CURVE, // head loss curve
GENERIC_CURVE // generic curve
} CurveType;
typedef enum {

View File

@@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE(test_net_builder)
BOOST_REQUIRE(error == 0);
error = EN_setpattern(ph, 1, P, 12);
BOOST_REQUIRE(error == 0);
error = EN_setoption(ph, EN_DEMANDDEFPAT, 1);
error = EN_setoption(ph, EN_DEFDEMANDPAT, 1);
BOOST_REQUIRE(error == 0);
for (i = 0; i < 9; i++)
{

View File

@@ -0,0 +1,114 @@
// Test of EPANET's Network Building Functions
//
// This is a test of the API functions EN_setjuncdata, EN_settankdata & EN_setpipedata
//
#define _CRT_SECURE_NO_DEPRECATE
//#define NO_BOOST
#ifndef NO_BOOST
#define BOOST_TEST_MODULE "toolkit"
#include <boost/test/included/unit_test.hpp>
#endif
#include <iostream>
#include <string>
#include "epanet2_2.h"
#define DATA_PATH_INP "./net1.inp"
#define DATA_PATH_RPT "./test.rpt"
#define DATA_PATH_OUT "./test.out"
#ifdef NO_BOOST
#define BOOST_REQUIRE(x) (((x)) ? cout << "\nPassed at line " << __LINE__ : cout << "\nFailed at line " << __LINE__ )
#endif
using namespace std;
#ifndef NO_BOOST
BOOST_AUTO_TEST_SUITE (test_toolkit)
BOOST_AUTO_TEST_CASE(test_setlinktype)
{
#else
int main(int argc, char *argv[])
{
#endif
int index;
char id[EN_MAXID+1];
float p1_1, p2_1, p1_2, p2_2;
float q1_1, q2_1, q1_2, q2_2;
// Create & initialize a project
EN_Project ph = NULL;
EN_createproject(&ph);
EN_init(ph, "", "", EN_GPM, EN_HW);
// Build a network
EN_addnode(ph, "N1", EN_JUNCTION);
EN_addnode(ph, "N2", EN_JUNCTION);
EN_addnode(ph, "N3", EN_RESERVOIR);
EN_addnode(ph, "N4", EN_TANK);
EN_addlink(ph, "L1", EN_PUMP, "N3", "N1");
EN_addlink(ph, "L2", EN_PIPE, "N1", "N3");
EN_addlink(ph, "L3", EN_PIPE, "N1", "N2");
EN_addcurve(ph, "C1");
// Set network data using the new helper functions
EN_setcurvevalue(ph, 1, 1, 1500, 250);
EN_setjuncdata(ph, 1, 700, 500, "");
EN_setjuncdata(ph, 2, 710, 500, "");
EN_setnodevalue(ph, 3, EN_ELEVATION, 800);
EN_settankdata(ph, 4, 850, 120, 100, 150, 50.5, 0, "");
EN_setlinkvalue(ph, 1, EN_PUMP_HCURVE, 1);
EN_setpipedata(ph, 2, 10560, 12, 100, 0);
EN_setpipedata(ph, 3, 5280, 14, 100, 0);
// Run hydraulics
EN_solveH(ph);
// Save results
EN_getnodevalue(ph, 1, EN_PRESSURE, &p1_1);
EN_getnodevalue(ph, 2, EN_PRESSURE, &p2_1);
EN_getlinkvalue(ph, 1, EN_FLOW, &q1_1);
EN_getlinkvalue(ph, 2, EN_FLOW, &q2_1);
// Save project
EN_saveinpfile(ph, "test2.inp");
// Close project
EN_close(ph);
// Open the saved project file
EN_open(ph, "test2.inp", "", "");
// Run hydraulics
EN_solveH(ph);
// Save these new results
EN_getnodevalue(ph, 1, EN_PRESSURE, &p1_2);
EN_getnodevalue(ph, 2, EN_PRESSURE, &p2_2);
EN_getlinkindex(ph, "L1", &index);
EN_getlinkvalue(ph, index, EN_FLOW, &q1_2);
EN_getlinkindex(ph, "L2", &index);
EN_getlinkvalue(ph, index, EN_FLOW, &q2_2);
// Display old & new results
cout << "\n Node N1 Pressure: " << p1_1 << " " << p1_2;
cout << "\n Node N2 Pressure: " << p2_1 << " " << p2_2;
cout << "\n Link L1 Flow: " << q1_1 << " " << q1_2;
cout << "\n Link L2 Flow: " << q2_1 << " " << q2_2;
// Compare old & new results
BOOST_REQUIRE(p1_1 == p1_2);
BOOST_REQUIRE(p2_1 == p2_2);
BOOST_REQUIRE(q1_1 == q1_2);
BOOST_REQUIRE(q2_1 == q2_2);
// Close project
EN_close(ph);
EN_deleteproject(&ph);
}
#ifndef NO_BOOST
BOOST_AUTO_TEST_SUITE_END()
#endif

View File

@@ -85,6 +85,7 @@ EXPORTS
ENsetelseaction = _ENsetelseaction@20
ENsetflowunits = _ENsetflowunits@4
ENsetheadcurveindex = _ENsetheadcurveindex@8
ENsetjuncdata = _ENsetjuncdata@16
ENsetlinkid = _ENsetlinkid@8
ENsetlinknodes = _ENsetlinknodes@12
ENsetlinktype = _ENsetlinktype@12
@@ -94,6 +95,7 @@ EXPORTS
ENsetoption = _ENsetoption@8
ENsetpattern = _ENsetpattern@12
ENsetpatternvalue = _ENsetpatternvalue@12
ENsetpipedata = _ENsetpipedata@20
ENsetpremise = _ENsetpremise@36
ENsetpremiseindex = _ENsetpremiseindex@12
ENsetpremisestatus = _ENsetpremisestatus@12
@@ -102,6 +104,7 @@ EXPORTS
ENsetreport = _ENsetreport@4
ENsetrulepriority = _ENsetrulepriority@8
ENsetstatusreport = _ENsetstatusreport@4
ENsettankdata = _ENsettankdata@32
ENsetthenaction = _ENsetthenaction@20
ENsettimeparam = _ENsettimeparam@8
ENsolveH = _ENsolveH@0