From d7d0472947449359301828c7416548c1f7ea7dd9 Mon Sep 17 00:00:00 2001 From: jamesuber Date: Sun, 25 Aug 2013 23:57:15 -0400 Subject: [PATCH] ENsetbasedemand() and ENsetnodevalue() - added ENsetbasedemand to allow changes to the base demands for each demand category. Changed behavior of ENsetnodevalue when used with EN_TANKLEVEL to also set the volume in addition to the initial volume (similar to how it sets the initial head and head. Without that, we can't reset the tank head and volume from RTX. --- include/epanet2.h | 1 + src/epanet.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/epanet2.h b/include/epanet2.h index 5e3cef5..c65d493 100644 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -252,6 +252,7 @@ extern "C" { int DLLEXPORT ENsetoption(int, EN_API_FLOAT_TYPE); int DLLEXPORT ENsetstatusreport(int); int DLLEXPORT ENsetqualtype(int qualcode, char *chemname, char *chemunits, char *tracenode); + int DLLEXPORT ENsetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE baseDemand); #if defined(__cplusplus) } diff --git a/src/epanet.c b/src/epanet.c index c3297f6..e3f4f3d 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -2000,6 +2000,8 @@ int DLLEXPORT ENsetnodevalue(int index, int code, EN_API_FLOAT_TYPE v) || value < Tank[j].Hmin) return(202); Tank[j].H0 = value; Tank[j].V0 = tankvolume(j, Tank[j].H0); + // Resetting Volume in addition to initial volume + Tank[j].V = Tank[j].V0; H[index] = Tank[j].H0; } break; @@ -3285,6 +3287,22 @@ int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE * } return 0; } + +int DLLEXPORT ENsetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE baseDemand) +{ + Pdemand d; + int n=1; + /* Check for valid arguments */ + if (!Openflag) return(102); + if (nodeIndex <= 0 || nodeIndex > Nnodes) return(203); + if (nodeIndex <= Njuncs) { + for(d=Node[nodeIndex].D; nnext) n++; + if(n!=demandIdx) return(253); + d->Base = baseDemand/Ucf[FLOW]; + } + return 0; +} + int DLLEXPORT ENgetdemandpattern(int nodeIndex, int demandIdx, int *pattIdx) { Pdemand d;