Add emitter backflow option

Adds a global hydraulic option to allow backflow or not through emitter elements. To maintain backward compatibility the default is YES.
This commit is contained in:
Lew Rossman
2023-02-05 15:16:20 -05:00
parent 9814564e29
commit 847fa82139
13 changed files with 55 additions and 10 deletions

View File

@@ -182,6 +182,8 @@ namespace EpanetCSharpLibrary
public const int EN_WALLORDER = 20; public const int EN_WALLORDER = 20;
public const int EN_TANKORDER = 21; public const int EN_TANKORDER = 21;
public const int EN_CONCENLIMIT = 22; public const int EN_CONCENLIMIT = 22;
public const int EN_DEMANDPATTERN = 23;
public const int EN_EMITBACKFLOW = 24;
public const int EN_LOWLEVEL = 0; //Control types public const int EN_LOWLEVEL = 0; //Control types
public const int EN_HILEVEL = 1; public const int EN_HILEVEL = 1;

View File

@@ -179,6 +179,8 @@ Public Const EN_BULKORDER = 19
Public Const EN_WALLORDER = 20 Public Const EN_WALLORDER = 20
Public Const EN_TANKORDER = 21 Public Const EN_TANKORDER = 21
Public Const EN_CONCENLIMIT = 22 Public Const EN_CONCENLIMIT = 22
Public Const EN_DEMANDPATTERN = 23
Public Const EN_EMITBACKFLOW = 24
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

@@ -185,6 +185,8 @@ const
EN_WALLORDER = 20; EN_WALLORDER = 20;
EN_TANKORDER = 21; EN_TANKORDER = 21;
EN_CONCENLIMIT = 22; EN_CONCENLIMIT = 22;
EN_DEMANDPATTERN = 23;
EN_EMITBACKFLOW = 24;
EN_LOWLEVEL = 0; { Control types } EN_LOWLEVEL = 0; { Control types }
EN_HILEVEL = 1; EN_HILEVEL = 1;

View File

@@ -174,6 +174,8 @@ Public Const EN_BULKORDER = 19
Public Const EN_WALLORDER = 20 Public Const EN_WALLORDER = 20
Public Const EN_TANKORDER = 21 Public Const EN_TANKORDER = 21
Public Const EN_CONCENLIMIT = 22 Public Const EN_CONCENLIMIT = 22
Public Const EN_DEMANDPATTERN = 23
Public Const EN_EMITBACKFLOW = 24
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: 08/13/2022 Last Updated: 02/05/2023
****************************************************************************** ******************************************************************************
*/ */
@@ -335,7 +335,8 @@ typedef enum {
EN_WALLORDER = 20, //!< Wall reaction order for pipes (either 0 or 1) EN_WALLORDER = 20, //!< Wall reaction order for pipes (either 0 or 1)
EN_TANKORDER = 21, //!< Bulk water reaction order for tanks 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_DEMANDPATTERN = 23, //!< Name of default demand pattern
EN_EMITBACKFLOW = 24 //!< 1 if emitters can backflow, 0 if not
} EN_Option; } EN_Option;
/// Simple control types /// Simple control types

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: 08/13/2022 Last Updated: 02/05/2023
****************************************************************************** ******************************************************************************
*/ */
@@ -112,6 +112,10 @@ char *RptFlagTxt[] = {w_NO,
w_YES, w_YES,
w_FULL}; w_FULL};
char *BackflowTxt[] = {w_NO,
w_YES,
NULL};
char *SectTxt[] = {s_TITLE, s_JUNCTIONS, s_RESERVOIRS, char *SectTxt[] = {s_TITLE, s_JUNCTIONS, s_RESERVOIRS,
s_TANKS, s_PIPES, s_PUMPS, s_TANKS, s_PIPES, s_PUMPS,
s_VALVES, s_CONTROLS, s_RULES, s_VALVES, s_CONTROLS, s_RULES,

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: 08/13/2022 Last Updated: 02/05/2023
****************************************************************************** ******************************************************************************
*/ */
@@ -1205,6 +1205,9 @@ int DLLEXPORT EN_getoption(EN_Project p, int option, double *value)
case EN_DEMANDPATTERN: case EN_DEMANDPATTERN:
v = hyd->DefPat; v = hyd->DefPat;
break; break;
case EN_EMITBACKFLOW:
v = hyd->EmitBackFlag;
break;
default: default:
return 251; return 251;
} }
@@ -1367,6 +1370,11 @@ int DLLEXPORT EN_setoption(EN_Project p, int option, double value)
hyd->DefPat = pat; hyd->DefPat = pat;
break; break;
case EN_EMITBACKFLOW:
if (value == 0.0 || value == 1.0) hyd->EmitBackFlag = (int)value;
else return 213;
break;
default: default:
return 251; return 251;
} }

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: 08/13/2022 Last Updated: 02/05/2023
****************************************************************************** ******************************************************************************
*/ */
@@ -495,6 +495,13 @@ void emitterheadloss(Project *pr, int i, double *hloss, double *hgrad)
// Otherwise use normal emitter head loss function // Otherwise use normal emitter head loss function
else *hloss = (*hgrad) * q / hyd->Qexp; else *hloss = (*hgrad) * q / hyd->Qexp;
// Prevent negative flow if backflow not allowed
if (hyd->EmitBackFlag == 0 && q <= 0.0)
{
*hgrad += CBIG;
*hloss += CBIG * q;
}
} }

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: 08/13/2022 Last Updated: 02/05/2023
****************************************************************************** ******************************************************************************
*/ */
@@ -33,6 +33,7 @@ extern char *MixTxt[];
extern char *TstatTxt[]; extern char *TstatTxt[];
extern char *RptFlagTxt[]; extern char *RptFlagTxt[];
extern char *SectTxt[]; extern char *SectTxt[];
extern char *BackflowTxt[];
void saveauxdata(Project *pr, FILE *f) void saveauxdata(Project *pr, FILE *f)
/* /*
@@ -676,6 +677,7 @@ int saveinpfile(Project *pr, const char *fname)
fprintf(f, "\n PATTERN %s", net->Pattern[hyd->DefPat].ID); fprintf(f, "\n PATTERN %s", net->Pattern[hyd->DefPat].ID);
fprintf(f, "\n DEMAND MULTIPLIER %-.4f", hyd->Dmult); fprintf(f, "\n DEMAND MULTIPLIER %-.4f", hyd->Dmult);
fprintf(f, "\n EMITTER EXPONENT %-.4f", 1.0 / hyd->Qexp); fprintf(f, "\n EMITTER EXPONENT %-.4f", 1.0 / hyd->Qexp);
fprintf(f, "\n EMITTER BACKFLOW %s", BackflowTxt[hyd->EmitBackFlag]);
fprintf(f, "\n VISCOSITY %-.6f", hyd->Viscos / VISCOS); fprintf(f, "\n VISCOSITY %-.6f", hyd->Viscos / VISCOS);
fprintf(f, "\n DIFFUSIVITY %-.6f", qual->Diffus / DIFFUS); fprintf(f, "\n DIFFUSIVITY %-.6f", qual->Diffus / DIFFUS);
fprintf(f, "\n SPECIFIC GRAVITY %-.6f", hyd->SpGrav); fprintf(f, "\n SPECIFIC GRAVITY %-.6f", hyd->SpGrav);

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: 07/08/2019 Last Updated: 02/05/2023
****************************************************************************** ******************************************************************************
*/ */
@@ -120,6 +120,7 @@ void setdefaults(Project *pr)
hyd->Epump = EPUMP; // Default pump efficiency hyd->Epump = EPUMP; // Default pump efficiency
hyd->Emax = 0.0; // Zero peak energy usage hyd->Emax = 0.0; // Zero peak energy usage
hyd->Qexp = 2.0; // Flow exponent for emitters hyd->Qexp = 2.0; // Flow exponent for emitters
hyd->EmitBackFlag = 1; // Allow emitter backflow
hyd->DefPat = 0; // Default demand pattern index hyd->DefPat = 0; // Default demand pattern index
hyd->Dmult = 1.0; // Demand multiplier hyd->Dmult = 1.0; // Demand multiplier
hyd->RQtol = RQTOL; // Default hydraulics parameters hyd->RQtol = RQTOL; // Default hydraulics parameters

View File

@@ -7,7 +7,7 @@ Description: parses network data from a line of an EPANET input file
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE License: see LICENSE
Last Updated: 08/13/2022 Last Updated: 02/05/2023
****************************************************************************** ******************************************************************************
*/ */
@@ -25,6 +25,7 @@ Last Updated: 08/13/2022
extern char *MixTxt[]; extern char *MixTxt[];
extern char *Fldname[]; extern char *Fldname[];
extern char *DemandModelTxt[]; extern char *DemandModelTxt[];
extern char *BackflowTxt[];
// Exported functions // Exported functions
int powercurve(double, double, double, double, double, double *, double *, int powercurve(double, double, double, double, double, double *, double *,
@@ -1759,6 +1760,7 @@ int optionchoice(Project *pr, int n)
** UNBALANCED STOP/CONTINUE {Niter} ** UNBALANCED STOP/CONTINUE {Niter}
** PATTERN id ** PATTERN id
** DEMAND MODEL DDA/PDA ** DEMAND MODEL DDA/PDA
** EMITTER BACKFLOW YES/NO
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
@@ -1897,6 +1899,16 @@ int optionchoice(Project *pr, int n)
hyd->DemandModel = choice; hyd->DemandModel = choice;
} }
// EMITTER BACKFLOW
else if (match(parser->Tok[0], w_EMITTER))
{
if (n < 2) return 0;
if (!match(parser->Tok[1], w_BACKFLOW)) return -1;
choice = findmatch(parser->Tok[2], BackflowTxt);
if (choice < 0) return setError(parser, 2, 213);
hyd->EmitBackFlag = choice;
}
// Return -1 if keyword did not match any option // Return -1 if keyword did not match any option
else return -1; else return -1;
return 0; return 0;

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: 08/13/2022 Last Updated: 02/05/2023
****************************************************************************** ******************************************************************************
*/ */
@@ -131,6 +131,7 @@
#define w_SEGMENTS "SEGM" #define w_SEGMENTS "SEGM"
#define w_TOLERANCE "TOLER" #define w_TOLERANCE "TOLER"
#define w_EMITTER "EMIT" #define w_EMITTER "EMIT"
#define w_BACKFLOW "BACK"
#define w_PRICE "PRICE" #define w_PRICE "PRICE"
#define w_DMNDCHARGE "DEMAN" #define w_DMNDCHARGE "DEMAN"

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: 08/13/2022 Last Updated: 02/05/2023
****************************************************************************** ******************************************************************************
*/ */
@@ -744,6 +744,7 @@ typedef struct {
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
EmitBackFlag, // Emitter backflow flag
Iterations, // Number of hydraulic trials taken Iterations, // Number of hydraulic trials taken
MaxIter, // Max. hydraulic trials allowed MaxIter, // Max. hydraulic trials allowed
ExtraIter, // Extra hydraulic trials ExtraIter, // Extra hydraulic trials