From 4c4d479f0d0b5e50eeb5d4016a7f81d82582cc5c Mon Sep 17 00:00:00 2001 From: Stuart Daines Date: Thu, 5 Dec 2024 14:38:46 +0000 Subject: [PATCH] Allow get_region(grid::UnstructuredVectorGrid, values) for a single-cell 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) --- src/Grids.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Grids.jl b/src/Grids.jl index 8a1c89e..7b33d68 100644 --- a/src/Grids.jl +++ b/src/Grids.jl @@ -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 @@ -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