Skip to content

Commit ef1dfc3

Browse files
author
Cinzia Mazzetti
committed
q1mm>eps to avoid instability and mass balance errors
1 parent 0d932f0 commit ef1dfc3

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

src/lisflood/hydrological_modules/routing.py

+26-17
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ def MCTRoutingLoop(self,ChanQMCTOutStart,ChanQMCTInStart,ChanQKinOut,ChanQKinOut
12731273
# q01[idpix] = eps
12741274

12751275
### calling MCT function for single cell
1276-
q11[idpix], V11[idpix], Cm0[idpix], Dm0[idpix] = self.MCTRouting_single(V00[idpix],q10[idpix], q01[idpix], q00[idpix], ql[idpix], Cm0[idpix], Dm0[idpix],
1276+
q11[idpix], V11[idpix],q1m[idpix], Cm0[idpix], Dm0[idpix] = self.MCTRouting_single(V00[idpix],q10[idpix], q01[idpix], q00[idpix], ql[idpix],q0m[idpix], Cm0[idpix], Dm0[idpix],
12771277
dt, xpix[idpix], s0[idpix], Balv[idpix], ANalv[idpix], Nalv[idpix])
12781278

12791279
# # cmcheck - tanto entra tanto esce
@@ -1282,19 +1282,17 @@ def MCTRoutingLoop(self,ChanQMCTOutStart,ChanQMCTInStart,ChanQKinOut,ChanQKinOut
12821282
# # Set outflow to be the same as inflow in MCT grid cells ('tanto entra tanto esce')
12831283
# V11[idpix] = V00[idpix]
12841284
# # Set end volume to be the same as initial volume in MCT grid cells ('tanto entra tanto esce')
1285-
# V11[idpix] = V00[idpix] + q01[idpix] + ql[idpix] - q11[idpix]
1286-
1287-
1288-
### calc integration on the control volume (pixel)
1289-
# calc average discharge outflow q1m for MCT channels during routing sub step dt
1290-
# Calculate average outflow using water balance for MCT channel grid cell over sub-routing step
1291-
q1m[idpix] = q0m[idpix] + ql[idpix] + (V00[idpix] - V11[idpix]) / dt
1292-
# cmcheck no valori di portata negativi
1293-
if q1m[idpix] < 0.:
1294-
q1m[idpix] = eps
1295-
V11[idpix] = V00[idpix] + (q0m[idpix] + ql[idpix] - q1m[idpix]) * dt
12961285

12971286

1287+
# ### calc integration on the control volume (pixel)
1288+
# moved to routing_single
1289+
# # calc average discharge outflow q1m for MCT channels during routing sub step dt
1290+
# # Calculate average outflow using water balance for MCT channel grid cell over sub-routing step
1291+
# q1m[idpix] = q0m[idpix] + ql[idpix] + (V00[idpix] - V11[idpix]) / dt
1292+
# # cmcheck no valori di portata negativi
1293+
# if q1m[idpix] < 0.:
1294+
# q1m[idpix] = eps
1295+
# V11[idpix] = V00[idpix] + (q0m[idpix] + ql[idpix] - q1m[idpix]) * dt
12981296

12991297

13001298
# Update contribution from upstream pixels at time t+1 (dim=all pixels) using the newly calculated q11
@@ -1346,7 +1344,7 @@ def MCTRoutingLoop(self,ChanQMCTOutStart,ChanQMCTInStart,ChanQKinOut,ChanQKinOut
13461344
return ChanQMCTOutAvg, ChanQMCTOut, ChanM3MCTOut, Cmout, Dmout
13471345

13481346

1349-
def MCTRouting_single(self, V00, q10, q01, q00, ql, Cm0, Dm0, dt, xpix, s0, Balv, ANalv, Nalv):
1347+
def MCTRouting_single(self, V00, q10, q01, q00, ql,q0mm, Cm0, Dm0, dt, xpix, s0, Balv, ANalv, Nalv):
13501348
'''
13511349
This function implements Muskingum-Cunge-Todini routing method for a single channel pixel.
13521350
References:
@@ -1384,7 +1382,7 @@ def MCTRouting_single(self, V00, q10, q01, q00, ql, Cm0, Dm0, dt, xpix, s0, Balv
13841382
# check for negative and zero discharge values
13851383
# zero outflow is not allowed
13861384
if q11 <= 0:
1387-
q11 = 0
1385+
q11 = eps
13881386

13891387
# calc reference discharge at time t
13901388
# qm0 = (I(t)+O(t))/2
@@ -1470,11 +1468,22 @@ def MCTRouting_single(self, V00, q10, q01, q00, ql, Cm0, Dm0, dt, xpix, s0, Balv
14701468
# V11 = k1 * (x1 * q01 + (1. - x1) * q11) # MUST be the same as above!
14711469

14721470

1473-
if (V11 < 0):
1474-
V11 = 0.
1471+
1472+
### calc integration on the control volume (pixel)
1473+
# calc average discharge outflow q1m for MCT channels during routing sub step dt
1474+
# Calculate average outflow using water balance for MCT channel grid cell over sub-routing step
1475+
q1mm = q0mm + ql + (V00 - V11) / dt
1476+
1477+
# cmcheck
1478+
# q1m cannot be too small or it will cause instability
1479+
if q1mm < eps:
1480+
q1mm = eps
1481+
V11 = V00 + (q0mm + ql - q1mm) * dt
1482+
1483+
14751484

14761485
# Outflow at O(t+dt), average outflow in time dt, water volume at t+dt, Courant and Reynolds numbers at t+1 for state files
1477-
return q11, V11, Cm1, Dm1
1486+
return q11, V11, q1mm, Cm1, Dm1
14781487

14791488

14801489
def hoq(self,q,s0,Balv,ANalv,Nalv):

0 commit comments

Comments
 (0)