-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug in advect_particle
#3923
Conversation
interpolate!
for regular gridsadvect_particle
src/Fields/interpolate.jl
Outdated
@@ -68,30 +68,30 @@ end | |||
x₀ = xnode(1, 1, 1, grid, locs...) | |||
Δx = xspacings(grid, locs...) | |||
FT = eltype(grid) | |||
return convert(FT, (x - x₀) / Δx) | |||
return convert(FT, (x - x₀) / Δx) # 0 - based indexing! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return convert(FT, (x - x₀) / Δx) # 0 - based indexing! | |
return convert(FT, (x - x₀) / Δx) + 1 |
why isn't this the fix?
Why don't we change |
I am trying option 2. I also think it might be the cleaner option. Let's see if something breaks |
Why does 0-based indexing support extrapolation when 1-based does not? |
I am actually not even sure that it can do extrapolation. Oceananigans.jl/src/Fields/interpolate.jl Lines 268 to 272 in 0be921d
and I kind of deduced is for extrapolation, but I see now that it does not make much sense |
…ans.jl into ss/fix-interpolation-bug
Thanks so much for the fix @simone-silvestri! I'm guessing the PR is not ready for testing? Happy to help here if I can. I tried running the MWE from #3917 (comment) which now throws a GPU exception at the first time step, caught with
|
src/Fields/interpolate.jl
Outdated
@@ -132,16 +134,16 @@ ZRegGrid = Union{ZRegularRG, ZRegularLLG, ZRegOrthogonalSphericalShellGrid} | |||
|
|||
@inline function fractional_z_index(z::FT, locs, grid::ZRegGrid) where FT | |||
z₀ = znode(1, 1, 1, grid, locs...) | |||
Δz = @inbounds first(zspacings(grid, locs...)) | |||
return convert(FT, (z - z₀) / Δz) | |||
Δz = Δz(1, 1, 1, grid, locs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Δz = Δz(1, 1, 1, grid, locs...) | |
Δz = zspacing(1, 1, 1, grid, locs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use the pointwise operators defined in the operator module instead of the zspacing
function and so on. (there is a conflict in the name here though, I ll correct it)
…ans.jl into ss/fix-interpolation-bug
Looking at the latest Buildkite build, I think one or some of the tests are failing because https://buildkite.com/clima/oceananigans/builds/19175#01934dbf-8dcf-471b-a3dc-ffecd42006df/18-582 |
Hmmm, shall we define it here in this PR? |
The problem is that |
Yeah I think that's what we decided to do as part of #3143: to define spacing functions as needed. Although if we find ourselves needing new ones all the time, then might as well define them all.
In #3143 we also decided that a |
I see. I think the problem is that In my opinion |
We should never use ^a in numerics. Only for grid-specific operators. Using ^a generally means that the code is incorrect. As @simone-silvestri this is not merely an issue with the underlying grids, but also affects immersed boundary grids which can change the metrics. |
…ans.jl into ss/fix-interpolation-bug
I understand now the role of nothing pointing to I defined the operators that were not defined and the tests now pass |
solid |
The problem here stems from the fact that
fractional_indices
used for interpolation are 0-based indices to which, in theinterpolate
function, is summed 1.The particle advection module uses
fractional_indices
directly outside the interpolate function, so the indices are inconsistent (there is a mix of 0-based and 1-based conventions).There might be two solutions here:
fractional_indices.
This might be cleaner from a user and developer perspective (mixing index basis is dangerous). However, as it stands now, we probably support extrapolation (becausefractional_index
can be negative), so we would lose that behavior.I also have a straightforward, simple unit test. We probably need some more.
There were also a couple more bugs in the bounce method
closes #3917