diff --git a/include/epanet2.h b/include/epanet2.h index fc99a067..1aaa655a 100644 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -320,6 +320,10 @@ extern "C" { int DLLEXPORT ENgetheadcurveindex(int linkIndex, int *curveIndex); int DLLEXPORT ENsetheadcurveindex(int linkIndex, int curveIndex); + + int DLLEXPORT ENgetefficiencycurveindex(int linkIndex, int *curveIndex); + + int DLLEXPORT ENsetefficiencycurveindex(int linkIndex, int curveIndex); /******************************************************************** diff --git a/include/epanet2_2.h b/include/epanet2_2.h index 81f2f9f0..1fb62b93 100644 --- a/include/epanet2_2.h +++ b/include/epanet2_2.h @@ -1371,6 +1371,24 @@ typedef struct Project *EN_Project; */ int DLLEXPORT EN_setheadcurveindex(EN_Project ph, int linkIndex, int curveIndex); + /** + @brief Retrieves the curve assigned to a pump's efficiency curve. + @param ph an EPANET project handle. + @param linkIndex the index of a pump link (starting from 1). + @param[out] curveIndex the index of the curve assigned to the pump's efficiency curve. + @return an error code. + */ + int DLLEXPORT EN_getefficiencycurveindex(EN_Project ph, int linkIndex, int *out_curveIndex); + + /** + @brief Assigns a curve to a pump's efficiency curve. + @param ph an EPANET project handle. + @param linkIndex the index of a pump link (starting from 1). + @param curveIndex the index of a curve to be assigned as the pump's efficiency curve. + @return an error code. + */ + int DLLEXPORT EN_setefficiencycurveindex(EN_Project ph, int linkIndex, int curveIndex); + /******************************************************************** Time Pattern Functions diff --git a/src/epanet.c b/src/epanet.c index 71cad747..723d6b4e 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -4460,6 +4460,59 @@ int DLLEXPORT EN_setheadcurveindex(EN_Project p, int linkIndex, int curveIndex) return 0; } +int DLLEXPORT EN_getefficiencycurveindex(EN_Project p, int linkIndex, int *curveIndex) +/*---------------------------------------------------------------- +** Input: linkIndex = index of a pump link +** Output: curveIndex = index of a pump's efficiency curve +** Returns: error code +** Purpose: retrieves the index of a pump's efficiency curve +**---------------------------------------------------------------- +*/ +{ + Network *net = &p->network; + + Slink *Link = net->Link; + Spump *Pump = net->Pump; + const int Nlinks = net->Nlinks; + + *curveIndex = 0; + if (!p->Openflag) return 102; + if (linkIndex < 1 || linkIndex > Nlinks) return 204; + if (PUMP != Link[linkIndex].Type) return 216; + *curveIndex = Pump[findpump(net, linkIndex)].Ecurve; + return 0; +} + +int DLLEXPORT EN_setefficiencycurveindex(EN_Project p, int linkIndex, int curveIndex) +/*---------------------------------------------------------------- +** Input: linkIndex = index of a pump link +** curveIndex = index of a curve +** Output: none +** Returns: error code +** Purpose: assigns a new efficiency curve to a pump +**---------------------------------------------------------------- +*/ +{ + Network *net = &p->network; + + int pumpIndex; + int err = 0; + Spump *pump; + + // Check for valid parameters + if (!p->Openflag) return 102; + if (linkIndex < 1 || linkIndex > net->Nlinks) return 204; + if (PUMP != net->Link[linkIndex].Type) return 0; + if (curveIndex < 0 || curveIndex > net->Ncurves) return 206; + + // Assign the new curve to the pump + pumpIndex = findpump(net, linkIndex); + pump = &net->Pump[pumpIndex]; + pump->Ecurve = curveIndex; + net->Link[linkIndex].Km = 0.0; + return 0; +} + /******************************************************************** Time Pattern Functions diff --git a/src/epanet2.c b/src/epanet2.c index 435a571c..8776885b 100644 --- a/src/epanet2.c +++ b/src/epanet2.c @@ -603,6 +603,16 @@ int DLLEXPORT ENsetheadcurveindex(int linkIndex, int curveIndex) return EN_setheadcurveindex(_defaultProject, linkIndex, curveIndex); } +int DLLEXPORT ENgetefficiencycurveindex(int linkIndex, int *curveIndex) +{ + return EN_getefficiencycurveindex(_defaultProject, linkIndex, curveIndex); +} + +int DLLEXPORT ENsetefficiencycurveindex(int linkIndex, int curveIndex) +{ + return EN_setefficiencycurveindex(_defaultProject, linkIndex, curveIndex); +} + /******************************************************************** Time Pattern Functions diff --git a/tests/test_pattern.cpp b/tests/test_pattern.cpp index 4d98ba37..72c9e98a 100644 --- a/tests/test_pattern.cpp +++ b/tests/test_pattern.cpp @@ -167,6 +167,25 @@ BOOST_AUTO_TEST_CASE(test_add_set) BOOST_REQUIRE(x == x3[0]); BOOST_REQUIRE(y == y3[0]); + // Add an efficiency curve to the pump + double xe[] = {0.0, 1.0}; + double ye[] = {100.0, 30.0}; + char eCurve[] = "ECurve"; + EN_addcurve(ph, eCurve); + EN_setcurve(ph, 3, xe, ye, 2); + EN_getcurveindex(ph, eCurve, &curveIdx); + EN_setefficiencycurveindex(ph, pumpIdx, curveIdx); + + // Check that pump's efficiency curve is eCurve + EN_getefficiencycurveindex(ph, pumpIdx, &curveIdx); + EN_getcurveid(ph, curveIdx, curveID); + BOOST_REQUIRE(strcmp(curveID, eCurve) == 0); + + // And that it contains the correct data + EN_getcurvevalue(ph, curveIdx, 1, &x, &y); + BOOST_REQUIRE(x == xe[0]); + BOOST_REQUIRE(y == ye[0]); + EN_close(ph); EN_deleteproject(ph); }