New updates to address compiler warnings (issue #370)
In addition to addressing compiler warnings, argument names in the API function prototypes were made more consistent and descriptive. Also additional Doxygen comments were added in preparation for producing a more thorough documentation of the API.
This commit is contained in:
220
src/epanet.c
220
src/epanet.c
@@ -123,8 +123,8 @@ int DLLEXPORT EN_init(EN_Project p, const char *rptFile, const char *outFile,
|
||||
/*----------------------------------------------------------------
|
||||
** Input: rptFile = name of report file
|
||||
** outFile = name of binary output file
|
||||
** unitsType = type of flow units (see EN_FlowUnits)
|
||||
** headLossType = type of head loss formula (see EN_HeadLossType)
|
||||
** unitsType = type of flow units (see FlowUnitsType)
|
||||
** headLossType = type of head loss formula (see HeadLossType)
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: initializes an EPANET project that isn't opened with
|
||||
@@ -255,7 +255,7 @@ int DLLEXPORT EN_close(EN_Project p)
|
||||
** Input: none
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: frees all memory & files used by EPANET
|
||||
** Purpose: frees all memory & files used by a project
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -367,7 +367,7 @@ int DLLEXPORT EN_saveH(EN_Project p)
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
char tmpflag;
|
||||
int tmpflag;
|
||||
int errcode;
|
||||
|
||||
// Check if hydraulic results exist
|
||||
@@ -392,7 +392,7 @@ int DLLEXPORT EN_openH(EN_Project p)
|
||||
** Input: none
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: opens EPANET's hydraulic solver
|
||||
** Purpose: opens a project's hydraulic solver
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -421,7 +421,7 @@ int DLLEXPORT EN_initH(EN_Project p, int initFlag)
|
||||
** results should be saved to file (1) or not (0)
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: initializes EPANET's hydraulic solver
|
||||
** Purpose: initializes a project's hydraulic solver
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -500,7 +500,7 @@ int DLLEXPORT EN_closeH(EN_Project p)
|
||||
** Input: none
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: closes EPANET's hydraulic solver
|
||||
** Purpose: closes a project's hydraulic solver
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -516,7 +516,7 @@ int DLLEXPORT EN_savehydfile(EN_Project p, char *filename)
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: saves results from a scratch hydraulics file to a
|
||||
** permanent one.
|
||||
** permanent one
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -543,8 +543,8 @@ int DLLEXPORT EN_usehydfile(EN_Project p, char *filename)
|
||||
** Input: filename = name of previously saved hydraulics file
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: uses contents of a previous saved hydraulics file to
|
||||
** run a water quality analysis.
|
||||
** Purpose: uses contents of a previously saved hydraulics file to
|
||||
** run a water quality analysis
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -626,7 +626,7 @@ int DLLEXPORT EN_openQ(EN_Project p)
|
||||
** Input: none
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: opens EPANET's water quality solver
|
||||
** Purpose: opens a project's water quality solver
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -694,7 +694,7 @@ int DLLEXPORT EN_nextQ(EN_Project p, long *tStep)
|
||||
** Output: tStep = time step over which water quality is updated (sec)
|
||||
** Returns: error code
|
||||
** Purpose: updates water quality throughout the network until
|
||||
** next hydraulic event occurs.
|
||||
** next hydraulic event occurs
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -717,7 +717,7 @@ int DLLEXPORT EN_stepQ(EN_Project p, long *timeLeft)
|
||||
** Output: timeLeft = amount of simulation time remaining (sec)
|
||||
** Returns: error code
|
||||
** Purpose: updates water quality throughout the network over
|
||||
** fixed time step.
|
||||
** fixed time step
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -739,7 +739,7 @@ int DLLEXPORT EN_closeQ(EN_Project p)
|
||||
** Input: none
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: closes EPANET's water quality solver
|
||||
** Purpose: closes a project's water quality solver
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -760,7 +760,7 @@ int DLLEXPORT EN_writeline(EN_Project p, char *line)
|
||||
** Input: line = line of text
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: write a line of text to the project's report file
|
||||
** Purpose: write a line of text to a project's report file
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -774,7 +774,7 @@ int DLLEXPORT EN_report(EN_Project p)
|
||||
** Input: none
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: writes formatted simulation results to the project's
|
||||
** Purpose: writes formatted simulation results to a project's
|
||||
** report file
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
@@ -858,11 +858,11 @@ int DLLEXPORT EN_getversion(int *version)
|
||||
** Input: none
|
||||
** Output: version = version number of the source code
|
||||
** Returns: error code (should always be 0)
|
||||
** Purpose: retrieves a number assigned to the most recent
|
||||
** update of the source code. This number, set by the
|
||||
** constant CODEVERSION found in TYPES.H, is to be
|
||||
** interpreted with implied decimals, i.e.,
|
||||
** "20100" == "2(.)01(.)00"
|
||||
** Purpose: retrieves the toolkit API version number
|
||||
**
|
||||
** The version number is set by the constant CODEVERSION found in
|
||||
** TYPES.H and is to be interpreted with implied decimals, i.e.,
|
||||
** "20100" == "2(.)01(.)00".
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -875,7 +875,7 @@ int DLLEXPORT EN_getcount(EN_Project p, int object, int *count)
|
||||
** Input: object = type of object to count (see EN_CountType)
|
||||
** Output: count = number of objects of the specified type
|
||||
** Returns: error code
|
||||
** Purpose: Retrieves number of network objects of a given type.
|
||||
** Purpose: Retrieves number of network objects of a given type
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -1283,7 +1283,7 @@ int DLLEXPORT EN_setflowunits(EN_Project p, int units)
|
||||
|
||||
int DLLEXPORT EN_gettimeparam(EN_Project p, int param, long *value)
|
||||
/*----------------------------------------------------------------
|
||||
** Input: param = time parameter code (see EN_TimeProperty)
|
||||
** Input: param = time parameter code (see EN_TimeParameter)
|
||||
** Output: value = time parameter value
|
||||
** Returns: error code
|
||||
** Purpose: retrieves the value of a time parameter
|
||||
@@ -1297,7 +1297,7 @@ int DLLEXPORT EN_gettimeparam(EN_Project p, int param, long *value)
|
||||
|
||||
*value = 0;
|
||||
if (!p->Openflag) return 102;
|
||||
if (param < EN_DURATION || param > EN_NEXTEVENTIDX) return 251;
|
||||
if (param < EN_DURATION || param > EN_NEXTEVENTTANK) return 251;
|
||||
switch (param)
|
||||
{
|
||||
case EN_DURATION:
|
||||
@@ -1341,7 +1341,7 @@ int DLLEXPORT EN_gettimeparam(EN_Project p, int param, long *value)
|
||||
// or the time to next full/empty tank
|
||||
tanktimestep(p, value);
|
||||
break;
|
||||
case EN_NEXTEVENTIDX:
|
||||
case EN_NEXTEVENTTANK:
|
||||
*value = time->Hstep;
|
||||
i = tanktimestep(p, value);
|
||||
*value = i;
|
||||
@@ -1352,7 +1352,7 @@ int DLLEXPORT EN_gettimeparam(EN_Project p, int param, long *value)
|
||||
|
||||
int DLLEXPORT EN_settimeparam(EN_Project p, int param, long value)
|
||||
/*----------------------------------------------------------------
|
||||
** Input: param = time parameter code (see EN_TimeProperty)
|
||||
** Input: param = time parameter code (see EN_TimeParameter)
|
||||
** value = time parameter value
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
@@ -1493,7 +1493,7 @@ int DLLEXPORT EN_setqualtype(EN_Project p, int qualType, char *chemName,
|
||||
** Input: qualType = type of quality analysis to run (see EN_QualityType)
|
||||
** chemname = name of chemical constituent
|
||||
** chemunits = concentration units of constituent
|
||||
** tracenode = index of node being traced (if applicable)
|
||||
** tracenode = ID name of node being traced (if applicable)
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: sets water quality analysis options
|
||||
@@ -1701,13 +1701,13 @@ int DLLEXPORT EN_deletenode(EN_Project p, int index, int actionCode)
|
||||
** its links appear in a control and returns an error code
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: deletes a node from a project.
|
||||
** Purpose: deletes a node from a project
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
Network *net = &p->network;
|
||||
|
||||
int i, nodeType, tankindex, numControls = 0;
|
||||
int i, nodeType, tankindex;
|
||||
Snode *node;
|
||||
Pdemand demand, nextdemand;
|
||||
Psource source;
|
||||
@@ -2350,7 +2350,7 @@ int DLLEXPORT EN_setjuncdata(EN_Project p, int index, double elev,
|
||||
** dmndpat = name of primary demand time pattern
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: sets several properties for a junction node.
|
||||
** Purpose: sets several properties for a junction node
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -2406,7 +2406,7 @@ int DLLEXPORT EN_settankdata(EN_Project p, int index, double elev,
|
||||
** volCurve = name of curve for volume v. level
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: sets several properties for a tank node.
|
||||
** Purpose: sets several properties for a tank node
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -2415,7 +2415,6 @@ int DLLEXPORT EN_settankdata(EN_Project p, int index, double elev,
|
||||
int i, j, n, curveIndex = 0;
|
||||
double area, elevation = elev;
|
||||
double *Ucf = p->Ucf;
|
||||
Snode *Node = net->Node;
|
||||
Stank *Tank = net->Tank;
|
||||
Scurve *curve;
|
||||
|
||||
@@ -2823,8 +2822,8 @@ int DLLEXPORT EN_addlink(EN_Project p, char *id, int linkType,
|
||||
link = &net->Link[n];
|
||||
strncpy(link->ID, id, MAXID);
|
||||
|
||||
if (linkType <= EN_PIPE) net->Npipes++;
|
||||
else if (linkType == EN_PUMP)
|
||||
if (linkType <= PIPE) net->Npipes++;
|
||||
else if (linkType == PUMP)
|
||||
{
|
||||
// Grow pump array to accomodate the new link
|
||||
net->Npumps++;
|
||||
@@ -2860,13 +2859,13 @@ int DLLEXPORT EN_addlink(EN_Project p, char *id, int linkType,
|
||||
link->N2 = n2;
|
||||
link->Status = OPEN;
|
||||
|
||||
if (linkType == EN_PUMP)
|
||||
if (linkType == PUMP)
|
||||
{
|
||||
link->Kc = 1.0; // Speed factor
|
||||
link->Km = 0.0; // Horsepower
|
||||
link->Len = 0.0;
|
||||
}
|
||||
else if (linkType <= EN_PIPE) // pipe or cvpipe
|
||||
else if (linkType <= PIPE) // pipe or cvpipe
|
||||
{
|
||||
link->Diam = 10 / p->Ucf[DIAM];
|
||||
link->Kc = 100; // Rough. coeff
|
||||
@@ -2901,7 +2900,7 @@ int DLLEXPORT EN_deletelink(EN_Project p, int index, int actionCode)
|
||||
** in a control and returns an error code
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: deletes a link from a project.
|
||||
** Purpose: deletes a link from a project
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -2918,7 +2917,7 @@ int DLLEXPORT EN_deletelink(EN_Project p, int index, int actionCode)
|
||||
if (p->hydraul.OpenHflag || p->quality.OpenQflag) return 262;
|
||||
|
||||
// Check that link exists
|
||||
if (index <= 0 || index > net->Nlinks) 204;
|
||||
if (index <= 0 || index > net->Nlinks) return 204;
|
||||
if (actionCode < EN_UNCONDITIONAL || actionCode > EN_CONDITIONAL) return 251;
|
||||
|
||||
// Deletion will be cancelled if link appears in any controls
|
||||
@@ -2964,7 +2963,7 @@ int DLLEXPORT EN_deletelink(EN_Project p, int index, int actionCode)
|
||||
net->Npumps--;
|
||||
}
|
||||
|
||||
// Delete any valve (linkType > EN_PUMP) associated with the deleted link
|
||||
// Delete any valve (linkType > PUMP) associated with the deleted link
|
||||
if (linkType > PUMP)
|
||||
{
|
||||
valveindex = findvalve(net, index);
|
||||
@@ -3235,7 +3234,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
|
||||
switch (property)
|
||||
{
|
||||
case EN_DIAMETER:
|
||||
if (Link[index].Type == EN_PUMP) v = 0.0;
|
||||
if (Link[index].Type == PUMP) v = 0.0;
|
||||
else v = Link[index].Diam * Ucf[DIAM];
|
||||
break;
|
||||
|
||||
@@ -3244,7 +3243,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
|
||||
break;
|
||||
|
||||
case EN_ROUGHNESS:
|
||||
if (Link[index].Type <= EN_PIPE)
|
||||
if (Link[index].Type <= PIPE)
|
||||
{
|
||||
if (hyd->Formflag == DW) v = Link[index].Kc * (1000.0 * Ucf[ELEV]);
|
||||
else v = Link[index].Kc;
|
||||
@@ -3253,7 +3252,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
|
||||
break;
|
||||
|
||||
case EN_MINORLOSS:
|
||||
if (Link[index].Type != EN_PUMP)
|
||||
if (Link[index].Type != PUMP)
|
||||
{
|
||||
v = Link[index].Km;
|
||||
v *= (SQR(Link[index].Diam) * SQR(Link[index].Diam) / 0.02517);
|
||||
@@ -3267,19 +3266,19 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
|
||||
break;
|
||||
|
||||
case EN_INITSETTING:
|
||||
if (Link[index].Type == EN_PIPE || Link[index].Type == EN_CVPIPE)
|
||||
if (Link[index].Type == PIPE || Link[index].Type == CVPIPE)
|
||||
{
|
||||
return EN_getlinkvalue(p, index, EN_ROUGHNESS, value);
|
||||
}
|
||||
v = Link[index].Kc;
|
||||
switch (Link[index].Type)
|
||||
{
|
||||
case EN_PRV:
|
||||
case EN_PSV:
|
||||
case EN_PBV:
|
||||
case PRV:
|
||||
case PSV:
|
||||
case PBV:
|
||||
v *= Ucf[PRESSURE];
|
||||
break;
|
||||
case EN_FCV:
|
||||
case FCV:
|
||||
v *= Ucf[FLOW];
|
||||
default:
|
||||
break;
|
||||
@@ -3300,7 +3299,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
|
||||
break;
|
||||
|
||||
case EN_VELOCITY:
|
||||
if (Link[index].Type == EN_PUMP) v = 0.0;
|
||||
if (Link[index].Type == PUMP) v = 0.0;
|
||||
else if (hyd->LinkStatus[index] <= CLOSED) v = 0.0;
|
||||
else
|
||||
{
|
||||
@@ -3315,7 +3314,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
|
||||
else
|
||||
{
|
||||
h = hyd->NodeHead[Link[index].N1] - hyd->NodeHead[Link[index].N2];
|
||||
if (Link[index].Type != EN_PUMP) h = ABS(h);
|
||||
if (Link[index].Type != PUMP) h = ABS(h);
|
||||
v = h * Ucf[HEADLOSS];
|
||||
}
|
||||
break;
|
||||
@@ -3326,7 +3325,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
|
||||
break;
|
||||
|
||||
case EN_SETTING:
|
||||
if (Link[index].Type == EN_PIPE || Link[index].Type == EN_CVPIPE)
|
||||
if (Link[index].Type == PIPE || Link[index].Type == CVPIPE)
|
||||
{
|
||||
return EN_getlinkvalue(p, index, EN_ROUGHNESS, value);
|
||||
}
|
||||
@@ -3334,12 +3333,12 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
|
||||
else v = LinkSetting[index];
|
||||
switch (Link[index].Type)
|
||||
{
|
||||
case EN_PRV:
|
||||
case EN_PSV:
|
||||
case EN_PBV:
|
||||
case PRV:
|
||||
case PSV:
|
||||
case PBV:
|
||||
v *= Ucf[PRESSURE];
|
||||
break;
|
||||
case EN_FCV:
|
||||
case FCV:
|
||||
v *= Ucf[FLOW];
|
||||
default:
|
||||
break;
|
||||
@@ -3355,7 +3354,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
|
||||
break;
|
||||
|
||||
case EN_LINKPATTERN:
|
||||
if (Link[index].Type == EN_PUMP)
|
||||
if (Link[index].Type == PUMP)
|
||||
{
|
||||
v = (double)Pump[findpump(&p->network, index)].Upat;
|
||||
}
|
||||
@@ -3364,7 +3363,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
|
||||
case EN_PUMP_STATE:
|
||||
v = hyd->LinkStatus[index];
|
||||
|
||||
if (Link[index].Type == EN_PUMP)
|
||||
if (Link[index].Type == PUMP)
|
||||
{
|
||||
pmp = findpump(net, index);
|
||||
if (hyd->LinkStatus[index] >= OPEN)
|
||||
@@ -3384,7 +3383,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
|
||||
|
||||
case EN_PUMP_POWER:
|
||||
v = 0;
|
||||
if (Link[index].Type == EN_PUMP)
|
||||
if (Link[index].Type == PUMP)
|
||||
{
|
||||
pmp = findpump(net, index);
|
||||
if (Pump[pmp].Ptype == CONST_HP) v = Link[index].Km; // Power in HP or KW
|
||||
@@ -3392,28 +3391,28 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
|
||||
break;
|
||||
|
||||
case EN_PUMP_HCURVE:
|
||||
if (Link[index].Type == EN_PUMP)
|
||||
if (Link[index].Type == PUMP)
|
||||
{
|
||||
v = (double)Pump[findpump(&p->network, index)].Hcurve;
|
||||
}
|
||||
break;
|
||||
|
||||
case EN_PUMP_ECURVE:
|
||||
if (Link[index].Type == EN_PUMP)
|
||||
if (Link[index].Type == PUMP)
|
||||
{
|
||||
v = (double)Pump[findpump(&p->network, index)].Ecurve;
|
||||
}
|
||||
break;
|
||||
|
||||
case EN_PUMP_ECOST:
|
||||
if (Link[index].Type == EN_PUMP)
|
||||
if (Link[index].Type == PUMP)
|
||||
{
|
||||
v = (double)Pump[findpump(&p->network, index)].Ecost;
|
||||
}
|
||||
break;
|
||||
|
||||
case EN_PUMP_EPAT:
|
||||
if (Link[index].Type == EN_PUMP)
|
||||
if (Link[index].Type == PUMP)
|
||||
{
|
||||
v = (double)Pump[findpump(&p->network, index)].Epat;
|
||||
}
|
||||
@@ -3453,7 +3452,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
switch (property)
|
||||
{
|
||||
case EN_DIAMETER:
|
||||
if (Link[index].Type != EN_PUMP)
|
||||
if (Link[index].Type != PUMP)
|
||||
{
|
||||
if (value <= 0.0) return 211;
|
||||
value /= Ucf[DIAM]; // Convert to feet
|
||||
@@ -3465,7 +3464,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
break;
|
||||
|
||||
case EN_LENGTH:
|
||||
if (Link[index].Type <= EN_PIPE)
|
||||
if (Link[index].Type <= PIPE)
|
||||
{
|
||||
if (value <= 0.0) return 211;
|
||||
Link[index].Len = value / Ucf[ELEV];
|
||||
@@ -3474,7 +3473,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
break;
|
||||
|
||||
case EN_ROUGHNESS:
|
||||
if (Link[index].Type <= EN_PIPE)
|
||||
if (Link[index].Type <= PIPE)
|
||||
{
|
||||
if (value <= 0.0) return 211;
|
||||
Link[index].Kc = value;
|
||||
@@ -3484,7 +3483,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
break;
|
||||
|
||||
case EN_MINORLOSS:
|
||||
if (Link[index].Type != EN_PUMP)
|
||||
if (Link[index].Type != PUMP)
|
||||
{
|
||||
if (value <= 0.0) return 211;
|
||||
Link[index].Km = 0.02517 * value / SQR(Link[index].Diam) /
|
||||
@@ -3495,7 +3494,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
case EN_INITSTATUS:
|
||||
case EN_STATUS:
|
||||
// Cannot set status for a check valve
|
||||
if (Link[index].Type == EN_CVPIPE) return 207;
|
||||
if (Link[index].Type == CVPIPE) return 207;
|
||||
s = (char)ROUND(value);
|
||||
if (s < 0 || s > 1) return 211;
|
||||
if (property == EN_INITSTATUS)
|
||||
@@ -3511,7 +3510,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
case EN_INITSETTING:
|
||||
case EN_SETTING:
|
||||
if (value < 0.0) return 211;
|
||||
if (Link[index].Type == EN_PIPE || Link[index].Type == EN_CVPIPE)
|
||||
if (Link[index].Type == PIPE || Link[index].Type == CVPIPE)
|
||||
{
|
||||
return EN_setlinkvalue(p, index, EN_ROUGHNESS, value);
|
||||
}
|
||||
@@ -3519,19 +3518,19 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
{
|
||||
switch (Link[index].Type)
|
||||
{
|
||||
case EN_PUMP:
|
||||
case PUMP:
|
||||
break;
|
||||
case EN_PRV:
|
||||
case EN_PSV:
|
||||
case EN_PBV:
|
||||
case PRV:
|
||||
case PSV:
|
||||
case PBV:
|
||||
value /= Ucf[PRESSURE];
|
||||
break;
|
||||
case EN_FCV:
|
||||
case FCV:
|
||||
value /= Ucf[FLOW];
|
||||
break;
|
||||
case EN_TCV:
|
||||
case TCV:
|
||||
break;
|
||||
case EN_GPV:
|
||||
case GPV:
|
||||
return 207; // Cannot modify setting for GPV
|
||||
default:
|
||||
return 0;
|
||||
@@ -3549,7 +3548,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
break;
|
||||
|
||||
case EN_KBULK:
|
||||
if (Link[index].Type <= EN_PIPE)
|
||||
if (Link[index].Type <= PIPE)
|
||||
{
|
||||
Link[index].Kb = value / SECperDAY;
|
||||
qual->Reactflag = 1;
|
||||
@@ -3557,7 +3556,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
break;
|
||||
|
||||
case EN_KWALL:
|
||||
if (Link[index].Type <= EN_PIPE)
|
||||
if (Link[index].Type <= PIPE)
|
||||
{
|
||||
Link[index].Kw = value / SECperDAY;
|
||||
qual->Reactflag = 1;
|
||||
@@ -3565,7 +3564,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
break;
|
||||
|
||||
case EN_LINKPATTERN:
|
||||
if (Link[index].Type == EN_PUMP)
|
||||
if (Link[index].Type == PUMP)
|
||||
{
|
||||
patIndex = ROUND(value);
|
||||
if (patIndex <= 0 || patIndex > net->Npats) return 205;
|
||||
@@ -3575,7 +3574,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
break;
|
||||
|
||||
case EN_PUMP_POWER:
|
||||
if (Link[index].Type == EN_PUMP)
|
||||
if (Link[index].Type == PUMP)
|
||||
{
|
||||
if (value <= 0.0) return 211;
|
||||
pumpIndex = findpump(&p->network, index);
|
||||
@@ -3591,14 +3590,14 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
break;
|
||||
|
||||
case EN_PUMP_HCURVE:
|
||||
if (Link[index].Type == EN_PUMP)
|
||||
if (Link[index].Type == PUMP)
|
||||
{
|
||||
return EN_setheadcurveindex(p, index, ROUND(value));
|
||||
}
|
||||
break;
|
||||
|
||||
case EN_PUMP_ECURVE:
|
||||
if (Link[index].Type == EN_PUMP)
|
||||
if (Link[index].Type == PUMP)
|
||||
{
|
||||
curveIndex = ROUND(value);
|
||||
if (curveIndex <= 0 || curveIndex > net->Ncurves) return 205;
|
||||
@@ -3608,7 +3607,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
break;
|
||||
|
||||
case EN_PUMP_ECOST:
|
||||
if (Link[index].Type == EN_PUMP)
|
||||
if (Link[index].Type == PUMP)
|
||||
{
|
||||
if (value < 0.0) return 211;
|
||||
pumpIndex = findpump(&p->network, index);
|
||||
@@ -3617,7 +3616,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
||||
break;
|
||||
|
||||
case EN_PUMP_EPAT:
|
||||
if (Link[index].Type == EN_PUMP)
|
||||
if (Link[index].Type == PUMP)
|
||||
{
|
||||
patIndex = ROUND(value);
|
||||
if (patIndex <= 0 || patIndex > net->Npats) return 205;
|
||||
@@ -3642,7 +3641,7 @@ int DLLEXPORT EN_setpipedata(EN_Project p, int index, double length,
|
||||
** mloss = minor loss coefficient
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: sets several properties for a pipe link.
|
||||
** Purpose: sets several properties for a pipe link
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -3655,7 +3654,7 @@ int DLLEXPORT EN_setpipedata(EN_Project p, int index, double length,
|
||||
// Check that pipe exists
|
||||
if (!p->Openflag) return 102;
|
||||
if (index <= 0 || index > net->Nlinks) return 204;
|
||||
if (Link[index].Type > EN_PIPE) return 0;
|
||||
if (Link[index].Type > PIPE) return 0;
|
||||
|
||||
// Check for valid parameters
|
||||
if (length <= 0.0 || diam <= 0.0 || rough <= 0.0 || mloss < 0.0) return 211;
|
||||
@@ -3698,7 +3697,7 @@ int DLLEXPORT EN_getpumptype(EN_Project p, int linkIndex, int *pumpType)
|
||||
*pumpType = -1;
|
||||
if (!p->Openflag) return 102;
|
||||
if (linkIndex < 1 || linkIndex > Nlinks) return 204;
|
||||
if (EN_PUMP != Link[linkIndex].Type) return 216;
|
||||
if (PUMP != Link[linkIndex].Type) return 216;
|
||||
*pumpType = Pump[findpump(&p->network, linkIndex)].Ptype;
|
||||
return 0;
|
||||
}
|
||||
@@ -3721,7 +3720,7 @@ int DLLEXPORT EN_getheadcurveindex(EN_Project p, int linkIndex, int *curveIndex)
|
||||
*curveIndex = 0;
|
||||
if (!p->Openflag) return 102;
|
||||
if (linkIndex < 1 || linkIndex > Nlinks) return 204;
|
||||
if (EN_PUMP != Link[linkIndex].Type) return 216;
|
||||
if (PUMP != Link[linkIndex].Type) return 216;
|
||||
*curveIndex = Pump[findpump(net, linkIndex)].Hcurve;
|
||||
return 0;
|
||||
}
|
||||
@@ -3738,9 +3737,6 @@ int DLLEXPORT EN_setheadcurveindex(EN_Project p, int linkIndex, int curveIndex)
|
||||
{
|
||||
Network *net = &p->network;
|
||||
|
||||
Slink *Link = net->Link;
|
||||
const int Nlinks = net->Nlinks;
|
||||
const int Ncurves = net->Ncurves;
|
||||
double *Ucf = p->Ucf;
|
||||
int pumpIndex;
|
||||
Spump *pump;
|
||||
@@ -3748,7 +3744,7 @@ int DLLEXPORT EN_setheadcurveindex(EN_Project p, int linkIndex, int curveIndex)
|
||||
// Check for valid parameters
|
||||
if (!p->Openflag) return 102;
|
||||
if (linkIndex < 1 || linkIndex > net->Nlinks) return 204;
|
||||
if (EN_PUMP != net->Link[linkIndex].Type) return 0;
|
||||
if (PUMP != net->Link[linkIndex].Type) return 0;
|
||||
if (curveIndex <= 0 || curveIndex > net->Ncurves) return 206;
|
||||
|
||||
// Assign the new curve to the pump
|
||||
@@ -4275,7 +4271,7 @@ int DLLEXPORT EN_addcontrol(EN_Project p, int type, int linkIndex, double settin
|
||||
if (linkIndex <= 0 || linkIndex > net->Nlinks) return 204;
|
||||
|
||||
// Cannot control check valve
|
||||
if (net->Link[linkIndex].Type == EN_CVPIPE) return 207;
|
||||
if (net->Link[linkIndex].Type == CVPIPE) return 207;
|
||||
|
||||
// Check for valid parameters
|
||||
if (type < 0 || type > EN_TIMEOFDAY) return 251;
|
||||
@@ -4289,22 +4285,22 @@ int DLLEXPORT EN_addcontrol(EN_Project p, int type, int linkIndex, double settin
|
||||
// Adjust units of control parameters
|
||||
switch (net->Link[linkIndex].Type)
|
||||
{
|
||||
case EN_PRV:
|
||||
case EN_PSV:
|
||||
case EN_PBV:
|
||||
case PRV:
|
||||
case PSV:
|
||||
case PBV:
|
||||
s /= Ucf[PRESSURE];
|
||||
break;
|
||||
case EN_FCV:
|
||||
case FCV:
|
||||
s /= Ucf[FLOW];
|
||||
break;
|
||||
case EN_GPV:
|
||||
case GPV:
|
||||
if (s == 0.0) status = CLOSED;
|
||||
else if (s == 1.0) status = OPEN;
|
||||
else return 202;
|
||||
s = net->Link[linkIndex].Kc;
|
||||
break;
|
||||
case EN_PIPE:
|
||||
case EN_PUMP:
|
||||
case PIPE:
|
||||
case PUMP:
|
||||
status = OPEN;
|
||||
if (s == 0.0) status = CLOSED;
|
||||
default:
|
||||
@@ -4407,12 +4403,12 @@ int DLLEXPORT EN_getcontrol(EN_Project p, int index, int *type, int *linkIndex,
|
||||
{
|
||||
switch (net->Link[*linkIndex].Type)
|
||||
{
|
||||
case EN_PRV:
|
||||
case EN_PSV:
|
||||
case EN_PBV:
|
||||
case PRV:
|
||||
case PSV:
|
||||
case PBV:
|
||||
s *= Ucf[PRESSURE];
|
||||
break;
|
||||
case EN_FCV:
|
||||
case FCV:
|
||||
s *= Ucf[FLOW];
|
||||
default:
|
||||
break;
|
||||
@@ -4487,7 +4483,7 @@ int DLLEXPORT EN_setcontrol(EN_Project p, int index, int type, int linkIndex,
|
||||
if (linkIndex < 0 || linkIndex > net->Nlinks) return 204;
|
||||
|
||||
// Cannot control check valve
|
||||
if (net->Link[linkIndex].Type == EN_CVPIPE) return 207;
|
||||
if (net->Link[linkIndex].Type == CVPIPE) return 207;
|
||||
|
||||
// Check for valid control properties
|
||||
if (type < 0 || type > EN_TIMEOFDAY) return 251;
|
||||
@@ -4502,22 +4498,22 @@ int DLLEXPORT EN_setcontrol(EN_Project p, int index, int type, int linkIndex,
|
||||
link = &net->Link[linkIndex];
|
||||
switch (link->Type)
|
||||
{
|
||||
case EN_PRV:
|
||||
case EN_PSV:
|
||||
case EN_PBV:
|
||||
case PRV:
|
||||
case PSV:
|
||||
case PBV:
|
||||
s /= Ucf[PRESSURE];
|
||||
break;
|
||||
case EN_FCV:
|
||||
case FCV:
|
||||
s /= Ucf[FLOW];
|
||||
break;
|
||||
case EN_GPV:
|
||||
case GPV:
|
||||
if (s == 0.0) status = CLOSED;
|
||||
else if (s == 1.0) status = OPEN;
|
||||
else return 202;
|
||||
s = link->Kc;
|
||||
break;
|
||||
case EN_PIPE:
|
||||
case EN_PUMP:
|
||||
case PIPE:
|
||||
case PUMP:
|
||||
status = OPEN;
|
||||
if (s == 0.0) status = CLOSED;
|
||||
default:
|
||||
@@ -4609,7 +4605,7 @@ int DLLEXPORT EN_deleterule(EN_Project p, int index)
|
||||
** Input: index = rule index
|
||||
** Output: none
|
||||
** Returns: error code
|
||||
** Purpose: deletes a rule from a project.
|
||||
** Purpose: deletes a rule from a project
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -4810,7 +4806,7 @@ int DLLEXPORT EN_setpremisestatus(EN_Project p, int ruleIndex, int premiseIndex,
|
||||
if (ruleIndex < 1 || ruleIndex > p->network.Nrules) return 257;
|
||||
|
||||
premises = p->network.Rule[ruleIndex].Premises;
|
||||
premise = getpremise(premises, ruleIndex);
|
||||
premise = getpremise(premises, premiseIndex);
|
||||
if (premise == NULL) return 258;
|
||||
|
||||
premise->status = status;
|
||||
|
||||
@@ -100,6 +100,8 @@ int hydsolve(Project *pr, int *iter, double *relerr)
|
||||
// Initialize status checking & relaxation factor
|
||||
nextcheck = hyd->CheckFreq;
|
||||
hyd->RelaxFactor = 1.0;
|
||||
hydbal.maxheaderror = 0.0;
|
||||
hydbal.maxflowchange = 0.0;
|
||||
|
||||
// Repeat iterations until convergence or trial limit is exceeded.
|
||||
// (ExtraIter used to increase trials in case of status cycling.)
|
||||
@@ -121,7 +123,7 @@ int hydsolve(Project *pr, int *iter, double *relerr)
|
||||
// Matrix ill-conditioning problem - if control valve causing problem,
|
||||
// fix its status & continue, otherwise quit with no solution.
|
||||
if (errcode > 0)
|
||||
{
|
||||
{
|
||||
if (badvalve(pr, sm->Order[errcode])) continue;
|
||||
else break;
|
||||
}
|
||||
@@ -360,7 +362,6 @@ double newflows(Project *pr, Hydbalance *hbal)
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Hydraul *hyd = &pr->hydraul;
|
||||
|
||||
double dqsum, // Network flow change
|
||||
|
||||
@@ -102,7 +102,6 @@ int saveinpfile(Project *pr, const char *fname)
|
||||
Times *time = &pr->times;
|
||||
|
||||
int i, j, n;
|
||||
int errcode;
|
||||
double d, kc, ke, km, ucf;
|
||||
char s[MAXLINE + 1], s1[MAXLINE + 1], s2[MAXLINE + 1];
|
||||
Pdemand demand;
|
||||
@@ -451,7 +450,7 @@ int saveinpfile(Project *pr, const char *fname)
|
||||
for (i = 1; i <= net->Nrules; i++)
|
||||
{
|
||||
fprintf(f, "\nRULE %s", pr->network.Rule[i].label);
|
||||
errcode = writerule(pr, f, i); // see RULES.C
|
||||
writerule(pr, f, i); // see RULES.C
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
|
||||
@@ -489,7 +488,7 @@ int saveinpfile(Project *pr, const char *fname)
|
||||
fprintf(f, s_MIXING);
|
||||
for (i = 1; i <= net->Ntanks; i++)
|
||||
{
|
||||
Stank *tank = &net->Tank[i];
|
||||
tank = &net->Tank[i];
|
||||
if (tank->A == 0.0) continue;
|
||||
fprintf(f, "\n %-31s %-8s %12.4f", net->Node[tank->Node].ID,
|
||||
MixTxt[tank->MixModel], (tank->V1max / tank->Vmax));
|
||||
@@ -719,7 +718,7 @@ int saveinpfile(Project *pr, const char *fname)
|
||||
j = 0;
|
||||
for (i = 1; i <= net->Nlinks; i++)
|
||||
{
|
||||
Slink *link = &net->Link[i];
|
||||
link = &net->Link[i];
|
||||
if (link->Rpt == 1)
|
||||
{
|
||||
if (j % 5 == 0) fprintf(f, "\n LINKS ");
|
||||
|
||||
130
src/input3.c
130
src/input3.c
@@ -45,7 +45,7 @@ static int getpumpcurve(Project *, int);
|
||||
static void changestatus(Network *, int, StatusType, double);
|
||||
static int setError(Parser *, int, int);
|
||||
|
||||
|
||||
|
||||
int setError(Parser *parser, int tokindex, int errcode)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
@@ -85,7 +85,7 @@ int juncdata(Project *pr)
|
||||
Pdemand demand; // demand record
|
||||
STmplist *patlist; // list of demands
|
||||
Snode *node;
|
||||
|
||||
|
||||
// Add new junction to data base
|
||||
n = parser->Ntokens;
|
||||
if (net->Nnodes == parser->MaxNodes) return 200;
|
||||
@@ -117,7 +117,7 @@ int juncdata(Project *pr)
|
||||
node->Type = JUNCTION;
|
||||
strcpy(node->Comment, parser->Comment);
|
||||
|
||||
|
||||
|
||||
// create a demand record, even if no demand is specified here.
|
||||
demand = (struct Sdemand *) malloc(sizeof(struct Sdemand));
|
||||
if (demand == NULL) return 101;
|
||||
@@ -162,7 +162,7 @@ int tankdata(Project *pr)
|
||||
STmplist *tmplist;
|
||||
Snode *node;
|
||||
Stank *tank;
|
||||
|
||||
|
||||
// Add new tank to data base
|
||||
n = parser->Ntokens;
|
||||
if (net->Ntanks == parser->MaxTanks ||
|
||||
@@ -189,7 +189,7 @@ int tankdata(Project *pr)
|
||||
}
|
||||
}
|
||||
else if (n < 6) return 201;
|
||||
|
||||
|
||||
// Tank is a storage tank
|
||||
else
|
||||
{
|
||||
@@ -232,7 +232,7 @@ int tankdata(Project *pr)
|
||||
tank->A = diam;
|
||||
tank->Pat = pattern;
|
||||
tank->Kb = MISSING;
|
||||
|
||||
|
||||
//*******************************************************************
|
||||
// NOTE: The min, max, & initial volumes set here are based on a
|
||||
// nominal tank diameter. They will be modified in INPUT1.C if
|
||||
@@ -275,7 +275,7 @@ int pipedata(Project *pr)
|
||||
LinkType type = PIPE; // Link type
|
||||
StatusType status = OPEN; // Link status
|
||||
Slink *link;
|
||||
|
||||
|
||||
// Add new pipe to data base
|
||||
n = parser->Ntokens;
|
||||
if (net->Nlinks == parser->MaxLinks) return 200;
|
||||
@@ -354,10 +354,10 @@ int pumpdata(Project *pr)
|
||||
Network *net = &pr->network;
|
||||
Parser *parser = &pr->parser;
|
||||
|
||||
int j,
|
||||
int j,
|
||||
j1, // Start-node index
|
||||
j2, // End-node index
|
||||
m, n; // # data items
|
||||
m, n; // # data items
|
||||
double y;
|
||||
STmplist *tmplist; // Temporary list
|
||||
Slink *link;
|
||||
@@ -380,7 +380,7 @@ int pumpdata(Project *pr)
|
||||
// Save pump data
|
||||
link = &net->Link[net->Nlinks];
|
||||
pump = &net->Pump[net->Npumps];
|
||||
|
||||
|
||||
link->N1 = j1;
|
||||
link->N2 = j2;
|
||||
link->Diam = 0;
|
||||
@@ -426,25 +426,25 @@ int pumpdata(Project *pr)
|
||||
if (y <= 0.0) return setError(parser, m, 202);
|
||||
pump->Ptype = CONST_HP;
|
||||
link->Km = y;
|
||||
}
|
||||
}
|
||||
else if (match(parser->Tok[m - 1], w_HEAD)) // Custom pump curve
|
||||
{
|
||||
tmplist = getlistitem(parser->Tok[m], parser->Curvelist);
|
||||
if (tmplist == NULL) return setError(parser, m, 206);
|
||||
pump->Hcurve = tmplist->i;
|
||||
}
|
||||
}
|
||||
else if (match(parser->Tok[m - 1], w_PATTERN)) // Speed/status pattern
|
||||
{
|
||||
tmplist = getlistitem(parser->Tok[m], parser->Patlist);
|
||||
if (tmplist == NULL) return setError(parser, m, 205);
|
||||
pump->Upat = tmplist->i;
|
||||
}
|
||||
}
|
||||
else if (match(parser->Tok[m - 1], w_SPEED)) // Speed setting
|
||||
{
|
||||
if (!getfloat(parser->Tok[m], &y)) return setError(parser, m, 202);
|
||||
if (y < 0.0) return setError(parser, m, 211);
|
||||
link->Kc = y;
|
||||
}
|
||||
}
|
||||
else return 201;
|
||||
m = m + 2; // Move to next keyword token
|
||||
}
|
||||
@@ -476,7 +476,7 @@ int valvedata(Project *pr)
|
||||
lcoeff = 0.0; // Minor loss coeff.
|
||||
STmplist *tmplist; // Temporary list
|
||||
Slink *link;
|
||||
|
||||
|
||||
// Add new valve to data base
|
||||
n = parser->Ntokens;
|
||||
if (net->Nlinks == parser->MaxLinks ||
|
||||
@@ -499,12 +499,12 @@ int valvedata(Project *pr)
|
||||
else if (match(parser->Tok[4], w_GPV)) type = GPV;
|
||||
else return setError(parser, 4, 213);
|
||||
|
||||
if (!getfloat(parser->Tok[3], &diam)) return setError(parser, 3, 202); 202;
|
||||
if (!getfloat(parser->Tok[3], &diam)) return setError(parser, 3, 202);
|
||||
if (diam <= 0.0) return setError(parser, 3, 211);
|
||||
|
||||
// Find headloss curve for GPV
|
||||
// Find headloss curve for GPV
|
||||
if (type == GPV)
|
||||
{
|
||||
{
|
||||
tmplist = getlistitem(parser->Tok[5], parser->Curvelist);
|
||||
if (tmplist == NULL) return setError(parser, 5, 206);
|
||||
setting = tmplist->i;
|
||||
@@ -532,7 +532,7 @@ int valvedata(Project *pr)
|
||||
link->Km = lcoeff;
|
||||
link->Kb = 0.0;
|
||||
link->Kw = 0.0;
|
||||
link->Type = type;
|
||||
link->Type = type;
|
||||
link->Status = status;
|
||||
link->Rpt = 0;
|
||||
strcpy(link->Comment, parser->Comment);
|
||||
@@ -658,11 +658,11 @@ int coordata(Project *pr)
|
||||
int j;
|
||||
double x, y;
|
||||
Snode *node;
|
||||
|
||||
|
||||
// Check for valid node ID
|
||||
if (parser->Ntokens < 3) return 201;
|
||||
if ((j = findnode(net, parser->Tok[0])) == 0) return setError(parser, 0, 203);
|
||||
|
||||
|
||||
// Check for valid data
|
||||
if (!getfloat(parser->Tok[1], &x)) return setError(parser, 1, 202);
|
||||
if (!getfloat(parser->Tok[2], &y)) return setError(parser, 2, 202);
|
||||
@@ -768,7 +768,7 @@ int controldata(Project *pr)
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Parser *parser = &pr->parser;
|
||||
|
||||
|
||||
int i = 0, // Node index
|
||||
k, // Link index
|
||||
n; // # data items
|
||||
@@ -779,7 +779,7 @@ int controldata(Project *pr)
|
||||
ControlType ctltype; // Control type
|
||||
LinkType linktype; // Link type
|
||||
Scontrol *control;
|
||||
|
||||
|
||||
// Check for sufficient number of input tokens
|
||||
n = parser->Ntokens;
|
||||
if (n < 6) return 201;
|
||||
@@ -878,7 +878,7 @@ int sourcedata(Project *pr)
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Parser *parser = &pr->parser;
|
||||
|
||||
|
||||
int i, // Token with quality value
|
||||
j, // Node index
|
||||
n, // # data items
|
||||
@@ -912,7 +912,7 @@ int sourcedata(Project *pr)
|
||||
|
||||
// Parse optional source time pattern
|
||||
if (n > i + 1 && strlen(parser->Tok[i + 1]) > 0 &&
|
||||
strcmp(parser->Tok[i + 1], "*") != 0)
|
||||
strcmp(parser->Tok[i + 1], "*") != 0)
|
||||
{
|
||||
patlist = getlistitem(parser->Tok[i + 1], parser->Patlist);
|
||||
if (patlist == NULL) return setError(parser, i+1, 205);
|
||||
@@ -921,7 +921,7 @@ int sourcedata(Project *pr)
|
||||
|
||||
// Destroy any existing source assigned to node
|
||||
if (net->Node[j].S != NULL) free(net->Node[j].S);
|
||||
|
||||
|
||||
// Create a new source & assign it to the node
|
||||
source = (struct Ssource *)malloc(sizeof(struct Ssource));
|
||||
if (source == NULL) return 101;
|
||||
@@ -946,7 +946,7 @@ int emitterdata(Project *pr)
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Parser *parser = &pr->parser;
|
||||
|
||||
|
||||
int j, // Node index
|
||||
n; // # data items
|
||||
double k; // Flow coeff.
|
||||
@@ -984,7 +984,7 @@ int qualdata(Project *pr)
|
||||
long i, i1, i2;
|
||||
double c0;
|
||||
Snode *Node = net->Node;
|
||||
|
||||
|
||||
if (net->Nnodes == 0) return setError(parser, 0, 203); // No nodes defined yet
|
||||
n = parser->Ntokens;
|
||||
if (n < 2) return 0;
|
||||
@@ -1016,7 +1016,7 @@ int qualdata(Project *pr)
|
||||
if (i >= i1 && i <= i2) Node[j].C0 = c0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Otherwise use lexicographic comparison
|
||||
else
|
||||
{
|
||||
@@ -1058,7 +1058,7 @@ int reactdata(Project *pr)
|
||||
long i, i1, i2;
|
||||
double y;
|
||||
|
||||
// Skip line if insufficient data
|
||||
// Skip line if insufficient data
|
||||
n = parser->Ntokens;
|
||||
if (n < 3) return 0;
|
||||
|
||||
@@ -1093,7 +1093,7 @@ int reactdata(Project *pr)
|
||||
qual->Climit = y;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Keyword is GLOBAL
|
||||
if (match(parser->Tok[0], w_GLOBAL))
|
||||
{
|
||||
@@ -1125,7 +1125,7 @@ int reactdata(Project *pr)
|
||||
if ((j = findnode(net,parser->Tok[1])) <= net->Njuncs) return 0;
|
||||
net->Tank[j - net->Njuncs].Kb = y;
|
||||
}
|
||||
|
||||
|
||||
// Case where a numerical range of tank IDs is specified
|
||||
else if ((i1 = atol(parser->Tok[1])) > 0 &&
|
||||
(i2 = atol(parser->Tok[2])) > 0)
|
||||
@@ -1160,7 +1160,7 @@ int reactdata(Project *pr)
|
||||
if (item == 1) net->Link[j].Kb = y;
|
||||
else net->Link[j].Kw = y;
|
||||
}
|
||||
|
||||
|
||||
// Case where a numerical range of link IDs is specified
|
||||
else if ((i1 = atol(parser->Tok[1])) > 0 &&
|
||||
(i2 = atol(parser->Tok[2])) > 0)
|
||||
@@ -1168,14 +1168,14 @@ int reactdata(Project *pr)
|
||||
for (j = 1; j <= net->Nlinks; j++)
|
||||
{
|
||||
i = atol(net->Link[j].ID);
|
||||
if (i >= i1 && i <= i2)
|
||||
if (i >= i1 && i <= i2)
|
||||
{
|
||||
if (item == 1) net->Link[j].Kb = y;
|
||||
else net->Link[j].Kw = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Case where a general range of link IDs is specified
|
||||
else for (j = 1; j <= net->Nlinks; j++)
|
||||
{
|
||||
@@ -1210,7 +1210,7 @@ int mixingdata(Project *pr)
|
||||
m, // Type of mixing model
|
||||
n; // Number of data items
|
||||
double v; // Mixing zone volume fraction
|
||||
|
||||
|
||||
// Check for valid data
|
||||
if (net->Nnodes == 0) return setError(parser, 0, 203);
|
||||
n = parser->Ntokens;
|
||||
@@ -1254,7 +1254,7 @@ int statusdata(Project *pr)
|
||||
long i, i1, i2;
|
||||
double y = 0.0;
|
||||
char status = ACTIVE;
|
||||
|
||||
|
||||
if (net->Nlinks == 0) return setError(parser, 0, 204);
|
||||
n = parser->Ntokens - 1;
|
||||
if (n < 1) return 201;
|
||||
@@ -1272,7 +1272,7 @@ int statusdata(Project *pr)
|
||||
if (n == 1)
|
||||
{
|
||||
if ((j = findlink(net, parser->Tok[0])) == 0) return setError(parser, 0, 204);
|
||||
|
||||
|
||||
// Cannot change status of a Check Valve
|
||||
if (net->Link[j].Type == CVPIPE) return setError(parser, 0, 207);
|
||||
|
||||
@@ -1291,7 +1291,7 @@ int statusdata(Project *pr)
|
||||
if (i >= i1 && i <= i2) changestatus(net, j, status, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// A range of general link ID's was supplied
|
||||
else for (j = 1; j <= net->Nlinks; j++)
|
||||
{
|
||||
@@ -1319,14 +1319,14 @@ int energydata(Project *pr)
|
||||
Network *net = &pr->network;
|
||||
Hydraul *hyd = &pr->hydraul;
|
||||
Parser *parser = &pr->parser;
|
||||
|
||||
|
||||
int j, k, n;
|
||||
double y;
|
||||
|
||||
STmplist *listitem;
|
||||
Slink *Link = net->Link;
|
||||
Spump *Pump = net->Pump;
|
||||
|
||||
|
||||
// Check for sufficient data
|
||||
n = parser->Ntokens;
|
||||
if (n < 3) return 201;
|
||||
@@ -1345,7 +1345,7 @@ int energydata(Project *pr)
|
||||
{
|
||||
j = 0;
|
||||
}
|
||||
|
||||
|
||||
// First keyword is PUMP (remaining data refer to a specific pump)
|
||||
else if (match(parser->Tok[0], w_PUMP))
|
||||
{
|
||||
@@ -1366,7 +1366,7 @@ int energydata(Project *pr)
|
||||
else Pump[j].Ecost = y;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Price PATTERN being set
|
||||
else if (match(parser->Tok[n - 2], w_PATTERN))
|
||||
{
|
||||
@@ -1376,7 +1376,7 @@ int energydata(Project *pr)
|
||||
else Pump[j].Epat = listitem->i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Pump EFFIC being set
|
||||
else if (match(parser->Tok[n - 2], w_EFFIC))
|
||||
{
|
||||
@@ -1389,7 +1389,7 @@ int energydata(Project *pr)
|
||||
else
|
||||
{
|
||||
listitem = getlistitem(parser->Tok[n - 1], parser->Curvelist);
|
||||
if (listitem == NULL) return setError(parser, n - 1, 206);
|
||||
if (listitem == NULL) return setError(parser, n - 1, 206);
|
||||
Pump[j].Ecurve = listitem->i;
|
||||
net->Curve[listitem->i].Type = EFFIC_CURVE;
|
||||
}
|
||||
@@ -1423,10 +1423,10 @@ int reportdata(Project *pr)
|
||||
Network *net = &pr->network;
|
||||
Report *rpt = &pr->report;
|
||||
Parser *parser = &pr->parser;
|
||||
|
||||
|
||||
int i, j, n;
|
||||
double y;
|
||||
|
||||
|
||||
n = parser->Ntokens - 1;
|
||||
if (n < 1) return 201;
|
||||
|
||||
@@ -1511,8 +1511,8 @@ int reportdata(Project *pr)
|
||||
// Report fields specified
|
||||
// Special case needed to distinguish "HEAD" from "HEADLOSS"
|
||||
if (strcomp(parser->Tok[0], t_HEADLOSS)) i = HEADLOSS;
|
||||
else i = findmatch(parser->Tok[0], Fldname);
|
||||
if (i >= 0)
|
||||
else i = findmatch(parser->Tok[0], Fldname);
|
||||
if (i >= 0)
|
||||
{
|
||||
if (i > FRICTION) return setError(parser, 0, 213);
|
||||
if (parser->Ntokens == 1 || match(parser->Tok[1], w_YES))
|
||||
@@ -1552,7 +1552,7 @@ int reportdata(Project *pr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If get to here then return error condition
|
||||
// If get to here then return error condition
|
||||
return 201;
|
||||
}
|
||||
|
||||
@@ -1690,10 +1690,10 @@ int optionchoice(Project *pr, int n)
|
||||
Quality *qual = &pr->quality;
|
||||
Parser *parser = &pr->parser;
|
||||
Outfile *out = &pr->outfile;
|
||||
|
||||
|
||||
int choice;
|
||||
|
||||
// Check if 1st token matches a parameter name and
|
||||
// Check if 1st token matches a parameter name and
|
||||
// process the input for the matched parameter
|
||||
if (n < 0) return 201;
|
||||
|
||||
@@ -1725,7 +1725,7 @@ int optionchoice(Project *pr, int n)
|
||||
else if (match(parser->Tok[1], w_METERS)) parser->Pressflag = METERS;
|
||||
else return setError(parser, 1, 213);
|
||||
}
|
||||
|
||||
|
||||
// HEADLOSS formula
|
||||
else if (match(parser->Tok[0], w_HEADLOSS))
|
||||
{
|
||||
@@ -1735,7 +1735,7 @@ int optionchoice(Project *pr, int n)
|
||||
else if (match(parser->Tok[1], w_CM)) hyd->Formflag = CM;
|
||||
else return setError(parser, 1, 213);
|
||||
}
|
||||
|
||||
|
||||
// HYDRUALICS USE/SAVE file option
|
||||
else if (match(parser->Tok[0], w_HYDRAULIC))
|
||||
{
|
||||
@@ -1777,19 +1777,19 @@ int optionchoice(Project *pr, int n)
|
||||
strncpy(qual->ChemUnits, u_HOURS, MAXID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MAP file name
|
||||
else if (match(parser->Tok[0], w_MAP))
|
||||
{
|
||||
if (n < 1) return 0;
|
||||
strncpy(pr->MapFname, parser->Tok[1], MAXFNAME);
|
||||
}
|
||||
|
||||
|
||||
else if (match(parser->Tok[0], w_VERIFY))
|
||||
{
|
||||
// Deprecated
|
||||
}
|
||||
|
||||
|
||||
// Hydraulics UNBALANCED option
|
||||
else if (match(parser->Tok[0], w_UNBALANCED))
|
||||
{
|
||||
@@ -1802,7 +1802,7 @@ int optionchoice(Project *pr, int n)
|
||||
}
|
||||
else return setError(parser, 1, 213);
|
||||
}
|
||||
|
||||
|
||||
// Default demand PATTERN
|
||||
else if (match(parser->Tok[0], w_PATTERN))
|
||||
{
|
||||
@@ -1854,7 +1854,7 @@ int optionvalue(Project *pr, int n)
|
||||
** RQTOL value
|
||||
** CHECKFREQ value
|
||||
** MAXCHECK value
|
||||
** DAMPLIMIT value
|
||||
** DAMPLIMIT value
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -1890,19 +1890,19 @@ int optionvalue(Project *pr, int n)
|
||||
|
||||
// Diffusivity
|
||||
if (match(tok0, w_DIFFUSIVITY))
|
||||
{
|
||||
{
|
||||
if (y < 0.0) return setError(parser, nvalue, 213);
|
||||
qual->Diffus = y;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Hydraulic damping limit option */
|
||||
// Hydraulic damping limit option */
|
||||
if (match(tok0, w_DAMPLIMIT))
|
||||
{
|
||||
hyd->DampLimit = y;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Flow change limit
|
||||
else if (match(tok0, w_FLOWCHANGE))
|
||||
{
|
||||
@@ -1989,7 +1989,7 @@ int getpumpcurve(Project *pr, int n)
|
||||
|
||||
double a, b, c, h0, h1, h2, q1, q2;
|
||||
Spump *pump = &net->Pump[net->Npumps];
|
||||
|
||||
|
||||
// Constant HP curve
|
||||
if (n == 1)
|
||||
{
|
||||
@@ -1997,7 +1997,7 @@ int getpumpcurve(Project *pr, int n)
|
||||
pump->Ptype = CONST_HP;
|
||||
net->Link[net->Nlinks].Km = parser->X[0];
|
||||
}
|
||||
|
||||
|
||||
// Power function curve
|
||||
else
|
||||
{
|
||||
@@ -2080,7 +2080,7 @@ void changestatus(Network *net, int j, StatusType status, double y)
|
||||
*/
|
||||
{
|
||||
Slink *link = &net->Link[j];
|
||||
|
||||
|
||||
if (link->Type == PIPE || link->Type == GPV)
|
||||
{
|
||||
if (status != ACTIVE) link->Status = status;
|
||||
|
||||
@@ -151,7 +151,7 @@ int openhydfile(Project *pr)
|
||||
if (version != ENGINE_VERSION) return 306;
|
||||
if (fread(nsize, sizeof(INT4), 6, pr->outfile.HydFile) < 6) return 306;
|
||||
if (nsize[0] != Nnodes || nsize[1] != Nlinks || nsize[2] != Ntanks ||
|
||||
nsize[3] != Npumps || nsize[4] != Nvalves ||
|
||||
nsize[3] != Npumps || nsize[4] != Nvalves ||
|
||||
nsize[5] != pr->times.Dur
|
||||
) return 306;
|
||||
pr->outfile.SaveHflag = TRUE;
|
||||
@@ -187,7 +187,7 @@ int openoutfile(Project *pr)
|
||||
}
|
||||
|
||||
// If output file name was supplied, then attempt to
|
||||
// open it. Otherwise open a temporary output file.
|
||||
// open it. Otherwise open a temporary output file.
|
||||
if (pr->outfile.Outflag == SAVE)
|
||||
{
|
||||
pr->outfile.OutFile = fopen(pr->outfile.OutFname, "w+b");
|
||||
@@ -305,7 +305,7 @@ int allocdata(Project *pr)
|
||||
ERRCODE(MEMCHECK(pr->quality.NodeQual));
|
||||
}
|
||||
|
||||
// Allocate memory for network links
|
||||
// Allocate memory for network links
|
||||
if (!errcode)
|
||||
{
|
||||
n = pr->parser.MaxLinks + 1;
|
||||
@@ -442,7 +442,7 @@ void freedata(Project *pr)
|
||||
free(demand);
|
||||
demand = nextdemand;
|
||||
}
|
||||
// Free memory used for WQ source data
|
||||
// Free memory used for WQ source data
|
||||
source = pr->network.Node[j].S;
|
||||
if (source != NULL) free(source);
|
||||
}
|
||||
@@ -579,7 +579,6 @@ int incontrols(Project *pr, int objType, int index)
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Rules *rules = &pr->rules;
|
||||
|
||||
int i, ruleObject;
|
||||
Spremise *premise;
|
||||
@@ -652,7 +651,7 @@ int valvecheck(Project *pr, int type, int j1, int j2)
|
||||
{
|
||||
// Can't be connected to a fixed grade node
|
||||
if (j1 > net->Njuncs || j2 > net->Njuncs) return 219;
|
||||
|
||||
|
||||
// Examine each existing valve
|
||||
for (k = 1; k <= net->Nvalves; k++)
|
||||
{
|
||||
@@ -832,7 +831,7 @@ double interp(int n, double x[], double y[], double xx)
|
||||
double dx, dy;
|
||||
|
||||
m = n - 1; // Highest data index
|
||||
if (xx <= x[0]) return (y[0]); // xx off low end of curve
|
||||
if (xx <= x[0]) return (y[0]); // xx off low end of curve
|
||||
for (k = 1; k <= m; k++) // Bracket xx on curve
|
||||
{
|
||||
if (x[k] >= xx) // Interp. over interval
|
||||
|
||||
@@ -35,7 +35,7 @@ const double Q_STAGNANT = 0.005 / GPMperCFS; // 0.005 gpm = 1.114e-5 cfs
|
||||
//int stepqual(Project *, long *);
|
||||
//int closequal(Project *);
|
||||
//double avgqual(Project *, int);
|
||||
double findsourcequal(Project *, int, double, double, long);
|
||||
double findsourcequal(Project *, int, double, long);
|
||||
|
||||
// Imported functions
|
||||
extern char setreactflag(Project *);
|
||||
@@ -78,21 +78,21 @@ int openqual(Project *pr)
|
||||
// Create a memory pool for water quality segments
|
||||
qual->OutOfMemory = FALSE;
|
||||
qual->SegPool = mempool_create();
|
||||
if (qual->SegPool == NULL) errcode = 101;
|
||||
if (qual->SegPool == NULL) errcode = 101;
|
||||
|
||||
// Allocate arrays for link flow direction & reaction rates
|
||||
n = net->Nlinks + 1;
|
||||
qual->FlowDir = (FlowDirection *)calloc(n, sizeof(FlowDirection));
|
||||
qual->PipeRateCoeff = (double *)calloc(n, sizeof(double));
|
||||
|
||||
// Allocate arrays used for volume segments in links & tanks
|
||||
// Allocate arrays used for volume segments in links & tanks
|
||||
n = net->Nlinks + net->Ntanks + 1;
|
||||
qual->FirstSeg = (Pseg *)calloc(n, sizeof(Pseg));
|
||||
qual->LastSeg = (Pseg *)calloc(n, sizeof(Pseg));
|
||||
|
||||
// Allocate memory for topologically sorted nodes
|
||||
// Allocate memory for topologically sorted nodes
|
||||
qual->SortedNodes = (int *)calloc(n, sizeof(int));
|
||||
|
||||
|
||||
ERRCODE(MEMCHECK(qual->FlowDir));
|
||||
ERRCODE(MEMCHECK(qual->PipeRateCoeff));
|
||||
ERRCODE(MEMCHECK(qual->FirstSeg));
|
||||
@@ -119,7 +119,7 @@ int initqual(Project *pr)
|
||||
int i;
|
||||
int errcode = 0;
|
||||
|
||||
// Re-position hydraulics file
|
||||
// Re-position hydraulics file
|
||||
if (!hyd->OpenHflag)
|
||||
{
|
||||
fseek(pr->outfile.HydFile, pr->outfile.HydOffset, SEEK_SET);
|
||||
@@ -148,7 +148,7 @@ int initqual(Project *pr)
|
||||
|
||||
// Initialize quality at trace node (if applicable)
|
||||
if (qual->Qualflag == TRACE) qual->NodeQual[qual->TraceNode] = 100.0;
|
||||
|
||||
|
||||
// Compute Schmidt number
|
||||
if (qual->Diffus > 0.0) qual->Sc = hyd->Viscos / qual->Diffus;
|
||||
else qual->Sc = 0.0;
|
||||
@@ -202,17 +202,17 @@ int runqual(Project *pr, long *t)
|
||||
Quality *qual = &pr->quality;
|
||||
Times *time = &pr->times;
|
||||
|
||||
long hydtime; // Hydraulic solution time
|
||||
long hydstep; // Hydraulic time step
|
||||
long hydtime = 0; // Hydraulic solution time
|
||||
long hydstep = 0; // Hydraulic time step
|
||||
int errcode = 0;
|
||||
|
||||
// Update reported simulation time
|
||||
*t = time->Qtime;
|
||||
|
||||
// Read hydraulic solution from hydraulics file
|
||||
// Read hydraulic solution from hydraulics file
|
||||
if (time->Qtime == time->Htime)
|
||||
{
|
||||
// Read hydraulic results from file
|
||||
// Read hydraulic results from file
|
||||
if (!hyd->OpenHflag)
|
||||
{
|
||||
if (!readhyd(pr, &hydtime)) return 307;
|
||||
@@ -220,7 +220,7 @@ int runqual(Project *pr, long *t)
|
||||
time->Htime = hydtime;
|
||||
}
|
||||
|
||||
// Save current results to output file
|
||||
// Save current results to output file
|
||||
if (time->Htime >= time->Rtime)
|
||||
{
|
||||
if (pr->outfile.Saveflag)
|
||||
@@ -263,7 +263,7 @@ int nextqual(Project *pr, long *tstep)
|
||||
{
|
||||
Quality *qual = &pr->quality;
|
||||
Times *time = &pr->times;
|
||||
|
||||
|
||||
long hydstep; // Time step until next hydraulic event
|
||||
long dt, qtime;
|
||||
int errcode = 0;
|
||||
@@ -316,7 +316,7 @@ int stepqual(Project *pr, long *tleft)
|
||||
** Input: none
|
||||
** Output: tleft = time left in simulation
|
||||
** Returns: error code
|
||||
** Purpose: updates quality conditions over a single
|
||||
** Purpose: updates quality conditions over a single
|
||||
** quality time step
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
@@ -402,7 +402,7 @@ int closequal(Project *pr)
|
||||
int errcode = 0;
|
||||
|
||||
if (qual->SegPool) mempool_delete(qual->SegPool);
|
||||
FREE(qual->FirstSeg);
|
||||
FREE(qual->FirstSeg);
|
||||
FREE(qual->LastSeg);
|
||||
FREE(qual->PipeRateCoeff);
|
||||
FREE(qual->FlowDir);
|
||||
@@ -452,11 +452,10 @@ double avgqual(Project *pr, int k)
|
||||
}
|
||||
|
||||
|
||||
double findsourcequal(Project *pr, int n, double volin, double volout, long tstep)
|
||||
double findsourcequal(Project *pr, int n, double volout, long tstep)
|
||||
/*
|
||||
**---------------------------------------------------------------------
|
||||
** Input: n = node index
|
||||
** volin = volume of node inflow over time step
|
||||
** volout = volume of node outflow over time step
|
||||
** tstep = current quality time step
|
||||
** Output: returns concentration added by an external quality source.
|
||||
@@ -543,7 +542,6 @@ double sourcequal(Project *pr, Psource source)
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Quality *qual = &pr->quality;
|
||||
Times *time = &pr->times;
|
||||
|
||||
int i;
|
||||
|
||||
@@ -222,7 +222,7 @@ double piperate(Project *pr, int k)
|
||||
|
||||
d = net->Link[k].Diam; // Pipe diameter, ft
|
||||
|
||||
// Ignore mass transfer if Schmidt No. is 0
|
||||
// Ignore mass transfer if Schmidt No. is 0
|
||||
if (qual->Sc == 0.0)
|
||||
{
|
||||
if (qual->WallOrder == 0.0) return BIG;
|
||||
@@ -445,7 +445,6 @@ double mixtank(Project *pr, int n, double volin, double massin, double volout)
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Quality *qual = &pr->quality;
|
||||
|
||||
int i;
|
||||
double vnet;
|
||||
@@ -475,7 +474,6 @@ void tankmix1(Project *pr, int i, double vin, double win, double vnet)
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Hydraul *hyd = &pr->hydraul;
|
||||
Quality *qual = &pr->quality;
|
||||
|
||||
int k;
|
||||
@@ -544,7 +542,7 @@ void tankmix2(Project *pr, int i, double vin, double win, double vnet)
|
||||
}
|
||||
}
|
||||
|
||||
// Tank is emptying
|
||||
// Tank is emptying
|
||||
else if (vnet < 0.0)
|
||||
{
|
||||
if (stagzone->v > 0.0) vt = MIN(stagzone->v, (-vnet));
|
||||
@@ -555,7 +553,7 @@ void tankmix2(Project *pr, int i, double vin, double win, double vnet)
|
||||
}
|
||||
}
|
||||
|
||||
// Update segment volumes
|
||||
// Update segment volumes
|
||||
if (vt > 0.0)
|
||||
{
|
||||
mixzone->v = vmz;
|
||||
@@ -589,7 +587,6 @@ void tankmix3(Project *pr, int i, double vin, double win, double vnet)
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Hydraul *hyd = &pr->hydraul;
|
||||
Quality *qual = &pr->quality;
|
||||
|
||||
int k;
|
||||
@@ -640,7 +637,7 @@ void tankmix3(Project *pr, int i, double vin, double win, double vnet)
|
||||
}
|
||||
|
||||
// Use quality withdrawn from 1st segment
|
||||
// to represent overall quality of tank
|
||||
// to represent overall quality of tank
|
||||
if (vsum > 0.0) tank->C = wsum / vsum;
|
||||
else if (qual->FirstSeg[k] == NULL) tank->C = 0.0;
|
||||
else tank->C = qual->FirstSeg[k]->c;
|
||||
@@ -662,7 +659,7 @@ void tankmix4(Project *pr, int i, double vin, double win, double vnet)
|
||||
Network *net = &pr->network;
|
||||
Quality *qual = &pr->quality;
|
||||
|
||||
int k, n;
|
||||
int k;
|
||||
double cin, vsum, wsum, vseg;
|
||||
Pseg seg;
|
||||
Stank *tank = &pr->network.Tank[i];
|
||||
@@ -671,7 +668,6 @@ void tankmix4(Project *pr, int i, double vin, double win, double vnet)
|
||||
if (qual->LastSeg[k] == NULL || qual->FirstSeg[k] == NULL) return;
|
||||
|
||||
// Find inflows & outflows
|
||||
n = tank->Node;
|
||||
if (vin > 0.0) cin = win / vin;
|
||||
else cin = 0.0;
|
||||
|
||||
@@ -691,7 +687,7 @@ void tankmix4(Project *pr, int i, double vin, double win, double vnet)
|
||||
qual->LastSeg[k]->prev = seg;
|
||||
}
|
||||
|
||||
// ... update reported tank quality
|
||||
// ... update reported tank quality
|
||||
tank->C = qual->LastSeg[k]->c;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ void reversesegs(Project *, int);
|
||||
void addseg(Project *, int, double, double);
|
||||
|
||||
// Imported functions
|
||||
extern double findsourcequal(Project *, int, double, double, long);
|
||||
extern double findsourcequal(Project *, int, double, long);
|
||||
extern void reactpipes(Project *, long);
|
||||
extern void reacttanks(Project *, long);
|
||||
extern double mixtank(Project *, int, double, double, double);
|
||||
@@ -147,7 +147,6 @@ void evalnodeinflow(Project *pr, int k, long tstep, double *volin,
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Hydraul *hyd = &pr->hydraul;
|
||||
Quality *qual = &pr->quality;
|
||||
|
||||
@@ -251,7 +250,7 @@ double findnodequal(Project *pr, int n, double volin,
|
||||
}
|
||||
|
||||
// Find quality contribued by any external chemical source
|
||||
else qual->SourceQual = findsourcequal(pr, n, volin, volout, tstep);
|
||||
else qual->SourceQual = findsourcequal(pr, n, volout, tstep);
|
||||
if (qual->SourceQual == 0.0) return qual->NodeQual[n];
|
||||
|
||||
// Combine source quality with node quality
|
||||
@@ -285,7 +284,6 @@ double noflowqual(Project *pr, int n)
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Hydraul *hyd = &pr->hydraul;
|
||||
Quality *qual = &pr->quality;
|
||||
|
||||
int k, inflow, kount = 0;
|
||||
@@ -300,7 +298,7 @@ double noflowqual(Project *pr, int n)
|
||||
k = alink->link;
|
||||
dir = qual->FlowDir[k];
|
||||
|
||||
// Node n is link's downstream node - add quality
|
||||
// Node n is link's downstream node - add quality
|
||||
// of link's first segment to average
|
||||
if (net->Link[k].N2 == n && dir >= 0) inflow = TRUE;
|
||||
else if (net->Link[k].N1 == n && dir < 0) inflow = TRUE;
|
||||
@@ -311,7 +309,7 @@ double noflowqual(Project *pr, int n)
|
||||
kount++;
|
||||
}
|
||||
|
||||
// Node n is link's upstream node - add quality
|
||||
// Node n is link's upstream node - add quality
|
||||
// of link's last segment to average
|
||||
else if (inflow == FALSE && qual->LastSeg[k] != NULL)
|
||||
{
|
||||
@@ -428,7 +426,6 @@ int sortnodes(Project *pr)
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Hydraul *hyd = &pr->hydraul;
|
||||
Quality *qual = &pr->quality;
|
||||
|
||||
int i, j, k, n;
|
||||
@@ -578,7 +575,6 @@ void initsegs(Project *pr)
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Hydraul *hyd = &pr->hydraul;
|
||||
Quality *qual = &pr->quality;
|
||||
|
||||
int j, k;
|
||||
|
||||
78
src/report.c
78
src/report.c
@@ -69,8 +69,8 @@ int writereport(Project *pr)
|
||||
{
|
||||
Report *rpt = &pr->report;
|
||||
Parser *parser = &pr->parser;
|
||||
|
||||
char tflag;
|
||||
|
||||
int tflag;
|
||||
FILE *tfile;
|
||||
int errcode = 0;
|
||||
|
||||
@@ -82,7 +82,7 @@ int writereport(Project *pr)
|
||||
if (rpt->Energyflag) writeenergy(pr);
|
||||
errcode = writeresults(pr);
|
||||
}
|
||||
|
||||
|
||||
// A secondary report file was specified
|
||||
else if (strlen(rpt->Rpt2Fname) > 0)
|
||||
{
|
||||
@@ -145,7 +145,7 @@ void writelogo(Project *pr)
|
||||
char s[80];
|
||||
time_t timer; // time_t structure & functions time() &
|
||||
// ctime() are defined in time.h
|
||||
|
||||
|
||||
version = CODEVERSION;
|
||||
major = version / 10000;
|
||||
minor = (version % 10000) / 100;
|
||||
@@ -230,12 +230,12 @@ void writesummary(Project *pr)
|
||||
writeline(pr, s);
|
||||
}
|
||||
|
||||
sprintf(s, FMT27a, hyd->CheckFreq);
|
||||
writeline(pr, s);
|
||||
sprintf(s, FMT27b, hyd->MaxCheck);
|
||||
writeline(pr, s);
|
||||
sprintf(s, FMT27c, hyd->DampLimit);
|
||||
writeline(pr, s);
|
||||
sprintf(s, FMT27a, hyd->CheckFreq);
|
||||
writeline(pr, s);
|
||||
sprintf(s, FMT27b, hyd->MaxCheck);
|
||||
writeline(pr, s);
|
||||
sprintf(s, FMT27c, hyd->DampLimit);
|
||||
writeline(pr, s);
|
||||
sprintf(s, FMT28, hyd->MaxIter);
|
||||
writeline(pr, s);
|
||||
|
||||
@@ -341,7 +341,7 @@ void writehydstat(Project *pr, int iter, double relerr)
|
||||
}
|
||||
}
|
||||
|
||||
// Display status changes for links
|
||||
// Display status changes for links
|
||||
for (i = 1; i <= net->Nlinks; i++)
|
||||
{
|
||||
if (hyd->LinkStatus[i] != hyd->OldStatus[i])
|
||||
@@ -399,7 +399,7 @@ void writemassbalance(Project *pr)
|
||||
writeline(pr, s1);
|
||||
snprintf(s1, MAXMSG, "Final Mass: %12.5e", qual->MassBalance.final);
|
||||
writeline(pr, s1);
|
||||
snprintf(s1, MAXMSG, "Mass Ratio: %-0.5f", qual->MassBalance.ratio);
|
||||
snprintf(s1, MAXMSG, "Mass Ratio: %-.5f", qual->MassBalance.ratio);
|
||||
writeline(pr, s1);
|
||||
snprintf(s1, MAXMSG, "================================\n");
|
||||
writeline(pr, s1);
|
||||
@@ -426,7 +426,7 @@ void writeenergy(Project *pr)
|
||||
if (net->Npumps == 0) return;
|
||||
writeline(pr, " ");
|
||||
writeheader(pr,ENERHDR, 0);
|
||||
|
||||
|
||||
csum = 0.0;
|
||||
for (j = 1; j <= net->Npumps; j++)
|
||||
{
|
||||
@@ -534,7 +534,7 @@ int writeresults(Project *pr)
|
||||
}
|
||||
}
|
||||
|
||||
// Free allocated memory
|
||||
// Free allocated memory
|
||||
for (j = 0; j < m; j++) free(x[j]);
|
||||
free(x);
|
||||
return errcode;
|
||||
@@ -572,7 +572,7 @@ void writenodetable(Project *pr, Pfloat *x)
|
||||
if ((rpt->Nodeflag == 1 || node->Rpt) &&
|
||||
checklimits(rpt, y, ELEV, QUALITY))
|
||||
{
|
||||
// Check if new page needed
|
||||
// Check if new page needed
|
||||
if (rpt->LineNum == (long)rpt->PageSize) writeheader(pr, NODEHDR, 1);
|
||||
|
||||
// Add node ID and each reported field to string s
|
||||
@@ -618,7 +618,7 @@ void writelinktable(Project *pr, Pfloat *x)
|
||||
double y[MAXVAR];
|
||||
double *Ucf = pr->Ucf;
|
||||
Slink *Link = net->Link;
|
||||
|
||||
|
||||
// Write table header
|
||||
writeheader(pr, LINKHDR, 0);
|
||||
|
||||
@@ -686,7 +686,7 @@ void writeheader(Project *pr, int type, int contin)
|
||||
Quality *qual = &pr->quality;
|
||||
Parser *parser = &pr->parser;
|
||||
Times *time = &pr->times;
|
||||
|
||||
|
||||
char s[MAXLINE + 1], s1[MAXLINE + 1], s2[MAXLINE + 1], s3[MAXLINE + 1];
|
||||
int i, n;
|
||||
|
||||
@@ -697,7 +697,7 @@ void writeheader(Project *pr, int type, int contin)
|
||||
}
|
||||
writeline(pr, " ");
|
||||
|
||||
// Hydraulic Status Table
|
||||
// Hydraulic Status Table
|
||||
if (type == STATHDR)
|
||||
{
|
||||
sprintf(s, FMT49);
|
||||
@@ -737,12 +737,12 @@ void writeheader(Project *pr, int type, int contin)
|
||||
else sprintf(s, FMT78, clocktime(rpt->Atime, time->Htime));
|
||||
if (contin) strcat(s, t_CONTINUED);
|
||||
writeline(pr, s);
|
||||
|
||||
|
||||
n = 15;
|
||||
sprintf(s2, "%15s", "");
|
||||
strcpy(s, t_NODEID);
|
||||
sprintf(s3, "%-15s", s);
|
||||
|
||||
|
||||
for (i = ELEV; i < QUALITY; i++)
|
||||
{
|
||||
if (rpt->Field[i].Enabled == TRUE)
|
||||
@@ -846,7 +846,7 @@ void writerelerr(Project *pr, int iter, double relerr)
|
||||
{
|
||||
Report *rpt = &pr->report;
|
||||
Times *time = &pr->times;
|
||||
|
||||
|
||||
if (iter == 0)
|
||||
{
|
||||
sprintf(pr->Msg, FMT64, clocktime(rpt->Atime, time->Htime));
|
||||
@@ -878,7 +878,7 @@ void writestatchange(Project *pr, int k, char s1, char s2)
|
||||
double *Ucf = pr->Ucf;
|
||||
double *LinkSetting = hyd->LinkSetting;
|
||||
Slink *Link = net->Link;
|
||||
|
||||
|
||||
// We have a pump/valve setting change instead of a status change
|
||||
if (s1 == s2)
|
||||
{
|
||||
@@ -934,7 +934,7 @@ void writecontrolaction(Project *pr, int k, int i)
|
||||
Snode *Node = net->Node;
|
||||
Slink *Link = net->Link;
|
||||
Scontrol *Control = net->Control;
|
||||
|
||||
|
||||
switch (Control[i].Type)
|
||||
{
|
||||
case LOWLEVEL:
|
||||
@@ -944,7 +944,7 @@ void writecontrolaction(Project *pr, int k, int i)
|
||||
LinkTxt[Link[k].Type], Link[k].ID,
|
||||
NodeTxt[getnodetype(net, n)], Node[n].ID);
|
||||
break;
|
||||
|
||||
|
||||
case TIMER:
|
||||
case TIMEOFDAY:
|
||||
sprintf(pr->Msg, FMT55, clocktime(rpt->Atime, time->Htime),
|
||||
@@ -1001,7 +1001,7 @@ int writehydwarn(Project *pr, int iter, double relerr)
|
||||
|
||||
int i, j;
|
||||
char flag = 0;
|
||||
char s;
|
||||
int s;
|
||||
Snode *Node = net->Node;
|
||||
Slink *Link = net->Link;
|
||||
Spump *Pump = net->Pump;
|
||||
@@ -1010,7 +1010,7 @@ int writehydwarn(Project *pr, int iter, double relerr)
|
||||
double *NodeDemand = hyd->NodeDemand;
|
||||
double *LinkFlow = hyd->LinkFlow;
|
||||
double *LinkSetting = hyd->LinkSetting;
|
||||
|
||||
|
||||
// Check if system unstable
|
||||
if (iter > hyd->MaxIter && relerr <= hyd->Hacc)
|
||||
{
|
||||
@@ -1046,19 +1046,19 @@ int writehydwarn(Project *pr, int iter, double relerr)
|
||||
}
|
||||
}
|
||||
|
||||
// Check for abnormal pump condition
|
||||
// Check for abnormal pump condition
|
||||
for (i = 1; i <= net->Npumps; i++)
|
||||
{
|
||||
j = Pump[i].Link;
|
||||
s = hyd->LinkStatus[j];
|
||||
if (hyd->LinkStatus[j] >= OPEN)
|
||||
{
|
||||
if (LinkFlow[j] > LinkSetting[j] * Pump[i].Qmax) s = XFLOW;
|
||||
if (LinkFlow[j] < 0.0) s = XHEAD;
|
||||
}
|
||||
if (s == XHEAD || s == XFLOW)
|
||||
s = hyd->LinkStatus[j];
|
||||
if (hyd->LinkStatus[j] >= OPEN)
|
||||
{
|
||||
sprintf(pr->Msg, WARN04, Link[j].ID, StatTxt[s],
|
||||
if (LinkFlow[j] > LinkSetting[j] * Pump[i].Qmax) s = XFLOW;
|
||||
if (LinkFlow[j] < 0.0) s = XHEAD;
|
||||
}
|
||||
if (s == XHEAD || s == XFLOW)
|
||||
{
|
||||
sprintf(pr->Msg, WARN04, Link[j].ID, StatTxt[s],
|
||||
clocktime(rpt->Atime, time->Htime));
|
||||
if (rpt->Messageflag) writeline(pr, pr->Msg);
|
||||
flag = 4;
|
||||
@@ -1098,7 +1098,7 @@ void writehyderr(Project *pr, int errnode)
|
||||
Times *time = &pr->times;
|
||||
|
||||
Snode *Node = net->Node;
|
||||
|
||||
|
||||
sprintf(pr->Msg, FMT62, clocktime(rpt->Atime, time->Htime),
|
||||
Node[errnode].ID);
|
||||
if (rpt->Messageflag) writeline(pr, pr->Msg);
|
||||
@@ -1218,7 +1218,7 @@ void marknodes(Project *pr, int m, int *nodelist, char *marked)
|
||||
|
||||
int i, j, k, n;
|
||||
Padjlist alink;
|
||||
|
||||
|
||||
// Scan each successive entry of node list
|
||||
n = 1;
|
||||
while (n <= m)
|
||||
@@ -1232,7 +1232,7 @@ void marknodes(Project *pr, int m, int *nodelist, char *marked)
|
||||
j = alink->node;
|
||||
if (marked[j]) continue;
|
||||
|
||||
// Check if valve connection is in correct direction
|
||||
// Check if valve connection is in correct direction
|
||||
switch (net->Link[k].Type)
|
||||
{
|
||||
case CVPIPE:
|
||||
@@ -1299,7 +1299,7 @@ void writelimits(Project *pr, int j1, int j2)
|
||||
{
|
||||
Report *rpt = &pr->report;
|
||||
int j;
|
||||
|
||||
|
||||
for (j = j1; j <= j2; j++)
|
||||
{
|
||||
if (rpt->Field[j].RptLim[LOW] < BIG)
|
||||
|
||||
24
src/rules.c
24
src/rules.c
@@ -193,7 +193,7 @@ int ruledata(Project *pr)
|
||||
switch (key)
|
||||
{
|
||||
case -1:
|
||||
err = 201; // Unrecognized keyword
|
||||
err = 201; // Unrecognized keyword
|
||||
break;
|
||||
|
||||
case r_RULE:
|
||||
@@ -328,7 +328,6 @@ void adjustrules(Project *pr, int objtype, int index)
|
||||
//-----------------------------------------------------------
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Rules *rules = &pr->rules;
|
||||
|
||||
int i, delete;
|
||||
Spremise *p;
|
||||
@@ -453,7 +452,6 @@ int writerule(Project *pr, FILE *f, int ruleIndex)
|
||||
//-----------------------------------------------------------------------------
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Rules *rules = &pr->rules;
|
||||
|
||||
Srule *rule = &net->Rule[ruleIndex];
|
||||
Spremise *p;
|
||||
@@ -678,7 +676,7 @@ int newpremise(Project *pr, int logop)
|
||||
{
|
||||
if (!getfloat(Tok[parser->Ntokens - 1], &x))
|
||||
return (202);
|
||||
if (v == r_FILLTIME || v == r_DRAINTIME) x = x * 3600.0;
|
||||
if (v == r_FILLTIME || v == r_DRAINTIME) x = x * 3600.0;
|
||||
}
|
||||
|
||||
// Create new premise structure
|
||||
@@ -715,7 +713,7 @@ int newaction(Project *pr)
|
||||
double x;
|
||||
Saction *a;
|
||||
char **Tok = parser->Tok;
|
||||
|
||||
|
||||
// Check for correct number of tokens
|
||||
if (parser->Ntokens != 6) return 201;
|
||||
|
||||
@@ -848,7 +846,7 @@ int checktime(Project *pr, Spremise *p)
|
||||
{
|
||||
t1 = rules->Time1;
|
||||
t2 = time->Htime;
|
||||
}
|
||||
}
|
||||
else if (p->variable == r_CLOCKTIME)
|
||||
{
|
||||
t1 = (rules->Time1 + time->Tstart) % SECperDAY;
|
||||
@@ -878,7 +876,7 @@ int checktime(Project *pr, Spremise *p)
|
||||
case EQ:
|
||||
case NE:
|
||||
flag = FALSE;
|
||||
if (t2 < t1) // E.g., 11:00 am to 1:00 am
|
||||
if (t2 < t1) // E.g., 11:00 am to 1:00 am
|
||||
{
|
||||
if (x >= t1 || x <= t2)
|
||||
flag = TRUE;
|
||||
@@ -893,7 +891,7 @@ int checktime(Project *pr, Spremise *p)
|
||||
break;
|
||||
}
|
||||
|
||||
// If we get to here then premise was satisfied
|
||||
// If we get to here then premise was satisfied
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -906,7 +904,7 @@ int checkstatus(Project *pr, Spremise *p)
|
||||
|
||||
char i;
|
||||
int j;
|
||||
|
||||
|
||||
switch (p->status)
|
||||
{
|
||||
case IS_OPEN:
|
||||
@@ -930,7 +928,7 @@ int checkvalue(Project *pr, Spremise *p)
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Hydraul *hyd = &pr->hydraul;
|
||||
|
||||
|
||||
int i, j, v;
|
||||
double x, // A variable's value
|
||||
tol = 1.e-3; // Equality tolerance
|
||||
@@ -942,7 +940,7 @@ int checkvalue(Project *pr, Spremise *p)
|
||||
Snode *Node = net->Node;
|
||||
Slink *Link = net->Link;
|
||||
Stank *Tank = net->Tank;
|
||||
|
||||
|
||||
// Find the value being checked
|
||||
i = p->index;
|
||||
v = p->variable;
|
||||
@@ -1099,13 +1097,13 @@ int takeactions(Project *pr)
|
||||
Hydraul *hyd = &pr->hydraul;
|
||||
Report *rpt = &pr->report;
|
||||
Rules *rules = &pr->rules;
|
||||
|
||||
|
||||
char flag;
|
||||
int k, s, n;
|
||||
double tol = 1.e-3, v, x;
|
||||
Saction *a;
|
||||
SactionList *actionItem;
|
||||
|
||||
|
||||
n = 0;
|
||||
actionItem = rules->ActionList;
|
||||
while (actionItem != NULL)
|
||||
|
||||
161
src/smatrix.c
161
src/smatrix.c
@@ -81,9 +81,9 @@ static void transpose(int, int *, int *, int *, int *,
|
||||
int createsparse(Project *pr)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: none
|
||||
** Output: returns error code
|
||||
** Purpose: creates sparse representation of coeff. matrix
|
||||
** Input: none
|
||||
** Output: returns error code
|
||||
** Purpose: creates sparse representation of coeff. matrix
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -104,7 +104,7 @@ int createsparse(Project *pr)
|
||||
errcode = localadjlists(net, sm);
|
||||
if (errcode) return errcode;
|
||||
|
||||
// Re-order nodes to minimize number of non-zero coeffs.
|
||||
// Re-order nodes to minimize number of non-zero coeffs.
|
||||
// in factorized solution matrix
|
||||
ERRCODE(reordernodes(pr));
|
||||
|
||||
@@ -134,9 +134,9 @@ int createsparse(Project *pr)
|
||||
int allocsmatrix(Smatrix *sm, int Nnodes, int Nlinks)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: none
|
||||
** Output: returns error code
|
||||
** Purpose: allocates memory for representing a sparse matrix
|
||||
** Input: none
|
||||
** Output: returns error code
|
||||
** Purpose: allocates memory for representing a sparse matrix
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -192,20 +192,19 @@ int alloclinsolve(Smatrix *sm, int n)
|
||||
void freesparse(Project *pr)
|
||||
/*
|
||||
**----------------------------------------------------------------
|
||||
** Input: None
|
||||
** Output: None
|
||||
** Purpose: Frees memory used for sparse matrix storage
|
||||
** Input: None
|
||||
** Output: None
|
||||
** Purpose: Frees memory used for sparse matrix storage
|
||||
**----------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Smatrix *sm = &pr->hydraul.smatrix;
|
||||
|
||||
// stoptimer(SmatrixTimer);
|
||||
// printf("\n");
|
||||
// printf("\n Processing Time = %7.3f s", gettimer(SmatrixTimer));
|
||||
// printf("\n");
|
||||
|
||||
|
||||
FREE(sm->Order);
|
||||
FREE(sm->Row);
|
||||
FREE(sm->Ndx);
|
||||
@@ -247,7 +246,7 @@ int localadjlists(Network *net, Smatrix *sm)
|
||||
i = net->Link[k].N1;
|
||||
j = net->Link[k].N2;
|
||||
pmark = paralink(net, sm, i, j, k); // Parallel link check
|
||||
|
||||
|
||||
// Include link in start node i's list
|
||||
alink = (struct Sadjlist *) malloc(sizeof(struct Sadjlist));
|
||||
if (alink == NULL) return(101);
|
||||
@@ -261,7 +260,7 @@ int localadjlists(Network *net, Smatrix *sm)
|
||||
alink = (struct Sadjlist *) malloc(sizeof(struct Sadjlist));
|
||||
if (alink == NULL) return(101);
|
||||
if (!pmark) alink->node = i;
|
||||
else alink->node = 0; // Parallel link marker
|
||||
else alink->node = 0; // Parallel link marker
|
||||
alink->link = k;
|
||||
alink->next = net->Adjlist[j];
|
||||
net->Adjlist[j] = alink;
|
||||
@@ -276,7 +275,7 @@ int localadjlists(Network *net, Smatrix *sm)
|
||||
int paralink(Network *net, Smatrix *sm, int i, int j, int k)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: i = index of start node of link
|
||||
** Input: i = index of start node of link
|
||||
** j = index of end node of link
|
||||
** k = link index
|
||||
** Output: returns 1 if link k parallels another link, else 0
|
||||
@@ -350,10 +349,10 @@ void xparalinks(Network *net)
|
||||
int reordernodes(Project *pr)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: none
|
||||
** Output: returns 1 if successful, 0 if not
|
||||
** Purpose: re-orders nodes to minimize # of non-zeros that
|
||||
** will appear in factorized solution matrix
|
||||
** Input: none
|
||||
** Output: returns 1 if successful, 0 if not
|
||||
** Purpose: re-orders nodes to minimize # of non-zeros that
|
||||
** will appear in factorized solution matrix
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -376,7 +375,7 @@ int reordernodes(Project *pr)
|
||||
int *qsize = NULL;
|
||||
int *llist = NULL;
|
||||
int *marker = NULL;
|
||||
|
||||
|
||||
// Default ordering
|
||||
for (k = 1; k <= net->Nnodes; k++)
|
||||
{
|
||||
@@ -483,17 +482,17 @@ int factorize(Project *pr)
|
||||
int growlist(Project *pr, int knode)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: knode = node index
|
||||
** Output: returns 1 if successful, 0 if not
|
||||
** Purpose: creates new entries in knode's adjacency list for
|
||||
** all unlinked pairs of active nodes that are
|
||||
** adjacent to knode
|
||||
** Input: knode = node index
|
||||
** Output: returns 1 if successful, 0 if not
|
||||
** Purpose: creates new entries in knode's adjacency list for
|
||||
** all unlinked pairs of active nodes that are
|
||||
** adjacent to knode
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Smatrix *sm = &pr->hydraul.smatrix;
|
||||
|
||||
|
||||
int node;
|
||||
Padjlist alink;
|
||||
|
||||
@@ -517,16 +516,16 @@ int growlist(Project *pr, int knode)
|
||||
int newlink(Project *pr, Padjlist alink)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: alink = element of node's adjacency list
|
||||
** Output: returns 1 if successful, 0 if not
|
||||
** Purpose: links end of current adjacent link to end nodes of
|
||||
** all links that follow it on adjacency list
|
||||
** Input: alink = element of node's adjacency list
|
||||
** Output: returns 1 if successful, 0 if not
|
||||
** Purpose: links end of current adjacent link to end nodes of
|
||||
** all links that follow it on adjacency list
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Smatrix *sm = &pr->hydraul.smatrix;
|
||||
|
||||
|
||||
int inode, jnode;
|
||||
Padjlist blink;
|
||||
|
||||
@@ -535,7 +534,7 @@ int newlink(Project *pr, Padjlist alink)
|
||||
for (blink = alink->next; blink != NULL; blink = blink->next)
|
||||
{
|
||||
jnode = blink->node; // End node of next connection
|
||||
|
||||
|
||||
// If jnode still active, and inode not connected to jnode,
|
||||
// then add a new connection between inode and jnode.
|
||||
if (jnode > 0 && sm->Degree[jnode] > 0) // jnode still active
|
||||
@@ -545,7 +544,7 @@ int newlink(Project *pr, Padjlist alink)
|
||||
// Since new connection represents a non-zero coeff.
|
||||
// in the solution matrix, update the coeff. count.
|
||||
sm->Ncoeffs++;
|
||||
|
||||
|
||||
// Update adjacency lists for inode & jnode to
|
||||
// reflect the new connection.
|
||||
if (!addlink(net, inode, jnode, sm->Ncoeffs)) return 0;
|
||||
@@ -562,10 +561,10 @@ int newlink(Project *pr, Padjlist alink)
|
||||
int linked(Network *net, int i, int j)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: i = node index
|
||||
** j = node index
|
||||
** Output: returns 1 if nodes i and j are linked, 0 if not
|
||||
** Purpose: checks if nodes i and j are already linked.
|
||||
** Input: i = node index
|
||||
** j = node index
|
||||
** Output: returns 1 if nodes i and j are linked, 0 if not
|
||||
** Purpose: checks if nodes i and j are already linked.
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -581,11 +580,11 @@ int linked(Network *net, int i, int j)
|
||||
int addlink(Network *net, int i, int j, int n)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: i = node index
|
||||
** j = node index
|
||||
** n = link index
|
||||
** Output: returns 1 if successful, 0 if not
|
||||
** Purpose: augments node i's adjacency list with node j
|
||||
** Input: i = node index
|
||||
** j = node index
|
||||
** n = link index
|
||||
** Output: returns 1 if successful, 0 if not
|
||||
** Purpose: augments node i's adjacency list with node j
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -603,20 +602,20 @@ int addlink(Network *net, int i, int j, int n)
|
||||
int storesparse(Project *pr, int n)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: n = number of rows in solution matrix
|
||||
** Output: returns error code
|
||||
** Purpose: stores row indexes of non-zeros of each column of
|
||||
** lower triangular portion of factorized matrix
|
||||
** Input: n = number of rows in solution matrix
|
||||
** Output: returns error code
|
||||
** Purpose: stores row indexes of non-zeros of each column of
|
||||
** lower triangular portion of factorized matrix
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
Network *net = &pr->network;
|
||||
Smatrix *sm = &pr->hydraul.smatrix;
|
||||
|
||||
|
||||
int i, ii, j, k, l, m;
|
||||
int errcode = 0;
|
||||
Padjlist alink;
|
||||
|
||||
|
||||
// Allocate sparse matrix storage
|
||||
sm->XLNZ = (int *) calloc(n+2, sizeof(int));
|
||||
sm->NZSUB = (int *) calloc(sm->Ncoeffs+2, sizeof(int));
|
||||
@@ -625,7 +624,7 @@ int storesparse(Project *pr, int n)
|
||||
ERRCODE(MEMCHECK(sm->NZSUB));
|
||||
ERRCODE(MEMCHECK(sm->LNZ));
|
||||
if (errcode) return errcode;
|
||||
|
||||
|
||||
// Generate row index pointers for each column of matrix
|
||||
k = 0;
|
||||
sm->XLNZ[1] = 1;
|
||||
@@ -655,20 +654,20 @@ int storesparse(Project *pr, int n)
|
||||
int sortsparse(Smatrix *sm, int n)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: n = number of rows in solution matrix
|
||||
** Output: returns eror code
|
||||
** Purpose: puts row indexes in ascending order in NZSUB
|
||||
** Input: n = number of rows in solution matrix
|
||||
** Output: returns eror code
|
||||
** Purpose: puts row indexes in ascending order in NZSUB
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
int i, k;
|
||||
int *xlnzt, *nzsubt, *lnzt, *nzt;
|
||||
int errcode = 0;
|
||||
|
||||
|
||||
int *LNZ = sm->LNZ;
|
||||
int *XLNZ = sm->XLNZ;
|
||||
int *NZSUB = sm->NZSUB;
|
||||
|
||||
|
||||
xlnzt = (int *) calloc(n+2, sizeof(int));
|
||||
nzsubt = (int *) calloc(sm->Ncoeffs+2, sizeof(int));
|
||||
lnzt = (int *) calloc(sm->Ncoeffs+2, sizeof(int));
|
||||
@@ -687,12 +686,12 @@ int sortsparse(Smatrix *sm, int n)
|
||||
}
|
||||
xlnzt[1] = 1;
|
||||
for (i = 1; i <= n; i++) xlnzt[i+1] = xlnzt[i] + nzt[i];
|
||||
|
||||
|
||||
// Transpose matrix twice to order column indexes
|
||||
transpose(n, XLNZ, NZSUB, LNZ, xlnzt, nzsubt, lnzt, nzt);
|
||||
transpose(n, xlnzt, nzsubt, lnzt, XLNZ, NZSUB, LNZ, nzt);
|
||||
}
|
||||
|
||||
|
||||
// Reclaim memory
|
||||
free(xlnzt);
|
||||
free(nzsubt);
|
||||
@@ -706,11 +705,11 @@ void transpose(int n, int *il, int *jl, int *xl, int *ilt, int *jlt,
|
||||
int *xlt, int *nzt)
|
||||
/*
|
||||
**---------------------------------------------------------------------
|
||||
** Input: n = matrix order
|
||||
** il,jl,xl = sparse storage scheme for original matrix
|
||||
** nzt = work array
|
||||
** Output: ilt,jlt,xlt = sparse storage scheme for transposed matrix
|
||||
** Purpose: Determines sparse storage scheme for transpose of a matrix
|
||||
** Input: n = matrix order
|
||||
** il,jl,xl = sparse storage scheme for original matrix
|
||||
** nzt = work array
|
||||
** Output: ilt,jlt,xlt = sparse storage scheme for transposed matrix
|
||||
** Purpose: Determines sparse storage scheme for transpose of a matrix
|
||||
**---------------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -735,25 +734,25 @@ int linsolve(Smatrix *sm, int n)
|
||||
/*
|
||||
**--------------------------------------------------------------
|
||||
** Input: sm = sparse matrix struct
|
||||
n = number of equations
|
||||
** Output: sm->F = solution values
|
||||
** returns 0 if solution found, or index of
|
||||
** equation causing system to be ill-conditioned
|
||||
** Purpose: solves sparse symmetric system of linear
|
||||
** equations using Cholesky factorization
|
||||
**
|
||||
** NOTE: This procedure assumes that the solution matrix has
|
||||
** been symbolically factorized with the positions of
|
||||
** the lower triangular, off-diagonal, non-zero coeffs.
|
||||
** stored in the following integer arrays:
|
||||
** XLNZ (start position of each column in NZSUB)
|
||||
** NZSUB (row index of each non-zero in each column)
|
||||
** LNZ (position of each NZSUB entry in Aij array)
|
||||
**
|
||||
** This procedure has been adapted from subroutines GSFCT and
|
||||
** GSSLV in the book "Computer Solution of Large Sparse
|
||||
** Positive Definite Systems" by A. George and J. W-H Liu
|
||||
** (Prentice-Hall, 1981).
|
||||
n = number of equations
|
||||
** Output: sm->F = solution values
|
||||
** returns 0 if solution found, or index of
|
||||
** equation causing system to be ill-conditioned
|
||||
** Purpose: solves sparse symmetric system of linear
|
||||
** equations using Cholesky factorization
|
||||
**
|
||||
** NOTE: This procedure assumes that the solution matrix has
|
||||
** been symbolically factorized with the positions of
|
||||
** the lower triangular, off-diagonal, non-zero coeffs.
|
||||
** stored in the following integer arrays:
|
||||
** XLNZ (start position of each column in NZSUB)
|
||||
** NZSUB (row index of each non-zero in each column)
|
||||
** LNZ (position of each NZSUB entry in Aij array)
|
||||
**
|
||||
** This procedure has been adapted from subroutines GSFCT and
|
||||
** GSSLV in the book "Computer Solution of Large Sparse
|
||||
** Positive Definite Systems" by A. George and J. W-H Liu
|
||||
** (Prentice-Hall, 1981).
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
@@ -766,7 +765,7 @@ int linsolve(Smatrix *sm, int n)
|
||||
int *NZSUB = sm->NZSUB;
|
||||
int *link = sm->link;
|
||||
int *first = sm->first;
|
||||
|
||||
|
||||
int i, istop, istrt, isub, j, k, kfirst, newk;
|
||||
double bj, diagj, ljk;
|
||||
|
||||
|
||||
60
src/types.h
60
src/types.h
@@ -384,7 +384,7 @@ typedef struct // Node Object
|
||||
Psource S; // source pointer
|
||||
double C0; // initial quality
|
||||
double Ke; // emitter coeff.
|
||||
char Rpt; // reporting flag
|
||||
int Rpt; // reporting flag
|
||||
NodeType Type; // node type
|
||||
char Comment[MAXMSG+1]; // node comment
|
||||
} Snode;
|
||||
@@ -405,7 +405,7 @@ typedef struct // Link Object
|
||||
double Qa; // low flow limit
|
||||
LinkType Type; // link type
|
||||
StatusType Status; // initial status
|
||||
char Rpt; // reporting flag
|
||||
int Rpt; // reporting flag
|
||||
char Comment[MAXMSG+1]; // link Comment
|
||||
} Slink;
|
||||
|
||||
@@ -466,7 +466,7 @@ typedef struct // Field Object of Report Table
|
||||
{
|
||||
char Name[MAXID+1]; // name of reported variable
|
||||
char Units[MAXID+1]; // units of reported variable
|
||||
char Enabled; // enabled if in table
|
||||
int Enabled; // enabled if in table
|
||||
int Precision; // number of decimal places
|
||||
double RptLim[2]; // lower/upper report limits
|
||||
} SField;
|
||||
@@ -544,9 +544,6 @@ typedef struct {
|
||||
FILE *InFile; // Input file handle
|
||||
|
||||
char
|
||||
Unitsflag, // Unit system flag
|
||||
Flowflag, // Flow units flag
|
||||
Pressflag, // Pressure units flag
|
||||
DefPatID[MAXID+1], // Default demand pattern ID
|
||||
InpFname[MAXFNAME+1], // Input file name
|
||||
*Tok[MAXTOKS], // Array of token strings
|
||||
@@ -566,7 +563,10 @@ typedef struct {
|
||||
MaxCurves, // Curve count " " "
|
||||
Ntokens, // Number of tokens in line of input
|
||||
Ntitle, // Number of title lines
|
||||
ErrTok; // Index of error-producing token
|
||||
ErrTok, // Index of error-producing token
|
||||
Unitsflag, // Unit system flag
|
||||
Flowflag, // Flow units flag
|
||||
Pressflag; // Pressure units flag
|
||||
|
||||
STmplist
|
||||
*Patlist, // Temporary time pattern list
|
||||
@@ -605,13 +605,7 @@ typedef struct {
|
||||
|
||||
int
|
||||
Nperiods, // Number of reporting periods
|
||||
PageSize; // Lines/page in output report/
|
||||
|
||||
long
|
||||
LineNum, // Current line number
|
||||
PageNum; // Current page number
|
||||
|
||||
char
|
||||
PageSize, // Lines/page in output report/
|
||||
Rptflag, // Report flag
|
||||
Tstatflag, // Report time series statistic flag
|
||||
Summaryflag, // Report summary flag
|
||||
@@ -620,11 +614,17 @@ typedef struct {
|
||||
Energyflag, // Energy report flag
|
||||
Nodeflag, // Node report flag
|
||||
Linkflag, // Link report flag
|
||||
Fprinterr; // File write error flag
|
||||
|
||||
long
|
||||
LineNum, // Current line number
|
||||
PageNum; // Current page number
|
||||
|
||||
char
|
||||
Atime[13], // Clock time (hrs:min:sec)
|
||||
Rpt1Fname[MAXFNAME+1], // Primary report file name
|
||||
Rpt2Fname[MAXFNAME+1], // Secondary report file name
|
||||
DateStamp[26], // Current date & time
|
||||
Fprinterr; // File write error flag
|
||||
DateStamp[26]; // Current date & time
|
||||
|
||||
SField Field[MAXVAR]; // Output reporting fields
|
||||
|
||||
@@ -635,7 +635,9 @@ typedef struct {
|
||||
|
||||
char
|
||||
HydFname[MAXFNAME+1], // Hydraulics file name
|
||||
OutFname[MAXFNAME+1], // Binary output file name
|
||||
OutFname[MAXFNAME+1]; // Binary output file name
|
||||
|
||||
int
|
||||
Outflag, // Output file flag
|
||||
Hydflag, // Hydraulics flag
|
||||
SaveHflag, // Hydraulic results saved flag
|
||||
@@ -732,22 +734,20 @@ typedef struct {
|
||||
DefPat, // Default demand pattern
|
||||
Epat, // Energy cost time pattern
|
||||
DemandModel, // Fixed or pressure dependent
|
||||
Formflag, // Head loss formula flag
|
||||
Iterations, // Number of hydraulic trials taken
|
||||
MaxIter, // Max. hydraulic trials allowed
|
||||
ExtraIter, // Extra hydraulic trials
|
||||
CheckFreq, // Hydraulic trials between status checks
|
||||
MaxCheck, // Hydraulic trials limit on status checks
|
||||
OpenHflag, // Hydraulic system opened flag
|
||||
Haltflag; // Flag to halt simulation
|
||||
|
||||
StatusType
|
||||
*LinkStatus, // Link status
|
||||
*OldStatus; // Previous link/tank status
|
||||
|
||||
char
|
||||
OpenHflag, // Hydraulic system opened flag
|
||||
Formflag; // Head loss formula flag
|
||||
|
||||
Smatrix smatrix; // Sparse matrix storage
|
||||
Smatrix smatrix; // Sparse matrix storage
|
||||
|
||||
} Hydraul;
|
||||
|
||||
@@ -757,20 +757,18 @@ struct Mempool;
|
||||
// Water Quality Solver Wrapper
|
||||
typedef struct {
|
||||
|
||||
char
|
||||
int
|
||||
Qualflag, // Water quality analysis flag
|
||||
OpenQflag, // Quality system opened flag
|
||||
Reactflag, // Reaction indicator
|
||||
OutOfMemory; // Out of memory indicator
|
||||
OutOfMemory, // Out of memory indicator
|
||||
TraceNode, // Source node for flow tracing
|
||||
*SortedNodes; // Topologically sorted node indexes
|
||||
|
||||
char
|
||||
ChemName[MAXID + 1], // Name of chemical
|
||||
ChemUnits[MAXID + 1]; // Units of chemical
|
||||
|
||||
int
|
||||
TraceNode, // Source node for flow tracing
|
||||
*SortedNodes; // Topologically sorted node indexes
|
||||
|
||||
double
|
||||
Ctol, // Water quality tolerance
|
||||
Diffus, // Diffusivity (sq ft/sec)
|
||||
@@ -854,9 +852,11 @@ typedef struct Project {
|
||||
|
||||
double Ucf[MAXVAR]; // Unit conversion factors
|
||||
|
||||
char
|
||||
int
|
||||
Openflag, // Project open flag
|
||||
Warnflag, // Warning flag
|
||||
Warnflag; // Warning flag
|
||||
|
||||
char
|
||||
Msg[MAXMSG+1], // General-purpose string: errors, messages
|
||||
Title[MAXTITLE][TITLELEN+1], // Project title
|
||||
MapFname[MAXFNAME+1], // Map file name
|
||||
|
||||
Reference in New Issue
Block a user