Cleaning up include statements adding crtdbg.h

This commit is contained in:
Michael Tryby
2019-04-03 15:55:23 -04:00
parent be2b0a3ac8
commit 84bf6f98d0
22 changed files with 706 additions and 619 deletions

View File

@@ -11,13 +11,16 @@
******************************************************************************
*/
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#else
#include <stdlib.h>
#endif
#include <math.h>
#include "types.h"
@@ -85,12 +88,12 @@ void resistcoeff(Project *pr, int k)
double e, d, L;
Slink *link = &net->Link[k];
link->Qa = 0.0;
switch (link->Type) {
// ... Link is a pipe. Compute resistance based on headloss formula.
// Friction factor for D-W formula gets included during head loss
// Friction factor for D-W formula gets included during head loss
// calculation.
case CVPIPE:
case PIPE:
@@ -244,14 +247,14 @@ void linkcoeffs(Project *pr)
// Update linear system coeffs. associated with start node n1
// ... node n1 is junction
if (n1 <= net->Njuncs)
if (n1 <= net->Njuncs)
{
sm->Aii[sm->Row[n1]] += hyd->P[k]; // Diagonal coeff.
sm->F[sm->Row[n1]] += hyd->Y[k]; // RHS coeff.
}
// ... node n1 is a tank/reservoir
else sm->F[sm->Row[n2]] += (hyd->P[k] * hyd->NodeHead[n1]);
else sm->F[sm->Row[n2]] += (hyd->P[k] * hyd->NodeHead[n1]);
// Update linear system coeffs. associated with end node n2
// ... node n2 is junction
@@ -262,7 +265,7 @@ void linkcoeffs(Project *pr)
}
// ... node n2 is a tank/reservoir
else sm->F[sm->Row[n1]] += (hyd->P[k] * hyd->NodeHead[n2]);
else sm->F[sm->Row[n1]] += (hyd->P[k] * hyd->NodeHead[n2]);
}
}
@@ -321,13 +324,13 @@ void valvecoeffs(Project *pr)
// Coeffs. for fixed status valves have already been computed
if (hyd->LinkSetting[k] == MISSING) continue;
// Start & end nodes of valve's link
// Start & end nodes of valve's link
link = &net->Link[k];
n1 = link->N1;
n2 = link->N2;
// Call valve-specific function
switch (link->Type)
switch (link->Type)
{
case PRV:
prvcoeff(pr, k, n1, n2);
@@ -482,7 +485,7 @@ void demandcoeffs(Project *pr)
double dp, // pressure range over which demand can vary (ft)
n, // exponent in head loss v. demand function
hloss, // head loss in supplying demand (ft)
hgrad; // gradient of demand head loss (ft/cfs)
hgrad; // gradient of demand head loss (ft/cfs)
// Get demand function parameters
if (hyd->DemandModel == DDA) return;
@@ -659,12 +662,12 @@ void DWpipecoeff(Project *pr, int k)
Slink *link = &pr->network.Link[k];
double q = ABS(hyd->LinkFlow[k]);
double r = link->R; // Resistance coeff.
double ml = link->Km; // Minor loss coeff.
double r = link->R; // Resistance coeff.
double ml = link->Km; // Minor loss coeff.
double e = link->Kc / link->Diam; // Relative roughness
double s = hyd->Viscos * link->Diam; // Viscosity / diameter
double hloss, hgrad, f, dfdq, r1;
// Compute head loss and its derivative
// ... use Hagen-Poiseuille formula for laminar flow (Re <= 2000)
if (q <= A2 * s)
@@ -673,7 +676,7 @@ void DWpipecoeff(Project *pr, int k)
hloss = hyd->LinkFlow[k] * (r + ml * q);
hgrad = r + 2.0 * ml * q;
}
// ... otherwise use Darcy-Weisbach formula with friction factor
else
{
@@ -683,7 +686,7 @@ void DWpipecoeff(Project *pr, int k)
hloss = r1 * q * hyd->LinkFlow[k];
hgrad = (2.0 * r1 * q) + (dfdq * r * q * q);
}
// Compute P and Y coefficients
hyd->P[k] = 1.0 / hgrad;
hyd->Y[k] = hloss / hgrad;
@@ -753,7 +756,7 @@ void pumpcoeff(Project *pr, int k)
int p; // Pump index
double h0, // Shutoff head
q, // Abs. value of flow
q, // Abs. value of flow
r, // Flow resistance coeff.
n, // Flow exponent coeff.
setting, // Pump speed setting
@@ -899,7 +902,7 @@ void gpvcoeff(Project *pr, int k)
Hydraul *hyd = &pr->hydraul;
// Treat as a pipe if valve closed
if (hyd->LinkStatus[k] == CLOSED) valvecoeff(pr, k);
if (hyd->LinkStatus[k] == CLOSED) valvecoeff(pr, k);
// Otherwise utilize segment of head loss curve
// bracketing current flow (curve index is stored
@@ -939,7 +942,7 @@ void pbvcoeff(Project *pr, int k)
// If valve fixed OPEN or CLOSED then treat as a pipe
if (hyd->LinkSetting[k] == MISSING || hyd->LinkSetting[k] == 0.0)
{
valvecoeff(pr, k);
valvecoeff(pr, k);
}
// If valve is active
@@ -948,7 +951,7 @@ void pbvcoeff(Project *pr, int k)
// Treat as a pipe if minor loss > valve setting
if (link->Km * SQR(hyd->LinkFlow[k]) > hyd->LinkSetting[k])
{
valvecoeff(pr, k);
valvecoeff(pr, k);
}
// Otherwise force headloss across valve to be equal to setting
else
@@ -983,7 +986,7 @@ void tcvcoeff(Project *pr, int k)
}
// Then apply usual valve formula
valvecoeff(pr, k);
valvecoeff(pr, k);
// Restore original loss coeff.
link->Km = km;
@@ -1017,7 +1020,7 @@ void prvcoeff(Project *pr, int k, int n1, int n2)
{
// Set coeffs. to force head at downstream
// node equal to valve setting & force flow
// node equal to valve setting & force flow
// to equal to flow excess at downstream node.
hyd->P[k] = 0.0;
@@ -1069,7 +1072,7 @@ void psvcoeff(Project *pr, int k, int n1, int n2)
if (hyd->LinkStatus[k] == ACTIVE)
{
// Set coeffs. to force head at upstream
// node equal to valve setting & force flow
// node equal to valve setting & force flow
// equal to flow excess at upstream node.
hyd->P[k] = 0.0;
@@ -1138,7 +1141,7 @@ void fcvcoeff(Project *pr, int k, int n1, int n2)
else
{
valvecoeff(pr, k);
valvecoeff(pr, k);
sm->Aij[sm->Ndx[k]] -= hyd->P[k];
sm->Aii[i] += hyd->P[k];
sm->Aii[j] += hyd->P[k];
@@ -1162,7 +1165,7 @@ void valvecoeff(Project *pr, int k)
Slink *link = &pr->network.Link[k];
double flow, q, y, qa, hgrad;
flow = hyd->LinkFlow[k];
// Valve is closed. Use a very small matrix coeff.