Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pump efficiency functions. #815

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/epanet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/********************************************************************

Expand Down
18 changes: 18 additions & 0 deletions include/epanet2_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions src/epanet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/epanet2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/test_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down