When using LagrangianParticles in a grid with one direction having Flat topology, the code fails because the fractional index function hits the wrong line of code. Here is a MWE:
using Oceananigans
using StructArrays
using Printf
grid = RectilinearGrid(CPU(), Float64,
size = (2, 2),
halo = (5, 5),
x = (0, 1),
y = (0, 1),
topology = (Periodic, Bounded, Flat))
#%%
struct SimpleParticle{X}
x :: X
y :: X
z :: X
end
x_particle = [0.5]
y_particle = [0.5]
z_particle = [0.5]
particles = StructArray{SimpleParticle}((x_particle, y_particle, z_particle))
lagrangian_particles = LagrangianParticles(particles)
#%%
model = NonhydrostaticModel(;
grid = grid,
timestepper = :RungeKutta3,
advection = WENO(order=9),
particles = lagrangian_particles
)
u, v, w = model.velocities
simulation = Simulation(model, Δt=0.1, stop_iteration=2)
wall_clock = [time_ns()]
function print_progress(sim)
@printf("i: %d, t: %s, wall time: %s, max(u): (%6.3e, %6.3e, %6.3e) m/s, next Δt: %s\n",
sim.model.clock.iteration,
prettytime(sim.model.clock.time),
prettytime(1e-9 * (time_ns() - wall_clock[1])),
maximum(abs, sim.model.velocities.u),
maximum(abs, sim.model.velocities.v),
maximum(abs, sim.model.velocities.w),
prettytime(sim.Δt))
@info "x(particle): $(round.(lagrangian_particles.properties.x, digits=2)), y(particle): $(round.(lagrangian_particles.properties.y, digits=2)), z(particle): $(round.(lagrangian_particles.properties.z, digits=2))\n"
wall_clock[1] = time_ns()
return nothing
end
simulation.callbacks[:print_progress] = Callback(print_progress, IterationInterval(1))
run!(simulation)
When using
LagrangianParticles
in agrid
with one direction havingFlat
topology, the code fails because the fractional index function hits the wrong line of code. Here is a MWE:which gives an error output of
The error indicates that
fractional_z_index
function hits https://github.com/CliMA/Oceananigans.jl/blob/d4bcc095be66c7b5c98a462106285a6f6d341fe1/src/Fields/interpolate.jl#L133 instead of https://github.com/CliMA/Oceananigans.jl/blob/d4bcc095be66c7b5c98a462106285a6f6d341fe1/src/Fields/interpolate.jl#L129, which is the intended function dispatch.Note: doing something like
is not supported, but perhaps this is a separate discussion.