Merge pull request #443 from OpenWaterAnalytics/lrossman-dev17

Removed the EN_DEFDEMANDPAT option
This commit is contained in:
Michael Tryby
2019-04-03 16:35:47 -04:00
committed by GitHub
11 changed files with 47 additions and 99 deletions

View File

@@ -147,12 +147,11 @@ Public Const EN_EMITEXPON = 3
Public Const EN_DEMANDMULT = 4 Public Const EN_DEMANDMULT = 4
Public Const EN_HEADERROR = 5 Public Const EN_HEADERROR = 5
Public Const EN_FLOWCHANGE = 6 Public Const EN_FLOWCHANGE = 6
Public Const EN_DEMANDDEFPAT = 7 Public Const EN_HEADLOSSFORM = 7
Public Const EN_HEADLOSSFORM = 8 Public Const EN_GLOBALEFFIC = 8
Public Const EN_GLOBALEFFIC = 9 Public Const EN_GLOBALPRICE = 9
Public Const EN_GLOBALPRICE = 10 Public Const EN_GLOBALPATTERN = 10
Public Const EN_GLOBALPATTERN = 11 Public Const EN_DEMANDCHARGE = 11
Public Const EN_DEMANDCHARGE = 12
Public Const EN_LOWLEVEL = 0 ' Control types Public Const EN_LOWLEVEL = 0 ' Control types
Public Const EN_HILEVEL = 1 Public Const EN_HILEVEL = 1

View File

@@ -152,12 +152,11 @@ Public Const EN_EMITEXPON = 3
Public Const EN_DEMANDMULT = 4 Public Const EN_DEMANDMULT = 4
Public Const EN_HEADERROR = 5 Public Const EN_HEADERROR = 5
Public Const EN_FLOWCHANGE = 6 Public Const EN_FLOWCHANGE = 6
Public Const EN_DEMANDDEFPAT = 7 Public Const EN_HEADLOSSFORM = 7
Public Const EN_HEADLOSSFORM = 8 Public Const EN_GLOBALEFFIC = 8
Public Const EN_GLOBALEFFIC = 9 Public Const EN_GLOBALPRICE = 9
Public Const EN_GLOBALPRICE = 10 Public Const EN_GLOBALPATTERN = 10
Public Const EN_GLOBALPATTERN = 11 Public Const EN_DEMANDCHARGE = 11
Public Const EN_DEMANDCHARGE = 12
Public Const EN_LOWLEVEL = 0 ' Control types Public Const EN_LOWLEVEL = 0 ' Control types
Public Const EN_HILEVEL = 1 Public Const EN_HILEVEL = 1

View File

@@ -9,7 +9,7 @@
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE 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_DEMANDMULT = 4, //!< Global demand multiplier
EN_HEADERROR = 5, //!< Maximum head loss error for hydraulic convergence EN_HEADERROR = 5, //!< Maximum head loss error for hydraulic convergence
EN_FLOWCHANGE = 6, //!< Maximum flow change for hydraulic convergence EN_FLOWCHANGE = 6, //!< Maximum flow change for hydraulic convergence
EN_DEFDEMANDPAT = 7, //!< Index of the default demand time pattern EN_HEADLOSSFORM = 7, //!< Head loss formula (see @ref EN_HeadLossType)
EN_HEADLOSSFORM = 8, //!< Head loss formula (see @ref EN_HeadLossType) EN_GLOBALEFFIC = 8, //!< Global pump efficiency (percent)
EN_GLOBALEFFIC = 9, //!< Global pump efficiency (percent) EN_GLOBALPRICE = 9, //!< Global energy price per KWH
EN_GLOBALPRICE = 10, //!< Global energy price per KWH EN_GLOBALPATTERN = 10, //!< Index of a global energy price pattern
EN_GLOBALPATTERN = 11, //!< Index of a global energy price pattern EN_DEMANDCHARGE = 11 //!< Energy charge per max. KW usage
EN_DEMANDCHARGE = 12 //!< Energy charge per max. KW usage
} EN_Option; } EN_Option;
/// Types of simple controls /// Types of simple controls

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE 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: case EN_FLOWCHANGE:
v = hyd->FlowChangeLimit * Ucf[FLOW]; v = hyd->FlowChangeLimit * Ucf[FLOW];
break; break;
case EN_DEFDEMANDPAT:
v = hyd->DefPat;
break;
case EN_HEADLOSSFORM: case EN_HEADLOSSFORM:
v = hyd->Formflag; v = hyd->Formflag;
break; break;
@@ -1156,13 +1153,9 @@ int DLLEXPORT EN_setoption(EN_Project p, int option, double value)
Hydraul *hyd = &p->hydraul; Hydraul *hyd = &p->hydraul;
Quality *qual = &p->quality; Quality *qual = &p->quality;
Snode *node; int Njuncs = net->Njuncs;
Pdemand demand;
const int Njuncs = net->Njuncs;
double *Ucf = p->Ucf; double *Ucf = p->Ucf;
int i, j; int i, j, pat;
int tmpPat, pat, error;
char tmpId[MAXID + 1];
double Ke, n, ucf; double Ke, n, ucf;
if (!p->Openflag) return 102; 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]; hyd->FlowChangeLimit = value / Ucf[FLOW];
break; break;
case EN_DEFDEMANDPAT: case EN_HEADLOSSFORM:
//check that the pattern exists or is set to zero to delete the default pattern // Can't change if hydraulic solver is open
pat = ROUND(value); if (p->hydraul.OpenHflag) return 262;
if (pat < 0 || pat > net->Npats) return 205; i = ROUND(value);
tmpPat = hyd->DefPat; if (i < HW || i > CM) return 213;
//get the new pattern ID hyd->Formflag = i;
if (pat == 0) if (hyd->Formflag == HW) hyd->Hexp = 1.852;
{ else hyd->Hexp = 2.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;
break; break;
case EN_GLOBALEFFIC: 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 = (struct Sdemand *)malloc(sizeof(struct Sdemand));
demand->Base = 0.0; demand->Base = 0.0;
demand->Pat = hyd->DefPat; // Use default pattern demand->Pat = 0;
demand->Name = NULL; demand->Name = NULL;
demand->next = NULL; demand->next = NULL;
node->D = demand; node->D = demand;
@@ -3917,9 +3888,6 @@ int DLLEXPORT EN_addpattern(EN_Project p, char *id)
// Update the number of patterns // Update the number of patterns
net->Npats = n; net->Npats = n;
parser->MaxPats = 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; return 0;
} }
@@ -3948,14 +3916,6 @@ int DLLEXPORT EN_deletepattern(EN_Project p, int index)
// Adjust references by other objects to patterns // Adjust references by other objects to patterns
adjustpatterns(net, index); 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 // Modify global energy price pattern
if (hyd->Epat == index) hyd->Epat = 0; if (hyd->Epat == index) hyd->Epat = 0;
else if (hyd->Epat > index) hyd->Epat--; else if (hyd->Epat > index) hyd->Epat--;

View File

@@ -7,7 +7,7 @@ Description: saves network data to an EPANET formatted text file
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE 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 UNITS %s", FlowUnitsTxt[parser->Flowflag]);
fprintf(f, "\n PRESSURE %s", PressUnitsTxt[parser->Pressflag]); fprintf(f, "\n PRESSURE %s", PressUnitsTxt[parser->Pressflag]);
fprintf(f, "\n HEADLOSS %s", FormTxt[hyd->Formflag]); 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) switch (out->Hydflag)
{ {
case USE: case USE:

View File

@@ -7,7 +7,7 @@ Description: retrieves network data from an EPANET input file
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE 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->Unitsflag = US; // US unit system
parser->Flowflag = GPM; // Flow units are gpm parser->Flowflag = GPM; // Flow units are gpm
parser->Pressflag = PSI; // Pressure units are psi parser->Pressflag = PSI; // Pressure units are psi
parser->DefPat = 0; // Default demand pattern index
out->Hydflag = SCRATCH; // No external hydraulics file out->Hydflag = SCRATCH; // No external hydraulics file
rpt->Tstatflag = SERIES; // Generate time series output rpt->Tstatflag = SERIES; // Generate time series output
@@ -117,7 +118,6 @@ void setdefaults(Project *pr)
hyd->ExtraIter = -1; // Stop if network unbalanced hyd->ExtraIter = -1; // Stop if network unbalanced
hyd->Viscos = MISSING; // Temporary viscosity hyd->Viscos = MISSING; // Temporary viscosity
hyd->SpGrav = SPGRAV; // Default specific gravity hyd->SpGrav = SPGRAV; // Default specific gravity
hyd->DefPat = 0; // Default demand pattern index
hyd->Epat = 0; // No energy price pattern hyd->Epat = 0; // No energy price pattern
hyd->Ecost = 0.0; // Zero unit energy cost hyd->Ecost = 0.0; // Zero unit energy cost
hyd->Dcost = 0.0; // Zero energy demand charge 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 // 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]; node = &net->Node[i];
for (demand = node->D; demand != NULL; demand = demand->next) for (demand = node->D; demand != NULL; demand = demand->next)
{ {
if (demand->Pat == 0) if (demand->Pat == 0) demand->Pat = parser->DefPat;
{
demand->Pat = hyd->DefPat;
xstrcpy(&demand->Name, "", MAXMSG);
}
} }
} }

View File

@@ -7,7 +7,7 @@ Description: reads and interprets network data from an EPANET input file
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE License: see LICENSE
Last Updated: 04/02/2019 Last Updated: 04/03/2019
****************************************************************************** ******************************************************************************
*/ */
@@ -649,7 +649,7 @@ int getpatterns(Project *pr)
i = tmppattern->i; i = tmppattern->i;
// Check if this is the default pattern // 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 // Copy temporary patttern to network's pattern
if (i >= 0 && i <= parser->MaxPats) if (i >= 0 && i <= parser->MaxPats)

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE 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 ErrTok, // Index of error-producing token
Unitsflag, // Unit system flag Unitsflag, // Unit system flag
Flowflag, // Flow units flag Flowflag, // Flow units flag
Pressflag; // Pressure units flag Pressflag, // Pressure units flag
DefPat; // Default demand pattern
STmplist STmplist
*Patlist, // Temporary time pattern list *Patlist, // Temporary time pattern list
@@ -738,7 +739,6 @@ typedef struct {
*Xflow; // Inflow - outflow at each node *Xflow; // Inflow - outflow at each node
int int
DefPat, // Default demand pattern
Epat, // Energy cost time pattern Epat, // Energy cost time pattern
DemandModel, // Fixed or pressure dependent DemandModel, // Fixed or pressure dependent
Formflag, // Head loss formula flag Formflag, // Head loss formula flag

View File

@@ -22,10 +22,10 @@ BOOST_AUTO_TEST_SUITE (test_analysis)
BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose) BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose)
{ {
int i; int i;
double array[13]; double array[12];
std::vector<double> test; std::vector<double> test;
std::vector<double> 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<double> 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); error = EN_solveH(ph);
BOOST_REQUIRE(error == 0); BOOST_REQUIRE(error == 0);
@@ -39,7 +39,7 @@ BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose)
BOOST_REQUIRE(error == 0); 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()); BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
error = EN_getoption(ph, 18, &array[0]); error = EN_getoption(ph, 18, &array[0]);

View File

@@ -121,8 +121,8 @@ BOOST_FIXTURE_TEST_CASE(test_build_net1, FixtureInitClose)
BOOST_REQUIRE(error == 0); BOOST_REQUIRE(error == 0);
error = EN_setpattern(ph, 1, P, 12); error = EN_setpattern(ph, 1, P, 12);
BOOST_REQUIRE(error == 0); BOOST_REQUIRE(error == 0);
error = EN_setoption(ph, EN_DEFDEMANDPAT, 1); //error = EN_setoption(ph, EN_DEFDEMANDPAT, 1);
BOOST_REQUIRE(error == 0); //BOOST_REQUIRE(error == 0);
for (i = 0; i < 9; i++) for (i = 0; i < 9; i++)
{ {
error = EN_addnode(ph, juncs[i], EN_JUNCTION); error = EN_addnode(ph, juncs[i], EN_JUNCTION);
@@ -131,6 +131,8 @@ BOOST_FIXTURE_TEST_CASE(test_build_net1, FixtureInitClose)
BOOST_REQUIRE(error == 0); BOOST_REQUIRE(error == 0);
error = EN_setnodevalue(ph, i + 1, EN_BASEDEMAND, d[i]); error = EN_setnodevalue(ph, i + 1, EN_BASEDEMAND, d[i]);
BOOST_REQUIRE(error == 0); 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]); error = EN_setcoord(ph, i + 1, X[i], Y[i]);
BOOST_REQUIRE(error == 0); BOOST_REQUIRE(error == 0);
//error = EN_setdemandpattern(ph, i + 1, 1, 1); //error = EN_setdemandpattern(ph, i + 1, 1, 1);

View File

@@ -33,12 +33,9 @@ BOOST_AUTO_TEST_CASE(add_set_pattern)
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), ""); error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), "");
BOOST_REQUIRE(error == 0); BOOST_REQUIRE(error == 0);
// Get the default pattern index // Assign the default pattern index
double dblPatIdx; int defPatIdx = 1;
int defPatIdx;
int patIdx; int patIdx;
EN_getoption(ph, EN_DEFDEMANDPAT, &dblPatIdx);
defPatIdx = (int)dblPatIdx;
// Rename the default pattern // Rename the default pattern
EN_setpatternid(ph, defPatIdx, (char *)"Pat1"); EN_setpatternid(ph, defPatIdx, (char *)"Pat1");