From 27c21e499e76ff9e4c308837e99e3f320366a8d3 Mon Sep 17 00:00:00 2001 From: Marios Kyriakou Date: Thu, 25 Oct 2018 13:55:03 +0300 Subject: [PATCH 1/4] Update ReleaseNotes2_2.md 1. Update description of new API functions. 2. Update API extensions --- ReleaseNotes2_2.md | 69 +++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/ReleaseNotes2_2.md b/ReleaseNotes2_2.md index 2b335f3..10ca70a 100644 --- a/ReleaseNotes2_2.md +++ b/ReleaseNotes2_2.md @@ -129,35 +129,35 @@ Both network files are available [here](https://doi.org/10.23719/1375314). ## New API functions |Function|Description| |--|--| -|`ENgetcurvetype`| | -|`ENgetdemandmodel`|| -|`ENsetdemandmodel`|| -|`ENsetflowunits`|| -|`ENaddcontrol`|| -|`ENsetdemandpattern`|| -|`ENgetrule`|| -|`ENsetrulepriority`|| -|`ENgetpremise`|| -|`ENsetpremise`|| -|`ENsetpremiseindex`|| -|`ENsetpremisestatus`|| -|`ENsetpremisevalue`|| -|`ENgettrueaction`|| -|`ENsettrueaction`|| -|`ENgetfalseaction`|| -|`ENsetfalseaction`|| -|`ENgetruleID`|| -|`ENinit`|| -|`ENsetheadcurveindex`|| -|`ENsetlinktype`|| -|`ENaddnode`|| -|`ENaddlink`|| -|`ENdeletelink`|| -|`ENdeletenode`|| -| `ENsetnodeid` || -| `ENsetlinkid` || -|`ENgetdemandname`|| -|`ENsetdemandname`|| +|`ENgetcurvetype`|Get the type of a curve| +|`ENgetdemandmodel`|Retrieves the type of demand model in use and its parameters| +|`ENsetdemandmodel`|Sets the type of demand model to use and its parameters| +|`ENsetflowunits`|Sets the flow units| +|`ENaddcontrol`|Specify parameters to add a new simple control| +|`ENsetdemandpattern`|Sets the index of the demand pattern assigned to a node for a category index| +|`ENgetrule`|Gets the number of premises, true actions, and false actions and the priority of an existing rule-based control| +|`ENsetrulepriority`|Sets the priority of the existing rule-based control| +|`ENgetpremise`|Gets the components of a premise/condition in an existing rule-based control| +|`ENsetpremise`|Sets the components of a premise/condition in an existing rule-based control| +|`ENsetpremiseindex`|Sets the index of an object in a premise of an existing rule-based control| +|`ENsetpremisestatus`|Sets the status in a premise of an existing rule-based control| +|`ENsetpremisevalue`|Sets the value in a premise of an existing rule-based control| +|`ENgettrueaction`|Gets the components of a true-action in an existing rule-based control| +|`ENsettrueaction`|Sets the components of a true-action in an existing rule-based control| +|`ENgetfalseaction`|Gets the components of a false-action in an existing rule-based control| +|`ENsetfalseaction`|Sets the components of a false-action in an existing rule-based control| +|`ENgetruleID`|Returns the ID of a rule| +|`ENinit`|Initializes an EPANET session| +|`ENsetheadcurveindex`|Sets the curve id for a specified pump index| +|`ENsetlinktype`|Set the link type code for a specified link| +|`ENaddnode`|Adds a new node| +|`ENaddlink`|Adds a new link| +|`ENdeletelink`|Deletes a link| +|`ENdeletenode`|Deletes a node| +| `ENsetnodeid` |Change the ID name for a node| +| `ENsetlinkid` |Change the ID name for a link| +|`ENgetdemandname`|Sets the node's demand name for a category| +|`ENsetdemandname`|Sets the node's demand name for a category| ## API Extensions (additional definitions) ### Link value types: @@ -174,10 +174,14 @@ Both network files are available [here](https://doi.org/10.23719/1375314). - `EN_HW` - `EN_DW` - `EN_CM` -### Misc. options: +### Option types: - `EN_HEADERROR` - `EN_FLOWCHANGE` - `EN_DEMANDDEFPAT` + - `EN_HEADLOSSFORM` +### Time statistic types: + - `EN_MAXHEADERROR` + - `EN_MAXFLOWCHANGE` - `EN_MASSBALANCE` ### Curve types: - `EN_V_CURVE` @@ -185,7 +189,10 @@ Both network files are available [here](https://doi.org/10.23719/1375314). - `EN_E_CURVE` - `EN_H_CURVE` - `EN_G_CURVE` - +### Demand model types: + - `EN_DDA` + - `EN_PDA` + ## Authors contributing to this release: - List item From c2b16a64663608ab3127812f10140c369dce3bd2 Mon Sep 17 00:00:00 2001 From: Lew Rossman Date: Sun, 28 Oct 2018 20:07:54 -0400 Subject: [PATCH 2/4] Deleted previous, commented-out version of EN_setlinktype --- src/epanet.c | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index 3fc97d9..50618cc 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -4963,45 +4963,6 @@ int DLLEXPORT EN_setlinktype(EN_ProjectHandle ph, int *index, EN_LinkType type) // Find the index of this new link EN_getlinkindex(ph, id, index); return set_error(p->error_handle, errcode); - - /*********************************************** - int i; - EN_LinkType fromType; - - EN_Project *p = (EN_Project*)ph; - - EN_Network *net = &p->network; - - if (!p->Openflag) - return set_error(p->error_handle, 102); - - // Check if a link with the id exists - if (EN_getlinkindex(p, id, &i) != 0) - return set_error(p->error_handle, 215); - - // Get the current type of the link - EN_getlinktype(p, i, &fromType); - if (fromType == toType) - return set_error(p->error_handle, 0); - - // Change link from Pipe - if (toType <= EN_PIPE) { - net->Npipes++; - } else if (toType == EN_PUMP) { - net->Npumps++; - net->Pump[net->Npumps].Link = i; - } else { - net->Nvalves++; - net->Valve[net->Nvalves].Link = i; - } - - if (fromType <= EN_PIPE) { - net->Npipes--; - } else if (fromType == EN_PUMP) { - net->Npumps--; - } - return set_error(p->error_handle, 0); -**********************************************/ } int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) { From 4394c53f9bf86d9307a7aceca95c5152386d861f Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Mon, 29 Oct 2018 17:20:45 +0200 Subject: [PATCH 3/4] Add ENsetlinknodes to DEF file and add a function check --- src/epanet.c | 3 +++ win_build/WinSDK/epanet2.def | 1 + 2 files changed, 4 insertions(+) diff --git a/src/epanet.c b/src/epanet.c index 50618cc..8d72f4a 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -3169,6 +3169,9 @@ int DLLEXPORT EN_setlinknodes(EN_ProjectHandle ph, int index, int node1, int nod int type; EN_Project *p = (EN_Project*)ph; EN_Network *net = &p->network; + + // Check that end and start nodes are not the same + if (node1 == node2) return set_error(p->error_handle, 222); // Check that nodes exist if (node1 < 0 || node1 > net->Nnodes) return set_error(p->error_handle, 203); diff --git a/win_build/WinSDK/epanet2.def b/win_build/WinSDK/epanet2.def index fd4d4a9..7935207 100644 --- a/win_build/WinSDK/epanet2.def +++ b/win_build/WinSDK/epanet2.def @@ -13,6 +13,7 @@ EXPORTS ENgetlinkid = _ENgetlinkid@8 ENgetlinkindex = _ENgetlinkindex@8 ENgetlinknodes = _ENgetlinknodes@12 + ENsetlinknodes = _ENsetlinknodes@12 ENgetlinktype = _ENgetlinktype@8 ENgetlinkvalue = _ENgetlinkvalue@12 ENgetnodeid = _ENgetnodeid@8 From 5f0ca809d7a39ad43b5868f1089f6be42c293744 Mon Sep 17 00:00:00 2001 From: Michael Tryby Date: Mon, 5 Nov 2018 10:05:30 -0500 Subject: [PATCH 4/4] Fixing bug in check_cdd --- tests/test_output.cpp | 74 ++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/tests/test_output.cpp b/tests/test_output.cpp index fa8bb98..b0848a1 100644 --- a/tests/test_output.cpp +++ b/tests/test_output.cpp @@ -24,34 +24,42 @@ #define DATA_PATH "./example1.out" -using namespace std; +using namespace std; -// Custom test to check the minimum number of correct decimal digits between -// the test and the ref vectors. -boost::test_tools::predicate_result check_cdd(std::vector& test, - std::vector& ref, long cdd_tol) -{ - float tmp, min_cdd = 100.0; - - // TODO: What is the vectors aren't the same length? +// Custom test to check the minimum number of correct decimal digits between +// the test and the ref vectors. +boost::test_tools::predicate_result check_cdd(std::vector& test, + std::vector& ref, long cdd_tol){ + float tmp, min_cdd = 10.0; + + // TODO: What if the vectors aren't the same length? std::vector::iterator test_it; std::vector::iterator ref_it; - for (test_it = test.begin(); test_it < test.end(); ++test_it) { - for (ref_it = ref.begin(); ref_it < ref.end(); ++ref_it) { - - if (*test_it != *ref_it) { - tmp = - log10f(abs(*test_it - *ref_it)); - if (tmp < min_cdd) min_cdd = tmp; - } + for (test_it = test.begin(), ref_it = ref.begin(); + (test_it < test.end()) && (ref_it < ref.end()); + ++test_it, ++ref_it) + { + if (*test_it != *ref_it) { + // Compute log absolute error + tmp = abs(*test_it - *ref_it); + if (tmp < 1.0e-7f) + tmp = 1.0e-7f; + + else if (tmp > 2.0f) + tmp = 1.0f; + + tmp = -log10(tmp); + if (tmp < 0.0f) + tmp = 0.0f; + + if (tmp < min_cdd) + min_cdd = tmp; } } - if (min_cdd == 100.0) - return true; - else - return floor(min_cdd) <= cdd_tol; + return floor(min_cdd) >= cdd_tol; } boost::test_tools::predicate_result check_string(std::string test, std::string ref) @@ -96,7 +104,7 @@ struct Fixture{ free((void*)array); error = ENR_close(&p_handle); } - + std::string path; int error; ENR_Handle p_handle; @@ -110,14 +118,14 @@ BOOST_AUTO_TEST_SUITE(test_output_fixture) BOOST_FIXTURE_TEST_CASE(test_getNetSize, Fixture) { int *i_array = NULL; - + error = ENR_getNetSize(p_handle, &i_array, &array_dim); BOOST_REQUIRE(error == 0); // nodes, tanks, links, pumps, valves std::vector test; test.assign(i_array, i_array + array_dim); - + std::vector ref = {11,2,13,1,0}; BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end()); @@ -149,11 +157,11 @@ BOOST_FIXTURE_TEST_CASE(test_getElementName, Fixture) { } BOOST_FIXTURE_TEST_CASE(test_getNodeAttribute, Fixture) { - + error = ENR_getNodeAttribute(p_handle, 1, ENR_quality, &array, &array_dim); BOOST_REQUIRE(error == 0); - std::vector ref_vec = { 1.0f, + std::vector ref_vec = { 1.0f, 0.44407997f, 0.43766347f, 0.42827705f, @@ -197,10 +205,10 @@ BOOST_FIXTURE_TEST_CASE(test_getLinkAttribute, Fixture) { } BOOST_FIXTURE_TEST_CASE(test_getNodeResult, Fixture) { - + error = ENR_getNodeResult(p_handle, 1, 2, &array, &array_dim); BOOST_REQUIRE(error == 0); - + std::vector ref_vec = {0.041142918f, 150.0f, 987.98358f, @@ -213,7 +221,7 @@ BOOST_FIXTURE_TEST_CASE(test_getNodeResult, Fixture) { } BOOST_FIXTURE_TEST_CASE(test_getLinkResult, Fixture) { - + error = ENR_getLinkResult(p_handle, 24, 13, &array, &array_dim); BOOST_REQUIRE(error == 0); @@ -233,7 +241,7 @@ BOOST_FIXTURE_TEST_CASE(test_getLinkResult, Fixture) { } BOOST_FIXTURE_TEST_CASE(test_getNodeSeries, Fixture){ - + error = ENR_getNodeSeries(p_handle, 2, ENR_pressure, 0, 10, &array, &array_dim); BOOST_REQUIRE(error == 0); @@ -250,12 +258,12 @@ BOOST_FIXTURE_TEST_CASE(test_getNodeSeries, Fixture){ std::vector test_vec; test_vec.assign(array, array + array_dim); - + BOOST_CHECK(check_cdd(test_vec, ref_vec, 3)); } BOOST_FIXTURE_TEST_CASE(test_getLinkSeries, Fixture) { - + error = ENR_getLinkSeries(p_handle, 2, ENR_flow, 0, 10, &array, &array_dim); BOOST_REQUIRE(error == 0); @@ -277,7 +285,7 @@ BOOST_FIXTURE_TEST_CASE(test_getLinkSeries, Fixture) { } BOOST_FIXTURE_TEST_CASE(test_getNetReacts, Fixture) { - + error = ENR_getNetReacts(p_handle, &array, &array_dim); BOOST_REQUIRE(error == 0); @@ -293,7 +301,7 @@ BOOST_FIXTURE_TEST_CASE(test_getNetReacts, Fixture) { } BOOST_FIXTURE_TEST_CASE(test_getEnergyUsage, Fixture) { - + int linkIdx; error = ENR_getEnergyUsage(p_handle, 1, &linkIdx, &array, &array_dim);