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 ENgetnodesvalues and ENgetlinksvalues methods #786

Merged
merged 3 commits into from
Jun 3, 2024
Merged
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
3 changes: 2 additions & 1 deletion ReleaseNotes2_3.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ This document describes the changes and updates that have been made in version 2
- `EN_PRESS_UNITS` can now be used with `EN_getoption` and `EN_setoption` to get or set the pressure unit used in EPANET.
- Continuous barrier functions were added to constrain emitter flows to allowable values.
- The `EN_openx` function has been added to enable the opening of input files with formatting errors through the API. This allows users to continue using toolkit functions even when such errors are present.
- Fixed a bug in EN_setnodevalue with EN_EMITTER option that could cause NaN results.
- The `EN_getnodesvalues` and `EN_getlinksvalues` were added to retrieve a property value for all nodes or links in the network.
- Fixed a bug in EN_setnodevalue with EN_EMITTER option that could cause NaN results.
4 changes: 4 additions & 0 deletions include/epanet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ extern "C" {

int DLLEXPORT ENgetnodevalue(int index, int property, EN_API_FLOAT_TYPE *value);

int DLLEXPORT ENgetnodevalues(int property, EN_API_FLOAT_TYPE *value);

int DLLEXPORT ENsetnodevalue(int index, int property, EN_API_FLOAT_TYPE value);

int DLLEXPORT ENsetjuncdata(int index, EN_API_FLOAT_TYPE elev,
Expand Down Expand Up @@ -291,6 +293,8 @@ extern "C" {

int DLLEXPORT ENgetlinkvalue(int index, int property, EN_API_FLOAT_TYPE *value);

int DLLEXPORT ENgetlinkvalues(int property, EN_API_FLOAT_TYPE *value);

int DLLEXPORT ENsetlinkvalue(int index, int property, EN_API_FLOAT_TYPE value);

int DLLEXPORT ENsetpipedata(int index, EN_API_FLOAT_TYPE length,
Expand Down
25 changes: 25 additions & 0 deletions include/epanet2_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,20 @@ typedef struct Project *EN_Project;
Values are returned in units that depend on the units used for flow rate
(see @ref Units).
*/

int DLLEXPORT EN_getnodevalues(EN_Project ph, int property, double *out_values);

/**
@brief Retrieves an array of property values for all nodes.
@param ph an EPANET project handle.
@param property the property to retrieve (see @ref EN_NodeProperty).
@param[out] values an array of values for all nodes.
@return an error code.

Values are returned in units that depend on the units used for flow rate
(see @ref Units).
*/

int DLLEXPORT EN_getnodevalue(EN_Project ph, int index, int property, double *out_value);

/**
Expand Down Expand Up @@ -1242,6 +1256,17 @@ typedef struct Project *EN_Project;
*/
int DLLEXPORT EN_getlinkvalue(EN_Project ph, int index, int property, double *out_value);

/**
@brief Retrieves an array of property values for all links.
@param ph an EPANET project handle.
@param property the property to retrieve (see @ref EN_LinkProperty).
@param[out] values an array of values for all links.
@return an error code.

Values are returned in units that depend on the units used for flow rate (see @ref Units).
*/
int DLLEXPORT EN_getlinkvalues(EN_Project ph, int property, double *out_values);

/**
@brief Sets a property value for a link.
@param ph an EPANET project handle.
Expand Down
39 changes: 39 additions & 0 deletions src/epanet.c
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,26 @@ int DLLEXPORT EN_getnodevalue(EN_Project p, int index, int property, double *val
return 0;
}

int DLLEXPORT EN_getnodevalues(EN_Project p, int property, double *values)
/*----------------------------------------------------------------
** Input: property = node property code (see EN_NodeProperty)
** Output: values = array of node property values
** Returns: error code
** Purpose: retrieves an array of node property values
**----------------------------------------------------------------
*/
{
int status = 0;

for (int i = 1; i <= p->network.Nnodes; i++)
{
status = EN_getnodevalue(p, i, property, &values[i - 1]);
// if status is not 0, return the error code
if (status != 0) { return status; }
}
return 0;
}

int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int property, double value)
/*----------------------------------------------------------------
** Input: index = node index
Expand Down Expand Up @@ -3910,6 +3930,25 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
return 0;
}

int DLLEXPORT EN_getlinkvalues(EN_Project p, int property, double *values)
/*----------------------------------------------------------------
** Input: property = link property code (see EN_LinkProperty)
** Output: values = array of link property values
** Returns: error code
** Purpose: retrieves property values for all links
**----------------------------------------------------------------
*/
{
int status = 0;
for(int i = 1; i <= p->network.Nlinks; i++)
{
status = EN_getlinkvalue(p, i, property, &values[i-1]);
// If an error occurs, return the error code
if(status != 0) { return status; }
}
return 0;
}

int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double value)
/*----------------------------------------------------------------
** Input: index = link index
Expand Down
9 changes: 9 additions & 0 deletions src/epanet2.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ int DLLEXPORT ENgetnodevalue(int index, int property, EN_API_FLOAT_TYPE *value)
return errcode;
}

int DLLEXPORT ENgetnodevalues(int property, EN_API_FLOAT_TYPE *values)
{
return EN_getnodevalues(_defaultProject, property, values);
}

int DLLEXPORT ENsetnodevalue(int index, int property, EN_API_FLOAT_TYPE value)
{
return EN_setnodevalue(_defaultProject, index, property, value);
Expand Down Expand Up @@ -523,6 +528,10 @@ int DLLEXPORT ENgetlinkvalue(int index, int property, EN_API_FLOAT_TYPE *value)
*value = (EN_API_FLOAT_TYPE)v;
return errcode;
}
int DLLEXPORT ENgetlinkvalues(int property, EN_API_FLOAT_TYPE *values)
{
return EN_getlinkvalues(_defaultProject, property, values);
}

int DLLEXPORT ENsetlinkvalue(int index, int property, EN_API_FLOAT_TYPE value)
{
Expand Down