From 1d071d19ba6323da106f0e341d5eeaa89a534857 Mon Sep 17 00:00:00 2001 From: AngelaMarchi Date: Sat, 10 Sep 2016 02:27:16 +0930 Subject: [PATCH] VSP efficiency + retrieving efficiency directly (#81) * VSP efficiency + retrieving efficiency directly Changes to the getenergy function (in hydraulic.c) to compute the correct efficiency of variable speed pumps according to the affinity laws. Changes to epanet2.h and epanet.c are for retrieving the efficiency of pumps throught the ENgetlinkvalue function (code 16 for efficiency) * Update epanet.c * VSP efficiency (incl. bas and vb file) - bas and vb file have been updated with code 16 for efficiency. - Retrieving efficiency case has been improved. --- include/epanet2.bas | 1 + include/epanet2.h | 3 ++- include/epanet2.vb | 1 + src/epanet.c | 6 +++++- src/hydraul.c | 7 ++++++- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/epanet2.bas b/include/epanet2.bas index adb5d70..d6dbb2a 100644 --- a/include/epanet2.bas +++ b/include/epanet2.bas @@ -52,6 +52,7 @@ Global Const EN_SETTING = 12 Global Const EN_ENERGY = 13 Global Const EN_LINKQUAL = 14 'ES Global Const EN_LINKPATTERN = 15 +Global Const EN_EFFICIENCY = 16 Global Const EN_DURATION = 0 ' Time parameters Global Const EN_HYDSTEP = 1 diff --git a/include/epanet2.h b/include/epanet2.h index 5a117c7..55749a3 100755 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -110,7 +110,8 @@ typedef enum { EN_SETTING = 12, EN_ENERGY = 13, EN_LINKQUAL = 14, - EN_LINKPATTERN = 15 + EN_LINKPATTERN = 15, + EN_EFFICIENCY = 16 } EN_LinkProperty; /// Time parameter codes diff --git a/include/epanet2.vb b/include/epanet2.vb index 9cd3e2c..bbaffb6 100644 --- a/include/epanet2.vb +++ b/include/epanet2.vb @@ -56,6 +56,7 @@ Public Const EN_SETTING = 12 Public Const EN_ENERGY = 13 Public Const EN_LINKQUAL = 14 'ES Public Const EN_LINKPATTERN = 15 +Public Const EN_EFFICIENCY = 16 Public Const EN_DURATION = 0 ' Time parameters Public Const EN_HYDSTEP = 1 diff --git a/src/epanet.c b/src/epanet.c index 27543b5..1d2c0ba 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -1458,7 +1458,11 @@ int DLLEXPORT ENgetlinkvalue(int index, int code, EN_API_FLOAT_TYPE *value) if (Link[index].Type == PUMP) v = (double)Pump[PUMPINDEX(index)].Upat; break; - + + case EN_EFFICIENCY: + getenergy(index, &a, &v); + break; + default: return(251); } *value = (EN_API_FLOAT_TYPE)v; diff --git a/src/hydraul.c b/src/hydraul.c index e9bcbb7..83ab227 100755 --- a/src/hydraul.c +++ b/src/hydraul.c @@ -998,6 +998,7 @@ void getenergy(int k, double *kw, double *eff) { int i,j; double dh, q, e; + double q4eff; //q4eff=flow at nominal speed to compute efficiency /*** Updated 6/24/02 ***/ /* No energy if link is closed */ @@ -1019,7 +1020,11 @@ void getenergy(int k, double *kw, double *eff) j = PUMPINDEX(k); e = Epump; if ( (i = Pump[j].Ecurve) > 0) - e = interp(Curve[i].Npts,Curve[i].X,Curve[i].Y,q*Ucf[FLOW]); + { + q4eff = q/LinkSetting[k]; + e = interp(Curve[i].Npts,Curve[i].X, Curve[i].Y, q4eff*Ucf[FLOW]); + } + // e = interp(Curve[i].Npts,Curve[i].X,Curve[i].Y,q*Ucf[FLOW]); //old line of code e = MIN(e, 100.0); e = MAX(e, 1.0); e /= 100.0;