Merge pull request #786 from Vitens/dev

add ENgetnodesvalues and ENgetlinksvalues methods
This commit is contained in:
Lew Rossman
2024-06-03 11:24:11 -04:00
committed by GitHub
5 changed files with 79 additions and 1 deletions

View File

@@ -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.
- 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.

View File

@@ -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,
@@ -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,

View File

@@ -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);
/**
@@ -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.

View File

@@ -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
@@ -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

View File

@@ -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);
@@ -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)
{