Skip to content
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

Update vertical fluxes all at once #1433

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions core/src/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,7 @@ function update_basin(integrator)::Nothing
set_table_row!(table, row, i)
end

for (i, id) in enumerate(basin.node_id)
update_vertical_flux!(basin, storage, i)
end
update_vertical_flux!(basin, storage)

# Forget about vertical fluxes to handle discontinuous forcing from basin_update
copyto!(vertical_flux_prev, vertical_flux)
Expand Down
42 changes: 22 additions & 20 deletions core/src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,31 @@ end
Smoothly let the evaporation flux go to 0 when at small water depths
Currently at less than 0.1 m.
"""
function update_vertical_flux!(basin::Basin, storage::AbstractVector, i::Int)::Nothing
function update_vertical_flux!(basin::Basin, storage::AbstractVector)::Nothing
(; current_level, current_area, vertical_flux_from_input, vertical_flux) = basin
current_level = get_tmp(current_level, storage)
current_area = get_tmp(current_area, storage)
vertical_flux = get_tmp(vertical_flux, storage)

level = current_level[i]
area = current_area[i]

bottom = basin.level[i][1]
fixed_area = basin.area[i][end]
depth = max(level - bottom, 0.0)
factor = reduction_factor(depth, 0.1)

precipitation = fixed_area * vertical_flux_from_input.precipitation[i]
evaporation = area * factor * vertical_flux_from_input.potential_evaporation[i]
drainage = vertical_flux_from_input.drainage[i]
infiltration = factor * vertical_flux_from_input.infiltration[i]

vertical_flux.precipitation[i] = precipitation
vertical_flux.evaporation[i] = evaporation
vertical_flux.drainage[i] = drainage
vertical_flux.infiltration[i] = infiltration
for (i, id) in enumerate(basin.node_id)
level = current_level[i]
area = current_area[i]

bottom = basin.level[i][1]
fixed_area = basin.area[i][end]
depth = max(level - bottom, 0.0)
factor = reduction_factor(depth, 0.1)

precipitation = fixed_area * vertical_flux_from_input.precipitation[i]
evaporation = area * factor * vertical_flux_from_input.potential_evaporation[i]
drainage = vertical_flux_from_input.drainage[i]
infiltration = factor * vertical_flux_from_input.infiltration[i]

vertical_flux.precipitation[i] = precipitation
vertical_flux.evaporation[i] = evaporation
vertical_flux.drainage[i] = drainage
vertical_flux.infiltration[i] = infiltration
end

return nothing
end
Expand All @@ -83,9 +85,9 @@ function formulate_basins!(
basin::Basin,
storage::AbstractVector,
)::Nothing
update_vertical_flux!(basin, storage)
for (i, id) in enumerate(basin.node_id)
# add all precipitation that falls within the profile
update_vertical_flux!(basin, storage, i)
# add all vertical fluxes that enter the Basin
du.storage[i] += get_influx(basin, i)
end
return nothing
Expand Down
Loading