Mercurial > repos > public > sbplib_julia
comparison src/Grids/tensor_grid.jl @ 1429:e87f3465b770 feature/grids/curvilinear
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 25 Aug 2023 08:57:27 +0200 |
parents | e82240df974d |
children | 48e16efaac7a 25af92b4a7ea af73340a8f0e e3a80ef08d09 |
comparison
equal
deleted
inserted
replaced
1428:a936b414283a | 1429:e87f3465b770 |
---|---|
110 `nds` would come from broadcasting `ndims` on the grids tuple of a | 110 `nds` would come from broadcasting `ndims` on the grids tuple of a |
111 `TensorGrid`. If you are interested in a dimension `d` of a tensor grid `g` | 111 `TensorGrid`. If you are interested in a dimension `d` of a tensor grid `g` |
112 ```julia | 112 ```julia |
113 gi, ldi = grid_and_local_dim_index(ndims.(g.grids), d) | 113 gi, ldi = grid_and_local_dim_index(ndims.(g.grids), d) |
114 ``` | 114 ``` |
115 tells you which grid it belongs to (`gi`) and wich index it is at within that | 115 tells you which grid it belongs to (`gi`) and which index it is at within that |
116 grid (`ldi`). | 116 grid (`ldi`). |
117 """ | 117 """ |
118 function grid_and_local_dim_index(nds, d) | 118 function grid_and_local_dim_index(nds, d) |
119 I = findfirst(>=(d), cumsum(nds)) | 119 I = findfirst(>=(d), cumsum(nds)) |
120 | 120 |
121 if I == 1 | 121 if I == 1 |
122 return (1, d) | 122 return (1, d) |
123 else | 123 else |
124 return (I, d-cumsum(nds)[I-1]) | 124 return (I, d-cumsum(nds)[I-1]) |
125 end | 125 end |
126 # TBD: Is there a cleaner way to compute this? | |
127 end | 126 end |