Skip to content
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

Fixes bug in FlatExtrapolation matching scheme #3854

Merged
merged 7 commits into from
Oct 25, 2024
Merged

Conversation

tomchor
Copy link
Collaborator

@tomchor tomchor commented Oct 22, 2024

No description provided.

@tomchor
Copy link
Collaborator Author

tomchor commented Oct 22, 2024

Should we add a test for this? Or at least make all directions testable on the validation script?

Copy link
Member

@ali-ramadhan ali-ramadhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find! Fix makes sense to me so I'm approving.

If it's non-trivial to design a good test for these open boundary conditions, then to me it make sense to merge this obvious fix and discuss how to more thoroughly test in a separate issue or PR.

@tomchor
Copy link
Collaborator Author

tomchor commented Oct 22, 2024

Nice find! Fix makes sense to me so I'm approving.

If it's non-trivial to design a good test for these open boundary conditions, then to me it make sense to merge this obvious fix and discuss how to more thoroughly test in a separate issue or PR.

I think creating a test is non-trivial, but modifying the existing validation script to be more expansive is trivial since I pretty much have the code ready. Should I just do that?

@glwagner
Copy link
Member

Does this fix the problems we see on #3848 ?

@tomchor
Copy link
Collaborator Author

tomchor commented Oct 22, 2024

Does this fix the problems we see on #3848 ?

No, this bug makes the code fail with an UndefVarError, but only when FlatExtrapolationOBC is used as a bottom BC.

@tomchor
Copy link
Collaborator Author

tomchor commented Oct 24, 2024

I changed oscillating_flow.jl to oscillate in two directions at once. It then oscillates first in the xy direction, then the xz direction, therefore testing all directions in the process. This is the animation it produces for the xy direction:

_cylinder_xy_FlatExtrapolation_Nx_40.jld2.mp4

and this is the animation for the xz direction:

_cylinder_xz_FlatExtrapolation_Nx_40.jld2.mp4

@jagoosw, I'm curious to hear your take on the artifacts that appear at the edges of the right x boundary. If I plot v and w those artifacts are also there (also on the "right" side), so I think this a general "issue" with the algorithm, rather than something wrong with the x direction specifically. Do you have any idea of what this is?

@tomchor tomchor mentioned this pull request Oct 25, 2024
@jagoosw
Copy link
Collaborator

jagoosw commented Oct 25, 2024

@jagoosw, I'm curious to hear your take on the artifacts that appear at the edges of the right x boundary. If I plot v and w those artifacts are also there (also on the "right" side), so I think this a general "issue" with the algorithm, rather than something wrong with the x direction specifically. Do you have any idea of what this is?

I'm not sure I'm seeing what you mean? Do you mean the corner points being different?

@tomchor
Copy link
Collaborator Author

tomchor commented Oct 25, 2024

@jagoosw, I'm curious to hear your take on the artifacts that appear at the edges of the right x boundary. If I plot v and w those artifacts are also there (also on the "right" side), so I think this a general "issue" with the algorithm, rather than something wrong with the x direction specifically. Do you have any idea of what this is?

I'm not sure I'm seeing what you mean? Do you mean the corner points being different?

Yes that's what I mean. To be even clearer, these:

image

The zero points in u being the cause of similar weirdness in the calculations of vorticity. Do you know what's going on there?

@tomchor tomchor merged commit 359bec8 into main Oct 25, 2024
46 checks passed
@tomchor tomchor deleted the tc/flat-extrapolation-bug branch October 25, 2024 13:50
@glwagner
Copy link
Member

You may need to fill the point Nx + 1 , Ny + 1

@tomchor
Copy link
Collaborator Author

tomchor commented Oct 26, 2024

You may need to fill the point Nx + 1 , Ny + 1

If I understand your comment, we are doing that:

@inline function _fill_east_open_halo!(j, k, grid, ϕ, bc::FEOBC, loc, clock, model_fields)
i = grid.Nx + 1
Δx₁ = xspacing(i-1, j, k, grid, c, c, c)
Δx₂ = xspacing(i-2, j, k, grid, c, c, c)
Δx₃ = xspacing(i-3, j, k, grid, c, c, c)
spacing_factor = Δx₁ / (Δx₂ + Δx₃)
gradient_free_ϕ = @inbounds ϕ[i - 2, j, k] - (ϕ[i - 1, j, k] - ϕ[i - 3, j, k]) * spacing_factor
@inbounds ϕ[i, j, k] = relax(j, k, grid, gradient_free_ϕ, bc, clock, model_fields)
return nothing
end

@glwagner
Copy link
Member

You may need to fill the point Nx + 1 , Ny + 1

If I understand your comment, we are doing that:

@inline function _fill_east_open_halo!(j, k, grid, ϕ, bc::FEOBC, loc, clock, model_fields)
i = grid.Nx + 1
Δx₁ = xspacing(i-1, j, k, grid, c, c, c)
Δx₂ = xspacing(i-2, j, k, grid, c, c, c)
Δx₃ = xspacing(i-3, j, k, grid, c, c, c)
spacing_factor = Δx₁ / (Δx₂ + Δx₃)
gradient_free_ϕ = @inbounds ϕ[i - 2, j, k] - (ϕ[i - 1, j, k] - ϕ[i - 3, j, k]) * spacing_factor
@inbounds ϕ[i, j, k] = relax(j, k, grid, gradient_free_ϕ, bc, clock, model_fields)
return nothing
end

Are you sure? What is the range of j (and k)?

@jagoosw
Copy link
Collaborator

jagoosw commented Oct 26, 2024

I'm not sure that the corner points are used in the prognostic calculations right? I guess this would be important if you wanted to do something on the boundary that includes the boundary tangent derivatives, but I haven't come across any schemes that use that

@tomchor
Copy link
Collaborator Author

tomchor commented Oct 26, 2024

Are you sure? What is the range of j (and k)?

You're right that j and k (or more generally the directions parallel to the boundary that's being filled) only go up to grid.Ny and grid.Nz. I'm not sure how to change that, though. I'd like to play around with things. Do you mind pointing me in the right direction?

I'm not sure that the corner points are used in the prognostic calculations right? I guess this would be important if you wanted to do something on the boundary that includes the boundary tangent derivatives, but I haven't come across any schemes that use that

You may be right. Still I'd like to investigate. The lack of symmetry between left and right sides is a bit suspicious, no?

@glwagner
Copy link
Member

I'm not sure that the corner points are used in the prognostic calculations right?

It depends on the physics. You should check for coriolis, VectorInvariant advection, and biharmonic viscosities. I suspect the corners come into play for those.

Do you mind pointing me in the right direction?

Check out Oceananigans.Utils.KernelParameters and use this when launching the kernel that fills the halos.

@tomchor
Copy link
Collaborator Author

tomchor commented Oct 27, 2024

It turns out the open boundary part of the code doesn't use KernelParameters. It instead uses fill_halo_size():

fill_size = fill_halo_size(field, regular_fill, indices, boundary_conditions, loc, grid)

Changing parameters there in order to go from 0 to grid.Ny+1 gets rid of those edges:

_cylinder_xy_FlatExtrapolation_Nx_40.jld2.mp4

I believe this is the preferred way to do things, but it would be nice to hear from other people. If we agree to change things I can open a PR.

@glwagner
Copy link
Member

It turns out the open boundary part of the code doesn't use KernelParameters. It instead uses fill_halo_size():

For sure, you just have to change it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants