From 4dff3bd054282c63afe6e086887c3c6b0d35ab02 Mon Sep 17 00:00:00 2001 From: Abel Heinsbroek Date: Tue, 23 Apr 2024 11:31:17 +0200 Subject: [PATCH 1/2] add ENgetnodesvalues and ENgetlinksvalues methods --- ReleaseNotes2_3.md | 1 + include/epanet2.h | 4 ++++ include/epanet2_2.h | 25 +++++++++++++++++++++++++ src/epanet.c | 39 +++++++++++++++++++++++++++++++++++++++ src/epanet2.c | 9 +++++++++ 5 files changed, 78 insertions(+) diff --git a/ReleaseNotes2_3.md b/ReleaseNotes2_3.md index 67680a8a..e7de309b 100644 --- a/ReleaseNotes2_3.md +++ b/ReleaseNotes2_3.md @@ -53,3 +53,4 @@ 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. \ No newline at end of file diff --git a/include/epanet2.h b/include/epanet2.h index 5cc6a415..c9fe5f83 100644 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -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 ENgetlinksvalues(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, diff --git a/include/epanet2_2.h b/include/epanet2_2.h index 5a3c3af2..01082e7d 100644 --- a/include/epanet2_2.h +++ b/include/epanet2_2.h @@ -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_getnodesvalues(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_getlinksvalues(EN_Project ph, int property, double *out_values); + /** @brief Sets a property value for a link. @param ph an EPANET project handle. diff --git a/src/epanet.c b/src/epanet.c index 86b510ba..45170f93 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -2358,6 +2358,26 @@ int DLLEXPORT EN_getnodevalue(EN_Project p, int index, int property, double *val return 0; } +int DLLEXPORT EN_getnodesvalues(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 @@ -3903,6 +3923,25 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val return 0; } +int DLLEXPORT EN_getlinksvalues(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 diff --git a/src/epanet2.c b/src/epanet2.c index 7d7cd50f..63b2217a 100644 --- a/src/epanet2.c +++ b/src/epanet2.c @@ -355,6 +355,11 @@ int DLLEXPORT ENgetnodevalue(int index, int property, EN_API_FLOAT_TYPE *value) return errcode; } +int DLLEXPORT ENgetnodesvalues(int property, EN_API_FLOAT_TYPE *values) +{ + return EN_getnodesvalues(_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 ENgetlinksvalues(int property, EN_API_FLOAT_TYPE *values) +{ + return EN_getlinksvalues(_defaultProject, property, values); +} int DLLEXPORT ENsetlinkvalue(int index, int property, EN_API_FLOAT_TYPE value) { From 9637f5c092cc5cddc7e15e2201805e3b6d5939aa Mon Sep 17 00:00:00 2001 From: Abel Heinsbroek Date: Wed, 24 Apr 2024 15:20:59 +0200 Subject: [PATCH 2/2] change names of new functions to ENgetnodevalues and ENgetlinkvalues --- include/epanet2.h | 2 +- include/epanet2_2.h | 4 ++-- src/epanet.c | 4 ++-- src/epanet2.c | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/epanet2.h b/include/epanet2.h index c9fe5f83..18a7345f 100644 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -293,7 +293,7 @@ extern "C" { int DLLEXPORT ENgetlinkvalue(int index, int property, EN_API_FLOAT_TYPE *value); - int DLLEXPORT ENgetlinksvalues(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); diff --git a/include/epanet2_2.h b/include/epanet2_2.h index 01082e7d..1094280d 100644 --- a/include/epanet2_2.h +++ b/include/epanet2_2.h @@ -882,7 +882,7 @@ typedef struct Project *EN_Project; (see @ref Units). */ - int DLLEXPORT EN_getnodesvalues(EN_Project ph, int property, double *out_values); + int DLLEXPORT EN_getnodevalues(EN_Project ph, int property, double *out_values); /** @brief Retrieves an array of property values for all nodes. @@ -1265,7 +1265,7 @@ 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_getlinksvalues(EN_Project ph, int property, double *out_values); + int DLLEXPORT EN_getlinkvalues(EN_Project ph, int property, double *out_values); /** @brief Sets a property value for a link. diff --git a/src/epanet.c b/src/epanet.c index 45170f93..8844cd54 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -2358,7 +2358,7 @@ int DLLEXPORT EN_getnodevalue(EN_Project p, int index, int property, double *val return 0; } -int DLLEXPORT EN_getnodesvalues(EN_Project p, int property, double *values) +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 @@ -3923,7 +3923,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val return 0; } -int DLLEXPORT EN_getlinksvalues(EN_Project p, int property, double *values) +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 diff --git a/src/epanet2.c b/src/epanet2.c index 63b2217a..82e74905 100644 --- a/src/epanet2.c +++ b/src/epanet2.c @@ -355,9 +355,9 @@ int DLLEXPORT ENgetnodevalue(int index, int property, EN_API_FLOAT_TYPE *value) return errcode; } -int DLLEXPORT ENgetnodesvalues(int property, EN_API_FLOAT_TYPE *values) +int DLLEXPORT ENgetnodevalues(int property, EN_API_FLOAT_TYPE *values) { - return EN_getnodesvalues(_defaultProject, property, values); + return EN_getnodevalues(_defaultProject, property, values); } int DLLEXPORT ENsetnodevalue(int index, int property, EN_API_FLOAT_TYPE value) @@ -528,9 +528,9 @@ int DLLEXPORT ENgetlinkvalue(int index, int property, EN_API_FLOAT_TYPE *value) *value = (EN_API_FLOAT_TYPE)v; return errcode; } -int DLLEXPORT ENgetlinksvalues(int property, EN_API_FLOAT_TYPE *values) +int DLLEXPORT ENgetlinkvalues(int property, EN_API_FLOAT_TYPE *values) { - return EN_getlinksvalues(_defaultProject, property, values); + return EN_getlinkvalues(_defaultProject, property, values); } int DLLEXPORT ENsetlinkvalue(int index, int property, EN_API_FLOAT_TYPE value)