Merge pull request #827 from OpenWaterAnalytics/dev-disabled-controls
Add read/write of disabled controls to input file
This commit is contained in:
@@ -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: 06/18/2024
|
Last Updated: 02/11/2025
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -519,7 +519,10 @@ int saveinpfile(Project *pr, const char *fname)
|
|||||||
fprintf(f, "\n%s AT %s %s", s, ControlTxt[TIMEOFDAY],
|
fprintf(f, "\n%s AT %s %s", s, ControlTxt[TIMEOFDAY],
|
||||||
clocktime(rpt->Atime, control->Time));
|
clocktime(rpt->Atime, control->Time));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default: continue;
|
||||||
}
|
}
|
||||||
|
if (control->isEnabled == FALSE) fprintf(f, " DISABLED");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write [RULES] section
|
// Write [RULES] section
|
||||||
@@ -529,6 +532,7 @@ int saveinpfile(Project *pr, const char *fname)
|
|||||||
{
|
{
|
||||||
fprintf(f, "\nRULE %s", pr->network.Rule[i].label);
|
fprintf(f, "\nRULE %s", pr->network.Rule[i].label);
|
||||||
writerule(pr, f, i); // see RULES.C
|
writerule(pr, f, i); // see RULES.C
|
||||||
|
if (pr->network.Rule[i].isEnabled == FALSE) fprintf(f, "\nDISABLED");
|
||||||
fprintf(f, "\n");
|
fprintf(f, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
22
src/input3.c
22
src/input3.c
@@ -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: 05/11/2024
|
Last Updated: 02/11/2025
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -920,10 +920,10 @@ int controldata(Project *pr)
|
|||||||
** Purpose: processes simple controls
|
** Purpose: processes simple controls
|
||||||
** Formats:
|
** Formats:
|
||||||
** [CONTROLS]
|
** [CONTROLS]
|
||||||
** LINK linkID setting IF NODE nodeID {BELOW/ABOVE} level
|
** LINK linkID setting IF NODE nodeID {BELOW/ABOVE} level (DISABLED)
|
||||||
** LINK linkID setting AT TIME value (units)
|
** LINK linkID setting AT TIME value (units) (DISABLED)
|
||||||
** LINK linkID setting AT CLOCKTIME value (units)
|
** LINK linkID setting AT CLOCKTIME value (units) (DISABLED)
|
||||||
** (0) (1) (2) (3) (4) (5) (6) (7)
|
** (0) (1) (2) (3) (4) (5) (6) (7) (8)
|
||||||
**--------------------------------------------------------------
|
**--------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
@@ -932,7 +932,8 @@ int controldata(Project *pr)
|
|||||||
|
|
||||||
int i = 0, // Node index
|
int i = 0, // Node index
|
||||||
k, // Link index
|
k, // Link index
|
||||||
n; // # data items
|
n, // # data items
|
||||||
|
isEnabled = TRUE; // Control enabled
|
||||||
double setting = MISSING, // Link setting
|
double setting = MISSING, // Link setting
|
||||||
time = 0.0, // Simulation time
|
time = 0.0, // Simulation time
|
||||||
level = 0.0; // Pressure or tank level
|
level = 0.0; // Pressure or tank level
|
||||||
@@ -944,6 +945,13 @@ int controldata(Project *pr)
|
|||||||
// Check for sufficient number of input tokens
|
// Check for sufficient number of input tokens
|
||||||
n = parser->Ntokens;
|
n = parser->Ntokens;
|
||||||
if (n < 6) return 201;
|
if (n < 6) return 201;
|
||||||
|
|
||||||
|
// Check if last token is "DISABLED"
|
||||||
|
if (match(parser->Tok[n-1], w_DISABLED))
|
||||||
|
{
|
||||||
|
isEnabled = FALSE;
|
||||||
|
n = n - 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Check that controlled link exists
|
// Check that controlled link exists
|
||||||
k = findlink(net, parser->Tok[1]);
|
k = findlink(net, parser->Tok[1]);
|
||||||
@@ -1020,7 +1028,7 @@ int controldata(Project *pr)
|
|||||||
control->Time = (long)(3600.0 * time);
|
control->Time = (long)(3600.0 * time);
|
||||||
if (ctltype == TIMEOFDAY) control->Time %= SECperDAY;
|
if (ctltype == TIMEOFDAY) control->Time %= SECperDAY;
|
||||||
control->Grade = level;
|
control->Grade = level;
|
||||||
control->isEnabled = TRUE;
|
control->isEnabled = isEnabled;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
17
src/rules.c
17
src/rules.c
@@ -1,13 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
Project: OWA EPANET
|
Project: OWA EPANET
|
||||||
Version: 2.2
|
Version: 2.3
|
||||||
Module: rules.c
|
Module: rules.c
|
||||||
Description: implements rule-based controls
|
Description: implements rule-based controls
|
||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 05/15/2019
|
Last Updated: 02/11/2025
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -32,10 +32,11 @@ enum Rulewords {
|
|||||||
r_THEN,
|
r_THEN,
|
||||||
r_ELSE,
|
r_ELSE,
|
||||||
r_PRIORITY,
|
r_PRIORITY,
|
||||||
|
r_DISABLED,
|
||||||
r_ERROR
|
r_ERROR
|
||||||
};
|
};
|
||||||
char *Ruleword[] = {w_RULE, w_IF, w_AND, w_OR,
|
char *Ruleword[] = {w_RULE, w_IF, w_AND, w_OR,
|
||||||
w_THEN, w_ELSE, w_PRIORITY, NULL};
|
w_THEN, w_ELSE, w_PRIORITY, w_DISABLED, NULL};
|
||||||
|
|
||||||
enum Varwords {
|
enum Varwords {
|
||||||
r_DEMAND,
|
r_DEMAND,
|
||||||
@@ -273,6 +274,16 @@ int ruledata(Project *pr)
|
|||||||
err = newpriority(pr);
|
err = newpriority(pr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case r_DISABLED:
|
||||||
|
if (rules->RuleState != r_THEN && rules->RuleState != r_ELSE &&
|
||||||
|
rules->RuleState != r_PRIORITY)
|
||||||
|
{
|
||||||
|
err = 221;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
net->Rule[net->Nrules].isEnabled = FALSE;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
err = 201;
|
err = 201;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 06/15/2024
|
Last Updated: 02/11/2025
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -196,6 +196,7 @@
|
|||||||
#define w_THEN "THEN"
|
#define w_THEN "THEN"
|
||||||
#define w_ELSE "ELSE"
|
#define w_ELSE "ELSE"
|
||||||
#define w_PRIORITY "PRIO"
|
#define w_PRIORITY "PRIO"
|
||||||
|
#define w_DISABLED "DISABLED"
|
||||||
|
|
||||||
// ------ Input File Section Names ------------------------
|
// ------ Input File Section Names ------------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user