Merge pull request #445 from michaeltryby/dev-unittesting
Fix leaky test code
This commit is contained in:
20
src/epanet.c
20
src/epanet.c
@@ -11,12 +11,16 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
|
||||
@@ -279,7 +283,7 @@ int DLLEXPORT EN_getcomment(EN_Project p, int object, int index, char *comment)
|
||||
/*----------------------------------------------------------------
|
||||
** Input: object = a type of object (see EN_ObjectType)
|
||||
** index = the object's index
|
||||
** Output: comment = the object's descriptive comment
|
||||
** Output: comment = the object's descriptive comment
|
||||
** Returns: error code
|
||||
** Purpose: Retrieves an object's descriptive comment
|
||||
**----------------------------------------------------------------
|
||||
@@ -840,7 +844,7 @@ int DLLEXPORT EN_closeQ(EN_Project p)
|
||||
if (!p->Openflag) return 102;
|
||||
closequal(p);
|
||||
p->quality.OpenQflag = FALSE;
|
||||
closeoutfile(p);
|
||||
closeoutfile(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1608,7 +1612,7 @@ int DLLEXPORT EN_setqualtype(EN_Project p, int qualType, char *chemName,
|
||||
p->network.Node[i].C0 *= Ucf[QUALITY];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ucf[QUALITY] = ccf;
|
||||
Ucf[LINKQUAL] = ccf;
|
||||
Ucf[REACTRATE] = ccf;
|
||||
|
||||
@@ -10,10 +10,12 @@
|
||||
Last Updated: 03/17/2019
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@@ -11,8 +11,13 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
#include "epanet_py.h"
|
||||
|
||||
18
src/hash.c
18
src/hash.c
@@ -11,11 +11,13 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include "hash.h"
|
||||
|
||||
@@ -84,7 +86,7 @@ int hashtable_update(HashTable *ht, char *key, int new_data)
|
||||
{
|
||||
unsigned int i = gethash(key);
|
||||
DataEntry *entry;
|
||||
|
||||
|
||||
if ( i >= HASHTABLEMAXSIZE ) return NOTFOUND;
|
||||
entry = ht[i];
|
||||
while (entry != NULL)
|
||||
@@ -104,7 +106,7 @@ int hashtable_delete(HashTable *ht, char *key)
|
||||
{
|
||||
unsigned int i = gethash(key);
|
||||
DataEntry *entry, *preventry;
|
||||
|
||||
|
||||
if ( i >= HASHTABLEMAXSIZE ) return NOTFOUND;
|
||||
|
||||
preventry = NULL;
|
||||
@@ -164,7 +166,7 @@ void hashtable_free(HashTable *ht)
|
||||
{
|
||||
DataEntry *entry, *nextentry;
|
||||
int i;
|
||||
|
||||
|
||||
for (i = 0; i < HASHTABLEMAXSIZE; i++)
|
||||
{
|
||||
entry = ht[i];
|
||||
|
||||
@@ -11,13 +11,16 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "types.h"
|
||||
@@ -85,12 +88,12 @@ void resistcoeff(Project *pr, int k)
|
||||
|
||||
double e, d, L;
|
||||
Slink *link = &net->Link[k];
|
||||
|
||||
|
||||
link->Qa = 0.0;
|
||||
switch (link->Type) {
|
||||
|
||||
// ... Link is a pipe. Compute resistance based on headloss formula.
|
||||
// Friction factor for D-W formula gets included during head loss
|
||||
// Friction factor for D-W formula gets included during head loss
|
||||
// calculation.
|
||||
case CVPIPE:
|
||||
case PIPE:
|
||||
@@ -244,14 +247,14 @@ void linkcoeffs(Project *pr)
|
||||
|
||||
// Update linear system coeffs. associated with start node n1
|
||||
// ... node n1 is junction
|
||||
if (n1 <= net->Njuncs)
|
||||
if (n1 <= net->Njuncs)
|
||||
{
|
||||
sm->Aii[sm->Row[n1]] += hyd->P[k]; // Diagonal coeff.
|
||||
sm->F[sm->Row[n1]] += hyd->Y[k]; // RHS coeff.
|
||||
}
|
||||
|
||||
// ... node n1 is a tank/reservoir
|
||||
else sm->F[sm->Row[n2]] += (hyd->P[k] * hyd->NodeHead[n1]);
|
||||
else sm->F[sm->Row[n2]] += (hyd->P[k] * hyd->NodeHead[n1]);
|
||||
|
||||
// Update linear system coeffs. associated with end node n2
|
||||
// ... node n2 is junction
|
||||
@@ -262,7 +265,7 @@ void linkcoeffs(Project *pr)
|
||||
}
|
||||
|
||||
// ... node n2 is a tank/reservoir
|
||||
else sm->F[sm->Row[n1]] += (hyd->P[k] * hyd->NodeHead[n2]);
|
||||
else sm->F[sm->Row[n1]] += (hyd->P[k] * hyd->NodeHead[n2]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,13 +324,13 @@ void valvecoeffs(Project *pr)
|
||||
// Coeffs. for fixed status valves have already been computed
|
||||
if (hyd->LinkSetting[k] == MISSING) continue;
|
||||
|
||||
// Start & end nodes of valve's link
|
||||
// Start & end nodes of valve's link
|
||||
link = &net->Link[k];
|
||||
n1 = link->N1;
|
||||
n2 = link->N2;
|
||||
|
||||
// Call valve-specific function
|
||||
switch (link->Type)
|
||||
switch (link->Type)
|
||||
{
|
||||
case PRV:
|
||||
prvcoeff(pr, k, n1, n2);
|
||||
@@ -482,7 +485,7 @@ void demandcoeffs(Project *pr)
|
||||
double dp, // pressure range over which demand can vary (ft)
|
||||
n, // exponent in head loss v. demand function
|
||||
hloss, // head loss in supplying demand (ft)
|
||||
hgrad; // gradient of demand head loss (ft/cfs)
|
||||
hgrad; // gradient of demand head loss (ft/cfs)
|
||||
|
||||
// Get demand function parameters
|
||||
if (hyd->DemandModel == DDA) return;
|
||||
@@ -659,12 +662,12 @@ void DWpipecoeff(Project *pr, int k)
|
||||
Slink *link = &pr->network.Link[k];
|
||||
|
||||
double q = ABS(hyd->LinkFlow[k]);
|
||||
double r = link->R; // Resistance coeff.
|
||||
double ml = link->Km; // Minor loss coeff.
|
||||
double r = link->R; // Resistance coeff.
|
||||
double ml = link->Km; // Minor loss coeff.
|
||||
double e = link->Kc / link->Diam; // Relative roughness
|
||||
double s = hyd->Viscos * link->Diam; // Viscosity / diameter
|
||||
double hloss, hgrad, f, dfdq, r1;
|
||||
|
||||
|
||||
// Compute head loss and its derivative
|
||||
// ... use Hagen-Poiseuille formula for laminar flow (Re <= 2000)
|
||||
if (q <= A2 * s)
|
||||
@@ -673,7 +676,7 @@ void DWpipecoeff(Project *pr, int k)
|
||||
hloss = hyd->LinkFlow[k] * (r + ml * q);
|
||||
hgrad = r + 2.0 * ml * q;
|
||||
}
|
||||
|
||||
|
||||
// ... otherwise use Darcy-Weisbach formula with friction factor
|
||||
else
|
||||
{
|
||||
@@ -683,7 +686,7 @@ void DWpipecoeff(Project *pr, int k)
|
||||
hloss = r1 * q * hyd->LinkFlow[k];
|
||||
hgrad = (2.0 * r1 * q) + (dfdq * r * q * q);
|
||||
}
|
||||
|
||||
|
||||
// Compute P and Y coefficients
|
||||
hyd->P[k] = 1.0 / hgrad;
|
||||
hyd->Y[k] = hloss / hgrad;
|
||||
@@ -753,7 +756,7 @@ void pumpcoeff(Project *pr, int k)
|
||||
|
||||
int p; // Pump index
|
||||
double h0, // Shutoff head
|
||||
q, // Abs. value of flow
|
||||
q, // Abs. value of flow
|
||||
r, // Flow resistance coeff.
|
||||
n, // Flow exponent coeff.
|
||||
setting, // Pump speed setting
|
||||
@@ -899,7 +902,7 @@ void gpvcoeff(Project *pr, int k)
|
||||
Hydraul *hyd = &pr->hydraul;
|
||||
|
||||
// Treat as a pipe if valve closed
|
||||
if (hyd->LinkStatus[k] == CLOSED) valvecoeff(pr, k);
|
||||
if (hyd->LinkStatus[k] == CLOSED) valvecoeff(pr, k);
|
||||
|
||||
// Otherwise utilize segment of head loss curve
|
||||
// bracketing current flow (curve index is stored
|
||||
@@ -939,7 +942,7 @@ void pbvcoeff(Project *pr, int k)
|
||||
// If valve fixed OPEN or CLOSED then treat as a pipe
|
||||
if (hyd->LinkSetting[k] == MISSING || hyd->LinkSetting[k] == 0.0)
|
||||
{
|
||||
valvecoeff(pr, k);
|
||||
valvecoeff(pr, k);
|
||||
}
|
||||
|
||||
// If valve is active
|
||||
@@ -948,7 +951,7 @@ void pbvcoeff(Project *pr, int k)
|
||||
// Treat as a pipe if minor loss > valve setting
|
||||
if (link->Km * SQR(hyd->LinkFlow[k]) > hyd->LinkSetting[k])
|
||||
{
|
||||
valvecoeff(pr, k);
|
||||
valvecoeff(pr, k);
|
||||
}
|
||||
// Otherwise force headloss across valve to be equal to setting
|
||||
else
|
||||
@@ -983,7 +986,7 @@ void tcvcoeff(Project *pr, int k)
|
||||
}
|
||||
|
||||
// Then apply usual valve formula
|
||||
valvecoeff(pr, k);
|
||||
valvecoeff(pr, k);
|
||||
|
||||
// Restore original loss coeff.
|
||||
link->Km = km;
|
||||
@@ -1017,7 +1020,7 @@ void prvcoeff(Project *pr, int k, int n1, int n2)
|
||||
{
|
||||
|
||||
// Set coeffs. to force head at downstream
|
||||
// node equal to valve setting & force flow
|
||||
// node equal to valve setting & force flow
|
||||
// to equal to flow excess at downstream node.
|
||||
|
||||
hyd->P[k] = 0.0;
|
||||
@@ -1069,7 +1072,7 @@ void psvcoeff(Project *pr, int k, int n1, int n2)
|
||||
if (hyd->LinkStatus[k] == ACTIVE)
|
||||
{
|
||||
// Set coeffs. to force head at upstream
|
||||
// node equal to valve setting & force flow
|
||||
// node equal to valve setting & force flow
|
||||
// equal to flow excess at upstream node.
|
||||
|
||||
hyd->P[k] = 0.0;
|
||||
@@ -1138,7 +1141,7 @@ void fcvcoeff(Project *pr, int k, int n1, int n2)
|
||||
|
||||
else
|
||||
{
|
||||
valvecoeff(pr, k);
|
||||
valvecoeff(pr, k);
|
||||
sm->Aij[sm->Ndx[k]] -= hyd->P[k];
|
||||
sm->Aii[i] += hyd->P[k];
|
||||
sm->Aii[j] += hyd->P[k];
|
||||
@@ -1162,7 +1165,7 @@ void valvecoeff(Project *pr, int k)
|
||||
Slink *link = &pr->network.Link[k];
|
||||
|
||||
double flow, q, y, qa, hgrad;
|
||||
|
||||
|
||||
flow = hyd->LinkFlow[k];
|
||||
|
||||
// Valve is closed. Use a very small matrix coeff.
|
||||
|
||||
227
src/hydraul.c
227
src/hydraul.c
@@ -3,7 +3,7 @@
|
||||
Project: OWA EPANET
|
||||
Version: 2.2
|
||||
Module: hydraul.c
|
||||
Description: implements EPANET's hydraulic engine
|
||||
Description: implements EPANET's hydraulic engine
|
||||
Authors: see AUTHORS
|
||||
Copyright: see AUTHORS
|
||||
License: see LICENSE
|
||||
@@ -11,13 +11,16 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "types.h"
|
||||
@@ -48,9 +51,9 @@ void tanklevels(Project *, long);
|
||||
int openhyd(Project *pr)
|
||||
/*
|
||||
*--------------------------------------------------------------
|
||||
* Input: none
|
||||
* Output: returns error code
|
||||
* Purpose: opens hydraulics solver system
|
||||
* Input: none
|
||||
* Output: returns error code
|
||||
* Purpose: opens hydraulics solver system
|
||||
*--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -92,8 +95,8 @@ void inithyd(Project *pr, int initflag)
|
||||
**--------------------------------------------------------------
|
||||
** Input: initflag > 0 if link flows should be re-initialized
|
||||
** = 0 if not
|
||||
** Output: none
|
||||
** Purpose: initializes hydraulics solver system
|
||||
** Output: none
|
||||
** Purpose: initializes hydraulics solver system
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -106,7 +109,7 @@ void inithyd(Project *pr, int initflag)
|
||||
Stank *tank;
|
||||
Slink *link;
|
||||
Spump *pump;
|
||||
|
||||
|
||||
// Initialize tanks
|
||||
for (i = 1; i <= net->Ntanks; i++)
|
||||
{
|
||||
@@ -128,7 +131,7 @@ void inithyd(Project *pr, int initflag)
|
||||
for (i = 1; i <= net->Nlinks; i++)
|
||||
{
|
||||
link = &net->Link[i];
|
||||
|
||||
|
||||
// Initialize status and setting
|
||||
hyd->LinkStatus[i] = link->Status;
|
||||
hyd->LinkSetting[i] = link->Kc;
|
||||
@@ -140,7 +143,7 @@ void inithyd(Project *pr, int initflag)
|
||||
if (
|
||||
(link->Type == PRV || link->Type == PSV
|
||||
|| link->Type == FCV) && (link->Kc != MISSING)
|
||||
) hyd->LinkStatus[i] = ACTIVE;
|
||||
) hyd->LinkStatus[i] = ACTIVE;
|
||||
|
||||
// Initialize flows if necessary
|
||||
if (hyd->LinkStatus[i] <= CLOSED)
|
||||
@@ -170,7 +173,7 @@ void inithyd(Project *pr, int initflag)
|
||||
|
||||
// Re-position hydraulics file
|
||||
if (pr->outfile.Saveflag)
|
||||
{
|
||||
{
|
||||
fseek(out->HydFile,out->HydOffset,SEEK_SET);
|
||||
}
|
||||
|
||||
@@ -185,10 +188,10 @@ void inithyd(Project *pr, int initflag)
|
||||
int runhyd(Project *pr, long *t)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: none
|
||||
** Input: none
|
||||
** Output: t = pointer to current time (in seconds)
|
||||
** Returns: error code
|
||||
** Purpose: solves network hydraulics in a single time period
|
||||
** Returns: error code
|
||||
** Purpose: solves network hydraulics in a single time period
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -199,7 +202,7 @@ int runhyd(Project *pr, long *t)
|
||||
int iter; // Iteration count
|
||||
int errcode; // Error code
|
||||
double relerr; // Solution accuracy
|
||||
|
||||
|
||||
// Find new demands & control actions
|
||||
*t = time->Htime;
|
||||
demands(pr);
|
||||
@@ -212,7 +215,7 @@ int runhyd(Project *pr, long *t)
|
||||
{
|
||||
// Report new status & save results
|
||||
if (rpt->Statflag) writehydstat(pr,iter,relerr);
|
||||
|
||||
|
||||
// If system unbalanced and no extra trials
|
||||
// allowed, then activate the Haltflag
|
||||
if (relerr > hyd->Hacc && hyd->ExtraIter == -1)
|
||||
@@ -229,11 +232,11 @@ int runhyd(Project *pr, long *t)
|
||||
int nexthyd(Project *pr, long *tstep)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: none
|
||||
** Input: none
|
||||
** Output: tstep = pointer to time step (in seconds)
|
||||
** Returns: error code
|
||||
** Returns: error code
|
||||
** Purpose: finds length of next time step & updates tank
|
||||
** levels and rule-based contol actions
|
||||
** levels and rule-based contol actions
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -242,7 +245,7 @@ int nexthyd(Project *pr, long *tstep)
|
||||
|
||||
long hydstep; // Actual time step
|
||||
int errcode = 0; // Error code
|
||||
|
||||
|
||||
// Save current results to hydraulics file and
|
||||
// force end of simulation if Haltflag is active
|
||||
if (pr->outfile.Saveflag) errcode = savehyd(pr, &time->Htime);
|
||||
@@ -277,14 +280,14 @@ int nexthyd(Project *pr, long *tstep)
|
||||
*tstep = hydstep;
|
||||
return errcode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void closehyd(Project *pr)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: none
|
||||
** Output: returns error code
|
||||
** Purpose: closes hydraulics solver system
|
||||
** Input: none
|
||||
** Output: returns error code
|
||||
** Purpose: closes hydraulics solver system
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -296,9 +299,9 @@ void closehyd(Project *pr)
|
||||
int allocmatrix(Project *pr)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: none
|
||||
** Output: returns error code
|
||||
** Purpose: allocates memory used for solution matrix coeffs.
|
||||
** Input: none
|
||||
** Output: returns error code
|
||||
** Purpose: allocates memory used for solution matrix coeffs.
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -306,7 +309,7 @@ int allocmatrix(Project *pr)
|
||||
Hydraul *hyd = &pr->hydraul;
|
||||
|
||||
int errcode = 0;
|
||||
|
||||
|
||||
hyd->P = (double *) calloc(net->Nlinks+1,sizeof(double));
|
||||
hyd->Y = (double *) calloc(net->Nlinks+1,sizeof(double));
|
||||
hyd->DemandFlow = (double *) calloc(net->Nnodes + 1, sizeof(double));
|
||||
@@ -328,14 +331,14 @@ int allocmatrix(Project *pr)
|
||||
void freematrix(Project *pr)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: none
|
||||
** Output: none
|
||||
** Purpose: frees memory used for solution matrix coeffs.
|
||||
** Input: none
|
||||
** Output: none
|
||||
** Purpose: frees memory used for solution matrix coeffs.
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
Hydraul *hyd = &pr->hydraul;
|
||||
|
||||
|
||||
free(hyd->P);
|
||||
free(hyd->Y);
|
||||
free(hyd->DemandFlow);
|
||||
@@ -351,7 +354,7 @@ void initlinkflow(Project *pr, int i, char s, double k)
|
||||
** Input: i = link index
|
||||
** s = link status
|
||||
** k = link setting (i.e., pump speed)
|
||||
** Output: none
|
||||
** Output: none
|
||||
** Purpose: sets initial flow in link to QZERO if link is closed,
|
||||
** to design flow for a pump, or to flow at velocity of
|
||||
** 1 fps for other links.
|
||||
@@ -362,7 +365,7 @@ void initlinkflow(Project *pr, int i, char s, double k)
|
||||
Network *n = &pr->network;
|
||||
|
||||
Slink *link = &n->Link[i];
|
||||
|
||||
|
||||
if (s == CLOSED)
|
||||
{
|
||||
hyd->LinkFlow[i] = QZERO;
|
||||
@@ -383,8 +386,8 @@ void setlinkflow(Project *pr, int k, double dh)
|
||||
**--------------------------------------------------------------
|
||||
** Input: k = link index
|
||||
** dh = head loss across link
|
||||
** Output: none
|
||||
** Purpose: sets flow in link based on current headloss
|
||||
** Output: none
|
||||
** Purpose: sets flow in link based on current headloss
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -396,7 +399,7 @@ void setlinkflow(Project *pr, int k, double dh)
|
||||
double x ,y;
|
||||
Slink *link = &net->Link[k];
|
||||
Scurve *curve;
|
||||
|
||||
|
||||
switch (link->Type)
|
||||
{
|
||||
case CVPIPE:
|
||||
@@ -408,7 +411,7 @@ void setlinkflow(Project *pr, int k, double dh)
|
||||
y = sqrt(ABS(dh) / link->R / 1.32547);
|
||||
hyd->LinkFlow[k] = x * y;
|
||||
}
|
||||
|
||||
|
||||
// For Hazen-Williams or Manning formulas use inverse of formula
|
||||
else
|
||||
{
|
||||
@@ -416,16 +419,16 @@ void setlinkflow(Project *pr, int k, double dh)
|
||||
y = 1.0 / hyd->Hexp;
|
||||
hyd->LinkFlow[k] = pow(x, y);
|
||||
}
|
||||
|
||||
|
||||
// Change sign of flow to match sign of head loss
|
||||
if (dh < 0.0) hyd->LinkFlow[k] = -hyd->LinkFlow[k];
|
||||
break;
|
||||
|
||||
|
||||
case PUMP:
|
||||
// Convert headloss to pump head gain
|
||||
dh = -dh;
|
||||
p = findpump(net, k);
|
||||
|
||||
|
||||
// For custom pump curve, interpolate from curve
|
||||
if (net->Pump[p].Ptype == CUSTOM)
|
||||
{
|
||||
@@ -435,7 +438,7 @@ void setlinkflow(Project *pr, int k, double dh)
|
||||
hyd->LinkFlow[k] = interp(curve->Npts, curve->Y, curve->X, dh) *
|
||||
hyd->LinkSetting[k] / pr->Ucf[FLOW];
|
||||
}
|
||||
|
||||
|
||||
// Otherwise use inverse of power curve
|
||||
else
|
||||
{
|
||||
@@ -459,7 +462,7 @@ void setlinkstatus(Project *pr, int index, char value, StatusType *s, double *k
|
||||
** s = pointer to link status
|
||||
** k = pointer to link setting
|
||||
** Output: none
|
||||
** Purpose: sets link status to OPEN or CLOSED
|
||||
** Purpose: sets link status to OPEN or CLOSED
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -467,11 +470,11 @@ void setlinkstatus(Project *pr, int index, char value, StatusType *s, double *k
|
||||
|
||||
Slink *link = &net->Link[index];
|
||||
LinkType t = link->Type;
|
||||
|
||||
// Status set to open
|
||||
|
||||
// Status set to open
|
||||
if (value == 1)
|
||||
{
|
||||
// Adjust link setting for pumps & valves
|
||||
// Adjust link setting for pumps & valves
|
||||
if (t == PUMP) *k = 1.0;
|
||||
if (t > PUMP && t != GPV) *k = MISSING;
|
||||
|
||||
@@ -479,7 +482,7 @@ void setlinkstatus(Project *pr, int index, char value, StatusType *s, double *k
|
||||
*s = OPEN;
|
||||
}
|
||||
|
||||
// Status set to closed
|
||||
// Status set to closed
|
||||
else if (value == 0)
|
||||
{
|
||||
// Adjust link setting for pumps & valves
|
||||
@@ -509,7 +512,7 @@ void setlinksetting(Project *pr, int index, double value, StatusType *s,
|
||||
|
||||
Slink *link = &net->Link[index];
|
||||
LinkType t = link->Type;
|
||||
|
||||
|
||||
// For a pump, status is OPEN if speed > 0, CLOSED otherwise
|
||||
if (t == PUMP)
|
||||
{
|
||||
@@ -531,15 +534,15 @@ void setlinksetting(Project *pr, int index, double value, StatusType *s,
|
||||
if (*k == MISSING && *s <= CLOSED) *s = OPEN;
|
||||
*k = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void demands(Project *pr)
|
||||
/*
|
||||
**--------------------------------------------------------------------
|
||||
** Input: none
|
||||
** Output: none
|
||||
** Purpose: computes demands at nodes during current time period
|
||||
** Input: none
|
||||
** Output: none
|
||||
** Purpose: computes demands at nodes during current time period
|
||||
**--------------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -610,9 +613,9 @@ void demands(Project *pr)
|
||||
int controls(Project *pr)
|
||||
/*
|
||||
**---------------------------------------------------------------------
|
||||
** Input: none
|
||||
** Output: number of links whose setting changes
|
||||
** Purpose: implements simple controls based on time or tank levels
|
||||
** Input: none
|
||||
** Output: number of links whose setting changes
|
||||
** Purpose: implements simple controls based on time or tank levels
|
||||
**---------------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -626,7 +629,7 @@ int controls(Project *pr)
|
||||
double k1, k2;
|
||||
char s1, s2;
|
||||
Slink *link;
|
||||
Scontrol *control;
|
||||
Scontrol *control;
|
||||
|
||||
// Examine each control statement
|
||||
setsum = 0;
|
||||
@@ -680,7 +683,7 @@ int controls(Project *pr)
|
||||
if (pr->report.Statflag) writecontrolaction(pr,k,i);
|
||||
setsum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return setsum;
|
||||
}
|
||||
@@ -689,9 +692,9 @@ int controls(Project *pr)
|
||||
long timestep(Project *pr)
|
||||
/*
|
||||
**----------------------------------------------------------------
|
||||
** Input: none
|
||||
** Output: returns time step until next change in hydraulics
|
||||
** Purpose: computes time step to advance hydraulic simulation
|
||||
** Input: none
|
||||
** Output: returns time step until next change in hydraulics
|
||||
** Purpose: computes time step to advance hydraulic simulation
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -699,26 +702,26 @@ long timestep(Project *pr)
|
||||
Times *time = &pr->times;
|
||||
|
||||
long n, t, tstep;
|
||||
|
||||
|
||||
// Normal time step is hydraulic time step
|
||||
tstep = time->Hstep;
|
||||
|
||||
|
||||
// Revise time step based on time until next demand period
|
||||
// (n = next pattern period, t = time till next period)
|
||||
n = ((time->Htime + time->Pstart) / time->Pstep) + 1;
|
||||
t = n * time->Pstep - time->Htime;
|
||||
if (t > 0 && t < tstep) tstep = t;
|
||||
|
||||
|
||||
// Revise time step based on time until next reporting period
|
||||
t = time->Rtime - time->Htime;
|
||||
if (t > 0 && t < tstep) tstep = t;
|
||||
|
||||
|
||||
// Revise time step based on smallest time to fill or drain a tank
|
||||
tanktimestep(pr, &tstep);
|
||||
|
||||
|
||||
// Revise time step based on smallest time to activate a control
|
||||
controltimestep(pr, &tstep);
|
||||
|
||||
|
||||
// Evaluate rule-based controls (which will also update tank levels)
|
||||
if (net->Nrules > 0) ruletimestep(pr, &tstep);
|
||||
else tanklevels(pr, tstep);
|
||||
@@ -729,10 +732,10 @@ long timestep(Project *pr)
|
||||
int tanktimestep(Project *pr, long *tstep)
|
||||
/*
|
||||
**-----------------------------------------------------------------
|
||||
** Input: *tstep = current time step
|
||||
** Output: *tstep = modified current time step
|
||||
** Input: *tstep = current time step
|
||||
** Output: *tstep = modified current time step
|
||||
** Purpose: revises time step based on shortest time to fill or
|
||||
** drain a tank
|
||||
** drain a tank
|
||||
**-----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -777,10 +780,10 @@ int tanktimestep(Project *pr, long *tstep)
|
||||
void controltimestep(Project *pr, long *tstep)
|
||||
/*
|
||||
**------------------------------------------------------------------
|
||||
** Input: *tstep = current time step
|
||||
** Output: *tstep = modified current time step
|
||||
** Input: *tstep = current time step
|
||||
** Output: *tstep = modified current time step
|
||||
** Purpose: revises time step based on shortest time to activate
|
||||
** a simple control
|
||||
** a simple control
|
||||
**------------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -792,24 +795,24 @@ void controltimestep(Project *pr, long *tstep)
|
||||
long t, t1, t2;
|
||||
Slink *link;
|
||||
Scontrol *control;
|
||||
|
||||
|
||||
// Examine each control
|
||||
for (i = 1; i <= net->Ncontrols; i++)
|
||||
{
|
||||
t = 0;
|
||||
control = &net->Control[i];
|
||||
|
||||
// Control depends on a tank level
|
||||
// Control depends on a tank level
|
||||
if ( (n = control->Node) > 0)
|
||||
{
|
||||
// Skip node if not a tank or reservoir
|
||||
if ((j = n - net->Njuncs) <= 0) continue;
|
||||
|
||||
|
||||
// Find current head and flow into tank
|
||||
h = hyd->NodeHead[n];
|
||||
q = hyd->NodeDemand[n];
|
||||
if (ABS(q) <= QZERO) continue;
|
||||
|
||||
|
||||
// Find time to reach upper or lower control level
|
||||
if ( (h < control->Grade && control->Type == HILEVEL && q > 0.0)
|
||||
|| (h > control->Grade && control->Type == LOWLEVEL && q < 0.0) )
|
||||
@@ -821,7 +824,7 @@ void controltimestep(Project *pr, long *tstep)
|
||||
|
||||
// Control is based on elapsed time
|
||||
if (control->Type == TIMER)
|
||||
{
|
||||
{
|
||||
if (control->Time > pr->times.Htime)
|
||||
{
|
||||
t = control->Time - pr->times.Htime;
|
||||
@@ -853,16 +856,16 @@ void controltimestep(Project *pr, long *tstep)
|
||||
void ruletimestep(Project *pr, long *tstep)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: *tstep = current time step (sec)
|
||||
** Output: *tstep = modified time step
|
||||
** Input: *tstep = current time step (sec)
|
||||
** Output: *tstep = modified time step
|
||||
** Purpose: updates next time step by checking if any rules
|
||||
** will fire before then; also updates tank levels.
|
||||
** will fire before then; also updates tank levels.
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Times *time = &pr->times;
|
||||
|
||||
|
||||
long tnow, // Start of time interval for rule evaluation
|
||||
tmax, // End of time interval for rule evaluation
|
||||
dt, // Normal time increment for rule evaluation
|
||||
@@ -880,7 +883,7 @@ void ruletimestep(Project *pr, long *tstep)
|
||||
}
|
||||
|
||||
// Otherwise, time increment equals rule evaluation time step and
|
||||
// first actual increment equals time until next even multiple of
|
||||
// first actual increment equals time until next even multiple of
|
||||
// Rulestep occurs.
|
||||
else
|
||||
{
|
||||
@@ -888,7 +891,7 @@ void ruletimestep(Project *pr, long *tstep)
|
||||
dt1 = time->Rulestep - (tnow % time->Rulestep);
|
||||
}
|
||||
|
||||
// Make sure time increment is no larger than current time step
|
||||
// Make sure time increment is no larger than current time step
|
||||
dt = MIN(dt, *tstep);
|
||||
dt1 = MIN(dt1, *tstep);
|
||||
if (dt1 == 0) dt1 = dt;
|
||||
@@ -918,14 +921,14 @@ void ruletimestep(Project *pr, long *tstep)
|
||||
*tstep = time->Htime - tnow;
|
||||
time->Htime = tnow;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void addenergy(Project *pr, long hstep)
|
||||
/*
|
||||
**-------------------------------------------------------------
|
||||
** Input: hstep = time step (sec)
|
||||
** Output: none
|
||||
** Purpose: accumulates pump energy usage
|
||||
** Input: hstep = time step (sec)
|
||||
** Output: none
|
||||
** Purpose: accumulates pump energy usage
|
||||
**-------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -1003,10 +1006,10 @@ void addenergy(Project *pr, long hstep)
|
||||
void getenergy(Project *pr, int k, double *kw, double *eff)
|
||||
/*
|
||||
**----------------------------------------------------------------
|
||||
** Input: k = link index
|
||||
** Input: k = link index
|
||||
** Output: *kw = kwatt energy used
|
||||
** *eff = efficiency (pumps only)
|
||||
** Purpose: computes flow energy associated with link k
|
||||
** Purpose: computes flow energy associated with link k
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -1022,7 +1025,7 @@ void getenergy(Project *pr, int k, double *kw, double *eff)
|
||||
double speed; // current speed setting
|
||||
Scurve *curve;
|
||||
Slink *link = &net->Link[k];
|
||||
|
||||
|
||||
// No energy if link is closed
|
||||
if (hyd->LinkStatus[k] <= CLOSED)
|
||||
{
|
||||
@@ -1065,10 +1068,10 @@ void getenergy(Project *pr, int k, double *kw, double *eff)
|
||||
void tanklevels(Project *pr, long tstep)
|
||||
/*
|
||||
**----------------------------------------------------------------
|
||||
** Input: tstep = current time step
|
||||
** Output: none
|
||||
** Purpose: computes new water levels in tanks after current
|
||||
** time step
|
||||
** Input: tstep = current time step
|
||||
** Output: none
|
||||
** Purpose: computes new water levels in tanks after current
|
||||
** time step
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -1077,17 +1080,17 @@ void tanklevels(Project *pr, long tstep)
|
||||
|
||||
int i, n;
|
||||
double dv;
|
||||
|
||||
|
||||
for (i = 1; i <= net->Ntanks; i++)
|
||||
{
|
||||
Stank *tank = &net->Tank[i];
|
||||
if (tank->A == 0.0) continue; // Skip reservoirs
|
||||
|
||||
// Update the tank's volume & water elevation
|
||||
|
||||
// Update the tank's volume & water elevation
|
||||
n = tank->Node;
|
||||
dv = hyd->NodeDemand[n] * tstep;
|
||||
tank->V += dv;
|
||||
|
||||
|
||||
// Check if tank full/empty within next second
|
||||
if (tank->V + hyd->NodeDemand[n] >= tank->Vmax)
|
||||
{
|
||||
@@ -1105,10 +1108,10 @@ void tanklevels(Project *pr, long tstep)
|
||||
double tankvolume(Project *pr, int i, double h)
|
||||
/*
|
||||
**--------------------------------------------------------------------
|
||||
** Input: i = tank index
|
||||
** h = water elevation in tank
|
||||
** Output: returns water volume in tank
|
||||
** Purpose: finds water volume in tank i corresponding to elev. h.
|
||||
** Input: i = tank index
|
||||
** h = water elevation in tank
|
||||
** Output: returns water volume in tank
|
||||
** Purpose: finds water volume in tank i corresponding to elev. h.
|
||||
**--------------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -1122,7 +1125,7 @@ double tankvolume(Project *pr, int i, double h)
|
||||
// Use level*area if no volume curve
|
||||
j = tank->Vcurve;
|
||||
if (j == 0) return(tank->Vmin + (h - tank->Hmin) * tank->A);
|
||||
|
||||
|
||||
// If curve exists, interpolate on h to find volume v
|
||||
// remembering that volume curve is in original units.
|
||||
else
|
||||
@@ -1138,10 +1141,10 @@ double tankvolume(Project *pr, int i, double h)
|
||||
double tankgrade(Project *pr, int i, double v)
|
||||
/*
|
||||
**-------------------------------------------------------------------
|
||||
** Input: i = tank index
|
||||
** v = volume in tank
|
||||
** Output: returns water level in tank
|
||||
** Purpose: finds water level in tank i corresponding to volume v.
|
||||
** Input: i = tank index
|
||||
** v = volume in tank
|
||||
** Output: returns water level in tank
|
||||
** Purpose: finds water level in tank i corresponding to volume v.
|
||||
**-------------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -1154,7 +1157,7 @@ double tankgrade(Project *pr, int i, double v)
|
||||
// Use area if no volume curve
|
||||
j = tank->Vcurve;
|
||||
if (j == 0) return(tank->Hmin + (v - tank->Vmin) / tank->A);
|
||||
|
||||
|
||||
// If curve exists, interpolate on volume (originally the Y-variable
|
||||
// but used here as the X-variable) to find new level above bottom.
|
||||
// Remember that volume curve is stored in original units.
|
||||
|
||||
@@ -12,13 +12,16 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "types.h"
|
||||
@@ -453,7 +456,7 @@ void newlinkflows(Project *pr, Hydbalance *hbal, double *qsum, double *dqsum)
|
||||
hbal->maxflownode = -1;
|
||||
}
|
||||
|
||||
// Update net flows to fixed grade nodes
|
||||
// Update net flows to fixed grade nodes
|
||||
if (hyd->LinkStatus[k] > CLOSED)
|
||||
{
|
||||
if (n1 > net->Njuncs) hyd->NodeDemand[n1] -= hyd->LinkFlow[k];
|
||||
@@ -487,7 +490,7 @@ void newemitterflows(Project *pr, Hydbalance *hbal, double *qsum,
|
||||
// Skip junction if it does not have an emitter
|
||||
if (net->Node[i].Ke == 0.0) continue;
|
||||
|
||||
// Find emitter head loss and gradient
|
||||
// Find emitter head loss and gradient
|
||||
emitheadloss(pr, i, &hloss, &hgrad);
|
||||
|
||||
// Find emitter flow change
|
||||
|
||||
@@ -10,8 +10,15 @@ License: see LICENSE
|
||||
Last Updated: 11/27/2018
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "funcs.h"
|
||||
|
||||
@@ -48,7 +55,7 @@ int valvestatus(Project *pr)
|
||||
n1, n2; // Start & end nodes
|
||||
double hset; // Valve head setting
|
||||
StatusType status; // Valve status settings
|
||||
Slink *link;
|
||||
Slink *link;
|
||||
|
||||
// Examine each valve
|
||||
for (i = 1; i <= net->Nvalves; i++)
|
||||
@@ -59,7 +66,7 @@ int valvestatus(Project *pr)
|
||||
|
||||
// Ignore valve if its status is fixed to OPEN/CLOSED
|
||||
if (hyd->LinkSetting[k] == MISSING) continue;
|
||||
|
||||
|
||||
// Get start/end node indexes & save current status
|
||||
n1 = link->N1;
|
||||
n2 = link->N2;
|
||||
@@ -449,7 +456,7 @@ void tankstatus(Project *pr, int k, int n1, int n2)
|
||||
|
||||
// Case 2: Downstream head > tank head
|
||||
// (e.g., an open outflow check valve would close)
|
||||
else if (cvstatus(pr, OPEN, h, q) == CLOSED)
|
||||
else if (cvstatus(pr, OPEN, h, q) == CLOSED)
|
||||
{
|
||||
hyd->LinkStatus[k] = TEMPCLOSED;
|
||||
}
|
||||
|
||||
@@ -11,13 +11,16 @@ Last Updated: 04/03/2019
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "types.h"
|
||||
@@ -38,7 +41,7 @@ extern char *TstatTxt[];
|
||||
extern char *RptFlagTxt[];
|
||||
extern char *SectTxt[];
|
||||
|
||||
void saveauxdata(Project *pr, FILE *f)
|
||||
void saveauxdata(Project *pr, FILE *f)
|
||||
/*
|
||||
------------------------------------------------------------
|
||||
Writes auxilary data from original input file to new file.
|
||||
@@ -51,7 +54,7 @@ void saveauxdata(Project *pr, FILE *f)
|
||||
char line[MAXLINE + 1];
|
||||
char s[MAXLINE + 1];
|
||||
FILE *InFile = pr->parser.InFile;
|
||||
|
||||
|
||||
// Re-open the input file
|
||||
if (InFile == NULL)
|
||||
{
|
||||
@@ -88,7 +91,7 @@ void saveauxdata(Project *pr, FILE *f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Write line of auxilary data to file
|
||||
else
|
||||
{
|
||||
@@ -147,7 +150,7 @@ int saveinpfile(Project *pr, const char *fname)
|
||||
// Open the new text file
|
||||
if ((f = fopen(fname, "wt")) == NULL) return 302;
|
||||
|
||||
// Write [TITLE] section
|
||||
// Write [TITLE] section
|
||||
fprintf(f, s_TITLE);
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
@@ -205,7 +208,7 @@ int saveinpfile(Project *pr, const char *fname)
|
||||
}
|
||||
}
|
||||
|
||||
// Write [PIPES] section
|
||||
// Write [PIPES] section
|
||||
fprintf(f, "\n\n");
|
||||
fprintf(f, s_PIPES);
|
||||
for (i = 1; i <= net->Nlinks; i++)
|
||||
@@ -244,7 +247,7 @@ int saveinpfile(Project *pr, const char *fname)
|
||||
// Pump has constant power
|
||||
if (pump->Ptype == CONST_HP) sprintf(s1, " POWER %.4f", link->Km);
|
||||
|
||||
// Pump has a head curve
|
||||
// Pump has a head curve
|
||||
else if ((j = pump->Hcurve) > 0)
|
||||
{
|
||||
sprintf(s1, " HEAD %s", net->Curve[j].ID);
|
||||
@@ -539,7 +542,7 @@ int saveinpfile(Project *pr, const char *fname)
|
||||
fprintf(f, "\n ORDER TANK %-.2f", qual->TankOrder);
|
||||
fprintf(f, "\n GLOBAL BULK %-.6f", qual->Kbulk * SECperDAY);
|
||||
fprintf(f, "\n GLOBAL WALL %-.6f", qual->Kwall * SECperDAY);
|
||||
|
||||
|
||||
if (qual->Climit > 0.0)
|
||||
{
|
||||
fprintf(f, "\n LIMITING POTENTIAL %-.6f", qual->Climit * pr->Ucf[QUALITY]);
|
||||
@@ -548,7 +551,7 @@ int saveinpfile(Project *pr, const char *fname)
|
||||
{
|
||||
fprintf(f, "\n ROUGHNESS CORRELATION %-.6f", qual->Rfactor);
|
||||
}
|
||||
|
||||
|
||||
// Pipe-specific parameters
|
||||
for (i = 1; i <= net->Nlinks; i++)
|
||||
{
|
||||
|
||||
31
src/input1.c
31
src/input1.c
@@ -3,7 +3,7 @@
|
||||
Project: OWA EPANET
|
||||
Version: 2.2
|
||||
Module: input1.c
|
||||
Description: retrieves network data from an EPANET input file
|
||||
Description: retrieves network data from an EPANET input file
|
||||
Authors: see AUTHORS
|
||||
Copyright: see AUTHORS
|
||||
License: see LICENSE
|
||||
@@ -11,18 +11,23 @@ Last Updated: 04/03/2019
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "funcs.h"
|
||||
#include "hash.h"
|
||||
#include "text.h"
|
||||
#include <math.h>
|
||||
|
||||
|
||||
// Default values
|
||||
#define MAXITER 200 // Default max. # hydraulic iterations
|
||||
@@ -56,7 +61,7 @@ int getdata(Project *pr)
|
||||
int errcode = 0;
|
||||
|
||||
// Assign default data values & reporting options
|
||||
setdefaults(pr);
|
||||
setdefaults(pr);
|
||||
initreport(&pr->report);
|
||||
|
||||
// Read in network data
|
||||
@@ -103,7 +108,7 @@ void setdefaults(Project *pr)
|
||||
parser->DefPat = 0; // Default demand pattern index
|
||||
out->Hydflag = SCRATCH; // No external hydraulics file
|
||||
rpt->Tstatflag = SERIES; // Generate time series output
|
||||
|
||||
|
||||
hyd->Formflag = HW; // Use Hazen-Williams formula
|
||||
hyd->Htol = HTOL; // Default head tolerance
|
||||
hyd->Qtol = QTOL; // Default flow tolerance
|
||||
@@ -349,7 +354,7 @@ int inittanks(Project *pr)
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
|
||||
|
||||
int i, j, n = 0;
|
||||
double a;
|
||||
int errcode = 0, levelerr;
|
||||
@@ -542,7 +547,7 @@ void convertunits(Project *pr)
|
||||
Slink *link;
|
||||
Spump *pump;
|
||||
Scontrol *control;
|
||||
|
||||
|
||||
// Convert nodal elevations & initial WQ
|
||||
// (WQ source units are converted in QUALITY.C
|
||||
for (i = 1; i <= net->Nnodes; i++)
|
||||
@@ -640,7 +645,7 @@ void convertunits(Project *pr)
|
||||
pump->H0 /= pr->Ucf[HEAD];
|
||||
pump->R *= (pow(pr->Ucf[FLOW], pump->N) / pr->Ucf[HEAD]);
|
||||
}
|
||||
|
||||
|
||||
// Convert flow range & max. head units
|
||||
pump->Q0 /= pr->Ucf[FLOW];
|
||||
pump->Qmax /= pr->Ucf[FLOW];
|
||||
@@ -649,7 +654,7 @@ void convertunits(Project *pr)
|
||||
}
|
||||
else
|
||||
{
|
||||
// For flow control valves, convert flow setting
|
||||
// For flow control valves, convert flow setting
|
||||
// while for other valves convert pressure setting
|
||||
link->Diam /= pr->Ucf[DIAM];
|
||||
link->Km = 0.02517 * link->Km / SQR(link->Diam) / SQR(link->Diam);
|
||||
|
||||
62
src/input2.c
62
src/input2.c
@@ -11,12 +11,16 @@ Last Updated: 04/03/2019
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "types.h"
|
||||
@@ -56,7 +60,7 @@ int netsize(Project *pr)
|
||||
*/
|
||||
{
|
||||
Parser *parser = &pr->parser;
|
||||
|
||||
|
||||
char line[MAXLINE + 1]; // Line from input data file
|
||||
char *tok; // First token of line
|
||||
int sect, newsect; // Input data sections
|
||||
@@ -246,10 +250,10 @@ int readdata(Project *pr)
|
||||
// Stop if reach end of file or max. error count
|
||||
if (errsum == MAXERRS) break;
|
||||
}
|
||||
|
||||
|
||||
// Check for errors
|
||||
if (errsum > 0) errcode = 200;
|
||||
|
||||
|
||||
// Check for unlinked nodes
|
||||
if (!errcode) errcode = unlinked(pr);
|
||||
|
||||
@@ -397,7 +401,7 @@ int updatepumpparams(Project *pr, int pumpindex)
|
||||
curve->Type = PUMP_CURVE;
|
||||
npts = curve->Npts;
|
||||
|
||||
// Generic power function curve
|
||||
// Generic power function curve
|
||||
if (npts == 1)
|
||||
{
|
||||
pump->Ptype = POWER_FUNC;
|
||||
@@ -407,7 +411,7 @@ int updatepumpparams(Project *pr, int pumpindex)
|
||||
q2 = 2.0 * q1;
|
||||
h2 = 0.0;
|
||||
}
|
||||
|
||||
|
||||
// 3 point curve with shutoff head
|
||||
else if (npts == 3 && curve->X[0] == 0.0)
|
||||
{
|
||||
@@ -418,7 +422,7 @@ int updatepumpparams(Project *pr, int pumpindex)
|
||||
q2 = curve->X[2];
|
||||
h2 = curve->Y[2];
|
||||
}
|
||||
|
||||
|
||||
// Custom pump curve
|
||||
else
|
||||
{
|
||||
@@ -431,7 +435,7 @@ int updatepumpparams(Project *pr, int pumpindex)
|
||||
pump->Q0 = (curve->X[0] + pump->Qmax) / 2.0;
|
||||
pump->Hmax = curve->Y[0];
|
||||
}
|
||||
|
||||
|
||||
// Compute shape factors & limits of power function curves
|
||||
if (pump->Ptype == POWER_FUNC)
|
||||
{
|
||||
@@ -461,7 +465,7 @@ int addnodeID(Network *net, int n, char *id)
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
if (findnode(net,id)) return 0;
|
||||
if (findnode(net,id)) return 0;
|
||||
strncpy(net->Node[n].ID, id, MAXID);
|
||||
hashtable_insert(net->NodeHashTable, net->Node[n].ID, n);
|
||||
return 1;
|
||||
@@ -587,7 +591,7 @@ int unlinked(Project *pr)
|
||||
Network *net = &pr->network;
|
||||
int *marked;
|
||||
int i, err, errcode;
|
||||
|
||||
|
||||
errcode = 0;
|
||||
err = 0;
|
||||
|
||||
@@ -596,19 +600,19 @@ int unlinked(Project *pr)
|
||||
ERRCODE(MEMCHECK(marked));
|
||||
if (errcode) return errcode;
|
||||
memset(marked, 0, (net->Nnodes + 1) * sizeof(int));
|
||||
|
||||
|
||||
// Mark end nodes of each link
|
||||
for (i = 1; i <= net->Nlinks; i++)
|
||||
{
|
||||
marked[net->Link[i].N1]++;
|
||||
marked[net->Link[i].N2]++;
|
||||
}
|
||||
|
||||
|
||||
// Check each junction
|
||||
for (i = 1; i <= net->Njuncs; i++)
|
||||
{
|
||||
// If not marked then error
|
||||
if (marked[i] == 0)
|
||||
if (marked[i] == 0)
|
||||
{
|
||||
err++;
|
||||
sprintf(pr->Msg, "Error 233: %s %s", geterrmsg(233, pr->Msg), net->Node[i].ID);
|
||||
@@ -638,7 +642,7 @@ int getpatterns(Project *pr)
|
||||
SFloatlist *f;
|
||||
STmplist *tmppattern;
|
||||
Spattern *pattern;
|
||||
|
||||
|
||||
// Start at head of the list of patterns
|
||||
tmppattern = parser->Patlist;
|
||||
|
||||
@@ -696,7 +700,7 @@ int getcurves(Project *pr)
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Parser *parser = &pr->parser;
|
||||
|
||||
|
||||
int i, j;
|
||||
double x;
|
||||
char errmsg[MAXMSG+1];
|
||||
@@ -827,14 +831,14 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment)
|
||||
int m, n;
|
||||
size_t len;
|
||||
char *c, *c2;
|
||||
|
||||
|
||||
// clear comment
|
||||
comment[0] = '\0';
|
||||
|
||||
|
||||
// Begin with no tokens
|
||||
for (n=0; n<maxToks; n++) Tok[n] = NULL;
|
||||
n = 0;
|
||||
|
||||
|
||||
// Truncate s at start of comment
|
||||
c = strchr(s,';');
|
||||
if (c)
|
||||
@@ -855,7 +859,7 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment)
|
||||
*c = '\0';
|
||||
}
|
||||
len = (int)strlen(s);
|
||||
|
||||
|
||||
// Scan s for tokens until nothing left
|
||||
while (len > 0 && n < MAXTOKS)
|
||||
{
|
||||
@@ -874,7 +878,7 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment)
|
||||
{
|
||||
s++; // Start token after quote
|
||||
m = (int)strcspn(s,"\"\n\r"); // Find end quote (or EOL)
|
||||
}
|
||||
}
|
||||
s[m] = '\0'; // Null-terminate the token
|
||||
Tok[n] = s; // Save pointer to token
|
||||
n++; // Update token count
|
||||
@@ -882,7 +886,7 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment)
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
double hour(char *time, char *units)
|
||||
/*
|
||||
@@ -920,7 +924,7 @@ double hour(char *time, char *units)
|
||||
if (match(units, w_DAYS)) return (y[0] * 24.0);
|
||||
}
|
||||
|
||||
// Convert hh:mm:ss format to decimal hours
|
||||
// Convert hh:mm:ss format to decimal hours
|
||||
if (n > 1) y[0] = y[0] + y[1] / 60.0 + y[2] / 3600.0;
|
||||
|
||||
// If am/pm attached then adjust hour accordingly
|
||||
@@ -939,7 +943,7 @@ double hour(char *time, char *units)
|
||||
else return (y[0] + 12.0);
|
||||
}
|
||||
return -1.0;
|
||||
}
|
||||
}
|
||||
|
||||
int getfloat(char *s, double *y)
|
||||
/*
|
||||
@@ -985,14 +989,14 @@ void inperrmsg(Project *pr, int err, int sect, char *line)
|
||||
*/
|
||||
{
|
||||
Parser *parser = &pr->parser;
|
||||
|
||||
|
||||
char errStr[MAXMSG + 1] = "";
|
||||
char tok[MAXMSG + 1];
|
||||
|
||||
// Get token associated with input error
|
||||
if (parser->ErrTok >= 0) strcpy(tok, parser->Tok[parser->ErrTok]);
|
||||
else strcpy(tok, "");
|
||||
|
||||
|
||||
// write error message to report file
|
||||
sprintf(pr->Msg, "Error %d: %s %s in %s section:",
|
||||
err, geterrmsg(err, errStr), tok, SectTxt[sect]);
|
||||
|
||||
14
src/input3.c
14
src/input3.c
@@ -11,12 +11,16 @@ Last Updated: 03/17/2019
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
@@ -14,10 +14,14 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "mempool.h"
|
||||
|
||||
/*
|
||||
|
||||
47
src/output.c
47
src/output.c
@@ -11,13 +11,16 @@ Last Updated: 11/27/2018
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "types.h"
|
||||
@@ -32,7 +35,7 @@ static int savetimestat(Project *, REAL4 *, HdrType);
|
||||
static int savenetreacts(Project *, double, double, double, double);
|
||||
static int saveepilog(Project *);
|
||||
|
||||
// Functions to write/read x[1] to x[n] to/from binary file
|
||||
// Functions to write/read x[1] to x[n] to/from binary file
|
||||
size_t f_save(REAL4 *x, int n, FILE *file)
|
||||
{
|
||||
return fwrite(x + 1, sizeof(REAL4), n, file);
|
||||
@@ -79,7 +82,7 @@ int savenetdata(Project *pr)
|
||||
{
|
||||
// Write integer variables to outFile
|
||||
ibuf[0] = MAGICNUMBER;
|
||||
ibuf[1] = 20012; // keep version at 2.00.12 so that GUI will run
|
||||
ibuf[1] = 20012; // keep version at 2.00.12 so that GUI will run
|
||||
ibuf[2] = net->Nnodes;
|
||||
ibuf[3] = net->Ntanks;
|
||||
ibuf[4] = net->Nlinks;
|
||||
@@ -141,7 +144,7 @@ int savenetdata(Project *pr)
|
||||
x[i] = (REAL4)(net->Node[i].El * pr->Ucf[ELEV]);
|
||||
}
|
||||
f_save(x, net->Nnodes, outFile);
|
||||
|
||||
|
||||
// Save link lengths & diameters to outFile
|
||||
for (i = 1; i <= net->Nlinks; i++)
|
||||
{
|
||||
@@ -185,7 +188,7 @@ int savehyd(Project *pr, long *htime)
|
||||
int errcode = 0;
|
||||
REAL4 *x;
|
||||
FILE *HydFile = out->HydFile;
|
||||
|
||||
|
||||
x = (REAL4 *)calloc(MAX(net->Nnodes, net->Nlinks) + 1, sizeof(REAL4));
|
||||
if (x == NULL) return 101;
|
||||
|
||||
@@ -212,13 +215,13 @@ int savehyd(Project *pr, long *htime)
|
||||
fwrite(x + 1, sizeof(REAL4), net->Nlinks, HydFile);
|
||||
//f_save(x, net->Nlinks, HydFile);
|
||||
|
||||
// Save link status
|
||||
// Save link status
|
||||
for (i = 1; i <= net->Nlinks; i++) x[i] = (REAL4)hyd->LinkStatus[i];
|
||||
fwrite(x + 1, sizeof(REAL4), net->Nlinks, HydFile);
|
||||
//f_save(x, net->Nlinks, HydFile);
|
||||
|
||||
// Save link settings & check for successful write-to-disk
|
||||
// (We assume that if any of the previous fwrites failed,
|
||||
// Save link settings & check for successful write-to-disk
|
||||
// (We assume that if any of the previous fwrites failed,
|
||||
// then this one will also fail.)
|
||||
for (i = 1; i <= net->Nlinks; i++) x[i] = (REAL4)hyd->LinkSetting[i];
|
||||
if (fwrite(x + 1, sizeof(REAL4), net->Nlinks, HydFile) <
|
||||
@@ -354,7 +357,7 @@ int readhyd(Project *pr, long *hydtime)
|
||||
int result = 1;
|
||||
REAL4 *x;
|
||||
FILE *HydFile = out->HydFile;
|
||||
|
||||
|
||||
x = (REAL4 *)calloc(MAX(net->Nnodes, net->Nlinks) + 1, sizeof(REAL4));
|
||||
if (x == NULL) return 0;
|
||||
|
||||
@@ -473,7 +476,7 @@ int nodeoutput(Project *pr, int j, REAL4 *x, double ucf)
|
||||
}
|
||||
}
|
||||
|
||||
// Write x[1] to x[net->Nnodes] to output file
|
||||
// Write x[1] to x[net->Nnodes] to output file
|
||||
if (f_save(x, net->Nnodes, outFile) < (unsigned)net->Nnodes) return 308;
|
||||
return 0;
|
||||
}
|
||||
@@ -497,7 +500,7 @@ int linkoutput(Project *pr, int j, REAL4 *x, double ucf)
|
||||
int i;
|
||||
double a, h, q, f, setting;
|
||||
FILE *outFile = out->TmpOutFile;
|
||||
|
||||
|
||||
// Load computed results (in proper units) into buffer x
|
||||
switch (j)
|
||||
{
|
||||
@@ -631,7 +634,7 @@ int savefinaloutput(Project *pr)
|
||||
int errcode = 0;
|
||||
REAL4 *x;
|
||||
FILE *outFile = out->OutFile;
|
||||
|
||||
|
||||
// Save time series statistic if computed
|
||||
if (rpt->Tstatflag != SERIES && out->TmpOutFile != NULL)
|
||||
{
|
||||
@@ -680,7 +683,7 @@ int savetimestat(Project *pr, REAL4 *x, HdrType objtype)
|
||||
long startbyte, skipbytes;
|
||||
float *stat1, *stat2, xx;
|
||||
FILE *outFile = out->OutFile;
|
||||
|
||||
|
||||
// Compute number of bytes in temp output file to skip over (skipbytes)
|
||||
// when moving from one time period to the next for a particular variable
|
||||
if (objtype == NODEHDR)
|
||||
@@ -722,11 +725,11 @@ int savetimestat(Project *pr, REAL4 *x, HdrType objtype)
|
||||
stat2[i] = MISSING;
|
||||
}
|
||||
|
||||
// Position temp output file at start of output
|
||||
// Position temp output file at start of output
|
||||
fseek(out->TmpOutFile, startbyte + (j - n1) * n * sizeof(REAL4),
|
||||
SEEK_SET);
|
||||
|
||||
// Process each time period
|
||||
// Process each time period
|
||||
for (p = 1; p <= rpt->Nperiods; p++)
|
||||
{
|
||||
// Get output results for time period & update stats
|
||||
@@ -751,7 +754,7 @@ int savetimestat(Project *pr, REAL4 *x, HdrType objtype)
|
||||
}
|
||||
}
|
||||
|
||||
// Advance file to next period
|
||||
// Advance file to next period
|
||||
if (p < rpt->Nperiods) fseek(out->TmpOutFile, skipbytes, SEEK_CUR);
|
||||
}
|
||||
|
||||
@@ -821,7 +824,7 @@ int savenetreacts(Project *pr, double wbulk, double wwall, double wtank, double
|
||||
double t;
|
||||
REAL4 w[4];
|
||||
FILE *outFile = out->OutFile;
|
||||
|
||||
|
||||
if (time->Dur > 0) t = (double)time->Dur / 3600.;
|
||||
else t = 1.;
|
||||
w[0] = (REAL4)(wbulk / t);
|
||||
@@ -846,7 +849,7 @@ int saveepilog(Project *pr)
|
||||
int errcode = 0;
|
||||
INT4 i;
|
||||
FILE *outFile = out->OutFile;
|
||||
|
||||
|
||||
i = rpt->Nperiods;
|
||||
if (fwrite(&i, sizeof(INT4), 1, outFile) < 1) errcode = 308;
|
||||
i = pr->Warnflag;
|
||||
|
||||
@@ -11,7 +11,13 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@@ -11,13 +11,16 @@ Last Updated: 11/27/2018
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "mempool.h"
|
||||
@@ -60,7 +63,7 @@ int openqual(Project *pr)
|
||||
|
||||
int errcode = 0;
|
||||
int n;
|
||||
|
||||
|
||||
// Return if no quality analysis requested
|
||||
if (qual->Qualflag == NONE) return errcode;
|
||||
|
||||
|
||||
@@ -11,6 +11,13 @@ Last Updated: 11/27/2018
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "types.h"
|
||||
|
||||
@@ -11,13 +11,17 @@ Last Updated: 11/27/2018
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "mempool.h"
|
||||
#include "types.h"
|
||||
|
||||
|
||||
16
src/report.c
16
src/report.c
@@ -11,13 +11,15 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define snprintf _snprintf
|
||||
@@ -83,7 +85,7 @@ int copyreport(Project* pr, char *filename)
|
||||
FILE *tfile;
|
||||
int c;
|
||||
Report *rpt = &pr->report;
|
||||
|
||||
|
||||
// Check that project's report file exists
|
||||
if (rpt->RptFile == NULL) return 0;
|
||||
|
||||
@@ -101,7 +103,7 @@ int copyreport(Project* pr, char *filename)
|
||||
while ((c = fgetc(rpt->RptFile)) != EOF) fputc(c, tfile);
|
||||
fclose(rpt->RptFile);
|
||||
}
|
||||
|
||||
|
||||
// Close destination file
|
||||
fclose(tfile);
|
||||
|
||||
|
||||
12
src/rules.c
12
src/rules.c
@@ -11,13 +11,15 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "types.h"
|
||||
#include "funcs.h"
|
||||
|
||||
@@ -18,13 +18,16 @@
|
||||
linsolve() -- called from netsolve() in HYDRAUL.C
|
||||
*/
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ set(toolkit_test_srcs
|
||||
test_pattern.cpp
|
||||
test_curve.cpp
|
||||
test_control.cpp
|
||||
test_net_builder.cpp)
|
||||
test_net_builder.cpp
|
||||
)
|
||||
|
||||
add_executable(test_toolkit ${toolkit_test_srcs})
|
||||
|
||||
|
||||
@@ -22,9 +22,10 @@ BOOST_AUTO_TEST_SUITE (test_analysis)
|
||||
BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose)
|
||||
{
|
||||
int i;
|
||||
double array[12];
|
||||
|
||||
std::vector<double> test;
|
||||
std::vector<double> test(12);
|
||||
double *array = test.data();
|
||||
|
||||
std::vector<double> ref = {40.0, 0.001, 0.01, 0.5, 1.0, 0.0, 0.0, 0.0, 75.0, 0.0, 0.0, 0.0};
|
||||
|
||||
error = EN_solveH(ph);
|
||||
@@ -35,23 +36,24 @@ BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose)
|
||||
|
||||
|
||||
for (i=EN_TRIALS; i<=EN_DEMANDCHARGE; i++) {
|
||||
error = EN_getoption(ph, i, &array[i]);
|
||||
error = EN_getoption(ph, i, array++);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
}
|
||||
|
||||
test.assign(array, array + 12);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
|
||||
|
||||
error = EN_getoption(ph, 18, &array[0]);
|
||||
double temp;
|
||||
error = EN_getoption(ph, 18, &temp);
|
||||
BOOST_CHECK(error == 251);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(test_anlys_gettimeparam, FixtureOpenClose)
|
||||
{
|
||||
int i;
|
||||
long array[16];
|
||||
|
||||
std::vector<long> test;
|
||||
std::vector<long> test(16);
|
||||
long *array = test.data();
|
||||
|
||||
std::vector<long> ref = {86400, 3600, 300, 7200, 0, 3600, 0, 360, 0, 25, 0, 86400, 86400, 0, 3600, 0};
|
||||
|
||||
error = EN_solveH(ph);
|
||||
@@ -62,14 +64,15 @@ BOOST_FIXTURE_TEST_CASE(test_anlys_gettimeparam, FixtureOpenClose)
|
||||
|
||||
|
||||
for (i=EN_DURATION; i<=EN_NEXTEVENTTANK; i++) {
|
||||
error = EN_gettimeparam(ph, i, &array[i]);
|
||||
error = EN_gettimeparam(ph, i, array++);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
}
|
||||
|
||||
test.assign(array, array + 16);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
|
||||
|
||||
error = EN_gettimeparam(ph, 18, &array[0]);
|
||||
long temp;
|
||||
error = EN_gettimeparam(ph, 18, &temp);
|
||||
BOOST_CHECK(error == 251);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -45,7 +45,7 @@ BOOST_FIXTURE_TEST_CASE(test_curve_comments, FixtureOpenClose)
|
||||
int n2;
|
||||
double X2[5], Y2[5];
|
||||
char id2[EN_MAXID+1];
|
||||
|
||||
|
||||
// Add data to a new curve
|
||||
error = EN_addcurve(ph, id1);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
@@ -53,7 +53,7 @@ BOOST_FIXTURE_TEST_CASE(test_curve_comments, FixtureOpenClose)
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_setcurve(ph, i, X1, Y1, n1);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
|
||||
// Retrieve data from curve
|
||||
error = EN_getcurve(ph, i, id2, &n2, X2, Y2);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
@@ -61,8 +61,8 @@ BOOST_FIXTURE_TEST_CASE(test_curve_comments, FixtureOpenClose)
|
||||
BOOST_REQUIRE(n2 == n1);
|
||||
for (i = 0; i < n1; i++)
|
||||
{
|
||||
BOOST_REQUIRE(X1[i] == X2[i]);
|
||||
BOOST_REQUIRE(Y1[i] == Y2[i]);
|
||||
BOOST_CHECK(X1[i] == X2[i]);
|
||||
BOOST_CHECK(Y1[i] == Y2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,14 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include "test_toolkit.hpp"
|
||||
@@ -35,6 +43,9 @@ BOOST_AUTO_TEST_CASE(test_init_close)
|
||||
|
||||
struct FixtureInitClose {
|
||||
FixtureInitClose() {
|
||||
error = 0;
|
||||
ph = NULL;
|
||||
|
||||
EN_createproject(&ph);
|
||||
EN_init(ph, DATA_PATH_RPT, DATA_PATH_OUT, EN_GPM, EN_HW);
|
||||
}
|
||||
@@ -50,55 +61,55 @@ struct FixtureInitClose {
|
||||
|
||||
|
||||
|
||||
//BOOST_AUTO_TEST_CASE(net_builder_I)
|
||||
//{
|
||||
// int error = 0;
|
||||
// int flag = 00;
|
||||
// long t, tstep;
|
||||
// int i, ind, Lindex, Nindex, Cindex;
|
||||
// double h_orig, h_build, h_build_loaded;
|
||||
// BOOST_AUTO_TEST_CASE(net_builder_I)
|
||||
// {
|
||||
// int error = 0;
|
||||
// int flag = 00;
|
||||
// long t, tstep;
|
||||
// int i, ind, Lindex, Nindex, Cindex;
|
||||
// double h_orig, h_build, h_build_loaded;
|
||||
//
|
||||
// // first we load Net1.inp, run it and record the head in Tank 2 at the end of the simulation (h_orig)
|
||||
// EN_Project ph = NULL;
|
||||
// EN_createproject(&ph);
|
||||
// // first we load Net1.inp, run it and record the head in Tank 2 at the end of the simulation (h_orig)
|
||||
// EN_Project ph = NULL;
|
||||
// EN_createproject(&ph);
|
||||
//
|
||||
// std::string path_inp = std::string(DATA_PATH_NET1);
|
||||
// std::string path_rpt = std::string(DATA_PATH_RPT);
|
||||
// std::string path_out = std::string(DATA_PATH_OUT);
|
||||
// std::string path_inp = std::string(DATA_PATH_NET1);
|
||||
// std::string path_rpt = std::string(DATA_PATH_RPT);
|
||||
// std::string path_out = std::string(DATA_PATH_OUT);
|
||||
//
|
||||
// error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
// error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
//
|
||||
// error = EN_getnodeindex(ph, (char *)"2", &Nindex);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
// error = EN_getnodeindex(ph, (char *)"2", &Nindex);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
//
|
||||
// error = EN_openH(ph);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
// error = EN_openH(ph);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
//
|
||||
// error = EN_initH(ph, flag);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
// error = EN_initH(ph, flag);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
//
|
||||
// do {
|
||||
// error = EN_runH(ph, &t);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
// do {
|
||||
// error = EN_runH(ph, &t);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
//
|
||||
// // this is the head at the end of the simulation after loading the original Net1.inp
|
||||
// error = EN_getnodevalue(ph, Nindex, EN_HEAD, &h_orig);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
// // this is the head at the end of the simulation after loading the original Net1.inp
|
||||
// error = EN_getnodevalue(ph, Nindex, EN_HEAD, &h_orig);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
//
|
||||
// error = EN_nextH(ph, &tstep);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
// error = EN_nextH(ph, &tstep);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
//
|
||||
// } while (tstep > 0);
|
||||
// } while (tstep > 0);
|
||||
//
|
||||
// error = EN_closeH(ph);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
// error = EN_closeH(ph);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
//
|
||||
// error = EN_close(ph);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
// error = EN_close(ph);
|
||||
// BOOST_REQUIRE(error == 0);
|
||||
//
|
||||
// EN_deleteproject(&ph);
|
||||
//}
|
||||
// EN_deleteproject(&ph);
|
||||
// }
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(test_build_net1, FixtureInitClose)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
@@ -109,37 +111,39 @@ BOOST_AUTO_TEST_SUITE(test_proj_fixture)
|
||||
BOOST_FIXTURE_TEST_CASE(test_title, FixtureOpenClose)
|
||||
{
|
||||
// How is the API user supposed to know array size?
|
||||
char c_test[3][80], c_ref[3][80];
|
||||
char c_test[3][80];
|
||||
|
||||
strncpy(c_ref[0], " EPANET Example Network 1", 26);
|
||||
strncpy(c_ref[1], "A simple example of modeling chlorine decay. Both bulk and", 59);
|
||||
strncpy(c_ref[2], "wall reactions are included. ", 30);
|
||||
// ref is an automatic variable and therefore doesn't need to be deleted
|
||||
std::string ref[3] = {
|
||||
" EPANET Example Network 1",
|
||||
"A simple example of modeling chlorine decay. Both bulk and",
|
||||
"wall reactions are included. "};
|
||||
|
||||
error = EN_gettitle(ph, c_test[0], c_test[1], c_test[2]);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
std::string test (c_test[i]);
|
||||
std::string ref (c_ref[i]);
|
||||
BOOST_CHECK(check_string(test, ref));
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
std::string test (c_test[i]);
|
||||
BOOST_CHECK(check_string(test, ref[i]));
|
||||
}
|
||||
|
||||
// Need a test for EN_settitle
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(test_getcount, FixtureOpenClose)
|
||||
{
|
||||
int i, array[7];
|
||||
int i;
|
||||
|
||||
std::vector<int> test;
|
||||
std::vector<int> ref = { 11, 2, 13, 1, 1, 2, 0 };
|
||||
std::vector<int> test(7);
|
||||
int *array = test.data();
|
||||
|
||||
std::vector<int> ref = { 11, 2, 13, 1, 1, 2, 0 };
|
||||
|
||||
for (i=EN_NODECOUNT; i<=EN_RULECOUNT; i++) {
|
||||
error = EN_getcount(ph, i, &array[i]);
|
||||
error = EN_getcount(ph, i, array++);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
}
|
||||
|
||||
test.assign(array, array + 7);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
|
||||
|
||||
error = EN_getcount(ph, 7, &i);
|
||||
|
||||
@@ -21,9 +21,10 @@ BOOST_AUTO_TEST_SUITE (test_report)
|
||||
BOOST_FIXTURE_TEST_CASE(test_rprt_anlysstats, FixtureOpenClose)
|
||||
{
|
||||
int i;
|
||||
double array[5];
|
||||
|
||||
std::vector<double> test;
|
||||
std::vector<double> test(5);
|
||||
double *array = test.data();
|
||||
|
||||
std::vector<double> ref = {3.0, 7.0799498320679432e-06, 1.6680242187483429e-08,
|
||||
0.0089173150106518495, 0.99999998187144024};
|
||||
|
||||
@@ -35,15 +36,13 @@ BOOST_FIXTURE_TEST_CASE(test_rprt_anlysstats, FixtureOpenClose)
|
||||
|
||||
|
||||
for (i=EN_ITERATIONS; i<=EN_MASSBALANCE; i++) {
|
||||
error = EN_getstatistic(ph, i, &array[i]);
|
||||
error = EN_getstatistic(ph, i, array++);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
}
|
||||
|
||||
test.assign(array, array + 5);
|
||||
// BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
|
||||
BOOST_CHECK(check_cdd_double(test, ref, 3));
|
||||
|
||||
error = EN_getstatistic(ph, 8, &array[0]);
|
||||
double temp;
|
||||
error = EN_getstatistic(ph, 8, &temp);
|
||||
BOOST_CHECK(error == 251);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#ifndef TEST_TOOLKIT_HPP
|
||||
#define TEST_TOOLKIT_HPP
|
||||
|
||||
|
||||
#include "epanet2_2.h"
|
||||
|
||||
|
||||
@@ -25,6 +24,9 @@
|
||||
|
||||
struct FixtureOpenClose{
|
||||
FixtureOpenClose() {
|
||||
error = 0;
|
||||
ph = NULL;
|
||||
|
||||
EN_createproject(&ph);
|
||||
error = EN_open(ph, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT);
|
||||
}
|
||||
@@ -41,6 +43,9 @@ struct FixtureOpenClose{
|
||||
|
||||
struct FixtureAfterStep{
|
||||
FixtureAfterStep() {
|
||||
error = 0;
|
||||
ph = NULL;
|
||||
|
||||
flag = 0;
|
||||
tstop = 10800;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user