Feature wrapper (#136)

this quite sizable commit does several things, but is primarily
focussed on building a toolkit that can run simultaneous
simulations/analyses within a shared memory space. Versions <=2.1 use a
long list of global variables that prevent multiple instantiations on
linux systems without resorting to compilation tricks (like duplicate
binaries or similar via static linkage). This version uses a single "Project" pointer to encapsulate
the network and analysis data. There are no changes to existing algo
implementations other than to accomodate dereferencing of the passed-in
pointers. A more detailed list of major changes below:

- mirrors all “ENxxxx” function calls with “EN_xxxx” versions (note the
underscore) that take an extra first parameter: a pointer to an
EN_Project struct, which contains all network, hydraulic, quality, and
associated data.
- tweaks some code formatting to make it more readable
- removes some deprecated/commented code that was sufficiently old
- fixes implicit type-cast warnings

* Added ENaddnode and ENaddlink functions

* More memory reallocations

* Added ENInit, ENsetheadcurveindex

* Added ENdeletelink and ENdeletenode

* restored default behavior for float types

* fixed type

* Added docstrings for ENinit

* cleanup change

* moves global rule variables to vars.h

* migrates rule structs to typedefs

for better readability

* char types to proper enums

fixes #93

* Change some variable declarations for compatibility

Changes to keep compatibility with C89 compilers: variables must be
declared at the top of the functions. Remove the use of EN_LinkType in
function call as it is not compatible with ENgetnodetype.

* Moved declaration of idstodelete to top of function

* Updated ENinit function and headers

Updated header files with new functions
Updated def file with new functions
For ENinit changes names of parameters #98
Added enum for headloss formula

* Missed these files in 1a033fc

* migrates char types to enums fixes #93,

supports unified link/node type enums, rather than public/private
redefinitions

* removing links in reverse-index order maintains proper indexing fixes #96

* style

* clarifies curve getter units issue (dox)

closes #95

* fixes link/node confusion in ENsetlinktype

partially reverts a3bce95dc330a5a297634a303d438e2e1bc41cc9

* partial compilation fix

* fixes dox issue

* fixes allocation issues with enums

- updates style in various places
- introduces FlowDirection enum
- use snprintf to prevent overflow

* fixes enum type cast

* updated mac project settings

* Use of _snprintf on Windows and remove DLLEXPORT from mempool.h

snprintf it not compatible on Windows so we use _snprintf
mempool gave starnge compilation errors while removing DLLEXPORT worked.
Not sure why these functions needed to be exposed in the DLL?

* Revert "Use of _snprintf on Windows and remove DLLEXPORT from mempool.h"

This reverts commit 6238f77d47fa0feaabe5836043c006937de433a2.

* use of _snprintf instead of snprintf on Windows and removed DLLEXPORT from mempool.h

Had compilation errors on mempool.h. Removed DLLEXPORT so solve it. Not
sure why there was a need to expose these functions?

* Shift indices for Links in ENaddnode

Need to shift indices for Links not just Pipes since a pump could be
connected directly to a reservoir. Also set the defult base demand to
zero (was 5).

* Set defualts for madatory link properties in ENaddlink and small fix for ENsetheadcurveindex

Relates to #102 and closes #103

* wraps globals into structs, duplicates api functions with objective versions



* parse and serialize Comment field for network elements

related to #47

* adds getter for head/efficiency curve

in EN_getlinkvalue

* adds getter for event node index

… to return the index of the junction (tank) that triggered the event.

* fixes edge case in parsing

… where inp files without demands in [JUNCTIONS] and without any
[DEMAND] categories will fail.

* adds freeing function for project pointer

* removes redundant string literals, fixes overrun issue in error message getter function

* check for hydraulics already closed

* moving error definitions to data file

* deprecates ENR err message getter (unused)

* updates location of errors data file

also begins to expose blind structs to curves and patterns,
anticipating buildout of APIs for those.

* updates CLI output to reflect executable name as invoked

relates to #109

* Feature nrtest (#131)

* Initial commit EPANET testing tools.

* Initial commit for epanet-nrtestsuite

* SWIG wrapper for EPANET outputapi (#118)

* Removed pervious version of outputapi and wrapper

* SWIG wrapper for EPANET outputapi

* Patching cmake build script fixed target for outputapi

* Build failing on deprecated test script

* Minor changes. Responding to review comments.

* Feature nrtest (#121)

* Configured python setup to automatically build nrtest tools.

* Working on build / testing automation

* Adding EPANET 2.0.12 benchmark

* Updated Travis yml to run nrtest

* Fixing InsecurePlatformWarning

* Fixing InsecurePlatformWarning again

* Fixing InsecurePlatformWarning

* Fixing InsecurePlatformWarning

* Fixing InsecurePlatformWarning

* Update .travis.yml

* Update .travis.yml

* Update .travis.yml

* Update .travis.yml

* Working on configuring python environment and building test tools under Travis CI.

* Making gen-config.sh and run-nrtest.sh executable

* Debugging .travis.yml

* Debugging .travis.yml

* Debugging .travis.yml again

* Debugging .travis.yml again

* debugging travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* Fixing bug with __strncpy_chk destlen < len

* nrtesting clean up

* re-implements fixes from:

5eead5ae40
3c788567a4

* removes extraneous build files, moves cmake and updates travis

* mirror of 9b37035560f9683f1514b439f7586a5c17bca5bf

* Move some variable declarations

* More variable declarations

* Fix TmpDir

* Allocate _defaultModel

* Fix EN_addcurve funcrion

* Fix for inpfile

* Fix writeRuleinInp call

* Set MAXMSG to 79 chars

* Fix for flow direction

* Refactoring testing related python packages and SWIG wrapper bug fix (#139)

* Eliminated epanet-reader package. Removed numpy dependency from epanet-output. Fixed reference counting bug in SWIG wrapper. Added error checking to run_nrtest.sh. Added nrtest package to requirements file.

* changing buildhome directory

* Fixing bug related to preprocessor definition of PI
This commit is contained in:
Sam Hatchett
2018-01-09 16:56:42 -05:00
committed by GitHub
parent 5eead5ae40
commit f97d837231
77 changed files with 37683 additions and 20504 deletions

View File

@@ -0,0 +1,251 @@
/*
* test_epanet_output.cpp
*
* Created: 8/4/2017
* Author: Michael E. Tryby
* US EPA - ORD/NRMRL
*
* Unit testing for EPANET Output API using google test.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include "gtest/gtest.h"
#include "../src/epanet_output.h"
#define PROJECT_HOME "C:/Users/mtryby/Workspace/GitRepo/michaeltryby/epanet/"
#define DATA_PATH "tools/epanet-output/test/data/net1.out"
namespace {
TEST(ENR_init, InitTest) {
ENR_Handle p_handle;
int error = ENR_init(&p_handle);
ASSERT_EQ(0, error);
ASSERT_TRUE(p_handle != NULL);
}
TEST(ENR_open, OpenTest) {
std::string path = std::string(PROJECT_HOME) + std::string(DATA_PATH);
ENR_Handle p_handle;
ENR_init(&p_handle);
int error = ENR_open(p_handle, path.c_str());
ASSERT_EQ(0, error);
ENR_close(&p_handle);
}
TEST(ENR_close, CloseTest) {
ENR_Handle p_handle;
int error = ENR_init(&p_handle);
error = ENR_close(&p_handle);
ASSERT_EQ(-1, error);
ASSERT_TRUE(p_handle != NULL);
}
class OutputapiTest : public testing::Test {
protected:
// SetUp for OutputapiTest fixture
virtual void SetUp() {
std::string path = std::string(PROJECT_HOME) + std::string(DATA_PATH);
error = ENR_init(&p_handle);
ENR_clearError(p_handle);
error = ENR_open(p_handle, path.c_str());
}
// TearDown for OutputapiTest fixture
virtual void TearDown() {
ENR_free((void**)&array);
error = ENR_close(&p_handle);
}
int error = 0;
ENR_Handle p_handle = NULL;
float* array = NULL;
int array_dim = 0;
};
TEST_F(OutputapiTest, getNetSizeTest) {
int* i_array = NULL;
// nodes, tanks, links, pumps, valves
int ref_array[5] = {11,2,13,1,0};
error = ENR_getNetSize(p_handle, &i_array, &array_dim);
ASSERT_EQ(0, error);
for (int i = 0; i < array_dim; i++)
EXPECT_EQ(ref_array[i], i_array[i]);
ENR_free((void**)&i_array);
}
TEST_F(OutputapiTest, getElementName) {
char* name = new char[MAXID];
int length, index = 1;
error = ENR_getElementName(p_handle, ENR_node, index, &name, &length);
ASSERT_EQ(0, error);
EXPECT_STREQ("10", name);
delete(name);
}
TEST_F(OutputapiTest, getNodeAttributeTest) {
float ref_array[11] = { 1.0,
0.44407997,
0.43766347,
0.42827705,
0.41342604,
0.42804748,
0.44152543,
0.40502965,
0.38635802,
1.0,
0.96745253 };
error = ENR_getNodeAttribute(p_handle, 1, ENR_quality, &array, &array_dim);
ASSERT_EQ(0, error);
for (int i = 0; i < array_dim; i++)
EXPECT_FLOAT_EQ(ref_array[i], array[i]);
}
TEST_F(OutputapiTest, getLinkAttributeTest) {
float ref_array[13] = { 1848.5812,
1220.4274,
130.11162,
187.6893,
119.8884,
40.464489,
-748.58112,
478.15378,
191.73459,
30.111609,
140.46449,
59.535515,
1848.5812};
error = ENR_getLinkAttribute(p_handle, 1, ENR_flow, &array ,&array_dim);
ASSERT_EQ(0, error);
for (int i = 0; i < array_dim; i++)
EXPECT_FLOAT_EQ(ref_array[i], array[i]);
}
TEST_F(OutputapiTest, getNodeResultTest) {
float ref_array[4] = {0.041142918,
150.0,
987.98358,
120.45029};
error = ENR_getNodeResult(p_handle, 1, 2, &array, &array_dim);
ASSERT_EQ(0, error);
for (int i = 0; i < array_dim; i++)
EXPECT_FLOAT_EQ(ref_array[i], array[i]);
}
TEST_F(OutputapiTest, getLinkResultTest) {
float ref_array[8] = {0.58586824,
1892.2433,
0.0,
-200.71875,
1.0,
3.0,
1.0,
0.0};
error = ENR_getLinkResult(p_handle, 24, 13, &array, &array_dim);
ASSERT_EQ(0, error);
for (int i = 0; i < array_dim; i++)
EXPECT_FLOAT_EQ(ref_array[i], array[i]);
}
TEST_F(OutputapiTest, getNodeSeriesTest){
float ref_array[10] = {119.25731,
120.45029,
121.19854,
122.00622,
122.37414,
122.8122,
122.82034,
122.90379,
123.40434,
123.81807};
error = ENR_getNodeSeries(p_handle, 2, ENR_pressure, 0, 10, &array, &array_dim);
ASSERT_EQ(0, error);
for (int i = 0; i < array_dim; i++)
EXPECT_FLOAT_EQ(ref_array[i], array[i]);
}
TEST_F(OutputapiTest, getLinkSeriesTest) {
float ref_array[10] = {1234.2072,
1220.4274,
1164.4,
1154.8175,
1100.0635,
1094.759,
1041.7854,
1040.7617,
1087.556,
1082.5011};
error = ENR_getLinkSeries(p_handle, 2, ENR_flow, 0, 10, &array, &array_dim);
ASSERT_EQ(0, error);
for (int i = 0; i < array_dim; i++)
EXPECT_FLOAT_EQ(ref_array[i], array[i]);
}
TEST_F(OutputapiTest, getNetReactsTest) {
float ref_array[4] = {18806.59,
85424.438,
115174.05,
238972.66};
error = ENR_getNetReacts(p_handle, &array, &array_dim);
ASSERT_EQ(0, error);
for (int i = 0; i < array_dim; i++)
EXPECT_FLOAT_EQ(ref_array[i], array[i]);
}
TEST_F(OutputapiTest, getEnergyUsageTest) {
float ref_array[6] = {57.712959,
75.0,
880.41583,
96.254318,
96.707115,
0.0};
int linkIdx;
error = ENR_getEnergyUsage(p_handle, 1, &linkIdx, &array, &array_dim);
ASSERT_EQ(0, error);
for (int i = 0; i < array_dim; i++)
EXPECT_FLOAT_EQ(ref_array[i], array[i]);
}
}
GTEST_API_ int main(int argc, char **argv) {
printf("Running main() from gtest_main.cc\n");
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}