Skip to content

Commit

Permalink
Fixes for PDA
Browse files Browse the repository at this point in the history
  • Loading branch information
LRossman committed Jun 26, 2024
1 parent 30a3fcb commit 68b73a1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
25 changes: 10 additions & 15 deletions src/flowbalance.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ void updateflowbalance(Project *pr, long hstep)
flowBalance.storageDemand = 0.0;
fullDemand = 0.0;

// Initialize demand deficiency & leakage loss
hyd->DeficientNodes = 0;
hyd->DemandReduction = 0.0;
// Initialize leakage loss
hyd->LeakageLoss = 0.0;

// Examine each junction node
Expand Down Expand Up @@ -104,11 +102,8 @@ void updateflowbalance(Project *pr, long hstep)
if (hyd->DemandModel == PDA && hyd->FullDemand[i] > 0.0)
{
deficit = hyd->FullDemand[i] - hyd->DemandFlow[i];
if (deficit > TINY)
{
hyd->DeficientNodes++;
if (deficit > 0.0)
flowBalance.deficitDemand += deficit;
}
}
}

Expand All @@ -118,25 +113,25 @@ void updateflowbalance(Project *pr, long hstep)
i = net->Tank[j].Node;
v = hyd->NodeDemand[i];

// For a snapshot analysis or a reservoir node
if (time->Dur == 0 || net->Tank[j].A == 0.0)
// For a reservoir node
if (net->Tank[j].A == 0.0)
{
if (v >= 0.0)
flowBalance.totalOutflow += v;
else
flowBalance.totalInflow += (-v);
}

// For tank under extended period analysis
// For tank
else
flowBalance.storageDemand += v;
}

// Find % demand reduction & % leakage for current period
if (fullDemand > 0.0)
hyd->DemandReduction = flowBalance.deficitDemand / fullDemand * 100.0;
if (flowBalance.totalInflow > 0.0)
hyd->LeakageLoss = flowBalance.leakageDemand / flowBalance.totalInflow * 100.0;
// Find % leakage for current period
v = flowBalance.totalInflow;
if (flowBalance.storageDemand < 0.0) v += (-flowBalance.storageDemand);
if (v > 0.0)
hyd->LeakageLoss = flowBalance.leakageDemand / v * 100.0;

// Update flow balance for entire run
hyd->FlowBalance.totalInflow += flowBalance.totalInflow * dt;
Expand Down
26 changes: 21 additions & 5 deletions src/hydsolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Authors: see AUTHORS
Copyright: see AUTHORS
License: see LICENSE
Last Updated: 06/15/2024
Last Updated: 06/26/2024
******************************************************************************
*/

Expand Down Expand Up @@ -703,10 +703,15 @@ int pdaconverged(Project *pr)
Hydraul *hyd = &pr->hydraul;

const double QTOL = 0.0001; // 0.0001 cfs ~= 0.005 gpm ~= 0.2 lpm)
int i;
int i, converged = 1;

double totalDemand = 0.0, totalReduction = 0.0;
double dp = hyd->Preq - hyd->Pmin;
double p, q, r;


hyd->DeficientNodes = 0;
hyd->DemandReduction = 0.0;

// Examine each network junction
for (i = 1; i <= pr->network.Njuncs; i++)
{
Expand All @@ -726,9 +731,20 @@ int pdaconverged(Project *pr)
}

// Check if demand has not converged
if (fabs(q - hyd->DemandFlow[i]) > QTOL) return 0;
if (fabs(q - hyd->DemandFlow[i]) > QTOL)
converged = 0;

// Accumulate demand deficient node count and demand deficit
if (hyd->DemandFlow[i] + QTOL < hyd->FullDemand[i])
{
hyd->DeficientNodes++;
totalDemand += hyd->FullDemand[i];
totalReduction += hyd->FullDemand[i] - hyd->DemandFlow[i];
}
}
return 1;
if (totalDemand > 0.0)
hyd->DemandReduction = totalReduction / totalDemand * 100.0;
return converged;
}


Expand Down
3 changes: 0 additions & 3 deletions tests/test_pda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ BOOST_AUTO_TEST_CASE(test_pda_model)
error = EN_getnodeindex(ph, (char *)"21", &index);
BOOST_REQUIRE(error == 0);
error = EN_getnodevalue(ph, index, EN_DEMANDDEFICIT, &reduction);

printf("\nreduction = %f", reduction);

BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(abs(reduction - 413.67) < 0.01);

Expand Down

0 comments on commit 68b73a1

Please sign in to comment.