Adds get/set for default demand pattern to toolkit

This commit is contained in:
Lew Rossman
2022-01-14 08:50:33 -05:00
parent 64f0d15afe
commit afda609223
6 changed files with 22 additions and 14 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

@@ -1188,6 +1188,9 @@ int DLLEXPORT EN_getoption(EN_Project p, int option, double *value)
v = qual->Climit * p->Ucf[QUALITY];
break;
case EN_DEMANDPATTERN:
v = hyd->DefPat;
default:
return 251;
}
@@ -1344,6 +1347,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;
}

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;
@@ -319,16 +319,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