Allow kernel functions with fewer indices for KernelFunctionOperation at reduced locations#5659
Allow kernel functions with fewer indices for KernelFunctionOperation at reduced locations#5659simone-silvestri wants to merge 4 commits into
Conversation
| ```julia | ||
| kernel_function(i, j, grid, arguments...) | ||
| ``` | ||
|
|
There was a problem hiding this comment.
I suggest including a full example that illustrates how this works including the KernelFunctionOperation{Center, Center, Nothing} constructor, to be fully explicit
glwagner
left a comment
There was a problem hiding this comment.
I remember considering this at some point in the past, but that there were some issues or barriers to it. Perhaps there are not.
| # Three-index kernel functions at reduced locations still work | ||
| three_index_kernel_function(i, j, k, grid) = i + j | ||
| op = KernelFunctionOperation{Center, Center, Nothing}(three_index_kernel_function, grid) | ||
| @test Array(interior(compute!(Field(op))))[:, :, 1] == [i + j for i in 1:size(grid, 1), j in 1:size(grid, 2)] |
There was a problem hiding this comment.
You don't need to call compute!(Field(op)), because compute! is already called within Field(op).
The indexing is also messed up, so this can be interior(Field(op), :, :, 1) |> Array or something.
|
I think the problem here is which method takes precedence, the three index method, the reduced method, or just allow only a reduced method which will cause no ambiguity. |
At the moment,
KernelFunctionOperations work only with functions that have signature(i, j, k, grid, args...). However, some time, we want to have KernelFunctionOperations on genuinely 2D functions, corresponding to Nothing locations.For example:
Oceananigans.jl/src/ImmersedBoundaries/grid_fitted_bottom.jl
Lines 151 to 154 in 5494227
At the moment, we would need to create a helper function that redirects a
kindex into two-d functions.This PR makes this step automatic so that it would be possible, for example, to do
without requiring extra code