Skip to content

Commit

Permalink
Allow get_region(grid::UnstructuredVectorGrid, values) for a single-c…
Browse files Browse the repository at this point in the history
…ell grid

Previously, a 'cell=1' argument was required in a call to
    get_region(grid::UnstructuredVectorGrid, values; cell::Union{Int, Symbol})
even if the grid only had 1 cell, which complicates use eg in plot scripts.

This commit adds
    get_region(grid::UnstructuredVectorGrid, values)
for a single-cell grid (grid.ncells == 1)
  • Loading branch information
sjdaines committed Dec 5, 2024
1 parent ce3b97e commit 4c4d479
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Grids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,12 @@ cartesian_to_internal(grid::UnstructuredVectorGrid, griddata::AbstractArray) = g
"""
get_region(grid::UnstructuredVectorGrid, values; cell) ->
values_subset, (dim_subset::NamedDimension, ...)
get_region(grid::UnstructuredVectorGrid, values)
# Keywords for region selection:
- `cell::Union{Int, Symbol}`: an Int, or a Symbol to look up in `cellnames`
`get_region(grid, values)` is also allowed for a single-cell Domain,
"""
function get_region(grid::UnstructuredVectorGrid, values; cell::Union{Int, Symbol})
if cell isa Int
Expand All @@ -295,6 +298,12 @@ function get_region(grid::UnstructuredVectorGrid, values; cell::Union{Int, Symbo
)
end

function get_region(grid::UnstructuredVectorGrid, values)
grid.ncells == 1 || throw(ArgumentError("'cell' argument is required for an UnstructuredVectorGrid with > 1 cell"))

return get_region(grid, values; cell=1)
end

"""
create_default_cellrange(domain, grid::UnstructuredVectorGrid [; operatorID=0]) -> CellRange
Expand Down

0 comments on commit 4c4d479

Please sign in to comment.