diff --git a/doc/input-file.dox b/doc/input-file.dox index be4c977..1c35f6f 100644 --- a/doc/input-file.dox +++ b/doc/input-file.dox @@ -279,6 +279,7 @@ __Formats:__ + @@ -321,6 +322,8 @@ __Definitions:__ For CFS, GPM, MGD, IMGD, and AFD other input quantities are expressed in US Customary Units. If flow units are in liters or cubic meters then Metric Units must be used for all other input quantities as well. (See the @ref Units topic). The default flow units are \b GPM. +\b PRESSURE sets the units in which pressure is expressed, for networks using metric units, as determined by the \b UNITS option, the choices are: (\b KPA), or (\b METERS). For networks using US Customary Units, you can only use (\b PSI). + \b HEADLOSS selects a formula to use for computing head loss for flow through a pipe. The choices are the Hazen-Williams (\b H-W ), Darcy-Weisbach (\b D-W ), or Chezy-Manning (\b C-M ) formulas. The default is \b H-W. The \b HYDRAULICS option allows you to either SAVE the current hydraulics solution to a file or \b USE a previously saved hydraulics solution. This is useful when studying factors that only affect water quality behavior. diff --git a/doc/modules.dox b/doc/modules.dox index 249c0ec..a2ad22e 100644 --- a/doc/modules.dox +++ b/doc/modules.dox @@ -289,6 +289,7 @@ These are the toolkit's enumerated types whose members are used as function argu \enum EN_TimeParameter \enum EN_Option \enum EN_FlowUnits +\enum EN_PressUnits \enum EN_DemandModel \enum EN_MixingModel \enum EN_StatisticType diff --git a/doc/toolkit-units.dox b/doc/toolkit-units.dox index 259726e..db30aa2 100644 --- a/doc/toolkit-units.dox +++ b/doc/toolkit-units.dox @@ -25,7 +25,7 @@ The toolkit can use data expressed in either US Customary of SI Metric units. A |Length | feet | meters | |Minor Loss Coeff. | unitless | unitless | |Power | horsepower | kwatts | -|Pressure | psi | meters | +|Pressure | psi | meters or kPa | |Reaction Coeff. (Bulk) | 1/day (1st-order)| 1/day (1st-order) | |Reaction Coeff. (Wall) | mass/sq-ft/day (0-order) | mass/sq-m/day (0-order) | | | ft/day (1st-order) | meters/day (1st-order) | diff --git a/include/epanet.cs b/include/epanet.cs index f3283b8..c9cb2d4 100644 --- a/include/epanet.cs +++ b/include/epanet.cs @@ -157,6 +157,10 @@ namespace EpanetCSharpLibrary public const int EN_CMD = 9; public const int EN_CMS = 10; + public const int EN_PSI = 0; //Pressure units types + public const int EN_KPA = 1; + public const int EN_METERS = 2; + public const int EN_DDA = 0; //Demand driven analysis public const int EN_PDA = 1; //Pressure driven analysis @@ -185,6 +189,7 @@ namespace EpanetCSharpLibrary public const int EN_CONCENLIMIT = 22; public const int EN_DEMANDPATTERN = 23; public const int EN_EMITBACKFLOW = 24; + public const int EN_PRESS_UNITS = 25; public const int EN_LOWLEVEL = 0; //Control types public const int EN_HILEVEL = 1; diff --git a/include/epanet2.bas b/include/epanet2.bas index 74e1d09..63e5db3 100644 --- a/include/epanet2.bas +++ b/include/epanet2.bas @@ -154,6 +154,10 @@ Public Const EN_CMH = 8 Public Const EN_CMD = 9 Public Const EN_CMS = 10 +Public Const EN_PSI = 0 ' Pressure units types +Public Const EN_KPA = 1 +Public Const EN_METERS = 2 + Public Const EN_DDA = 0 ' Demand driven analysis Public Const EN_PDA = 1 ' Pressure driven analysis @@ -182,6 +186,7 @@ Public Const EN_TANKORDER = 21 Public Const EN_CONCENLIMIT = 22 Public Const EN_DEMANDPATTERN = 23 Public Const EN_EMITBACKFLOW = 24 +Public Const EN_PRESS_UNITS = 25 Public Const EN_LOWLEVEL = 0 ' Control types Public Const EN_HILEVEL = 1 diff --git a/include/epanet2.vb b/include/epanet2.vb index e05e1d5..daf5703 100644 --- a/include/epanet2.vb +++ b/include/epanet2.vb @@ -149,6 +149,10 @@ Public Const EN_CMH = 8 Public Const EN_CMD = 9 Public Const EN_CMS = 10 +Public Const EN_PSI = 0 ' Pressure units types +Public Const EN_KPA = 1 +Public Const EN_METERS = 2 + Public Const EN_DDA = 0 ' Demand driven analysis Public Const EN_PDA = 1 ' Pressure driven analysis @@ -177,6 +181,7 @@ Public Const EN_TANKORDER = 21 Public Const EN_CONCENLIMIT = 22 Public Const EN_DEMANDPATTERN = 23 Public Const EN_EMITBACKFLOW = 24 +Public Const EN_PRESS_UNITS = 25 Public Const EN_LOWLEVEL = 0 ' Control types Public Const EN_HILEVEL = 1 diff --git a/include/epanet2_enums.h b/include/epanet2_enums.h index ff62b38..4263eb6 100644 --- a/include/epanet2_enums.h +++ b/include/epanet2_enums.h @@ -291,6 +291,19 @@ typedef enum { EN_CMS = 10 //!< Cubic meters per second } EN_FlowUnits; +/// Pressure units +/** +The available choices for pressure units for the \b EN_PRESS_UNITS option in @ref EN_getoption +and @ref EN_setoption. For networks using US Customary units for flow ( \b EN_CFS through +\b EN_AFD ) pressure units can only be set as PSI. For network using metric units, you can +select either \b EN_MTR or \b EN_KPA. +*/ +typedef enum { + EN_PSI = 0, //!< Pounds per square inch + EN_KPA = 1, //!< Kilopascals + EN_METERS = 2 //!< Meters +} EN_PressUnits; + /// Demand models /** These choices for modeling consumer demands are used with @ref EN_getdemandmodel @@ -337,7 +350,8 @@ typedef enum { EN_TANKORDER = 21, //!< Bulk water reaction order for tanks EN_CONCENLIMIT = 22, //!< Limiting concentration for growth reactions EN_DEMANDPATTERN = 23, //!< Name of default demand pattern - EN_EMITBACKFLOW = 24 //!< 1 if emitters can backflow, 0 if not + EN_EMITBACKFLOW = 24, //!< 1 if emitters can backflow, 0 if not + EN_PRESS_UNITS = 25 //!< Pressure units (see @ref EN_PressUnits) } EN_Option; /// Simple control types diff --git a/src/epanet.c b/src/epanet.c index 115e87a..b4027cb 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -1208,6 +1208,9 @@ int DLLEXPORT EN_getoption(EN_Project p, int option, double *value) case EN_EMITBACKFLOW: v = hyd->EmitBackFlag; break; + case EN_PRESS_UNITS: + v = (double)p->parser.Pressflag; + break; default: return 251; } @@ -1231,7 +1234,7 @@ int DLLEXPORT EN_setoption(EN_Project p, int option, double value) int Njuncs = net->Njuncs; double *Ucf = p->Ucf; - int i, j, pat; + int i, j, pat, unit; double Ke, n, ucf; if (!p->Openflag) return 102; @@ -1375,6 +1378,14 @@ int DLLEXPORT EN_setoption(EN_Project p, int option, double value) else return 213; break; + case EN_PRESS_UNITS: + unit = ROUND(value); + if (unit < 0 || unit > METERS) return 205; + if (p->parser.Unitsflag == US && unit > PSI) return 0; + p->parser.Pressflag = unit; + initunits(p); + break; + default: return 251; } diff --git a/tests/test_analysis.cpp b/tests/test_analysis.cpp index b3c9a93..e366cd7 100644 --- a/tests/test_analysis.cpp +++ b/tests/test_analysis.cpp @@ -23,11 +23,11 @@ BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose) { int i; - std::vector test(23); + std::vector test(26); double *array = test.data(); std::vector ref = {40.0, 0.001, 0.01, 0.5, 1.0, 0.0, 0.0, 0.0, 75.0, 0.0, 0.0, 0.0, - 1.0, 1.0, 10.0, 2.0, 10.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0}; + 1.0, 1.0, 10.0, 2.0, 10.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0}; error = EN_solveH(ph); BOOST_REQUIRE(error == 0); @@ -36,7 +36,7 @@ BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose) BOOST_REQUIRE(error == 0); - for (i=EN_TRIALS; i<=EN_CONCENLIMIT; i++) { + for (i=EN_TRIALS; i<=EN_PRESS_UNITS; i++) { error = EN_getoption(ph, i, array++); BOOST_REQUIRE(error == 0); } @@ -44,7 +44,7 @@ BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose) BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end()); double temp; - error = EN_getoption(ph, 25, &temp); + error = EN_getoption(ph, 26, &temp); BOOST_CHECK(error == 251); } diff --git a/tests/test_project.cpp b/tests/test_project.cpp index 627afbd..c1635cd 100644 --- a/tests/test_project.cpp +++ b/tests/test_project.cpp @@ -116,8 +116,79 @@ BOOST_AUTO_TEST_CASE(test_run) EN_deleteproject(ph); } -BOOST_AUTO_TEST_SUITE_END() +BOOST_FIXTURE_TEST_CASE(test_pressure_units, FixtureInitClose) +{ + int index; + long t; + double p, units; + // Create basic network + error = EN_addnode(ph, "R1", EN_RESERVOIR, &index); + BOOST_REQUIRE(error == 0); + error = EN_setnodevalue(ph, index, EN_ELEVATION, 100); + BOOST_REQUIRE(error == 0); + error = EN_addnode(ph, "J1", EN_JUNCTION, &index); + BOOST_REQUIRE(error == 0); + error = EN_addlink(ph, "P1", EN_PIPE, "R1", "J1", &index); + BOOST_REQUIRE(error == 0); + + // Run simulation and get junction pressure + error = EN_openH(ph); + BOOST_REQUIRE(error == 0); + error = EN_initH(ph, EN_NOSAVE); + BOOST_REQUIRE(error == 0); + error = EN_runH(ph, &t); + BOOST_REQUIRE(error == 0); + error = EN_getnodevalue(ph, 1, EN_PRESSURE, &p); + BOOST_REQUIRE(error == 0); + BOOST_CHECK(abs(p - 43.33) < 1.e-5); + + // Get pressure unit and check that it is PSI + error = EN_getoption(ph, EN_PRESS_UNITS, &units); + BOOST_REQUIRE(error == 0); + BOOST_CHECK(units == EN_PSI); + + // Check that pressure unit is PSI + error = EN_setoption(ph, EN_PRESS_UNITS, EN_METERS); + BOOST_REQUIRE(error == 0); + + // Change to meters and confirm that units are still PSI + error = EN_getoption(ph, EN_PRESS_UNITS, &units); + BOOST_REQUIRE(error == 0); + BOOST_CHECK(units == EN_PSI); + + // Change flow units to LPS to change to metric units and rerun simulation + error = EN_setflowunits(ph, EN_LPS); + BOOST_REQUIRE(error == 0); + error = EN_initH(ph, EN_NOSAVE); + BOOST_REQUIRE(error == 0); + error = EN_runH(ph, &t); + BOOST_REQUIRE(error == 0); + + // Confirm that pressure is now in meters + error = EN_getnodevalue(ph, 1, EN_PRESSURE, &p); + BOOST_REQUIRE(error == 0); + BOOST_CHECK(abs(p - 30.48) < 1.e-5); + error = EN_getoption(ph, EN_PRESS_UNITS, &units); + BOOST_REQUIRE(error == 0); + BOOST_CHECK(units == EN_METERS); + + // Set and check that pressure units are in kPa + error = EN_setoption(ph, EN_PRESS_UNITS, EN_KPA); + BOOST_REQUIRE(error == 0); + error = EN_getoption(ph, EN_PRESS_UNITS, &units); + BOOST_REQUIRE(error == 0); + BOOST_CHECK(units == EN_KPA); + error = EN_getnodevalue(ph, 1, EN_PRESSURE, &p); + BOOST_REQUIRE(error == 0); + BOOST_CHECK(abs(p - 298.76035) < 1.e-5); + + error = EN_closeH(ph); + BOOST_REQUIRE(error == 0); + +} + +BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE(test_proj_fixture)
UNITSCFS / GPM / MGD / IMGD / AFD /
LPS / LPM / MLD / CMS / CMH / CMD
PRESSUREPSI / KPA / METERS
HEADLOSSH-W / D-W / C-M
HYDRAULICSUSE / SAVE  filename
VISCOSITYvalue