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

BMI use simulation starttime as t = 0, not 1970 #246

Merged
merged 3 commits into from
Mar 9, 2023
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
13 changes: 13 additions & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased]

### Fixed
- `BMI.get_time_units` now gets called on the model rather than the type, like all other BMI
functions, except `BMI.initialize`. Also it returns "s" instead of "seconds since
1970-01-01T00:00:00", in line with the BMI specification.

### Changed
- The time values returned in the BMI interface are no longer in seconds since 1970, but in
seconds since the model start time. This is more in line with standard BMI practices.

### Added

## v0.6.3 - 2023-03-01

### Fixed
Expand Down
10 changes: 5 additions & 5 deletions src/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,19 @@ function BMI.get_var_location(model::Model, name::String)
end

function BMI.get_current_time(model::Model)
datetime2unix(reinterpret(DateTime, model.clock.time))
0.001 * Dates.value(model.clock.time - model.config.starttime)
end

function BMI.get_start_time(model::Model)
datetime2unix(DateTime(model.config.starttime))
0.0
end

function BMI.get_end_time(model::Model)
datetime2unix(DateTime(model.config.endtime))
0.001 * Dates.value(model.config.endtime - model.config.starttime)
end

function BMI.get_time_units(::Type{<:Model})
string("seconds since ", unix2datetime(0))
function BMI.get_time_units(model::Model)
"s"
end

function BMI.get_time_step(model::Model)
Expand Down
10 changes: 5 additions & 5 deletions test/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ tomlpath = joinpath(@__DIR__, "sbm_config.toml")
model = BMI.initialize(Wflow.Model, tomlpath)

@testset "initialization and time functions" begin
@test BMI.get_time_units(Wflow.Model) == "seconds since 1970-01-01T00:00:00"
@test BMI.get_time_units(model) == "s"
@test BMI.get_time_step(model) == 86400.0
@test BMI.get_start_time(model) == 9.467712e8
@test BMI.get_current_time(model) == 9.467712e8
@test BMI.get_end_time(model) == 9.493632e8
@test BMI.get_start_time(model) == 0.0
@test BMI.get_current_time(model) == 0.0
@test BMI.get_end_time(model) == 30 * 86400.0
end

@testset "model information functions" begin
Expand Down Expand Up @@ -48,7 +48,7 @@ tomlpath = joinpath(@__DIR__, "sbm_config.toml")
model = BMI.update(model)

@testset "update and get and set functions" begin
@test BMI.get_current_time(model) == 9.468576e8
@test BMI.get_current_time(model) == 86400.0
@test mean(BMI.get_value(model, "vertical.zi")) ≈ 276.3767651555451
@test BMI.get_value_at_indices(model, "lateral.river.q", [1, 100, 5617]) ≈
[0.6211503865184697, 5.219305686635002, 0.026163746306482282]
Expand Down