Skip to content

(0.105.5) Add unit test for zero momentum flux at immersed peripheral nodes#5402

Merged
tomchor merged 9 commits intomainfrom
tc/test-advective-forcing
Mar 17, 2026
Merged

(0.105.5) Add unit test for zero momentum flux at immersed peripheral nodes#5402
tomchor merged 9 commits intomainfrom
tc/test-advective-forcing

Conversation

@tomchor
Copy link
Copy Markdown
Member

@tomchor tomchor commented Mar 16, 2026

Tests that all 9 advective momentum flux kernels return zero at immersed peripheral nodes, for Centered(2), UpwindBiased(3), and WENO(5). This documents the expected behavior after PR #4987 removed the explicit conditional_flux zeroing from advective_momentum_flux* on ImmersedBoundaryGrid, relying instead on velocity masking in immersed cells and the no-penetration BC at the boundary face.

cc @simone-silvestri

Tests that all 9 advective momentum flux kernels return zero at
immersed peripheral nodes, for Centered(2), UpwindBiased(3), and
WENO(5). This documents the expected behavior after PR #4987 removed
the explicit conditional_flux zeroing from _advective_momentum_flux_*
on ImmersedBoundaryGrid, relying instead on velocity masking in
immersed cells and the no-penetration BC at the boundary face.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@simone-silvestri
Copy link
Copy Markdown
Collaborator

simone-silvestri commented Mar 16, 2026

I would make it a little more stressful, something like a random bottom boundary and then create a test field and then check if everywhere we have an immersed node, the flux is zero. Something like

c = Center()
f = Face()

@kernel function _populate_test!(tuu, tuv, tuw, tvu, tvv, tvw, twu, twv, tww grid, u, v, w)
    i, j, k = @index(Global, NTuple)
    Fuu = _advective_momentum_flux_Uu(i, j, k, grid, scheme, u, u)
    Fuv = _advective_momentum_flux_Uv(i, j, k, grid, scheme, u, v)
    Fuw = _advective_momentum_flux_Uw(i, j, k, grid, scheme, u, w)
    Fvu = _advective_momentum_flux_Vu(i, j, k, grid, scheme, v, u)
    Fvv = _advective_momentum_flux_Vv(i, j, k, grid, scheme, v, v)
    Fvw = _advective_momentum_flux_Vw(i, j, k, grid, scheme, v, w)
    Fwu = _advective_momentum_flux_Wu(i, j, k, grid, scheme, w, u)
    Fwv = _advective_momentum_flux_Wv(i, j, k, grid, scheme, w, v)
    Fww = _advective_momentum_flux_Ww(i, j, k, grid, scheme, w, w)
    
    @inbounds begin
         tuu[i, j, k] = (Fuu == 0) & immersed_peripheral_node(i, j, k, grid, c, c, c)
         tuv[i, j, k] = (Fuv == 0) & immersed_peripheral_node(i, j, k, grid, f, f, c)
         tuw[i, j, k] = (Fuw == 0) & immersed_peripheral_node(i, j, k, grid, f, c, f)
         tvu[i, j, k] = (Fvu == 0) & immersed_peripheral_node(i, j, k, grid, f, f, c)
         tvv[i, j, k] = (Fvv == 0) & immersed_peripheral_node(i, j, k, grid, c, c, c)
         tvw[i, j, k] = (Fvw == 0) & immersed_peripheral_node(i, j, k, grid, c, f, f)
         twu[i, j, k] = (Fwu == 0) & immersed_peripheral_node(i, j, k, grid, f, c, f)
         twv[i, j, k] = (Fwv == 0) & immersed_peripheral_node(i, j, k, grid, c, f, f)
         tww[i, j, k] = (Fww == 0) & immersed_peripheral_node(i, j, k, grid, c, c, c)
    end
end

then you can check

@test all(Array(interior(tuu))

and so on.

@tomchor
Copy link
Copy Markdown
Member Author

tomchor commented Mar 16, 2026

@simone-silvestri can you double check? Locally those tests fail for me. But they also fail when I include the conditional momentum fluxes back so maybe I misunderstood what you're trying to check?

Feel free to modify this PR directly also if that's easier.

@simone-silvestri
Copy link
Copy Markdown
Collaborator

We needed to include boundaries. Btw, it looks like we indeed need the conditional fluxes

@simone-silvestri simone-silvestri marked this pull request as ready for review March 16, 2026 12:12
@tomchor
Copy link
Copy Markdown
Member Author

tomchor commented Mar 16, 2026

cc @glwagner

@tomchor tomchor changed the title Add unit test for zero momentum flux at immersed peripheral nodes (0.105.5) Add unit test for zero momentum flux at immersed peripheral nodes Mar 16, 2026
@tomchor
Copy link
Copy Markdown
Member Author

tomchor commented Mar 16, 2026

Changed the title since apparently this is a bugfix. Although we could wait before this PR and #5366 are merged before registering a new version.

Added fallback functions for 'nothing' advection in immersed advective fluxes.
@simone-silvestri
Copy link
Copy Markdown
Collaborator

Changed the title since apparently this is a bugfix. Although we could wait before this PR and #5366 are merged before registering a new version.

We could also wait for #5383 which should be ready

@tomchor
Copy link
Copy Markdown
Member Author

tomchor commented Mar 17, 2026

Changed the title since apparently this is a bugfix. Although we could wait before this PR and #5366 are merged before registering a new version.

We could also wait for #5383 which should be ready

Sounds good. I reviewed and approved it already. I'd appreciate it if you could also review #5366 when you have a chance. And then maybe we can register a new version with all three PRs sooner rather than later.

@tomchor
Copy link
Copy Markdown
Member Author

tomchor commented Mar 17, 2026

Also I took the liberty to fix the test that was failing. Hopefully tests pass now.

@tomchor tomchor merged commit 4aa81b5 into main Mar 17, 2026
66 of 79 checks passed
@tomchor tomchor deleted the tc/test-advective-forcing branch March 17, 2026 22:20
briochemc added a commit to briochemc/Oceananigans.jl that referenced this pull request Mar 21, 2026
* glw/prescribed-free-surface:
  Clean up update_prescribed_∂t_σ! method signatures
  Fix ∂t_σ = 0 bug for PrescribedFreeSurface + ZStarCoordinate
  Revise citation for De Abreu and Timmermans (CliMA#5411)
  Add benchmarking package with earth_ocean case (CliMA#5317)
  (0.105.5) Add unit test for zero momentum flux at immersed peripheral nodes (CliMA#5402)
  (0.105.5) Fix `initialize_closure_fields!()` use with `DynamicSmagorinsky` (CliMA#5366)
  Fix the reference list in the Langmuir example (CliMA#5400)
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.

2 participants