diff --git a/include/epanet2.bas b/include/epanet2.bas index f0ba641..ba94210 100644 --- a/include/epanet2.bas +++ b/include/epanet2.bas @@ -147,12 +147,11 @@ Public Const EN_EMITEXPON = 3 Public Const EN_DEMANDMULT = 4 Public Const EN_HEADERROR = 5 Public Const EN_FLOWCHANGE = 6 -Public Const EN_DEMANDDEFPAT = 7 -Public Const EN_HEADLOSSFORM = 8 -Public Const EN_GLOBALEFFIC = 9 -Public Const EN_GLOBALPRICE = 10 -Public Const EN_GLOBALPATTERN = 11 -Public Const EN_DEMANDCHARGE = 12 +Public Const EN_HEADLOSSFORM = 7 +Public Const EN_GLOBALEFFIC = 8 +Public Const EN_GLOBALPRICE = 9 +Public Const EN_GLOBALPATTERN = 10 +Public Const EN_DEMANDCHARGE = 11 Public Const EN_LOWLEVEL = 0 ' Control types Public Const EN_HILEVEL = 1 diff --git a/include/epanet2.vb b/include/epanet2.vb index b4345eb..6f71b26 100644 --- a/include/epanet2.vb +++ b/include/epanet2.vb @@ -152,12 +152,11 @@ Public Const EN_EMITEXPON = 3 Public Const EN_DEMANDMULT = 4 Public Const EN_HEADERROR = 5 Public Const EN_FLOWCHANGE = 6 -Public Const EN_DEMANDDEFPAT = 7 -Public Const EN_HEADLOSSFORM = 8 -Public Const EN_GLOBALEFFIC = 9 -Public Const EN_GLOBALPRICE = 10 -Public Const EN_GLOBALPATTERN = 11 -Public Const EN_DEMANDCHARGE = 12 +Public Const EN_HEADLOSSFORM = 7 +Public Const EN_GLOBALEFFIC = 8 +Public Const EN_GLOBALPRICE = 9 +Public Const EN_GLOBALPATTERN = 10 +Public Const EN_DEMANDCHARGE = 11 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 558d670..fa00688 100644 --- a/include/epanet2_enums.h +++ b/include/epanet2_enums.h @@ -9,7 +9,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 03/17/2019 + Last Updated: 04/03/2019 ****************************************************************************** */ @@ -294,12 +294,11 @@ typedef enum { EN_DEMANDMULT = 4, //!< Global demand multiplier EN_HEADERROR = 5, //!< Maximum head loss error for hydraulic convergence EN_FLOWCHANGE = 6, //!< Maximum flow change for hydraulic convergence - EN_DEFDEMANDPAT = 7, //!< Index of the default demand time pattern - EN_HEADLOSSFORM = 8, //!< Head loss formula (see @ref EN_HeadLossType) - EN_GLOBALEFFIC = 9, //!< Global pump efficiency (percent) - EN_GLOBALPRICE = 10, //!< Global energy price per KWH - EN_GLOBALPATTERN = 11, //!< Index of a global energy price pattern - EN_DEMANDCHARGE = 12 //!< Energy charge per max. KW usage + EN_HEADLOSSFORM = 7, //!< Head loss formula (see @ref EN_HeadLossType) + EN_GLOBALEFFIC = 8, //!< Global pump efficiency (percent) + EN_GLOBALPRICE = 9, //!< Global energy price per KWH + EN_GLOBALPATTERN = 10, //!< Index of a global energy price pattern + EN_DEMANDCHARGE = 11 //!< Energy charge per max. KW usage } EN_Option; /// Types of simple controls diff --git a/src/epanet.c b/src/epanet.c index 8942f6e..e2f1d4f 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -7,7 +7,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 04/02/2019 + Last Updated: 04/03/2019 ****************************************************************************** */ @@ -1116,9 +1116,6 @@ int DLLEXPORT EN_getoption(EN_Project p, int option, double *value) case EN_FLOWCHANGE: v = hyd->FlowChangeLimit * Ucf[FLOW]; break; - case EN_DEFDEMANDPAT: - v = hyd->DefPat; - break; case EN_HEADLOSSFORM: v = hyd->Formflag; break; @@ -1156,13 +1153,9 @@ int DLLEXPORT EN_setoption(EN_Project p, int option, double value) Hydraul *hyd = &p->hydraul; Quality *qual = &p->quality; - Snode *node; - Pdemand demand; - const int Njuncs = net->Njuncs; + int Njuncs = net->Njuncs; double *Ucf = p->Ucf; - int i, j; - int tmpPat, pat, error; - char tmpId[MAXID + 1]; + int i, j, pat; double Ke, n, ucf; if (!p->Openflag) return 102; @@ -1210,36 +1203,14 @@ int DLLEXPORT EN_setoption(EN_Project p, int option, double value) hyd->FlowChangeLimit = value / Ucf[FLOW]; break; - case EN_DEFDEMANDPAT: - //check that the pattern exists or is set to zero to delete the default pattern - pat = ROUND(value); - if (pat < 0 || pat > net->Npats) return 205; - tmpPat = hyd->DefPat; - //get the new pattern ID - if (pat == 0) - { - strncpy(tmpId, p->parser.DefPatID, MAXID); - } - else - { - error = EN_getpatternid(p, pat, tmpId); - if (error != 0) return error; - } - // replace node patterns with default pattern - for (i = 1; i <= net->Nnodes; i++) - { - node = &net->Node[i]; - for (demand = node->D; demand != NULL; demand = demand->next) - { - if (demand->Pat == tmpPat) - { - demand->Pat = pat; - demand->Name = xstrcpy(&demand->Name, "", MAXMSG); - } - } - } - strncpy(p->parser.DefPatID, tmpId, MAXID); - hyd->DefPat = pat; + case EN_HEADLOSSFORM: + // Can't change if hydraulic solver is open + if (p->hydraul.OpenHflag) return 262; + i = ROUND(value); + if (i < HW || i > CM) return 213; + hyd->Formflag = i; + if (hyd->Formflag == HW) hyd->Hexp = 1.852; + else hyd->Hexp = 2.0; break; case EN_GLOBALEFFIC: @@ -1700,7 +1671,7 @@ int DLLEXPORT EN_addnode(EN_Project p, char *id, int nodeType) demand = (struct Sdemand *)malloc(sizeof(struct Sdemand)); demand->Base = 0.0; - demand->Pat = hyd->DefPat; // Use default pattern + demand->Pat = 0; demand->Name = NULL; demand->next = NULL; node->D = demand; @@ -3917,9 +3888,6 @@ int DLLEXPORT EN_addpattern(EN_Project p, char *id) // Update the number of patterns net->Npats = n; parser->MaxPats = n; - - // Make new pattern be default demand pattern if name matches - if (strcmp(id, parser->DefPatID) == 0) hyd->DefPat = n; return 0; } @@ -3948,14 +3916,6 @@ int DLLEXPORT EN_deletepattern(EN_Project p, int index) // Adjust references by other objects to patterns adjustpatterns(net, index); - // Modify default demand pattern - if (hyd->DefPat == index) - { - hyd->DefPat = 0; - strcpy(parser->DefPatID, ""); - } - else if (hyd->DefPat > index) hyd->DefPat--; - // Modify global energy price pattern if (hyd->Epat == index) hyd->Epat = 0; else if (hyd->Epat > index) hyd->Epat--; diff --git a/src/inpfile.c b/src/inpfile.c index 8aa3c52..509a255 100644 --- a/src/inpfile.c +++ b/src/inpfile.c @@ -7,7 +7,7 @@ Description: saves network data to an EPANET formatted text file Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE -Last Updated: 04/02/2019 +Last Updated: 04/03/2019 ****************************************************************************** */ @@ -633,10 +633,6 @@ int saveinpfile(Project *pr, const char *fname) fprintf(f, "\n UNITS %s", FlowUnitsTxt[parser->Flowflag]); fprintf(f, "\n PRESSURE %s", PressUnitsTxt[parser->Pressflag]); fprintf(f, "\n HEADLOSS %s", FormTxt[hyd->Formflag]); - if (hyd->DefPat >= 1 && hyd->DefPat <= net->Npats) - { - fprintf(f, "\n PATTERN %s", net->Pattern[hyd->DefPat].ID); - } switch (out->Hydflag) { case USE: diff --git a/src/input1.c b/src/input1.c index fe606d9..1516a44 100644 --- a/src/input1.c +++ b/src/input1.c @@ -7,7 +7,7 @@ Description: retrieves network data from an EPANET input file Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE -Last Updated: 03/17/2019 +Last Updated: 04/03/2019 ****************************************************************************** */ @@ -100,6 +100,7 @@ void setdefaults(Project *pr) parser->Unitsflag = US; // US unit system parser->Flowflag = GPM; // Flow units are gpm parser->Pressflag = PSI; // Pressure units are psi + parser->DefPat = 0; // Default demand pattern index out->Hydflag = SCRATCH; // No external hydraulics file rpt->Tstatflag = SERIES; // Generate time series output @@ -117,7 +118,6 @@ void setdefaults(Project *pr) hyd->ExtraIter = -1; // Stop if network unbalanced hyd->Viscos = MISSING; // Temporary viscosity hyd->SpGrav = SPGRAV; // Default specific gravity - hyd->DefPat = 0; // Default demand pattern index hyd->Epat = 0; // No energy price pattern hyd->Ecost = 0.0; // Zero unit energy cost hyd->Dcost = 0.0; // Zero energy demand charge @@ -326,16 +326,12 @@ void adjustdata(Project *pr) } // Use default pattern if none assigned to a demand - for (i = 1; i <= net->Nnodes; i++) + if (parser->DefPat > 0) for (i = 1; i <= net->Nnodes; i++) { node = &net->Node[i]; for (demand = node->D; demand != NULL; demand = demand->next) { - if (demand->Pat == 0) - { - demand->Pat = hyd->DefPat; - xstrcpy(&demand->Name, "", MAXMSG); - } + if (demand->Pat == 0) demand->Pat = parser->DefPat; } } diff --git a/src/input2.c b/src/input2.c index f1d0c9f..b337e5a 100644 --- a/src/input2.c +++ b/src/input2.c @@ -7,7 +7,7 @@ Description: reads and interprets network data from an EPANET input file Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE -Last Updated: 04/02/2019 +Last Updated: 04/03/2019 ****************************************************************************** */ @@ -649,7 +649,7 @@ int getpatterns(Project *pr) i = tmppattern->i; // Check if this is the default pattern - if (strcmp(tmppattern->ID, parser->DefPatID) == 0) hyd->DefPat = i; + if (strcmp(tmppattern->ID, parser->DefPatID) == 0) parser->DefPat = i; // Copy temporary patttern to network's pattern if (i >= 0 && i <= parser->MaxPats) diff --git a/src/types.h b/src/types.h index 4329414..0f574ce 100755 --- a/src/types.h +++ b/src/types.h @@ -7,7 +7,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 03/17/2019 + Last Updated: 04/03/2019 ****************************************************************************** */ @@ -573,7 +573,8 @@ typedef struct { ErrTok, // Index of error-producing token Unitsflag, // Unit system flag Flowflag, // Flow units flag - Pressflag; // Pressure units flag + Pressflag, // Pressure units flag + DefPat; // Default demand pattern STmplist *Patlist, // Temporary time pattern list @@ -738,7 +739,6 @@ typedef struct { *Xflow; // Inflow - outflow at each node int - DefPat, // Default demand pattern Epat, // Energy cost time pattern DemandModel, // Fixed or pressure dependent Formflag, // Head loss formula flag diff --git a/tests/test_analysis.cpp b/tests/test_analysis.cpp index f7120f1..dfdbc13 100644 --- a/tests/test_analysis.cpp +++ b/tests/test_analysis.cpp @@ -22,10 +22,10 @@ BOOST_AUTO_TEST_SUITE (test_analysis) BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose) { int i; - double array[13]; + double array[12]; std::vector test; - std::vector ref = {40.0, 0.001, 0.01, 0.5, 1.0, 0.0, 0.0, 1.0, 0.0, 75.0, 0.0, 0.0, 0.0}; + 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}; error = EN_solveH(ph); BOOST_REQUIRE(error == 0); @@ -39,7 +39,7 @@ BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose) BOOST_REQUIRE(error == 0); } - test.assign(array, array + 13); + test.assign(array, array + 12); BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end()); error = EN_getoption(ph, 18, &array[0]); diff --git a/tests/test_net_builder.cpp b/tests/test_net_builder.cpp index 5c6f274..56efa8d 100644 --- a/tests/test_net_builder.cpp +++ b/tests/test_net_builder.cpp @@ -121,8 +121,8 @@ BOOST_FIXTURE_TEST_CASE(test_build_net1, FixtureInitClose) BOOST_REQUIRE(error == 0); error = EN_setpattern(ph, 1, P, 12); BOOST_REQUIRE(error == 0); - error = EN_setoption(ph, EN_DEFDEMANDPAT, 1); - BOOST_REQUIRE(error == 0); + //error = EN_setoption(ph, EN_DEFDEMANDPAT, 1); + //BOOST_REQUIRE(error == 0); for (i = 0; i < 9; i++) { error = EN_addnode(ph, juncs[i], EN_JUNCTION); @@ -131,6 +131,8 @@ BOOST_FIXTURE_TEST_CASE(test_build_net1, FixtureInitClose) BOOST_REQUIRE(error == 0); error = EN_setnodevalue(ph, i + 1, EN_BASEDEMAND, d[i]); BOOST_REQUIRE(error == 0); + error = EN_setnodevalue(ph, i+1, EN_PATTERN, 1); + BOOST_REQUIRE(error == 0); error = EN_setcoord(ph, i + 1, X[i], Y[i]); BOOST_REQUIRE(error == 0); //error = EN_setdemandpattern(ph, i + 1, 1, 1); diff --git a/tests/test_pattern.cpp b/tests/test_pattern.cpp index 674ea76..bedad48 100644 --- a/tests/test_pattern.cpp +++ b/tests/test_pattern.cpp @@ -33,12 +33,9 @@ BOOST_AUTO_TEST_CASE(add_set_pattern) error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), ""); BOOST_REQUIRE(error == 0); - // Get the default pattern index - double dblPatIdx; - int defPatIdx; + // Assign the default pattern index + int defPatIdx = 1; int patIdx; - EN_getoption(ph, EN_DEFDEMANDPAT, &dblPatIdx); - defPatIdx = (int)dblPatIdx; // Rename the default pattern EN_setpatternid(ph, defPatIdx, (char *)"Pat1");