-
Notifications
You must be signed in to change notification settings - Fork 173
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 index calculation for Lagrangian particles in periodic directions #3416
base: main
Are you sure you want to change the base?
Conversation
Here's a test script: using Oceananigans
using Oceananigans.Units
using StructArrays
using Printf
using Random
using Statistics
Random.seed!(123)
grid = RectilinearGrid(CPU(), Float64,
size = (2, 2, 2),
halo = (5, 5, 5),
x = (0, 1),
y = (0, 1),
z = (-1, 0),
topology = (Periodic, Bounded, Bounded))
#%%
struct SimpleParticle{X}
x :: X
y :: X
z :: X
end
x_particle = collect(0:0.25:1.5)
y_particle = collect(0:0.25:1.5)
z_particle = collect(fill(-0.5, length(x_particle)))
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.1seconds, 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) In the test script, the domain is initialized to be Here's the output of the script:
We see that the particles that are outside of the domain in |
Oh I see, that looks good. My confusion was because I guess instead of using |
I suggest defining a new function for the rightmost cell index instead of using interface_index_rightmost(::Bounded, N) = N + 1
interface_index_rightmost(::Periodic, N) = N + 1
interface_index_rightmost(::Flat, N) = N Then iᴿ = interface_index_rightmost(tx, Nx)
jᴿ = interface_index_rightmost(ty, Ny)
kᴿ = interface_index_rightmost(tz, Nz) I am not sure whether |
That is indeed different from |
See issue #3415