Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
- Use `divrem` for computing `steps` in `BMI.update_until` function. The remainder `rem` is used to throw an error message.
- take the for loop in function `BMI.update_until` out of the conditional block.

Co-authored-by: Carlos Fernando Baptista <[email protected]>
  • Loading branch information
vers-w and CFBaptista committed Apr 15, 2024
1 parent 97f7690 commit da8948c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ end
function BMI.update_until(model::Model, time::Float64)
@unpack clock, network, config = model
t = BMI.get_current_time(model)
steps = (time - t) / model.clock.Δt.value
_div, _rem = divrem(time - t, model.clock.Δt.value)
steps = Int(_div)
if steps < 0
error("The current model timestamp $t is larger than provided `time` $time")
elseif !isinteger(steps)
elseif abs(_rem) > eps()
error_message = string(
"Provided `time` $time minus the current model timestamp $t",
" is not an integer multiple of model time step $(model.clock.Δt.value)",
)
error(error_message)
else
for _ = 1:steps
model = run_timestep(model)
end
end
for _ = 1:steps
model = run_timestep(model)
end
return model
end
Expand Down

0 comments on commit da8948c

Please sign in to comment.