Fixes bugs in pump and demand head loss gradients

This commit is contained in:
Lew Rossman
2019-09-26 11:01:01 -04:00
parent 647abd71c1
commit da1253f4ea
2 changed files with 12 additions and 11 deletions

View File

@@ -505,20 +505,19 @@ void demandheadloss(Project *pr, int i, double dp, double n,
*hloss = (*hgrad) * d;
}
// Otherwise use power head loss function
else
// Use power head loss function for demand less than full
else if (r < 1.0)
{
*hgrad = n * dp * pow(r, n - 1.0) / dfull;
*hloss = (*hgrad) * d / n;
// Add on barrier function for any demand above full value
if (r >= 1.0)
{
*hgrad += CBIG;
*hloss += CBIG * (d - dfull);
}
}
// Use upper barrier function for demand above full value
else
{
*hgrad = CBIG;
*hloss = dp + CBIG * (d - dfull);
}
}
@@ -761,7 +760,8 @@ void pumpcoeff(Project *pr, int k)
if (n != 1.0)
{
// ... use linear approx. to pump curve for small flows
qa = pow(hyd->RQtol / n / r, 1.0 / (n - 1.0));
if (pump->Ptype == CONST_HP) qa = -CBIG;
else qa = pow(hyd->RQtol / n / r, 1.0 / (n - 1.0));
if (q <= qa)
{
hgrad = hyd->RQtol;

View File

@@ -14,11 +14,12 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
//*** For the Windows SDK _tempnam function ***//
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h >
#endif
#include "types.h"