CliMA / Oceananigans.jl

🌊 Julia software for fast, friendly, flexible, ocean-flavored fluid dynamics on CPUs and GPUs
https://clima.github.io/OceananigansDocumentation/stable
MIT License
987 stars 193 forks source link

Strange behaviour of Lagrangian Particles near top of domain #2681

Closed jagoosw closed 2 years ago

jagoosw commented 2 years ago

Hi all,

I've come across a strange issue with Lagrangian particles where if they're near the top of the domain they always jump down by Δz after the first intermediate time step. I have tracked this down to the boundary condition enforcement where there is an off by one error choosing the maximum allowed position. The error would also have occurred in the x and y directions too.

I will pull request this fix: https://github.com/jagoosw/Oceananigans.jl/tree/particle_tracking

I realized @simone-silvestri is working on an overhaul of Lagrangian particle tracking but it seems to not be fixed in that branch either.

Hope this helps!

MWE:

using Oceananigans

grid = RectilinearGrid(size=(2,2,2), extent=(2,2,2))
particles =  LagrangianParticles(x=[0.5], y=[0.5], z=[-0.5])
model = NonhydrostaticModel(; grid, timestepper=:RungeKutta3, particles=particles)
set!(model, u=0, v=0, w=0)
sim = Simulation(model, Δt=1, stop_time=1)
printz(sim)=println(sim.model.particles.properties.z)
sim.callbacks[:z] = Callback(printz)
run!(sim)

Result:

[ Info: Initializing simulation...
[-0.5]
[ Info:     ... simulation initialization complete (429.036 ms)
[ Info: Executing initial time step...
[ Info:     ... initial time step complete (22.760 seconds).
[ Info: Simulation is stopping. Model time 1 second has hit or exceeded simulation stop time 1 second.
[-1.5]

Results with fix

[ Info: Initializing simulation...
[-0.5]
[ Info:     ... simulation initialization complete (10.887 ms)
[ Info: Executing initial time step...
[ Info:     ... initial time step complete (1.866 ms).
[ Info: Simulation is stopping. Model time 1 second has hit or exceeded simulation stop time 1 second.
[-0.5]
tomchor commented 2 years ago

Fixed by https://github.com/CliMA/Oceananigans.jl/pull/2682