Skip to content

Commit baf178d

Browse files
author
Cinzia Mazzetti
committedMay 24, 2024·
Solving issue with numbe in discharge_avg in solve1pixel

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed
 

‎src/lisflood/hydrological_modules/kinematic_wave_parallel_tools.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def solve1Pixel(pix, discharge_avg, discharge, lateral_inflow, constant,\
9797
for ups_ix in range(num_upstream_pixels[pix]):
9898
upstream_inflow += discharge[upstream_lookup[pix,ups_ix]]
9999
upstream_inflow_avg += discharge_avg[upstream_lookup[pix, ups_ix]]
100+
100101
const_plus_ups_infl = upstream_inflow + constant[pix] # upstream_inflow + alpha*dx/dt*Qold**beta + dx*specific_lateral_inflow
101102
# If old discharge, upstream inflow and lateral inflow are below accuracy: set discharge to 0 and exit
102103
if const_plus_ups_infl <= NEWTON_TOL:
@@ -122,15 +123,15 @@ def solve1Pixel(pix, discharge_avg, discharge, lateral_inflow, constant,\
122123
if discharge[pix] == NEWTON_TOL:
123124
discharge[pix] = 0
124125

125-
# cmcheck
126-
# avoid negative discharge
127-
if discharge[pix] < 0:
128-
discharge[pix] = 0
129126
# volume of water in channel at end of computation step
130127
channel_volume_end = a_dx * discharge[pix]**beta
128+
131129
# mass water balance to calc average outflow
132-
discharge_avg[pix] = upstream_inflow_avg + lateral_inflow + (channel_volume_start - channel_volume_end) * inv_time_delta
130+
discharge_avg[pix] = upstream_inflow_avg + lateral_inflow[pix] + (channel_volume_start[pix] - channel_volume_end[pix]) * inv_time_delta
133131

132+
# avoid negative average discharge
133+
if discharge_avg[pix] < 0:
134+
discharge_avg[pix] = 0
134135

135136
# to simulate inf or nan: discharge[pix] = 1.0/0.0
136137
# with gil:

‎src/lisflood/hydrological_modules/surface_routing.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ def initial(self):
9494
self.var.OFQOther = ((self.var.OFM3Other * self.var.InvPixelLength * self.var.InvOFAlpha.values[self.var.dim_runoff[1].index('Other')])**(self.var.InvBeta)).astype(float)
9595
self.var.OFQForest = ((self.var.OFM3Forest * self.var.InvPixelLength * self.var.InvOFAlpha.values[self.var.dim_runoff[1].index('Forest')])**(self.var.InvBeta)).astype(float)
9696

97+
# cmcheck
98+
# Initial average overland discharge [m3 s-1]
99+
self.var.OFQDirect_avg = maskinfo.in_zero()
100+
self.var.OFQOther_avg = maskinfo.in_zero()
101+
self.var.OFQForest_avg = maskinfo.in_zero()
102+
97103
def initialSecond(self):
98104
""" 2nd initialisation part of the surface routing module:
99105
to be called after all needed parameters are set (PixelLength, LddToChan, Alpha...)
@@ -148,13 +154,10 @@ def dynamic(self):
148154
SideflowOther = np.sum(self.var.SurfaceRunSoil.values[ilusevalues],self.var.SurfaceRunSoil.dims.index("landuse")) * self.var.MMtoM3 * self.var.InvPixelLength * self.var.InvDtSec
149155
SideflowForest = self.var.SurfaceRunSoil.values[self.var.epic_settings.soil_uses.index('Forest')] * self.var.MMtoM3 * self.var.InvPixelLength * self.var.InvDtSec
150156
# All surface runoff that is generated during current time step added as side flow [m3/s/m pixel-length]
151-
# cmcheck
152-
OFQDirect_avg = 0.
153-
OFQOther_avg = 0.
154-
OFQForest_avg = 0.
155-
self.direct_surface_router.kinematicWaveRouting(OFQDirect_avg,self.var.OFQDirect, SideflowDirect)
156-
self.other_surface_router.kinematicWaveRouting(OFQOther_avg, self.var.OFQOther, SideflowOther)
157-
self.forest_surface_router.kinematicWaveRouting(OFQForest_avg, self.var.OFQForest, SideflowForest)
157+
158+
self.direct_surface_router.kinematicWaveRouting(self.var.OFQDirect_avg,self.var.OFQDirect, SideflowDirect)
159+
self.other_surface_router.kinematicWaveRouting(self.var.OFQOther_avg, self.var.OFQOther, SideflowOther)
160+
self.forest_surface_router.kinematicWaveRouting(self.var.OFQForest_avg, self.var.OFQForest, SideflowForest)
158161

159162
# to PCRASTER
160163

0 commit comments

Comments
 (0)
Please sign in to comment.