Fixes to implement issue #161

This commit is contained in:
Lew Rossman
2018-06-19 10:30:02 -04:00
parent d5194ffb81
commit e9303de078
6 changed files with 25 additions and 1394 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -192,12 +192,18 @@ void linkcoeffs(EN_Project *pr)
// Examine each link of network */ // Examine each link of network */
for (k = 1; k <= net->Nlinks; k++) for (k = 1; k <= net->Nlinks; k++)
{ {
if (sol->P[k] == 0.0) continue; // if (sol->P[k] == 0.0) continue;
link = &net->Link[k]; link = &net->Link[k];
switch (link->Type) {
case EN_PRV:
case EN_PSV:
case EN_FCV:
if (hyd->LinkSetting[k] != MISSING) continue;
}
n1 = link->N1; // Start node of link n1 = link->N1; // Start node of link
n2 = link->N2; // End node of link n2 = link->N2; // End node of link
// Update net nodal inflows (X), solution matrix (A) and RHS array (F) // Update net nodal inflows (X), solution matrix (A) and RHS array (F)
// (Use covention that flow out of node is (-), flow into node is (+)) // (Use covention that flow out of node is (-), flow into node is (+))
hyd->X_tmp[n1] -= hyd->LinkFlows[k]; hyd->X_tmp[n1] -= hyd->LinkFlows[k];

View File

@@ -636,6 +636,7 @@ int controls(EN_Project *pr)
double k1, k2; double k1, k2;
char s1, s2; char s1, s2;
Slink *link; Slink *link;
Scontrol *control;
EN_Network *net = &pr->network; EN_Network *net = &pr->network;
time_options_t *top = &pr->time_options; time_options_t *top = &pr->time_options;
@@ -645,7 +646,7 @@ int controls(EN_Project *pr)
setsum = 0; setsum = 0;
for (i=1; i <= net->Ncontrols; i++) for (i=1; i <= net->Ncontrols; i++)
{ {
Scontrol *control = &net->Control[i]; control = &net->Control[i];
/* Make sure that link is defined */ /* Make sure that link is defined */
reset = 0; reset = 0;
if ( (k = control->Link) <= 0) { if ( (k = control->Link) <= 0) {

View File

@@ -101,11 +101,6 @@ int hydsolve(EN_Project *pr, int *iter, double *relerr)
nextcheck = hyd->CheckFreq; nextcheck = hyd->CheckFreq;
hyd->RelaxFactor = 1.0; hyd->RelaxFactor = 1.0;
/* Compute initial head loss coefficients*/
for (i = 1; i <= net->Nlinks; i++) {
hlosscoeff(pr, i);
}
/* Repeat iterations until convergence or trial limit is exceeded. */ /* Repeat iterations until convergence or trial limit is exceeded. */
/* (hyd->ExtraIter used to increase trials in case of status cycling.) */ /* (hyd->ExtraIter used to increase trials in case of status cycling.) */
if (pr->report.Statflag == FULL) { if (pr->report.Statflag == FULL) {
@@ -123,6 +118,9 @@ int hydsolve(EN_Project *pr, int *iter, double *relerr)
** head loss gradients, & F = flow correction terms. ** head loss gradients, & F = flow correction terms.
** Solution for H is returned in F from call to linsolve(). ** Solution for H is returned in F from call to linsolve().
*/ */
for (i = 1; i <= net->Nlinks; i++) {
hlosscoeff(pr, i);
}
matrixcoeffs(pr); matrixcoeffs(pr);
errcode = linsolve(&hyd->solver, net->Njuncs); errcode = linsolve(&hyd->solver, net->Njuncs);
@@ -147,16 +145,9 @@ int hydsolve(EN_Project *pr, int *iter, double *relerr)
newerr = newflows(pr, &hydbal); /* Update flows */ newerr = newflows(pr, &hydbal); /* Update flows */
*relerr = newerr; *relerr = newerr;
/* Check hydraulic balance & re-compute head loss coefficients */
checkhydbalance(pr, &hydbal);
for (i = 1; i <= net->Nlinks; i++) {
hlosscoeff(pr, i);
}
/* Write convergence error to status report if called for */ /* Write convergence error to status report if called for */
if (rep->Statflag == FULL) { if (rep->Statflag == FULL) {
writerelerr(pr, *iter, *relerr); writerelerr(pr, *iter, *relerr);
reporthydbal(pr, &hydbal);
} }
/* Apply solution damping & check for change in valve status */ /* Apply solution damping & check for change in valve status */
@@ -870,7 +861,7 @@ double newflows(EN_Project *pr, Hydbalance *hbal)
dqsum = 0.0; dqsum = 0.0;
hbal->maxflowchange = 0.0; hbal->maxflowchange = 0.0;
hbal->maxflowlink = -1; hbal->maxflowlink = 1;
/* Update flows in all links */ /* Update flows in all links */
for (k = 1; k <= net->Nlinks; k++) for (k = 1; k <= net->Nlinks; k++)
@@ -988,8 +979,9 @@ void checkhydbalance(EN_Project *pr, Hydbalance *hbal)
solver_t *sol = &hyd->solver; solver_t *sol = &hyd->solver;
Slink *link; Slink *link;
hbal->maxheaderror = 0.0; hbal->maxheaderror = 0.0;
hbal->maxheadlink = -1; hbal->maxheadlink = 1;
for (k = 1; k <= net->Nlinks; k++) { for (k = 1; k <= net->Nlinks; k++) {
hlosscoeff(pr, k);
if (sol->P[k] == 0.0) continue; if (sol->P[k] == 0.0) continue;
link = &net->Link[k]; link = &net->Link[k];
n1 = link->N1; n1 = link->N1;
@@ -1019,6 +1011,10 @@ int hasconverged(EN_Project *pr, double *relerr, Hydbalance *hbal)
hydraulics_t *hyd = &pr->hydraulics; hydraulics_t *hyd = &pr->hydraulics;
if (*relerr > hyd->Hacc) return 0; if (*relerr > hyd->Hacc) return 0;
checkhydbalance(pr, hbal);
if (pr->report.Statflag == FULL) {
reporthydbal(pr, hbal);
}
if (hyd->HeadErrorLimit > 0.0 && if (hyd->HeadErrorLimit > 0.0 &&
hbal->maxheaderror > hyd->HeadErrorLimit) return 0; hbal->maxheaderror > hyd->HeadErrorLimit) return 0;
if (hyd->FlowChangeLimit > 0.0 && if (hyd->FlowChangeLimit > 0.0 &&

View File

@@ -1,135 +0,0 @@
#include <stdio.h>
#include <string.h>
#include "epanet2.h"
#define MAXMSG 255 /* Max. # characters in message text */
#define MAXWARNCODE 99
/* text copied here, no more need of include "text.h" */
#define FMT01 "\nEPANET Version %d.%d.%d"
#define FMT03 "\n Correct syntax is:\n %s <input file> <output file>\n"
#define FMT09 "\n\nEPANET completed."
#define FMT10 "\nEPANET completed. There are warnings."
#define FMT11 "\nEPANET completed. There are errors."
void writeConsole(char *s);
/*
----------------------------------------------------------------
Entry point used to compile a stand-alone executable.
----------------------------------------------------------------
*/
int main(int argc, char *argv[])
/*--------------------------------------------------------------
** Input: argc = number of command line arguments
** *argv[] = array of command line arguments
** Output: none
** Purpose: main program segment
**
** Command line for stand-alone operation is:
** progname f1 f2 f3
** where progname = name of executable this code was compiled to,
** f1 = name of input file,
** f2 = name of report file (optional, stdout if left blank)
** f3 = name of binary output file (optional, nullfile if left blank).
**--------------------------------------------------------------
*/
{
char *f1,*f2,*f3;
char blank[] = "";
char errmsg[MAXMSG+1]="";
int errcode;
int version;
char s[256];
int major;
int minor;
int patch;
/* get version from DLL and trasform in Major.Minor.Patch format
instead of hardcoded version */
ENgetversion(&version);
major= version/10000;
minor= (version%10000)/100;
patch= version%100;
sprintf(s,FMT01, major , minor, patch);
writeConsole(s);
/* Check for proper number of command line arguments */
if (argc < 2) {
sprintf(s, FMT03, argv[0]);
writeConsole(s);
return(1);
}
/* set inputfile name */
f1 = argv[1];
if (argc > 2) {
/* set rptfile name */
f2 = argv[2];
}
else {
/* use stdout for rptfile */
f2 = blank;
}
if (argc > 3) {
/* set binary output file name */
f3 = argv[3];
}
else {
/* NO binary output*/
f3 = blank;
}
/* Call the main control function */
if (strlen(f2)> 0) {
/* use stdout for progress messages */
//errcode = ENepanet(f1,f2,f3,writeConsole);
errcode = ENepanet(f1, f2, f3, NULL);
}
else {
/* use stdout for reporting, no progress messages */
errcode = ENepanet(f1,f2,f3,NULL);
}
/* Error/Warning check */
if (errcode == 0) {
/* no errors */
writeConsole(FMT09);
return(0);
}
else {
if (errcode > MAXWARNCODE) printf("\n Fatal Error: ");
ENgeterror(errcode, errmsg, MAXMSG);
writeConsole(errmsg);
if (errcode > MAXWARNCODE) {
// error //
writeConsole(FMT11);
return(errcode);
}
else {
// warning //
writeConsole(FMT10);
return(0);
}
}
} /* End of main */
void writeConsole(char *s)
/*----------------------------------------------------------------
** Input: text string
** Output: none
** Purpose: writes string of characters to console
**----------------------------------------------------------------
*/
{
fprintf(stdout,"%s\n",s);
fflush(stdout);
}

View File

@@ -50,7 +50,6 @@ typedef int INT4;
#define MAXMSG 79 /* Max. # characters in message text */ #define MAXMSG 79 /* Max. # characters in message text */
#define MAXLINE 255 /* Max. # characters read from input line */ #define MAXLINE 255 /* Max. # characters read from input line */
#define MAXFNAME 259 /* Max. # characters in file name */ #define MAXFNAME 259 /* Max. # characters in file name */
>>>>>>> f11308fc72eccc8b74b18d5ddab0eb2ae0d36587
#define MAXTOKS 40 /* Max. items per line of input */ #define MAXTOKS 40 /* Max. items per line of input */
#define TZERO 1.E-4 /* Zero time tolerance */ #define TZERO 1.E-4 /* Zero time tolerance */
#define TRUE 1 #define TRUE 1