Removed the EN_DEFDEMANDPAT option

See issue #429. Also allowed the EN_HEADLOSSFORM option to be changed if the solver is not active.
This commit is contained in:
Lew Rossman
2019-04-03 10:25:37 -04:00
parent 23b11ab672
commit 83ffc1cfc7
9 changed files with 40 additions and 94 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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--;

View File

@@ -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:

View File

@@ -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;
}
}

View File

@@ -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)

View File

@@ -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

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(), "");
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");