-
Notifications
You must be signed in to change notification settings - Fork 188
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
Lagrangian particles on Flat topology #3545
Comments
Thank you for opening this @Jamie-Hilditch ! Of course we want to advect particles in I think this is a bug because apparently there is some attempt to support Oceananigans.jl/src/Models/LagrangianParticleTracking/lagrangian_particle_advection.jl Line 76 in ce4faba
calls these functions Oceananigans.jl/src/Models/LagrangianParticleTracking/LagrangianParticleTracking.jl Lines 121 to 128 in ce4faba
Something must have broken when we changed We may want # Deal with `nothing` indices, which are output by `fractional_indices` in `Flat` domains
@inline truncate_index(::Nothing) = 1
@inline truncate_index(i) = Base.unsafe_trunc(Int, i) and then fi, fj, fk = fractional_indices(X, grid, c, c, c)
i = truncate_index(fi)
j = truncate_index(fj)
k = truncate_index(fk) Does this solve the problem? (I'm also suggesting a small change in notation to clarify the difference between a "fractional index" and a truncated index.) @Jamie-Hilditch if you like, you can contribute this change --- or I can add it. Up to you, let us know. |
Yes, this change plus adding the code to "enforce" the boundary conditions appears to fix the bug. The fractional indices are truncated in two places - the advection code and in |
@Jamie-Hilditch great! We could also change the name of |
I was trying to add some Lagrangian particles to a 2D simulation I was running but Lagrangian particle advection currently assumes that the grid is bounded or periodic in all dimensions. An MWE (on Julia 1.10.1+0.x64.w64.mingw32 and Oceananigans version 0.90.12) that reproduces the issue is:
with output
The offending line is
Oceananigans.jl/src/Models/LagrangianParticleTracking/lagrangian_particle_advection.jl
Line 81 in ce4faba
which fails because
Oceananigans.jl/src/Models/LagrangianParticleTracking/lagrangian_particle_advection.jl
Line 79 in ce4faba
returns
j = nothing
wheny
isFlat
.However, I think that in general
advect_particle
is not written with Flat topologies in mind. For example, there are no boundary conditions implemented for the Flat topology.The ability to do 2D (and 1D) Lagrangian particles would be quite useful. Although, it's not obvious what it means to advect a particle in the Flat direction. Skipping that direction entirely or simply accumulating the displacement in that direction (as I do below) could both be valid in some contexts. (For my original use case I don't care what happens in
y
.)Finally, for this particular simple example, propagating
j = nothing
throughunsafe_trunc
and defining some boundary conditions was sufficient to make the example run.I'm not sure whether propagating
j = nothing
forward is a sensible or desirable thing to do, or if it even works in other cases, but I thought that I'd point out that it works here.The text was updated successfully, but these errors were encountered: