Skip to content

Commit 0bd4bfd

Browse files
authored
Merge pull request #895 from OpenWaterAnalytics/dev-Flow_Balance_Fix
Fixes flow balance bug for halted runs
2 parents 5978893 + 3e72731 commit 0bd4bfd

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/flowbalance.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// Exported functions (declared in funcs.h)
1717
//void startflowbalance(Project *);
1818
//void updateflowbalance(Project *, long);
19-
//void endflowbalance(Project *);
19+
//void endflowbalance(Project *, long);
2020

2121
void startflowbalance(Project *pr)
2222
/*
@@ -143,7 +143,7 @@ void updateflowbalance(Project *pr, long hstep)
143143
hyd->FlowBalance.storageDemand += flowBalance.storageDemand * dt;
144144
}
145145

146-
void endflowbalance(Project *pr)
146+
void endflowbalance(Project *pr, long tFinal)
147147
/*
148148
**-------------------------------------------------------------------
149149
** Input: none
@@ -153,12 +153,11 @@ void endflowbalance(Project *pr)
153153
*/
154154
{
155155
Hydraul *hyd = &pr->hydraul;
156-
Times *time = &pr->times;
157156

158157
double seconds, qin, qout, qstor, r;
159158

160-
if (time->Htime > 0)
161-
seconds = time->Htime;
159+
if (tFinal > 0)
160+
seconds = tFinal;
162161
else
163162
seconds = 1.0;
164163
hyd->FlowBalance.totalInflow /= seconds;

src/funcs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,6 @@ int leakagehasconverged(Project *);
215215

216216
void startflowbalance(Project *);
217217
void updateflowbalance(Project *, long);
218-
void endflowbalance(Project *);
218+
void endflowbalance(Project *, long);
219219

220220
#endif

src/hydraul.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ int nexthyd(Project *pr, long *tstep)
243243
Hydraul *hyd = &pr->hydraul;
244244
Times *time = &pr->times;
245245

246+
long tNow = time->Htime;
246247
long hydstep; // Actual time step
247248
int errcode = 0; // Error code
248249

@@ -280,7 +281,7 @@ int nexthyd(Project *pr, long *tstep)
280281
// No more time remains - force completion of analysis
281282
else
282283
{
283-
endflowbalance(pr);
284+
endflowbalance(pr, tNow);
284285
if (pr->report.Statflag) writeflowbalance(pr);
285286
time->Htime++;
286287
if (pr->quality.OpenQflag) time->Qtime++;

0 commit comments

Comments
 (0)