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

Fix BMI.update_until (InexactError: Int64) #387

Merged
merged 8 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 3 additions & 2 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- For the computation of Gash interception model parameter `e_r` multiply the precipitation
input with the canopy fraction (this was only done for the potential evapotranspiration
input).


- `BMI.update_until` could throw an `InexactError: Int64` caused by a not whole number. This
is fixed by applying `round()`.

### Changed
- Stop exposing scalar variables through BMI. The `BMI.get_value_ptr` function was not
working correctly for scalar model variables (a `view` was applied). Only a few scalar
Expand Down
18 changes: 14 additions & 4 deletions src/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,20 @@ end

function BMI.update_until(model::Model, time::Float64)
@unpack clock, network, config = model
curtime = BMI.get_current_time(model)
n = Int(max(0, (time - curtime) / model.clock.Δt.value))
for _ = 1:n
model = run_timestep(model)
t = BMI.get_current_time(model)
steps = (time - t) / model.clock.Δt.value
verseve marked this conversation as resolved.
Show resolved Hide resolved
if steps < 0
error("The current model timestamp $t is larger than provided `time` $time")
elseif !isinteger(steps)
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)
verseve marked this conversation as resolved.
Show resolved Hide resolved
else
for _ = 1:steps
model = run_timestep(model)
end
verseve marked this conversation as resolved.
Show resolved Hide resolved
end
return model
end
Expand Down
Loading