OpenWaterAnalytics / EPANET

The Water Distribution System Hydraulic and Water Quality Analysis Toolkit
MIT License
279 stars 204 forks source link

BUG? Add Simple Control Valve #677

Closed gustavods14 closed 2 years ago

gustavods14 commented 2 years ago

I want to add simple control from toolkit EPANET v 2.2 using VB.net. Bbut how i can add control valve closed or open?, for example: "LINK VALVE-1 CLOSED AT TIME 0" "LINK VALVE-1 OPEN AT TIME 1"

There is a constant (Rule status types) in Epanet2: EN_R_IS_OPEN = 1 and EN_R_IS_CLOSED=2 .... but, when i write the code:

ENsetcontrol(2, 2, 3, EN_R_IS_CLOSED, 0, 0)
ENsetcontrol(1, 2, 3, EN_R_IS_OPEN, 0, 0)

... and Open the INP file, Controls looks like: "LINK VALVE-1 2.000 AT TIME 0" "LINK VALVE-1 1.000 AT TIME 1"

Ostoveni commented 2 years ago

Hello Gustavo, Add "ByRef" to the last parameter of the function "ENaddcontrol" Use zero instead of "EN_R_IS_CLOSED". Use one instead of "EN_R_IS_OPEN". "EN_R_IS_CLOSED" and "EN_R_IS_OPEN" Used for rules

Ostoveni commented 2 years ago

Hi, @eladsal @LRossman With my friend Gustavo we have found, apparently, a bug in the simple control rules. After writing the lines of code:

ENopen(FileInput, "", "") ENaddcontrol(EN_TIMER, 13, 1340.75, 0, 3600, 3) ENaddcontrol(EN_TIMER, 13, 800.75, 0, 7200, 4) ENaddcontrol(EN_TIMER, 13, 1, 0, 10800, 5) ------> '1 = Open ENsaveinpfile(FileOutput) ENclose()

And generate an INP file, and after running a simulation, Epanet interprets the value of 1 as a setting when in fact the valve is asked to be open. Is it possible that it is an error?. If it is an error, I think a solution is to write "Open" instead of 1 and "Closed" instead of 0.

LRossman commented 2 years ago

You can't use the ENaddcontroland ENsetcontrolAPI functions to fix the status of a pressure or flow control valve to fully open or fully closed (thus making the valve non-active). Those functions can only adjust the valve's pressure or flow setting. This should have been explained more clearly in the Toolkit documentation.

Here are two ways to set a control valve's status to OPEN or CLOSED at a particular point in time (that corresponds to a whole number of hydraulic time steps):

  1. Use a rule to do so (e.g.)
   ENaddrule ("RULE Link13_Timer\nIF SYSTEM TIME = 10800\nTHEN LINK 13 STATUS IS OPEN")
  1. Add code in the ENrunH loop to do what the above rule does:
    long t = 0, tstep;
    do {
        if (t == 10800) then
            ENsetlinkvalue(13, EN_STATUS, EN_OPEN);
        ENrunH(&t);
        ENnextH(&tstep);
    } while (tstep > 0);    
Ostoveni commented 2 years ago

Thanks @LRossman

gustavods14 commented 2 years ago

Thanks @Ostoveni @LRossman !

samhatchett commented 2 years ago

closing as resolved