Skip to content

Commit 313d00c

Browse files
author
Cinzia Mazzetti
committed
mct using average discharge and closing water balance on catchment
1 parent 36aecd5 commit 313d00c

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

src/lisflood/Lisflood_dynamic.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ def splitlanduse(array1, array2=None, array3=None):
218218

219219
self.ChanQAvg = self.sumDisDay/self.NoRoutSteps
220220
# Average channel outflow over the model computation step
221-
# NOT the same as ChanQ even when if using only one routing sub-step
222221

223222

224223
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -230,12 +229,14 @@ def splitlanduse(array1, array2=None, array3=None):
230229
# Set water level dynamic wave to dummy value (needed
231230

232231
if option['InitLisflood'] or option['repAverageDis']:
233-
self.CumQ += self.ChanQ
232+
# self.CumQ += self.ChanQ
233+
self.CumQ += self.ChanQAvg
234234
#cmcheck - we should use ChanQAvg here not ChanQ
235235
self.avgdis = self.CumQ/self.TimeSinceStart
236236
# to calculate average discharge over the entire simulation
237237

238-
self.DischargeM3Out += np.where(self.AtLastPointC ,self.ChanQ * self.DtSec,0)
238+
#self.DischargeM3Out += np.where(self.AtLastPointC ,self.ChanQ * self.DtSec,0)
239+
self.DischargeM3Out += np.where(self.AtLastPointC, self.ChanQAvg * self.DtSec, 0)
239240
# Cumulative outflow out of map
240241
# cmcheck - we should use ChanQAvg here not ChanQ
241242

src/lisflood/Lisflood_initial.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ def __init__(self):
234234

235235
# initialise averaged discharge
236236
maskinfo = MaskInfo.instance()
237-
238-
#cmcheck - now it's a state variable and it's initialised elsewhere
239-
# self.ChanQAvg = maskinfo.in_zero()
237+
self.ChanQAvg = maskinfo.in_zero()
240238

241239
# initialise outputs once everything is set
242240
self.output_module.initial()

src/lisflood/hydrological_modules/routing.py

+28-27
Original file line numberDiff line numberDiff line change
@@ -380,20 +380,19 @@ def initial(self):
380380
# Here it becomes Outflow (x+dx) Q at the beginning of the computation step (t) for full section (instant)
381381
# Used to calculated Inflow (x) from upstream pixels at the beginning of the computation step (t)
382382
self.var.ChanQ = np.where(PrevDischarge == -9999, self.var.ChanQKin, PrevDischarge) #np
383-
# Initialise channel discharge: cold start: equal to ChanQKin [m3/s]
383+
# Initialise instantaneous channel discharge: cold start: equal to ChanQKin [m3/s]
384384

385385
# # cmcheck - deve diventare una variabile di stato
386386
# PrevAvgDischarge = loadmap('DischargeMaps')
387-
# self.var.ChanQAvg = np.where(PrevAvgDischarge == -9999, maskinfo.in_zero(), PrevAvgDischarge) #np
387+
# self.var.ChanQAvgDt = np.where(PrevAvgDischarge == -9999, maskinfo.in_zero(), PrevAvgDischarge) #np
388388
# cmcheck - per adesso
389389
self.var.ChanQAvgDt = maskinfo.in_zero()
390-
391-
# Average channel outflow (x+dx) from channels during previous model computation step (dt)
390+
# Initialise average channel outflow (x+dx) from channels during previous model computation step (dt)
392391

393392
# cmcheck
394393
ChanQAvgDtPcr = decompress(self.var.ChanQAvgDt) # pcr
395394
self.var.ChanQAvgInDt = compressArray(upstream(self.var.LddChan, ChanQAvgDtPcr))
396-
# Average channel inflow (x) from channels for next model computation step (dt)
395+
# Initialise average channel inflow (x) from channels for next model computation step (dt)
397396
# Using LddChan here because we need all pixels upstream, kin and mct
398397

399398

@@ -706,21 +705,23 @@ def dynamic(self, NoRoutingExecuted):
706705
# Outflow (x+dx) at time t beginning of calculation step (instant)
707706
# This is used to calculate inflow from upstream cells
708707

709-
# ChanM3KinStart = self.var.ChanM3Kin.copy()
708+
ChanM3KinStart = self.var.ChanM3Kin.copy()
710709
# Channel storage at time t beginning of calculation step (instant)
711710

712711
ChanQKinOutEnd,ChanM3KinEnd = self.KINRouting(ChanQKinOutStart,SideflowChan)
713712
# Outflow (x+dx) at time t+dt end of calculation step (instant)
714713
# Channel storage at time t+dt end of calculation step (instant)
714+
# This is in fact the same as the average outflow -> from some feature in kinematic routing function
715715

716716
# cmcheck
717-
self.var.ChanQAvgDt = (self.var.ChanQAvgInDt * self.var.DtRouting + SideflowChanM3 - ChanM3KinEnd + self.var.ChanM3) * self.var.InvDtRouting
717+
# Calculate average outflow using water balance for channel grid cell over sub-routing step
718+
self.var.ChanQAvgDt = (self.var.ChanQAvgInDt * self.var.DtRouting + SideflowChanM3 - ChanM3KinEnd + ChanM3KinStart) * self.var.InvDtRouting
718719
# if np.any(self.var.ChanQAvgDt < 0):
719720
# print("At least one value is less than 0.")
720721
self.var.ChanQAvgDt[self.var.ChanQAvgDt < 0] = 0
721722
# Average outflow (x+dx) QAvg during routing step (average)
722-
# Qout_avg = Qin_avg -(Vend - Vini)
723-
723+
# Qout_avg = Qin_avg -(Vend - Vstart)/DtRouting
724+
# Qin_avg = Qin_avg_channels + Qin_avg_sideflow
724725

725726
# updating variables for next routing step
726727
self.var.ChanQKin = ChanQKinOutEnd.copy()
@@ -735,15 +736,16 @@ def dynamic(self, NoRoutingExecuted):
735736
# Channel storage V at the end of computation step t+dt for full section (instant)
736737
# same as ChanM3KinEnd for Kinematic routing only
737738

738-
# Update average channel inflow (x) Qavg for next step
739-
ChanQAvgInDt = decompress(self.var.ChanQAvgDt) # pcr
740-
self.var.ChanQAvgInDt = compressArray(upstream(self.var.LddChan, ChanQAvgInDt))
739+
# Update average channel inflow (x) Qavg for next sub-routing step
740+
ChanQAvgDtPcr = decompress(self.var.ChanQAvgDt) # pcr
741+
self.var.ChanQAvgInDt = compressArray(upstream(self.var.LddChan, ChanQAvgDtPcr))
741742

742743
# self.var.sumDisDay += self.var.ChanQ
743744
# # sum of total river outflow on model sub-step
744745

745746
self.var.sumDisDay += self.var.ChanQAvgDt
746-
# sum of average river outflow on model routing sub-step
747+
# sum of average river outflow on routing sub-step
748+
# used for calculating average discharge on model time step
747749

748750

749751
# SPLIT ROUTING - no InitLisfllod
@@ -775,29 +777,27 @@ def dynamic(self, NoRoutingExecuted):
775777

776778
if not (option['SplitRouting']):
777779
# Kinematic routing
780+
# This is calculated for every grid cell, including MCT grid cells
778781

779782
ChanQKinOutStart = self.var.ChanQ.copy()
780783
# Outflow (x+dx) Q at time t beginning of calculation step (instant)
784+
# This is used to calculate inflow from upstream cells
781785

782786
ChanM3KinStart = self.var.ChanM3.copy()
783-
784-
# ChanM3KinStart = self.var.ChanM3.copy()
785-
# Channel storage at time t (instant)
787+
# Channel storage at time t beginning of calculation step (instant)
786788

787789
ChanQKinOutEnd,ChanM3KinEnd = self.KINRouting(ChanQKinOutStart,SideflowChan)
788790
# Outflow at time t+dt end of calculation step (instant)
789791
# Channel storage at time t+dt end of calculation step (instant)
790-
792+
# This is in fact the same as the average outflow -> from some feature in kinematic routing function
791793

792794
# cmcheck
793-
794-
# cal average outflow discharge for channels during routing sub step dt
795-
795+
# Calculate average outflow using water balance for channel grid cell
796796
ChanQKinAvgDt = (self.var.ChanQAvgInDt * self.var.DtRouting + SideflowChanM3 - ChanM3KinEnd + ChanM3KinStart) * self.var.InvDtRouting
797797
# if np.any(self.var.ChanQAvgDt < 0):
798798
# print("At least one value is less than 0.")
799799
ChanQKinAvgDt[ChanQKinAvgDt < 0] = 0
800-
# Average outflow (x+dx) QAvg during routing step (average)
800+
# Average outflow (x+dx) QAvg during sub-routing step (average)
801801
# Qout_avg = Qin_avg -(Vend - Vini)
802802

803803

@@ -822,7 +822,7 @@ def dynamic(self, NoRoutingExecuted):
822822
# MCT routing
823823

824824
ChanQMCTOutStart = self.var.ChanQ.copy()
825-
# Outflow (x+dx) at time t q10 (instant)
825+
# Outflow (x+dx) at time t (instant) q10
826826

827827
# debug
828828
# ChanQKinOutEnd[ChanQKinOutEnd != 0] = 0
@@ -832,7 +832,7 @@ def dynamic(self, NoRoutingExecuted):
832832
# Channel storage at time t V00
833833

834834
ChanQMCTInStart = self.var.PrevQMCTin.copy()
835-
# Inflow (x) at time t instant (instant)
835+
# Inflow (x) at time t instant (instant) q00
836836
# This is coming from upstream pixels
837837

838838
# calling MCT routing
@@ -842,10 +842,11 @@ def dynamic(self, NoRoutingExecuted):
842842
# Channel storage at time t+dt end of calculation step (instant)
843843

844844

845-
# # update input (x) Q at t for next step (instant)
846-
# ChanQMCTStartPcr = decompress(ChanQMCTOutStart) # pcr
847-
# self.var.PrevQMCTin = compressArray(upstream(self.var.LddChan, ChanQMCTStartPcr))
845+
# # update input (x) Q at t for next step (instant) q10 -> q00
846+
# ChanQMCTOutStartPcr = decompress(ChanQMCTOutStart) # pcr
847+
# self.var.PrevQMCTin = compressArray(upstream(self.var.LddChan, ChanQMCTOutStartPcr))
848848
# # using LddChan here because we need to input from upstream pixels to include kinematic pixels
849+
# update input (x) Q at t for next step (instant)
849850

850851

851852
# Storing MCT Courant and Reynolds numbers for state files
@@ -855,6 +856,7 @@ def dynamic(self, NoRoutingExecuted):
855856
# cmcheck
856857

857858
# calc average discharge outflow for MCT channels during routing sub step dt
859+
# Calculate average outflow using water balance for MCT channel grid cell over sub-routing step
858860
# ChanQMCTAvgDt = (self.var.ChanQAvgInDt * self.var.DtRouting + SideflowChanMCT * self.var.DtRouting - ChanM3MCTEnd + ChanM3MCTStart) * self.var.InvDtRouting
859861
ChanQMCTAvgDt = np.where(self.var.IsChannelKinematic, 0., (
860862
self.var.ChanQAvgInDt * self.var.DtRouting + SideflowChanMCT * self.var.DtRouting - ChanM3MCTEnd + ChanM3MCTStart) * self.var.InvDtRouting)
@@ -884,7 +886,6 @@ def dynamic(self, NoRoutingExecuted):
884886
self.var.PrevQMCTin = compressArray(upstream(self.var.LddChan, ChanQMCTStartPcr))
885887
# using LddChan here because we need to input from upstream pixels to include kinematic pixels
886888

887-
888889
# Update average channel inflow (x) Qavg for next step
889890
ChanQAvgInDtPcr = decompress(self.var.ChanQAvgDt) # pcr
890891
self.var.ChanQAvgInDt = compressArray(upstream(self.var.LddChan, ChanQAvgInDtPcr))

src/lisflood/hydrological_modules/waterbalance.py

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ def dynamic(self):
213213

214214
##sum1 = self.var.sumDis.copy()
215215
sum1 = self.var.ChanQAvg.copy()
216+
# averge outflow during model time step
216217
sum1[self.var.AtLastPointC == 0] = 0
217218
WaterOut = np.take(np.bincount(self.var.Catchments,weights=sum1 * self.var.DtSec),self.var.Catchments)
218219
# Water that goes out of the system at the channels level [m3]

0 commit comments

Comments
 (0)