Mercurial > repos > public > sbplib_julia
comparison src/Grids/grid.jl @ 1397:86026367a9ff feature/grids/scalar_eval_on
Support evaluating scalars on grids
| author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
|---|---|
| date | Tue, 15 Aug 2023 22:55:25 +0200 |
| parents | 08f06bfacd5c |
| children | dba1e8c95bbb |
comparison
equal
deleted
inserted
replaced
| 1384:851d1e4ab3de | 1397:86026367a9ff |
|---|---|
| 72 # TBD: Can we implement a version here that accepts multiple ids and grouped boundaries? Maybe we need multiblock stuff? | 72 # TBD: Can we implement a version here that accepts multiple ids and grouped boundaries? Maybe we need multiblock stuff? |
| 73 | 73 |
| 74 """ | 74 """ |
| 75 eval_on(g::Grid, f) | 75 eval_on(g::Grid, f) |
| 76 | 76 |
| 77 Lazy evaluation `f` on the grid. `f` can either be on the form `f(x,y,...)` | 77 Lazy evaluation of `f` on the grid. `f` can either be on the form `f(x,y,...)` |
| 78 with each coordinate as an argument, or on the form `f(x̄)` taking a | 78 with each coordinate as an argument, or on the form `f(x̄)` taking a |
| 79 coordinate vector. | 79 coordinate vector. |
| 80 | 80 |
| 81 For concrete array grid functions `map(f,g)` can be used instead. | 81 For concrete array grid functions `map(f,g)` can be used instead. |
| 82 """ | 82 """ |
| 86 return LazyTensors.LazyFunctionArray((I...)->f(g[I...]), size(g)) | 86 return LazyTensors.LazyFunctionArray((I...)->f(g[I...]), size(g)) |
| 87 else | 87 else |
| 88 return LazyTensors.LazyFunctionArray((I...)->f(g[I...]...), size(g)) | 88 return LazyTensors.LazyFunctionArray((I...)->f(g[I...]...), size(g)) |
| 89 end | 89 end |
| 90 end | 90 end |
| 91 """ | |
| 92 eval_on(g::Grid, f::Number) | |
| 93 | |
| 94 Lazy evaluation of a scalar `f` on the grid. ` | |
| 95 | |
| 96 For concrete array grid functions `map(f,g)` can be used instead. | |
| 97 """ | |
| 98 eval_on(g::Grid, f::Number) = return LazyTensors.LazyConstantArray(f, size(g)) | |
| 91 | 99 |
| 92 _ncomponents(::Type{<:Number}) = 1 | 100 _ncomponents(::Type{<:Number}) = 1 |
| 93 _ncomponents(T::Type{<:SVector}) = length(T) | 101 _ncomponents(T::Type{<:SVector}) = length(T) |
