OpenWaterAnalytics / EPANET

The Water Distribution System Hydraulic and Water Quality Analysis Toolkit
MIT License
273 stars 203 forks source link

EN_addcontrol and EN_setcontrol unable to assign a fixed status to a valve #730

Closed LRossman closed 1 year ago

LRossman commented 1 year ago

This issue was previously identified in #677 which was closed but never completely resolved.

The EN_addcontrol and EN_setcontrol API functions are unable to set the status of a FCV, PRV, or PSV to be fixed OPENor CLOSED. The functions only accept a numerical value for the flow or pressure setting of these types of valves while assigning their status to ACTIVE. This prohibits the API from building a model that could mimic an EPANET .inp file where the [CONTROLS] section has entries that assign a fixed status to such valves.

One possible fix would be to add an additional Status argument to these functions (as well as the EN_getcontrol function) so that a valve's status could be fixed OPENor CLOSED. Another possibility is to change the existing Setting argument to be a character string instead of a double which the functions could then interpret as either a fixed status or numerical setting. The downside of both options is that they would break backward compatibility.

LRossman commented 1 year ago

An alternative that preserves backward compatibility is to #define two new constants, EN_SET_CLOSED as -1e10 and EN_SET_OPEN as +1e10, to use as the setting argument to EN_addcontrol andEN_setcontrol to indicate that a valve has a fixed setting (since it's highly unlikely that someone would use these particular values for an actual valve flow or pressure setting).

LRossman commented 1 year ago

This issue has been addressed with PR #732 and can be closed now.