Skip to content

Commit

Permalink
Replace squares and square roots
Browse files Browse the repository at this point in the history
For faster alternatives
  • Loading branch information
visr committed Oct 2, 2024
1 parent a945721 commit fe2fc8a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/reservoir_lake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,16 @@ function update(lake::Lake, i, inflow, doy, timestepsecs)
# outflowfunc = 3
# Calculate lake factor and SI parameter
if lake.outflowfunc[i] == 3
lakefactor = lake.area[i] / (timestepsecs * pow(lake.b[i], 0.5))
lakefactor = lake.area[i] / (timestepsecs * sqrt(lake.b[i]))
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
if si_factor_adj > 0.0
quadratic_sol_term =
-lakefactor + pow((pow(lakefactor, 2.0) + 4.0 * si_factor_adj), 0.5)
-lakefactor + sqrt(lakefactor^2 + 4.0 * si_factor_adj)
if quadratic_sol_term > 0.0
outflow = pow(0.5 * quadratic_sol_term, 2.0)
outflow = 0.5 * quadratic_sol_term^2
else
outflow = 0.0
end
Expand Down

0 comments on commit fe2fc8a

Please sign in to comment.