-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check lake balance #330
Merged
Merged
Check lake balance #330
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8c98969
Limit lake evaporation
vers-w b125707
Limit reservoir evaporation
vers-w 38b06a8
Update tests (lake and reservoir)
vers-w 2c15451
Limit lake outflow and solution Modified Puls approach
vers-w 25b6f33
Add parameter `actevap` to docs
vers-w 02ea9ce
Small refactoring (limit lake outflow)
vers-w 3fa3e16
Update changelog
vers-w 162b769
Fix limit outflow for lakes with threshold
vers-w 894c811
Merge branch 'master' into check_lake_balance
vers-w b24bde1
Address review comments
vers-w File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,7 @@ | |||||
demandrelease::Vector{T} | "m3 s-1" # minimum (environmental) flow released from reservoir [m³ s⁻¹] | ||||||
precipitation::Vector{T} # average precipitation for reservoir area [mm Δt⁻¹] | ||||||
evaporation::Vector{T} # average evaporation for reservoir area [mm Δt⁻¹] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
actevap::Vector{T} # average actual evaporation for reservoir area [mm Δt⁻¹] | ||||||
|
||||||
function SimpleReservoir{T}(args...) where {T} | ||||||
equal_size_vectors(args) | ||||||
|
@@ -148,6 +149,7 @@ function initialize_simple_reservoir(config, nc, inds_riv, nriv, pits, Δt) | |||||
demandrelease = fill(mv, n), | ||||||
precipitation = fill(mv, n), | ||||||
evaporation = fill(mv, n), | ||||||
actevap = fill(mv, n), | ||||||
) | ||||||
|
||||||
return reservoirs, | ||||||
|
@@ -168,15 +170,14 @@ element rather than all at once. | |||||
""" | ||||||
function update(res::SimpleReservoir, i, inflow, timestepsecs) | ||||||
|
||||||
vol = max( | ||||||
0.0, | ||||||
( | ||||||
res.volume[i] + | ||||||
(inflow * timestepsecs) + | ||||||
(res.precipitation[i] * (timestepsecs / res.Δt) / 1000.0) * res.area[i] - | ||||||
(res.evaporation[i] * (timestepsecs / res.Δt) / 1000.0) * res.area[i] | ||||||
), | ||||||
) | ||||||
# limit lake evaporation based on total available volume [m³] | ||||||
precipitation = 0.001 * res.precipitation[i] * (timestepsecs / res.Δt) * res.area[i] | ||||||
available_volume = res.volume[i] + inflow * timestepsecs + precipitation | ||||||
evap = 0.001 * res.evaporation[i] * (timestepsecs / res.Δt) * res.area[i] | ||||||
actevap = min(available_volume, evap) # [m³/timestepsecs] | ||||||
|
||||||
vol = res.volume[i] + (inflow * timestepsecs) + precipitation - actevap | ||||||
vol = max(vol, 0.0) | ||||||
|
||||||
percfull = vol / res.maxvolume[i] | ||||||
# first determine minimum (environmental) flow using a simple sigmoid curve to scale for target level | ||||||
|
@@ -199,6 +200,7 @@ function update(res::SimpleReservoir, i, inflow, timestepsecs) | |||||
res.demandrelease[i] = demandrelease / timestepsecs | ||||||
res.percfull[i] = percfull | ||||||
res.volume[i] = vol | ||||||
res.actevap[i] += 1000.0 * (actevap / res.area[i]) | ||||||
|
||||||
return res | ||||||
end | ||||||
|
@@ -222,6 +224,7 @@ end | |||||
totaloutflow::Vector{T} | "m3" # total outflow lake [m³] | ||||||
precipitation::Vector{T} # average precipitation for lake area [mm Δt⁻¹] | ||||||
evaporation::Vector{T} # average evaporation for lake area [mm Δt⁻¹] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
actevap::Vector{T} # average actual evapotranspiration for lake area [mm Δt⁻¹] | ||||||
|
||||||
function Lake{T}(args...) where {T} | ||||||
equal_size_vectors(args) | ||||||
|
@@ -415,6 +418,7 @@ function initialize_lake(config, nc, inds_riv, nriv, pits, Δt) | |||||
totaloutflow = fill(mv, n), | ||||||
precipitation = fill(mv, n), | ||||||
evaporation = fill(mv, n), | ||||||
actevap = fill(mv, n), | ||||||
) | ||||||
|
||||||
return lakes, | ||||||
|
@@ -495,31 +499,33 @@ function update(lake::Lake, i, inflow, doy, timestepsecs) | |||||
lo = lake.lowerlake_ind[i] | ||||||
has_lowerlake = lo != 0 | ||||||
|
||||||
# limit lake evaporation based on total available volume [m³] | ||||||
precipitation = 0.001 * lake.precipitation[i] * (timestepsecs / lake.Δt) * lake.area[i] | ||||||
available_volume = lake.storage[i] + inflow * timestepsecs + precipitation | ||||||
evap = 0.001 * lake.evaporation[i] * (timestepsecs / lake.Δt) * lake.area[i] | ||||||
actevap = min(available_volume, evap) # [m³/timestepsecs] | ||||||
|
||||||
### Modified Puls Approach (Burek et al., 2013, LISFLOOD) ### | ||||||
# outflowfunc = 3 | ||||||
# Calculate lake factor and SI parameter | ||||||
if lake.outflowfunc[i] == 3 | ||||||
lakefactor = lake.area[i] / (timestepsecs * pow(lake.b[i], 0.5)) | ||||||
si_factor = | ||||||
( | ||||||
lake.storage[i] + | ||||||
(lake.precipitation[i] - lake.evaporation[i]) * | ||||||
(timestepsecs / lake.Δt) * | ||||||
lake.area[i] / 1000.0 | ||||||
) / timestepsecs + inflow | ||||||
#Adjust SIFactor for ResThreshold != 0 | ||||||
si_factor = (lake.storage[i] + precipitation - actevap) / timestepsecs + inflow | ||||||
# Adjust SIFactor for ResThreshold != 0 | ||||||
si_factor_adj = si_factor - lake.area[i] * lake.threshold[i] / timestepsecs | ||||||
#Calculate the new lake outflow/waterlevel/storage | ||||||
|
||||||
# Calculate the new lake outflow/waterlevel/storage | ||||||
if si_factor_adj > 0.0 | ||||||
outflow = pow( | ||||||
0.5 * | ||||||
(-lakefactor + pow((pow(lakefactor, 2.0) + 4.0 * si_factor_adj), 0.5)), | ||||||
2.0, | ||||||
) | ||||||
quadratic_sol_term = | ||||||
-lakefactor + pow((pow(lakefactor, 2.0) + 4.0 * si_factor_adj), 0.5) | ||||||
if quadratic_sol_term > 0.0 | ||||||
outflow = pow(0.5 * quadratic_sol_term, 2.0) | ||||||
else | ||||||
outflow = 0.0 | ||||||
end | ||||||
else | ||||||
outflow = 0.0 | ||||||
end | ||||||
outflow = min(outflow, si_factor) | ||||||
storage = (si_factor - outflow) * timestepsecs | ||||||
waterlevel = storage / lake.area[i] | ||||||
end | ||||||
|
@@ -529,35 +535,33 @@ function update(lake::Lake, i, inflow, doy, timestepsecs) | |||||
|
||||||
diff_wl = has_lowerlake ? lake.waterlevel[i] - lake.waterlevel[lo] : 0.0 | ||||||
|
||||||
storage_input = (lake.storage[i] + precipitation - actevap) / timestepsecs + inflow | ||||||
if lake.outflowfunc[i] == 1 | ||||||
outflow = | ||||||
interpolate_linear(lake.waterlevel[i], lake.hq[i].H, lake.hq[i].Q[:, doy]) | ||||||
outflow = min(outflow, storage_input) | ||||||
else | ||||||
if diff_wl >= 0.0 | ||||||
if lake.waterlevel[i] > lake.threshold[i] | ||||||
outflow = | ||||||
lake.b[i] * pow((lake.waterlevel[i] - lake.threshold[i]), lake.e[i]) | ||||||
Δh = lake.waterlevel[i] - lake.threshold[i] | ||||||
outflow = lake.b[i] * pow(Δh, lake.e[i]) | ||||||
maxflow = (Δh * lake.area[i]) / timestepsecs | ||||||
outflow = min(outflow, maxflow) | ||||||
else | ||||||
outflow = Float(0) | ||||||
end | ||||||
else | ||||||
if lake.waterlevel[lo] > lake.threshold[i] | ||||||
outflow = | ||||||
-1.0 * | ||||||
lake.b[i] * | ||||||
pow((lake.waterlevel[lo] - lake.threshold[i]), lake.e[i]) | ||||||
Δh = lake.waterlevel[lo] - lake.threshold[i] | ||||||
outflow = -1.0 * lake.b[i] * pow(Δh, lake.e[i]) | ||||||
maxflow = (Δh * lake.area[lo]) / timestepsecs | ||||||
outflow = max(outflow, -maxflow) | ||||||
else | ||||||
outflow = Float(0) | ||||||
end | ||||||
end | ||||||
end | ||||||
|
||||||
storage = | ||||||
lake.storage[i] + | ||||||
inflow * timestepsecs + | ||||||
(lake.precipitation[i] / 1000.0) * (timestepsecs / lake.Δt) * lake.area[i] - | ||||||
(lake.evaporation[i] / 1000.0) * (timestepsecs / lake.Δt) * lake.area[i] - | ||||||
outflow * timestepsecs | ||||||
storage = (storage_input - outflow) * timestepsecs | ||||||
|
||||||
# update storage and outflow for lake with rating curve of type 1. | ||||||
if lake.outflowfunc[i] == 1 | ||||||
|
@@ -584,6 +588,7 @@ function update(lake::Lake, i, inflow, doy, timestepsecs) | |||||
|
||||||
# update values for the lower lake in place | ||||||
lake.outflow[lo] = -outflow | ||||||
lake.totaloutflow[lo] += -outflow * timestepsecs | ||||||
lake.storage[lo] = lowerlake_storage | ||||||
lake.waterlevel[lo] = lowerlake_waterlevel | ||||||
end | ||||||
|
@@ -596,6 +601,7 @@ function update(lake::Lake, i, inflow, doy, timestepsecs) | |||||
lake.inflow[i] += inflow * timestepsecs | ||||||
lake.totaloutflow[i] += outflow * timestepsecs | ||||||
lake.storage[i] = storage | ||||||
lake.actevap[i] += 1000.0 * (actevap / lake.area[i]) | ||||||
|
||||||
return lake | ||||||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.