Skip to content

Open lateral boundary conditions for anelastic models#494

Open
glwagner wants to merge 6 commits into
mainfrom
glw/anelastic-open-bcs
Open

Open lateral boundary conditions for anelastic models#494
glwagner wants to merge 6 commits into
mainfrom
glw/anelastic-open-bcs

Conversation

@glwagner
Copy link
Copy Markdown
Member

Summary

  • Implements open lateral boundary conditions for anelastic dynamics using Oceananigans' PerturbationAdvection radiation scheme and a new density-aware PerturbationMomentumAdvection variant
  • Adds BoundaryMassFluxes infrastructure to enforce the anelastic solvability condition (net mass flux through open boundaries must vanish)
  • Fixes PMA application count: was applied 3x per RK3 stage (via fill_halo_regions! in update_state!, compute_velocities!, and compute_pressure_correction!); now applied only once by passing fill_open_bcs=false to non-pressure halo fills
  • Sets clock.last_stage_Δt before first pressure correction so PMA uses correct Δt on the first time step
  • Adds two literate examples: open-boundary thermal bubble and mountain wave with witch-of-Agnesi ridge
  • Adds comprehensive test suite for open boundary construction, velocity BC propagation, mass conservation, and uniform flow stability

Test plan

  • All 1542 tests pass (Pkg.test("Breeze"))
  • Open boundary tests pass (21/21) including new uniform flow stability test
  • Quality assurance passes (17/17) — ExplicitImports, Aqua
  • Parcel dynamics passes (93/93) — handles empty momentum gracefully
  • Mountain wave example runs to completion with stable lee waves (verified locally)
  • CI passes on GitHub

🤖 Generated with Claude Code

glwagner and others added 5 commits February 18, 2026 20:37
Add PerturbationMomentumAdvection scheme for density-aware open boundary
radiation, GPU-compatible boundary mass flux computation for the anelastic
solvability condition, and velocity field BC inheritance from momentum fields.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
A 2D rising thermal in a stably stratified atmosphere demonstrates
gravity wave radiation through open lateral boundaries using the
Klemp-Wilhelmson radiation scheme.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ve example

The open boundary radiation scheme (PerturbationAdvection) was being applied
3x per RK3 stage instead of once, because fill_halo_regions! triggered it in
update_state!, compute_velocities!, and compute_pressure_correction!. This
caused boundary instability equivalent to advancing by 3*Δt instead of Δt.

Fixes:
- Add fill_open_bcs=false to fill_halo_regions! calls in update_state! and
  compute_velocities!, matching Oceananigans' NonhydrostaticModel pattern
- Set clock.last_stage_Δt = Δt before first pressure correction so PMA uses
  correct Δt on the first time step (was Inf, making PMA a no-op)
- Replace inherit_momentum_bcs with propagate_open_bcs for cleaner velocity
  BC handling at open boundaries
- Handle ParcelModels with empty momentum in initialize_boundary_mass_fluxes
- Fix ExplicitImports violation (view imported from Base, not Oceananigans.Fields)

Adds mountain wave literate example with witch-of-Agnesi ridge, uniform 10 m/s
wind, stable stratification, and PerturbationAdvection open boundaries with
outflow_timescale=1. Adds uniform flow stability test to open_boundaries.jl.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ationAdvection

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
glwagner added a commit to CliMA/Oceananigans.jl that referenced this pull request Feb 20, 2026
Extends PerturbationAdvection with two optional features needed for
models with density-weighted prognostic variables (e.g., anelastic models):

1. `density` field: when provided, converts density-weighted fields (ρψ)
   to intensive fields (ψ) before radiation and back after. This fixes the
   dimensional inconsistency when applying PerturbationAdvection directly
   to prognostic variables like ρu, ρθ, ρq.

2. `gravity_wave_speed`: additional phase speed added to the advective
   velocity, following Klemp & Wilhelmson (1978). Useful for momentum
   fields where gravity waves propagate faster than the mean flow.

Both default to `nothing` and `0` respectively, so this is fully backward
compatible — existing code using PerturbationAdvection is unaffected.

Also adds _fill_*_halo! methods for Center-located fields, enabling
PerturbationAdvection to be used on scalar fields (tracers, ρθ, etc.)
in addition to Face-located velocity/momentum fields.

Motivated by NumericalEarth/Breeze.jl#494 which currently maintains a
separate PerturbationMomentumAdvection scheme with ~270 lines of
duplicated radiation logic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 75.78947% with 46 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ndaryConditions/perturbation_momentum_advection.jl 55.20% 43 Missing ⚠️
src/AtmosphereModels/boundary_mass_fluxes.jl 96.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

glwagner added a commit to CliMA/Oceananigans.jl that referenced this pull request Feb 26, 2026
…#5314)

* Add density and gravity_wave_speed to PerturbationAdvection

Extends PerturbationAdvection with two optional features needed for
models with density-weighted prognostic variables (e.g., anelastic models):

1. `density` field: when provided, converts density-weighted fields (ρψ)
   to intensive fields (ψ) before radiation and back after. This fixes the
   dimensional inconsistency when applying PerturbationAdvection directly
   to prognostic variables like ρu, ρθ, ρq.

2. `gravity_wave_speed`: additional phase speed added to the advective
   velocity, following Klemp & Wilhelmson (1978). Useful for momentum
   fields where gravity waves propagate faster than the mean flow.

Both default to `nothing` and `0` respectively, so this is fully backward
compatible — existing code using PerturbationAdvection is unaffected.

Also adds _fill_*_halo! methods for Center-located fields, enabling
PerturbationAdvection to be used on scalar fields (tracers, ρθ, etc.)
in addition to Face-located velocity/momentum fields.

Motivated by NumericalEarth/Breeze.jl#494 which currently maintains a
separate PerturbationMomentumAdvection scheme with ~270 lines of
duplicated radiation logic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Bump version to 0.105.1

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add backward-compatible PerturbationAdvection constructor and update call sites

Add a 2-positional-arg constructor for backward compatibility after the
struct gained gravity_wave_speed and density fields. Update tests and
validation scripts to use keyword arguments. Rename test_CGSolver to
test_cgsolver to conform with naming conventions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Apply suggestion from @glwagner

* Fix PerturbationAdvection doctest for new struct signature

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Retrigger CI

* Apply suggestion from @glwagner

* Update Project.toml

* update notation

* Apply suggestion from @glwagner

* Use unicode instead of LaTeX in PerturbationAdvection docstring

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant