Mercurial > repos > public > sbplib_julia
diff src/Grids/tensor_grid.jl @ 1388:c0208286234e bugfix/grids/complete_interface_impl
Add `grid_and_local_dim_index`
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 15 Aug 2023 22:11:20 +0200 |
parents | 42ecd4b3e215 |
children | 47931bef8471 |
line wrap: on
line diff
--- a/src/Grids/tensor_grid.jl Tue Aug 15 21:20:29 2023 +0200 +++ b/src/Grids/tensor_grid.jl Tue Aug 15 22:11:20 2023 +0200 @@ -97,3 +97,20 @@ function combine_coordinates(coords...) return mapreduce(SVector, vcat, coords) end + +""" + grid_and_local_dim_index(nds, d) + +Given a tuple of number of dimensions `nds`, and a global dimension `d`, +calculate which grid index and local dimension `d` corresponds to. +""" +function grid_and_local_dim_index(nds, d) + I = findfirst(>=(d), cumsum(nds)) + + if I == 1 + return (1, d) + else + return (I, d-cumsum(nds)[I-1]) + end + # TBD: Is there a cleaner way to compute this? +end