-
Notifications
You must be signed in to change notification settings - Fork 195
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 for lat-lon grid with Periodic y
-dimension
#3467
Conversation
y
-dimension
there are other places that this can change -- just wanna see if all tests are OK first |
Co-authored-by: Gregory L. Wagner <[email protected]>
Co-authored-by: Gregory L. Wagner <[email protected]>
Co-authored-by: Gregory L. Wagner <[email protected]>
I believe this PR is ready to review |
Interestingly this breaks the distributed tests! |
That's annoying. There must be some implicit assumptions that we can't see |
@simone-silvestri can you help? |
this is the assumption Oceananigans.jl/src/DistributedComputations/distributed_grids.jl Lines 140 to 160 in c55878e
|
I don't understand that text on first read... I think it's just wrong that the meridional direction is always |
Hmmm, I am not sure how you solved this in the serial grid, but I guess in the same way. By removing that assumption and calculating the coordinate accordingly? |
Since we removed the assumption, do we also eliminate the need for this code which avoids the assumption? |
If the metrics are correctly calculated on the boundary for Note that in the latitude direction, the halo metrics for |
|
sure it is possible to define it, still it is conceptually wrong, you can easily see it if you visualize the grid: julia> grid = LatitudeLongitudeGrid(size = (1, 2, 1), topology = (Periodic, Periodic, Bounded), latitude = (50, 52), longitude = (10, 11), z = (0, 1))
1×2×1 LatitudeLongitudeGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo and with precomputed metrics
├── longitude: Periodic λ ∈ [10.0, 11.0) regularly spaced with Δλ=1.0
├── latitude: Periodic φ ∈ [50.0, 52.0) regularly spaced with Δφ=1.0
└── z: Bounded z ∈ [0.0, 1.0] regularly spaced with Δz=1.0
julia> grid.Δxᶜᶠᵃ
8-element OffsetArray(::Vector{Float64}, -2:5) with eltype Float64 with indices -2:5:
0.0
74403.92868970236
72950.43560309989
71474.721107126
69977.2347187117
68458.43258671739
66918.77735298542
0.0 Note, the delta x in the halos. They are inconsistent with the periodic assumption. Even if it were, it is impossible to reconcile julia> Vᶜᶜᶜ(1, 3, 1, grid)
7.526820531985937e9
julia> Vᶜᶜᶜ(1, 1, 1, grid)
7.864569567312662e9 |
It's valid for a single column and that is exactly why we need this feature. If you want, we can throw an error or warning if we have more than one point in y. |
Shouldn't a single column use a |
In a periodic single column, again, the problem would be that A consequence is that, since there should be zero derivatives in the y direction, |
Not when we want to interpolate data onto a particular location. |
The halo region metrics need to be enforced to be periodic. Just like we do for |
Where in the code does this crop up? Note that advection is turned off for a single column model... |
This is what we get for julia> flat_grid = LatitudeLongitudeGrid(size=grid.Nz, longitude=(215, 215.25), latitude=(50, 50.25), z=(-400, 0), topology=(Flat, Flat, Bounded))
1×1×100 LatitudeLongitudeGrid{Float64, Flat, Flat, Bounded} on CPU with 0×0×3 halo and without precomputed metrics
├── longitude: Flat λ
├── latitude: Flat φ
└── z: Bounded z ∈ [-400.0, 0.0] regularly spaced with Δz=4.0
julia> flat_grid.λᶜᵃᵃ
StepRangeLen(1.0, 0.0, 1) |
Changes in both grid construction and also interpolation would be needed to support
|
Another possibility is to build two grids, then use one for interpolation and then manually copy the data onto a new field generated on the Another question is whether this should work for grids that are symmetric about the equator. It seems like it should. |
I think we can close this PR and #3465 because the fix was already merged in #3450 (sorry for putting that in silently, I was just trying to get the code working). As @simone-silvestri points out, simulations that are Periodic-in-latitude may be physically incorrect. However, the code will run and does not necessary blow up immediately, for example: toroidal_world.mp4I think we could consider adding a warning for this case in a future PR, but we can discuss that elsewhere. |
Code for the above here: using Oceananigans
using Oceananigans.Units
using Oceananigans.BoundaryConditions: fill_halo_regions!
using GLMakie
Δ = 30
δ = 10
grid = LatitudeLongitudeGrid(size = (128, 128, 1),
longitude = (-Δ, Δ),
latitude = (-Δ, Δ),
z = (-1, 0),
topology = (Periodic, Periodic, Bounded))
model = HydrostaticFreeSurfaceModel(; grid,
coriolis = HydrostaticSphericalCoriolis(),
free_surface = SplitExplicitFreeSurface(cfl=0.7; grid),
tracer_advection = nothing,
momentum_advection = WENO())
Δx = minimum_xspacing(grid)
ψᵢ(λ, φ, z) = exp(-(λ^2 + φ^2) / (2δ^2))
ψ = Field{Face, Face, Center}(grid)
set!(ψ, ψᵢ)
fill_halo_regions!(ψ)
set!(model, u=-∂y(ψ), v=∂x(ψ))
#uᵢ(λ, φ, z) = exp(-(λ^2 + φ^2) / (2δ^2))
#set!(model, u=uᵢ)
simulation = Simulation(model, Δt=20minutes, stop_iteration=1000)
ut = []
vt = []
t = []
function save_uvt(sim)
push!(ut, deepcopy(interior(sim.model.velocities.u, :, :, 1)))
push!(vt, deepcopy(interior(sim.model.velocities.v, :, :, 1)))
push!(t, time(sim))
@info string("Iter: ", iteration(sim), ", time: ", prettytime(sim))
return nothing
end
add_callback!(simulation, save_uvt, IterationInterval(10))
run!(simulation)
fig = Figure(size=(800, 400))
axu = Axis(fig[1, 1])
axv = Axis(fig[1, 2])
Nt = length(t)
n = Observable(1)
un = @lift ut[$n]
vn = @lift vt[$n]
heatmap!(axu, un)
heatmap!(axv, vn)
record(fig, "toroidal_world.mp4", 1:Nt) do nn
@info "Drawing frame $nn of $Nt..."
n[] = nn
end |
Since #3465 was closed, do we still need this PR open? |
no we don't |
Closes #3465