Merge pull request #624 from OpenWaterAnalytics/dev_tank_fix
Empty tank draining fix
This commit is contained in:
@@ -691,6 +691,8 @@ void pumpcoeff(Project *pr, int k)
|
|||||||
hgrad; // Head loss gradient
|
hgrad; // Head loss gradient
|
||||||
Spump *pump;
|
Spump *pump;
|
||||||
|
|
||||||
|
double qstar;
|
||||||
|
|
||||||
// Use high resistance pipe if pump closed or cannot deliver head
|
// Use high resistance pipe if pump closed or cannot deliver head
|
||||||
setting = hyd->LinkSetting[k];
|
setting = hyd->LinkSetting[k];
|
||||||
if (hyd->LinkStatus[k] <= CLOSED || setting == 0.0)
|
if (hyd->LinkStatus[k] <= CLOSED || setting == 0.0)
|
||||||
@@ -748,12 +750,14 @@ void pumpcoeff(Project *pr, int k)
|
|||||||
if (hgrad > CBIG)
|
if (hgrad > CBIG)
|
||||||
{
|
{
|
||||||
hgrad = CBIG;
|
hgrad = CBIG;
|
||||||
hloss = -hgrad * hyd->LinkFlow[k];
|
qstar = sqrt(-r / hgrad);
|
||||||
|
hloss = (r / qstar) - hgrad * (qstar - q);
|
||||||
}
|
}
|
||||||
else if (hgrad < hyd->RQtol)
|
else if (hgrad < hyd->RQtol)
|
||||||
{
|
{
|
||||||
hgrad = hyd->RQtol;
|
hgrad = hyd->RQtol;
|
||||||
hloss = -hgrad * hyd->LinkFlow[k];
|
qstar = sqrt(-r / hgrad);
|
||||||
|
hloss = (r / qstar) - hgrad * (qstar - q);
|
||||||
}
|
}
|
||||||
// ... otherwise compute head loss from pump curve
|
// ... otherwise compute head loss from pump curve
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -413,7 +413,7 @@ void tankstatus(Project *pr, int k, int n1, int n2)
|
|||||||
Hydraul *hyd = &pr->hydraul;
|
Hydraul *hyd = &pr->hydraul;
|
||||||
|
|
||||||
int i, n;
|
int i, n;
|
||||||
double h, q;
|
double q;
|
||||||
Stank *tank;
|
Stank *tank;
|
||||||
Slink *link = &net->Link[k];
|
Slink *link = &net->Link[k];
|
||||||
|
|
||||||
@@ -437,40 +437,21 @@ void tankstatus(Project *pr, int k, int n1, int n2)
|
|||||||
tank = &net->Tank[i];
|
tank = &net->Tank[i];
|
||||||
if (tank->A == 0.0) return;
|
if (tank->A == 0.0) return;
|
||||||
|
|
||||||
// Find head difference across link
|
// Can't add flow to a full tank
|
||||||
h = hyd->NodeHead[n1] - hyd->NodeHead[n2];
|
if (hyd->NodeHead[n1] >= tank->Hmax && !tank->CanOverflow)
|
||||||
|
|
||||||
// If tank is full, then prevent flow into it
|
|
||||||
if (hyd->NodeHead[n1] >= tank->Hmax - hyd->Htol && !tank->CanOverflow)
|
|
||||||
{
|
{
|
||||||
// Case 1: Link is a pump discharging into tank
|
if (link->Type == PUMP && link->N2 == n1)
|
||||||
if (link->Type == PUMP)
|
hyd->LinkStatus[k] = TEMPCLOSED;
|
||||||
{
|
else if (q < 0.0)
|
||||||
if (link->N2 == n1) hyd->LinkStatus[k] = TEMPCLOSED;
|
hyd->LinkStatus[k] = TEMPCLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Case 2: Downstream head > tank head
|
// Can't remove flow from an empty tank
|
||||||
// (e.g., an open outflow check valve would close)
|
if (hyd->NodeHead[n1] <= tank->Hmin)
|
||||||
else if (cvstatus(pr, OPEN, h, q) == CLOSED)
|
|
||||||
{
|
{
|
||||||
|
if (link->Type == PUMP && link->N1 == n1)
|
||||||
|
hyd->LinkStatus[k] = TEMPCLOSED;
|
||||||
|
else if (q > 0.0)
|
||||||
hyd->LinkStatus[k] = TEMPCLOSED;
|
hyd->LinkStatus[k] = TEMPCLOSED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If tank is empty, then prevent flow out of it
|
|
||||||
if (hyd->NodeHead[n1] <= tank->Hmin + hyd->Htol)
|
|
||||||
{
|
|
||||||
// Case 1: Link is a pump discharging from tank
|
|
||||||
if (link->Type == PUMP)
|
|
||||||
{
|
|
||||||
if (link->N1 == n1) hyd->LinkStatus[k] = TEMPCLOSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Case 2: Tank head > downstream head
|
|
||||||
// (e.g., a closed outflow check valve would open)
|
|
||||||
else if (cvstatus(pr, CLOSED, h, q) == OPEN)
|
|
||||||
{
|
|
||||||
hyd->LinkStatus[k] = TEMPCLOSED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user