Merge pull request #660 from OpenWaterAnalytics/dev-DefaultPatternFix

Fix for getting/setting/saving default demand pattern option
This commit is contained in:
Lew Rossman
2022-01-18 11:01:10 -05:00
committed by GitHub
7 changed files with 27 additions and 18 deletions

View File

@@ -320,7 +320,8 @@ typedef enum {
EN_BULKORDER = 19, //!< Bulk water reaction order for pipes
EN_WALLORDER = 20, //!< Wall reaction order for pipes (either 0 or 1)
EN_TANKORDER = 21, //!< Bulk water reaction order for tanks
EN_CONCENLIMIT = 22 //!< Limiting concentration for growth reactions
EN_CONCENLIMIT = 22, //!< Limiting concentration for growth reactions
EN_DEMANDPATTERN = 23 //!< Name of default demand pattern
} EN_Option;
/// Simple control types

View File

@@ -1187,7 +1187,9 @@ int DLLEXPORT EN_getoption(EN_Project p, int option, double *value)
case EN_CONCENLIMIT:
v = qual->Climit * p->Ucf[QUALITY];
break;
case EN_DEMANDPATTERN:
v = hyd->DefPat;
break;
default:
return 251;
}
@@ -1344,6 +1346,12 @@ int DLLEXPORT EN_setoption(EN_Project p, int option, double value)
qual->Climit = value / p->Ucf[QUALITY];
break;
case EN_DEMANDPATTERN:
pat = ROUND(value);
if (pat < 0 || pat > net->Npats) return 205;
hyd->DefPat = pat;
break;
default:
return 251;
}
@@ -4378,6 +4386,10 @@ int DLLEXPORT EN_deletepattern(EN_Project p, int index)
if (hyd->Epat == index) hyd->Epat = 0;
else if (hyd->Epat > index) hyd->Epat--;
// Modify global default demand pattern
if (hyd->DefPat == index) hyd->DefPat = 0;
else if (hyd->DefPat > index) hyd->DefPat--;
// Free the pattern's factor array
FREE(net->Pattern[index].F);
FREE(net->Pattern[index].Comment);

View File

@@ -485,6 +485,8 @@ void demands(Project *pr)
{
// pattern period (k) = (elapsed periods) modulus (periods per pattern)
j = demand->Pat;
if (j == 0)
j = hyd->DefPat;
k = p % (long)net->Pattern[j].Length;
djunc = (demand->Base) * net->Pattern[j].F[k] * hyd->Dmult;
if (djunc > 0.0) hyd->Dsystem += djunc;

View File

@@ -666,6 +666,8 @@ int saveinpfile(Project *pr, const char *fname)
break;
}
if (hyd->DefPat > 0)
fprintf(f, "\n PATTERN %s", net->Pattern[hyd->DefPat].ID);
fprintf(f, "\n DEMAND MULTIPLIER %-.4f", hyd->Dmult);
fprintf(f, "\n EMITTER EXPONENT %-.4f", 1.0 / hyd->Qexp);
fprintf(f, "\n VISCOSITY %-.6f", hyd->Viscos / VISCOS);

View File

@@ -97,7 +97,6 @@ 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
@@ -121,6 +120,7 @@ void setdefaults(Project *pr)
hyd->Epump = EPUMP; // Default pump efficiency
hyd->Emax = 0.0; // Zero peak energy usage
hyd->Qexp = 2.0; // Flow exponent for emitters
hyd->DefPat = 0; // Default demand pattern index
hyd->Dmult = 1.0; // Demand multiplier
hyd->RQtol = RQTOL; // Default hydraulics parameters
hyd->CheckFreq = CHECKFREQ;
@@ -212,9 +212,7 @@ void adjustdata(Project *pr)
int i;
double ucf; // Unit conversion factor
Pdemand demand; // Pointer to demand record
Slink *link;
Snode *node;
Stank *tank;
// Use 1 hr pattern & report time step if none specified
@@ -319,16 +317,10 @@ void adjustdata(Project *pr)
if (tank->Kb == MISSING) tank->Kb = qual->Kbulk;
}
// Use default pattern if none assigned to a demand
parser->DefPat = findpattern(net, parser->DefPatID);
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 = parser->DefPat;
}
}
// Set default pattern index
i = findpattern(net, parser->DefPatID);
if (i > 0)
hyd->DefPat = i;
// Remove QUALITY as a reporting variable if no WQ analysis
if (qual->Qualflag == NONE) rpt->Field[QUALITY].Enabled = FALSE;

View File

@@ -573,8 +573,7 @@ typedef struct {
ErrTok, // Index of error-producing token
Unitsflag, // Unit system flag
Flowflag, // Flow units flag
Pressflag, // Pressure units flag
DefPat; // Default demand pattern
Pressflag; // Pressure units flag
Spattern *PrevPat; // Previous pattern processed
Scurve *PrevCurve; // Previous curve processed
@@ -735,6 +734,7 @@ 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

@@ -89,7 +89,7 @@ BOOST_FIXTURE_TEST_CASE(test_junc_props, FixtureOpenClose)
double *value = test.data();
error = EN_getnodeindex(ph, (char *)"11", &index);
std::vector<double> ref = {710.0, 150.0, 1.0, 0.0, 0.5};
std::vector<double> ref = {710.0, 150.0, 0.0, 0.0, 0.5};
// Ranged for loop iterates over property set