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
970 stars 193 forks source link

Open halo filling #3810

Open jagoosw opened 2 hours ago

jagoosw commented 2 hours ago

Hi all,

I think there's been a mistake in the open boundary filling that's only becoming a problem now that we're trying to fill non-zero value.

https://github.com/CliMA/Oceananigans.jl/blob/3ea2545331d9910d8b467dd8eb31074fb426af5b/src/BoundaryConditions/fill_halo_regions_open.jl#L86-L91

The open fill has always set point at index 1 on the right hand side and grid.N+1 on the right hand side, but 1 is part of the prognostic domain and halo points we need are just for computing gradients at the face point, which should be at 0.

I came across this because I've only been testing open boundaries on the right side, but was checking it worked in the other directions and realised it always failed when I just switched the direction and sides for a simple case.

Am I missing something here?

jagoosw commented 2 hours ago

For reference, when I fill u[0, j, k] instead of u[1, j, k] I can just reverse the flow in this cylinder case by changing the sign and swapping the boundary conditions round, but before it was failing instantly.

https://github.com/user-attachments/assets/b711f8aa-1848-4e9a-9546-3567f4816a1c

https://github.com/user-attachments/assets/04f8e2bb-ecd7-4af4-8f47-6633e099721e

glwagner commented 43 minutes ago

For face indexing convention, 1 is the interface forming left boundary of the domain and N+1 is the interface forming the right boundary.

For center indexing, the first cell on the left is 1 and the last cell on the right is N.

I'm not 100% sure what you are asking but this is the definition of the indices.

I think if you set N+1 for right-sided open boundaries, you should set 1 for left-sided open boundaries. If you set N+2 for the right side, then you would set 0 for the left side.

Maybe there is a bug somewhere else?