Skip to content

Commit

Permalink
Merge pull request #831 from OpenWaterAnalytics/dev-tags
Browse files Browse the repository at this point in the history
Adds EN_gettag and EN_settag functions to the Toolkit
  • Loading branch information
LRossman authored Feb 24, 2025
2 parents c8db9c1 + f37e493 commit 7947354
Show file tree
Hide file tree
Showing 22 changed files with 398 additions and 107 deletions.
148 changes: 105 additions & 43 deletions ReleaseNotes2_3.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,132 @@

This document describes the changes and updates that have been made in version 2.3 of EPANET.

- The check for at least two nodes, one tank/reservoir and no unconnected junction nodes was moved from `EN_open` to `EN_openH` and `EN_openQ` so that partial network data files could be opened by the toolkit.
### New Features

- A `EN_setcurvetype` function was added to allow API clients to set a curve's type (e.g., `EN_PUMP_CURVE,` `EN_VOLUME_CURVE,` etc.).

- A `EN_setvertex` function was added to allow API clients to change the coordinates of a single link vertex.

- Support has been added for FAVAD (Fixed And Variable Area Discharge) modeling of pipe leaks:
- A new `[LEAKAGE]` section has been added to the input file format where each line contains the ID name of a pipe, its leak area in sq. mm per 100 length units, and its leak expansion rate in sq. mm per unit of pressure head.
- `EN_LEAK_AREA` and `EN_LEAK_EXPAN` can be used with the functions `EN_getlinkvalue` and `EN_setlinkvalue` to retrieve and assign values for a pipe's leak area and expansion properties.
- `EN_LINK_LEAKAGE` can be used with `EN_getlinkvalue` to retrieve a pipe's leakage rate at a given point in time.
- `EN_LEAKAGEFLOW` can be used with `EN_getnodevalue` to retrieve the leakage demand generated at a node from all its connecting pipes at a given point in time.
- `EN_LEAKAGELOSS` can be used with `EN_getstatistic` to retrieve the the total leakage loss in the system at a given point in time as a percentage of total flow entering the system.

- Support has been added for reading the `[TAGS]` section of an EPANET input file. In addition:
- A newly added `EN_settag` function will assign a Tag to a node or link.
- A newly added `EN_gettag` function will retrieve a node or link's Tag.
- The exisitng `EN_saveinpfile` will include saving all node and link tags to file.
- A new Flow Balance Report has been added to end of a simulation run's Status Report that lists the various components of the system's total inflow and outflow over the simulation period. It also displays the ratio of outflow to inflow as a check on flow continuity.

- A new type of valve, a Positional Control Valve (PCV), was added. It uses a valve characteristic curve to relate its loss coefficient to a percentage open setting (parameter - `EN_PCV`).

- `EN_VALVE_CURVE` can now be used with the `EN_getcurvetype` and `EN_setcurvetype` to get or set the valve position curve.

- A new set of functions has been added to get information about upcoming time step events. Users will now see what type of event is going to cause the end of a time step to occur. See `EN_timetonextevent`.

- A new set of functions has been added to allow users to set a reporting callback function. The user-supplied function will receive all output normally directed to the report file.

- A `EN_EMITBACKFLOW` option was added that either allows emitters to have reverse flow through them (the default) or not.

- The functions `EN_getnodevalue` and `EN_getlinkvalue` now include the options `EN_NODE_INCONTROL` and `EN_LINK_INCONTROL` to determine whether a node or link appears in any simple or rule-based control.

- `EN_SET_CLOSED` and `EN_SET_OPEN` constants were added that can be used with `EN_setcontrol` to fix the status of pipes and valves to completely closed or completely open.

- `EN_STATUS_REPORT` can now be used with `EN_getoption` and `EN_setoption` to get or set the type of status report that EPANET will generate (`EN_NO_REPORT`, `EN_NORMAL_REPORT` or `EN_FULL_REPORT`).

- `EN_PRESS_UNITS` can now be used with `EN_getoption` and `EN_setoption` to get or set the pressure unit used in EPANET.

- The following constants can be used with EN_getnodevalue to retrieve the components of a node's total demand at a given point in time:
- `EN_FULLDEMAND` - the consumer demand requested
- `EN_DEMANDFLOW` - the consumer demand delivered
- `EN_DEMANDDEFICIT` - the difference between the consumer demand requested and delivered
- `EN_EMITTERFLOW` - the node's emitter flow
- `EN_LEAKAGEFLOW` - the node's leakage flow
- `EN_DEMAND` - the sum of the node's consumer demand, emitter flow, and leakage flow

- Additional API functions for enabling/disabling controls and rules were added (`EN_getcontrolenabled`, `EN_setcontrolenabled`, `EN_getruleenabled`, `EN_setruleenabled`). A new keyword `DISABLED` is added to the end of a control or rule statement in an EPANET input file to indicate that the control is disabled.

- The `EN_openX` function has been added to enable the opening of input files with formatting errors through the API. This allows users to continue using toolkit functions even when such errors are present.

- The `EN_getnodesvalues` and `EN_getlinksvalues` were added to retrieve a property value for all nodes or links in the network.

- Support was added for cubic meters per second (`EN_CMS`) flow units.

- A header file for binding C# to the Toolkit has been added.

- Support was added for Conan dependency manager.

### Feature Updates

- The check for at least two nodes, one tank/reservoir and no unconnected junction nodes was moved from `EN_open` to `EN_openH` and `EN_openQ` so that partial network data files could be opened by the toolkit.

- The indices of a General Purpose Valve (GPV) and a Positional Control Valve (PCV) were added to the list of editable Link Properties using the symbolic constant names `EN_GPV_CURVE` and `EN_PCV_CURVE`, respectively.

- The `EN_getlinkvalue` and `EN_setlinkvalue` functions were updated to get and set the values of `EN_GPV_CURVE` and `EN_PCV_CURVE`.

- Negative pressure values for `EN_SETTING` are now permitted in the `EN_setlinkvalue` function.

- The `EN_STARTTIME` parameter was added into the `EN_settimeparam` function.

- A `EN_DEMANDPATTERN` parameter was added as the index of the default time pattern used by demands with no specific pattern assigned. It can be set or retrieved with the `EN_setoption` and `EN_getoption` functions, respectively, and is saved to the file when the `EN_saveinpfile` function is called.

- The `EN_getaveragepatternvalue` function will now accept a pattern index of zero which represents the constant pattern assigned to junction demands by default.
- The adjustment of a tank's minimum volume (`Vmin`) when its parameters are changed using `EN_setnodevalue` or `EN_settankdata` has been corrected.
- A pump whose status is set to CLOSED in the input file now also has its speed setting set to zero which allows a simple pressure control to activate the pump correctly.
- A failure to raise an error condition for a non-positive pipe roughness in the input file has been fixed.
- The calculation of head loss gradient for low flow conditions was corrected.

- Improved updating and convergence tests were added to pressure-dependent demand analysis.

- Improved checks to prevent outflow from empty tanks or inflow to full (non-overflow) tanks, including the case where a link is connected to a pair of tanks, were added.

- The `EN_INITSETTING` option in function `EN_getlinkvalue` will now return `EN_MISSING` for a valve whose initial status is fixed to `EN_OPEN` or `EN_CLOSED`.

- A new error code `263 - node is not a tank` is returned when `EN_settankdata` or `EN_setnodevalue` attempts to set a tank-only parameter for a non-tank node.

- Errors in node and link vertex coordinates are now ignored when reading an EPANET input file.

- Only non-zero demands are now included in the `[DEMANDS]` section of the input file produced by `EN_saveinpfile`.

- Setting the demand multiplier within the `[DEMANDS]` section of INP has been depreciated, please use `DEMAND MULTIPLIER` inside `[OPTIONS]` instead.

- Continuous barrier functions were added to constrain emitter flows to allowable values.

- The CI regression test protocol was modified by:
- changing the absolute tolerance used to compare the closeness of test results to benchmark values from 0 to 0.0001
- dropping the "correct decimal digits" test
- dropping the check for identical status report content since it prevents accepting code changes that produce more accurate solutions in fewer iterations.

### Bug Fixes

- The adjustment of a tank's minimum volume (`Vmin`) when its parameters are changed using `EN_setnodevalue` or `EN_settankdata` has been corrected.

- A pump whose status is set to CLOSED in the input file now also has its speed setting set to zero which allows a simple pressure control to activate the pump correctly.

- A failure to raise an error condition for a non-positive pipe roughness in the input file has been fixed.

- The calculation of head loss gradient for low flow conditions was corrected.

- A possible loss of network connectivity when evaluating a Pressure Sustaining Valve was prevented.

- Having the implied loss coefficient for an active Flow Control Valve be less than its fully opened value was prevented.
- A new type of valve, a Positional Control Valve (PCV), was added. It uses a valve characteristic curve to relate its loss coefficient to a percentage open setting (parameter - `EN_PCV`).
- `EN_VALVE_CURVE` can now be used with the `EN_getcurvetype` and `EN_setcurvetype` to get or set the valve position curve.
- A new set of functions has been added to get information about upcoming time step events. Users will now see what type of event is going to cause the end of a time step to occur. See `EN_timetonextevent`.
- A new set of functions has been added to allow users to set a reporting callback function. The user-supplied function will receive all output normally directed to the report file.
- A `EN_EMITBACKFLOW` option was added that either allows emitters to have reverse flow through them (the default) or not.

- An incorrect tank elevation value set using `EN_settankdata` with SI units has been fixed.
- The `EN_INITSETTING` option in function `EN_getlinkvalue` will now return `EN_MISSING` for a valve whose initial status is fixed to `EN_OPEN` or `EN_CLOSED`.
- The functions `EN_getnodevalue` and `EN_getlinkvalue` now include the options `EN_NODE_INCONTROL` and `EN_LINK_INCONTROL` to determine whether a node or link appears in any simple or rule-based control.

- An error is no longer raised when a minor loss coefficient of zero is assigned in `EN_setlinkvalue(ph, index, EN_MINORLOSS, 0)`.

- The incorrect display of unconnected nodes has been fixed.
- A header file for binding C# to the Toolkit has been added.
- A new error code `263 - node is not a tank` is returned when `EN_settankdata` or `EN_setnodevalue` attempts to set a tank-only parameter for a non-tank node.

- The function `EN_saveinpfile` was corrected for simple controls on GPV's by saving their status instead of the index of their head loss curve.
- Support was added for Conan dependency manager.

- The internal Qualflag variable is now adjusted when an EPANET input file has a QUALITY option not equal to NONE and a simulation duration of zero.
- Support was added for cubic meters per second (`EN_CMS`) flow units.

- An EPANET input file with simple timer control that has more than 9 input tokens no longer results in an incorrect hour setting.
- Errors in node and link vertex coordinates are now ignored when reading an EPANET input file.
- Only non-zero demands are now included in the `[DEMANDS]` section of the input file produced by `EN_saveinpfile`.
- `EN_SET_CLOSED` and `EN_SET_OPEN` constants were added that can be used with `EN_setcontrol` to fix the status of pipes and valves to completely closed or completely open.
- `EN_EMITTERFLOW` can now be used with `EN_getnodevalue` to retrieve a node's emitter flow rate.
- `EN_STATUS_REPORT` can now be used with `EN_getoption` and `EN_setoption` to get or set the type of status report that EPANET will generate (`EN_NO_REPORT`, `EN_NORMAL_REPORT` or `EN_FULL_REPORT`).

- A possible parser error that could result in a Trace Node ID in an input file not being recognized was fixed.
- Additional API functions for enabling/disabling controls and rules were added (`EN_getcontrolenabled`, `EN_setcontrolenabled`, `EN_getruleenabled`, `EN_setruleenabled`).

- Updated the internal function `getclosedlink` in report.c to use a loop instead of recursion to prevent a stack overflow during the analysis of very large disconnections.
- Setting the demand multiplier within the `[DEMANDS]` section of INP has been depreciated, please use `DEMAND MULTIPLIER` inside `[OPTIONS]` instead.
- `EN_PRESS_UNITS` can now be used with `EN_getoption` and `EN_setoption` to get or set the pressure unit used in EPANET.
- Continuous barrier functions were added to constrain emitter flows to allowable values.
- The `EN_openX` function has been added to enable the opening of input files with formatting errors through the API. This allows users to continue using toolkit functions even when such errors are present.
- The `EN_getnodesvalues` and `EN_getlinksvalues` were added to retrieve a property value for all nodes or links in the network.
- Fixed a bug in EN_setnodevalue with EN_EMITTER option that could cause NaN results.
- Support has been added for FAVAD (Fixed And Variable Area Discharge) modeling of pipe leaks:
- A new `[LEAKAGE]` section has been added to the input file format where each line contains the ID name of a pipe, its leak area in sq. mm per 100 length units, and its leak expansion rate in sq. mm per unit of pressure head.
- `EN_LEAK_AREA` and `EN_LEAK_EXPAN` can be used with the functions `EN_getlinkvalue` and `EN_setlinkvalue` to retrieve and assign values for a pipe's leak area and expansion properties.
- `EN_LINK_LEAKAGE` can be used with `EN_getlinkvalue` to retrieve a pipe's leakage rate at a given point in time.
- `EN_LEAKAGEFLOW` can be used with `EN_getnodevalue` to retrieve the leakage demand generated at a node from all its connecting pipes at a given point in time.
- `EN_LEAKAGELOSS` can be used with `EN_getstatistic` to retrieve the the total leakage loss in the system at a given point in time as a percentage of total flow entering the system.
- A new Flow Balance Report has been added to end of a simulation run's Status Report that lists the various components of the system's total inflow and outflow over the simulation period. It also displays the ratio of outflow to inflow as a check on flow continuity.
- The following constants can be used with EN_getnodevalue to retrieve the components of a node's total demand at a given point in time:
- `EN_FULLDEMAND` - the consumer demand requested
- `EN_DEMANDFLOW` - the consumer demand delivered
- `EN_DEMANDDEFICIT` - the difference between the consumer demand requested and delivered
- `EN_EMITTERFLOW` - the node's emitter flow
- `EN_LEAKAGEFLOW` - the node's leakage flow
- `EN_DEMAND` - the sum of the node's consumer demand, emitter flow, and leakage flow

- Fixed a bug in EN_setnodevalue with EN_EMITTER option that could cause NaN results.

- A failure to close a temporary hydraulics file between successive simulations of an opened project was fixed.

- Corrupting the index of a water quality Trace Node when adding or deleting a node was fixed.
7 changes: 4 additions & 3 deletions include/epanet2.bas
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Attribute VB_Name = "Module1"
'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT
'(EPANET2.DLL)

'Last updated on 06/23/2024
'Last updated on 02/14/2025

' These are codes used by the DLL functions
Public Const EN_ELEVATION = 0 ' Node parameters
Expand Down Expand Up @@ -297,8 +297,8 @@ Public Const EN_TRUE = 1 ' boolean true
Declare Function ENclose Lib "epanet2.dll" () As Long
Declare Function ENgetcomment Lib "epanet2.dll" (ByVal ObjectType As Long, ByVal index As Long, ByVal comment As String) As Long
Declare Function ENsetcomment Lib "epanet2.dll" (ByVal ObjectType As Long, ByVal index As Long, ByVal comment As String) As Long


Declare Function ENgettag Lib "epanet2.dll" (ByVal ObjectType As Long, ByVal index As Long, ByVal tag As String) As Long
Declare Function ENsettag Lib "epanet2.dll" (ByVal ObjectType As Long, ByVal index As Long, ByVal tag As String) As Long
'Hydraulic Analysis Functions
Declare Function ENsolveH Lib "epanet2.dll" () As Long
Declare Function ENsaveH Lib "epanet2.dll" () As Long
Expand Down Expand Up @@ -408,6 +408,7 @@ Public Const EN_TRUE = 1 ' boolean true
Declare Function ENsetpatternvalue Lib "epanet2.dll" (ByVal index As Long, ByVal period As Long, ByVal value As Single) As Long
Declare Function ENgetaveragepatternvalue Lib "epanet2.dll" (ByVal index As Long, value As Single) As Long
Declare Function ENsetpattern Lib "epanet2.dll" (ByVal index As Long, values As Any, ByVal len_ As Long) As Long
Declare Function ENloadpatternfile Lib "epanet2.dll" (ByVal filename As String, ByVal id As String) As Long

'Data Curve Functions
Declare Function ENaddcurve Lib "epanet2.dll" (ByVal id As String) As Long
Expand Down
16 changes: 15 additions & 1 deletion include/epanet2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Runtime.InteropServices;

//epanet2.cs[By Oscar Vegas]
//Last updated on 06/23/2024
//Last updated on 02/14/2025

//Declarations of functions in the EPANET PROGRAMMERs TOOLKIT
//(EPANET2.DLL) for use with C#
Expand Down Expand Up @@ -303,7 +303,18 @@ public static class Epanet

[DllImport(EPANETDLL, EntryPoint = "ENsettitle")]
public static extern int ENsettitle(string titleline1, string titleline2, string titleline3);

[DllImport(EPANETDLL, EntryPoint = "ENgetcomment")]
public static extern int ENgetcomment(int type, int index, string comment);

[DllImport(EPANETDLL, EntryPoint = "ENsetcomment")]
public static extern int ENsetcomment(int type, int index, string comment);

[DllImport(EPANETDLL, EntryPoint = "ENgettag")]
public static extern int ENgettag(int type, int index, string tag);

[DllImport(EPANETDLL, EntryPoint = "ENsettag")]
public static extern int ENsettag(int type, int index, string tag);
[DllImport(EPANETDLL, EntryPoint = "ENsaveinpfile")]
public static extern int ENsaveinpfile(string filename);

Expand Down Expand Up @@ -600,6 +611,9 @@ public static class Epanet
[DllImport(EPANETDLL, EntryPoint = "ENsetpattern")]
public static extern int ENsetpattern(int index, ref float[] values, int len);

[DllImport(EPANETDLL, EntryPoint = "ENloadpatternfile")]
public static extern int ENdeletepattern(string filename, string id);


//Data Curve Functions
[DllImport(EPANETDLL, EntryPoint = "ENaddcurve")]
Expand Down
5 changes: 4 additions & 1 deletion include/epanet2.def
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ EXPORTS
ENgetruleenabled = _ENgetruleenabled@8
ENgetruleID = _ENgetruleID@8
ENgetstatistic = _ENgetstatistic@8
ENgettag = _ENgettag@12
ENgetthenaction = _ENgetthenaction@20
ENgettimeparam = _ENgettimeparam@8
ENgettitle = _ENgettitle@12
Expand All @@ -76,7 +77,8 @@ EXPORTS
ENgetvertexcount = _ENgetvertexcount@8
ENinit = _ENinit@16
ENinitH = _ENinitH@4
ENinitQ = _ENinitQ@4
ENinitQ = _ENinitQ@4
ENloadpatternfile = _ENloadpatternfile@8
ENnextH = _ENnextH@4
ENnextQ = _ENnextQ@4
ENopen = _ENopen@12
Expand Down Expand Up @@ -126,6 +128,7 @@ EXPORTS
ENsetruleenabled = _ENsetruleenabled@8
ENsetrulepriority = _ENsetrulepriority@8
ENsetstatusreport = _ENsetstatusreport@4
ENsettag = _ENsettag@12
ENsettankdata = _ENsettankdata@32
ENsetthenaction = _ENsetthenaction@20
ENsettimeparam = _ENsettimeparam@8
Expand Down
Loading

0 comments on commit 7947354

Please sign in to comment.