diff --git a/src/hydcoeffs.c b/src/hydcoeffs.c index 9f4ac3d..e044dff 100644 --- a/src/hydcoeffs.c +++ b/src/hydcoeffs.c @@ -691,6 +691,8 @@ void pumpcoeff(Project *pr, int k) hgrad; // Head loss gradient Spump *pump; + double qstar; + // Use high resistance pipe if pump closed or cannot deliver head setting = hyd->LinkSetting[k]; if (hyd->LinkStatus[k] <= CLOSED || setting == 0.0) @@ -748,12 +750,14 @@ void pumpcoeff(Project *pr, int k) if (hgrad > CBIG) { hgrad = CBIG; - hloss = -hgrad * hyd->LinkFlow[k]; + qstar = sqrt(-r / hgrad); + hloss = (r / qstar) - hgrad * (qstar - q); } else if (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 else diff --git a/src/hydstatus.c b/src/hydstatus.c index 3d7c106..4013ec9 100644 --- a/src/hydstatus.c +++ b/src/hydstatus.c @@ -437,12 +437,21 @@ void tankstatus(Project *pr, int k, int n1, int n2) tank = &net->Tank[i]; if (tank->A == 0.0) return; - if (hyd->NodeHead[n1] >= tank->Hmax - hyd->Htol && !tank->CanOverflow) + // Can't add flow to a full tank + if (hyd->NodeHead[n1] >= tank->Hmax && !tank->CanOverflow) { - if (q < 0.0) hyd->LinkStatus[k] = TEMPCLOSED; + if (link->Type == PUMP && link->N2 == n1) + hyd->LinkStatus[k] = TEMPCLOSED; + else if (q < 0.0) + hyd->LinkStatus[k] = TEMPCLOSED; } - if (hyd->NodeHead[n1] <= tank->Hmin + hyd->Htol) + + // Can't remove flow from an empty tank + if (hyd->NodeHead[n1] <= tank->Hmin) { - if (q > 0.0) hyd->LinkStatus[k] = TEMPCLOSED; + if (link->Type == PUMP && link->N1 == n1) + hyd->LinkStatus[k] = TEMPCLOSED; + else if (q > 0.0) + hyd->LinkStatus[k] = TEMPCLOSED; } }