diff --git a/docs/src/changelog.md b/docs/src/changelog.md index c2bbf7a49..c14da9a0c 100644 --- a/docs/src/changelog.md +++ b/docs/src/changelog.md @@ -5,10 +5,12 @@ 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 +## [unreleased] ### Fixed - +- Added missing BMI function `get_grid_size`, it is used for unstructured grids, for example + to get the length of arrays returned by BMI functions `get_grid_x` and `get_grid_y`. + ### Changed ### Added diff --git a/src/bmi.jl b/src/bmi.jl index 3f0c71979..0ef6e574a 100644 --- a/src/bmi.jl +++ b/src/bmi.jl @@ -338,6 +338,10 @@ function BMI.get_grid_node_count(model::Model, grid::Int) return length(active_indices(model.network, grids[grid])) end +function BMI.get_grid_size(model::Model, grid::Int) + return length(active_indices(model.network, grids[grid])) +end + function BMI.get_grid_edge_count(model::Model, grid::Int) @unpack network = model if grid == 4 diff --git a/test/bmi.jl b/test/bmi.jl index 979ff6284..36154e1b6 100644 --- a/test/bmi.jl +++ b/test/bmi.jl @@ -90,6 +90,10 @@ tomlpath = joinpath(@__DIR__, "sbm_config.toml") @test BMI.get_grid_node_count(model, 4) == 5809 @test BMI.get_grid_node_count(model, 5) == 50063 @test BMI.get_grid_node_count(model, 6) == 50063 + @test BMI.get_grid_size(model, 1) == 2 + @test BMI.get_grid_size(model, 4) == 5809 + @test BMI.get_grid_size(model, 5) == 50063 + @test BMI.get_grid_size(model, 6) == 50063 @test minimum(BMI.get_grid_x(model, 5, zeros(Float, 50063))) ≈ 5.426666666666667f0 @test maximum(BMI.get_grid_x(model, 5, zeros(Float, 50063))) ≈