Skip to content

Commit

Permalink
use flattened, one-dimensional arrays (#5)
Browse files Browse the repository at this point in the history
This addresses the following point from the [BMI best practices](https://bmi.readthedocs.io/en/latest/bmi.best_practices.html#best-practices)

> BMI functions always use flattened, one-dimensional arrays. This avoids any issues stemming from row/column-major indexing when coupling models written in different languages. It’s the developer’s responsibility to ensure that array information is flattened/redimensionalized in the correct order.

As long as you stay in Julia this difference doesn't matter much since Julia supports linear indexing, e.g. `array[3,1] == array[3]`. But @BSchilperoort pointed out this is not the case when doing interop with e.g. numpy.
  • Loading branch information
visr authored Oct 10, 2023
1 parent 8e512ee commit 80c34b4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ BMI.get_var_grid(m::Model, name) = hasvar(name) && 0
BMI.get_grid_rank(m::Model, grid) = hasgrid(grid) && ndims(m.temperature)
BMI.get_grid_size(m::Model, grid) = hasgrid(grid) && length(m.temperature)

BMI.get_value_ptr(m::Model, name) = hasvar(name) && m.temperature
BMI.get_value_ptr(m::Model, name) = hasvar(name) && vec(m.temperature)

function BMI.get_value(m::Model, name, dest)
val = BMI.get_value_ptr(m, name)
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Aqua
@testset "initialize from defaults" begin
m = BMI.initialize(Heat.Model)
z0 = BMI.get_value_ptr(m, "plate_surface__temperature")
@test ndims(z0) == 1
@test z0 == vec(m.temperature)
@test all(z0 .>= 0)
@test all(z0 .< 1)
end
Expand Down

0 comments on commit 80c34b4

Please sign in to comment.